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
130 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 attempt. |
| 10 | $attempt_data = $attempt_list[0]; |
| 11 | include __DIR__ . '/header.php'; |
| 12 | } |
| 13 | ?> |
| 14 | |
| 15 | <?php if ( is_array( $attempt_list ) && count( $attempt_list ) ): ?> |
| 16 | <div class="tutor-table-responsive tutor-mt-24"> |
| 17 | <table class="tutor-table tutor-table-quiz-attempts"> |
| 18 | <thead> |
| 19 | <tr> |
| 20 | <?php foreach ( $table_columns as $key => $column ) : ?> |
| 21 | <th style="<?php echo $key == 'quiz_info' ? 'width: 30%;' : ''; ?>"><?php echo $column; ?></th> |
| 22 | <?php endforeach; ?> |
| 23 | </tr> |
| 24 | </thead> |
| 25 | |
| 26 | <?php |
| 27 | $attempt_ids = array_column($attempt_list, 'attempt_id'); |
| 28 | $answers_array = tutor_utils()->get_quiz_answers_by_attempt_id($attempt_ids, true); |
| 29 | ?> |
| 30 | |
| 31 | <tbody> |
| 32 | <?php foreach ( $attempt_list as $attempt ) : ?> |
| 33 | <?php |
| 34 | $earned_percentage = $attempt->earned_marks > 0 ? ( number_format( ( $attempt->earned_marks * 100 ) / $attempt->total_marks ) ) : 0; |
| 35 | $answers = isset($answers_array[$attempt->attempt_id]) ? $answers_array[$attempt->attempt_id] : array(); |
| 36 | $attempt_info = @unserialize($attempt->attempt_info); |
| 37 | $attempt_info = !is_array($attempt_info) ? array() : $attempt_info; |
| 38 | $passing_grade = isset($attempt_info['passing_grade']) ? (int)$attempt_info['passing_grade'] : 0; |
| 39 | $ans_array = is_array($answers) ? $answers : array(); |
| 40 | |
| 41 | $has_pending = count( array_filter( $ans_array, function( $ans ) { |
| 42 | return $ans->is_correct === null; |
| 43 | })); |
| 44 | |
| 45 | $correct = 0; |
| 46 | $incorrect = 0; |
| 47 | |
| 48 | if ( is_array( $answers ) && count( $answers ) > 0 ) { |
| 49 | foreach ( $answers as $answer ) { |
| 50 | if ( (bool) $answer->is_correct ) { |
| 51 | $correct++; |
| 52 | } else if(!($answer->is_correct===null)) { |
| 53 | $incorrect++; |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | ?> |
| 58 | <tr> |
| 59 | <?php foreach ( $table_columns as $key => $column ) : ?> |
| 60 | <td> |
| 61 | <?php if ( $key == "checkbox" ) : ?> |
| 62 | <div class="tutor-d-flex"> |
| 63 | <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; ?>" /> |
| 64 | </div> |
| 65 | <?php elseif ( $key == "date" ) : ?> |
| 66 | <?php echo date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $attempt->attempt_ended_at ) ); ?> |
| 67 | <?php elseif ( $key == "quiz_info" ) : ?> |
| 68 | <div> |
| 69 | <div class="tutor-fs-7 tutor-fw-normal tutor-color-muted"> |
| 70 | <?php echo date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $attempt->attempt_ended_at ) ); ?> |
| 71 | </div> |
| 72 | <div class="tutor-mt-8"> |
| 73 | <?php echo get_the_title( $attempt->course_id ); ?> |
| 74 | </div> |
| 75 | <div class="tutor-fs-7 tutor-mt-8"> |
| 76 | <?php |
| 77 | $attempt_user = get_userdata( $attempt->user_id ); |
| 78 | $user_name = $attempt_user ? $attempt_user->display_name : ''; |
| 79 | ?> |
| 80 | <span class="tutor-color-secondary"><?php _e( 'Student:', 'tutor' ); ?></span> |
| 81 | <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> |
| 82 | </div> |
| 83 | <?php do_action( 'tutor_quiz/table/after/course_title', $attempt, $context ); ?> |
| 84 | </div> |
| 85 | <?php elseif ( $key == "course" ) : ?> |
| 86 | <?php echo get_the_title( $attempt->course_id ); ?> |
| 87 | <?php elseif ( $key == "question" ) : ?> |
| 88 | <?php echo count( $answers ); ?> |
| 89 | <?php elseif ( $key == "total_marks" ) : ?> |
| 90 | <?php echo round($attempt->total_marks); ?> |
| 91 | <?php elseif ( $key == "correct_answer" ) : ?> |
| 92 | <?php echo $correct; ?> |
| 93 | <?php elseif ( $key == "incorrect_answer" ) : ?> |
| 94 | <?php echo $incorrect; ?> |
| 95 | <?php elseif ( $key == "earned_marks" ) : ?> |
| 96 | <?php echo round($attempt->earned_marks) . ' ( ' . $earned_percentage . '% )'; ?> |
| 97 | <?php elseif ( $key == "result" ) : ?> |
| 98 | <?php |
| 99 | if ( $has_pending ) { |
| 100 | echo '<span class="tutor-badge-label label-warning">'.__('Pending', 'tutor').'</span>'; |
| 101 | } else { |
| 102 | echo $earned_percentage >= $passing_grade ? |
| 103 | '<span class="tutor-badge-label label-success">' . __( 'Pass', 'tutor' ) . '</span>' : |
| 104 | '<span class="tutor-badge-label label-danger">' . __( 'Fail', 'tutor' ) . '</span>'; |
| 105 | } |
| 106 | ?> |
| 107 | <?php elseif ( $key == "details" ) : ?> |
| 108 | <?php $url = add_query_arg( array( 'view_quiz_attempt_id' => $attempt->attempt_id ), tutor()->current_url ); ?> |
| 109 | <div class="tutor-d-inline-flex tutor-align-center td-action-btns"> |
| 110 | <a href="<?php echo $url; ?>" class="tutor-btn tutor-btn-outline-primary tutor-btn-sm"> |
| 111 | <?php |
| 112 | if ( $has_pending && ( $context == 'frontend-dashboard-students-attempts' || $context == 'backend-dashboard-students-attempts' ) ) { |
| 113 | esc_html_e( 'Review', 'tutor' ); |
| 114 | } else { |
| 115 | esc_html_e( 'Details', 'tutor-pro' ); |
| 116 | } |
| 117 | ?> |
| 118 | </a> |
| 119 | </div> |
| 120 | <?php endif; ?> |
| 121 | </td> |
| 122 | <?php endforeach; ?> |
| 123 | </tr> |
| 124 | <?php endforeach; ?> |
| 125 | </tbody> |
| 126 | </table> |
| 127 | </div> |
| 128 | <?php else : ?> |
| 129 | <?php tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); ?> |
| 130 | <?php endif; ?> |