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.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 / question-header.php
tutor / templates / shared / components / quiz / attempt-details Last commit date
questions 3 days ago question-header.php 3 days ago question.php 1 month ago questions-sidebar.php 3 days ago review-answers.php 1 month ago summary.php 1 month ago
question-header.php
170 lines
1 <?php
2 /**
3 * Attempt details question header.
4 *
5 * @package Tutor\Templates
6 * @subpackage LearningArea\Quiz\AttemptDetails
7 * @since 4.0.0
8 */
9
10 defined( 'ABSPATH' ) || exit;
11
12 use TUTOR\Quiz;
13 use TUTOR\Icon;
14 use Tutor\Components\Badge;
15 use Tutor\Components\SvgIcon;
16
17 /**
18 * Build Alpine.js attribute expressions for a reactive review-status badge.
19 *
20 * @param string $review_field_name The form field name, e.g. "review_statuses[42]".
21 *
22 * @return array{ x_text: string, class_expr: string }
23 */
24 $build_badge_attrs = function ( string $review_field_name ): array {
25 $label_map = wp_json_encode(
26 array(
27 'pending' => __( 'Pending', 'tutor' ),
28 'correct' => __( 'Correct', 'tutor' ),
29 'incorrect' => __( 'Incorrect', 'tutor' ),
30 )
31 );
32
33 $variant_map = wp_json_encode(
34 array(
35 'pending' => Badge::WARNING,
36 'correct' => Badge::SUCCESS,
37 'incorrect' => Badge::ERROR,
38 )
39 );
40
41 $field = esc_attr( $review_field_name );
42
43 return array(
44 'x_text' => "({$label_map})[watch('{$field}')] ?? ''",
45 'class_expr' => "'tutor-badge tutor-badge-rounded tutor-badge-' + (({$variant_map})[watch('{$field}')] ?? 'info')",
46 );
47 };
48
49 $index = (int) ( $index ?? 1 );
50 $question_title = (string) ( $question_title ?? '' );
51 $question_description = (string) ( $question_description ?? '' );
52 $status_badges = isset( $status_badges ) && is_array( $status_badges ) ? $status_badges : array();
53 $question = isset( $question ) && is_object( $question ) ? $question : null;
54 $answer_status = (string) ( $answer_status ?? '' );
55 $attempt_id = (int) ( $attempt_id ?? 0 );
56 $attempt_answer_id = (int) ( $attempt_answer_id ?? 0 );
57 $is_instructor_review = ! empty( $is_instructor_review );
58 $review_field_name = (string) ( $review_field_name ?? '' );
59 ?>
60
61 <div class="tutor-quiz-question-header">
62 <div class="tutor-quiz-question-number">
63 <?php echo esc_html( $index ); ?>
64 </div>
65
66 <div class="tutor-quiz-question-title">
67 <?php echo esc_html( Quiz::sanitize_quiz_content( $question_title ?? '' ) ); ?>
68
69 <?php if ( ! empty( $question_description ) ) : ?>
70 <?php
71 $description = apply_filters( 'tutor_filter_quiz_question_description', wp_unslash( (string) ( $question_description ?? '' ) ) );
72 if ( $description ) {
73 $markup = "<div class='tutor-p2 tutor-text-secondary'>{$description}</div>";
74 if ( function_exists( 'tutor' ) && tutor()->has_pro ) {
75 do_action( 'tutor_quiz_question_desc_render', $markup, $question );
76 } else {
77 echo wp_kses_post( $markup );
78 }
79 }
80 ?>
81 <?php endif; ?>
82 </div>
83
84 <?php if ( ! empty( $status_badges ) || ( $is_instructor_review && $attempt_id ) ) : ?>
85 <div class="tutor-quiz-question-header-actions">
86 <?php if ( ! empty( $status_badges ) ) : ?>
87 <div class="tutor-quiz-question-header-status">
88 <?php foreach ( $status_badges as $badge ) : ?>
89 <?php
90 $badge_status = (string) ( $badge['status'] ?? '' );
91
92 if ( $badge_status && $is_instructor_review ) :
93 $badge_attrs = $build_badge_attrs( $review_field_name );
94
95 Badge::make()
96 ->rounded()
97 ->attr( 'x-text', $badge_attrs['x_text'] )
98 ->attr( ':class', $badge_attrs['class_expr'] )
99 ->render();
100 else :
101 $badge_label = (string) ( $badge['label'] ?? '' );
102 $badge_variant = (string) ( $badge['variant'] ?? '' );
103
104 if ( '' === $badge_label || '' === $badge_variant ) {
105 continue;
106 }
107
108 Badge::make()
109 ->label( $badge_label )
110 ->variant( $badge_variant )
111 ->rounded()
112 ->render();
113 endif;
114 ?>
115 <?php endforeach; ?>
116 </div>
117 <?php endif; ?>
118
119 <?php if ( $is_instructor_review && $attempt_id && $review_field_name ) : ?>
120 <div class="tutor-quiz-question-header-divider" aria-hidden="true"></div>
121
122 <div class="tutor-quiz-question-review-actions">
123 <input
124 type="hidden"
125 name="<?php echo esc_attr( $review_field_name ); ?>"
126 value="<?php echo esc_attr( $answer_status ); ?>"
127 x-bind="register('<?php echo esc_attr( $review_field_name ); ?>')"
128 />
129
130 <label
131 class="tutor-quiz-question-review-action"
132 data-review-status="correct"
133 title="<?php esc_attr_e( 'Mark as correct', 'tutor' ); ?>"
134 @click="setValue('<?php echo esc_attr( $review_field_name ); ?>', 'correct', { shouldDirty: true })"
135 >
136 <input
137 class="tutor-quiz-question-review-input"
138 type="radio"
139 name="<?php echo esc_attr( $review_field_name ); ?>"
140 value="correct"
141 :checked="watch('<?php echo esc_attr( $review_field_name ); ?>') === 'correct'"
142 tabindex="-1"
143 aria-hidden="true"
144 />
145 <?php SvgIcon::make()->name( Icon::CHECK_2 )->size( 20 )->render(); ?>
146 </label>
147
148 <label
149 class="tutor-quiz-question-review-action"
150 data-review-status="incorrect"
151 title="<?php esc_attr_e( 'Mark as incorrect', 'tutor' ); ?>"
152 @click="setValue('<?php echo esc_attr( $review_field_name ); ?>', 'incorrect', { shouldDirty: true })"
153 >
154 <input
155 class="tutor-quiz-question-review-input"
156 type="radio"
157 name="<?php echo esc_attr( $review_field_name ); ?>"
158 value="incorrect"
159 :checked="watch('<?php echo esc_attr( $review_field_name ); ?>') === 'incorrect'"
160 tabindex="-1"
161 aria-hidden="true"
162 />
163 <?php SvgIcon::make()->name( Icon::CROSS )->size( 20 )->render(); ?>
164 </label>
165 </div>
166 <?php endif; ?>
167 </div>
168 <?php endif; ?>
169 </div>
170