protected function _settings() { $current_question_id = learn_press_get_current_question(); // !empty( $_REQUEST['question_id'] ) ? intval( $_REQUEST['question_id'] ) : 0; $questions = learn_press_get_quiz_questions(); if ($questions) { $question_ids = array_keys($questions); } else { $question_ids = array(); } if (!$current_question_id || !in_array($current_question_id, $question_ids)) { $current_question_id = reset($question_ids); } $question = LP_Question_Factory::get_question($current_question_id); $user_id = get_current_user_id(); $user = learn_press_get_current_user(); $js = array('time_format' => $this->duration > 300 ? 'h%:m%:s%' : 'm%:s%', 'total_time' => $this->duration, 'id' => $this->id, 'questions' => $question_ids, 'question_id' => absint($current_question_id), 'status' => $user->get_quiz_status($this->id), 'time_remaining' => ($time_remaining = $user->get_quiz_time_remaining($this->id)) !== false && !in_array($user->get_quiz_status($this->id), array('', 'completed')) ? $time_remaining : $this->duration, 'permalink' => get_the_permalink(), 'ajaxurl' => admin_url('admin-ajax.php'), 'user_id' => $user->id); return apply_filters('learn_press_single_quiz_params', $js, $this); }
function learn_press_get_user_question_url($quiz_id, $current_question_id = 0, $user_id = 0) { if (!$current_question_id) { $current_question_id = learn_press_get_current_question($quiz_id, $user_id); } $permalink = get_the_permalink($quiz_id); $question_name = get_post_field('post_name', $current_question_id); if ('' != get_option('permalink_structure')) { $permalink .= get_post_field('post_name', $current_question_id); } else { $permalink .= (strpos($permalink, '?') === false ? "?" : "&") . "question={$question_name}"; } return $permalink; }
/** * get position of current question is displaying in the quiz for user * * @param null $user_id * @param null $quiz_id * @param null $question_id * * @return int|mixed */ function learn_press_get_question_position($user_id = null, $quiz_id = null, $question_id = null) { $return = array('position' => -1, 'id' => 0); if (!$user_id) { $user_id = get_current_user_id(); } if (!$quiz_id) { global $quiz; $quiz_id = $quiz ? $quiz->ID : 0; } if (!$question_id) { $question_id = learn_press_get_current_question($quiz_id, $user_id); } $pos = -1; if ($user_id && $quiz_id) { /*if ( ! $question_id ) { $current_questions = get_user_meta($user_id, '_lpr_quiz_current_question', true); if ( ! empty ( $current_questions[ $quiz_id ] ) ) { $question_id = $current_questions[ $quiz_id ]; } }*/ $questions = get_user_meta($user_id, '_lpr_quiz_questions', true); if (!empty($questions[$quiz_id])) { $pos = array_search($question_id, $questions[$quiz_id]); $pos = false !== $pos ? $pos : -1; } } $return['position'] = $pos; $return['id'] = $question_id; // added since 0.9.5 $return = apply_filters('learn_press_get_question_position', $return, $user_id, $quiz_id, $question_id); return $return; }
?> <h3><?php echo $title; ?> </h3> <?php } ?> <?php do_action('learn_press_quiz_questions_before_questions_loop'); ?> <ul> <?php $index = 0; $question_loop_template = learn_press_locate_template('quiz/loop.php'); $current_question = learn_press_get_current_question(); $quiz_completed = learn_press_user_has_completed_quiz(); if (!empty($question_list)) { foreach ($question_list as $question_id => $question_options) { $index++; $question_title = get_the_title($question_id); $question = get_post($question_id); if ($current_question && $current_question == $question_id && !$quiz_completed) { $current = true; } else { $current = false; } // include to ensure that sub-template can be load all variables from here require $question_loop_template; } }
function learn_press_get_user_question_url($quiz_id, $current_question_id = 0, $user_id = 0) { if (!$current_question_id) { $current_question_id = learn_press_get_current_question($quiz_id, $user_id); } $permalink = get_the_permalink($quiz_id); if ($current_question_id && get_post_type($current_question_id) == 'lp_question') { $question_name = get_post_field('post_name', $current_question_id); if ('' != get_option('permalink_structure')) { $permalink .= $question_name; } else { $permalink = add_query_arg('question', $question_name, $permalink); } } return apply_filters('learn_press_quiz_question_url', $permalink, $quiz_id, $current_question_id, $user_id); }
/** * Output js script configuration for single quiz page */ function learn_press_print_quiz_question_content_script() { $current_question_id = learn_press_get_current_question(); // !empty( $_REQUEST['question_id'] ) ? intval( $_REQUEST['question_id'] ) : 0; $questions = learn_press_get_quiz_questions(); if ($questions) { $question_ids = array_keys($questions); } else { $question_ids = array(); } if (!$current_question_id || !in_array($current_question_id, $question_ids)) { $current_question_id = reset($question_ids); } $question = LPR_Question_Type::instance($current_question_id); $user_id = get_current_user_id(); global $quiz; if ($quiz && !empty($quiz->id)) { $user = learn_press_get_current_user(); $js = array('id' => $quiz->id, 'questions' => $question_ids, 'status' => $user->get_quiz_status($quiz->id), 'time_remaining' => learn_press_get_quiz_time_remaining($user->id, $quiz->id), 'question_id' => $current_question_id, 'permalink' => get_the_permalink(), 'ajaxurl' => admin_url('admin-ajax.php'), 'user_id' => $user->id); ?> <script type="text/javascript"> jQuery(document).ready(function () { LearnPress.initQuiz(<?php echo json_encode($js); ?> ); }) </script> <?php } }