header-context
3 years ago
attempt-details.php
3 years ago
attempt-table.php
3 years ago
contexts.php
3 years ago
header.php
3 years ago
instructor-feedback.php
3 years ago
attempt-table.php
208 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Attempt table |
| 4 | * |
| 5 | * @package Tutor\Views |
| 6 | * @subpackage Tutor\Quiz |
| 7 | * @author Themeum <support@themeum.com> |
| 8 | * @link https://themeum.com |
| 9 | * @since 1.0.0 |
| 10 | */ |
| 11 | |
| 12 | extract( $data ); // $attempt_list, $context; |
| 13 | |
| 14 | $page_key = 'attempt-table'; |
| 15 | $table_columns = include __DIR__ . '/contexts.php'; |
| 16 | $enabled_hide_quiz_details = tutor_utils()->get_option( 'hide_quiz_details' ); |
| 17 | |
| 18 | if ( 'course-single-previous-attempts' == $context && is_array( $attempt_list ) && count( $attempt_list ) ) { |
| 19 | // Provide the attempt data from the first attempt |
| 20 | // For now now attempt specific data is shown, that's why no problem if we take meta data from any attempt. |
| 21 | $attempt_data = $attempt_list[0]; |
| 22 | include __DIR__ . '/header.php'; |
| 23 | } |
| 24 | ?> |
| 25 | |
| 26 | <?php if ( is_array( $attempt_list ) && count( $attempt_list ) ) : ?> |
| 27 | <div class="tutor-table-responsive tutor-my-24"> |
| 28 | <table class="tutor-table tutor-table-quiz-attempts"> |
| 29 | <thead> |
| 30 | <tr> |
| 31 | <?php foreach ( $table_columns as $key => $column ) : ?> |
| 32 | <?php |
| 33 | /** |
| 34 | * Pro feature: Only for frontend |
| 35 | * |
| 36 | * @since 2.07 |
| 37 | */ |
| 38 | if ( 'details' === $key && ! is_admin() && ! current_user_can( 'tutor_instructor' ) && true === $enabled_hide_quiz_details ) { |
| 39 | continue; |
| 40 | } |
| 41 | ?> |
| 42 | |
| 43 | <th><?php echo $column; //phpcs:ignore -- contain safe data ?></th> |
| 44 | <?php endforeach; ?> |
| 45 | </tr> |
| 46 | </thead> |
| 47 | |
| 48 | <?php |
| 49 | $attempt_ids = array_column( $attempt_list, 'attempt_id' ); |
| 50 | $answers_array = \Tutor\Models\QuizModel::get_quiz_answers_by_attempt_id( $attempt_ids, true ); |
| 51 | ?> |
| 52 | |
| 53 | <tbody> |
| 54 | <?php foreach ( $attempt_list as $attempt ) : ?> |
| 55 | <?php |
| 56 | $course_id = is_object( $attempt ) && property_exists( $attempt, 'course_id' ) ? $attempt->course_id : 0; |
| 57 | $earned_percentage = $attempt->earned_marks > 0 ? ( number_format( ( $attempt->earned_marks * 100 ) / $attempt->total_marks ) ) : 0; |
| 58 | $answers = isset( $answers_array[ $attempt->attempt_id ] ) ? $answers_array[ $attempt->attempt_id ] : array(); |
| 59 | $attempt_info = @unserialize( $attempt->attempt_info ); |
| 60 | $attempt_info = ! is_array( $attempt_info ) ? array() : $attempt_info; |
| 61 | $passing_grade = isset( $attempt_info['passing_grade'] ) ? (int) $attempt_info['passing_grade'] : 0; |
| 62 | $ans_array = is_array( $answers ) ? $answers : array(); |
| 63 | |
| 64 | $has_pending = count( |
| 65 | array_filter( |
| 66 | $ans_array, |
| 67 | function( $ans ) { |
| 68 | return null === $ans->is_correct; |
| 69 | } |
| 70 | ) |
| 71 | ); |
| 72 | |
| 73 | $correct = 0; |
| 74 | $incorrect = 0; |
| 75 | $attempt_id = $attempt->attempt_id; |
| 76 | |
| 77 | if ( is_array( $answers ) && count( $answers ) > 0 ) { |
| 78 | foreach ( $answers as $answer ) { |
| 79 | if ( (bool) $answer->is_correct ) { |
| 80 | $correct++; |
| 81 | } elseif ( ! ( null === $answer->is_correct ) ) { |
| 82 | $incorrect++; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | ?> |
| 87 | <tr> |
| 88 | <?php foreach ( $table_columns as $key => $column ) : ?> |
| 89 | <?php |
| 90 | /** |
| 91 | * Pro feature: Only for frontend |
| 92 | * |
| 93 | * @since 2.07 |
| 94 | */ |
| 95 | if ( 'details' === $key && ! is_admin() && ! current_user_can( 'tutor_instructor' ) && true === $enabled_hide_quiz_details ) { |
| 96 | continue; |
| 97 | } |
| 98 | ?> |
| 99 | <td> |
| 100 | <?php if ( 'checkbox' == $key ) : ?> |
| 101 | <div class="tutor-d-flex"> |
| 102 | <input id="tutor-admin-list-<?php echo esc_attr( $attempt->attempt_id ); ?>" type="checkbox" class="tutor-form-check-input tutor-bulk-checkbox" name="tutor-bulk-checkbox-all" value="<?php echo esc_attr( $attempt->attempt_id ); ?>" /> |
| 103 | </div> |
| 104 | <?php elseif ( 'date' == $key ) : ?> |
| 105 | <?php echo esc_html( date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $attempt->attempt_ended_at ) ) ); ?> |
| 106 | <?php elseif ( 'quiz_info' == $key ) : ?> |
| 107 | <div> |
| 108 | <div class="tutor-fs-7 tutor-fw-normal"> |
| 109 | <?php echo esc_html( date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $attempt->attempt_ended_at ) ) ); ?> |
| 110 | </div> |
| 111 | <div class="tutor-mt-4"> |
| 112 | <?php |
| 113 | // For admin panel. |
| 114 | if ( is_admin() ) { |
| 115 | echo esc_html( get_the_title( $attempt->quiz_id ) ); |
| 116 | } else { |
| 117 | // For frontend. |
| 118 | echo esc_html( get_the_title( $attempt->quiz_id ) ); |
| 119 | ?> |
| 120 | <div class="tooltip-wrap tooltip-icon-custom" > |
| 121 | <i class="tutor-icon-circle-info-o tutor-color-muted tutor-ml-4 tutor-fs-7"></i> |
| 122 | <span class="tooltip-txt tooltip-right"> |
| 123 | <?php echo esc_html( get_the_title( $attempt->course_id ) ); ?> |
| 124 | </span> |
| 125 | </div> |
| 126 | <?php |
| 127 | } |
| 128 | ?> |
| 129 | </div> |
| 130 | <div class="tutor-fs-7 tutor-mt-8"> |
| 131 | <?php |
| 132 | $attempt_user = get_userdata( $attempt->user_id ); |
| 133 | $user_name = $attempt_user ? $attempt_user->display_name : ''; |
| 134 | ?> |
| 135 | <span class="tutor-color-secondary"><?php esc_html_e( 'Student:', 'tutor' ); ?></span> |
| 136 | <span class="tutor-fw-normal tutor-color-muted"><?php echo 'backend-dashboard-students-attempts' == $context ? esc_html( $user_name ) : esc_attr( isset( $attempt->display_name ) ? $attempt->display_name : $user_name ); ?></span> |
| 137 | </div> |
| 138 | <?php do_action( 'tutor_quiz/table/after/course_title', $attempt, $context ); ?> |
| 139 | </div> |
| 140 | <?php elseif ( 'course' == $key ) : ?> |
| 141 | <?php echo esc_html( get_the_title( $attempt->course_id ) ); ?> |
| 142 | <?php elseif ( 'question' == $key ) : ?> |
| 143 | <?php echo esc_html( count( $answers ) ); ?> |
| 144 | <?php elseif ( 'total_marks' == $key ) : ?> |
| 145 | <?php echo esc_html( round( $attempt->total_marks ) ); ?> |
| 146 | <?php elseif ( 'correct_answer' == $key ) : ?> |
| 147 | <?php echo esc_html( $correct ); ?> |
| 148 | <?php elseif ( 'incorrect_answer' == $key ) : ?> |
| 149 | <?php echo esc_html( $incorrect ); ?> |
| 150 | <?php elseif ( 'earned_marks' == $key ) : ?> |
| 151 | <?php echo esc_html( round( $attempt->earned_marks ) . ' (' . $earned_percentage . '%)' ); ?> |
| 152 | <?php elseif ( 'result' == $key ) : ?> |
| 153 | <?php |
| 154 | if ( $has_pending ) { |
| 155 | echo '<span class="tutor-badge-label label-warning">' . esc_html__( 'Pending', 'tutor' ) . '</span>'; |
| 156 | } else { |
| 157 | echo $earned_percentage >= $passing_grade ? |
| 158 | '<span class="tutor-badge-label label-success">' . esc_html__( 'Pass', 'tutor' ) . '</span>' : |
| 159 | '<span class="tutor-badge-label label-danger">' . esc_html__( 'Fail', 'tutor' ) . '</span>'; |
| 160 | } |
| 161 | ?> |
| 162 | <?php elseif ( 'details' == $key ) : ?> |
| 163 | <?php |
| 164 | $url = add_query_arg( array( 'view_quiz_attempt_id' => $attempt->attempt_id ), tutor()->current_url ); |
| 165 | $style = ''; |
| 166 | ?> |
| 167 | <div class="tutor-d-inline-flex tutor-align-center" style="<?php echo esc_attr( ! is_admin() ? $style : '' ); ?>"> |
| 168 | <a href="<?php echo esc_url( $url ); ?>" class="tutor-btn tutor-btn-outline-primary tutor-btn-sm"> |
| 169 | <?php |
| 170 | if ( $has_pending && ( 'frontend-dashboard-students-attempts' == $context || 'backend-dashboard-students-attempts' == $context ) ) { |
| 171 | esc_html_e( 'Review', 'tutor' ); |
| 172 | } else { |
| 173 | esc_html_e( 'Details', 'tutor-pro' ); |
| 174 | } |
| 175 | ?> |
| 176 | </a> |
| 177 | <?php |
| 178 | $current_page = tutor_utils()->get_current_page_slug(); |
| 179 | if ( ! is_admin() && $course_id && ( tutor_utils()->is_instructor_of_this_course( get_current_user_id(), $course_id ) || current_user_can( 'administrator' ) ) ) : |
| 180 | ?> |
| 181 | <!-- Don't show delete option on the spotlight section since JS not support --> |
| 182 | <?php if ( 'quiz-attempts' === $current_page || 'tutor_quiz_attempts' === $current_page ) : ?> |
| 183 | <a href="#" class="tutor-quiz-attempt-delete tutor-iconic-btn tutor-flex-shrink-0 tutor-ml-4" data-quiz-id="<?php echo esc_attr( $attempt_id ); ?>" data-tutor-modal-target="tutor-common-confirmation-modal"> |
| 184 | <i class="tutor-icon-trash-can-line" data-quiz-id="<?php echo esc_attr( $attempt_id ); ?>"></i> |
| 185 | </a> |
| 186 | <?php endif; ?> |
| 187 | <?php endif; ?> |
| 188 | </div> |
| 189 | <?php endif; ?> |
| 190 | </td> |
| 191 | <?php endforeach; ?> |
| 192 | </tr> |
| 193 | <?php endforeach; ?> |
| 194 | </tbody> |
| 195 | </table> |
| 196 | </div> |
| 197 | <?php else : ?> |
| 198 | <?php tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); ?> |
| 199 | <?php endif; ?> |
| 200 | <?php |
| 201 | // Load delete modal. |
| 202 | tutor_load_template_from_custom_path( |
| 203 | tutor()->path . 'views/elements/common-confirm-popup.php', |
| 204 | array( |
| 205 | 'message' => __( 'Would you like to delete Quiz Attempt permanently? We suggest you proceed with caution.', 'tutor' ), |
| 206 | ) |
| 207 | ); |
| 208 |