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.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Quiz_Attempts_List.php
tutor / classes Last commit date
Addons.php 4 years ago Admin.php 4 years ago Ajax.php 4 years ago Announcements.php 4 years ago Assets.php 4 years ago Backend_Page_Trait.php 4 years ago Course.php 4 years ago Course_Filter.php 4 years ago Course_List.php 4 years ago Course_Settings_Tabs.php 4 years ago Course_Widget.php 4 years ago Custom_Validation.php 4 years ago Dashboard.php 4 years ago FormHandler.php 4 years ago Frontend.php 4 years ago Gutenberg.php 4 years ago Input.php 4 years ago Instructor.php 4 years ago Instructors_List.php 4 years ago Lesson.php 4 years ago Options_V2.php 4 years ago Post_types.php 4 years ago Private_Course_Access.php 4 years ago Q_and_A.php 4 years ago Question_Answers_List.php 4 years ago Quiz.php 4 years ago Quiz_Attempts_List.php 4 years ago RestAPI.php 4 years ago Reviews.php 4 years ago Rewrite_Rules.php 4 years ago Shortcode.php 4 years ago Student.php 4 years ago Students_List.php 4 years ago Taxonomies.php 4 years ago Template.php 4 years ago Theme_Compatibility.php 5 years ago Tools.php 4 years ago Tools_V2.php 4 years ago Tutor.php 4 years ago TutorEDD.php 4 years ago Tutor_Base.php 5 years ago Tutor_List_Table.php 4 years ago Tutor_Setup.php 4 years ago Upgrader.php 4 years ago User.php 4 years ago Utils.php 4 years ago Video_Stream.php 4 years ago Withdraw.php 4 years ago Withdraw_Requests_List.php 4 years ago WooCommerce.php 4 years ago
Quiz_Attempts_List.php
215 lines
1 <?php
2 namespace TUTOR;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 class Quiz_Attempts_List {
9
10 const QUIZ_ATTEMPT_PAGE = 'tutor_quiz_attempts';
11
12 /**
13 * Trait for utilities
14 *
15 * @var $page_title
16 */
17
18 use Backend_Page_Trait;
19 /**
20 * Page Title
21 *
22 * @var $page_title
23 */
24 public $page_title;
25
26 /**
27 * Bulk Action
28 *
29 * @var $bulk_action
30 */
31 public $bulk_action = true;
32
33 /**
34 * Handle dependencies
35 */
36 public function __construct($register_hook=true) {
37 $this->page_title = __( 'Quiz Attempts', 'tutor' );
38 if(!$register_hook) {
39 return;
40 }
41
42 /**
43 * Handle bulk action
44 *
45 * @since v2.0.0
46 */
47 add_action( 'wp_ajax_tutor_quiz_attempts_bulk_action', array( $this, 'quiz_attempts_bulk_action' ) );
48 }
49
50 /**
51 * @return array
52 *
53 *
54 * Get the attempts stat from specific instructor context
55 *
56 * @since 2.0.0
57 */
58 public function get_quiz_attempts_stat() {
59 global $wpdb;
60
61 // Get total attempt count.
62 // Exclude incomplete attempts by checking if attempt_ended_at not null
63 $all = tutor_utils()->get_quiz_attempts( 0, null, '', '', '', '', null, true, true );
64 $pass = tutor_utils()->get_quiz_attempts( 0, null, '', '', '', '', 'pass', true, true );
65 $fail = tutor_utils()->get_quiz_attempts( 0, null, '', '', '', '', 'fail', true, true );
66 $pending = tutor_utils()->get_quiz_attempts( 0, null, '', '', '', '', 'pending', true, true );
67
68 return compact('all', 'pass', 'fail', 'pending');
69 }
70
71 /**
72 * Available tabs that will visible on the right side of page navbar
73 *
74 * @param string $user_id selected quiz_attempts id | optional.
75 * @param string $date selected date | optional.
76 * @param string $search search by user name or email | optional.
77 * @return array
78 * @since v2.0.0
79 */
80 public function tabs_key_value( $user_id, $course_id, $date, $search ): array {
81 $url = get_pagenum_link();
82 $stats = $this->get_quiz_attempts_stat(get_current_user_id());
83
84 $tabs = array(
85 array(
86 'key' => 'all',
87 'title' => __( 'All', 'tutor' ),
88 'value' => $stats['all'],
89 'url' => $url . '&data=all',
90 ),
91 array(
92 'key' => 'pass',
93 'title' => __( 'Pass', 'tutor' ),
94 'value' => $stats['pass'],
95 'url' => $url . '&data=pass',
96 ),
97 array(
98 'key' => 'fail',
99 'title' => __( 'Fail', 'tutor' ),
100 'value' => $stats['fail'],
101 'url' => $url . '&data=fail',
102 ),
103 array(
104 'key' => 'pending',
105 'title' => __( 'Pending', 'tutor' ),
106 'value' => $stats['pending'],
107 'url' => $url . '&data=pending',
108 ),
109 );
110
111 return $tabs;
112 }
113
114 /**
115 * Prepare bulk actions that will show on dropdown options
116 *
117 * @return array
118 * @since v2.0.0
119 */
120 public function prpare_bulk_actions(): array {
121 $actions = array(
122 $this->bulk_action_default(),
123 $this->bulk_action_delete(),
124 );
125 return $actions;
126 }
127
128 /**
129 * Count enrolled number by status & filters
130 * Count all enrolment | approved | cancelled
131 *
132 * @param string $status | required.
133 * @param string $user_id selected user id | optional.
134 * @param string $date selected date | optional.
135 * @param string $search_term search by user name or email | optional.
136 * @return int
137 * @since v2.0.0
138 */
139 protected static function get_instructor_number( $status = '', $user_id = '', $course_id = '', $attempt_id = '', $date = '', $search_term = '' ): int {
140 global $wpdb;
141 $status = sanitize_text_field( $status );
142 $course_id = sanitize_text_field( $course_id );
143 $user_id = sanitize_text_field( $user_id );
144 $attempt_id = sanitize_text_field( $attempt_id );
145 $date = sanitize_text_field( $date );
146 $search_term = sanitize_text_field( $search_term );
147
148 $search_term = '%' . $wpdb->esc_like( $search_term ) . '%';
149
150 // add user id in where clause.
151 $user_query = '';
152 if ( '' !== $user_id ) {
153 $user_query = "AND user.ID = $user_id";
154 }
155
156 // add quiz id in where clause.
157 $quiz_query = '';
158 if ( '' !== $quiz_id ) {
159 $quiz_query = "AND quiz.ID = $user_id";
160 }
161
162 $count = $wpdb->get_var(
163 $wpdb->prepare(
164 "SELECT COUNT(attempt_id)
165 FROM {$wpdb->prefix}tutor_quiz_attempts quiz_attempts
166 INNER JOIN {$wpdb->tutor_quiz_attempt_answers} quiz
167 ON quiz_attempts.quiz_id = quiz.ID
168 INNER JOIN {$wpdb->users}
169 ON quiz_attempts.user_id = {$wpdb->users}.ID
170 WHERE attempt_status != %s
171 AND ( user_email = %s OR display_name LIKE %s OR post_title LIKE %s )
172 ",
173 'attempt_started',
174 $status,
175 $search_term,
176 $search_term,
177 $search_term,
178 $search_term
179 )
180 );
181 return $count ? $count : 0;
182 }
183
184 /**
185 * Handle bulk action for instructor delete
186 *
187 * @return string JSON response.
188 * @since v2.0.0
189 */
190 public function quiz_attempts_bulk_action() {
191 // check nonce.
192 tutor_utils()->checking_nonce();
193
194 $bulk_action = isset( $_POST['bulk-action'] ) ? sanitize_text_field( $_POST['bulk-action'] ) : '';
195 $bulk_ids = isset( $_POST['bulk-ids'] ) ? sanitize_text_field( $_POST['bulk-ids'] ) :'';
196 $bulk_ids = explode(',', $bulk_ids);
197 $bulk_ids = array_map(function($id){return (int)trim($id);}, $bulk_ids);
198
199 switch($bulk_action) {
200 case 'delete' :
201 tutor_utils()->delete_quiz_attempt( $bulk_ids );
202 break;
203 }
204
205 wp_send_json_success();
206 }
207
208 function get_bulk_actions() {
209 $actions = array(
210 'delete' => 'Delete',
211 );
212 return $actions;
213 }
214 }
215