# Event types

The $state object (and the quiz_states table) has a field $event which indicates the event that led to the state's creation. The field can take the value of any of the following constants (defined in locallib.php):

- EVENTOPEN: The attempt has just been opened and this is the initial state for which no attempts have come in yet.
- EVENTSAVE: The responses are just being saved, either because the student requested this explicitly or because the student navigated to another quiz page.
- EVENTVALIDATE: The student requested a validation of the responses.
- EVENTGRADE: The responses are being graded but the question session is not closed.
- EVENTCLOSE: The responses are being graded and the question session is closed. Usually this happens because the whole attempt closes, either because the student requests it or because the time is up or we are beyond the due date.
- EVENTDUPLICATEGRADE: This is a strange one. It indicates that the responses would have been graded had they not been found to be identical to previous responses.

When new responses are being processed by quiz_process_responses() then this function is being passed the event type in $action->event while the responses are in $action->responses.