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 |