body.php
5 years ago
content.php
5 years ago
no_course_belongs.php
5 years ago
previous-attempts.php
5 years ago
single_quiz_contents.php
5 years ago
top.php
5 years ago
body.php
455 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package TutorLMS/Templates |
| 4 | * @version 1.5.7 |
| 5 | */ |
| 6 | |
| 7 | |
| 8 | global $post; |
| 9 | $currentPost = $post; |
| 10 | |
| 11 | $quiz_id = get_the_ID(); |
| 12 | $is_started_quiz = tutor_utils()->is_started_quiz(); |
| 13 | |
| 14 | $previous_attempts = tutor_utils()->quiz_attempts(); |
| 15 | $attempted_count = is_array($previous_attempts) ? count($previous_attempts) : 0; |
| 16 | $questions_order = tutor_utils()->get_quiz_option($quiz_id, 'questions_order', 'rand'); |
| 17 | $attempts_allowed = tutor_utils()->get_quiz_option($quiz_id, 'attempts_allowed', 0); |
| 18 | $passing_grade = tutor_utils()->get_quiz_option($quiz_id, 'passing_grade', 0); |
| 19 | $feedback_mode = tutor_utils()->get_quiz_option($quiz_id, 'feedback_mode', 0); |
| 20 | |
| 21 | $attempt_remaining = $attempts_allowed - $attempted_count; |
| 22 | ?> |
| 23 | |
| 24 | <div id="tutor-quiz-body" class="tutor-quiz-body tutor-quiz-body-<?php the_ID(); ?>"> |
| 25 | <?php |
| 26 | |
| 27 | do_action('tutor_quiz/body/before', $quiz_id); |
| 28 | |
| 29 | if ($is_started_quiz){ |
| 30 | $quiz_attempt_info = tutor_utils()->quiz_attempt_info($is_started_quiz->attempt_info); |
| 31 | $quiz_attempt_info['date_time_now'] = date("Y-m-d H:i:s", tutor_time()); |
| 32 | |
| 33 | $time_limit_seconds = tutor_utils()->avalue_dot('time_limit.time_limit_seconds', $quiz_attempt_info); |
| 34 | $question_layout_view = tutor_utils()->avalue_dot('question_layout_view', $quiz_attempt_info); |
| 35 | |
| 36 | $hide_quiz_time_display = (bool) tutor_utils()->avalue_dot('hide_quiz_time_display', $quiz_attempt_info); |
| 37 | $hide_question_number_overview = (bool) tutor_utils()->avalue_dot('hide_question_number_overview', $quiz_attempt_info); |
| 38 | |
| 39 | $remaining_time_secs = (strtotime($is_started_quiz->attempt_started_at) + $time_limit_seconds ) - strtotime($quiz_attempt_info['date_time_now']); |
| 40 | |
| 41 | $remaining_time_context = tutor_utils()->seconds_to_time_context($remaining_time_secs); |
| 42 | $questions = tutor_utils()->get_random_questions_by_quiz(); |
| 43 | ?> |
| 44 | |
| 45 | <div class="quiz-head-meta-info"> |
| 46 | <?php |
| 47 | if ( ! $hide_quiz_time_display){ |
| 48 | ?> |
| 49 | <div class="time-remaining"> |
| 50 | <?php _e('Time remaining : '); ?> <span id="tutor-quiz-time-update" data-attempt-settings="<?php echo esc_attr(json_encode($is_started_quiz)) ?>" data-attempt-meta="<?php echo esc_attr(json_encode($quiz_attempt_info)) ?>"><?php echo $remaining_time_context; ?></span> |
| 51 | </div> |
| 52 | <?php } ?> |
| 53 | </div> |
| 54 | |
| 55 | <?php |
| 56 | if (is_array($questions) && count($questions)) { |
| 57 | ?> |
| 58 | <div id="tutor-quiz-attempt-questions-wrap" data-question-layout-view="<?php echo $question_layout_view; ?>"> |
| 59 | |
| 60 | <?php |
| 61 | if ($question_layout_view === 'question_pagination'){ |
| 62 | $question_i = 0; |
| 63 | ?> |
| 64 | <div class="tutor-quiz-questions-pagination"> |
| 65 | <ul> |
| 66 | <?php |
| 67 | foreach ($questions as $question) { |
| 68 | $question_i++; |
| 69 | echo "<li><a href='#quiz-attempt-single-question-{$question->question_id}' class='tutor-quiz-question-paginate-item'>{$question_i}</a> </li>"; |
| 70 | } |
| 71 | ?> |
| 72 | </ul> |
| 73 | </div> |
| 74 | <?php |
| 75 | } |
| 76 | ?> |
| 77 | |
| 78 | <form id="tutor-answering-quiz" method="post"> |
| 79 | <?php wp_nonce_field( tutor()->nonce_action, tutor()->nonce ); ?> |
| 80 | <input type="hidden" value="<?php echo $is_started_quiz->attempt_id; ?>" name="attempt_id"/> |
| 81 | <input type="hidden" value="tutor_answering_quiz_question" name="tutor_action"/> |
| 82 | <?php |
| 83 | $question_i = 0; |
| 84 | foreach ($questions as $question) { |
| 85 | $question_i++; |
| 86 | $question_settings = maybe_unserialize($question->question_settings); |
| 87 | |
| 88 | $style_display = ($question_layout_view !== 'question_below_each_other' && $question_i == 1) ? 'block' : 'none'; |
| 89 | if ($question_layout_view === 'question_below_each_other'){ |
| 90 | $style_display = 'block'; |
| 91 | } |
| 92 | |
| 93 | $next_question = isset($questions[$question_i]) ? $questions[$question_i] : false; |
| 94 | ?> |
| 95 | <div id="quiz-attempt-single-question-<?php echo $question->question_id; ?>" class="quiz-attempt-single-question quiz-attempt-single-question-<?php echo $question_i; ?>" style="display: <?php echo $style_display; ?> ;" <?php echo $next_question ? "data-next-question-id='#quiz-attempt-single-question-{$next_question->question_id}'" : '' ; ?> data-quiz-feedback-mode="<?php echo $feedback_mode; ?>" > |
| 96 | |
| 97 | <?php echo "<input type='hidden' name='attempt[{$is_started_quiz->attempt_id}][quiz_question_ids][]' value='{$question->question_id}' />"; |
| 98 | |
| 99 | |
| 100 | $question_type = $question->question_type; |
| 101 | |
| 102 | $rand_choice = false; |
| 103 | if($question_type == 'single_choice' || $question_type == 'multiple_choice'){ |
| 104 | $choice = maybe_unserialize($question->question_settings); |
| 105 | if(isset($choice['randomize_question'])){ |
| 106 | $rand_choice = $choice['randomize_question'] == 1 ? true : false; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | $answers = tutor_utils()->get_answers_by_quiz_question($question->question_id, $rand_choice); |
| 111 | $show_question_mark = (bool) tutor_utils()->avalue_dot('show_question_mark', $question_settings); |
| 112 | $answer_required = (bool) tutils()->array_get('answer_required', $question_settings); |
| 113 | |
| 114 | echo '<h4 class="question-text">'; |
| 115 | if ( ! $hide_question_number_overview){ |
| 116 | echo $question_i. ". "; |
| 117 | } |
| 118 | echo stripslashes($question->question_title); |
| 119 | echo '</h4>'; |
| 120 | |
| 121 | if ($show_question_mark){ |
| 122 | echo '<p class="question-marks"> '.__('Marks : ', 'tutor').$question->question_mark.' </p>'; |
| 123 | } |
| 124 | |
| 125 | $question_description = stripslashes($question->question_description); |
| 126 | if ($question_description){ |
| 127 | echo "<p class='question-description'>{$question_description}</p>"; |
| 128 | } |
| 129 | ?> |
| 130 | |
| 131 | <div class="tutor-quiz-answers-wrap question-type-<?php echo $question_type; ?> <?php echo $answer_required? 'quiz-answer-required':''; ?> "> |
| 132 | <?php |
| 133 | if ( is_array($answers) && count($answers) ) { |
| 134 | foreach ($answers as $answer){ |
| 135 | $answer_title = stripslashes($answer->answer_title); |
| 136 | |
| 137 | if ( $question_type === 'true_false' || $question_type === 'single_choice' ) { |
| 138 | ?> |
| 139 | <label class="answer-view-<?php echo $answer->answer_view_format; ?>"> |
| 140 | <div class="quiz-answer-input-body"> |
| 141 | <?php |
| 142 | if ($answer->answer_view_format === 'image' || $answer->answer_view_format === 'text_image'){ |
| 143 | ?> |
| 144 | <div class="quiz-answer-image-wrap"> |
| 145 | <img src="<?php echo wp_get_attachment_image_url($answer->image_id, 'full') ?>" /> |
| 146 | </div> |
| 147 | <?php |
| 148 | } |
| 149 | ?> |
| 150 | <div class="quiz-answer-input-bottom"> |
| 151 | <div class="quiz-answer-input-field"> |
| 152 | <input name="attempt[<?php echo $is_started_quiz->attempt_id; ?>][quiz_question][<?php echo $question->question_id; ?>]" type="radio" value="<?php echo $answer->answer_id; ?>" data-is-correct="<?php echo $answer->is_correct ?>" > |
| 153 | <span> </span> |
| 154 | <?php |
| 155 | if ($answer->answer_view_format !== 'image'){ echo $answer_title;} |
| 156 | ?> |
| 157 | </div> |
| 158 | </div> |
| 159 | </div> |
| 160 | </label> |
| 161 | <?php |
| 162 | }elseif ($question_type === 'multiple_choice'){ |
| 163 | ?> |
| 164 | <label class="answer-view-<?php echo $answer->answer_view_format; ?>"> |
| 165 | |
| 166 | |
| 167 | <div class="quiz-answer-input-body"> |
| 168 | <?php if ($answer->answer_view_format === 'image' || $answer->answer_view_format === 'text_image'){ ?> |
| 169 | <div class="quiz-answer-image-wrap"> |
| 170 | <img src="<?php echo wp_get_attachment_image_url($answer->image_id, 'full') ?>" /> |
| 171 | </div> |
| 172 | <?php } ?> |
| 173 | |
| 174 | <div class="quiz-answer-input-bottom"> |
| 175 | <div class="quiz-answer-input-field"> |
| 176 | <input name="attempt[<?php echo $is_started_quiz->attempt_id; ?>][quiz_question][<?php echo $question->question_id; ?>][]" type="checkbox" data-is-correct="<?php echo $answer->is_correct ?>" value="<?php echo $answer->answer_id; ?>"> |
| 177 | <span> </span> |
| 178 | <?php if ($answer->answer_view_format !== 'image'){ |
| 179 | echo $answer_title; |
| 180 | } ?> |
| 181 | </div> |
| 182 | </div> |
| 183 | </div> |
| 184 | </label> |
| 185 | <?php |
| 186 | } |
| 187 | elseif ($question_type === 'fill_in_the_blank'){ |
| 188 | ?> |
| 189 | <p class="fill-in-the-blank-field"> |
| 190 | <?php |
| 191 | $count_dash_fields = substr_count($answer_title, '{dash}'); |
| 192 | if ($count_dash_fields){ |
| 193 | |
| 194 | $dash_string = array(); |
| 195 | $input_data = array(); |
| 196 | for($i=1; $i <=$count_dash_fields; $i ++){ |
| 197 | $dash_string[] = '{dash}'; |
| 198 | $input_data[] = "<input type='text' name='attempt[{$is_started_quiz->attempt_id}][quiz_question][{$question->question_id}][]' class='fill-in-the-blank-text-input' />"; |
| 199 | } |
| 200 | echo str_replace($dash_string, $input_data, $answer_title); |
| 201 | } |
| 202 | ?> |
| 203 | </p> |
| 204 | <?php |
| 205 | } |
| 206 | elseif ($question_type === 'ordering'){ |
| 207 | ?> |
| 208 | <div class="question-type-ordering-item"> |
| 209 | <div class="answer-title"> |
| 210 | <?php |
| 211 | if ($answer->answer_view_format !== 'image'){ |
| 212 | echo "<p class='tutor-quiz-answer-title'>{$answer_title}</p>"; |
| 213 | } |
| 214 | if ($answer->answer_view_format === 'image' || $answer->answer_view_format === 'text_image'){ |
| 215 | ?> |
| 216 | <div class="quiz-answer-image-wrap"> |
| 217 | <img src="<?php echo wp_get_attachment_image_url($answer->image_id, 'full') ?>" /> |
| 218 | </div> |
| 219 | <?php |
| 220 | } |
| 221 | ?> |
| 222 | </div> |
| 223 | <span class="answer-sorting-bar"><i class="tutor-icon-menu-2"></i> </span> |
| 224 | <input type="hidden" name="attempt[<?php echo $is_started_quiz->attempt_id; ?>][quiz_question][<?php echo $question->question_id; ?>][answers][]" value="<?php echo $answer->answer_id; ?>" > |
| 225 | </div> |
| 226 | <?php |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Question type matchind and image matching |
| 232 | */ |
| 233 | if ($question_type === 'matching' || $question_type === 'image_matching'){ |
| 234 | ?> |
| 235 | <div class="quiz-answers-type-matching-wrap <?php echo 'answer-type-'.$question_type ?> "> |
| 236 | <div class="quiz-draggable-rand-answers"> |
| 237 | <?php |
| 238 | $rand_answers = tutor_utils()->get_answers_by_quiz_question($question->question_id, true); |
| 239 | foreach ($rand_answers as $rand_answer){ |
| 240 | ?> |
| 241 | <div class="quiz-draggable-answer-item"> |
| 242 | <?php |
| 243 | if ($question_type === 'matching'){ |
| 244 | echo "<span class='draggable-answer-title'>{$rand_answer->answer_two_gap_match}</span>"; |
| 245 | }else{ |
| 246 | echo "<span class='draggable-answer-title'>{$rand_answer->answer_title}</span>"; |
| 247 | } |
| 248 | ?> |
| 249 | <span class="draggable-answer-icon"> <i class="tutor-icon-menu-2"></i> </span> |
| 250 | <input type="hidden" name="attempt[<?php echo $is_started_quiz->attempt_id; ?>][quiz_question][<?php echo $question->question_id; ?>][answers][]" value="<?php echo $rand_answer->answer_id; ?>" > |
| 251 | </div> |
| 252 | <?php |
| 253 | } |
| 254 | ?> |
| 255 | </div> |
| 256 | |
| 257 | <div class="quiz-answer-matching-items-wrap"> |
| 258 | <?php |
| 259 | foreach ($answers as $answer){ |
| 260 | ?> |
| 261 | <div class="quiz-answer-item-matching"> |
| 262 | <div class="quiz-answer-matching-title"> |
| 263 | <?php |
| 264 | if ($question_type === 'matching') { |
| 265 | |
| 266 | if ($answer->answer_view_format !== 'image'){ |
| 267 | echo "<p class='tutor-quiz-answer-title'>{$answer->answer_title}</p>"; |
| 268 | } |
| 269 | if ($answer->answer_view_format === 'image' || $answer->answer_view_format === 'text_image'){ |
| 270 | ?> |
| 271 | <div class="quiz-answer-image-wrap"> |
| 272 | <img src="<?php echo wp_get_attachment_image_url($answer->image_id, 'full') ?>" /> |
| 273 | </div> |
| 274 | <?php |
| 275 | } |
| 276 | }elseif (intval($answer->image_id)){ |
| 277 | echo '<img src="'.wp_get_attachment_image_url($answer->image_id, 'full').'" />'; |
| 278 | } |
| 279 | ?> |
| 280 | </div> |
| 281 | <div class="quiz-answer-matching-droppable"></div> |
| 282 | </div> |
| 283 | <?php |
| 284 | } |
| 285 | ?> |
| 286 | |
| 287 | </div> |
| 288 | </div> |
| 289 | <?php |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * For Open Ended Question Type |
| 295 | */ |
| 296 | if ($question_type === 'open_ended' || $question_type === 'short_answer'){ |
| 297 | ?> |
| 298 | <textarea class="question_type_<?php echo $question_type; ?>" name="attempt[<?php echo |
| 299 | $is_started_quiz->attempt_id; ?>][quiz_question][<?php echo $question->question_id; ?>]"></textarea> |
| 300 | <?php |
| 301 | if ($question_type === 'short_answer') { |
| 302 | $get_option_meta = tutor_utils()->get_quiz_option($quiz_id); |
| 303 | if(isset($get_option_meta['short_answer_characters_limit'])){ |
| 304 | if($get_option_meta['short_answer_characters_limit'] != "" ){ |
| 305 | $characters_limit = tutor_utils()->avalue_dot('short_answer_characters_limit', $quiz_attempt_info); |
| 306 | echo '<p class="answer_limit_desc">'. __('characters remaining', 'tutor' ) .' :<span class="characters_remaining">'.$characters_limit.'</span> </p>'; |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | if ($question_type === 'open_ended') { |
| 311 | $get_option_meta = tutor_utils()->get_quiz_option($quiz_id); |
| 312 | if(isset($get_option_meta['open_ended_answer_characters_limit'])){ |
| 313 | if($get_option_meta['open_ended_answer_characters_limit'] != "" ){ |
| 314 | $characters_limit = $get_option_meta['open_ended_answer_characters_limit']; |
| 315 | echo '<p class="answer_limit_desc">'. __('characters remaining', 'tutor' ) .' :<span class="characters_remaining">'.$characters_limit.'</span> </p>'; |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | |
| 322 | if ($question_type === 'image_answering'){ |
| 323 | ?> |
| 324 | <div class="quiz-image-answering-wrap"> |
| 325 | <?php |
| 326 | foreach ($answers as $answer){ |
| 327 | ?> |
| 328 | <div class="quiz-image-answering-answer"> |
| 329 | <?php |
| 330 | if (intval($answer->image_id)){ |
| 331 | ?> |
| 332 | <div class="quiz-image-answering-image-wrap"> |
| 333 | <?php echo '<img src="'.wp_get_attachment_image_url($answer->image_id, 'full').'" />'; ?> |
| 334 | </div> |
| 335 | |
| 336 | <div class="quiz-image-answering-input-field-wrap"> |
| 337 | <input type="text" name="attempt[<?php echo $is_started_quiz->attempt_id; ?>][quiz_question][<?php echo $question->question_id; ?>][answer_id][<?php echo $answer->answer_id; ?>]" > |
| 338 | </div> |
| 339 | <?php |
| 340 | } |
| 341 | ?> |
| 342 | </div> |
| 343 | <?php |
| 344 | } |
| 345 | ?> |
| 346 | </div> |
| 347 | <?php |
| 348 | } |
| 349 | ?> |
| 350 | |
| 351 | <div class="answer-help-block"></div> |
| 352 | |
| 353 | </div> |
| 354 | |
| 355 | <?php |
| 356 | if ($question_layout_view !== 'question_below_each_other'){ |
| 357 | if ($next_question){ |
| 358 | ?> |
| 359 | <div class="quiz-answer-footer-bar"> |
| 360 | <div class="quiz-footer-button"> |
| 361 | <button type="button" value="quiz_answer_submit" class="tutor-button |
| 362 | tutor-success tutor-quiz-answer-next-btn"><?php _e( 'Answer & Next Question', 'tutor' ); ?></button> |
| 363 | </div> |
| 364 | </div> |
| 365 | <?php |
| 366 | }else{ |
| 367 | ?> |
| 368 | <div class="quiz-answer-footer-bar"> |
| 369 | <div class="quiz-footer-button"> |
| 370 | <button type="submit" name="quiz_answer_submit_btn" value="quiz_answer_submit" class="tutor-button tutor-success"><?php |
| 371 | _e( 'Submit Quiz', 'tutor' ); ?></button> |
| 372 | </div> |
| 373 | </div> |
| 374 | <?php |
| 375 | } |
| 376 | } |
| 377 | ?> |
| 378 | </div> |
| 379 | |
| 380 | <?php |
| 381 | } |
| 382 | |
| 383 | if ($question_layout_view === 'question_below_each_other'){ |
| 384 | ?> |
| 385 | <div class="quiz-answer-footer-bar"> |
| 386 | <div class="quiz-footer-button"> |
| 387 | <button type="submit" name="quiz_answer_submit_btn" value="quiz_answer_submit" class="tutor-button |
| 388 | tutor-success"><?php _e( 'Submit Quiz', 'tutor' ); ?></button> |
| 389 | </div> |
| 390 | </div> |
| 391 | <?php } ?> |
| 392 | |
| 393 | </form> |
| 394 | </div> |
| 395 | |
| 396 | <?php |
| 397 | |
| 398 | }else{ |
| 399 | ?> |
| 400 | <div class="start-quiz-wrap"> |
| 401 | <form id="tutor-finish-quiz" method="post"> |
| 402 | <?php wp_nonce_field( tutor()->nonce_action, tutor()->nonce ); ?> |
| 403 | |
| 404 | <input type="hidden" value="<?php echo $quiz_id; ?>" name="quiz_id"/> |
| 405 | <input type="hidden" value="tutor_finish_quiz_attempt" name="tutor_action"/> |
| 406 | |
| 407 | <button type="submit" class="tutor-button" name="finish_quiz_btn" value="finish_quiz"> |
| 408 | <i class="icon-floppy"></i> <?php _e( 'Finish', 'tutor' ); ?> |
| 409 | </button> |
| 410 | </form> |
| 411 | </div> |
| 412 | |
| 413 | <?php |
| 414 | } |
| 415 | }else{ |
| 416 | if ($attempt_remaining > 0 || $attempts_allowed == 0) { |
| 417 | do_action('tuotr_quiz/start_form/before', $quiz_id); |
| 418 | ?> |
| 419 | <div class="start-quiz-wrap"> |
| 420 | <form id="tutor-start-quiz" method="post"> |
| 421 | <?php wp_nonce_field( tutor()->nonce_action, tutor()->nonce ); ?> |
| 422 | |
| 423 | <input type="hidden" value="<?php echo $quiz_id; ?>" name="quiz_id"/> |
| 424 | <input type="hidden" value="tutor_start_quiz" name="tutor_action"/> |
| 425 | |
| 426 | <button type="submit" class="tutor-button" name="start_quiz_btn" value="start_quiz"> |
| 427 | <i class="icon-hourglass-1"></i> <?php _e( 'Start Quiz', 'tutor' ); ?> |
| 428 | </button> |
| 429 | </form> |
| 430 | </div> |
| 431 | |
| 432 | <?php |
| 433 | do_action('tuotr_quiz/start_form/after', $quiz_id); |
| 434 | } |
| 435 | |
| 436 | |
| 437 | |
| 438 | if ($previous_attempts){ |
| 439 | do_action('tutor_quiz/previous_attempts_html/before', $previous_attempts, $quiz_id); |
| 440 | |
| 441 | ob_start(); |
| 442 | tutor_load_template('single.quiz.previous-attempts', compact('previous_attempts', 'quiz_id')); |
| 443 | $previous_attempts_html = ob_get_clean(); |
| 444 | echo apply_filters('tutor_quiz/previous_attempts_html', $previous_attempts_html, $previous_attempts, $quiz_id); |
| 445 | |
| 446 | do_action('tutor_quiz/previous_attempts/after', $previous_attempts, $quiz_id); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | |
| 451 | tutor_next_previous_pagination(); |
| 452 | |
| 453 | do_action('tutor_quiz/body/after', $quiz_id); |
| 454 | ?> |
| 455 | </div> |