/** * Process and save quiz take form submissions and set the response variable */ public function save_quiz_take() { $response = false; $save_data = array(); // get the posted id if (isset($_POST['enp-quiz-id'])) { $save_data['quiz_id'] = $_POST['enp-quiz-id']; } $validate_nonce = $this->validate_nonce($save_data['quiz_id']); if ($validate_nonce === false) { // set the response as our error $this->response = array('error' => $this->error); // cast it to an object so we can access it like // $this->response->error as if it actually came back // from the save_quiz_take class that way $this->response = (object) $this->response; return false; } // get the posted data // get user action if (isset($_POST['enp-question-submit'])) { $save_data['user_action'] = $_POST['enp-question-submit']; } // get the user_id $save_data['user_id'] = $this->user_id; $save_data['response_quiz_id'] = $this->get_submitted_response_quiz_id(); if ($save_data['response_quiz_id'] === false) { return false; } // get the correctly_answered value if (isset($_POST['enp-quiz-correctly-answered'])) { $save_data['correctly_answered'] = $_POST['enp-quiz-correctly-answered']; } else { // set the response as our error $this->response = array('error' => $this->error); $this->error[] = 'No Quiz Correctly Answered Total found.'; return false; } $save_data['response_quiz_updated_at'] = date("Y-m-d H:i:s"); if ($save_data['user_action'] === 'enp-question-submit') { // build the data array $save_data = $this->build_response_data($save_data); } elseif ($save_data['user_action'] === 'enp-next-question') { // build the data array $save_data = $this->build_moving_on_data($save_data); } // save the response $save_quiz_take = new Enp_quiz_Save_quiz_take(); $response = $save_quiz_take->save_quiz_take($save_data); // parse the JSON response $this->response = json_decode($response); }
/** * Set the next question array for our response */ protected function set_next_question($question_id) { // check if we need to randomize mc options or not $quiz_mc_options_order = self::$quiz->get_quiz_mc_options_order(); $options = array('mc_options_order' => $quiz_mc_options_order); self::$next_question = new Enp_quiz_Question($question_id, $options); self::$return['next_question'] = self::$next_question->get_take_question_array(); }