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