header-context
3 years ago
attempt-details.php
3 years ago
attempt-table.php
3 years ago
contexts.php
3 years ago
header.php
3 years ago
instructor-feedback.php
4 years ago
attempt-details.php
670 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Attempt details page |
| 4 | * |
| 5 | * @author themeum |
| 6 | * @link https://themeum.com |
| 7 | * @package Tutor\Quiz |
| 8 | * @since 1.0.0 |
| 9 | */ |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ){ |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | use Tutor\Models\QuizModel; |
| 16 | |
| 17 | $enabled_hide_quiz_details = tutor_utils()->get_option( 'hide_quiz_details' ); |
| 18 | if ( ! is_admin() && ! current_user_can( 'tutor_instructor') && true === $enabled_hide_quiz_details ) { |
| 19 | exit; |
| 20 | } |
| 21 | |
| 22 | extract($data); // $user_id, $attempt_id, $attempt_data(nullable), $context(nullable) |
| 23 | |
| 24 | !isset($attempt_data) ? $attempt_data = tutor_utils()->get_attempt($attempt_id) : 0; |
| 25 | !isset($context) ? $context=null : 0; |
| 26 | |
| 27 | if ( ! $attempt_id || ! $attempt_data || $user_id != $attempt_data->user_id ) { |
| 28 | tutor_utils()->tutor_empty_state( __( 'Attempt not found or access permission denied', 'tutor' ) ); |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | if ( isset( $user_id ) && $user_id > 0 ) { |
| 33 | $user = get_userdata( $user_id ); |
| 34 | if ( ! $user ) { |
| 35 | return; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | function tutor_render_answer_list( $answers= array(), $dump_data=false ){ |
| 40 | if(!empty($answers)){ |
| 41 | |
| 42 | echo '<div class="correct-answer-wrap">'; |
| 43 | |
| 44 | $multi_texts = array(); |
| 45 | foreach ($answers as $key => $ans) { |
| 46 | $type = isset($ans->answer_view_format) ? $ans->answer_view_format : 'text_image'; |
| 47 | |
| 48 | if (isset($ans->answer_two_gap_match)) { |
| 49 | echo '<div class="matching-type">'; |
| 50 | } |
| 51 | |
| 52 | switch ($type) { |
| 53 | case 'text_image': |
| 54 | echo '<div class="text-image-type tutor-mb-4">'; |
| 55 | if(isset($ans->image_id)){ |
| 56 | $img_url = wp_get_attachment_image_url($ans->image_id); |
| 57 | if($img_url){ |
| 58 | echo '<span class="image"><img src="'.$img_url.'" /></span>'; |
| 59 | } |
| 60 | } |
| 61 | if(isset($ans->answer_title)) { |
| 62 | echo '<span class="caption">'.stripslashes($ans->answer_title).'</span>'; |
| 63 | } |
| 64 | echo '</div>'; |
| 65 | break; |
| 66 | |
| 67 | case 'text': |
| 68 | $ans_string = '<span class="tutor-fs-7 tutor-fw-medium tutor-color-black">' |
| 69 | .esc_html( $ans->answer_title ). |
| 70 | '</span>'; |
| 71 | |
| 72 | if(isset($ans->answer_title) && !isset($ans->answer_two_gap_match)) { |
| 73 | $multi_texts[$ans->answer_title] = $ans_string; |
| 74 | } else { |
| 75 | echo $ans_string; |
| 76 | } |
| 77 | break; |
| 78 | |
| 79 | case 'image': |
| 80 | echo '<div class="image-type">'; |
| 81 | if(isset($ans->image_id)){ |
| 82 | $img_url = wp_get_attachment_image_url($ans->image_id); |
| 83 | if($img_url){ |
| 84 | echo '<span class="image"><img src="'.$img_url.'" />'.'</span>'; |
| 85 | } |
| 86 | } |
| 87 | echo '</div>'; |
| 88 | break; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | if ( isset( $ans->answer_two_gap_match ) ) { |
| 93 | echo '<div class="image-match">' . stripslashes( $ans->answer_two_gap_match ) . '</div>'; |
| 94 | echo '</div>'; |
| 95 | } |
| 96 | } |
| 97 | echo count( $multi_texts ) ? implode( ', ', wp_unslash( $multi_texts ) ) : ''; |
| 98 | |
| 99 | echo '</div>'; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | function tutor_render_fill_in_the_blank_answer($get_db_answers_by_question, $answer_titles) { |
| 104 | |
| 105 | $spaces = ' '; |
| 106 | |
| 107 | // Loop through the answers |
| 108 | foreach ($get_db_answers_by_question as $db_answer){ |
| 109 | $count_dash_fields = substr_count($db_answer->answer_title, '{dash}'); |
| 110 | |
| 111 | if ($count_dash_fields){ |
| 112 | $dash_string = array(); |
| 113 | $input_data = array(); |
| 114 | for($i=0; $i<$count_dash_fields; $i++){ |
| 115 | $ans_title = (!empty($answer_titles[$i]) && !ctype_space($answer_titles[$i])) ? $answer_titles[$i] : null; |
| 116 | $input_data[] = $ans_title ? "<span class='filled_dash_unser'>{$ans_title}</span>" : $spaces; |
| 117 | } |
| 118 | |
| 119 | $answer_title = $db_answer->answer_title; |
| 120 | |
| 121 | foreach($input_data as $index=>$replace){ |
| 122 | $replace = '<span style="text-decoration:underline;">'.$replace.'</span>'; |
| 123 | $answer_title = preg_replace('/{dash}/i', $replace, $answer_title, 1); |
| 124 | } |
| 125 | echo str_replace('{dash}', "<span class='filled_dash_unser'>{$spaces}</span>", stripslashes($answer_title)); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // Prepare student data |
| 131 | if(!isset($user_data)) { |
| 132 | $user_data = get_userdata( $user_id ); |
| 133 | } |
| 134 | |
| 135 | // Prepare atttempt meta info |
| 136 | extract( QuizModel::get_quiz_attempt_timing( $attempt_data ) ); // $attempt_duration, $attempt_duration_taken; |
| 137 | |
| 138 | // Prepare the correct/incorrect answer count for the first summary table |
| 139 | $answers = QuizModel::get_quiz_answers_by_attempt_id($attempt_id); |
| 140 | $correct = 0; |
| 141 | $incorrect = 0; |
| 142 | if(is_array($answers) && count($answers) > 0) { |
| 143 | foreach ($answers as $answer){ |
| 144 | if ( (bool) isset( $answer->is_correct ) ? $answer->is_correct : '' ) { |
| 145 | $correct++; |
| 146 | } else { |
| 147 | if ($answer->question_type === 'open_ended' || $answer->question_type === 'short_answer'){ |
| 148 | } else { |
| 149 | $incorrect++; |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // Prepare the column list for the first summary table |
| 156 | $page_key ='attempt-details-summary'; |
| 157 | $table_1_columns = include __DIR__ . '/contexts.php'; |
| 158 | |
| 159 | // Prepare the column list for the second table (eery single answer list) |
| 160 | $page_key = 'attempt-details-answers'; |
| 161 | $table_2_columns = include __DIR__ . '/contexts.php'; |
| 162 | |
| 163 | include __DIR__ . '/header.php'; |
| 164 | |
| 165 | $attempt_info = @unserialize( $attempt_data->attempt_info ); |
| 166 | |
| 167 | if ( is_array( $attempt_info ) ) { |
| 168 | $attempt_type = ''; |
| 169 | // Allowed duration |
| 170 | if ( isset( $attempt_info['time_limit'] ) ) { |
| 171 | $attempt_duration = tutor_utils()->second_to_formated_time( $attempt_info['time_limit']['time_limit_seconds'], $attempt_info['time_limit']['time_type'] ); |
| 172 | } |
| 173 | if ( 'days' == $attempt_info['time_limit']['time_type'] ) { |
| 174 | $attempt_type = 'hours'; |
| 175 | } |
| 176 | if ( 'hours' == $attempt_info['time_limit']['time_type'] ) { |
| 177 | $attempt_type = 'minutes'; |
| 178 | } |
| 179 | if ( 'minutes' == $attempt_info['time_limit']['time_type'] ) { |
| 180 | $attempt_type = 'minutes'; |
| 181 | } |
| 182 | |
| 183 | // Taken duration |
| 184 | $seconds = strtotime( $attempt_data->attempt_ended_at ) - strtotime( $attempt_data->attempt_started_at ); |
| 185 | $attempt_duration_taken = tutor_utils()->second_to_formated_time( $seconds, $attempt_type ); |
| 186 | } |
| 187 | ?> |
| 188 | |
| 189 | <?php echo is_admin() ? '<div class="tutor-admin-body">' : ''; ?> |
| 190 | <div class="tutor-table-responsive tutor-mb-32"> |
| 191 | <table class="tutor-table my-quiz-attempts"> |
| 192 | <thead> |
| 193 | <tr> |
| 194 | <?php foreach($table_1_columns as $key => $column) : ?> |
| 195 | <th><?php echo $column; ?></th> |
| 196 | <?php endforeach; ?> |
| 197 | </tr> |
| 198 | </thead> |
| 199 | |
| 200 | <tbody> |
| 201 | <tr> |
| 202 | <?php foreach( $table_1_columns as $key => $column ) : ?> |
| 203 | <td> |
| 204 | <?php if ( $key == 'user' ) : ?> |
| 205 | <div class="tutor-d-flex tutor-align-center"> |
| 206 | <?php echo tutor_utils()->get_tutor_avatar( $user_id ); ?> |
| 207 | <div class="tutor-ml-16"> |
| 208 | <div> |
| 209 | <?php echo $user_data ? $user_data->display_name : ''; ?> |
| 210 | </div> |
| 211 | <a href="<?php echo esc_url( tutor_utils()->profile_url($user_id, false) ) ?>" class="tutor-iconic-btn"> |
| 212 | <span class="tutor-icon-external-link"></span> |
| 213 | </a> |
| 214 | </div> |
| 215 | </div> |
| 216 | |
| 217 | <?php elseif ( $key == 'date' ) : ?> |
| 218 | <div> |
| 219 | <?php echo date_i18n(get_option('date_format'), strtotime($attempt_data->attempt_started_at)); ?> |
| 220 | </div> |
| 221 | <div> |
| 222 | <?php echo date_i18n(get_option('time_format'), strtotime($attempt_data->attempt_started_at)); ?> |
| 223 | </div> |
| 224 | <?php elseif ( $key == 'qeustion_count' ) : ?> |
| 225 | <?php echo $attempt_data->total_questions; ?> |
| 226 | <?php elseif ( $key == 'quiz_time' ) : ?> |
| 227 | <?php echo $attempt_duration; ?> |
| 228 | <?php elseif ( $key == 'attempt_time' ) : ?> |
| 229 | <?php echo $attempt_duration_taken; ?> |
| 230 | <?php elseif ( $key == 'total_marks' ) : ?> |
| 231 | <?php echo $attempt_data->total_marks; ?> |
| 232 | <?php elseif ( $key == 'pass_marks' ) : ?> |
| 233 | <?php |
| 234 | $pass_marks = ($total_marks * $passing_grade) / 100; |
| 235 | echo number_format_i18n($pass_marks, 2); |
| 236 | |
| 237 | $pass_mark_percent = $passing_grade; |
| 238 | echo ' ('.$pass_mark_percent.'%)'; |
| 239 | ?> |
| 240 | <?php elseif ( $key == 'correct_answer' ) : ?> |
| 241 | <?php echo $correct; ?> |
| 242 | <?php elseif ( $key == 'incorrect_answer' ) : ?> |
| 243 | <?php echo $incorrect; ?> |
| 244 | <?php elseif ( $key == 'earned_marks' ) : ?> |
| 245 | <?php |
| 246 | echo $attempt_data->earned_marks; |
| 247 | $earned_percentage = $attempt_data->earned_marks > 0 ? ( number_format(($attempt_data->earned_marks * 100) / $attempt_data->total_marks)) : 0; |
| 248 | echo ' ('.$earned_percentage.'%)'; |
| 249 | ?> |
| 250 | <?php elseif ( $key == 'result' ) : ?> |
| 251 | <?php |
| 252 | $ans_array = is_array( $answers ) ? $answers : array(); |
| 253 | $has_pending = count( array_filter( $ans_array, function( $ans ) { |
| 254 | return $ans->is_correct === null; |
| 255 | })); |
| 256 | |
| 257 | if ( $has_pending ) { |
| 258 | echo '<span class="tutor-badge-label label-warning">'.__('Pending', 'tutor').'</span>'; |
| 259 | } else if ( $earned_percentage >= $pass_mark_percent ) { |
| 260 | echo '<span class="tutor-badge-label label-success">'.__('Pass', 'tutor').'</span>'; |
| 261 | } else { |
| 262 | echo '<span class="tutor-badge-label label-danger">'.__('Fail', 'tutor').'</span>'; |
| 263 | } |
| 264 | ?> |
| 265 | <?php endif; ?> |
| 266 | </td> |
| 267 | <?php endforeach; ?> |
| 268 | </tr> |
| 269 | </tbody> |
| 270 | </table> |
| 271 | </div> |
| 272 | |
| 273 | <?php |
| 274 | // instructor feedback. |
| 275 | global $wp_query; |
| 276 | $query_vars = $wp_query->query_vars; |
| 277 | $page_name = isset( $query_vars['tutor_dashboard_page'] ) ? $query_vars['tutor_dashboard_page'] : ''; |
| 278 | $attempt_info = unserialize( $attempt_data->attempt_info ); |
| 279 | $feedback = is_array( $attempt_info ) && isset( $attempt_info['instructor_feedback'] ) ? $attempt_info['instructor_feedback'] : ''; |
| 280 | // don't show on instructor quiz attempt since below already have feedback box area. |
| 281 | if ( '' !== $feedback && 'my-quiz-attempts' === $page_name ) { |
| 282 | ?> |
| 283 | <div class="tutor-quiz-attempt-note tutor-instructor-note tutor-my-32 tutor-py-20 tutor-px-24 tutor-py-sm-32 tutor-px-sm-36"> |
| 284 | <div class="tutor-in-title tutor-fs-6 tutor-fw-medium tutor-color-black"> |
| 285 | <?php esc_html_e( 'Instructor Note', 'tutor' ); ?> |
| 286 | </div> |
| 287 | <div class="tutor-in-body tutor-fs-6 tutor-color-secondary tutor-pt-12 tutor-pt-sm-16"> |
| 288 | <?php echo wp_kses_post( $feedback ); ?> |
| 289 | </div> |
| 290 | </div> |
| 291 | <?php } ?> |
| 292 | |
| 293 | <?php |
| 294 | if (is_array($answers) && count($answers)){ |
| 295 | echo $context!='course-single-previous-attempts' ? '<div class="tutor-fs-6 tutor-fw-medium tutor-color-black tutor-mt-24">'.__('Quiz Overview', 'tutor').'</div>' : ''; |
| 296 | ?> |
| 297 | <div class="tutor-table-responsive tutor-mt-16"> |
| 298 | <table class="tutor-table tutor-quiz-attempt-details tutor-mb-32"> |
| 299 | <thead> |
| 300 | <tr> |
| 301 | <?php foreach($table_2_columns as $key => $column) : ?> |
| 302 | <th><?php echo $column; ?></th> |
| 303 | <?php endforeach; ?> |
| 304 | </tr> |
| 305 | </thead> |
| 306 | |
| 307 | <tbody> |
| 308 | <?php |
| 309 | $answer_i = 0; |
| 310 | foreach ($answers as $answer){ |
| 311 | $answer_i++; |
| 312 | $question_type = tutor_utils()->get_question_types($answer->question_type); |
| 313 | |
| 314 | $answer_status = 'wrong'; |
| 315 | |
| 316 | // If already correct, then show it |
| 317 | if ( (bool)$answer->is_correct ) { |
| 318 | $answer_status = 'correct'; |
| 319 | } |
| 320 | |
| 321 | // Image answering also needs review since the answer texts are not meant to match exactly |
| 322 | else if (in_array($answer->question_type, array('open_ended', 'short_answer', 'image_answering'))){ |
| 323 | $answer_status = $answer->is_correct===null ? 'pending' : 'wrong'; |
| 324 | } |
| 325 | ?> |
| 326 | |
| 327 | <tr class="tutor-quiz-answer-status-<?php echo esc_html( $answer_status ); ?>"> |
| 328 | <?php foreach($table_2_columns as $key => $column): ?> |
| 329 | <?php |
| 330 | switch($key) { |
| 331 | case 'no' : |
| 332 | ?> |
| 333 | <td class="no"> |
| 334 | <span class="tutor-fs-7 tutor-fw-medium tutor-color-black"> |
| 335 | <?php echo $answer_i; ?> |
| 336 | </span> |
| 337 | </td> |
| 338 | <?php |
| 339 | break; |
| 340 | |
| 341 | case 'type' : |
| 342 | ?> |
| 343 | <td class="type"> |
| 344 | <?php $type = tutor_utils()->get_question_types( $answer->question_type ); ?> |
| 345 | <div class="tooltip-wrap tooltip-icon tutor-d-flex"> |
| 346 | <?php echo $question_type['icon'] ?? ''; ?> |
| 347 | <span class="tooltip-txt tooltip-top"> |
| 348 | <?php echo $type['name'] ?? ''; ?> |
| 349 | </span> |
| 350 | </div> |
| 351 | </td> |
| 352 | <?php |
| 353 | break; |
| 354 | |
| 355 | case 'questions' : |
| 356 | ?> |
| 357 | <td class="questions"> |
| 358 | <span class="tutor-fs-7 tutor-fw-medium tutor-d-flex tutor-align-center"> |
| 359 | <?php echo stripslashes($answer->question_title); ?> |
| 360 | </span> |
| 361 | </td> |
| 362 | <?php |
| 363 | break; |
| 364 | |
| 365 | case 'given_answer' : |
| 366 | ?> |
| 367 | <td class="given-answer"> |
| 368 | <?php |
| 369 | // Single choice |
| 370 | if ( $answer->question_type === 'single_choice' ) { |
| 371 | $get_answers = tutor_utils()->get_answer_by_id($answer->given_answer); |
| 372 | tutor_render_answer_list($get_answers); |
| 373 | } |
| 374 | |
| 375 | |
| 376 | // True false or single choise |
| 377 | if ($answer->question_type === 'true_false'){ |
| 378 | $get_answers = tutor_utils()->get_answer_by_id($answer->given_answer); |
| 379 | $answer_titles = wp_list_pluck($get_answers, 'answer_title'); |
| 380 | $answer_titles = array_map('stripslashes', $answer_titles); |
| 381 | |
| 382 | echo '<span class="tutor-fs-7 tutor-fw-medium tutor-color-black">'. |
| 383 | implode('</p><p>', $answer_titles). |
| 384 | '</span>'; |
| 385 | } |
| 386 | |
| 387 | // Multiple choice |
| 388 | elseif ($answer->question_type === 'multiple_choice'){ |
| 389 | $get_answers = tutor_utils()->get_answer_by_id(maybe_unserialize($answer->given_answer)); |
| 390 | tutor_render_answer_list($get_answers); |
| 391 | } |
| 392 | |
| 393 | // Fill in the blank |
| 394 | elseif ($answer->question_type === 'fill_in_the_blank'){ |
| 395 | $answer_titles = maybe_unserialize($answer->given_answer); |
| 396 | $get_db_answers_by_question = QuizModel::get_answers_by_quiz_question($answer->question_id); |
| 397 | |
| 398 | echo tutor_render_fill_in_the_blank_answer($get_db_answers_by_question, $answer_titles); |
| 399 | } |
| 400 | |
| 401 | // Open ended or short answer |
| 402 | elseif ($answer->question_type === 'open_ended' || $answer->question_type === 'short_answer'){ |
| 403 | if ($answer->given_answer){ |
| 404 | echo wpautop(stripslashes($answer->given_answer)); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | // Ordering |
| 409 | elseif ($answer->question_type === 'ordering'){ |
| 410 | $ordering_ids = maybe_unserialize($answer->given_answer); |
| 411 | foreach ($ordering_ids as $ordering_id){ |
| 412 | $get_answers = tutor_utils()->get_answer_by_id($ordering_id); |
| 413 | tutor_render_answer_list($get_answers); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | // Matching |
| 418 | elseif ($answer->question_type === 'matching'){ |
| 419 | |
| 420 | $ordering_ids = maybe_unserialize($answer->given_answer); |
| 421 | $original_saved_answers = QuizModel::get_answers_by_quiz_question($answer->question_id); |
| 422 | |
| 423 | $answers = array(); |
| 424 | |
| 425 | foreach ($original_saved_answers as $key => $original_saved_answer){ |
| 426 | $provided_answer_order_id = isset($ordering_ids[$key]) ? $ordering_ids[$key] : 0; |
| 427 | $provided_answer_order = tutor_utils()->get_answer_by_id($provided_answer_order_id); |
| 428 | if(tutor_utils()->count($provided_answer_order)){ |
| 429 | foreach ($provided_answer_order as $provided_answer_order); |
| 430 | $original_saved_answer->answer_two_gap_match = $provided_answer_order->answer_two_gap_match; |
| 431 | $answers[] = $original_saved_answer; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | tutor_render_answer_list( $answers ); |
| 436 | } |
| 437 | |
| 438 | elseif ($answer->question_type === 'image_matching'){ |
| 439 | |
| 440 | $ordering_ids = maybe_unserialize($answer->given_answer); |
| 441 | $original_saved_answers = QuizModel::get_answers_by_quiz_question($answer->question_id); |
| 442 | |
| 443 | $answers = array(); |
| 444 | |
| 445 | foreach ($original_saved_answers as $key => $original_saved_answer){ |
| 446 | $provided_answer_order_id = isset($ordering_ids[$key]) ? $ordering_ids[$key] : 0; |
| 447 | $provided_answer_order = tutor_utils()->get_answer_by_id($provided_answer_order_id); |
| 448 | foreach ($provided_answer_order as $provided_answer_order); |
| 449 | |
| 450 | if($provided_answer_order->answer_title) { |
| 451 | $original_saved_answer->answer_view_format = 'text_image'; |
| 452 | $original_saved_answer->answer_title = $provided_answer_order->answer_title; |
| 453 | $answers[] = $original_saved_answer; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | tutor_render_answer_list( $answers ); |
| 458 | } |
| 459 | |
| 460 | elseif ($answer->question_type === 'image_answering'){ |
| 461 | |
| 462 | $ordering_ids = maybe_unserialize($answer->given_answer); |
| 463 | |
| 464 | $answers = array(); |
| 465 | |
| 466 | foreach ($ordering_ids as $answer_id => $image_answer){ |
| 467 | $db_answers = tutor_utils()->get_answer_by_id($answer_id); |
| 468 | foreach ($db_answers as $db_answer); |
| 469 | $db_answer->answer_title = $image_answer; |
| 470 | $db_answer->answer_view_format = 'text_image'; |
| 471 | $answers[] = $db_answer; |
| 472 | |
| 473 | } |
| 474 | |
| 475 | tutor_render_answer_list( $answers ); |
| 476 | } |
| 477 | ?> |
| 478 | </td> |
| 479 | <?php |
| 480 | break; |
| 481 | |
| 482 | case 'correct_answer' : |
| 483 | ?> |
| 484 | <td class="correct-answer"> |
| 485 | <?php |
| 486 | if (($answer->question_type != 'open_ended' && $answer->question_type != 'short_answer')) { |
| 487 | |
| 488 | global $wpdb; |
| 489 | |
| 490 | // True false |
| 491 | if ( $answer->question_type === 'true_false' ) { |
| 492 | $correct_answer = $wpdb->get_var( $wpdb->prepare( |
| 493 | "SELECT answer_title FROM {$wpdb->prefix}tutor_quiz_question_answers |
| 494 | WHERE belongs_question_id = %d |
| 495 | AND belongs_question_type='true_false' |
| 496 | AND is_correct = 1", |
| 497 | $answer->question_id |
| 498 | ) ); |
| 499 | |
| 500 | echo '<span class="tutor-fs-7 tutor-fw-medium tutor-color-black">' . |
| 501 | $correct_answer . |
| 502 | '</span>'; |
| 503 | } |
| 504 | |
| 505 | // Single choice |
| 506 | elseif ( $answer->question_type === 'single_choice' ) { |
| 507 | $correct_answer = $wpdb->get_results( $wpdb->prepare( |
| 508 | "SELECT answer_title, image_id, answer_view_format |
| 509 | FROM {$wpdb->prefix}tutor_quiz_question_answers |
| 510 | WHERE belongs_question_id = %d |
| 511 | AND belongs_question_type='single_choice' AND |
| 512 | is_correct = 1", |
| 513 | $answer->question_id |
| 514 | ) ); |
| 515 | |
| 516 | tutor_render_answer_list($correct_answer); |
| 517 | } |
| 518 | |
| 519 | // Multiple choice |
| 520 | elseif ( $answer->question_type === 'multiple_choice' ) { |
| 521 | $correct_answer = $wpdb->get_results( $wpdb->prepare( |
| 522 | "SELECT answer_title, image_id, answer_view_format |
| 523 | FROM {$wpdb->prefix}tutor_quiz_question_answers |
| 524 | WHERE belongs_question_id = %d |
| 525 | AND belongs_question_type='multiple_choice' |
| 526 | AND is_correct = 1 ;", |
| 527 | $answer->question_id |
| 528 | ) ); |
| 529 | |
| 530 | tutor_render_answer_list($correct_answer); |
| 531 | } |
| 532 | |
| 533 | // Fill in the blanks |
| 534 | elseif ( $answer->question_type === 'fill_in_the_blank' ) { |
| 535 | $correct_answer = $wpdb->get_var( $wpdb->prepare( |
| 536 | "SELECT answer_two_gap_match FROM {$wpdb->prefix}tutor_quiz_question_answers |
| 537 | WHERE belongs_question_id = %d |
| 538 | AND belongs_question_type='fill_in_the_blank'", |
| 539 | $answer->question_id |
| 540 | ) ); |
| 541 | |
| 542 | $answer_titles = explode('|', stripslashes($correct_answer)); |
| 543 | $get_db_answers_by_question = QuizModel::get_answers_by_quiz_question($answer->question_id); |
| 544 | |
| 545 | echo tutor_render_fill_in_the_blank_answer($get_db_answers_by_question, $answer_titles); |
| 546 | } |
| 547 | |
| 548 | // Ordering |
| 549 | elseif ( $answer->question_type === 'ordering' ) { |
| 550 | $correct_answer = $wpdb->get_results( $wpdb->prepare( |
| 551 | "SELECT answer_title, image_id, answer_view_format |
| 552 | FROM {$wpdb->prefix}tutor_quiz_question_answers |
| 553 | WHERE belongs_question_id = %d |
| 554 | AND belongs_question_type='ordering' |
| 555 | ORDER BY answer_order ASC;", |
| 556 | $answer->question_id |
| 557 | ) ); |
| 558 | |
| 559 | foreach($correct_answer as $ans) { |
| 560 | tutor_render_answer_list(array($ans)); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | // Matching |
| 565 | elseif( $answer->question_type === 'matching' ){ |
| 566 | $correct_answer = $wpdb->get_results( $wpdb->prepare( |
| 567 | "SELECT answer_title, image_id, answer_two_gap_match, answer_view_format |
| 568 | FROM {$wpdb->prefix}tutor_quiz_question_answers |
| 569 | WHERE belongs_question_id = %d |
| 570 | AND belongs_question_type='matching' |
| 571 | ORDER BY answer_order ASC;", |
| 572 | $answer->question_id |
| 573 | ) ); |
| 574 | |
| 575 | tutor_render_answer_list($correct_answer); |
| 576 | } |
| 577 | |
| 578 | // Image matching |
| 579 | elseif( $answer->question_type === 'image_matching' ) { |
| 580 | $correct_answer = $wpdb->get_results( $wpdb->prepare( |
| 581 | "SELECT answer_title, image_id, answer_two_gap_match |
| 582 | FROM {$wpdb->prefix}tutor_quiz_question_answers |
| 583 | WHERE belongs_question_id = %d |
| 584 | AND belongs_question_type='image_matching' |
| 585 | ORDER BY answer_order ASC;", |
| 586 | $answer->question_id |
| 587 | ) ); |
| 588 | |
| 589 | tutor_render_answer_list($correct_answer, true); |
| 590 | } |
| 591 | |
| 592 | // Image Answering |
| 593 | elseif ($answer->question_type === 'image_answering'){ |
| 594 | |
| 595 | $correct_answer = $wpdb->get_results( $wpdb->prepare( |
| 596 | "SELECT answer_title, image_id, answer_two_gap_match |
| 597 | FROM {$wpdb->prefix}tutor_quiz_question_answers |
| 598 | WHERE belongs_question_id = %d |
| 599 | AND belongs_question_type='image_answering' |
| 600 | ORDER BY answer_order ASC;", |
| 601 | $answer->question_id |
| 602 | ) ); |
| 603 | |
| 604 | !is_array($correct_answer) ? $correct_answer=array() : 0; |
| 605 | |
| 606 | echo '<div class="answer-image-matched-wrap">'; |
| 607 | foreach ($correct_answer as $image_answer){ |
| 608 | ?> |
| 609 | <div class="image-matching-item"> |
| 610 | <p class="dragged-img-rap"><img src="<?php echo wp_get_attachment_image_url( $image_answer->image_id); ?>" /> </p> |
| 611 | <p class="dragged-caption"><?php echo $image_answer->answer_title; ?></p> |
| 612 | </div> |
| 613 | <?php |
| 614 | } |
| 615 | echo '</div>'; |
| 616 | } |
| 617 | } |
| 618 | ?> |
| 619 | </td> |
| 620 | <?php |
| 621 | break; |
| 622 | |
| 623 | case 'result' : |
| 624 | ?> |
| 625 | <td class="result"> |
| 626 | <?php |
| 627 | switch($answer_status) { |
| 628 | case 'correct' : |
| 629 | echo '<span class="tutor-badge-label label-success">'.__('Correct', 'tutor').'</span>'; |
| 630 | break; |
| 631 | |
| 632 | case 'pending' : |
| 633 | echo '<span class="tutor-badge-label label-warning">'.__('Pending', 'tutor').'</span>'; |
| 634 | break; |
| 635 | |
| 636 | case 'wrong' : |
| 637 | echo '<span class="tutor-badge-label label-danger">'.__('Incorrect', 'tutor').'</span>'; |
| 638 | break; |
| 639 | } |
| 640 | ?> |
| 641 | </td> |
| 642 | <?php |
| 643 | break; |
| 644 | |
| 645 | case 'manual_review' : |
| 646 | ?> |
| 647 | <td class="tutor-text-center tutor-nowrap-ellipsis"> |
| 648 | <a href="javascript:;" data-back-url="<?php echo $back_url; ?>" data-attempt-id="<?php echo $attempt_id; ?>" data-attempt-answer-id="<?php echo $answer->attempt_answer_id; ?>" data-mark-as="correct" data-context="<?php echo $context; ?>" title="<?php _e('Mark as correct', 'tutor'); ?>" class="quiz-manual-review-action tutor-mr-12 tutor-icon-rounded tutor-color-success"> |
| 649 | <i class="tutor-icon-mark"></i> |
| 650 | </a> |
| 651 | <a href="javascript:;" data-back-url="<?php echo $back_url; ?>" data-attempt-id="<?php echo $attempt_id; ?>" data-attempt-answer-id="<?php echo $answer->attempt_answer_id; ?>" data-mark-as="incorrect" data-context="<?php echo $context; ?>" title="<?php _e('Mark as In correct', 'tutor'); ?>" class="quiz-manual-review-action tutor-icon-rounded tutor-color-danger"> |
| 652 | <i class="tutor-icon-times"></i> |
| 653 | </a> |
| 654 | </td> |
| 655 | <?php |
| 656 | } |
| 657 | ?> |
| 658 | <?php endforeach; ?> |
| 659 | </tr> |
| 660 | <?php |
| 661 | } |
| 662 | ?> |
| 663 | </tbody> |
| 664 | </table> |
| 665 | </div> |
| 666 | <?php |
| 667 | } |
| 668 | ?> |
| 669 | |
| 670 | <?php echo is_admin() ? '</div>' : ''; ?> |