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.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / templates / shared / components / quiz / attempt-details / questions / review-answer-dnd.php
tutor / templates / shared / components / quiz / attempt-details / questions Last commit date
fill-in-the-blank.php 1 month ago multiple-choice.php 1 month ago open-ended.php 1 month ago review-answer-dnd.php 1 month ago true-false.php 1 month ago
review-answer-dnd.php
135 lines
1 <?php
2 /**
3 * Shared read-only review template for DnD-like question types.
4 *
5 * Supports: image_answering, ordering, matching, image_matching.
6 *
7 * @package Tutor\Templates
8 * @subpackage LearningArea\Quiz\AttemptDetails
9 * @since 4.0.0
10 */
11
12 defined( 'ABSPATH' ) || exit;
13
14 use Tutor\Models\QuizModel;
15
16 if ( ! isset( $question ) || ! is_object( $question ) ) {
17 return;
18 }
19
20 $question_settings = maybe_unserialize( $question->question_settings );
21 $question_settings = is_array( $question_settings ) ? $question_settings : array();
22 $question_type = (string) ( $question->question_type ?? '' );
23 $is_image_matching = 'image_matching' === $question_type || '1' === (string) ( $question_settings['is_image_matching'] ?? '0' );
24
25 if ( $is_image_matching ) {
26 $question_type = 'matching';
27 }
28
29 $question_settings['show_question_mark'] = $question_settings['show_question_mark'] ?? '1';
30 $question_settings['is_image_matching'] = $is_image_matching ? '1' : ( $question_settings['is_image_matching'] ?? '0' );
31 $question_answers = QuizModel::get_answers_by_quiz_question( (int) $question->question_id );
32 $question_answers = is_array( $question_answers ) ? array_values( $question_answers ) : array();
33 $given_raw = $question->given_answer ?? null;
34 $given_answer = maybe_unserialize( $given_raw );
35
36 $normalize = static function ( $value ) {
37 return strtolower( trim( wp_strip_all_tags( (string) $value ) ) );
38 };
39
40 $get_answer_by_id = static function ( $answer_id ) {
41 $results = tutor_utils()->get_answer_by_id( (int) $answer_id );
42 return is_array( $results ) && ! empty( $results ) ? $results[0] : null;
43 };
44
45 $get_image_url = static function ( $answer ) {
46 if ( ! empty( $answer->image_id ) ) {
47 return wp_get_attachment_image_url( $answer->image_id, 'thumbnail' );
48 }
49 return '';
50 };
51
52 $rows = array();
53
54 if ( 'ordering' === $question_type ) {
55 $given_ids = is_array( $given_answer ) ? array_values( $given_answer ) : array();
56 foreach ( $question_answers as $idx => $correct_item ) {
57 $selected_item = isset( $given_ids[ $idx ] ) ? $get_answer_by_id( $given_ids[ $idx ] ) : null;
58 $is_row_ok = $selected_item && (int) $selected_item->answer_id === (int) $correct_item->answer_id;
59
60 $rows[] = array(
61 'given_text' => $selected_item->answer_title ?? '',
62 'given_image' => $selected_item ? $get_image_url( $selected_item ) : '',
63 'correct_text' => $correct_item->answer_title ?? '',
64 'correct_image' => $get_image_url( $correct_item ),
65 'given_status' => $is_row_ok ? 'correct' : 'incorrect',
66 );
67 }
68 } elseif ( 'matching' === $question_type ) {
69 $given_ids = is_array( $given_answer ) ? array_values( $given_answer ) : array();
70 foreach ( $question_answers as $idx => $correct_item ) {
71 $selected_item = isset( $given_ids[ $idx ] ) ? $get_answer_by_id( $given_ids[ $idx ] ) : null;
72 $given_text = $is_image_matching ? ( $selected_item->answer_title ?? '' ) : ( $selected_item->answer_two_gap_match ?? '' );
73 $correct_text = $is_image_matching ? ( $correct_item->answer_title ?? '' ) : ( $correct_item->answer_two_gap_match ?? '' );
74 $is_row_ok = $normalize( $given_text ) === $normalize( $correct_text );
75
76 $rows[] = array(
77 'given_text' => $given_text,
78 'given_image' => $is_image_matching && $selected_item ? $get_image_url( $selected_item ) : '',
79 'correct_text' => $correct_text,
80 'correct_image' => $is_image_matching ? $get_image_url( $correct_item ) : '',
81 'given_status' => $is_row_ok ? 'correct' : 'incorrect',
82 );
83 }
84 } elseif ( 'image_answering' === $question_type ) {
85 $given_map = is_array( $given_answer ) ? $given_answer : array();
86 $answer_status = QuizModel::get_attempt_answer_status( $question );
87 $row_item_state = 'correct' === $answer_status ? 'correct' : ( 'pending' === $answer_status ? 'pending' : 'incorrect' );
88
89 foreach ( $question_answers as $correct_item ) {
90 $answer_id = (int) ( $correct_item->answer_id ?? 0 );
91 $given_text = (string) ( $given_map[ $answer_id ] ?? '' );
92 $correct_text = (string) ( $correct_item->answer_title ?? '' );
93
94 $rows[] = array(
95 'given_text' => $given_text,
96 'given_image' => $get_image_url( $correct_item ),
97 'correct_text' => $correct_text,
98 'correct_image' => $get_image_url( $correct_item ),
99 'given_status' => $row_item_state,
100 );
101 }
102 }
103 ?>
104
105 <div class="tutor-quiz-review-dnd-grid">
106 <div class="tutor-quiz-review-dnd-head">
107 <div class="tutor-quiz-review-col-title tutor-quiz-review-given"><?php esc_html_e( 'Given Answer', 'tutor' ); ?></div>
108 <div class="tutor-quiz-review-col-title tutor-quiz-review-correct"><?php esc_html_e( 'Correct Answer', 'tutor' ); ?></div>
109 </div>
110
111 <div class="tutor-quiz-review-dnd-rows">
112 <?php
113 foreach ( $rows as $row ) :
114 $given_text = isset( $row['given_text'] ) ? wp_unslash( $row['given_text'] ) : '';
115 $correct_text = isset( $row['correct_text'] ) ? wp_unslash( $row['correct_text'] ) : '';
116 $given_status = isset( $row['given_status'] ) ? $row['given_status'] : 'neutral';
117 ?>
118 <div class="tutor-quiz-review-dnd-row">
119 <div class="tutor-quiz-review-item tutor-quiz-review-given" data-option="<?php echo esc_attr( $given_status ); ?>">
120 <?php if ( ! empty( $row['given_image'] ) ) : ?>
121 <img src="<?php echo esc_url( $row['given_image'] ); ?>" alt="<?php echo esc_attr( $given_text ); ?>">
122 <?php endif; ?>
123 <span><?php echo esc_html( $given_text ); ?></span>
124 </div>
125 <div class="tutor-quiz-review-item tutor-quiz-review-correct" data-option="neutral">
126 <?php if ( ! empty( $row['correct_image'] ) ) : ?>
127 <img src="<?php echo esc_url( $row['correct_image'] ); ?>" alt="<?php echo esc_attr( $correct_text ); ?>">
128 <?php endif; ?>
129 <span><?php echo esc_html( $correct_text ); ?></span>
130 </div>
131 </div>
132 <?php endforeach; ?>
133 </div>
134 </div>
135