protected function update_quiz_data($data) { // if it doesn't match one of the states we need, go ahead and exit if (self::$return['state'] !== 'question_explanation' && self::$return['state'] !== 'quiz_end') { return false; } $quiz_data = new Enp_quiz_Save_quiz_take_Quiz_data(self::$quiz); $question_ids = self::$quiz->get_questions(); // if the new returned state is question_explanation and the submitted question_id was the first question of the quiz, then someone Started the quiz. if (self::$return['state'] === 'question_explanation' && (int) $data['question_id'] === (int) $question_ids[0]) { $quiz_data->update_quiz_starts(); } elseif (self::$return['state'] === 'quiz_end') { // update the response quiz table with the new score and state self::$save_response_quiz_obj->update_response_quiz_completed(self::$return); // if the new returnd state is quiz_end, then they finished the quiz // get their score $quiz_data->update_quiz_finishes(self::$return['quiz_end']['score']); } }