header-context
4 years ago
attempt-details.php
3 years ago
attempt-table.php
3 years ago
contexts.php
4 years ago
header.php
4 years ago
instructor-feedback.php
4 years ago
attempt-table.php
166 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 | * @since 2.07 |
| 26 | */ |
| 27 | if ( $key === 'details' && ! is_admin() && ! current_user_can( 'tutor_instructor') && true === $enabled_hide_quiz_details ) { |
| 28 | continue; |
| 29 | } |
| 30 | ?> |
| 31 | |
| 32 | <th style="<?php echo $key == 'quiz_info' ? 'width: 30%;' : ''; ?>"><?php echo $column; ?></th> |
| 33 | <?php endforeach; ?> |
| 34 | </tr> |
| 35 | </thead> |
| 36 | |
| 37 | <?php |
| 38 | $attempt_ids = array_column($attempt_list, 'attempt_id'); |
| 39 | $answers_array = tutor_utils()->get_quiz_answers_by_attempt_id($attempt_ids, true); |
| 40 | ?> |
| 41 | |
| 42 | <tbody> |
| 43 | <?php foreach ( $attempt_list as $attempt ) : ?> |
| 44 | <?php |
| 45 | $earned_percentage = $attempt->earned_marks > 0 ? ( number_format( ( $attempt->earned_marks * 100 ) / $attempt->total_marks ) ) : 0; |
| 46 | $answers = isset($answers_array[$attempt->attempt_id]) ? $answers_array[$attempt->attempt_id] : array(); |
| 47 | $attempt_info = @unserialize($attempt->attempt_info); |
| 48 | $attempt_info = !is_array($attempt_info) ? array() : $attempt_info; |
| 49 | $passing_grade = isset($attempt_info['passing_grade']) ? (int)$attempt_info['passing_grade'] : 0; |
| 50 | $ans_array = is_array($answers) ? $answers : array(); |
| 51 | |
| 52 | $has_pending = count( array_filter( $ans_array, function( $ans ) { |
| 53 | return $ans->is_correct === null; |
| 54 | })); |
| 55 | |
| 56 | $correct = 0; |
| 57 | $incorrect = 0; |
| 58 | |
| 59 | if ( is_array( $answers ) && count( $answers ) > 0 ) { |
| 60 | foreach ( $answers as $answer ) { |
| 61 | if ( (bool) $answer->is_correct ) { |
| 62 | $correct++; |
| 63 | } else if(!($answer->is_correct===null)) { |
| 64 | $incorrect++; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | ?> |
| 69 | <tr> |
| 70 | <?php foreach ( $table_columns as $key => $column ) : ?> |
| 71 | <?php |
| 72 | /** |
| 73 | * Pro feature: Only for frontend |
| 74 | * @since 2.07 |
| 75 | */ |
| 76 | if ( $key === 'details' && ! is_admin() && ! current_user_can( 'tutor_instructor') && true === $enabled_hide_quiz_details ) { |
| 77 | continue; |
| 78 | } |
| 79 | ?> |
| 80 | <td> |
| 81 | <?php if ( $key == "checkbox" ) : ?> |
| 82 | <div class="tutor-d-flex"> |
| 83 | <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; ?>" /> |
| 84 | </div> |
| 85 | <?php elseif ( $key == "date" ) : ?> |
| 86 | <?php echo date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $attempt->attempt_ended_at ) ); ?> |
| 87 | <?php elseif ( $key == "quiz_info" ) : ?> |
| 88 | <div> |
| 89 | <div class="tutor-fs-7 tutor-fw-normal tutor-color-muted"> |
| 90 | <?php echo date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $attempt->attempt_ended_at ) ); ?> |
| 91 | </div> |
| 92 | <div class="tutor-mt-8"> |
| 93 | <?php |
| 94 | // For admin panel |
| 95 | if ( is_admin() ) { |
| 96 | esc_html_e( get_the_title( $attempt->quiz_id ) ); |
| 97 | } else { |
| 98 | // For frontend |
| 99 | esc_html_e( get_the_title( $attempt->quiz_id ) ); |
| 100 | ?> |
| 101 | <div class="tooltip-wrap tooltip-icon-custom" > |
| 102 | <i class="tutor-icon-circle-info-o tutor-color-muted tutor-ml-4 tutor-fs-7"></i> |
| 103 | <span class="tooltip-txt tooltip-right"> |
| 104 | <?php esc_html_e( get_the_title( $attempt->course_id ) ) ?> |
| 105 | </span> |
| 106 | </div> |
| 107 | <?php |
| 108 | } |
| 109 | ?> |
| 110 | </div> |
| 111 | <div class="tutor-fs-7 tutor-mt-8"> |
| 112 | <?php |
| 113 | $attempt_user = get_userdata( $attempt->user_id ); |
| 114 | $user_name = $attempt_user ? $attempt_user->display_name : ''; |
| 115 | ?> |
| 116 | <span class="tutor-color-secondary"><?php _e( 'Student:', 'tutor' ); ?></span> |
| 117 | <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> |
| 118 | </div> |
| 119 | <?php do_action( 'tutor_quiz/table/after/course_title', $attempt, $context ); ?> |
| 120 | </div> |
| 121 | <?php elseif ( $key == "course" ) : ?> |
| 122 | <?php esc_html_e( get_the_title( $attempt->course_id ) ); ?> |
| 123 | <?php elseif ( $key == "question" ) : ?> |
| 124 | <?php echo count( $answers ); ?> |
| 125 | <?php elseif ( $key == "total_marks" ) : ?> |
| 126 | <?php echo round($attempt->total_marks); ?> |
| 127 | <?php elseif ( $key == "correct_answer" ) : ?> |
| 128 | <?php echo $correct; ?> |
| 129 | <?php elseif ( $key == "incorrect_answer" ) : ?> |
| 130 | <?php echo $incorrect; ?> |
| 131 | <?php elseif ( $key == "earned_marks" ) : ?> |
| 132 | <?php echo round($attempt->earned_marks) . ' ( ' . $earned_percentage . '% )'; ?> |
| 133 | <?php elseif ( $key == "result" ) : ?> |
| 134 | <?php |
| 135 | if ( $has_pending ) { |
| 136 | echo '<span class="tutor-badge-label label-warning">'.__('Pending', 'tutor').'</span>'; |
| 137 | } else { |
| 138 | echo $earned_percentage >= $passing_grade ? |
| 139 | '<span class="tutor-badge-label label-success">' . __( 'Pass', 'tutor' ) . '</span>' : |
| 140 | '<span class="tutor-badge-label label-danger">' . __( 'Fail', 'tutor' ) . '</span>'; |
| 141 | } |
| 142 | ?> |
| 143 | <?php elseif ( $key == "details" ) : ?> |
| 144 | <?php $url = add_query_arg( array( 'view_quiz_attempt_id' => $attempt->attempt_id ), tutor()->current_url ); ?> |
| 145 | <div class="tutor-d-inline-flex tutor-align-center td-action-btns"> |
| 146 | <a href="<?php echo $url; ?>" class="tutor-btn tutor-btn-outline-primary tutor-btn-sm"> |
| 147 | <?php |
| 148 | if ( $has_pending && ( $context == 'frontend-dashboard-students-attempts' || $context == 'backend-dashboard-students-attempts' ) ) { |
| 149 | esc_html_e( 'Review', 'tutor' ); |
| 150 | } else { |
| 151 | esc_html_e( 'Details', 'tutor-pro' ); |
| 152 | } |
| 153 | ?> |
| 154 | </a> |
| 155 | </div> |
| 156 | <?php endif; ?> |
| 157 | </td> |
| 158 | <?php endforeach; ?> |
| 159 | </tr> |
| 160 | <?php endforeach; ?> |
| 161 | </tbody> |
| 162 | </table> |
| 163 | </div> |
| 164 | <?php else : ?> |
| 165 | <?php tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); ?> |
| 166 | <?php endif; ?> |