protected function is_mc_option_response_correct($response) { // see if it's right... $mc = new Enp_quiz_MC_option($response['question_response']); // will return 0 if wrong, 1 if right. We don't care if // it's right or not, just that we KNOW if it's right or not $response_correct = $mc->get_mc_option_correct(); // if somehow this has been called on an invalid item if ($response_correct !== '0' && $response_correct !== '1') { var_dump('invalid response'); } return $response_correct; }
public function __construct($mc_option_id, $ab_test_id) { parent::__construct($mc_option_id); if ($ab_test_id === false) { return false; } $this->get_ab_test_mc_option_results($ab_test_id); }
<?php // set-up the mc option $mc_option = new Enp_quiz_MC_option($mc_option_id); ?> <li id="enp-mc-option--<?php echo $mc_option_id; ?> " class="enp-mc-option enp-mc-option--inputs<?php echo (int) $mc_option->get_mc_option_correct() === 1 ? ' enp-mc-option--correct' : ''; ?> "> <label for="enp-mc-option__<?php echo $question_i . '__' . $mc_option_i; ?> " class="enp-screen-reader-text">Multiple Choice Option</label> <input class="enp-mc-option-id" type="hidden" name="enp_question[<?php echo $question_i; ?> ][mc_option][<?php echo $mc_option_i; ?> ][mc_option_id]" value="<?php echo $mc_option_id; ?> " /> <input id="enp-mc-option__<?php echo $question_i . '__' . $mc_option_i; ?> " type="text" class="enp-input enp-mc-option__input" name="enp_question[<?php
/** * Get the built question with all MC Option / Slider data for taking quizzes * * @param $question = question object * @return array with full question data for taking quizzes or converting to JSON */ public function get_take_question_array() { // cast object to array $question_array = (array) $this; // remove what we don't need unset($question_array['quiz_id']); unset($question_array['mc_options']); // get question type $question_type = $this->get_question_type(); // get question images info $question_array['question_image_src'] = $this->get_question_image_src(); $question_array['question_image_srcset'] = $this->get_question_image_srcset(); // if mc, get mc options if ($question_type === 'mc') { // get the mc options $mc_option_ids = $this->get_mc_options(); // create a mc_options_array $question_array['mc_option'] = array(); // create the MC Options foreach ($mc_option_ids as $mc_option_id) { // build mc option object $mc_option = new Enp_quiz_MC_option($mc_option_id); // cast object to array in question_array $mc_option_array = $mc_option->get_take_mc_option_array(); $question_array['mc_option'][] = $mc_option_array; } } elseif ($question_type === 'slider') { $slider_id = $this->get_slider(); $slider = new Enp_quiz_Slider($slider_id); $question_array['slider'] = (array) $slider; } return $question_array; }