/** * Set the data context for the question. * Decide which question we need based on current quiz state. * * @param $response (array) response from server, if present * @param $quiz (object) Enp_quiz_Quiz() * @return $question (array) The question we need to display */ public function set_question() { // if we have a question id, get the question data for it if (!empty($this->qt->current_question_id)) { $options = array('mc_options_order' => $this->qt->quiz->get_quiz_mc_options_order()); $question = new Enp_quiz_Question($this->qt->current_question_id, $options); } $question_type = $question->get_question_type(); $this->question = $question; }
protected function reset_all_quiz_questions_data($question_ids) { if (!empty($question_ids)) { foreach ($question_ids as $question_id) { // soft delete responses $this->delete_question_responses($question_id); // reset stats $this->reset_question_data($question_id); // create the question object $question = new Enp_quiz_Question($question_id); // get the question type $question_type = $question->get_question_type(); if ($question_type === 'mc') { $mc_option_ids = $question->get_mc_options(); foreach ($mc_option_ids as $mc_option_id) { // reset compiled mc option data $this->reset_mc_option_data($mc_option_id); // soft delete mc option response $this->delete_mc_option_responses($mc_option_id); } } elseif ($question_type === 'slider') { // get the slider id $slider_id = $question->get_slider(); // soft delete the responses $this->delete_slider_responses($slider_id); } } } }
public function quiz_object_to_array($quiz_obj) { $quiz_array = (array) $quiz_obj; $new_questions_array = array(); if (!empty($quiz_array)) { $question_ids = $quiz_obj->get_questions(); if (!empty($question_ids)) { foreach ($question_ids as $question_id) { // generate the object $question_obj = new Enp_quiz_Question($question_id); // arrayify the question $question_array = (array) $question_obj; // check if mc or slider and add that object as an array if ($question_obj->get_question_type() === 'mc') { $mc_option_ids = $question_obj->get_mc_options(); if (!empty($mc_option_ids)) { foreach ($question_obj->get_mc_options() as $mc_option_id) { $mc_option_object = new Enp_quiz_MC_option($mc_option_id); $mc_option_array = (array) $mc_option_object; $question_array['mc_option'][] = $mc_option_array; } } } elseif ($question_obj->get_question_type() === 'slider') { // get the slider ID $slider_id = $question_obj->get_slider(); // get the slider object $slider_object = new Enp_quiz_Slider($slider_id); // cast it to an array $slider_array = (array) $slider_object; // add it to the question $question_array['slider'] = $slider_array; } // add it to our questions array $quiz_array['question'][] = $question_array; } } } return $quiz_array; }