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