fill-in-the-blank.php
1 week ago
multiple-choice.php
1 week ago
open-ended.php
1 month ago
review-answer-dnd.php
1 week ago
true-false.php
1 week ago
multiple-choice.php
75 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Attempt details Multiple Choice/Single Choice (read-only). |
| 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\Models\QuizModel; |
| 14 | |
| 15 | if ( ! isset( $question ) || ! is_object( $question ) ) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | $question_settings = maybe_unserialize( $question->question_settings ); |
| 20 | $question_settings = is_array( $question_settings ) ? $question_settings : array(); |
| 21 | $question_answers = QuizModel::get_answers_by_quiz_question( (int) $question->question_id ); |
| 22 | $question_answers = is_array( $question_answers ) ? $question_answers : array(); |
| 23 | $has_multiple_correct_answer = isset( $question_settings['has_multiple_correct_answer'] ) && '1' === (string) $question_settings['has_multiple_correct_answer']; |
| 24 | |
| 25 | $given_ids = array(); |
| 26 | if ( isset( $question->given_answer ) ) { |
| 27 | $given_value = maybe_unserialize( $question->given_answer ); |
| 28 | $given_ids = is_array( $given_value ) ? array_values( $given_value ) : array( $given_value ); |
| 29 | } |
| 30 | $given_ids = array_map( 'intval', array_filter( $given_ids ) ); |
| 31 | ?> |
| 32 | |
| 33 | <div class="tutor-quiz-question-options"> |
| 34 | <?php foreach ( $question_answers as $index => $answer ) : ?> |
| 35 | <?php |
| 36 | $is_selected = in_array( (int) $answer->answer_id, $given_ids, true ); |
| 37 | $is_correct = (bool) ( $answer->is_correct ?? false ); |
| 38 | $option_attr = ''; |
| 39 | if ( $is_selected && $is_correct ) { |
| 40 | $option_attr = 'correct'; |
| 41 | } elseif ( $is_selected && ! $is_correct ) { |
| 42 | $option_attr = 'incorrect'; |
| 43 | } elseif ( ! $is_selected && $is_correct ) { |
| 44 | $option_attr = 'correct'; |
| 45 | } |
| 46 | ?> |
| 47 | <div class="tutor-quiz-question-option" data-option="<?php echo esc_attr( $option_attr ); ?>" data-readonly="true"> |
| 48 | <?php if ( ! empty( $answer->image_id ) ) : ?> |
| 49 | <img |
| 50 | src="<?php echo esc_url( wp_get_attachment_image_url( $answer->image_id, 'full' ) ); ?>" |
| 51 | alt="<?php echo esc_attr( Quiz::sanitize_quiz_content( $answer->answer_title ?? '' ) ); ?>" |
| 52 | > |
| 53 | <div data-title> |
| 54 | <?php echo esc_html( Quiz::sanitize_quiz_content( $answer->answer_title ?? '' ) ); ?> |
| 55 | </div> |
| 56 | <?php else : ?> |
| 57 | <div class="tutor-input-field"> |
| 58 | <div class="tutor-input-wrapper"> |
| 59 | <input |
| 60 | type="<?php echo esc_attr( $has_multiple_correct_answer ? 'checkbox' : 'radio' ); ?>" |
| 61 | class="<?php echo esc_attr( $has_multiple_correct_answer ? 'tutor-checkbox' : 'tutor-radio' ); ?>" |
| 62 | id="<?php echo esc_attr( 'attempt-review-' . $question->question_id . '-' . $index ); ?>" |
| 63 | <?php checked( $is_selected ); ?> |
| 64 | disabled |
| 65 | > |
| 66 | <label class="tutor-label" for="<?php echo esc_attr( 'attempt-review-' . $question->question_id . '-' . $index ); ?>"> |
| 67 | <?php echo esc_html( Quiz::sanitize_quiz_content( $answer->answer_title ?? '' ) ); ?> |
| 68 | </label> |
| 69 | </div> |
| 70 | </div> |
| 71 | <?php endif; ?> |
| 72 | </div> |
| 73 | <?php endforeach; ?> |
| 74 | </div> |
| 75 |