function the_quiz($args = NULL) { $defaults = array('quiz_id' => get_the_ID(), 'ques_id' => ''); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $user_id = get_current_user_id(); $questions = vibe_sanitize(get_post_meta($quiz_id, 'quiz_questions' . $user_id, false)); if (!isset($questions) || !is_array($questions)) { // Fallback for Older versions $questions = vibe_sanitize(get_post_meta($quiz_id, 'vibe_quiz_questions', false)); } if (isset($questions['ques']) && is_array($questions['ques'])) { $key = array_search($ques_id, $questions['ques']); } if ($ques_id) { $the_query = new WP_Query(array('post_type' => 'question', 'p' => $ques_id)); while ($the_query->have_posts()) { $the_query->the_post(); the_question(); echo '<div class="quiz_bar">'; if ($key == 0) { // FIRST QUESTION if ($key != count($questions['ques']) - 1) { // First But not the Last echo '<a href="#" class="ques_link right quiz_question nextq" data-quiz="' . $quiz_id . '" data-qid="' . $questions['ques'][$key + 1] . '">' . __('Next Question', 'vibe') . ' ›</a>'; } } elseif ($key == count($questions['ques']) - 1) { // LAST QUESTION echo '<a href="#" class="ques_link left quiz_question prevq" data-quiz="' . $quiz_id . '" data-qid="' . $questions['ques'][$key - 1] . '">‹ ' . __('Previous Question', 'vibe') . '</a>'; echo '<a href="#" class="ques_link right quiz_question" data-quiz="' . $quiz_id . '" data-qid="' . $questions['ques'][$key + 1] . '">' . __('Save Answer', 'vibe') . ' ›</a>'; } elseif ($key == count($questions['ques']) - 1) { // Mark For Reveiw echo '<a href="#" class="ques_link right quiz_question mark" data-quiz="' . $quiz_id . '" data-qid="' . $questions['ques'][$key] . '">' . __(' Mark For Review ', 'vibe') . ' ›</a>'; } else { echo '<a href="#" class="ques_link left quiz_question prevq" data-quiz="' . $quiz_id . '" data-qid="' . $questions['ques'][$key - 1] . '">‹ ' . __('Previous Question', 'vibe') . '</a>'; echo '<a href="#" class="ques_link right quiz_question nextq" data-quiz="' . $quiz_id . '" data-qid="' . $questions['ques'][$key + 1] . '">' . __('Next Question', 'vibe') . ' ›</a>'; } echo '<a href="#" class="ques_link right quiz_question mark" data-quiz="' . $quiz_id . '" data-qid="' . $questions['ques'][$key] . '">' . __(' Mark For Review ', 'vibe') . ' ›</a>'; echo '</div>'; } wp_reset_postdata(); } else { $quiz_taken = get_user_meta($user_id, $quiz_id, true); if (isset($quiz_taken) && $quiz_taken && $quiz_taken < time()) { $message = get_post_meta($quiz_id, 'vibe_quiz_message', true); $total_markes = get_post_meta($quiz_id, $user_id, true); $ques_count = get_post_meta($quiz_id, 'vibe_quiz_questions', false); $tques_count = count($ques_count[0]['ques']); // print_r($ques_count); $markes_count = array_sum($ques_count[0]['marks']); //$mark_per = ((100*$total_markes)/$markes_count); $mark_per = $total_markes; // $msg = get_option('wplms'); $msg = $message; $val_count = count($msg) / 3; for ($k = 0; $k < $val_count; $k++) { $i = $k * 3; if ($mark_per >= $msg[$i] && $mark_per <= $msg[$i + 1]) { $message = $msg[$i + 2]; break; } } //print_r($msg['Image']); echo '<div class="main_content">'; echo html_entity_decode($message); echo '</div>'; } else { echo '<div class="main_content">'; the_content(); echo '</div>'; } } }
<div class="share"> <?php if (function_exists('sharing_display')) { echo sharing_display(); // Jetpack Integration } ?> </div> </div> </div> <div class="row"> <div class="col-md-8 col-md-offset-2"> <div class="content"> <div class="main_content"> <?php the_question(); ?> </div> <?php do_action('wplms_question_after_content'); ?> </div> <?php } } do_action('wplms_front_end_question_controls'); ?> </div> </div> </div> </section>
function the_quiz($args = null) { $defaults = array('quiz_id' => get_the_ID(), 'ques_id' => ''); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $user_id = get_current_user_id(); $questions = get_post_meta($quiz_id, '_lpr_quiz_questions' . $user_id, false); if (!isset($questions) || !is_array($questions)) { $questions = get_post_meta($quiz_id, '_lpr_quiz_questions', false); } if (isset($questions['ques']) && is_array($questions['ques'])) { $key = array_search($ques_id, $questions['ques']); } if ($ques_id) { $the_query = new WP_Query(array('post_type' => 'question', 'p' => $ques_id)); while ($the_query->have_posts()) { $the_query->the_post(); the_question(); echo '<div class="quiz_bar">'; if ($key == 0) { // FIRST QUESTION if ($key != count($questions['ques']) - 1) { echo '<a href="#" class="ques_link right quiz_question nextq" data-quiz="' . $quiz_id . '" data-qid="' . $questions['ques'][$key + 1] . '">' . __('Next Question', 'learn_press') . ' ›</a>'; } } elseif ($key == count($questions['ques']) - 1) { // LAST QUESTION echo '<a href="#" class="ques_link left quiz_question prevq" data-quiz="' . $quiz_id . '" data-qid="' . $questions['ques'][$key - 1] . '">‹ ' . __('Previous Question', 'learn_press') . '</a>'; } else { echo '<a href="#" class="ques_link left quiz_question prevq" data-quiz="' . $quiz_id . '" data-qid="' . $questions['ques'][$key - 1] . '">‹ ' . __('Previous Question', 'learn_press') . '</a>'; echo '<a href="#" class="ques_link right quiz_question nextq" data-quiz="' . $quiz_id . '" data-qid="' . $questions['ques'][$key + 1] . '">' . __('Next Question', 'learn_press') . ' ›</a>'; } echo '</div>'; } wp_reset_postdata(); } else { $quiz_taken = get_user_meta($user_id, $quiz_id, true); if (isset($quiz_taken) && $quiz_taken && $quiz_taken < current_time('timestamp')) { $message = get_post_meta($quiz_id, '_lpr_quiz_message', true); echo '<div class="main_content">'; echo $message; echo '</div>'; } else { echo '<div class="main_content">'; the_content(); echo '</div>'; } } }
function preview_sub_element() { $question_id = $_POST['id']; if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'security') || !current_user_can('edit_posts') || !is_numeric($_POST['id'])) { _e('Security check Failed. Contact Administrator.', 'wplms-front-end'); die; } ?> <?php $post_type = get_post_type($question_id); $flag = apply_filters('wplms_front_end_get_question', 1, $question_id); // For future purpose if ($flag) { ?> <div class="question_display" id="<?php echo $question_id; ?> "> <?php $args = apply_filters('preview_question_element', array('p' => $question_id, 'post_type' => $post_type)); $the_query = new WP_Query($args); if ($the_query->have_posts()) { while ($the_query->have_posts()) { $the_query->the_post(); global $post; the_question(); } } wp_reset_postdata(); $buttons = array(array('label' => __('FULL PREVIEW & STATS', 'vibe'), 'id' => 'preview_element_button', 'href' => get_permalink($question_id), 'type' => 'small_button'), array('label' => __('Close', 'vibe'), 'id' => 'close_element_button', 'type' => 'small_button')); foreach ($buttons as $button) { WPLMS_Front_End_Fields::generate_fields($button, $question_id); } ?> </div> <?php } die; }