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.2 3.5.0 3.6.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 5 years ago Dashboard.php 4 years ago FormHandler.php 4 years ago Frontend.php 4 years ago Gutenberg.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
218 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 * @param int context $instructor_id
52 *
53 * @return array
54 *
55 *
56 * Get the attempts stat from specific instructor context
57 *
58 * @since 2.0.0
59 */
60 public function get_quiz_attempts_stat($instructor_id) {
61 global $wpdb;
62
63 // Get total attempt count.
64 // Exclude incomplete attempts by checking if attempt_ended_at not null
65 $all = tutor_utils()->get_quiz_attempts( 0, null, '', '', '', '', null, true );
66
67 $pass = tutor_utils()->get_quiz_attempts( 0, null, '', '', '', '', 'pass', true );
68 $fail = tutor_utils()->get_quiz_attempts( 0, null, '', '', '', '', 'fail', true );
69 $pending = tutor_utils()->get_quiz_attempts( 0, null, '', '', '', '', 'pending', true );
70
71 return compact('all', 'pass', 'fail', 'pending');
72 }
73
74 /**
75 * Available tabs that will visible on the right side of page navbar
76 *
77 * @param string $user_id selected quiz_attempts id | optional.
78 * @param string $date selected date | optional.
79 * @param string $search search by user name or email | optional.
80 * @return array
81 * @since v2.0.0
82 */
83 public function tabs_key_value( $user_id, $course_id, $date, $search ): array {
84 $url = get_pagenum_link();
85 $stats = $this->get_quiz_attempts_stat(get_current_user_id());
86
87 $tabs = array(
88 array(
89 'key' => 'all',
90 'title' => __( 'All', 'tutor' ),
91 'value' => $stats['all'],
92 'url' => $url . '&data=all',
93 ),
94 array(
95 'key' => 'pass',
96 'title' => __( 'Pass', 'tutor' ),
97 'value' => $stats['pass'],
98 'url' => $url . '&data=pass',
99 ),
100 array(
101 'key' => 'fail',
102 'title' => __( 'Fail', 'tutor' ),
103 'value' => $stats['fail'],
104 'url' => $url . '&data=fail',
105 ),
106 array(
107 'key' => 'pending',
108 'title' => __( 'Pending', 'tutor' ),
109 'value' => $stats['pending'],
110 'url' => $url . '&data=pending',
111 ),
112 );
113
114 return $tabs;
115 }
116
117 /**
118 * Prepare bulk actions that will show on dropdown options
119 *
120 * @return array
121 * @since v2.0.0
122 */
123 public function prpare_bulk_actions(): array {
124 $actions = array(
125 $this->bulk_action_default(),
126 $this->bulk_action_delete(),
127 );
128 return $actions;
129 }
130
131 /**
132 * Count enrolled number by status & filters
133 * Count all enrollment | approved | cancelled
134 *
135 * @param string $status | required.
136 * @param string $user_id selected user id | optional.
137 * @param string $date selected date | optional.
138 * @param string $search_term search by user name or email | optional.
139 * @return int
140 * @since v2.0.0
141 */
142 protected static function get_instructor_number( $status = '', $user_id = '', $course_id = '', $attempt_id = '', $date = '', $search_term = '' ): int {
143 global $wpdb;
144 $status = sanitize_text_field( $status );
145 $course_id = sanitize_text_field( $course_id );
146 $user_id = sanitize_text_field( $user_id );
147 $attempt_id = sanitize_text_field( $attempt_id );
148 $date = sanitize_text_field( $date );
149 $search_term = sanitize_text_field( $search_term );
150
151 $search_term = '%' . $wpdb->esc_like( $search_term ) . '%';
152
153 // add user id in where clause.
154 $user_query = '';
155 if ( '' !== $user_id ) {
156 $user_query = "AND user.ID = $user_id";
157 }
158
159 // add quiz id in where clause.
160 $quiz_query = '';
161 if ( '' !== $quiz_id ) {
162 $quiz_query = "AND quiz.ID = $user_id";
163 }
164
165 $count = $wpdb->get_var(
166 $wpdb->prepare(
167 "SELECT COUNT(attempt_id)
168 FROM {$wpdb->prefix}tutor_quiz_attempts quiz_attempts
169 INNER JOIN {$wpdb->tutor_quiz_attempt_answers} quiz
170 ON quiz_attempts.quiz_id = quiz.ID
171 INNER JOIN {$wpdb->users}
172 ON quiz_attempts.user_id = {$wpdb->users}.ID
173 WHERE attempt_status != %s
174 AND ( user_email LIKE %s OR display_name LIKE %s OR post_title LIKE %s )
175 ",
176 'attempt_started',
177 $status,
178 $search_term,
179 $search_term,
180 $search_term,
181 $search_term
182 )
183 );
184 return $count ? $count : 0;
185 }
186
187 /**
188 * Handle bulk action for instructor delete
189 *
190 * @return string JSON response.
191 * @since v2.0.0
192 */
193 public function quiz_attempts_bulk_action() {
194 // check nonce.
195 tutor_utils()->checking_nonce();
196
197 $bulk_action = isset( $_POST['bulk-action'] ) ? sanitize_text_field( $_POST['bulk-action'] ) : '';
198 $bulk_ids = isset( $_POST['bulk-ids'] ) ? sanitize_text_field( $_POST['bulk-ids'] ) :'';
199 $bulk_ids = explode(',', $bulk_ids);
200 $bulk_ids = array_map(function($id){return (int)trim($id);}, $bulk_ids);
201
202 switch($bulk_action) {
203 case 'delete' :
204 tutor_utils()->delete_quiz_attempt( $bulk_ids );
205 break;
206 }
207
208 wp_send_json_success();
209 }
210
211 function get_bulk_actions() {
212 $actions = array(
213 'delete' => 'Delete',
214 );
215 return $actions;
216 }
217 }
218