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.php
115 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Attempt details question wrapper. |
| 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\Models\QuizModel; |
| 14 | |
| 15 | if ( ! isset( $question ) || ! is_object( $question ) || empty( $question_template ) ) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | $index = (int) ( $index ?? 1 ); |
| 20 | $attempt_id = (int) ( $attempt_id ?? 0 ); |
| 21 | $back_url = (string) ( $back_url ?? '' ); |
| 22 | $context = (string) ( $context ?? '' ); |
| 23 | $is_instructor_review = ! empty( $is_instructor_review ); |
| 24 | $review_field_name = (string) ( $review_field_name ?? '' ); |
| 25 | $question_settings = maybe_unserialize( $question->question_settings ); |
| 26 | $question_settings = is_array( $question_settings ) ? $question_settings : array(); |
| 27 | $question_type = (string) ( $question->question_type ?? '' ); |
| 28 | |
| 29 | if ( 'image_matching' === $question_type ) { |
| 30 | $question_type = 'matching'; |
| 31 | } |
| 32 | |
| 33 | if ( 'single_choice' === $question_type ) { |
| 34 | $question_type = 'multiple_choice'; |
| 35 | } |
| 36 | |
| 37 | $is_skipped = QuizModel::is_attempt_answer_skipped( $question ); |
| 38 | $review_status = $question ? QuizModel::get_attempt_answer_status( $question ) : 'skipped'; |
| 39 | $answer_status = $review_status; |
| 40 | $status_badges = array(); |
| 41 | |
| 42 | if ( $is_skipped ) { |
| 43 | $status_badges[] = array( |
| 44 | 'label' => __( 'Skipped', 'tutor' ), |
| 45 | 'variant' => Badge::INFO, |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | if ( $is_instructor_review ) { |
| 50 | $status_badges[] = array( |
| 51 | 'status' => $review_status, |
| 52 | ); |
| 53 | } elseif ( 'correct' === $review_status ) { |
| 54 | $status_badges[] = array( |
| 55 | 'label' => __( 'Correct', 'tutor' ), |
| 56 | 'variant' => Badge::SUCCESS, |
| 57 | ); |
| 58 | } elseif ( 'pending' === $review_status ) { |
| 59 | $status_badges[] = array( |
| 60 | 'label' => __( 'Pending', 'tutor' ), |
| 61 | 'variant' => Badge::WARNING, |
| 62 | ); |
| 63 | } elseif ( 'incorrect' === $review_status ) { |
| 64 | $status_badges[] = array( |
| 65 | 'label' => __( 'Incorrect', 'tutor' ), |
| 66 | 'variant' => Badge::ERROR, |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | $question_wrapper_classes = array( 'tutor-quiz-question' ); |
| 72 | if ( 'review-answer-dnd' === $question_template ) { |
| 73 | $question_wrapper_classes[] = 'tutor-quiz-review-dnd'; |
| 74 | } |
| 75 | |
| 76 | ?> |
| 77 | |
| 78 | <div class="<?php echo esc_attr( implode( ' ', $question_wrapper_classes ) ); ?>" data-question="<?php echo esc_attr( $question_type ); ?>"> |
| 79 | <?php |
| 80 | tutor_load_template( |
| 81 | 'shared.components.quiz.attempt-details.question-header', |
| 82 | array( |
| 83 | 'question' => $question, |
| 84 | 'index' => $index, |
| 85 | 'question_title' => (string) ( $question->question_title ?? '' ), |
| 86 | 'question_description' => (string) ( $question->question_description ?? '' ), |
| 87 | 'question_mark' => (string) ( $question->question_mark ?? '' ), |
| 88 | 'show_question_mark' => '1' === (string) ( $question_settings['show_question_mark'] ?? '1' ), |
| 89 | 'status_badges' => $status_badges, |
| 90 | 'answer_status' => $answer_status, |
| 91 | 'attempt_id' => $attempt_id, |
| 92 | 'attempt_answer_id' => (int) ( $question->attempt_answer_id ?? 0 ), |
| 93 | 'back_url' => $back_url, |
| 94 | 'context' => $context, |
| 95 | 'is_instructor_review' => $is_instructor_review, |
| 96 | 'review_field_name' => $review_field_name, |
| 97 | ) |
| 98 | ); |
| 99 | |
| 100 | tutor_load_template( |
| 101 | 'shared.components.quiz.attempt-details.questions.' . $question_template, |
| 102 | array( |
| 103 | 'question' => $question, |
| 104 | 'index' => $index, |
| 105 | ) |
| 106 | ); |
| 107 | |
| 108 | do_action( 'tutor_quiz_attempt_details_after_question_template', $question, $question_template, $index ); |
| 109 | |
| 110 | if ( is_object( $question ) ) { |
| 111 | do_action( 'tutor_quiz_attempt_details_loop_after_row', $question, $answer_status, array() ); |
| 112 | } |
| 113 | ?> |
| 114 | </div> |
| 115 |