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