student-quiz-attempt-row.php
156 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Tutor dashboard quiz attempt row. |
| 4 | * Reusable component for displaying a single quiz attempt row. |
| 5 | * |
| 6 | * @package Tutor\Templates |
| 7 | * @author Themeum <support@themeum.com> |
| 8 | * @link https://themeum.com |
| 9 | * @since 4.0.0 |
| 10 | */ |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | use TUTOR\Icon; |
| 15 | use TUTOR\Quiz_Attempts_List; |
| 16 | use Tutor\Components\SvgIcon; |
| 17 | use Tutor\Components\PreviewTrigger; |
| 18 | use Tutor\Components\Constants\Color; |
| 19 | |
| 20 | if ( empty( $attempt ) ) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | $show_quiz_title = $show_quiz_title ?? false; |
| 25 | $show_course = $show_course ?? false; |
| 26 | $attempt_number = $attempt_number ?? null; |
| 27 | $attempts_count = $attempts_count ?? 0; |
| 28 | $is_previous = $is_previous ?? false; |
| 29 | $is_learning_area = $is_learning_area ?? false; |
| 30 | $details_url = $quiz_attempt_obj->get_review_url( |
| 31 | $attempt, |
| 32 | array( 'action' => 'view_details' ) |
| 33 | ) ?? '#'; |
| 34 | |
| 35 | $hide_quiz_details = Quiz_Attempts_List::is_attempt_details_hidden(); |
| 36 | |
| 37 | ?> |
| 38 | <div class="tutor-quiz-attempts-item" data-learning-area="<?php echo esc_attr( $is_learning_area ? 'true' : 'false' ); ?>"> |
| 39 | <div class="tutor-quiz-item-info"> |
| 40 | <?php |
| 41 | if ( $show_quiz_title && ! empty( $quiz_title ) ) : |
| 42 | ?> |
| 43 | <div class="tutor-quiz-item-info-expanded"> |
| 44 | <?php if ( $hide_quiz_details ) : ?> |
| 45 | <div class="tutor-medium tutor-font-semibold tutor-text-start"> |
| 46 | <?php echo esc_html( $quiz_title ); ?> |
| 47 | </div> |
| 48 | <?php else : ?> |
| 49 | <a href="<?php echo esc_url( $details_url ); ?>" class="tutor-quiz-item-info-title"> |
| 50 | <?php echo esc_html( $quiz_title ); ?> |
| 51 | </a> |
| 52 | <?php endif; ?> |
| 53 | <?php if ( $attempts_count > 1 ) : ?> |
| 54 | <button @click="expanded = !expanded" class="tutor-quiz-attempts-expand-btn"> |
| 55 | <?php |
| 56 | printf( |
| 57 | /* translators: %d: number of attempts */ |
| 58 | esc_html__( '%d Attempts', 'tutor' ), |
| 59 | esc_attr( $attempts_count ) |
| 60 | ); |
| 61 | ?> |
| 62 | <span class="tutor-quiz-attempts-expand-icon"> |
| 63 | <?php SvgIcon::make()->name( Icon::CHEVRON_DOWN )->size( 18 )->render(); ?> |
| 64 | </span> |
| 65 | </button> |
| 66 | <?php endif; ?> |
| 67 | </div> |
| 68 | <?php endif; ?> |
| 69 | |
| 70 | <?php if ( $attempt_number ) : ?> |
| 71 | <div class="tutor-flex tutor-items-start tutor-justify-start tutor-gap-4"> |
| 72 | <?php if ( $hide_quiz_details ) : ?> |
| 73 | <div class="tutor-medium tutor-font-semibold"> |
| 74 | <?php |
| 75 | /* translators: %d: attempt number */ |
| 76 | echo esc_html( sprintf( __( 'Attempt %d', 'tutor' ), $attempt_number ) ); |
| 77 | ?> |
| 78 | </div> |
| 79 | <?php else : ?> |
| 80 | <a href="<?php echo esc_url( $details_url ); ?>" class="tutor-quiz-item-info-title"> |
| 81 | <?php |
| 82 | /* translators: %d: attempt number */ |
| 83 | echo esc_html( sprintf( __( 'Attempt %d', 'tutor' ), $attempt_number ) ); |
| 84 | ?> |
| 85 | </a> |
| 86 | <?php endif; ?> |
| 87 | </div> |
| 88 | <?php endif; ?> |
| 89 | |
| 90 | <?php if ( ! $is_previous ) : ?> |
| 91 | <div class="tutor-quiz-item-info-course"> |
| 92 | <?php esc_html_e( 'Course:', 'tutor' ); ?> |
| 93 | <?php |
| 94 | PreviewTrigger::make() |
| 95 | ->id( $course_id ?? 0 ) |
| 96 | ->render() |
| 97 | ?> |
| 98 | </div> |
| 99 | <?php endif; ?> |
| 100 | |
| 101 | <div class="tutor-quiz-item-info-date"> |
| 102 | <?php |
| 103 | echo $is_learning_area && ! $hide_quiz_details |
| 104 | ? '<a href="' . esc_url( $details_url ) . '">' . esc_html( $attempt['date'] ?? '' ) . '</a>' |
| 105 | : esc_html( $attempt['date'] ?? '' ); |
| 106 | ?> |
| 107 | </div> |
| 108 | </div> |
| 109 | |
| 110 | <div class="tutor-quiz-item-marks"> |
| 111 | <?php Quiz_Attempts_List::render_quiz_attempt_marks_percentage( $attempt['result'], $attempt['marks_percent'] ); ?> |
| 112 | <div class="tutor-quiz-marks-breakdown"> |
| 113 | <div class="tutor-quiz-marks-correct"> |
| 114 | <?php |
| 115 | /* translators: %d: number of correct answers */ |
| 116 | echo esc_html( sprintf( __( '%d correct', 'tutor' ), $attempt['correct_answers'] ?? 0 ) ); |
| 117 | ?> |
| 118 | </div> |
| 119 | <div class="tutor-quiz-marks-incorrect"> |
| 120 | <?php |
| 121 | /* translators: %d: number of incorrect answers */ |
| 122 | echo esc_html( sprintf( __( '%d incorrect', 'tutor' ), $attempt['incorrect_answers'] ?? 0 ) ); |
| 123 | ?> |
| 124 | </div> |
| 125 | </div> |
| 126 | </div> |
| 127 | |
| 128 | <div class="tutor-quiz-item-time"> |
| 129 | <?php SvgIcon::make()->name( Icon::STOPWATCH )->size( 20 )->color( Color::SECONDARY )->render(); ?> |
| 130 | <?php echo esc_html( $attempt['time_taken'] ?? '' ); ?> |
| 131 | </div> |
| 132 | |
| 133 | <div class="tutor-quiz-item-result"> |
| 134 | <?php |
| 135 | $quiz_attempt_obj->render_quiz_attempt_list_badge( $attempt ); |
| 136 | $quiz_attempt_obj->render_student_attempt_popover( $attempt, $attempts_count, $quiz_id, $is_learning_area ); |
| 137 | ?> |
| 138 | </div> |
| 139 | <?php if ( $attempts_count > 1 ) : ?> |
| 140 | <div class="tutor-quiz-item-actions" x-show="expanded" x-cloak> |
| 141 | <?php |
| 142 | $quiz_attempt_obj->render_details_button( $attempt ); |
| 143 | $quiz_attempt_obj->render_student_attempt_popover( $attempt, $attempts_count, $quiz_id, false, false ); |
| 144 | ?> |
| 145 | </div> |
| 146 | <?php endif; ?> |
| 147 | |
| 148 | <?php if ( $attempt_number && $is_previous ) : ?> |
| 149 | <div class="tutor-quiz-item-actions" x-show="expanded" x-cloak> |
| 150 | <?php |
| 151 | $quiz_attempt_obj->render_details_button( $attempt ); |
| 152 | ?> |
| 153 | </div> |
| 154 | <?php endif; ?> |
| 155 | </div> |
| 156 |