header-context
4 years ago
attempt-details.php
4 years ago
attempt-table.php
4 years ago
contexts.php
4 years ago
header.php
4 years ago
instructor-feedback.php
4 years ago
attempt-table.php
244 lines
| 1 | <?php |
| 2 | extract( $data ); // $attempt_list, $context; |
| 3 | |
| 4 | $page_key = 'attempt-table'; |
| 5 | $table_columns = include __DIR__ . '/contexts.php'; |
| 6 | |
| 7 | if ( $context == 'course-single-previous-attempts' && is_array( $attempt_list ) && count( $attempt_list ) ) { |
| 8 | // Provide the attempt data from the first attempt |
| 9 | // For now now attempt specific data is shown, that's why no problem if we take meta data from any atttempt. |
| 10 | $attempt_data = $attempt_list[0]; |
| 11 | include __DIR__ . '/header.php'; |
| 12 | } |
| 13 | ?> |
| 14 | |
| 15 | <div class="tutor-table-wrapper tutor-my-24"> |
| 16 | <table class="tutor-table tutor-table-responsive my-quiz-attempts"> |
| 17 | <?php if ( is_array( $attempt_list ) && count( $attempt_list ) ) { ?> |
| 18 | <thead> |
| 19 | <tr> |
| 20 | <?php |
| 21 | foreach ( $table_columns as $key => $column ) { |
| 22 | echo '<th> |
| 23 | <div class="tutor-fs-7 tutor-color-secondary"> |
| 24 | ' . $column . ' |
| 25 | </div> |
| 26 | </th>'; |
| 27 | } |
| 28 | ?> |
| 29 | </tr> |
| 30 | </thead> |
| 31 | <?php } ?> |
| 32 | <tbody> |
| 33 | <?php |
| 34 | if ( is_array( $attempt_list ) && count( $attempt_list ) ) { |
| 35 | foreach ( $attempt_list as $attempt ) { |
| 36 | $attempt_action = tutor_utils()->get_tutor_dashboard_page_permalink( 'my-quiz-attempts/attempts-details/?attempt_id=' . $attempt->attempt_id ); |
| 37 | $earned_percentage = $attempt->earned_marks > 0 ? ( number_format( ( $attempt->earned_marks * 100 ) / $attempt->total_marks ) ) : 0; |
| 38 | $answers = tutor_utils()->get_quiz_answers_by_attempt_id( $attempt->attempt_id ); |
| 39 | |
| 40 | $attempt_info = @unserialize($attempt->attempt_info); |
| 41 | $attempt_info = !is_array($attempt_info) ? array() : $attempt_info; |
| 42 | $passing_grade = isset($attempt_info['passing_grade']) ? (int)$attempt_info['passing_grade'] : 0; |
| 43 | |
| 44 | $ans_array = is_array($answers) ? $answers : array(); |
| 45 | $has_pending = count(array_filter($ans_array, function($ans){ |
| 46 | return $ans->is_correct===null; |
| 47 | })); |
| 48 | |
| 49 | $correct = 0; |
| 50 | $incorrect = 0; |
| 51 | if ( is_array( $answers ) && count( $answers ) > 0 ) { |
| 52 | foreach ( $answers as $answer ) { |
| 53 | if ( (bool) $answer->is_correct ) { |
| 54 | $correct++; |
| 55 | } else if(!($answer->is_correct===null)) { |
| 56 | $incorrect++; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | ?> |
| 61 | <tr> |
| 62 | <?php |
| 63 | foreach ( $table_columns as $key => $column ) { |
| 64 | switch ( $key ) { |
| 65 | case 'checkbox': |
| 66 | ?> |
| 67 | <td data-th="<?php _e( 'Mark', 'tutor' ); ?>" class="v-align-top"> |
| 68 | <div class="td-checkbox tutor-d-flex "> |
| 69 | <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; ?>" /> |
| 70 | </div> |
| 71 | </td> |
| 72 | <?php |
| 73 | break; |
| 74 | |
| 75 | case 'date': |
| 76 | ?> |
| 77 | <td data-th="<?php echo $column; ?>"> |
| 78 | <div class="td-statement-info"> |
| 79 | <span class="tutor-fs-7 tutor-color-black"> |
| 80 | <?php echo date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $attempt->attempt_ended_at ) ); ?> |
| 81 | </span> |
| 82 | </div> |
| 83 | </td> |
| 84 | <?php |
| 85 | break; |
| 86 | |
| 87 | case 'quiz_info': |
| 88 | ?> |
| 89 | <td data-th="<?php echo $column; ?>"> |
| 90 | <div class="td-statement-info"> |
| 91 | <span class="tutor-fs-7 tutor-color-black"> |
| 92 | <?php echo date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $attempt->attempt_ended_at ) ); ?> |
| 93 | </span> |
| 94 | <div class="tutor-fs-6 tutor-fw-medium tutor-color-black tutor-margin-0"> |
| 95 | <div class="tutor-fs-6 tutor-fw-medium tutor-color-black" data-href="<?php echo get_the_permalink( $attempt->course_id ); ?>"> |
| 96 | <?php echo get_the_title( $attempt->course_id ); ?> |
| 97 | </div> |
| 98 | <?php |
| 99 | $attempt_user = get_userdata( $attempt->user_id ); |
| 100 | $user_name = $attempt_user ? $attempt_user->display_name : ''; |
| 101 | if ( $context == 'backend-dashboard-students-attempts' ) { |
| 102 | $attempt_user = get_userdata( $attempt->user_id ); |
| 103 | $user_name = $attempt_user ? $attempt_user->display_name : ''; |
| 104 | |
| 105 | ?> |
| 106 | <div> |
| 107 | <span class="tutor-fs-7 tutor-color-secondary"> |
| 108 | <?php _e( 'Student', 'tutor' ); ?> |
| 109 | </span>: <span class="tutor-fs-7 tutor-fw-medium"> <?php echo $user_name; ?> </span> |
| 110 | </div> |
| 111 | <?php |
| 112 | } else { |
| 113 | ?> |
| 114 | <?php if(!empty($user_name) && isset( $attempt->user_email ) ) : ?> |
| 115 | <span class="tutor-fs-7 tutor-color-secondary"><?php esc_html_e( 'Student', 'tutor' ); ?>: </span> |
| 116 | <span class="tutor-color-secondary tutor-fs-8 tutor-fw-medium" title="<?php echo esc_attr( $attempt->user_email ); ?>"> |
| 117 | <?php echo esc_attr( isset($attempt->display_name) ? $attempt->display_name : $user_name ); ?> |
| 118 | </span> |
| 119 | |
| 120 | <?php endif; |
| 121 | } |
| 122 | ?> |
| 123 | </div> |
| 124 | <?php do_action( 'tutor_quiz/table/after/course_title', $attempt, $context ); ?> |
| 125 | </div> |
| 126 | </div> |
| 127 | </td> |
| 128 | <?php |
| 129 | break; |
| 130 | |
| 131 | case 'course': |
| 132 | ?> |
| 133 | <td data-th="<?php echo $column; ?>"> |
| 134 | <span class="tutor-fs-7 tutor-fw-medium tutor-color-black"> |
| 135 | <?php echo get_the_title( $attempt->course_id ); ?> |
| 136 | </span> |
| 137 | </td> |
| 138 | <?php |
| 139 | break; |
| 140 | |
| 141 | case 'question': |
| 142 | ?> |
| 143 | <td data-th="<?php echo $column; ?>"> |
| 144 | <span class="tutor-fs-7 tutor-fw-medium tutor-color-black"> |
| 145 | <?php echo count( $answers ); ?> |
| 146 | </span> |
| 147 | </td> |
| 148 | <?php |
| 149 | break; |
| 150 | |
| 151 | case 'total_marks': |
| 152 | ?> |
| 153 | <td data-th="<?php echo $column; ?>"> |
| 154 | <span class="tutor-fs-7 tutor-fw-medium tutor-color-black"> |
| 155 | <?php echo round($attempt->total_marks); ?> |
| 156 | </span> |
| 157 | </td> |
| 158 | <?php |
| 159 | break; |
| 160 | |
| 161 | case 'correct_answer': |
| 162 | ?> |
| 163 | <td data-th="<?php echo $column; ?>"> |
| 164 | <span class="tutor-fs-7 tutor-fw-medium tutor-color-black"> |
| 165 | <?php echo $correct; ?> |
| 166 | </span> |
| 167 | </td> |
| 168 | <?php |
| 169 | break; |
| 170 | |
| 171 | case 'incorrect_answer': |
| 172 | ?> |
| 173 | <td data-th="<?php echo $column; ?>"> |
| 174 | <span class="tutor-fs-7 tutor-fw-medium tutor-color-black"> |
| 175 | <?php echo $incorrect; ?> |
| 176 | </span> |
| 177 | </td> |
| 178 | <?php |
| 179 | break; |
| 180 | |
| 181 | case 'earned_marks': |
| 182 | ?> |
| 183 | <td data-th="<?php echo $column; ?>"> |
| 184 | <span class="tutor-fs-7 tutor-fw-medium tutor-color-black"> |
| 185 | <?php echo round($attempt->earned_marks) . ' (' . $earned_percentage . '% )'; ?> |
| 186 | </span> |
| 187 | </td> |
| 188 | <?php |
| 189 | break; |
| 190 | |
| 191 | case 'result': |
| 192 | ?> |
| 193 | <td data-th="<?php echo $column; ?>"> |
| 194 | <?php |
| 195 | if($has_pending){ |
| 196 | echo '<span class="tutor-badge-label label-warning">'.__('Pending', 'tutor').'</span>'; |
| 197 | } else { |
| 198 | echo $earned_percentage >= $passing_grade ? |
| 199 | '<span class="tutor-badge-label label-success">' . __( 'Pass', 'tutor' ) . '</span>' : |
| 200 | '<span class="tutor-badge-label label-danger">' . __( 'Fail', 'tutor' ) . '</span>'; |
| 201 | } |
| 202 | ?> |
| 203 | </td> |
| 204 | <?php |
| 205 | break; |
| 206 | |
| 207 | case 'details': |
| 208 | $url = add_query_arg( array( 'view_quiz_attempt_id' => $attempt->attempt_id ), tutor()->current_url ); |
| 209 | ?> |
| 210 | <td data-th="See Details"> |
| 211 | <div class="tutor-d-inline-flex tutor-align-center td-action-btns"> |
| 212 | <a href="<?php echo $url; ?>" class="tutor-btn tutor-btn-outline-primary tutor-btn-sm"> |
| 213 | <?php |
| 214 | if ( $has_pending && ( $context == 'frontend-dashboard-students-attempts' || $context == 'backend-dashboard-students-attempts' ) ) { |
| 215 | esc_html_e( 'Review', 'tutor' ); |
| 216 | } else { |
| 217 | esc_html_e( 'Details', 'tutor-pro' ); |
| 218 | } |
| 219 | ?> |
| 220 | </a> |
| 221 | </div> |
| 222 | </td> |
| 223 | <?php |
| 224 | break; |
| 225 | } |
| 226 | } |
| 227 | ?> |
| 228 | </tr> |
| 229 | <?php |
| 230 | } |
| 231 | } else { |
| 232 | ?> |
| 233 | <tr> |
| 234 | <td colspan="100%" class="column-empty-state"> |
| 235 | <?php tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); ?> |
| 236 | </td> |
| 237 | </tr> |
| 238 | <?php |
| 239 | } |
| 240 | ?> |
| 241 | </tbody> |
| 242 | </table> |
| 243 | </div> |
| 244 |