@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Admin Analysis Course Data Table in Sensei. |
@@ -20,27 +20,27 @@ discard block |
||
20 | 20 | * Constructor |
21 | 21 | * @since 1.2.0 |
22 | 22 | */ |
23 | - public function __construct ( $course_id = 0, $user_id = 0 ) { |
|
24 | - $this->course_id = intval( $course_id ); |
|
25 | - $this->user_id = intval( $user_id ); |
|
23 | + public function __construct($course_id = 0, $user_id = 0) { |
|
24 | + $this->course_id = intval($course_id); |
|
25 | + $this->user_id = intval($user_id); |
|
26 | 26 | |
27 | - if( isset( $_GET['view'] ) && in_array( $_GET['view'], array( 'user', 'lesson' ) ) ) { |
|
27 | + if (isset($_GET['view']) && in_array($_GET['view'], array('user', 'lesson'))) { |
|
28 | 28 | $this->view = $_GET['view']; |
29 | 29 | } |
30 | 30 | |
31 | 31 | // Viewing a single Learner always sets the view to Lessons |
32 | - if( $this->user_id ) { |
|
32 | + if ($this->user_id) { |
|
33 | 33 | $this->view = 'lesson'; |
34 | 34 | } |
35 | 35 | |
36 | 36 | // Load Parent token into constructor |
37 | - parent::__construct( 'analysis_course' ); |
|
37 | + parent::__construct('analysis_course'); |
|
38 | 38 | |
39 | 39 | // Actions |
40 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
41 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
40 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
41 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
42 | 42 | |
43 | - add_filter( 'sensei_list_table_search_button_text', array( $this, 'search_button' ) ); |
|
43 | + add_filter('sensei_list_table_search_button_text', array($this, 'search_button')); |
|
44 | 44 | |
45 | 45 | } // End __construct() |
46 | 46 | |
@@ -51,45 +51,45 @@ discard block |
||
51 | 51 | */ |
52 | 52 | function get_columns() { |
53 | 53 | |
54 | - switch( $this->view ) { |
|
54 | + switch ($this->view) { |
|
55 | 55 | case 'user' : |
56 | 56 | $columns = array( |
57 | - 'title' => __( 'Learner', 'woothemes-sensei' ), |
|
58 | - 'started' => __( 'Date Started', 'woothemes-sensei' ), |
|
59 | - 'completed' => __( 'Date Completed', 'woothemes-sensei' ), |
|
60 | - 'user_status' => __( 'Status', 'woothemes-sensei' ), |
|
61 | - 'percent' => __( 'Percent Complete', 'woothemes-sensei' ), |
|
57 | + 'title' => __('Learner', 'woothemes-sensei'), |
|
58 | + 'started' => __('Date Started', 'woothemes-sensei'), |
|
59 | + 'completed' => __('Date Completed', 'woothemes-sensei'), |
|
60 | + 'user_status' => __('Status', 'woothemes-sensei'), |
|
61 | + 'percent' => __('Percent Complete', 'woothemes-sensei'), |
|
62 | 62 | ); |
63 | 63 | break; |
64 | 64 | |
65 | 65 | case 'lesson' : |
66 | 66 | default: |
67 | - if ( $this->user_id ) { |
|
67 | + if ($this->user_id) { |
|
68 | 68 | |
69 | 69 | $columns = array( |
70 | - 'title' => __( 'Lesson', 'woothemes-sensei' ), |
|
71 | - 'started' => __( 'Date Started', 'woothemes-sensei' ), |
|
72 | - 'completed' => __( 'Date Completed', 'woothemes-sensei' ), |
|
73 | - 'user_status' => __( 'Status', 'woothemes-sensei' ), |
|
74 | - 'grade' => __( 'Grade', 'woothemes-sensei' ), |
|
70 | + 'title' => __('Lesson', 'woothemes-sensei'), |
|
71 | + 'started' => __('Date Started', 'woothemes-sensei'), |
|
72 | + 'completed' => __('Date Completed', 'woothemes-sensei'), |
|
73 | + 'user_status' => __('Status', 'woothemes-sensei'), |
|
74 | + 'grade' => __('Grade', 'woothemes-sensei'), |
|
75 | 75 | ); |
76 | 76 | |
77 | 77 | } else { |
78 | 78 | |
79 | 79 | $columns = array( |
80 | - 'title' => __( 'Lesson', 'woothemes-sensei' ), |
|
81 | - 'num_learners' => __( 'Learners', 'woothemes-sensei' ), |
|
82 | - 'completions' => __( 'Completed', 'woothemes-sensei' ), |
|
83 | - 'average_grade' => __( 'Average Grade', 'woothemes-sensei' ), |
|
80 | + 'title' => __('Lesson', 'woothemes-sensei'), |
|
81 | + 'num_learners' => __('Learners', 'woothemes-sensei'), |
|
82 | + 'completions' => __('Completed', 'woothemes-sensei'), |
|
83 | + 'average_grade' => __('Average Grade', 'woothemes-sensei'), |
|
84 | 84 | ); |
85 | 85 | |
86 | 86 | } |
87 | 87 | break; |
88 | 88 | } |
89 | 89 | // Backwards compatible |
90 | - $columns = apply_filters( 'sensei_analysis_course_' . $this->view . '_columns', $columns, $this ); |
|
90 | + $columns = apply_filters('sensei_analysis_course_'.$this->view.'_columns', $columns, $this); |
|
91 | 91 | // Moving forward, single filter with args |
92 | - $columns = apply_filters( 'sensei_analysis_course_columns', $columns, $this ); |
|
92 | + $columns = apply_filters('sensei_analysis_course_columns', $columns, $this); |
|
93 | 93 | return $columns; |
94 | 94 | } |
95 | 95 | |
@@ -100,46 +100,46 @@ discard block |
||
100 | 100 | */ |
101 | 101 | function get_sortable_columns() { |
102 | 102 | |
103 | - switch( $this->view ) { |
|
103 | + switch ($this->view) { |
|
104 | 104 | case 'user' : |
105 | 105 | $columns = array( |
106 | - 'title' => array( 'title', false ), |
|
107 | - 'started' => array( 'started', false ), |
|
108 | - 'completed' => array( 'completed', false ), |
|
109 | - 'user_status' => array( 'user_status', false ), |
|
106 | + 'title' => array('title', false), |
|
107 | + 'started' => array('started', false), |
|
108 | + 'completed' => array('completed', false), |
|
109 | + 'user_status' => array('user_status', false), |
|
110 | 110 | // 'grade' => array( 'grade', false ), |
111 | - 'percent' => array( 'percent', false ) |
|
111 | + 'percent' => array('percent', false) |
|
112 | 112 | ); |
113 | 113 | break; |
114 | 114 | |
115 | 115 | case 'lesson' : |
116 | 116 | default: |
117 | - if ( $this->user_id ) { |
|
117 | + if ($this->user_id) { |
|
118 | 118 | |
119 | 119 | $columns = array( |
120 | - 'title' => array( 'title', false ), |
|
121 | - 'started' => array( 'started', false ), |
|
122 | - 'completed' => array( 'completed', false ), |
|
123 | - 'user_status' => array( 'user_status', false ), |
|
124 | - 'grade' => array( 'grade', false ), |
|
120 | + 'title' => array('title', false), |
|
121 | + 'started' => array('started', false), |
|
122 | + 'completed' => array('completed', false), |
|
123 | + 'user_status' => array('user_status', false), |
|
124 | + 'grade' => array('grade', false), |
|
125 | 125 | ); |
126 | 126 | |
127 | 127 | } else { |
128 | 128 | |
129 | 129 | $columns = array( |
130 | - 'title' => array( 'title', false ), |
|
131 | - 'num_learners' => array( 'num_learners', false ), |
|
132 | - 'completions' => array( 'completions', false ), |
|
133 | - 'average_grade' => array( 'average_grade', false ) |
|
130 | + 'title' => array('title', false), |
|
131 | + 'num_learners' => array('num_learners', false), |
|
132 | + 'completions' => array('completions', false), |
|
133 | + 'average_grade' => array('average_grade', false) |
|
134 | 134 | ); |
135 | 135 | |
136 | 136 | } |
137 | 137 | break; |
138 | 138 | } |
139 | 139 | // Backwards compatible |
140 | - $columns = apply_filters( 'sensei_analysis_course_' . $this->view . '_columns_sortable', $columns, $this ); |
|
140 | + $columns = apply_filters('sensei_analysis_course_'.$this->view.'_columns_sortable', $columns, $this); |
|
141 | 141 | // Moving forward, single filter with args |
142 | - $columns = apply_filters( 'sensei_analysis_course_columns_sortable', $columns, $this ); |
|
142 | + $columns = apply_filters('sensei_analysis_course_columns_sortable', $columns, $this); |
|
143 | 143 | return $columns; |
144 | 144 | } |
145 | 145 | |
@@ -153,32 +153,32 @@ discard block |
||
153 | 153 | |
154 | 154 | // Handle orderby (needs work) |
155 | 155 | $orderby = ''; |
156 | - if ( !empty( $_GET['orderby'] ) ) { |
|
157 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
158 | - $orderby = esc_html( $_GET['orderby'] ); |
|
156 | + if ( ! empty($_GET['orderby'])) { |
|
157 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
158 | + $orderby = esc_html($_GET['orderby']); |
|
159 | 159 | } // End If Statement |
160 | 160 | } |
161 | 161 | |
162 | 162 | // Handle order |
163 | 163 | $order = 'ASC'; |
164 | - if ( !empty( $_GET['order'] ) ) { |
|
165 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
164 | + if ( ! empty($_GET['order'])) { |
|
165 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | // Handle search, need 4.1 version of WP to be able to restrict statuses to known post_ids |
169 | 169 | $search = false; |
170 | - if ( !empty( $_GET['s'] ) ) { |
|
171 | - $search = esc_html( $_GET['s'] ); |
|
170 | + if ( ! empty($_GET['s'])) { |
|
171 | + $search = esc_html($_GET['s']); |
|
172 | 172 | } // End If Statement |
173 | 173 | $this->search = $search; |
174 | 174 | |
175 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
176 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
175 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
176 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
177 | 177 | |
178 | 178 | $paged = $this->get_pagenum(); |
179 | 179 | $offset = 0; |
180 | - if ( !empty($paged) ) { |
|
181 | - $offset = $per_page * ( $paged - 1 ); |
|
180 | + if ( ! empty($paged)) { |
|
181 | + $offset = $per_page * ($paged - 1); |
|
182 | 182 | } // End If Statement |
183 | 183 | |
184 | 184 | $args = array( |
@@ -187,28 +187,28 @@ discard block |
||
187 | 187 | 'orderby' => $orderby, |
188 | 188 | 'order' => $order, |
189 | 189 | ); |
190 | - if ( $this->search ) { |
|
190 | + if ($this->search) { |
|
191 | 191 | $args['search'] = $this->search; |
192 | 192 | } // End If Statement |
193 | 193 | |
194 | - switch( $this->view ) { |
|
194 | + switch ($this->view) { |
|
195 | 195 | case 'user' : |
196 | - $this->items = $this->get_course_statuses( $args ); |
|
196 | + $this->items = $this->get_course_statuses($args); |
|
197 | 197 | break; |
198 | 198 | |
199 | 199 | case 'lesson': |
200 | 200 | default: |
201 | - $this->items = $this->get_lessons( $args ); |
|
201 | + $this->items = $this->get_lessons($args); |
|
202 | 202 | break; |
203 | 203 | } |
204 | 204 | |
205 | 205 | $total_items = $this->total_items; |
206 | - $total_pages = ceil( $total_items / $per_page ); |
|
207 | - $this->set_pagination_args( array( |
|
206 | + $total_pages = ceil($total_items / $per_page); |
|
207 | + $this->set_pagination_args(array( |
|
208 | 208 | 'total_items' => $total_items, |
209 | 209 | 'total_pages' => $total_pages, |
210 | 210 | 'per_page' => $per_page |
211 | - ) ); |
|
211 | + )); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @since 1.7.0 |
217 | 217 | * @return data |
218 | 218 | */ |
219 | - public function generate_report( $report ) { |
|
219 | + public function generate_report($report) { |
|
220 | 220 | |
221 | 221 | $data = array(); |
222 | 222 | |
@@ -224,22 +224,22 @@ discard block |
||
224 | 224 | |
225 | 225 | // Handle orderby |
226 | 226 | $orderby = ''; |
227 | - if ( !empty( $_GET['orderby'] ) ) { |
|
228 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
229 | - $orderby = esc_html( $_GET['orderby'] ); |
|
227 | + if ( ! empty($_GET['orderby'])) { |
|
228 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
229 | + $orderby = esc_html($_GET['orderby']); |
|
230 | 230 | } // End If Statement |
231 | 231 | } |
232 | 232 | |
233 | 233 | // Handle order |
234 | 234 | $order = 'ASC'; |
235 | - if ( !empty( $_GET['order'] ) ) { |
|
236 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
235 | + if ( ! empty($_GET['order'])) { |
|
236 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | // Handle search |
240 | 240 | $search = false; |
241 | - if ( !empty( $_GET['s'] ) ) { |
|
242 | - $search = esc_html( $_GET['s'] ); |
|
241 | + if ( ! empty($_GET['s'])) { |
|
242 | + $search = esc_html($_GET['s']); |
|
243 | 243 | } // End If Statement |
244 | 244 | $this->search = $search; |
245 | 245 | |
@@ -247,32 +247,32 @@ discard block |
||
247 | 247 | 'orderby' => $orderby, |
248 | 248 | 'order' => $order, |
249 | 249 | ); |
250 | - if ( $this->search ) { |
|
250 | + if ($this->search) { |
|
251 | 251 | $args['search'] = $this->search; |
252 | 252 | } // End If Statement |
253 | 253 | |
254 | 254 | // Start the csv with the column headings |
255 | 255 | $column_headers = array(); |
256 | 256 | $columns = $this->get_columns(); |
257 | - foreach( $columns AS $key => $title ) { |
|
257 | + foreach ($columns AS $key => $title) { |
|
258 | 258 | $column_headers[] = $title; |
259 | 259 | } |
260 | 260 | $data[] = $column_headers; |
261 | 261 | |
262 | - switch( $this->view ) { |
|
262 | + switch ($this->view) { |
|
263 | 263 | case 'user' : |
264 | - $this->items = $this->get_course_statuses( $args ); |
|
264 | + $this->items = $this->get_course_statuses($args); |
|
265 | 265 | break; |
266 | 266 | |
267 | 267 | case 'lesson': |
268 | 268 | default: |
269 | - $this->items = $this->get_lessons( $args ); |
|
269 | + $this->items = $this->get_lessons($args); |
|
270 | 270 | break; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Process each row |
274 | - foreach( $this->items AS $item) { |
|
275 | - $data[] = $this->get_row_data( $item ); |
|
274 | + foreach ($this->items AS $item) { |
|
275 | + $data[] = $this->get_row_data($item); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | return $data; |
@@ -284,37 +284,37 @@ discard block |
||
284 | 284 | * @since 1.7.0 |
285 | 285 | * @param object $item The current item |
286 | 286 | */ |
287 | - protected function get_row_data( $item ) { |
|
287 | + protected function get_row_data($item) { |
|
288 | 288 | |
289 | - switch( $this->view ) { |
|
289 | + switch ($this->view) { |
|
290 | 290 | case 'user' : |
291 | - $user_start_date = get_comment_meta( $item->comment_ID, 'start', true ); |
|
291 | + $user_start_date = get_comment_meta($item->comment_ID, 'start', true); |
|
292 | 292 | $user_end_date = $item->comment_date; |
293 | 293 | |
294 | - if( 'complete' == $item->comment_approved ) { |
|
294 | + if ('complete' == $item->comment_approved) { |
|
295 | 295 | |
296 | - $status = __( 'Completed', 'woothemes-sensei' ); |
|
296 | + $status = __('Completed', 'woothemes-sensei'); |
|
297 | 297 | $status_class = 'graded'; |
298 | 298 | |
299 | 299 | } else { |
300 | 300 | |
301 | - $status = __( 'In Progress', 'woothemes-sensei' ); |
|
301 | + $status = __('In Progress', 'woothemes-sensei'); |
|
302 | 302 | $status_class = 'in-progress'; |
303 | 303 | $user_end_date = ''; |
304 | 304 | |
305 | 305 | } |
306 | - $course_percent = get_comment_meta( $item->comment_ID, 'percent', true ); |
|
306 | + $course_percent = get_comment_meta($item->comment_ID, 'percent', true); |
|
307 | 307 | |
308 | 308 | // Output users data |
309 | - $user_name = Sensei_Learner::get_full_name( $item->user_id ); |
|
309 | + $user_name = Sensei_Learner::get_full_name($item->user_id); |
|
310 | 310 | |
311 | - if ( !$this->csv_output ) { |
|
311 | + if ( ! $this->csv_output) { |
|
312 | 312 | |
313 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->user_id, 'course_id' => $this->course_id ), admin_url( 'admin.php' ) ); |
|
313 | + $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->user_id, 'course_id' => $this->course_id), admin_url('admin.php')); |
|
314 | 314 | |
315 | - $user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $user_name . '</a></strong>'; |
|
316 | - $status = sprintf( '<span class="%s">%s</span>', $status_class, $status ); |
|
317 | - if ( is_numeric($course_percent) ) { |
|
315 | + $user_name = '<strong><a class="row-title" href="'.esc_url($url).'">'.$user_name.'</a></strong>'; |
|
316 | + $status = sprintf('<span class="%s">%s</span>', $status_class, $status); |
|
317 | + if (is_numeric($course_percent)) { |
|
318 | 318 | |
319 | 319 | $course_percent .= '%'; |
320 | 320 | |
@@ -322,19 +322,19 @@ discard block |
||
322 | 322 | |
323 | 323 | } // End If Statement |
324 | 324 | |
325 | - $column_data = apply_filters( 'sensei_analysis_course_column_data', array( 'title' => $user_name, |
|
325 | + $column_data = apply_filters('sensei_analysis_course_column_data', array('title' => $user_name, |
|
326 | 326 | 'started' => $user_start_date, |
327 | 327 | 'completed' => $user_end_date, |
328 | 328 | 'user_status' => $status, |
329 | 329 | 'percent' => $course_percent, |
330 | - ), $item, $this ); |
|
330 | + ), $item, $this); |
|
331 | 331 | break; |
332 | 332 | |
333 | 333 | case 'lesson': |
334 | 334 | default: |
335 | 335 | // Displaying lessons for this Course for a specific User |
336 | - if ( $this->user_id ) { |
|
337 | - $status = __( 'Not started', 'woothemes-sensei' ); |
|
336 | + if ($this->user_id) { |
|
337 | + $status = __('Not started', 'woothemes-sensei'); |
|
338 | 338 | $user_start_date = $user_end_date = $status_class = $grade = ''; |
339 | 339 | |
340 | 340 | $lesson_args = array( |
@@ -343,66 +343,66 @@ discard block |
||
343 | 343 | 'type' => 'sensei_lesson_status', |
344 | 344 | 'status' => 'any', |
345 | 345 | ); |
346 | - $lesson_status = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_user_lesson', $lesson_args, $item, $this->user_id ), true ); |
|
346 | + $lesson_status = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_user_lesson', $lesson_args, $item, $this->user_id), true); |
|
347 | 347 | |
348 | - if ( !empty($lesson_status) ) { |
|
349 | - $user_start_date = get_comment_meta( $lesson_status->comment_ID, 'start', true ); |
|
348 | + if ( ! empty($lesson_status)) { |
|
349 | + $user_start_date = get_comment_meta($lesson_status->comment_ID, 'start', true); |
|
350 | 350 | $user_end_date = $lesson_status->comment_date; |
351 | 351 | |
352 | - if( 'complete' == $lesson_status->comment_approved ) { |
|
353 | - $status = __( 'Completed', 'woothemes-sensei' ); |
|
352 | + if ('complete' == $lesson_status->comment_approved) { |
|
353 | + $status = __('Completed', 'woothemes-sensei'); |
|
354 | 354 | $status_class = 'graded'; |
355 | 355 | |
356 | - $grade = __( 'No Grade', 'woothemes-sensei' ); |
|
356 | + $grade = __('No Grade', 'woothemes-sensei'); |
|
357 | 357 | } |
358 | - elseif( 'graded' == $lesson_status->comment_approved ) { |
|
359 | - $status = __( 'Graded', 'woothemes-sensei' ); |
|
358 | + elseif ('graded' == $lesson_status->comment_approved) { |
|
359 | + $status = __('Graded', 'woothemes-sensei'); |
|
360 | 360 | $status_class = 'graded'; |
361 | 361 | |
362 | - $grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true); |
|
362 | + $grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
363 | 363 | } |
364 | - elseif( 'passed' == $lesson_status->comment_approved ) { |
|
365 | - $status = __( 'Passed', 'woothemes-sensei' ); |
|
364 | + elseif ('passed' == $lesson_status->comment_approved) { |
|
365 | + $status = __('Passed', 'woothemes-sensei'); |
|
366 | 366 | $status_class = 'graded'; |
367 | 367 | |
368 | - $grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true); |
|
368 | + $grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
369 | 369 | } |
370 | - elseif( 'failed' == $lesson_status->comment_approved ) { |
|
371 | - $status = __( 'Failed', 'woothemes-sensei' ); |
|
370 | + elseif ('failed' == $lesson_status->comment_approved) { |
|
371 | + $status = __('Failed', 'woothemes-sensei'); |
|
372 | 372 | $status_class = 'failed'; |
373 | 373 | |
374 | - $grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true); |
|
374 | + $grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
375 | 375 | } |
376 | - elseif( 'ungraded' == $lesson_status->comment_approved ) { |
|
377 | - $status = __( 'Ungraded', 'woothemes-sensei' ); |
|
376 | + elseif ('ungraded' == $lesson_status->comment_approved) { |
|
377 | + $status = __('Ungraded', 'woothemes-sensei'); |
|
378 | 378 | $status_class = 'ungraded'; |
379 | 379 | |
380 | 380 | } |
381 | - elseif( 'in-progress' == $lesson_status->comment_approved ) { |
|
382 | - $status = __( 'In Progress', 'woothemes-sensei' ); |
|
381 | + elseif ('in-progress' == $lesson_status->comment_approved) { |
|
382 | + $status = __('In Progress', 'woothemes-sensei'); |
|
383 | 383 | $user_end_date = ''; |
384 | 384 | } |
385 | 385 | } // END lesson_status |
386 | 386 | |
387 | 387 | // Output users data |
388 | - if ( $this->csv_output ) { |
|
389 | - $lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
|
388 | + if ($this->csv_output) { |
|
389 | + $lesson_title = apply_filters('the_title', $item->post_title, $item->ID); |
|
390 | 390 | } |
391 | 391 | else { |
392 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
393 | - $lesson_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
|
392 | + $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID), admin_url('admin.php')); |
|
393 | + $lesson_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>'; |
|
394 | 394 | |
395 | - $status = sprintf( '<span class="%s">%s</span>', $status_class, $status ); |
|
396 | - if ( is_numeric($grade) ) { |
|
395 | + $status = sprintf('<span class="%s">%s</span>', $status_class, $status); |
|
396 | + if (is_numeric($grade)) { |
|
397 | 397 | $grade .= '%'; |
398 | 398 | } |
399 | 399 | } // End If Statement |
400 | - $column_data = apply_filters( 'sensei_analysis_course_column_data', array( 'title' => $lesson_title, |
|
400 | + $column_data = apply_filters('sensei_analysis_course_column_data', array('title' => $lesson_title, |
|
401 | 401 | 'started' => $user_start_date, |
402 | 402 | 'completed' => $user_end_date, |
403 | 403 | 'user_status' => $status, |
404 | 404 | 'grade' => $grade, |
405 | - ), $item, $this ); |
|
405 | + ), $item, $this); |
|
406 | 406 | } |
407 | 407 | // Display lessons for this Course regardless of users |
408 | 408 | else { |
@@ -412,51 +412,51 @@ discard block |
||
412 | 412 | 'type' => 'sensei_lesson_status', |
413 | 413 | 'status' => 'any', |
414 | 414 | ); |
415 | - $lesson_students = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_learners', $lesson_args, $item ) ); |
|
415 | + $lesson_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_learners', $lesson_args, $item)); |
|
416 | 416 | |
417 | 417 | // Get Course Completions |
418 | 418 | $lesson_args = array( |
419 | 419 | 'post_id' => $item->ID, |
420 | 420 | 'type' => 'sensei_lesson_status', |
421 | - 'status' => array( 'complete', 'graded', 'passed', 'failed' ), |
|
421 | + 'status' => array('complete', 'graded', 'passed', 'failed'), |
|
422 | 422 | 'count' => true, |
423 | 423 | ); |
424 | - $lesson_completions = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_completions', $lesson_args, $item ) ); |
|
424 | + $lesson_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_completions', $lesson_args, $item)); |
|
425 | 425 | |
426 | 426 | $lesson_average_grade = __('n/a', 'woothemes-sensei'); |
427 | - if ( false != get_post_meta($item->ID, '_quiz_has_questions', true) ) { |
|
427 | + if (false != get_post_meta($item->ID, '_quiz_has_questions', true)) { |
|
428 | 428 | // Get Percent Complete |
429 | 429 | $grade_args = array( |
430 | 430 | 'post_id' => $item->ID, |
431 | 431 | 'type' => 'sensei_lesson_status', |
432 | - 'status' => array( 'graded', 'passed', 'failed' ), |
|
432 | + 'status' => array('graded', 'passed', 'failed'), |
|
433 | 433 | 'meta_key' => 'grade', |
434 | 434 | ); |
435 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
436 | - $lesson_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_grades', $grade_args, $item ), true ); |
|
437 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
435 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
436 | + $lesson_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_grades', $grade_args, $item), true); |
|
437 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
438 | 438 | |
439 | - $grade_count = !empty( $lesson_grades->total ) ? $lesson_grades->total : 1; |
|
440 | - $grade_total = !empty( $lesson_grades->meta_sum ) ? doubleval( $lesson_grades->meta_sum ) : 0; |
|
441 | - $lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) ); |
|
439 | + $grade_count = ! empty($lesson_grades->total) ? $lesson_grades->total : 1; |
|
440 | + $grade_total = ! empty($lesson_grades->meta_sum) ? doubleval($lesson_grades->meta_sum) : 0; |
|
441 | + $lesson_average_grade = abs(round(doubleval($grade_total / $grade_count), 2)); |
|
442 | 442 | } |
443 | 443 | // Output lesson data |
444 | - if ( $this->csv_output ) { |
|
445 | - $lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
|
444 | + if ($this->csv_output) { |
|
445 | + $lesson_title = apply_filters('the_title', $item->post_title, $item->ID); |
|
446 | 446 | } |
447 | 447 | else { |
448 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
449 | - $lesson_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
|
448 | + $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID), admin_url('admin.php')); |
|
449 | + $lesson_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>'; |
|
450 | 450 | |
451 | - if ( is_numeric( $lesson_average_grade ) ) { |
|
451 | + if (is_numeric($lesson_average_grade)) { |
|
452 | 452 | $lesson_average_grade .= '%'; |
453 | 453 | } |
454 | 454 | } // End If Statement |
455 | - $column_data = apply_filters( 'sensei_analysis_course_column_data', array( 'title' => $lesson_title, |
|
455 | + $column_data = apply_filters('sensei_analysis_course_column_data', array('title' => $lesson_title, |
|
456 | 456 | 'num_learners' => $lesson_students, |
457 | 457 | 'completions' => $lesson_completions, |
458 | 458 | 'average_grade' => $lesson_average_grade, |
459 | - ), $item, $this ); |
|
459 | + ), $item, $this); |
|
460 | 460 | } // END if |
461 | 461 | break; |
462 | 462 | } // END switch |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | * @since 1.7.0 |
470 | 470 | * @return array statuses |
471 | 471 | */ |
472 | - private function get_course_statuses( $args ) { |
|
472 | + private function get_course_statuses($args) { |
|
473 | 473 | |
474 | 474 | $activity_args = array( |
475 | 475 | 'post_id' => $this->course_id, |
@@ -482,34 +482,34 @@ discard block |
||
482 | 482 | ); |
483 | 483 | |
484 | 484 | // Searching users on statuses requires sub-selecting the statuses by user_ids |
485 | - if ( $this->search ) { |
|
485 | + if ($this->search) { |
|
486 | 486 | $user_args = array( |
487 | - 'search' => '*' . $this->search . '*', |
|
487 | + 'search' => '*'.$this->search.'*', |
|
488 | 488 | 'fields' => 'ID', |
489 | 489 | ); |
490 | 490 | // Filter for extending |
491 | - $user_args = apply_filters( 'sensei_analysis_course_search_users', $user_args ); |
|
492 | - if ( !empty( $user_args ) ) { |
|
493 | - $learners_search = new WP_User_Query( $user_args ); |
|
491 | + $user_args = apply_filters('sensei_analysis_course_search_users', $user_args); |
|
492 | + if ( ! empty($user_args)) { |
|
493 | + $learners_search = new WP_User_Query($user_args); |
|
494 | 494 | // Store for reuse on counts |
495 | 495 | $activity_args['user_id'] = (array) $learners_search->get_results(); |
496 | 496 | } |
497 | 497 | } // End If Statement |
498 | 498 | |
499 | - $activity_args = apply_filters( 'sensei_analysis_course_filter_statuses', $activity_args ); |
|
499 | + $activity_args = apply_filters('sensei_analysis_course_filter_statuses', $activity_args); |
|
500 | 500 | |
501 | 501 | // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice |
502 | - $this->total_items = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); |
|
502 | + $this->total_items = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); |
|
503 | 503 | |
504 | 504 | // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? |
505 | - if ( $this->total_items < $activity_args['offset'] ) { |
|
506 | - $new_paged = floor( $this->total_items / $activity_args['number'] ); |
|
505 | + if ($this->total_items < $activity_args['offset']) { |
|
506 | + $new_paged = floor($this->total_items / $activity_args['number']); |
|
507 | 507 | $activity_args['offset'] = $new_paged * $activity_args['number']; |
508 | 508 | } |
509 | - $statuses = Sensei_Utils::sensei_check_for_activity( $activity_args, true ); |
|
509 | + $statuses = Sensei_Utils::sensei_check_for_activity($activity_args, true); |
|
510 | 510 | // Need to always return an array, even with only 1 item |
511 | - if ( !is_array($statuses) ) { |
|
512 | - $statuses = array( $statuses ); |
|
511 | + if ( ! is_array($statuses)) { |
|
512 | + $statuses = array($statuses); |
|
513 | 513 | } |
514 | 514 | return $statuses; |
515 | 515 | } // End get_course_statuses() |
@@ -519,32 +519,32 @@ discard block |
||
519 | 519 | * @since 1.7.0 |
520 | 520 | * @return array statuses |
521 | 521 | */ |
522 | - private function get_lessons( $args ) { |
|
522 | + private function get_lessons($args) { |
|
523 | 523 | |
524 | - $lessons_args = array( 'post_type' => 'lesson', |
|
524 | + $lessons_args = array('post_type' => 'lesson', |
|
525 | 525 | 'posts_per_page' => $args['number'], |
526 | 526 | 'offset' => $args['offset'], |
527 | - 'meta_key' => '_order_' . $this->course_id, |
|
527 | + 'meta_key' => '_order_'.$this->course_id, |
|
528 | 528 | // 'orderby' => $args['orderby'], |
529 | 529 | 'order' => $args['order'], |
530 | 530 | 'meta_query' => array( |
531 | 531 | array( |
532 | 532 | 'key' => '_lesson_course', |
533 | - 'value' => intval( $this->course_id ), |
|
533 | + 'value' => intval($this->course_id), |
|
534 | 534 | ), |
535 | 535 | ), |
536 | 536 | 'post_status' => array('publish', 'private'), |
537 | 537 | 'suppress_filters' => 0 |
538 | 538 | ); |
539 | - if ( $this->search ) { |
|
539 | + if ($this->search) { |
|
540 | 540 | $lessons_args['s'] = $this->search; |
541 | 541 | } |
542 | - if ( $this->csv_output ) { |
|
542 | + if ($this->csv_output) { |
|
543 | 543 | $lessons_args['posts_per_page'] = '-1'; |
544 | 544 | } |
545 | 545 | |
546 | 546 | // Using WP_Query as get_posts() doesn't support 'found_posts' |
547 | - $lessons_query = new WP_Query( apply_filters( 'sensei_analysis_course_filter_lessons', $lessons_args ) ); |
|
547 | + $lessons_query = new WP_Query(apply_filters('sensei_analysis_course_filter_lessons', $lessons_args)); |
|
548 | 548 | $this->total_items = $lessons_query->found_posts; |
549 | 549 | return $lessons_query->posts; |
550 | 550 | } // End get_lessons() |
@@ -556,17 +556,17 @@ discard block |
||
556 | 556 | * @return void |
557 | 557 | */ |
558 | 558 | public function no_items() { |
559 | - switch( $this->view ) { |
|
559 | + switch ($this->view) { |
|
560 | 560 | case 'user' : |
561 | - $text = __( 'No learners found.', 'woothemes-sensei' ); |
|
561 | + $text = __('No learners found.', 'woothemes-sensei'); |
|
562 | 562 | break; |
563 | 563 | |
564 | 564 | case 'lesson': |
565 | 565 | default: |
566 | - $text = __( 'No lessons found.', 'woothemes-sensei' ); |
|
566 | + $text = __('No lessons found.', 'woothemes-sensei'); |
|
567 | 567 | break; |
568 | 568 | } |
569 | - echo apply_filters( 'sensei_analysis_course_no_items_text', $text ); |
|
569 | + echo apply_filters('sensei_analysis_course_no_items_text', $text); |
|
570 | 570 | } // End no_items() |
571 | 571 | |
572 | 572 | /** |
@@ -575,25 +575,25 @@ discard block |
||
575 | 575 | * @return void |
576 | 576 | */ |
577 | 577 | public function data_table_header() { |
578 | - if ( $this->user_id ) { |
|
579 | - $learners_text = __( 'Other Learners taking this Course', 'woothemes-sensei' ); |
|
578 | + if ($this->user_id) { |
|
579 | + $learners_text = __('Other Learners taking this Course', 'woothemes-sensei'); |
|
580 | 580 | } |
581 | 581 | else { |
582 | - $learners_text = __( 'Learners taking this Course', 'woothemes-sensei' ); |
|
582 | + $learners_text = __('Learners taking this Course', 'woothemes-sensei'); |
|
583 | 583 | } |
584 | - $lessons_text = __( 'Lessons in this Course', 'woothemes-sensei' ); |
|
584 | + $lessons_text = __('Lessons in this Course', 'woothemes-sensei'); |
|
585 | 585 | |
586 | 586 | $url_args = array( |
587 | 587 | 'page' => $this->page_slug, |
588 | 588 | 'course_id' => $this->course_id, |
589 | 589 | ); |
590 | - $learners_url = esc_url( add_query_arg( array_merge( $url_args, array( 'view' => 'user' ) ), admin_url( 'admin.php' ) ) ); |
|
591 | - $lessons_url = esc_url( add_query_arg( array_merge( $url_args, array( 'view' => 'lesson' ) ), admin_url( 'admin.php' ) ) ); |
|
590 | + $learners_url = esc_url(add_query_arg(array_merge($url_args, array('view' => 'user')), admin_url('admin.php'))); |
|
591 | + $lessons_url = esc_url(add_query_arg(array_merge($url_args, array('view' => 'lesson')), admin_url('admin.php'))); |
|
592 | 592 | |
593 | 593 | $learners_class = $lessons_class = ''; |
594 | 594 | |
595 | 595 | $menu = array(); |
596 | - switch( $this->view ) { |
|
596 | + switch ($this->view) { |
|
597 | 597 | case 'user' : |
598 | 598 | $learners_class = 'current'; |
599 | 599 | break; |
@@ -603,17 +603,17 @@ discard block |
||
603 | 603 | $lessons_class = 'current'; |
604 | 604 | break; |
605 | 605 | } |
606 | - $menu['lesson'] = sprintf( '<a href="%s" class="%s">%s</a>', $lessons_url, $lessons_class, $lessons_text ); |
|
607 | - $menu['user'] = sprintf( '<a href="%s" class="%s">%s</a>', $learners_url, $learners_class, $learners_text ); |
|
608 | - |
|
609 | - $menu = apply_filters( 'sensei_analysis_course_sub_menu', $menu ); |
|
610 | - if ( !empty($menu) ) { |
|
611 | - echo '<ul class="subsubsub">' . "\n"; |
|
612 | - foreach ( $menu as $class => $item ) { |
|
613 | - $menu[ $class ] = "\t<li class='$class'>$item"; |
|
606 | + $menu['lesson'] = sprintf('<a href="%s" class="%s">%s</a>', $lessons_url, $lessons_class, $lessons_text); |
|
607 | + $menu['user'] = sprintf('<a href="%s" class="%s">%s</a>', $learners_url, $learners_class, $learners_text); |
|
608 | + |
|
609 | + $menu = apply_filters('sensei_analysis_course_sub_menu', $menu); |
|
610 | + if ( ! empty($menu)) { |
|
611 | + echo '<ul class="subsubsub">'."\n"; |
|
612 | + foreach ($menu as $class => $item) { |
|
613 | + $menu[$class] = "\t<li class='$class'>$item"; |
|
614 | 614 | } |
615 | - echo implode( " |</li>\n", $menu ) . "</li>\n"; |
|
616 | - echo '</ul>' . "\n"; |
|
615 | + echo implode(" |</li>\n", $menu)."</li>\n"; |
|
616 | + echo '</ul>'."\n"; |
|
617 | 617 | } |
618 | 618 | } // End data_table_header() |
619 | 619 | |
@@ -624,19 +624,19 @@ discard block |
||
624 | 624 | */ |
625 | 625 | public function data_table_footer() { |
626 | 626 | |
627 | - $course = get_post( $this->course_id ); |
|
628 | - $report = sanitize_title( $course->post_title ) . '-' . $this->view . 's-overview'; |
|
629 | - if ( $this->user_id ) { |
|
630 | - $user_name = Sensei_Learner::get_full_name( $this->user_id ); |
|
631 | - $report = sanitize_title( $user_name ) . '-' . $report; |
|
627 | + $course = get_post($this->course_id); |
|
628 | + $report = sanitize_title($course->post_title).'-'.$this->view.'s-overview'; |
|
629 | + if ($this->user_id) { |
|
630 | + $user_name = Sensei_Learner::get_full_name($this->user_id); |
|
631 | + $report = sanitize_title($user_name).'-'.$report; |
|
632 | 632 | } |
633 | 633 | |
634 | - $url_args = array( 'page' => $this->page_slug, 'course_id' => $this->course_id, 'view' => $this->view, 'sensei_report_download' => $report ); |
|
635 | - if ( $this->user_id ) { |
|
634 | + $url_args = array('page' => $this->page_slug, 'course_id' => $this->course_id, 'view' => $this->view, 'sensei_report_download' => $report); |
|
635 | + if ($this->user_id) { |
|
636 | 636 | $url_args['user_id'] = $this->user_id; |
637 | 637 | } |
638 | - $url = add_query_arg( $url_args, admin_url( 'admin.php' ) ); |
|
639 | - echo '<a class="button button-primary" href="' . esc_url( wp_nonce_url( $url, 'sensei_csv_download-' . $report, '_sdl_nonce' ) ) . '">' . __( 'Export all rows (CSV)', 'woothemes-sensei' ) . '</a>'; |
|
638 | + $url = add_query_arg($url_args, admin_url('admin.php')); |
|
639 | + echo '<a class="button button-primary" href="'.esc_url(wp_nonce_url($url, 'sensei_csv_download-'.$report, '_sdl_nonce')).'">'.__('Export all rows (CSV)', 'woothemes-sensei').'</a>'; |
|
640 | 640 | } // End data_table_footer() |
641 | 641 | |
642 | 642 | /** |
@@ -644,15 +644,15 @@ discard block |
||
644 | 644 | * @since 1.7.0 |
645 | 645 | * @return string $text |
646 | 646 | */ |
647 | - public function search_button( $text = '' ) { |
|
648 | - switch( $this->view ) { |
|
647 | + public function search_button($text = '') { |
|
648 | + switch ($this->view) { |
|
649 | 649 | case 'user': |
650 | - $text = __( 'Search Learners', 'woothemes-sensei' ); |
|
650 | + $text = __('Search Learners', 'woothemes-sensei'); |
|
651 | 651 | break; |
652 | 652 | |
653 | 653 | case 'lesson': |
654 | 654 | default: |
655 | - $text = __( 'Search Lessons', 'woothemes-sensei' ); |
|
655 | + $text = __('Search Lessons', 'woothemes-sensei'); |
|
656 | 656 | break; |
657 | 657 | } // End Switch Statement |
658 | 658 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Learners Overview List Table Class |
@@ -22,28 +22,28 @@ discard block |
||
22 | 22 | * Constructor |
23 | 23 | * @since 1.6.0 |
24 | 24 | */ |
25 | - public function __construct ( $course_id = 0, $lesson_id = 0 ) { |
|
26 | - $this->course_id = intval( $course_id ); |
|
27 | - $this->lesson_id = intval( $lesson_id ); |
|
25 | + public function __construct($course_id = 0, $lesson_id = 0) { |
|
26 | + $this->course_id = intval($course_id); |
|
27 | + $this->lesson_id = intval($lesson_id); |
|
28 | 28 | |
29 | - if( isset( $_GET['view'] ) && in_array( $_GET['view'], array( 'courses', 'lessons', 'learners' ) ) ) { |
|
29 | + if (isset($_GET['view']) && in_array($_GET['view'], array('courses', 'lessons', 'learners'))) { |
|
30 | 30 | $this->view = $_GET['view']; |
31 | 31 | } |
32 | 32 | |
33 | 33 | // Viewing a single lesson always sets the view to Learners |
34 | - if( $this->lesson_id ) { |
|
34 | + if ($this->lesson_id) { |
|
35 | 35 | $this->view = 'learners'; |
36 | 36 | } |
37 | 37 | |
38 | 38 | // Load Parent token into constructor |
39 | - parent::__construct( 'learners_main' ); |
|
39 | + parent::__construct('learners_main'); |
|
40 | 40 | |
41 | 41 | // Actions |
42 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
43 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
44 | - add_action( 'sensei_learners_extra', array( $this, 'add_learners_box' ) ); |
|
42 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
43 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
44 | + add_action('sensei_learners_extra', array($this, 'add_learners_box')); |
|
45 | 45 | |
46 | - add_filter( 'sensei_list_table_search_button_text', array( $this, 'search_button' ) ); |
|
46 | + add_filter('sensei_list_table_search_button_text', array($this, 'search_button')); |
|
47 | 47 | } // End __construct() |
48 | 48 | |
49 | 49 | /** |
@@ -53,38 +53,38 @@ discard block |
||
53 | 53 | */ |
54 | 54 | function get_columns() { |
55 | 55 | $columns = array(); |
56 | - switch( $this->view ) { |
|
56 | + switch ($this->view) { |
|
57 | 57 | case 'learners': |
58 | 58 | $columns = array( |
59 | - 'title' => __( 'Learner', 'woothemes-sensei' ), |
|
60 | - 'date_started' => __( 'Date Started', 'woothemes-sensei' ), |
|
61 | - 'user_status' => __( 'Status', 'woothemes-sensei' ), |
|
59 | + 'title' => __('Learner', 'woothemes-sensei'), |
|
60 | + 'date_started' => __('Date Started', 'woothemes-sensei'), |
|
61 | + 'user_status' => __('Status', 'woothemes-sensei'), |
|
62 | 62 | ); |
63 | 63 | break; |
64 | 64 | |
65 | 65 | case 'lessons': |
66 | 66 | $columns = array( |
67 | - 'title' => __( 'Lesson', 'woothemes-sensei' ), |
|
68 | - 'num_learners' => __( '# Learners', 'woothemes-sensei' ), |
|
69 | - 'updated' => __( 'Last Updated', 'woothemes-sensei' ), |
|
67 | + 'title' => __('Lesson', 'woothemes-sensei'), |
|
68 | + 'num_learners' => __('# Learners', 'woothemes-sensei'), |
|
69 | + 'updated' => __('Last Updated', 'woothemes-sensei'), |
|
70 | 70 | ); |
71 | 71 | break; |
72 | 72 | |
73 | 73 | case 'courses': |
74 | 74 | default: |
75 | 75 | $columns = array( |
76 | - 'title' => __( 'Course', 'woothemes-sensei' ), |
|
77 | - 'num_learners' => __( '# Learners', 'woothemes-sensei' ), |
|
78 | - 'updated' => __( 'Last Updated', 'woothemes-sensei' ), |
|
76 | + 'title' => __('Course', 'woothemes-sensei'), |
|
77 | + 'num_learners' => __('# Learners', 'woothemes-sensei'), |
|
78 | + 'updated' => __('Last Updated', 'woothemes-sensei'), |
|
79 | 79 | ); |
80 | 80 | break; |
81 | 81 | } |
82 | 82 | $columns['actions'] = ''; |
83 | 83 | // Backwards compatible |
84 | - if ( 'learners' == $this->view ) { |
|
85 | - $columns = apply_filters( 'sensei_learners_learners_columns', $columns, $this ); |
|
84 | + if ('learners' == $this->view) { |
|
85 | + $columns = apply_filters('sensei_learners_learners_columns', $columns, $this); |
|
86 | 86 | } |
87 | - $columns = apply_filters( 'sensei_learners_default_columns', $columns, $this ); |
|
87 | + $columns = apply_filters('sensei_learners_default_columns', $columns, $this); |
|
88 | 88 | return $columns; |
89 | 89 | } |
90 | 90 | |
@@ -95,32 +95,32 @@ discard block |
||
95 | 95 | */ |
96 | 96 | function get_sortable_columns() { |
97 | 97 | $columns = array(); |
98 | - switch( $this->view ) { |
|
98 | + switch ($this->view) { |
|
99 | 99 | case 'learners': |
100 | 100 | $columns = array( |
101 | - 'title' => array( 'title', false ), |
|
101 | + 'title' => array('title', false), |
|
102 | 102 | ); |
103 | 103 | break; |
104 | 104 | |
105 | 105 | case 'lessons': |
106 | 106 | $columns = array( |
107 | - 'title' => array( 'title', false ), |
|
108 | - 'updated' => array( 'post_modified', false ), |
|
107 | + 'title' => array('title', false), |
|
108 | + 'updated' => array('post_modified', false), |
|
109 | 109 | ); |
110 | 110 | break; |
111 | 111 | |
112 | 112 | default: |
113 | 113 | $columns = array( |
114 | - 'title' => array( 'title', false ), |
|
115 | - 'updated' => array( 'post_modified', false ), |
|
114 | + 'title' => array('title', false), |
|
115 | + 'updated' => array('post_modified', false), |
|
116 | 116 | ); |
117 | 117 | break; |
118 | 118 | } |
119 | 119 | // Backwards compatible |
120 | - if ( 'learners' == $this->view ) { |
|
121 | - $columns = apply_filters( 'sensei_learners_learners_columns_sortable', $columns, $this ); |
|
120 | + if ('learners' == $this->view) { |
|
121 | + $columns = apply_filters('sensei_learners_learners_columns_sortable', $columns, $this); |
|
122 | 122 | } |
123 | - $columns = apply_filters( 'sensei_learners_default_columns_sortable', $columns, $this ); |
|
123 | + $columns = apply_filters('sensei_learners_default_columns_sortable', $columns, $this); |
|
124 | 124 | return $columns; |
125 | 125 | } |
126 | 126 | |
@@ -134,72 +134,72 @@ discard block |
||
134 | 134 | |
135 | 135 | // Handle orderby |
136 | 136 | $orderby = ''; |
137 | - if ( !empty( $_GET['orderby'] ) ) { |
|
138 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
139 | - $orderby = esc_html( $_GET['orderby'] ); |
|
137 | + if ( ! empty($_GET['orderby'])) { |
|
138 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
139 | + $orderby = esc_html($_GET['orderby']); |
|
140 | 140 | } // End If Statement |
141 | 141 | } |
142 | 142 | |
143 | 143 | // Handle order |
144 | 144 | $order = 'DESC'; |
145 | - if ( !empty( $_GET['order'] ) ) { |
|
146 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
145 | + if ( ! empty($_GET['order'])) { |
|
146 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | // Handle category selection |
150 | 150 | $category = false; |
151 | - if ( !empty( $_GET['course_cat'] ) ) { |
|
152 | - $category = intval( $_GET['course_cat'] ); |
|
151 | + if ( ! empty($_GET['course_cat'])) { |
|
152 | + $category = intval($_GET['course_cat']); |
|
153 | 153 | } // End If Statement |
154 | 154 | |
155 | 155 | // Handle search |
156 | 156 | $search = false; |
157 | - if ( !empty( $_GET['s'] ) ) { |
|
158 | - $search = esc_html( $_GET['s'] ); |
|
157 | + if ( ! empty($_GET['s'])) { |
|
158 | + $search = esc_html($_GET['s']); |
|
159 | 159 | } // End If Statement |
160 | 160 | |
161 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
162 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
161 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
162 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
163 | 163 | |
164 | 164 | $paged = $this->get_pagenum(); |
165 | 165 | $offset = 0; |
166 | - if ( !empty($paged) ) { |
|
167 | - $offset = $per_page * ( $paged - 1 ); |
|
166 | + if ( ! empty($paged)) { |
|
167 | + $offset = $per_page * ($paged - 1); |
|
168 | 168 | } // End If Statement |
169 | 169 | |
170 | - switch( $this->view ) { |
|
170 | + switch ($this->view) { |
|
171 | 171 | case 'learners': |
172 | - if ( empty($orderby) ) { |
|
172 | + if (empty($orderby)) { |
|
173 | 173 | $orderby = ''; |
174 | 174 | } |
175 | - $this->items = $this->get_learners( compact( 'per_page', 'offset', 'orderby', 'order', 'search' ) ); |
|
175 | + $this->items = $this->get_learners(compact('per_page', 'offset', 'orderby', 'order', 'search')); |
|
176 | 176 | |
177 | 177 | break; |
178 | 178 | |
179 | 179 | case 'lessons': |
180 | - if ( empty($orderby) ) { |
|
180 | + if (empty($orderby)) { |
|
181 | 181 | $orderby = 'post_modified'; |
182 | 182 | } |
183 | - $this->items = $this->get_lessons( compact( 'per_page', 'offset', 'orderby', 'order', 'search' ) ); |
|
183 | + $this->items = $this->get_lessons(compact('per_page', 'offset', 'orderby', 'order', 'search')); |
|
184 | 184 | |
185 | 185 | break; |
186 | 186 | |
187 | 187 | default: |
188 | - if ( empty($orderby) ) { |
|
188 | + if (empty($orderby)) { |
|
189 | 189 | $orderby = 'post_modified'; |
190 | 190 | } |
191 | - $this->items = $this->get_courses( compact( 'per_page', 'offset', 'orderby', 'order', 'category', 'search' ) ); |
|
191 | + $this->items = $this->get_courses(compact('per_page', 'offset', 'orderby', 'order', 'category', 'search')); |
|
192 | 192 | |
193 | 193 | break; |
194 | 194 | } |
195 | 195 | |
196 | 196 | $total_items = $this->total_items; |
197 | - $total_pages = ceil( $total_items / $per_page ); |
|
198 | - $this->set_pagination_args( array( |
|
197 | + $total_pages = ceil($total_items / $per_page); |
|
198 | + $this->set_pagination_args(array( |
|
199 | 199 | 'total_items' => $total_items, |
200 | 200 | 'total_pages' => $total_pages, |
201 | 201 | 'per_page' => $per_page |
202 | - ) ); |
|
202 | + )); |
|
203 | 203 | |
204 | 204 | } // End prepare_items() |
205 | 205 | |
@@ -213,42 +213,42 @@ discard block |
||
213 | 213 | * |
214 | 214 | * @return void |
215 | 215 | */ |
216 | - protected function get_row_data( $item ) { |
|
216 | + protected function get_row_data($item) { |
|
217 | 217 | global $wp_version; |
218 | 218 | |
219 | - switch ( $this->view ) { |
|
219 | + switch ($this->view) { |
|
220 | 220 | case 'learners' : |
221 | 221 | |
222 | 222 | // in this case the item passed in is actually the users activity on course of lesson |
223 | 223 | $user_activity = $item; |
224 | 224 | $post_id = false; |
225 | 225 | |
226 | - if( $this->lesson_id ) { |
|
226 | + if ($this->lesson_id) { |
|
227 | 227 | |
228 | - $post_id = intval( $this->lesson_id ); |
|
229 | - $object_type = __( 'lesson', 'woothemes-sensei' ); |
|
228 | + $post_id = intval($this->lesson_id); |
|
229 | + $object_type = __('lesson', 'woothemes-sensei'); |
|
230 | 230 | $post_type = 'lesson'; |
231 | 231 | |
232 | - } elseif( $this->course_id ) { |
|
232 | + } elseif ($this->course_id) { |
|
233 | 233 | |
234 | - $post_id = intval( $this->course_id ); |
|
235 | - $object_type = __( 'course', 'woothemes-sensei' ); |
|
234 | + $post_id = intval($this->course_id); |
|
235 | + $object_type = __('course', 'woothemes-sensei'); |
|
236 | 236 | $post_type = 'course'; |
237 | 237 | |
238 | 238 | } |
239 | 239 | |
240 | - if( 'complete' == $user_activity->comment_approved || 'graded' == $user_activity->comment_approved || 'passed' == $user_activity->comment_approved ) { |
|
240 | + if ('complete' == $user_activity->comment_approved || 'graded' == $user_activity->comment_approved || 'passed' == $user_activity->comment_approved) { |
|
241 | 241 | |
242 | - $status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>'; |
|
242 | + $status_html = '<span class="graded">'.__('Completed', 'woothemes-sensei').'</span>'; |
|
243 | 243 | |
244 | 244 | } else { |
245 | 245 | |
246 | - $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>'; |
|
246 | + $status_html = '<span class="in-progress">'.__('In Progress', 'woothemes-sensei').'</span>'; |
|
247 | 247 | |
248 | 248 | } |
249 | 249 | |
250 | - $title = Sensei_Learner::get_full_name( $user_activity->user_id ); |
|
251 | - $a_title = sprintf( __( 'Edit “%s”' ), $title ); |
|
250 | + $title = Sensei_Learner::get_full_name($user_activity->user_id); |
|
251 | + $a_title = sprintf(__('Edit “%s”'), $title); |
|
252 | 252 | |
253 | 253 | /** |
254 | 254 | * sensei_learners_main_column_data filter |
@@ -263,50 +263,50 @@ discard block |
||
263 | 263 | * type html $action_buttons |
264 | 264 | * } |
265 | 265 | */ |
266 | - $column_data = apply_filters( 'sensei_learners_main_column_data', array( |
|
267 | - 'title' => '<strong><a class="row-title" href="' . admin_url( 'user-edit.php?user_id=' . $user_activity->user_id ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>', |
|
268 | - 'date_started' => get_comment_meta( $user_activity->comment_ID, 'start', true), |
|
266 | + $column_data = apply_filters('sensei_learners_main_column_data', array( |
|
267 | + 'title' => '<strong><a class="row-title" href="'.admin_url('user-edit.php?user_id='.$user_activity->user_id).'" title="'.esc_attr($a_title).'">'.$title.'</a></strong>', |
|
268 | + 'date_started' => get_comment_meta($user_activity->comment_ID, 'start', true), |
|
269 | 269 | 'user_status' => $status_html, |
270 | - 'actions' => '<a class="remove-learner button" data-user_id="' . $user_activity->user_id . '" data-post_id="' . $post_id . '" data-post_type="' . $post_type . '">' . sprintf( __( 'Remove from %1$s', 'woothemes-sensei' ), $object_type ) . '</a>', |
|
271 | - ), $item, $post_id, $post_type ); |
|
270 | + 'actions' => '<a class="remove-learner button" data-user_id="'.$user_activity->user_id.'" data-post_id="'.$post_id.'" data-post_type="'.$post_type.'">'.sprintf(__('Remove from %1$s', 'woothemes-sensei'), $object_type).'</a>', |
|
271 | + ), $item, $post_id, $post_type); |
|
272 | 272 | |
273 | 273 | break; |
274 | 274 | |
275 | 275 | case 'lessons' : |
276 | - $lesson_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_lesson_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_lesson_status', 'status' => 'any' ) ) ); |
|
277 | - $title = get_the_title( $item ); |
|
278 | - $a_title = sprintf( __( 'Edit “%s”' ), $title ); |
|
276 | + $lesson_learners = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_learners_lesson_learners', array('post_id' => $item->ID, 'type' => 'sensei_lesson_status', 'status' => 'any'))); |
|
277 | + $title = get_the_title($item); |
|
278 | + $a_title = sprintf(__('Edit “%s”'), $title); |
|
279 | 279 | |
280 | 280 | $grading_action = ''; |
281 | - if ( get_post_meta( $item->ID, '_quiz_has_questions', true ) ) { |
|
282 | - $grading_action = ' <a class="button" href="' . esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'lesson_id' => $item->ID, 'course_id' => $this->course_id ), admin_url( 'admin.php' ) ) ) . '">' . __( 'Grading', 'woothemes-sensei' ) . '</a>'; |
|
281 | + if (get_post_meta($item->ID, '_quiz_has_questions', true)) { |
|
282 | + $grading_action = ' <a class="button" href="'.esc_url(add_query_arg(array('page' => 'sensei_grading', 'lesson_id' => $item->ID, 'course_id' => $this->course_id), admin_url('admin.php'))).'">'.__('Grading', 'woothemes-sensei').'</a>'; |
|
283 | 283 | } |
284 | 284 | |
285 | - $column_data = apply_filters( 'sensei_learners_main_column_data', array( |
|
286 | - 'title' => '<strong><a class="row-title" href="' . admin_url( 'post.php?action=edit&post=' . $item->ID ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>', |
|
285 | + $column_data = apply_filters('sensei_learners_main_column_data', array( |
|
286 | + 'title' => '<strong><a class="row-title" href="'.admin_url('post.php?action=edit&post='.$item->ID).'" title="'.esc_attr($a_title).'">'.$title.'</a></strong>', |
|
287 | 287 | 'num_learners' => $lesson_learners, |
288 | 288 | 'updated' => $item->post_modified, |
289 | - 'actions' => '<a class="button" href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID, 'course_id' => $this->course_id, 'view' => 'learners' ), admin_url( 'admin.php' ) ) ) . '">' . __( 'Manage learners', 'woothemes-sensei' ) . '</a> ' . $grading_action, |
|
290 | - ), $item, $this->course_id ); |
|
289 | + 'actions' => '<a class="button" href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID, 'course_id' => $this->course_id, 'view' => 'learners'), admin_url('admin.php'))).'">'.__('Manage learners', 'woothemes-sensei').'</a> '.$grading_action, |
|
290 | + ), $item, $this->course_id); |
|
291 | 291 | break; |
292 | 292 | |
293 | 293 | case 'courses' : |
294 | 294 | default: |
295 | - $course_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_course_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any' ) ) ); |
|
296 | - $title = get_the_title( $item ); |
|
297 | - $a_title = sprintf( __( 'Edit “%s”' ), $title ); |
|
295 | + $course_learners = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_learners_course_learners', array('post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any'))); |
|
296 | + $title = get_the_title($item); |
|
297 | + $a_title = sprintf(__('Edit “%s”'), $title); |
|
298 | 298 | |
299 | 299 | $grading_action = ''; |
300 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
301 | - $grading_action = ' <a class="button" href="' . esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $item->ID ), admin_url( 'admin.php' ) ) ) . '">' . __( 'Grading', 'woothemes-sensei' ) . '</a>'; |
|
300 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
301 | + $grading_action = ' <a class="button" href="'.esc_url(add_query_arg(array('page' => 'sensei_grading', 'course_id' => $item->ID), admin_url('admin.php'))).'">'.__('Grading', 'woothemes-sensei').'</a>'; |
|
302 | 302 | } |
303 | 303 | |
304 | - $column_data = apply_filters( 'sensei_learners_main_column_data', array( |
|
305 | - 'title' => '<strong><a class="row-title" href="' . admin_url( 'post.php?action=edit&post=' . $item->ID ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>', |
|
304 | + $column_data = apply_filters('sensei_learners_main_column_data', array( |
|
305 | + 'title' => '<strong><a class="row-title" href="'.admin_url('post.php?action=edit&post='.$item->ID).'" title="'.esc_attr($a_title).'">'.$title.'</a></strong>', |
|
306 | 306 | 'num_learners' => $course_learners, |
307 | 307 | 'updated' => $item->post_modified, |
308 | - 'actions' => '<a class="button" href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $item->ID, 'view' => 'learners' ), admin_url( 'admin.php' ) ) ) . '">' . __( 'Manage learners', 'woothemes-sensei' ) . '</a> ' . $grading_action, |
|
309 | - ), $item ); |
|
308 | + 'actions' => '<a class="button" href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'course_id' => $item->ID, 'view' => 'learners'), admin_url('admin.php'))).'">'.__('Manage learners', 'woothemes-sensei').'</a> '.$grading_action, |
|
309 | + ), $item); |
|
310 | 310 | |
311 | 311 | break; |
312 | 312 | } // switch |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @since 1.7.0 |
320 | 320 | * @return array courses |
321 | 321 | */ |
322 | - private function get_courses( $args ) { |
|
322 | + private function get_courses($args) { |
|
323 | 323 | $course_args = array( |
324 | 324 | 'post_type' => 'course', |
325 | 325 | 'post_status' => 'publish', |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | 'order' => $args['order'], |
330 | 330 | ); |
331 | 331 | |
332 | - if( $args['category'] ) { |
|
332 | + if ($args['category']) { |
|
333 | 333 | $course_args['tax_query'][] = array( |
334 | 334 | 'taxonomy' => 'course-category', |
335 | 335 | 'field' => 'id', |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | ); |
338 | 338 | } |
339 | 339 | |
340 | - if( $args['search'] ) { |
|
340 | + if ($args['search']) { |
|
341 | 341 | $course_args['s'] = $args['search']; |
342 | 342 | } |
343 | 343 | |
344 | - $courses_query = new WP_Query( apply_filters( 'sensei_learners_filter_courses', $course_args ) ); |
|
344 | + $courses_query = new WP_Query(apply_filters('sensei_learners_filter_courses', $course_args)); |
|
345 | 345 | |
346 | 346 | $this->total_items = $courses_query->found_posts; |
347 | 347 | return $courses_query->posts; |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | * @since 1.7.0 |
353 | 353 | * @return array lessons |
354 | 354 | */ |
355 | - private function get_lessons( $args ) { |
|
355 | + private function get_lessons($args) { |
|
356 | 356 | $lesson_args = array( |
357 | 357 | 'post_type' => 'lesson', |
358 | 358 | 'post_status' => 'publish', |
@@ -362,18 +362,18 @@ discard block |
||
362 | 362 | 'order' => $args['order'], |
363 | 363 | ); |
364 | 364 | |
365 | - if( $this->course_id ) { |
|
365 | + if ($this->course_id) { |
|
366 | 366 | $lesson_args['meta_query'][] = array( |
367 | 367 | 'key' => '_lesson_course', |
368 | 368 | 'value' => $this->course_id, |
369 | 369 | ); |
370 | 370 | } |
371 | 371 | |
372 | - if( $args['search'] ) { |
|
372 | + if ($args['search']) { |
|
373 | 373 | $lesson_args['s'] = $args['search']; |
374 | 374 | } |
375 | 375 | |
376 | - $lessons_query = new WP_Query( apply_filters( 'sensei_learners_filter_lessons', $lesson_args ) ); |
|
376 | + $lessons_query = new WP_Query(apply_filters('sensei_learners_filter_lessons', $lesson_args)); |
|
377 | 377 | |
378 | 378 | $this->total_items = $lessons_query->found_posts; |
379 | 379 | return $lessons_query->posts; |
@@ -384,22 +384,22 @@ discard block |
||
384 | 384 | * @since 1.7.0 |
385 | 385 | * @return array learners |
386 | 386 | */ |
387 | - private function get_learners( $args ) { |
|
387 | + private function get_learners($args) { |
|
388 | 388 | |
389 | 389 | $user_ids = false; |
390 | 390 | $post_id = 0; |
391 | 391 | $activity = ''; |
392 | 392 | |
393 | - if( $this->lesson_id ) { |
|
394 | - $post_id = intval( $this->lesson_id ); |
|
393 | + if ($this->lesson_id) { |
|
394 | + $post_id = intval($this->lesson_id); |
|
395 | 395 | $activity = 'sensei_lesson_status'; |
396 | 396 | } |
397 | - elseif( $this->course_id ) { |
|
398 | - $post_id = intval( $this->course_id ); |
|
397 | + elseif ($this->course_id) { |
|
398 | + $post_id = intval($this->course_id); |
|
399 | 399 | $activity = 'sensei_course_status'; |
400 | 400 | } |
401 | 401 | |
402 | - if( ! $post_id || ! $activity ) { |
|
402 | + if ( ! $post_id || ! $activity) { |
|
403 | 403 | $this->total_items = 0; |
404 | 404 | return array(); |
405 | 405 | } |
@@ -415,32 +415,32 @@ discard block |
||
415 | 415 | ); |
416 | 416 | |
417 | 417 | // Searching users on statuses requires sub-selecting the statuses by user_ids |
418 | - if ( $args['search'] ) { |
|
418 | + if ($args['search']) { |
|
419 | 419 | $user_args = array( |
420 | - 'search' => '*' . $args['search'] . '*', |
|
420 | + 'search' => '*'.$args['search'].'*', |
|
421 | 421 | 'fields' => 'ID' |
422 | 422 | ); |
423 | 423 | // Filter for extending |
424 | - $user_args = apply_filters( 'sensei_learners_search_users', $user_args ); |
|
425 | - if ( !empty( $user_args ) ) { |
|
426 | - $learners_search = new WP_User_Query( $user_args ); |
|
424 | + $user_args = apply_filters('sensei_learners_search_users', $user_args); |
|
425 | + if ( ! empty($user_args)) { |
|
426 | + $learners_search = new WP_User_Query($user_args); |
|
427 | 427 | $activity_args['user_id'] = $learners_search->get_results(); |
428 | 428 | } |
429 | 429 | } |
430 | 430 | |
431 | - $activity_args = apply_filters( 'sensei_learners_filter_users', $activity_args ); |
|
431 | + $activity_args = apply_filters('sensei_learners_filter_users', $activity_args); |
|
432 | 432 | |
433 | 433 | // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice |
434 | - $total_learners = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); |
|
434 | + $total_learners = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); |
|
435 | 435 | // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? |
436 | - if ( $total_learners < $activity_args['offset'] ) { |
|
437 | - $new_paged = floor( $total_learners / $activity_args['number'] ); |
|
436 | + if ($total_learners < $activity_args['offset']) { |
|
437 | + $new_paged = floor($total_learners / $activity_args['number']); |
|
438 | 438 | $activity_args['offset'] = $new_paged * $activity_args['number']; |
439 | 439 | } |
440 | - $learners = Sensei_Utils::sensei_check_for_activity( $activity_args, true ); |
|
440 | + $learners = Sensei_Utils::sensei_check_for_activity($activity_args, true); |
|
441 | 441 | // Need to always return an array, even with only 1 item |
442 | - if ( !is_array($learners) ) { |
|
443 | - $learners = array( $learners ); |
|
442 | + if ( ! is_array($learners)) { |
|
443 | + $learners = array($learners); |
|
444 | 444 | } |
445 | 445 | $this->total_items = $total_learners; |
446 | 446 | return $learners; |
@@ -453,22 +453,22 @@ discard block |
||
453 | 453 | * @return void |
454 | 454 | */ |
455 | 455 | public function no_items() { |
456 | - switch( $this->view ) { |
|
456 | + switch ($this->view) { |
|
457 | 457 | case 'learners' : |
458 | - $text = __( 'No learners found.', 'woothemes-sensei' ); |
|
458 | + $text = __('No learners found.', 'woothemes-sensei'); |
|
459 | 459 | break; |
460 | 460 | |
461 | 461 | case 'lessons' : |
462 | - $text = __( 'No lessons found.', 'woothemes-sensei' ); |
|
462 | + $text = __('No lessons found.', 'woothemes-sensei'); |
|
463 | 463 | break; |
464 | 464 | |
465 | 465 | case 'courses': |
466 | 466 | case 'default': |
467 | 467 | default: |
468 | - $text = __( 'No courses found.', 'woothemes-sensei' ); |
|
468 | + $text = __('No courses found.', 'woothemes-sensei'); |
|
469 | 469 | break; |
470 | 470 | } |
471 | - echo apply_filters( 'sensei_learners_no_items_text', $text ); |
|
471 | + echo apply_filters('sensei_learners_no_items_text', $text); |
|
472 | 472 | } // End no_items() |
473 | 473 | |
474 | 474 | /** |
@@ -479,40 +479,40 @@ discard block |
||
479 | 479 | public function data_table_header() { |
480 | 480 | |
481 | 481 | echo '<div class="learners-selects">'; |
482 | - do_action( 'sensei_learners_before_dropdown_filters' ); |
|
482 | + do_action('sensei_learners_before_dropdown_filters'); |
|
483 | 483 | |
484 | 484 | // Display Course Categories only on default view |
485 | - if( 'courses' == $this->view ) { |
|
485 | + if ('courses' == $this->view) { |
|
486 | 486 | |
487 | 487 | $selected_cat = 0; |
488 | - if ( isset( $_GET['course_cat'] ) && '' != esc_html( $_GET['course_cat'] ) ) { |
|
489 | - $selected_cat = intval( $_GET['course_cat'] ); |
|
488 | + if (isset($_GET['course_cat']) && '' != esc_html($_GET['course_cat'])) { |
|
489 | + $selected_cat = intval($_GET['course_cat']); |
|
490 | 490 | } |
491 | 491 | |
492 | - $cats = get_terms( 'course-category', array( 'hide_empty' => false ) ); |
|
492 | + $cats = get_terms('course-category', array('hide_empty' => false)); |
|
493 | 493 | |
494 | - echo '<div class="select-box">' . "\n"; |
|
494 | + echo '<div class="select-box">'."\n"; |
|
495 | 495 | |
496 | - echo '<select id="course-category-options" data-placeholder="' . __( 'Course Category', 'woothemes-sensei' ) . '" name="learners_course_cat" class="chosen_select widefat">' . "\n"; |
|
496 | + echo '<select id="course-category-options" data-placeholder="'.__('Course Category', 'woothemes-sensei').'" name="learners_course_cat" class="chosen_select widefat">'."\n"; |
|
497 | 497 | |
498 | - echo '<option value="0">' . __( 'All Course Categories', 'woothemes-sensei' ) . '</option>' . "\n"; |
|
498 | + echo '<option value="0">'.__('All Course Categories', 'woothemes-sensei').'</option>'."\n"; |
|
499 | 499 | |
500 | - foreach( $cats as $cat ) { |
|
501 | - echo '<option value="' . $cat->term_id . '"' . selected( $cat->term_id, $selected_cat, false ) . '>' . $cat->name . '</option>' . "\n"; |
|
500 | + foreach ($cats as $cat) { |
|
501 | + echo '<option value="'.$cat->term_id.'"'.selected($cat->term_id, $selected_cat, false).'>'.$cat->name.'</option>'."\n"; |
|
502 | 502 | } |
503 | 503 | |
504 | - echo '</select>' . "\n"; |
|
504 | + echo '</select>'."\n"; |
|
505 | 505 | |
506 | - echo '</div>' . "\n"; |
|
506 | + echo '</div>'."\n"; |
|
507 | 507 | } |
508 | 508 | echo '</div><!-- /.learners-selects -->'; |
509 | 509 | |
510 | 510 | $menu = array(); |
511 | 511 | // Have Course no Lesson |
512 | - if( $this->course_id && ! $this->lesson_id ) { |
|
512 | + if ($this->course_id && ! $this->lesson_id) { |
|
513 | 513 | |
514 | 514 | $learners_class = $lessons_class = ''; |
515 | - switch( $this->view ) { |
|
515 | + switch ($this->view) { |
|
516 | 516 | case 'learners': |
517 | 517 | $learners_class = 'current'; |
518 | 518 | break; |
@@ -531,12 +531,12 @@ discard block |
||
531 | 531 | $learner_args['view'] = 'learners'; |
532 | 532 | $lesson_args['view'] = 'lessons'; |
533 | 533 | |
534 | - $menu['learners'] = '<a class="' . $learners_class . '" href="' . esc_url( add_query_arg( $learner_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Learners', 'woothemes-sensei' ) . '</a>'; |
|
535 | - $menu['lessons'] = '<a class="' . $lessons_class . '" href="' . esc_url( add_query_arg( $lesson_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Lessons', 'woothemes-sensei' ) . '</a>'; |
|
534 | + $menu['learners'] = '<a class="'.$learners_class.'" href="'.esc_url(add_query_arg($learner_args, admin_url('admin.php'))).'">'.__('Learners', 'woothemes-sensei').'</a>'; |
|
535 | + $menu['lessons'] = '<a class="'.$lessons_class.'" href="'.esc_url(add_query_arg($lesson_args, admin_url('admin.php'))).'">'.__('Lessons', 'woothemes-sensei').'</a>'; |
|
536 | 536 | |
537 | 537 | } |
538 | 538 | // Have Course and Lesson |
539 | - elseif( $this->course_id && $this->lesson_id ) { |
|
539 | + elseif ($this->course_id && $this->lesson_id) { |
|
540 | 540 | |
541 | 541 | $query_args = array( |
542 | 542 | 'page' => $this->page_slug, |
@@ -544,18 +544,18 @@ discard block |
||
544 | 544 | 'view' => 'lessons' |
545 | 545 | ); |
546 | 546 | |
547 | - $course = get_the_title( $this->course_id ); |
|
547 | + $course = get_the_title($this->course_id); |
|
548 | 548 | |
549 | - $menu['back'] = '<a href="' . esc_url( add_query_arg( $query_args, admin_url( 'admin.php' ) ) ) . '">' . sprintf( __( '%1$sBack to %2$s%3$s', 'woothemes-sensei' ), '<em>← ', $course, '</em>' ) . '</a>'; |
|
549 | + $menu['back'] = '<a href="'.esc_url(add_query_arg($query_args, admin_url('admin.php'))).'">'.sprintf(__('%1$sBack to %2$s%3$s', 'woothemes-sensei'), '<em>← ', $course, '</em>').'</a>'; |
|
550 | 550 | } |
551 | - $menu = apply_filters( 'sensei_learners_sub_menu', $menu ); |
|
552 | - if ( !empty($menu) ) { |
|
553 | - echo '<ul class="subsubsub">' . "\n"; |
|
554 | - foreach ( $menu as $class => $item ) { |
|
555 | - $menu[ $class ] = "\t<li class='$class'>$item"; |
|
551 | + $menu = apply_filters('sensei_learners_sub_menu', $menu); |
|
552 | + if ( ! empty($menu)) { |
|
553 | + echo '<ul class="subsubsub">'."\n"; |
|
554 | + foreach ($menu as $class => $item) { |
|
555 | + $menu[$class] = "\t<li class='$class'>$item"; |
|
556 | 556 | } |
557 | - echo implode( " |</li>\n", $menu ) . "</li>\n"; |
|
558 | - echo '</ul>' . "\n"; |
|
557 | + echo implode(" |</li>\n", $menu)."</li>\n"; |
|
558 | + echo '</ul>'."\n"; |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | } // End data_table_header() |
@@ -580,50 +580,50 @@ discard block |
||
580 | 580 | $form_post_type = ''; |
581 | 581 | $form_course_id = 0; |
582 | 582 | $form_lesson_id = 0; |
583 | - if( $this->course_id && ! $this->lesson_id ) { |
|
584 | - $post_title = get_the_title( $this->course_id ); |
|
585 | - $post_type = __( 'Course', 'woothemes-sensei' ); |
|
583 | + if ($this->course_id && ! $this->lesson_id) { |
|
584 | + $post_title = get_the_title($this->course_id); |
|
585 | + $post_type = __('Course', 'woothemes-sensei'); |
|
586 | 586 | $form_post_type = 'course'; |
587 | 587 | $form_course_id = $this->course_id; |
588 | 588 | } |
589 | - elseif( $this->course_id && $this->lesson_id ) { |
|
590 | - $post_title = get_the_title( $this->lesson_id ); |
|
591 | - $post_type = __( 'Lesson', 'woothemes-sensei' ); |
|
589 | + elseif ($this->course_id && $this->lesson_id) { |
|
590 | + $post_title = get_the_title($this->lesson_id); |
|
591 | + $post_type = __('Lesson', 'woothemes-sensei'); |
|
592 | 592 | $form_post_type = 'lesson'; |
593 | 593 | $form_course_id = $this->course_id; |
594 | 594 | $form_lesson_id = $this->lesson_id; |
595 | - $course_title = get_the_title( $this->course_id ); |
|
595 | + $course_title = get_the_title($this->course_id); |
|
596 | 596 | } |
597 | - if ( empty($form_post_type) ) { |
|
597 | + if (empty($form_post_type)) { |
|
598 | 598 | return; |
599 | 599 | } |
600 | 600 | ?> |
601 | 601 | <div class="postbox"> |
602 | - <h3><span><?php printf( __( 'Add Learner to %1$s', 'woothemes-sensei' ), $post_type ); ?></span></h3> |
|
602 | + <h3><span><?php printf(__('Add Learner to %1$s', 'woothemes-sensei'), $post_type); ?></span></h3> |
|
603 | 603 | <div class="inside"> |
604 | 604 | <form name="add_learner" action="" method="post"> |
605 | 605 | <p> |
606 | - <input name="add_user_id" placeholder="<?php _e( 'Find learner', 'woothemes-sensei' ) ;?>" id="add_learner_search" style="min-width:300px;" /> |
|
607 | - <?php if( 'lesson' == $form_post_type ) { ?> |
|
608 | - <label for="add_complete_lesson"><input type="checkbox" id="add_complete_lesson" name="add_complete_lesson" value="yes" /> <?php _e( 'Complete lesson for learner', 'woothemes-sensei' ); ?></label> |
|
609 | - <?php } elseif( 'course' == $form_post_type ) { ?> |
|
610 | - <label for="add_complete_course"><input type="checkbox" id="add_complete_course" name="add_complete_course" value="yes" /> <?php _e( 'Complete course for learner', 'woothemes-sensei' ); ?></label> |
|
606 | + <input name="add_user_id" placeholder="<?php _e('Find learner', 'woothemes-sensei'); ?>" id="add_learner_search" style="min-width:300px;" /> |
|
607 | + <?php if ('lesson' == $form_post_type) { ?> |
|
608 | + <label for="add_complete_lesson"><input type="checkbox" id="add_complete_lesson" name="add_complete_lesson" value="yes" /> <?php _e('Complete lesson for learner', 'woothemes-sensei'); ?></label> |
|
609 | + <?php } elseif ('course' == $form_post_type) { ?> |
|
610 | + <label for="add_complete_course"><input type="checkbox" id="add_complete_course" name="add_complete_course" value="yes" /> <?php _e('Complete course for learner', 'woothemes-sensei'); ?></label> |
|
611 | 611 | <?php } ?> |
612 | 612 | <br/> |
613 | - <span class="description"><?php _e( 'Search for a user by typing their name or username.', 'woothemes-sensei' ); ?></span> |
|
613 | + <span class="description"><?php _e('Search for a user by typing their name or username.', 'woothemes-sensei'); ?></span> |
|
614 | 614 | </p> |
615 | - <p><?php submit_button( sprintf( __( 'Add to \'%1$s\'', 'woothemes-sensei' ), $post_title ), 'primary', 'add_learner_submit', false, array() ); ?></p> |
|
616 | - <?php if( 'lesson' == $form_post_type ) { ?> |
|
617 | - <p><span class="description"><?php printf( __( 'Learner will also be added to the course \'%1$s\' if they are not already taking it.', 'woothemes-sensei' ), $course_title ); ?></span></p> |
|
615 | + <p><?php submit_button(sprintf(__('Add to \'%1$s\'', 'woothemes-sensei'), $post_title), 'primary', 'add_learner_submit', false, array()); ?></p> |
|
616 | + <?php if ('lesson' == $form_post_type) { ?> |
|
617 | + <p><span class="description"><?php printf(__('Learner will also be added to the course \'%1$s\' if they are not already taking it.', 'woothemes-sensei'), $course_title); ?></span></p> |
|
618 | 618 | <?php } ?> |
619 | 619 | |
620 | 620 | <input type="hidden" name="add_post_type" value="<?php echo $form_post_type; ?>" /> |
621 | 621 | <input type="hidden" name="add_course_id" value="<?php echo $form_course_id; ?>" /> |
622 | 622 | <input type="hidden" name="add_lesson_id" value="<?php echo $form_lesson_id; ?>" /> |
623 | 623 | <?php |
624 | - do_action( 'sensei_learners_add_learner_form' ); |
|
624 | + do_action('sensei_learners_add_learner_form'); |
|
625 | 625 | ?> |
626 | - <?php wp_nonce_field( 'add_learner_to_sensei', 'add_learner_nonce' ); ?> |
|
626 | + <?php wp_nonce_field('add_learner_to_sensei', 'add_learner_nonce'); ?> |
|
627 | 627 | </form> |
628 | 628 | </div> |
629 | 629 | </div> |
@@ -635,19 +635,19 @@ discard block |
||
635 | 635 | * @since 1.7.0 |
636 | 636 | * @return string $text |
637 | 637 | */ |
638 | - public function search_button( $text = '' ) { |
|
638 | + public function search_button($text = '') { |
|
639 | 639 | |
640 | - switch( $this->view ) { |
|
640 | + switch ($this->view) { |
|
641 | 641 | case 'learners': |
642 | - $text = __( 'Search Learners', 'woothemes-sensei' ); |
|
642 | + $text = __('Search Learners', 'woothemes-sensei'); |
|
643 | 643 | break; |
644 | 644 | |
645 | 645 | case 'lessons': |
646 | - $text = __( 'Search Lessons', 'woothemes-sensei' ); |
|
646 | + $text = __('Search Lessons', 'woothemes-sensei'); |
|
647 | 647 | break; |
648 | 648 | |
649 | 649 | default: |
650 | - $text = __( 'Search Courses', 'woothemes-sensei' ); |
|
650 | + $text = __('Search Courses', 'woothemes-sensei'); |
|
651 | 651 | break; |
652 | 652 | } |
653 | 653 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Grading Class |
@@ -23,30 +23,30 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param $file |
25 | 25 | */ |
26 | - public function __construct ( $file ) { |
|
27 | - $this->name = __( 'Grading', 'woothemes-sensei' ); |
|
26 | + public function __construct($file) { |
|
27 | + $this->name = __('Grading', 'woothemes-sensei'); |
|
28 | 28 | $this->file = $file; |
29 | 29 | $this->page_slug = 'sensei_grading'; |
30 | 30 | |
31 | 31 | // Admin functions |
32 | - if ( is_admin() ) { |
|
33 | - add_action( 'admin_menu', array( $this, 'grading_admin_menu' ), 20); |
|
34 | - add_action( 'grading_wrapper_container', array( $this, 'wrapper_container' ) ); |
|
35 | - if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) { |
|
36 | - add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) ); |
|
37 | - add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) ); |
|
32 | + if (is_admin()) { |
|
33 | + add_action('admin_menu', array($this, 'grading_admin_menu'), 20); |
|
34 | + add_action('grading_wrapper_container', array($this, 'wrapper_container')); |
|
35 | + if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) { |
|
36 | + add_action('admin_print_scripts', array($this, 'enqueue_scripts')); |
|
37 | + add_action('admin_print_styles', array($this, 'enqueue_styles')); |
|
38 | 38 | } |
39 | 39 | |
40 | - add_action( 'admin_init', array( $this, 'admin_process_grading_submission' ) ); |
|
40 | + add_action('admin_init', array($this, 'admin_process_grading_submission')); |
|
41 | 41 | |
42 | - add_action( 'admin_notices', array( $this, 'add_grading_notices' ) ); |
|
42 | + add_action('admin_notices', array($this, 'add_grading_notices')); |
|
43 | 43 | // add_action( 'sensei_grading_notices', array( $this, 'sensei_grading_notices' ) ); |
44 | 44 | } // End If Statement |
45 | 45 | |
46 | 46 | // Ajax functions |
47 | - if ( is_admin() ) { |
|
48 | - add_action( 'wp_ajax_get_lessons_dropdown', array( $this, 'get_lessons_dropdown' ) ); |
|
49 | - add_action( 'wp_ajax_get_redirect_url', array( $this, 'get_redirect_url' ) ); |
|
47 | + if (is_admin()) { |
|
48 | + add_action('wp_ajax_get_lessons_dropdown', array($this, 'get_lessons_dropdown')); |
|
49 | + add_action('wp_ajax_get_redirect_url', array($this, 'get_redirect_url')); |
|
50 | 50 | } // End If Statement |
51 | 51 | } // End __construct() |
52 | 52 | |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | public function grading_admin_menu() { |
60 | 60 | global $menu; |
61 | 61 | |
62 | - if ( current_user_can( 'manage_sensei_grades' ) ) { |
|
63 | - $grading_page = add_submenu_page('sensei', __('Grading', 'woothemes-sensei'), __('Grading', 'woothemes-sensei') , 'manage_sensei_grades', $this->page_slug, array( $this, 'grading_page' ) ); |
|
62 | + if (current_user_can('manage_sensei_grades')) { |
|
63 | + $grading_page = add_submenu_page('sensei', __('Grading', 'woothemes-sensei'), __('Grading', 'woothemes-sensei'), 'manage_sensei_grades', $this->page_slug, array($this, 'grading_page')); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | } // End grading_admin_menu() |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | * @since 1.3.0 |
74 | 74 | * @return void |
75 | 75 | */ |
76 | - public function enqueue_scripts () { |
|
76 | + public function enqueue_scripts() { |
|
77 | 77 | |
78 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
78 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
79 | 79 | |
80 | 80 | // Load Grading JS |
81 | - wp_enqueue_script( 'sensei-grading-general', Sensei()->plugin_url . 'assets/js/grading-general' . $suffix . '.js', array( 'jquery' ), Sensei()->version ); |
|
81 | + wp_enqueue_script('sensei-grading-general', Sensei()->plugin_url.'assets/js/grading-general'.$suffix.'.js', array('jquery'), Sensei()->version); |
|
82 | 82 | |
83 | 83 | } // End enqueue_scripts() |
84 | 84 | |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | * @since 1.0.0 |
91 | 91 | * @return void |
92 | 92 | */ |
93 | - public function enqueue_styles () { |
|
93 | + public function enqueue_styles() { |
|
94 | 94 | |
95 | - wp_enqueue_style( Sensei()->token . '-admin' ); |
|
95 | + wp_enqueue_style(Sensei()->token.'-admin'); |
|
96 | 96 | |
97 | - wp_enqueue_style( 'woothemes-sensei-settings-api', Sensei()->plugin_url . 'assets/css/settings.css', '', Sensei()->version ); |
|
97 | + wp_enqueue_style('woothemes-sensei-settings-api', Sensei()->plugin_url.'assets/css/settings.css', '', Sensei()->version); |
|
98 | 98 | |
99 | 99 | } // End enqueue_styles() |
100 | 100 | |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | public function load_data_table_files() { |
107 | 107 | |
108 | 108 | // Load Grading Classes |
109 | - $classes_to_load = array( 'list-table', |
|
109 | + $classes_to_load = array('list-table', |
|
110 | 110 | 'grading-main', |
111 | 111 | 'grading-user-quiz' |
112 | 112 | ); |
113 | - foreach ( $classes_to_load as $class_file ) { |
|
114 | - Sensei()->load_class( $class_file ); |
|
113 | + foreach ($classes_to_load as $class_file) { |
|
114 | + Sensei()->load_class($class_file); |
|
115 | 115 | } // End For Loop |
116 | 116 | } // End load_data_table_files() |
117 | 117 | |
@@ -123,16 +123,16 @@ discard block |
||
123 | 123 | * @param undefined $optional_data optional constructor arguments |
124 | 124 | * @return object class instance object |
125 | 125 | */ |
126 | - public function load_data_object( $name = '', $data = 0, $optional_data = null ) { |
|
126 | + public function load_data_object($name = '', $data = 0, $optional_data = null) { |
|
127 | 127 | // Load Analysis data |
128 | - $object_name = 'WooThemes_Sensei_Grading_' . $name; |
|
129 | - if ( is_null($optional_data) ) { |
|
130 | - $sensei_grading_object = new $object_name( $data ); |
|
128 | + $object_name = 'WooThemes_Sensei_Grading_'.$name; |
|
129 | + if (is_null($optional_data)) { |
|
130 | + $sensei_grading_object = new $object_name($data); |
|
131 | 131 | } |
132 | 132 | else { |
133 | - $sensei_grading_object = new $object_name( $data, $optional_data ); |
|
133 | + $sensei_grading_object = new $object_name($data, $optional_data); |
|
134 | 134 | } // End If Statement |
135 | - if ( 'Main' == $name ) { |
|
135 | + if ('Main' == $name) { |
|
136 | 136 | $sensei_grading_object->prepare_items(); |
137 | 137 | } // End If Statement |
138 | 138 | return $sensei_grading_object; |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function grading_page() { |
148 | 148 | |
149 | - if ( isset( $_GET['quiz_id'] ) && 0 < intval( $_GET['quiz_id'] ) && isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { |
|
149 | + if (isset($_GET['quiz_id']) && 0 < intval($_GET['quiz_id']) && isset($_GET['user']) && 0 < intval($_GET['user'])) { |
|
150 | 150 | $this->grading_user_quiz_view(); |
151 | 151 | } |
152 | 152 | else { |
@@ -162,23 +162,23 @@ discard block |
||
162 | 162 | public function grading_default_view() { |
163 | 163 | |
164 | 164 | // Load Grading data |
165 | - if( !empty( $_GET['course_id'] ) ) { |
|
166 | - $course_id = intval( $_GET['course_id'] ); |
|
165 | + if ( ! empty($_GET['course_id'])) { |
|
166 | + $course_id = intval($_GET['course_id']); |
|
167 | 167 | } |
168 | - if( !empty( $_GET['lesson_id'] ) ) { |
|
169 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
168 | + if ( ! empty($_GET['lesson_id'])) { |
|
169 | + $lesson_id = intval($_GET['lesson_id']); |
|
170 | 170 | } |
171 | - if( !empty( $_GET['user_id'] ) ) { |
|
172 | - $user_id = intval( $_GET['user_id'] ); |
|
171 | + if ( ! empty($_GET['user_id'])) { |
|
172 | + $user_id = intval($_GET['user_id']); |
|
173 | 173 | } |
174 | - if( !empty( $_GET['view'] ) ) { |
|
175 | - $view = esc_html( $_GET['view'] ); |
|
174 | + if ( ! empty($_GET['view'])) { |
|
175 | + $view = esc_html($_GET['view']); |
|
176 | 176 | } |
177 | - $sensei_grading_overview = $this->load_data_object( 'Main', compact( 'course_id', 'lesson_id', 'user_id', 'view' ) ); |
|
177 | + $sensei_grading_overview = $this->load_data_object('Main', compact('course_id', 'lesson_id', 'user_id', 'view')); |
|
178 | 178 | |
179 | 179 | // Wrappers |
180 | - do_action( 'grading_before_container' ); |
|
181 | - do_action( 'grading_wrapper_container', 'top' ); |
|
180 | + do_action('grading_before_container'); |
|
181 | + do_action('grading_wrapper_container', 'top'); |
|
182 | 182 | $this->grading_headers(); |
183 | 183 | ?> |
184 | 184 | <div id="poststuff" class="sensei-grading-wrap"> |
@@ -186,12 +186,12 @@ discard block |
||
186 | 186 | <?php $sensei_grading_overview->display(); ?> |
187 | 187 | </div> |
188 | 188 | <div class="sensei-grading-extra"> |
189 | - <?php do_action( 'sensei_grading_extra' ); ?> |
|
189 | + <?php do_action('sensei_grading_extra'); ?> |
|
190 | 190 | </div> |
191 | 191 | </div> |
192 | 192 | <?php |
193 | - do_action( 'grading_wrapper_container', 'bottom' ); |
|
194 | - do_action( 'grading_after_container' ); |
|
193 | + do_action('grading_wrapper_container', 'bottom'); |
|
194 | + do_action('grading_after_container'); |
|
195 | 195 | } // End grading_default_view() |
196 | 196 | |
197 | 197 | /** |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | // Load Grading data |
205 | 205 | $user_id = 0; |
206 | 206 | $quiz_id = 0; |
207 | - if( isset( $_GET['user'] ) ) { |
|
208 | - $user_id = intval( $_GET['user'] ); |
|
207 | + if (isset($_GET['user'])) { |
|
208 | + $user_id = intval($_GET['user']); |
|
209 | 209 | } |
210 | - if( isset( $_GET['quiz_id'] ) ) { |
|
211 | - $quiz_id = intval( $_GET['quiz_id'] ); |
|
210 | + if (isset($_GET['quiz_id'])) { |
|
211 | + $quiz_id = intval($_GET['quiz_id']); |
|
212 | 212 | } |
213 | - $sensei_grading_user_profile = $this->load_data_object( 'User_Quiz', $user_id, $quiz_id ); |
|
213 | + $sensei_grading_user_profile = $this->load_data_object('User_Quiz', $user_id, $quiz_id); |
|
214 | 214 | // Wrappers |
215 | - do_action( 'grading_before_container' ); |
|
216 | - do_action( 'grading_wrapper_container', 'top' ); |
|
217 | - $this->grading_headers( array( 'nav' => 'user_quiz' ) ); |
|
215 | + do_action('grading_before_container'); |
|
216 | + do_action('grading_wrapper_container', 'top'); |
|
217 | + $this->grading_headers(array('nav' => 'user_quiz')); |
|
218 | 218 | ?> |
219 | 219 | <div id="poststuff" class="sensei-grading-wrap user-profile"> |
220 | 220 | <div class="sensei-grading-main"> |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | </div> |
224 | 224 | </div> |
225 | 225 | <?php |
226 | - do_action( 'grading_wrapper_container', 'bottom' ); |
|
227 | - do_action( 'grading_after_container' ); |
|
226 | + do_action('grading_wrapper_container', 'bottom'); |
|
227 | + do_action('grading_after_container'); |
|
228 | 228 | } // End grading_user_quiz_view() |
229 | 229 | |
230 | 230 | /** |
@@ -233,14 +233,14 @@ discard block |
||
233 | 233 | * @param array $args |
234 | 234 | * @return void |
235 | 235 | */ |
236 | - public function grading_headers( $args = array( 'nav' => 'default' ) ) { |
|
236 | + public function grading_headers($args = array('nav' => 'default')) { |
|
237 | 237 | |
238 | - $function = 'grading_' . $args['nav'] . '_nav'; |
|
238 | + $function = 'grading_'.$args['nav'].'_nav'; |
|
239 | 239 | $this->$function(); |
240 | 240 | ?> |
241 | - <p class="powered-by-woo"><?php _e( 'Powered by', 'woothemes-sensei' ); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p> |
|
241 | + <p class="powered-by-woo"><?php _e('Powered by', 'woothemes-sensei'); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p> |
|
242 | 242 | <?php |
243 | - do_action( 'sensei_grading_after_headers' ); |
|
243 | + do_action('sensei_grading_after_headers'); |
|
244 | 244 | } // End grading_headers() |
245 | 245 | |
246 | 246 | /** |
@@ -249,10 +249,10 @@ discard block |
||
249 | 249 | * @param $which string |
250 | 250 | * @return void |
251 | 251 | */ |
252 | - public function wrapper_container( $which ) { |
|
253 | - if ( 'top' == $which ) { |
|
252 | + public function wrapper_container($which) { |
|
253 | + if ('top' == $which) { |
|
254 | 254 | ?><div id="woothemes-sensei" class="wrap woothemes-sensei"><?php |
255 | - } elseif ( 'bottom' == $which ) { |
|
255 | + } elseif ('bottom' == $which) { |
|
256 | 256 | ?></div><!--/#woothemes-sensei--><?php |
257 | 257 | } // End If Statement |
258 | 258 | } // End wrapper_container() |
@@ -265,29 +265,29 @@ discard block |
||
265 | 265 | public function grading_default_nav() { |
266 | 266 | global $wp_version; |
267 | 267 | |
268 | - $title = sprintf( '<a href="%s">%s</a>', esc_url(add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ) ), esc_html( $this->name ) ); |
|
269 | - if ( isset( $_GET['course_id'] ) ) { |
|
270 | - $course_id = intval( $_GET['course_id'] ); |
|
271 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
272 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
273 | - $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
|
268 | + $title = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => $this->page_slug), admin_url('admin.php'))), esc_html($this->name)); |
|
269 | + if (isset($_GET['course_id'])) { |
|
270 | + $course_id = intval($_GET['course_id']); |
|
271 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
272 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
273 | + $title .= sprintf(' <span class="course-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); |
|
274 | 274 | } |
275 | 275 | else { |
276 | - $title .= sprintf( ' <span class="course-title">> %s</span>', get_the_title( $course_id ) ); |
|
276 | + $title .= sprintf(' <span class="course-title">> %s</span>', get_the_title($course_id)); |
|
277 | 277 | } |
278 | 278 | } |
279 | - if ( isset( $_GET['lesson_id'] ) ) { |
|
280 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
281 | - $title .= ' <span class="lesson-title">> ' . get_the_title( intval( $lesson_id ) ) . '</span>'; |
|
279 | + if (isset($_GET['lesson_id'])) { |
|
280 | + $lesson_id = intval($_GET['lesson_id']); |
|
281 | + $title .= ' <span class="lesson-title">> '.get_the_title(intval($lesson_id)).'</span>'; |
|
282 | 282 | } |
283 | - if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) { |
|
283 | + if (isset($_GET['user_id']) && 0 < intval($_GET['user_id'])) { |
|
284 | 284 | |
285 | - $user_name = Sensei_Learner::get_full_name( $_GET['user_id'] ); |
|
286 | - $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
|
285 | + $user_name = Sensei_Learner::get_full_name($_GET['user_id']); |
|
286 | + $title .= ' <span class="user-title">> '.$user_name.'</span>'; |
|
287 | 287 | |
288 | 288 | } // End If Statement |
289 | 289 | ?> |
290 | - <h2><?php echo apply_filters( 'sensei_grading_nav_title', $title ); ?></h2> |
|
290 | + <h2><?php echo apply_filters('sensei_grading_nav_title', $title); ?></h2> |
|
291 | 291 | <?php |
292 | 292 | } // End grading_default_nav() |
293 | 293 | |
@@ -299,29 +299,29 @@ discard block |
||
299 | 299 | public function grading_user_quiz_nav() { |
300 | 300 | global $wp_version; |
301 | 301 | |
302 | - $title = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ), esc_html( $this->name ) ); |
|
303 | - if ( isset( $_GET['quiz_id'] ) ) { |
|
304 | - $quiz_id = intval( $_GET['quiz_id'] ); |
|
305 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
306 | - $course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
307 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
308 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
309 | - $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
|
302 | + $title = sprintf('<a href="%s">%s</a>', add_query_arg(array('page' => $this->page_slug), admin_url('admin.php')), esc_html($this->name)); |
|
303 | + if (isset($_GET['quiz_id'])) { |
|
304 | + $quiz_id = intval($_GET['quiz_id']); |
|
305 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
306 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
307 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
308 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
309 | + $title .= sprintf(' <span class="course-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); |
|
310 | 310 | } |
311 | 311 | else { |
312 | - $title .= sprintf( ' <span class="course-title">> %s</span>', get_the_title( $course_id ) ); |
|
312 | + $title .= sprintf(' <span class="course-title">> %s</span>', get_the_title($course_id)); |
|
313 | 313 | } |
314 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id ), admin_url( 'admin.php' ) ); |
|
315 | - $title .= sprintf( ' <span class="lesson-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $lesson_id ) ); |
|
314 | + $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id), admin_url('admin.php')); |
|
315 | + $title .= sprintf(' <span class="lesson-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($lesson_id)); |
|
316 | 316 | } |
317 | - if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { |
|
317 | + if (isset($_GET['user']) && 0 < intval($_GET['user'])) { |
|
318 | 318 | |
319 | - $user_name = Sensei_Learner::get_full_name( $_GET['user'] ); |
|
320 | - $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
|
319 | + $user_name = Sensei_Learner::get_full_name($_GET['user']); |
|
320 | + $title .= ' <span class="user-title">> '.$user_name.'</span>'; |
|
321 | 321 | |
322 | 322 | } // End If Statement |
323 | 323 | ?> |
324 | - <h2><?php echo apply_filters( 'sensei_grading_nav_title', $title ); ?></h2> |
|
324 | + <h2><?php echo apply_filters('sensei_grading_nav_title', $title); ?></h2> |
|
325 | 325 | <?php |
326 | 326 | } // End grading_user_quiz_nav() |
327 | 327 | |
@@ -330,9 +330,9 @@ discard block |
||
330 | 330 | * @since 1.7.0 |
331 | 331 | * @return array |
332 | 332 | */ |
333 | - public function get_stati( $type ) { |
|
333 | + public function get_stati($type) { |
|
334 | 334 | $statuses = array(); |
335 | - switch( $type ) { |
|
335 | + switch ($type) { |
|
336 | 336 | case 'course' : |
337 | 337 | $statuses = array( |
338 | 338 | 'in-progress', |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | * @param array $args (default: array()) |
363 | 363 | * @return object |
364 | 364 | */ |
365 | - public function count_statuses( $args = array() ) { |
|
365 | + public function count_statuses($args = array()) { |
|
366 | 366 | global $wpdb; |
367 | 367 | |
368 | 368 | /** |
@@ -373,71 +373,71 @@ discard block |
||
373 | 373 | * @since 1.8.0 |
374 | 374 | * @param array $args |
375 | 375 | */ |
376 | - $args = apply_filters( 'sensei_count_statuses_args', $args ); |
|
376 | + $args = apply_filters('sensei_count_statuses_args', $args); |
|
377 | 377 | |
378 | - if ( 'course' == $args['type'] ) { |
|
378 | + if ('course' == $args['type']) { |
|
379 | 379 | $type = 'sensei_course_status'; |
380 | 380 | } |
381 | 381 | else { |
382 | 382 | $type = 'sensei_lesson_status'; |
383 | 383 | } |
384 | - $cache_key = 'sensei-' . $args['type'] . '-statuses'; |
|
384 | + $cache_key = 'sensei-'.$args['type'].'-statuses'; |
|
385 | 385 | |
386 | 386 | $query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s "; |
387 | 387 | |
388 | 388 | // Restrict to specific posts |
389 | - if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) { |
|
390 | - $query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')'; |
|
389 | + if (isset($args['post__in']) && ! empty($args['post__in']) && is_array($args['post__in'])) { |
|
390 | + $query .= ' AND comment_post_ID IN ('.implode(',', array_map('absint', $args['post__in'])).')'; |
|
391 | 391 | } |
392 | - elseif ( !empty( $args['post_id'] ) ) { |
|
393 | - $query .= $wpdb->prepare( ' AND comment_post_ID = %d', $args['post_id'] ); |
|
392 | + elseif ( ! empty($args['post_id'])) { |
|
393 | + $query .= $wpdb->prepare(' AND comment_post_ID = %d', $args['post_id']); |
|
394 | 394 | } |
395 | 395 | // Restrict to specific users |
396 | - if ( isset( $args['user_id'] ) && is_array( $args['user_id'] ) ) { |
|
397 | - $query .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $args['user_id'] ) ) . ')'; |
|
396 | + if (isset($args['user_id']) && is_array($args['user_id'])) { |
|
397 | + $query .= ' AND user_id IN ('.implode(',', array_map('absint', $args['user_id'])).')'; |
|
398 | 398 | } |
399 | - elseif ( !empty( $args['user_id'] ) ) { |
|
400 | - $query .= $wpdb->prepare( ' AND user_id = %d', $args['user_id'] ); |
|
399 | + elseif ( ! empty($args['user_id'])) { |
|
400 | + $query .= $wpdb->prepare(' AND user_id = %d', $args['user_id']); |
|
401 | 401 | } |
402 | 402 | $query .= ' GROUP BY comment_approved'; |
403 | 403 | |
404 | - $counts = wp_cache_get( $cache_key, 'counts' ); |
|
405 | - if ( false === $counts ) { |
|
406 | - $sql = $wpdb->prepare( $query, $type ); |
|
407 | - $results = (array) $wpdb->get_results( $sql, ARRAY_A ); |
|
408 | - $counts = array_fill_keys( $this->get_stati( $type ), 0 ); |
|
404 | + $counts = wp_cache_get($cache_key, 'counts'); |
|
405 | + if (false === $counts) { |
|
406 | + $sql = $wpdb->prepare($query, $type); |
|
407 | + $results = (array) $wpdb->get_results($sql, ARRAY_A); |
|
408 | + $counts = array_fill_keys($this->get_stati($type), 0); |
|
409 | 409 | |
410 | - foreach ( $results as $row ) { |
|
411 | - $counts[ $row['comment_approved'] ] = $row['total']; |
|
410 | + foreach ($results as $row) { |
|
411 | + $counts[$row['comment_approved']] = $row['total']; |
|
412 | 412 | } |
413 | - wp_cache_set( $cache_key, $counts, 'counts' ); |
|
413 | + wp_cache_set($cache_key, $counts, 'counts'); |
|
414 | 414 | } |
415 | 415 | |
416 | - if( ! isset( $counts['graded'] ) ) { |
|
416 | + if ( ! isset($counts['graded'])) { |
|
417 | 417 | $counts['graded'] = 0; |
418 | 418 | } |
419 | 419 | |
420 | - if( ! isset( $counts['ungraded'] ) ) { |
|
420 | + if ( ! isset($counts['ungraded'])) { |
|
421 | 421 | $counts['ungraded'] = 0; |
422 | 422 | } |
423 | 423 | |
424 | - if( ! isset( $counts['passed'] ) ) { |
|
424 | + if ( ! isset($counts['passed'])) { |
|
425 | 425 | $counts['passed'] = 0; |
426 | 426 | } |
427 | 427 | |
428 | - if( ! isset( $counts['failed'] ) ) { |
|
428 | + if ( ! isset($counts['failed'])) { |
|
429 | 429 | $counts['failed'] = 0; |
430 | 430 | } |
431 | 431 | |
432 | - if( ! isset( $counts['in-progress'] ) ) { |
|
432 | + if ( ! isset($counts['in-progress'])) { |
|
433 | 433 | $counts['in-progress'] = 0; |
434 | 434 | } |
435 | 435 | |
436 | - if( ! isset( $counts['complete'] ) ) { |
|
436 | + if ( ! isset($counts['complete'])) { |
|
437 | 437 | $counts['complete'] = 0; |
438 | 438 | } |
439 | 439 | |
440 | - return apply_filters( 'sensei_count_statuses', $counts, $type ); |
|
440 | + return apply_filters('sensei_count_statuses', $counts, $type); |
|
441 | 441 | } // End sensei_count_statuses() |
442 | 442 | |
443 | 443 | /** |
@@ -445,11 +445,11 @@ discard block |
||
445 | 445 | * @since 1.7.0 |
446 | 446 | * @return string |
447 | 447 | */ |
448 | - public function courses_drop_down_html( $selected_course_id = 0 ) { |
|
448 | + public function courses_drop_down_html($selected_course_id = 0) { |
|
449 | 449 | |
450 | 450 | $html = ''; |
451 | 451 | |
452 | - $course_args = array( 'post_type' => 'course', |
|
452 | + $course_args = array('post_type' => 'course', |
|
453 | 453 | 'posts_per_page' => -1, |
454 | 454 | 'orderby' => 'title', |
455 | 455 | 'order' => 'ASC', |
@@ -457,12 +457,12 @@ discard block |
||
457 | 457 | 'suppress_filters' => 0, |
458 | 458 | 'fields' => 'ids', |
459 | 459 | ); |
460 | - $courses = get_posts( apply_filters( 'sensei_grading_filter_courses', $course_args ) ); |
|
460 | + $courses = get_posts(apply_filters('sensei_grading_filter_courses', $course_args)); |
|
461 | 461 | |
462 | - $html .= '<option value="">' . __( 'Select a course', 'woothemes-sensei' ) . '</option>'; |
|
463 | - if ( count( $courses ) > 0 ) { |
|
464 | - foreach ($courses as $course_id){ |
|
465 | - $html .= '<option value="' . esc_attr( absint( $course_id ) ) . '" ' . selected( $course_id, $selected_course_id, false ) . '>' . esc_html( get_the_title( $course_id ) ) . '</option>' . "\n"; |
|
462 | + $html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'; |
|
463 | + if (count($courses) > 0) { |
|
464 | + foreach ($courses as $course_id) { |
|
465 | + $html .= '<option value="'.esc_attr(absint($course_id)).'" '.selected($course_id, $selected_course_id, false).'>'.esc_html(get_the_title($course_id)).'</option>'."\n"; |
|
466 | 466 | } // End For Loop |
467 | 467 | } // End If Statement |
468 | 468 | |
@@ -483,20 +483,20 @@ discard block |
||
483 | 483 | $course_data = array(); |
484 | 484 | parse_str($data, $course_data); |
485 | 485 | |
486 | - $course_id = intval( $course_data['course_id'] ); |
|
486 | + $course_id = intval($course_data['course_id']); |
|
487 | 487 | |
488 | - $html = $this->lessons_drop_down_html( $course_id ); |
|
488 | + $html = $this->lessons_drop_down_html($course_id); |
|
489 | 489 | |
490 | 490 | echo $html; |
491 | 491 | die(); // WordPress may print out a spurious zero without this can be particularly bad if using JSON |
492 | 492 | } |
493 | 493 | |
494 | - public function lessons_drop_down_html( $course_id = 0, $selected_lesson_id = 0 ) { |
|
494 | + public function lessons_drop_down_html($course_id = 0, $selected_lesson_id = 0) { |
|
495 | 495 | |
496 | 496 | $html = ''; |
497 | - if ( 0 < intval( $course_id ) ) { |
|
497 | + if (0 < intval($course_id)) { |
|
498 | 498 | |
499 | - $lesson_args = array( 'post_type' => 'lesson', |
|
499 | + $lesson_args = array('post_type' => 'lesson', |
|
500 | 500 | 'posts_per_page' => -1, |
501 | 501 | 'orderby' => 'title', |
502 | 502 | 'order' => 'ASC', |
@@ -506,12 +506,12 @@ discard block |
||
506 | 506 | 'suppress_filters' => 0, |
507 | 507 | 'fields' => 'ids', |
508 | 508 | ); |
509 | - $lessons = get_posts( apply_filters( 'sensei_grading_filter_lessons', $lesson_args ) ); |
|
509 | + $lessons = get_posts(apply_filters('sensei_grading_filter_lessons', $lesson_args)); |
|
510 | 510 | |
511 | - $html .= '<option value="">' . __( 'Select a lesson', 'woothemes-sensei' ) . '</option>'; |
|
512 | - if ( count( $lessons ) > 0 ) { |
|
513 | - foreach ( $lessons as $lesson_id ){ |
|
514 | - $html .= '<option value="' . esc_attr( absint( $lesson_id ) ) . '" ' . selected( $lesson_id, $selected_lesson_id, false ) . '>' . esc_html( get_the_title( $lesson_id ) ) . '</option>' . "\n"; |
|
511 | + $html .= '<option value="">'.__('Select a lesson', 'woothemes-sensei').'</option>'; |
|
512 | + if (count($lessons) > 0) { |
|
513 | + foreach ($lessons as $lesson_id) { |
|
514 | + $html .= '<option value="'.esc_attr(absint($lesson_id)).'" '.selected($lesson_id, $selected_lesson_id, false).'>'.esc_html(get_the_title($lesson_id)).'</option>'."\n"; |
|
515 | 515 | } // End For Loop |
516 | 516 | } // End If Statement |
517 | 517 | |
@@ -532,10 +532,10 @@ discard block |
||
532 | 532 | public function admin_process_grading_submission() { |
533 | 533 | |
534 | 534 | // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry |
535 | - if( ! isset( $_POST['sensei_manual_grade'] ) |
|
536 | - || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) |
|
537 | - || ! isset( $_GET['quiz_id'] ) |
|
538 | - || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { |
|
535 | + if ( ! isset($_POST['sensei_manual_grade']) |
|
536 | + || ! wp_verify_nonce($_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading') |
|
537 | + || ! isset($_GET['quiz_id']) |
|
538 | + || $_GET['quiz_id'] != $_POST['sensei_manual_grade']) { |
|
539 | 539 | |
540 | 540 | return false; //exit and do not grade |
541 | 541 | |
@@ -545,30 +545,30 @@ discard block |
||
545 | 545 | $user_id = $_GET['user']; |
546 | 546 | |
547 | 547 | |
548 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
549 | - $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
548 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
549 | + $quiz_lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
550 | 550 | $quiz_grade = 0; |
551 | 551 | $count = 0; |
552 | 552 | $quiz_grade_total = $_POST['quiz_grade_total']; |
553 | 553 | $all_question_grades = array(); |
554 | 554 | $all_answers_feedback = array(); |
555 | 555 | |
556 | - foreach( $questions as $question ) { |
|
556 | + foreach ($questions as $question) { |
|
557 | 557 | |
558 | 558 | ++$count; |
559 | 559 | $question_id = $question->ID; |
560 | 560 | |
561 | - if( isset( $_POST[ 'question_' . $question_id ] ) ) { |
|
561 | + if (isset($_POST['question_'.$question_id])) { |
|
562 | 562 | |
563 | 563 | $question_grade = 0; |
564 | - if( $_POST[ 'question_' . $question_id ] == 'right' ) { |
|
564 | + if ($_POST['question_'.$question_id] == 'right') { |
|
565 | 565 | |
566 | - $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; |
|
566 | + $question_grade = $_POST['question_'.$question_id.'_grade']; |
|
567 | 567 | |
568 | 568 | } |
569 | 569 | |
570 | 570 | // add data to the array that will, after the loop, be stored on the lesson status |
571 | - $all_question_grades[ $question_id ] = $question_grade; |
|
571 | + $all_question_grades[$question_id] = $question_grade; |
|
572 | 572 | |
573 | 573 | // tally up the total quiz grade |
574 | 574 | $quiz_grade += $question_grade; |
@@ -577,41 +577,41 @@ discard block |
||
577 | 577 | |
578 | 578 | // Question answer feedback / notes |
579 | 579 | $question_feedback = ''; |
580 | - if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ |
|
580 | + if (isset($_POST['questions_feedback'][$question_id])) { |
|
581 | 581 | |
582 | - $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); |
|
582 | + $question_feedback = wp_unslash($_POST['questions_feedback'][$question_id]); |
|
583 | 583 | |
584 | 584 | } |
585 | - $all_answers_feedback[ $question_id ] = $question_feedback; |
|
585 | + $all_answers_feedback[$question_id] = $question_feedback; |
|
586 | 586 | |
587 | 587 | } // end for each $questions |
588 | 588 | |
589 | 589 | //store all question grades on the lesson status |
590 | - Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); |
|
590 | + Sensei()->quiz->set_user_grades($all_question_grades, $quiz_lesson_id, $user_id); |
|
591 | 591 | |
592 | 592 | //store the feedback from grading |
593 | - Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); |
|
593 | + Sensei()->quiz->save_user_answers_feedback($all_answers_feedback, $quiz_lesson_id, $user_id); |
|
594 | 594 | |
595 | 595 | // $_POST['all_questions_graded'] is set when all questions have been graded |
596 | 596 | // in the class sensei grading user quiz -> display() |
597 | - if( $_POST['all_questions_graded'] == 'yes' ) { |
|
597 | + if ($_POST['all_questions_graded'] == 'yes') { |
|
598 | 598 | |
599 | 599 | // set the users total quiz grade |
600 | - if ( 0 < intval( $quiz_grade_total ) ) { |
|
601 | - $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); |
|
600 | + if (0 < intval($quiz_grade_total)) { |
|
601 | + $grade = abs(round((doubleval($quiz_grade) * 100) / ($quiz_grade_total), 2)); |
|
602 | 602 | } |
603 | 603 | else { |
604 | 604 | $grade = 0; |
605 | 605 | } |
606 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); |
|
606 | + Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id); |
|
607 | 607 | |
608 | 608 | // Duplicating what Frontend->sensei_complete_quiz() does |
609 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
610 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
609 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
610 | + $quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); |
|
611 | 611 | $lesson_metadata = array(); |
612 | - if ( $pass_required ) { |
|
612 | + if ($pass_required) { |
|
613 | 613 | // Student has reached the pass mark and lesson is complete |
614 | - if ( $quiz_passmark <= $grade ) { |
|
614 | + if ($quiz_passmark <= $grade) { |
|
615 | 615 | $lesson_status = 'passed'; |
616 | 616 | } |
617 | 617 | else { |
@@ -624,9 +624,9 @@ discard block |
||
624 | 624 | } |
625 | 625 | $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above |
626 | 626 | |
627 | - Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); |
|
627 | + Sensei_Utils::update_lesson_status($user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata); |
|
628 | 628 | |
629 | - if( in_array( $lesson_status, array( 'passed', 'graded' ) ) ) { |
|
629 | + if (in_array($lesson_status, array('passed', 'graded'))) { |
|
630 | 630 | |
631 | 631 | /** |
632 | 632 | * Summary. |
@@ -638,27 +638,27 @@ discard block |
||
638 | 638 | * @param int $user_id |
639 | 639 | * @param int $quiz_lesson_id |
640 | 640 | */ |
641 | - do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); |
|
641 | + do_action('sensei_user_lesson_end', $user_id, $quiz_lesson_id); |
|
642 | 642 | |
643 | 643 | } // end if in_array |
644 | 644 | |
645 | 645 | }// end if $_POST['all_que... |
646 | 646 | |
647 | - if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { |
|
647 | + if (isset($_POST['sensei_grade_next_learner']) && strlen($_POST['sensei_grade_next_learner']) > 0) { |
|
648 | 648 | |
649 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
649 | + $load_url = add_query_arg(array('message' => 'graded')); |
|
650 | 650 | |
651 | - } elseif ( isset( $_POST['_wp_http_referer'] ) ) { |
|
651 | + } elseif (isset($_POST['_wp_http_referer'])) { |
|
652 | 652 | |
653 | - $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); |
|
653 | + $load_url = add_query_arg(array('message' => 'graded'), $_POST['_wp_http_referer']); |
|
654 | 654 | |
655 | 655 | } else { |
656 | 656 | |
657 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
657 | + $load_url = add_query_arg(array('message' => 'graded')); |
|
658 | 658 | |
659 | 659 | } |
660 | 660 | |
661 | - wp_safe_redirect( esc_url_raw( $load_url ) ); |
|
661 | + wp_safe_redirect(esc_url_raw($load_url)); |
|
662 | 662 | exit; |
663 | 663 | |
664 | 664 | } // end admin_process_grading_submission |
@@ -669,13 +669,13 @@ discard block |
||
669 | 669 | $lesson_data = array(); |
670 | 670 | parse_str($data, $lesson_data); |
671 | 671 | |
672 | - $lesson_id = intval( $lesson_data['lesson_id'] ); |
|
673 | - $course_id = intval( $lesson_data['course_id'] ); |
|
674 | - $grading_view = sanitize_text_field( $lesson_data['view'] ); |
|
672 | + $lesson_id = intval($lesson_data['lesson_id']); |
|
673 | + $course_id = intval($lesson_data['course_id']); |
|
674 | + $grading_view = sanitize_text_field($lesson_data['view']); |
|
675 | 675 | |
676 | 676 | $redirect_url = ''; |
677 | - if ( 0 < $lesson_id && 0 < $course_id ) { |
|
678 | - $redirect_url = esc_url_raw( apply_filters( 'sensei_ajax_redirect_url', add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id, 'course_id' => $course_id, 'view' => $grading_view ), admin_url( 'admin.php' ) ) ) ); |
|
677 | + if (0 < $lesson_id && 0 < $course_id) { |
|
678 | + $redirect_url = esc_url_raw(apply_filters('sensei_ajax_redirect_url', add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id, 'course_id' => $course_id, 'view' => $grading_view), admin_url('admin.php')))); |
|
679 | 679 | } // End If Statement |
680 | 680 | |
681 | 681 | echo $redirect_url; |
@@ -683,11 +683,11 @@ discard block |
||
683 | 683 | } |
684 | 684 | |
685 | 685 | public function add_grading_notices() { |
686 | - if( isset( $_GET['page'] ) && $this->page_slug == $_GET['page'] && isset( $_GET['message'] ) && $_GET['message'] ) { |
|
687 | - if( 'graded' == $_GET['message'] ) { |
|
686 | + if (isset($_GET['page']) && $this->page_slug == $_GET['page'] && isset($_GET['message']) && $_GET['message']) { |
|
687 | + if ('graded' == $_GET['message']) { |
|
688 | 688 | $msg = array( |
689 | 689 | 'updated', |
690 | - __( 'Quiz Graded Successfully!', 'woothemes-sensei' ), |
|
690 | + __('Quiz Graded Successfully!', 'woothemes-sensei'), |
|
691 | 691 | ); |
692 | 692 | } |
693 | 693 | ?> |
@@ -699,9 +699,9 @@ discard block |
||
699 | 699 | } |
700 | 700 | |
701 | 701 | public function sensei_grading_notices() { |
702 | - if ( isset( $_GET['action'] ) && 'graded' == $_GET['action'] ) { |
|
702 | + if (isset($_GET['action']) && 'graded' == $_GET['action']) { |
|
703 | 703 | echo '<div class="grading-notice updated">'; |
704 | - echo '<p>' . __( 'Quiz Graded Successfully!', 'woothemes-sensei' ) . '</p>'; |
|
704 | + echo '<p>'.__('Quiz Graded Successfully!', 'woothemes-sensei').'</p>'; |
|
705 | 705 | echo '</div>'; |
706 | 706 | } // End If Statement |
707 | 707 | } // End sensei_grading_notices() |
@@ -724,16 +724,16 @@ discard block |
||
724 | 724 | * |
725 | 725 | * @return int $quiz_grade total sum of all question grades |
726 | 726 | */ |
727 | - public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
727 | + public static function grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') { |
|
728 | 728 | |
729 | - if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted |
|
730 | - || $quiz_grade_type != 'auto' ) { |
|
729 | + if ( ! (intval($quiz_id) > 0) || ! $submitted |
|
730 | + || $quiz_grade_type != 'auto') { |
|
731 | 731 | return false; // exit early |
732 | 732 | } |
733 | 733 | |
734 | 734 | |
735 | 735 | $user_id = get_current_user_id(); |
736 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; |
|
736 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
737 | 737 | $quiz_autogradable = true; |
738 | 738 | |
739 | 739 | /** |
@@ -747,23 +747,23 @@ discard block |
||
747 | 747 | * 'gap-fill'. |
748 | 748 | * } |
749 | 749 | */ |
750 | - $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); |
|
750 | + $autogradable_question_types = apply_filters('sensei_autogradable_question_types', array('multiple-choice', 'boolean', 'gap-fill')); |
|
751 | 751 | |
752 | 752 | $grade_total = 0; |
753 | 753 | $all_question_grades = array(); |
754 | - foreach( $submitted as $question_id => $answer ) { |
|
754 | + foreach ($submitted as $question_id => $answer) { |
|
755 | 755 | |
756 | 756 | // check if the question is autogradable, either by type, or because the grade is 0 |
757 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
758 | - $achievable_grade = Sensei()->question->get_question_grade( $question_id ); |
|
757 | + $question_type = Sensei()->question->get_question_type($question_id); |
|
758 | + $achievable_grade = Sensei()->question->get_question_grade($question_id); |
|
759 | 759 | // Question has a zero grade, so skip grading |
760 | - if ( 0 == $achievable_grade ) { |
|
761 | - $all_question_grades[ $question_id ] = $achievable_grade; |
|
760 | + if (0 == $achievable_grade) { |
|
761 | + $all_question_grades[$question_id] = $achievable_grade; |
|
762 | 762 | } |
763 | - elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
763 | + elseif (in_array($question_type, $autogradable_question_types)) { |
|
764 | 764 | // Get user question grade |
765 | - $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
766 | - $all_question_grades[ $question_id ] = $question_grade; |
|
765 | + $question_grade = Sensei_Utils::sensei_grade_question_auto($question_id, $question_type, $answer, $user_id); |
|
766 | + $all_question_grades[$question_id] = $question_grade; |
|
767 | 767 | $grade_total += $question_grade; |
768 | 768 | |
769 | 769 | } else { |
@@ -776,27 +776,27 @@ discard block |
||
776 | 776 | }// end for each question |
777 | 777 | |
778 | 778 | // Only if the whole quiz was autogradable do we set a grade |
779 | - if ( $quiz_autogradable ) { |
|
779 | + if ($quiz_autogradable) { |
|
780 | 780 | |
781 | - $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); |
|
781 | + $quiz_total = Sensei_Utils::sensei_get_quiz_total($quiz_id); |
|
782 | 782 | // Check for zero total from grades |
783 | - if ( 0 < $quiz_total ) { |
|
784 | - $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); |
|
783 | + if (0 < $quiz_total) { |
|
784 | + $grade = abs(round((doubleval($grade_total) * 100) / ($quiz_total), 2)); |
|
785 | 785 | } |
786 | 786 | else { |
787 | 787 | $grade = 0; |
788 | 788 | } |
789 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); |
|
789 | + Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id, $quiz_grade_type); |
|
790 | 790 | |
791 | 791 | } else { |
792 | 792 | |
793 | - $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); |
|
793 | + $grade = new WP_Error('autograde', __('This quiz is not able to be automatically graded.', 'woothemes-sensei')); |
|
794 | 794 | |
795 | 795 | } |
796 | 796 | |
797 | 797 | // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default |
798 | 798 | // when doing manual grading. |
799 | - Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); |
|
799 | + Sensei()->quiz-> set_user_grades($all_question_grades, $lesson_id, $user_id); |
|
800 | 800 | |
801 | 801 | return $grade; |
802 | 802 | |
@@ -816,22 +816,22 @@ discard block |
||
816 | 816 | * |
817 | 817 | * @return int $question_grade |
818 | 818 | */ |
819 | - public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
819 | + public static function grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) { |
|
820 | 820 | |
821 | - if( intval( $user_id ) == 0 ) { |
|
821 | + if (intval($user_id) == 0) { |
|
822 | 822 | |
823 | 823 | $user_id = get_current_user_id(); |
824 | 824 | |
825 | 825 | } |
826 | 826 | |
827 | - if( ! ( intval( $question_id ) > 0 ) ) { |
|
827 | + if ( ! (intval($question_id) > 0)) { |
|
828 | 828 | |
829 | 829 | return false; |
830 | 830 | |
831 | 831 | } |
832 | 832 | |
833 | 833 | |
834 | - Sensei()->question->get_question_type( $question_id ); |
|
834 | + Sensei()->question->get_question_type($question_id); |
|
835 | 835 | |
836 | 836 | /** |
837 | 837 | * Applying a grade before the auto grading takes place. |
@@ -845,42 +845,42 @@ discard block |
||
845 | 845 | * @param string $question_type one of the Sensei question type. |
846 | 846 | * @param string $answer user supplied question answer |
847 | 847 | */ |
848 | - $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); |
|
848 | + $question_grade = apply_filters('sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer); |
|
849 | 849 | |
850 | - if ( false !== $question_grade ) { |
|
850 | + if (false !== $question_grade) { |
|
851 | 851 | |
852 | 852 | return $question_grade; |
853 | 853 | |
854 | 854 | } |
855 | 855 | |
856 | 856 | // auto grading core |
857 | - if( in_array( $question_type , array( 'multiple-choice' , 'boolean' ) ) ){ |
|
857 | + if (in_array($question_type, array('multiple-choice', 'boolean'))) { |
|
858 | 858 | |
859 | - $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); |
|
859 | + $right_answer = (array) get_post_meta($question_id, '_question_right_answer', true); |
|
860 | 860 | |
861 | - if( 0 == get_magic_quotes_gpc() ) { |
|
862 | - $answer = wp_unslash( $answer ); |
|
861 | + if (0 == get_magic_quotes_gpc()) { |
|
862 | + $answer = wp_unslash($answer); |
|
863 | 863 | } |
864 | 864 | $answer = (array) $answer; |
865 | - if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { |
|
865 | + if (is_array($right_answer) && count($right_answer) == count($answer)) { |
|
866 | 866 | // Loop through all answers ensure none are 'missing' |
867 | 867 | $all_correct = true; |
868 | - foreach ( $answer as $check_answer ) { |
|
869 | - if ( !in_array( $check_answer, $right_answer ) ) { |
|
868 | + foreach ($answer as $check_answer) { |
|
869 | + if ( ! in_array($check_answer, $right_answer)) { |
|
870 | 870 | $all_correct = false; |
871 | 871 | } |
872 | 872 | } |
873 | 873 | // If all correct then grade |
874 | - if ( $all_correct ) { |
|
875 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
874 | + if ($all_correct) { |
|
875 | + $question_grade = Sensei()->question->get_question_grade($question_id); |
|
876 | 876 | } |
877 | 877 | } |
878 | 878 | |
879 | - } elseif( 'gap-fill' == $question_type ){ |
|
879 | + } elseif ('gap-fill' == $question_type) { |
|
880 | 880 | |
881 | - $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); |
|
881 | + $question_grade = self::grade_gap_fill_question($question_id, $answer); |
|
882 | 882 | |
883 | - } else{ |
|
883 | + } else { |
|
884 | 884 | |
885 | 885 | /** |
886 | 886 | * Grading questions that are not auto gradable. |
@@ -893,7 +893,7 @@ discard block |
||
893 | 893 | * @param string $question_type one of the Sensei question type. |
894 | 894 | * @param string $answer user supplied question answer |
895 | 895 | */ |
896 | - $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); |
|
896 | + $question_grade = (int) apply_filters('sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer); |
|
897 | 897 | |
898 | 898 | } // end if $question_type |
899 | 899 | |
@@ -909,13 +909,13 @@ discard block |
||
909 | 909 | * |
910 | 910 | * @return bool | int false or the grade given to the user answer |
911 | 911 | */ |
912 | - public static function grade_gap_fill_question( $question_id, $user_answer ){ |
|
912 | + public static function grade_gap_fill_question($question_id, $user_answer) { |
|
913 | 913 | |
914 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
915 | - $gapfill_array = explode( '||', $right_answer ); |
|
914 | + $right_answer = get_post_meta($question_id, '_question_right_answer', true); |
|
915 | + $gapfill_array = explode('||', $right_answer); |
|
916 | 916 | |
917 | - if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
918 | - $user_answer = wp_unslash( $user_answer ); |
|
917 | + if (0 == get_magic_quotes_gpc()) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
918 | + $user_answer = wp_unslash($user_answer); |
|
919 | 919 | } |
920 | 920 | |
921 | 921 | /** |
@@ -928,53 +928,53 @@ discard block |
||
928 | 928 | * |
929 | 929 | * @since 1.9.0 |
930 | 930 | */ |
931 | - $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); |
|
931 | + $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false); |
|
932 | 932 | |
933 | - if( $do_case_sensitive_comparison ){ |
|
933 | + if ($do_case_sensitive_comparison) { |
|
934 | 934 | |
935 | 935 | // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
936 | - if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { |
|
936 | + if (trim(($gapfill_array[1])) == trim($user_answer)) { |
|
937 | 937 | |
938 | - return Sensei()->question->get_question_grade( $question_id ); |
|
938 | + return Sensei()->question->get_question_grade($question_id); |
|
939 | 939 | |
940 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
940 | + } else if (@preg_match('/'.$gapfill_array[1].'/i', null) !== FALSE) { |
|
941 | 941 | |
942 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
942 | + if (preg_match('/'.$gapfill_array[1].'/i', $user_answer)) { |
|
943 | 943 | |
944 | 944 | return Sensei()->question->get_question_grade($question_id); |
945 | 945 | |
946 | - }else{ |
|
946 | + } else { |
|
947 | 947 | |
948 | 948 | return false; |
949 | 949 | |
950 | 950 | } |
951 | 951 | |
952 | - }else{ |
|
952 | + } else { |
|
953 | 953 | |
954 | 954 | return false; |
955 | 955 | |
956 | 956 | } |
957 | 957 | |
958 | - }else{ |
|
958 | + } else { |
|
959 | 959 | |
960 | 960 | // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
961 | - if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { |
|
961 | + if (trim(strtolower($gapfill_array[1])) == trim(strtolower($user_answer))) { |
|
962 | 962 | |
963 | - return Sensei()->question->get_question_grade( $question_id ); |
|
963 | + return Sensei()->question->get_question_grade($question_id); |
|
964 | 964 | |
965 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
965 | + } else if (@preg_match('/'.$gapfill_array[1].'/i', null) !== FALSE) { |
|
966 | 966 | |
967 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
967 | + if (preg_match('/'.$gapfill_array[1].'/i', $user_answer)) { |
|
968 | 968 | |
969 | - return Sensei()->question->get_question_grade( $question_id ); |
|
969 | + return Sensei()->question->get_question_grade($question_id); |
|
970 | 970 | |
971 | - }else{ |
|
971 | + } else { |
|
972 | 972 | |
973 | 973 | return false; |
974 | 974 | |
975 | 975 | } |
976 | 976 | |
977 | - }else{ |
|
977 | + } else { |
|
978 | 978 | |
979 | 979 | return false; |
980 | 980 | |
@@ -991,4 +991,4 @@ discard block |
||
991 | 991 | * @ignore only for backward compatibility |
992 | 992 | * @since 1.9.0 |
993 | 993 | */ |
994 | -class WooThemes_Sensei_Grading extends Sensei_Grading{} |
|
994 | +class WooThemes_Sensei_Grading extends Sensei_Grading {} |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Analysis Overview Data Table. |
@@ -18,17 +18,17 @@ discard block |
||
18 | 18 | * @since 1.2.0 |
19 | 19 | * @return void |
20 | 20 | */ |
21 | - public function __construct ( $type = 'users' ) { |
|
22 | - $this->type = in_array( $type, array( 'courses', 'lessons', 'users' ) ) ? $type : 'users'; |
|
21 | + public function __construct($type = 'users') { |
|
22 | + $this->type = in_array($type, array('courses', 'lessons', 'users')) ? $type : 'users'; |
|
23 | 23 | |
24 | 24 | // Load Parent token into constructor |
25 | - parent::__construct( 'analysis_overview' ); |
|
25 | + parent::__construct('analysis_overview'); |
|
26 | 26 | |
27 | 27 | // Actions |
28 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
29 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
28 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
29 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
30 | 30 | |
31 | - add_filter( 'sensei_list_table_search_button_text', array( $this, 'search_button' ) ); |
|
31 | + add_filter('sensei_list_table_search_button_text', array($this, 'search_button')); |
|
32 | 32 | } // End __construct() |
33 | 33 | |
34 | 34 | /** |
@@ -38,41 +38,41 @@ discard block |
||
38 | 38 | */ |
39 | 39 | function get_columns() { |
40 | 40 | |
41 | - switch( $this->type ) { |
|
41 | + switch ($this->type) { |
|
42 | 42 | case 'courses': |
43 | 43 | $columns = array( |
44 | - 'title' => __( 'Course', 'woothemes-sensei' ), |
|
45 | - 'students' => __( 'Learners', 'woothemes-sensei' ), |
|
46 | - 'lessons' => __( 'Lessons', 'woothemes-sensei' ), |
|
47 | - 'completions' => __( 'Completed', 'woothemes-sensei' ), |
|
48 | - 'average_percent' => __( 'Average Percentage', 'woothemes-sensei' ), |
|
44 | + 'title' => __('Course', 'woothemes-sensei'), |
|
45 | + 'students' => __('Learners', 'woothemes-sensei'), |
|
46 | + 'lessons' => __('Lessons', 'woothemes-sensei'), |
|
47 | + 'completions' => __('Completed', 'woothemes-sensei'), |
|
48 | + 'average_percent' => __('Average Percentage', 'woothemes-sensei'), |
|
49 | 49 | ); |
50 | 50 | break; |
51 | 51 | |
52 | 52 | case 'lessons': |
53 | 53 | $columns = array( |
54 | - 'title' => __( 'Lesson', 'woothemes-sensei' ), |
|
55 | - 'course' => __( 'Course', 'woothemes-sensei' ), |
|
56 | - 'students' => __( 'Learners', 'woothemes-sensei' ), |
|
57 | - 'completions' => __( 'Completed', 'woothemes-sensei' ), |
|
58 | - 'average_grade' => __( 'Average Grade', 'woothemes-sensei' ), |
|
54 | + 'title' => __('Lesson', 'woothemes-sensei'), |
|
55 | + 'course' => __('Course', 'woothemes-sensei'), |
|
56 | + 'students' => __('Learners', 'woothemes-sensei'), |
|
57 | + 'completions' => __('Completed', 'woothemes-sensei'), |
|
58 | + 'average_grade' => __('Average Grade', 'woothemes-sensei'), |
|
59 | 59 | ); |
60 | 60 | break; |
61 | 61 | |
62 | 62 | case 'users': |
63 | 63 | default: |
64 | 64 | $columns = array( |
65 | - 'title' => __( 'Learner', 'woothemes-sensei' ), |
|
66 | - 'registered' => __( 'Date Registered', 'woothemes-sensei' ), |
|
67 | - 'active_courses' => __( 'Active Courses', 'woothemes-sensei' ), |
|
68 | - 'completed_courses' => __( 'Completed Courses', 'woothemes-sensei' ), |
|
69 | - 'average_grade' => __( 'Average Grade', 'woothemes-sensei' ), |
|
65 | + 'title' => __('Learner', 'woothemes-sensei'), |
|
66 | + 'registered' => __('Date Registered', 'woothemes-sensei'), |
|
67 | + 'active_courses' => __('Active Courses', 'woothemes-sensei'), |
|
68 | + 'completed_courses' => __('Completed Courses', 'woothemes-sensei'), |
|
69 | + 'average_grade' => __('Average Grade', 'woothemes-sensei'), |
|
70 | 70 | ); |
71 | 71 | break; |
72 | 72 | } |
73 | 73 | // Backwards compatible filter name, moving forward should have single filter name |
74 | - $columns = apply_filters( 'sensei_analysis_overview_' . $this->type . '_columns', $columns, $this ); |
|
75 | - $columns = apply_filters( 'sensei_analysis_overview_columns', $columns, $this ); |
|
74 | + $columns = apply_filters('sensei_analysis_overview_'.$this->type.'_columns', $columns, $this); |
|
75 | + $columns = apply_filters('sensei_analysis_overview_columns', $columns, $this); |
|
76 | 76 | return $columns; |
77 | 77 | } |
78 | 78 | |
@@ -83,41 +83,41 @@ discard block |
||
83 | 83 | */ |
84 | 84 | function get_sortable_columns() { |
85 | 85 | |
86 | - switch( $this->type ) { |
|
86 | + switch ($this->type) { |
|
87 | 87 | case 'courses': |
88 | 88 | $columns = array( |
89 | - 'title' => array( 'title', false ), |
|
90 | - 'students' => array( 'students', false ), |
|
91 | - 'lessons' => array( 'lessons', false ), |
|
92 | - 'completions' => array( 'completions', false ), |
|
93 | - 'average_percent' => array( 'average_percent', false ), |
|
89 | + 'title' => array('title', false), |
|
90 | + 'students' => array('students', false), |
|
91 | + 'lessons' => array('lessons', false), |
|
92 | + 'completions' => array('completions', false), |
|
93 | + 'average_percent' => array('average_percent', false), |
|
94 | 94 | ); |
95 | 95 | break; |
96 | 96 | |
97 | 97 | case 'lessons': |
98 | 98 | $columns = array( |
99 | - 'title' => array( 'title', false ), |
|
100 | - 'course' => array( 'course', false ), |
|
101 | - 'students' => array( 'students', false ), |
|
102 | - 'completions' => array( 'completions', false ), |
|
103 | - 'average_grade' => array( 'average_grade', false ), |
|
99 | + 'title' => array('title', false), |
|
100 | + 'course' => array('course', false), |
|
101 | + 'students' => array('students', false), |
|
102 | + 'completions' => array('completions', false), |
|
103 | + 'average_grade' => array('average_grade', false), |
|
104 | 104 | ); |
105 | 105 | break; |
106 | 106 | |
107 | 107 | case 'users': |
108 | 108 | default: |
109 | 109 | $columns = array( |
110 | - 'title' => array( 'user_login', false ), |
|
111 | - 'registered' => array( 'registered', false ), |
|
112 | - 'active_courses' => array( 'active_courses', false ), |
|
113 | - 'completed_courses' => array( 'completed_courses', false ), |
|
114 | - 'average_grade' => array( 'average_grade', false ) |
|
110 | + 'title' => array('user_login', false), |
|
111 | + 'registered' => array('registered', false), |
|
112 | + 'active_courses' => array('active_courses', false), |
|
113 | + 'completed_courses' => array('completed_courses', false), |
|
114 | + 'average_grade' => array('average_grade', false) |
|
115 | 115 | ); |
116 | 116 | break; |
117 | 117 | } |
118 | 118 | // Backwards compatible filter name, moving forward should have single filter name |
119 | - $columns = apply_filters( 'sensei_analysis_overview_' . $this->type . '_columns_sortable', $columns, $this ); |
|
120 | - $columns = apply_filters( 'sensei_analysis_overview_columns_sortable', $columns, $this ); |
|
119 | + $columns = apply_filters('sensei_analysis_overview_'.$this->type.'_columns_sortable', $columns, $this); |
|
120 | + $columns = apply_filters('sensei_analysis_overview_columns_sortable', $columns, $this); |
|
121 | 121 | return $columns; |
122 | 122 | } |
123 | 123 | |
@@ -131,25 +131,25 @@ discard block |
||
131 | 131 | |
132 | 132 | // Handle orderby |
133 | 133 | $orderby = ''; |
134 | - if ( !empty( $_GET['orderby'] ) ) { |
|
135 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
136 | - $orderby = esc_html( $_GET['orderby'] ); |
|
134 | + if ( ! empty($_GET['orderby'])) { |
|
135 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
136 | + $orderby = esc_html($_GET['orderby']); |
|
137 | 137 | } // End If Statement |
138 | 138 | } |
139 | 139 | |
140 | 140 | // Handle order |
141 | 141 | $order = 'ASC'; |
142 | - if ( !empty( $_GET['order'] ) ) { |
|
143 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
142 | + if ( ! empty($_GET['order'])) { |
|
143 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
144 | 144 | } |
145 | 145 | |
146 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
147 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
146 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
147 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
148 | 148 | |
149 | 149 | $paged = $this->get_pagenum(); |
150 | 150 | $offset = 0; |
151 | - if ( !empty($paged) ) { |
|
152 | - $offset = $per_page * ( $paged - 1 ); |
|
151 | + if ( ! empty($paged)) { |
|
152 | + $offset = $per_page * ($paged - 1); |
|
153 | 153 | } // End If Statement |
154 | 154 | |
155 | 155 | $args = array( |
@@ -160,32 +160,32 @@ discard block |
||
160 | 160 | ); |
161 | 161 | |
162 | 162 | // Handle search |
163 | - if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
164 | - $args['search'] = esc_html( $_GET['s'] ); |
|
163 | + if (isset($_GET['s']) && ! empty($_GET['s'])) { |
|
164 | + $args['search'] = esc_html($_GET['s']); |
|
165 | 165 | } |
166 | 166 | |
167 | - switch ( $this->type ) { |
|
167 | + switch ($this->type) { |
|
168 | 168 | case 'courses': |
169 | - $this->items = $this->get_courses( $args ); |
|
169 | + $this->items = $this->get_courses($args); |
|
170 | 170 | break; |
171 | 171 | |
172 | 172 | case 'lessons': |
173 | - $this->items = $this->get_lessons( $args ); |
|
173 | + $this->items = $this->get_lessons($args); |
|
174 | 174 | break; |
175 | 175 | |
176 | 176 | case 'users': |
177 | 177 | default : |
178 | - $this->items = $this->get_learners( $args ); |
|
178 | + $this->items = $this->get_learners($args); |
|
179 | 179 | break; |
180 | 180 | } |
181 | 181 | |
182 | 182 | $total_items = $this->total_items; |
183 | - $total_pages = ceil( $total_items / $per_page ); |
|
184 | - $this->set_pagination_args( array( |
|
183 | + $total_pages = ceil($total_items / $per_page); |
|
184 | + $this->set_pagination_args(array( |
|
185 | 185 | 'total_items' => $total_items, |
186 | 186 | 'total_pages' => $total_pages, |
187 | 187 | 'per_page' => $per_page |
188 | - ) ); |
|
188 | + )); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @since 1.7.0 |
194 | 194 | * @return data |
195 | 195 | */ |
196 | - public function generate_report( $report ) { |
|
196 | + public function generate_report($report) { |
|
197 | 197 | |
198 | 198 | $data = array(); |
199 | 199 | |
@@ -201,16 +201,16 @@ discard block |
||
201 | 201 | |
202 | 202 | // Handle orderby |
203 | 203 | $orderby = ''; |
204 | - if ( !empty( $_GET['orderby'] ) ) { |
|
205 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
206 | - $orderby = esc_html( $_GET['orderby'] ); |
|
204 | + if ( ! empty($_GET['orderby'])) { |
|
205 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
206 | + $orderby = esc_html($_GET['orderby']); |
|
207 | 207 | } // End If Statement |
208 | 208 | } |
209 | 209 | |
210 | 210 | // Handle order |
211 | 211 | $order = 'ASC'; |
212 | - if ( !empty( $_GET['order'] ) ) { |
|
213 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
212 | + if ( ! empty($_GET['order'])) { |
|
213 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | $args = array( |
@@ -220,37 +220,37 @@ discard block |
||
220 | 220 | |
221 | 221 | |
222 | 222 | // Handle search |
223 | - if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
224 | - $args['search'] = esc_html( $_GET['s'] ); |
|
223 | + if (isset($_GET['s']) && ! empty($_GET['s'])) { |
|
224 | + $args['search'] = esc_html($_GET['s']); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | |
228 | 228 | // Start the csv with the column headings |
229 | 229 | $column_headers = array(); |
230 | 230 | $columns = $this->get_columns(); |
231 | - foreach( $columns AS $key => $title ) { |
|
231 | + foreach ($columns AS $key => $title) { |
|
232 | 232 | $column_headers[] = $title; |
233 | 233 | } |
234 | 234 | $data[] = $column_headers; |
235 | 235 | |
236 | - switch ( $this->type ) { |
|
236 | + switch ($this->type) { |
|
237 | 237 | case 'courses': |
238 | - $this->items = $this->get_courses( $args ); |
|
238 | + $this->items = $this->get_courses($args); |
|
239 | 239 | break; |
240 | 240 | |
241 | 241 | case 'lessons': |
242 | - $this->items = $this->get_lessons( $args ); |
|
242 | + $this->items = $this->get_lessons($args); |
|
243 | 243 | break; |
244 | 244 | |
245 | 245 | case 'users': |
246 | 246 | default : |
247 | - $this->items = $this->get_learners( $args ); |
|
247 | + $this->items = $this->get_learners($args); |
|
248 | 248 | break; |
249 | 249 | } |
250 | 250 | |
251 | 251 | // Process each row |
252 | - foreach( $this->items AS $item) { |
|
253 | - $data[] = $this->get_row_data( $item ); |
|
252 | + foreach ($this->items AS $item) { |
|
253 | + $data[] = $this->get_row_data($item); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | return $data; |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | * @param object $item The current item |
263 | 263 | * @return array $column_data; |
264 | 264 | */ |
265 | - protected function get_row_data( $item ) { |
|
265 | + protected function get_row_data($item) { |
|
266 | 266 | |
267 | - switch( $this->type ) { |
|
267 | + switch ($this->type) { |
|
268 | 268 | case 'courses' : |
269 | 269 | // Get Learners (i.e. those who have started) |
270 | 270 | $course_args = array( |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | 'type' => 'sensei_course_status', |
273 | 273 | 'status' => 'any', |
274 | 274 | ); |
275 | - $course_students = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_learners', $course_args, $item ) ); |
|
275 | + $course_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_learners', $course_args, $item)); |
|
276 | 276 | |
277 | 277 | // Get Course Completions |
278 | 278 | $course_args = array( |
@@ -280,10 +280,10 @@ discard block |
||
280 | 280 | 'type' => 'sensei_course_status', |
281 | 281 | 'status' => 'complete', |
282 | 282 | ); |
283 | - $course_completions = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_completions', $course_args, $item ) ); |
|
283 | + $course_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_completions', $course_args, $item)); |
|
284 | 284 | |
285 | 285 | // Course Lessons |
286 | - $course_lessons = Sensei()->lesson->lesson_count( array('publish', 'private'), $item->ID ); |
|
286 | + $course_lessons = Sensei()->lesson->lesson_count(array('publish', 'private'), $item->ID); |
|
287 | 287 | |
288 | 288 | // Get Percent Complete |
289 | 289 | $grade_args = array( |
@@ -292,30 +292,30 @@ discard block |
||
292 | 292 | 'status' => 'any', |
293 | 293 | 'meta_key' => 'percent', |
294 | 294 | ); |
295 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
296 | - $course_percentage = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_percentage', $grade_args, $item ), true ); |
|
297 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
295 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
296 | + $course_percentage = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_percentage', $grade_args, $item), true); |
|
297 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
298 | 298 | |
299 | - $percent_count = !empty( $course_percentage->total ) ? $course_percentage->total : 1; |
|
300 | - $percent_total = !empty( $course_percentage->meta_sum ) ? doubleval( $course_percentage->meta_sum ) : 0; |
|
301 | - $course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) ); |
|
299 | + $percent_count = ! empty($course_percentage->total) ? $course_percentage->total : 1; |
|
300 | + $percent_total = ! empty($course_percentage->meta_sum) ? doubleval($course_percentage->meta_sum) : 0; |
|
301 | + $course_average_percent = abs(round(doubleval($percent_total / $percent_count), 2)); |
|
302 | 302 | |
303 | 303 | // Output course data |
304 | - if ( $this->csv_output ) { |
|
305 | - $course_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
|
304 | + if ($this->csv_output) { |
|
305 | + $course_title = apply_filters('the_title', $item->post_title, $item->ID); |
|
306 | 306 | } |
307 | 307 | else { |
308 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
308 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $item->ID), admin_url('admin.php')); |
|
309 | 309 | |
310 | - $course_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
|
310 | + $course_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>'; |
|
311 | 311 | $course_average_percent .= '%'; |
312 | 312 | } // End If Statement |
313 | - $column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $course_title, |
|
313 | + $column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $course_title, |
|
314 | 314 | 'students' => $course_students, |
315 | 315 | 'lessons' => $course_lessons, |
316 | 316 | 'completions' => $course_completions, |
317 | 317 | 'average_percent' => $course_average_percent, |
318 | - ), $item, $this ); |
|
318 | + ), $item, $this); |
|
319 | 319 | break; |
320 | 320 | |
321 | 321 | case 'lessons' : |
@@ -325,63 +325,63 @@ discard block |
||
325 | 325 | 'type' => 'sensei_lesson_status', |
326 | 326 | 'status' => 'any', |
327 | 327 | ); |
328 | - $lesson_students = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_learners', $lesson_args, $item ) ); |
|
328 | + $lesson_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_learners', $lesson_args, $item)); |
|
329 | 329 | |
330 | 330 | // Get Course Completions |
331 | 331 | $lesson_args = array( |
332 | 332 | 'post_id' => $item->ID, |
333 | 333 | 'type' => 'sensei_lesson_status', |
334 | - 'status' => array( 'complete', 'graded', 'passed', 'failed' ), |
|
334 | + 'status' => array('complete', 'graded', 'passed', 'failed'), |
|
335 | 335 | 'count' => true, |
336 | 336 | ); |
337 | - $lesson_completions = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_completions', $lesson_args, $item ) ); |
|
337 | + $lesson_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_completions', $lesson_args, $item)); |
|
338 | 338 | |
339 | 339 | // Course |
340 | - $course_id = get_post_meta( $item->ID, '_lesson_course', true ); |
|
341 | - $course_title = $course_id ? get_the_title( $course_id ) : ''; |
|
340 | + $course_id = get_post_meta($item->ID, '_lesson_course', true); |
|
341 | + $course_title = $course_id ? get_the_title($course_id) : ''; |
|
342 | 342 | |
343 | 343 | $lesson_average_grade = __('n/a', 'woothemes-sensei'); |
344 | - if ( false != get_post_meta($item->ID, '_quiz_has_questions', true) ) { |
|
344 | + if (false != get_post_meta($item->ID, '_quiz_has_questions', true)) { |
|
345 | 345 | // Get Percent Complete |
346 | 346 | $grade_args = array( |
347 | 347 | 'post_id' => $item->ID, |
348 | 348 | 'type' => 'sensei_lesson_status', |
349 | - 'status' => array( 'graded', 'passed', 'failed' ), |
|
349 | + 'status' => array('graded', 'passed', 'failed'), |
|
350 | 350 | 'meta_key' => 'grade', |
351 | 351 | ); |
352 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
353 | - $lesson_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_grades', $grade_args, $item ), true ); |
|
354 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
352 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
353 | + $lesson_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_grades', $grade_args, $item), true); |
|
354 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
355 | 355 | |
356 | - $grade_count = !empty( $lesson_grades->total ) ? $lesson_grades->total : 1; |
|
357 | - $grade_total = !empty( $lesson_grades->meta_sum ) ? doubleval( $lesson_grades->meta_sum ) : 0; |
|
358 | - $lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) ); |
|
356 | + $grade_count = ! empty($lesson_grades->total) ? $lesson_grades->total : 1; |
|
357 | + $grade_total = ! empty($lesson_grades->meta_sum) ? doubleval($lesson_grades->meta_sum) : 0; |
|
358 | + $lesson_average_grade = abs(round(doubleval($grade_total / $grade_count), 2)); |
|
359 | 359 | } |
360 | 360 | // Output lesson data |
361 | - if ( $this->csv_output ) { |
|
362 | - $lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
|
361 | + if ($this->csv_output) { |
|
362 | + $lesson_title = apply_filters('the_title', $item->post_title, $item->ID); |
|
363 | 363 | } |
364 | 364 | else { |
365 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
366 | - $lesson_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
|
365 | + $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID), admin_url('admin.php')); |
|
366 | + $lesson_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>'; |
|
367 | 367 | |
368 | - if ( $course_id ) { |
|
369 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
370 | - $course_title = '<a href="' . esc_url( $url ) . '">' . $course_title . '</a>'; |
|
368 | + if ($course_id) { |
|
369 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
370 | + $course_title = '<a href="'.esc_url($url).'">'.$course_title.'</a>'; |
|
371 | 371 | } |
372 | 372 | else { |
373 | 373 | $course_title = __('n/a', 'woothemes-sensei'); |
374 | 374 | } |
375 | - if ( is_numeric( $lesson_average_grade ) ) { |
|
375 | + if (is_numeric($lesson_average_grade)) { |
|
376 | 376 | $lesson_average_grade .= '%'; |
377 | 377 | } |
378 | 378 | } // End If Statement |
379 | - $column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $lesson_title, |
|
379 | + $column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $lesson_title, |
|
380 | 380 | 'course' => $course_title, |
381 | 381 | 'students' => $lesson_students, |
382 | 382 | 'completions' => $lesson_completions, |
383 | 383 | 'average_grade' => $lesson_average_grade, |
384 | - ), $item, $this ); |
|
384 | + ), $item, $this); |
|
385 | 385 | break; |
386 | 386 | |
387 | 387 | case 'users' : |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | 'type' => 'sensei_course_status', |
393 | 393 | 'status' => 'any', |
394 | 394 | ); |
395 | - $user_courses_started = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_courses_started', $course_args, $item ) ); |
|
395 | + $user_courses_started = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_courses_started', $course_args, $item)); |
|
396 | 396 | |
397 | 397 | // Get Completed Courses |
398 | 398 | $course_args = array( |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | 'type' => 'sensei_course_status', |
401 | 401 | 'status' => 'complete', |
402 | 402 | ); |
403 | - $user_courses_ended = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_courses_ended', $course_args, $item ) ); |
|
403 | + $user_courses_ended = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_courses_ended', $course_args, $item)); |
|
404 | 404 | |
405 | 405 | // Get Quiz Grades |
406 | 406 | $grade_args = array( |
@@ -409,29 +409,29 @@ discard block |
||
409 | 409 | 'status' => 'any', |
410 | 410 | 'meta_key' => 'grade', |
411 | 411 | ); |
412 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
413 | - $user_quiz_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_lesson_grades', $grade_args, $item ), true ); |
|
414 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
412 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
413 | + $user_quiz_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_lesson_grades', $grade_args, $item), true); |
|
414 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
415 | 415 | |
416 | - $grade_count = !empty( $user_quiz_grades->total ) ? $user_quiz_grades->total : 1; |
|
417 | - $grade_total = !empty( $user_quiz_grades->meta_sum ) ? doubleval( $user_quiz_grades->meta_sum ) : 0; |
|
418 | - $user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) ); |
|
416 | + $grade_count = ! empty($user_quiz_grades->total) ? $user_quiz_grades->total : 1; |
|
417 | + $grade_total = ! empty($user_quiz_grades->meta_sum) ? doubleval($user_quiz_grades->meta_sum) : 0; |
|
418 | + $user_average_grade = abs(round(doubleval($grade_total / $grade_count), 2)); |
|
419 | 419 | |
420 | 420 | // Output the users data |
421 | - if ( $this->csv_output ) { |
|
422 | - $user_name = Sensei_Learner::get_full_name( $item->ID ); |
|
421 | + if ($this->csv_output) { |
|
422 | + $user_name = Sensei_Learner::get_full_name($item->ID); |
|
423 | 423 | } |
424 | 424 | else { |
425 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
426 | - $user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>'; |
|
425 | + $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->ID), admin_url('admin.php')); |
|
426 | + $user_name = '<strong><a class="row-title" href="'.esc_url($url).'">'.$item->display_name.'</a></strong>'; |
|
427 | 427 | $user_average_grade .= '%'; |
428 | 428 | } // End If Statement |
429 | - $column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $user_name, |
|
429 | + $column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $user_name, |
|
430 | 430 | 'registered' => $item->user_registered, |
431 | - 'active_courses' => ( $user_courses_started - $user_courses_ended ), |
|
431 | + 'active_courses' => ($user_courses_started - $user_courses_ended), |
|
432 | 432 | 'completed_courses' => $user_courses_ended, |
433 | 433 | 'average_grade' => $user_average_grade, |
434 | - ), $item, $this ); |
|
434 | + ), $item, $this); |
|
435 | 435 | break; |
436 | 436 | } // end switch |
437 | 437 | return $column_data; |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | * @since 1.7.0 |
443 | 443 | * @return array courses |
444 | 444 | */ |
445 | - private function get_courses( $args ) { |
|
445 | + private function get_courses($args) { |
|
446 | 446 | $course_args = array( |
447 | 447 | 'post_type' => 'course', |
448 | 448 | 'post_status' => array('publish', 'private'), |
@@ -453,16 +453,16 @@ discard block |
||
453 | 453 | 'suppress_filters' => 0, |
454 | 454 | ); |
455 | 455 | |
456 | - if ( $this->csv_output ) { |
|
456 | + if ($this->csv_output) { |
|
457 | 457 | $course_args['posts_per_page'] = '-1'; |
458 | 458 | } |
459 | 459 | |
460 | - if( isset( $args['search'] ) ) { |
|
460 | + if (isset($args['search'])) { |
|
461 | 461 | $course_args['s'] = $args['search']; |
462 | 462 | } |
463 | 463 | |
464 | 464 | // Using WP_Query as get_posts() doesn't support 'found_posts' |
465 | - $courses_query = new WP_Query( apply_filters( 'sensei_analysis_overview_filter_courses', $course_args ) ); |
|
465 | + $courses_query = new WP_Query(apply_filters('sensei_analysis_overview_filter_courses', $course_args)); |
|
466 | 466 | $this->total_items = $courses_query->found_posts; |
467 | 467 | return $courses_query->posts; |
468 | 468 | |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | * @since 1.7.0 |
474 | 474 | * @return array lessons |
475 | 475 | */ |
476 | - private function get_lessons( $args ) { |
|
476 | + private function get_lessons($args) { |
|
477 | 477 | $lessons_args = array( |
478 | 478 | 'post_type' => 'lesson', |
479 | 479 | 'post_status' => array('publish', 'private'), |
@@ -484,16 +484,16 @@ discard block |
||
484 | 484 | 'suppress_filters' => 0, |
485 | 485 | ); |
486 | 486 | |
487 | - if ( $this->csv_output ) { |
|
487 | + if ($this->csv_output) { |
|
488 | 488 | $lessons_args['posts_per_page'] = '-1'; |
489 | 489 | } |
490 | 490 | |
491 | - if( isset( $args['search'] ) ) { |
|
491 | + if (isset($args['search'])) { |
|
492 | 492 | $lessons_args['s'] = $args['search']; |
493 | 493 | } |
494 | 494 | |
495 | 495 | // Using WP_Query as get_posts() doesn't support 'found_posts' |
496 | - $lessons_query = new WP_Query( apply_filters( 'sensei_analysis_overview_filter_lessons', $lessons_args ) ); |
|
496 | + $lessons_query = new WP_Query(apply_filters('sensei_analysis_overview_filter_lessons', $lessons_args)); |
|
497 | 497 | $this->total_items = $lessons_query->found_posts; |
498 | 498 | return $lessons_query->posts; |
499 | 499 | } // End get_lessons() |
@@ -503,24 +503,24 @@ discard block |
||
503 | 503 | * @since 1.7.0 |
504 | 504 | * @return array learners |
505 | 505 | */ |
506 | - private function get_learners( $args ) { |
|
506 | + private function get_learners($args) { |
|
507 | 507 | |
508 | - if ( !empty($args['search']) ) { |
|
508 | + if ( ! empty($args['search'])) { |
|
509 | 509 | $args = array( |
510 | - 'search' => '*' . trim( $args['search'], '*' ) . '*', |
|
510 | + 'search' => '*'.trim($args['search'], '*').'*', |
|
511 | 511 | ); |
512 | 512 | } |
513 | 513 | |
514 | 514 | // This stops the full meta data of each user being loaded |
515 | - $args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' ); |
|
515 | + $args['fields'] = array('ID', 'user_login', 'user_email', 'user_registered', 'display_name'); |
|
516 | 516 | |
517 | 517 | /** |
518 | 518 | * Filter the WP_User_Query arguments |
519 | 519 | * @since 1.6.0 |
520 | 520 | * @param $args |
521 | 521 | */ |
522 | - $args = apply_filters( 'sensei_analysis_overview_filter_users', $args ); |
|
523 | - $wp_user_search = new WP_User_Query( $args ); |
|
522 | + $args = apply_filters('sensei_analysis_overview_filter_users', $args); |
|
523 | + $wp_user_search = new WP_User_Query($args); |
|
524 | 524 | $learners = $wp_user_search->get_results(); |
525 | 525 | $this->total_items = $wp_user_search->get_total(); |
526 | 526 | |
@@ -533,13 +533,13 @@ discard block |
||
533 | 533 | * @since 1.2.0 |
534 | 534 | * @return array $stats_to_render of stats boxes and values |
535 | 535 | */ |
536 | - public function stats_boxes () { |
|
536 | + public function stats_boxes() { |
|
537 | 537 | |
538 | 538 | // Get the data required |
539 | 539 | $user_count = count_users(); |
540 | - $user_count = apply_filters( 'sensei_analysis_total_users', $user_count['total_users'], $user_count ); |
|
541 | - $total_courses = Sensei()->course->course_count( array('publish', 'private') ); |
|
542 | - $total_lessons = Sensei()->lesson->lesson_count( array('publish', 'private') ); |
|
540 | + $user_count = apply_filters('sensei_analysis_total_users', $user_count['total_users'], $user_count); |
|
541 | + $total_courses = Sensei()->course->course_count(array('publish', 'private')); |
|
542 | + $total_lessons = Sensei()->lesson->lesson_count(array('publish', 'private')); |
|
543 | 543 | |
544 | 544 | $grade_args = array( |
545 | 545 | 'type' => 'sensei_lesson_status', |
@@ -547,36 +547,36 @@ discard block |
||
547 | 547 | 'meta_key' => 'grade', |
548 | 548 | ); |
549 | 549 | |
550 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
551 | - $total_quiz_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_quiz_grades', $grade_args ), true ); |
|
552 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
550 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
551 | + $total_quiz_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_quiz_grades', $grade_args), true); |
|
552 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
553 | 553 | |
554 | - $total_grade_count = !empty( $total_quiz_grades->total ) ? $total_quiz_grades->total : 1; |
|
555 | - $total_grade_total = !empty( $total_quiz_grades->meta_sum ) ? doubleval( $total_quiz_grades->meta_sum ) : 0; |
|
556 | - $total_average_grade = abs( round( doubleval( $total_grade_total / $total_grade_count ), 2 ) ); |
|
554 | + $total_grade_count = ! empty($total_quiz_grades->total) ? $total_quiz_grades->total : 1; |
|
555 | + $total_grade_total = ! empty($total_quiz_grades->meta_sum) ? doubleval($total_quiz_grades->meta_sum) : 0; |
|
556 | + $total_average_grade = abs(round(doubleval($total_grade_total / $total_grade_count), 2)); |
|
557 | 557 | |
558 | 558 | $course_args = array( |
559 | 559 | 'type' => 'sensei_course_status', |
560 | 560 | 'status' => 'any', |
561 | 561 | ); |
562 | - $total_courses_started = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_courses_started', $course_args ) ); |
|
562 | + $total_courses_started = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_courses_started', $course_args)); |
|
563 | 563 | $course_args = array( |
564 | 564 | 'type' => 'sensei_course_status', |
565 | 565 | 'status' => 'complete', |
566 | 566 | ); |
567 | - $total_courses_ended = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_courses_ended', $course_args ) ); |
|
568 | - $average_courses_per_learner = abs( round( doubleval( $total_courses_started / $user_count ), 2 ) ); |
|
567 | + $total_courses_ended = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_courses_ended', $course_args)); |
|
568 | + $average_courses_per_learner = abs(round(doubleval($total_courses_started / $user_count), 2)); |
|
569 | 569 | |
570 | 570 | // Setup the boxes to render |
571 | 571 | $stats_to_render = array( |
572 | - __( 'Total Courses', 'woothemes-sensei' ) => $total_courses, |
|
573 | - __( 'Total Lessons', 'woothemes-sensei' ) => $total_lessons, |
|
574 | - __( 'Total Learners', 'woothemes-sensei' ) => $user_count, |
|
575 | - __( 'Average Courses per Learner', 'woothemes-sensei' ) => $average_courses_per_learner, |
|
576 | - __( 'Average Grade', 'woothemes-sensei' ) => $total_average_grade . '%', |
|
577 | - __( 'Total Completed Courses', 'woothemes-sensei' ) => $total_courses_ended, |
|
572 | + __('Total Courses', 'woothemes-sensei') => $total_courses, |
|
573 | + __('Total Lessons', 'woothemes-sensei') => $total_lessons, |
|
574 | + __('Total Learners', 'woothemes-sensei') => $user_count, |
|
575 | + __('Average Courses per Learner', 'woothemes-sensei') => $average_courses_per_learner, |
|
576 | + __('Average Grade', 'woothemes-sensei') => $total_average_grade.'%', |
|
577 | + __('Total Completed Courses', 'woothemes-sensei') => $total_courses_ended, |
|
578 | 578 | ); |
579 | - return apply_filters( 'sensei_analysis_stats_boxes', $stats_to_render ); |
|
579 | + return apply_filters('sensei_analysis_stats_boxes', $stats_to_render); |
|
580 | 580 | } // End stats_boxes() |
581 | 581 | |
582 | 582 | /** |
@@ -586,12 +586,12 @@ discard block |
||
586 | 586 | * @return void |
587 | 587 | */ |
588 | 588 | public function no_items() { |
589 | - if( ! $this->view || 'users' == $this->view ) { |
|
589 | + if ( ! $this->view || 'users' == $this->view) { |
|
590 | 590 | $type = 'learners'; |
591 | 591 | } else { |
592 | 592 | $type = $this->view; |
593 | 593 | } |
594 | - echo sprintf( __( '%1$sNo %2$s found%3$s', 'woothemes-sensei' ), '<em>', $type, '</em>' ); |
|
594 | + echo sprintf(__('%1$sNo %2$s found%3$s', 'woothemes-sensei'), '<em>', $type, '</em>'); |
|
595 | 595 | } // End no_items() |
596 | 596 | |
597 | 597 | /** |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | 'page' => $this->page_slug, |
607 | 607 | ); |
608 | 608 | $learners_class = $courses_class = $lessons_class = ''; |
609 | - switch( $this->type ) { |
|
609 | + switch ($this->type) { |
|
610 | 610 | case 'courses': |
611 | 611 | $courses_class = 'current'; |
612 | 612 | break; |
@@ -624,18 +624,18 @@ discard block |
||
624 | 624 | $lesson_args['view'] = 'lessons'; |
625 | 625 | $courses_args['view'] = 'courses'; |
626 | 626 | |
627 | - $menu['learners'] = '<a class="' . $learners_class . '" href="' . esc_url( add_query_arg( $learner_args, admin_url( 'admin.php' ) ) ). '">' . __( 'Learners', 'woothemes-sensei' ) . '</a>'; |
|
628 | - $menu['courses'] = '<a class="' . $courses_class . '" href="' . esc_url ( add_query_arg( $courses_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Courses', 'woothemes-sensei' ) . '</a>'; |
|
629 | - $menu['lessons'] = '<a class="' . $lessons_class . '" href="' . esc_url( add_query_arg( $lesson_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Lessons', 'woothemes-sensei' ) . '</a>'; |
|
627 | + $menu['learners'] = '<a class="'.$learners_class.'" href="'.esc_url(add_query_arg($learner_args, admin_url('admin.php'))).'">'.__('Learners', 'woothemes-sensei').'</a>'; |
|
628 | + $menu['courses'] = '<a class="'.$courses_class.'" href="'.esc_url(add_query_arg($courses_args, admin_url('admin.php'))).'">'.__('Courses', 'woothemes-sensei').'</a>'; |
|
629 | + $menu['lessons'] = '<a class="'.$lessons_class.'" href="'.esc_url(add_query_arg($lesson_args, admin_url('admin.php'))).'">'.__('Lessons', 'woothemes-sensei').'</a>'; |
|
630 | 630 | |
631 | - $menu = apply_filters( 'sensei_analysis_overview_sub_menu', $menu ); |
|
632 | - if ( !empty($menu) ) { |
|
633 | - echo '<ul class="subsubsub">' . "\n"; |
|
634 | - foreach ( $menu as $class => $item ) { |
|
635 | - $menu[ $class ] = "\t<li class='$class'>$item"; |
|
631 | + $menu = apply_filters('sensei_analysis_overview_sub_menu', $menu); |
|
632 | + if ( ! empty($menu)) { |
|
633 | + echo '<ul class="subsubsub">'."\n"; |
|
634 | + foreach ($menu as $class => $item) { |
|
635 | + $menu[$class] = "\t<li class='$class'>$item"; |
|
636 | 636 | } |
637 | - echo implode( " |</li>\n", $menu ) . "</li>\n"; |
|
638 | - echo '</ul>' . "\n"; |
|
637 | + echo implode(" |</li>\n", $menu)."</li>\n"; |
|
638 | + echo '</ul>'."\n"; |
|
639 | 639 | } |
640 | 640 | } // End data_table_header() |
641 | 641 | |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | * @return void |
646 | 646 | */ |
647 | 647 | public function data_table_footer() { |
648 | - switch ( $this->type ) { |
|
648 | + switch ($this->type) { |
|
649 | 649 | case 'courses': |
650 | 650 | $report = 'courses-overview'; |
651 | 651 | break; |
@@ -659,8 +659,8 @@ discard block |
||
659 | 659 | $report = 'user-overview'; |
660 | 660 | break; |
661 | 661 | } // End Switch Statement |
662 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'view' => $this->type, 'sensei_report_download' => $report ), admin_url( 'admin.php' ) ); |
|
663 | - echo '<a class="button button-primary" href="' . esc_url( wp_nonce_url( $url, 'sensei_csv_download-' . $report, '_sdl_nonce' ) ) . '">' . __( 'Export all rows (CSV)', 'woothemes-sensei' ) . '</a>'; |
|
662 | + $url = add_query_arg(array('page' => $this->page_slug, 'view' => $this->type, 'sensei_report_download' => $report), admin_url('admin.php')); |
|
663 | + echo '<a class="button button-primary" href="'.esc_url(wp_nonce_url($url, 'sensei_csv_download-'.$report, '_sdl_nonce')).'">'.__('Export all rows (CSV)', 'woothemes-sensei').'</a>'; |
|
664 | 664 | } // End data_table_footer() |
665 | 665 | |
666 | 666 | /** |
@@ -668,19 +668,19 @@ discard block |
||
668 | 668 | * @since 1.7.0 |
669 | 669 | * @return string $text |
670 | 670 | */ |
671 | - public function search_button( $text = '' ) { |
|
672 | - switch( $this->type ) { |
|
671 | + public function search_button($text = '') { |
|
672 | + switch ($this->type) { |
|
673 | 673 | case 'courses': |
674 | - $text = __( 'Search Courses', 'woothemes-sensei' ); |
|
674 | + $text = __('Search Courses', 'woothemes-sensei'); |
|
675 | 675 | break; |
676 | 676 | |
677 | 677 | case 'lessons': |
678 | - $text = __( 'Search Lessons', 'woothemes-sensei' ); |
|
678 | + $text = __('Search Lessons', 'woothemes-sensei'); |
|
679 | 679 | break; |
680 | 680 | |
681 | 681 | case 'users': |
682 | 682 | default: |
683 | - $text = __( 'Search Learners', 'woothemes-sensei' ); |
|
683 | + $text = __('Search Learners', 'woothemes-sensei'); |
|
684 | 684 | break; |
685 | 685 | } // End Switch Statement |
686 | 686 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Analysis User Profile Data Table in Sensei. |
@@ -18,17 +18,17 @@ discard block |
||
18 | 18 | * @since 1.2.0 |
19 | 19 | * @return void |
20 | 20 | */ |
21 | - public function __construct ( $user_id = 0 ) { |
|
22 | - $this->user_id = intval( $user_id ); |
|
21 | + public function __construct($user_id = 0) { |
|
22 | + $this->user_id = intval($user_id); |
|
23 | 23 | |
24 | 24 | // Load Parent token into constructor |
25 | - parent::__construct( 'analysis_user_profile' ); |
|
25 | + parent::__construct('analysis_user_profile'); |
|
26 | 26 | |
27 | 27 | // Actions |
28 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
29 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
28 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
29 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
30 | 30 | |
31 | - add_filter( 'sensei_list_table_search_button_text', array( $this, 'search_button' ) ); |
|
31 | + add_filter('sensei_list_table_search_button_text', array($this, 'search_button')); |
|
32 | 32 | } // End __construct() |
33 | 33 | |
34 | 34 | /** |
@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | */ |
39 | 39 | function get_columns() { |
40 | 40 | $columns = array( |
41 | - 'title' => __( 'Course', 'woothemes-sensei' ), |
|
42 | - 'started' => __( 'Date Started', 'woothemes-sensei' ), |
|
43 | - 'completed' => __( 'Date Completed', 'woothemes-sensei' ), |
|
44 | - 'status' => __( 'Status', 'woothemes-sensei' ), |
|
41 | + 'title' => __('Course', 'woothemes-sensei'), |
|
42 | + 'started' => __('Date Started', 'woothemes-sensei'), |
|
43 | + 'completed' => __('Date Completed', 'woothemes-sensei'), |
|
44 | + 'status' => __('Status', 'woothemes-sensei'), |
|
45 | 45 | // 'grade' => __( 'Grade', 'woothemes-sensei' ), |
46 | - 'percent' => __( 'Percent Complete', 'woothemes-sensei' ), |
|
46 | + 'percent' => __('Percent Complete', 'woothemes-sensei'), |
|
47 | 47 | ); |
48 | - $columns = apply_filters( 'sensei_analysis_user_profile_columns', $columns ); |
|
48 | + $columns = apply_filters('sensei_analysis_user_profile_columns', $columns); |
|
49 | 49 | return $columns; |
50 | 50 | } |
51 | 51 | |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | */ |
57 | 57 | function get_sortable_columns() { |
58 | 58 | $columns = array( |
59 | - 'title' => array( 'title', false ), |
|
60 | - 'started' => array( 'started', false ), |
|
61 | - 'completed' => array( 'completed', false ), |
|
62 | - 'status' => array( 'status', false ), |
|
59 | + 'title' => array('title', false), |
|
60 | + 'started' => array('started', false), |
|
61 | + 'completed' => array('completed', false), |
|
62 | + 'status' => array('status', false), |
|
63 | 63 | // 'grade' => array( 'grade', false ), |
64 | - 'percent' => array( 'percent', false ) |
|
64 | + 'percent' => array('percent', false) |
|
65 | 65 | ); |
66 | - $columns = apply_filters( 'sensei_analysis_user_profile_columns_sortable', $columns ); |
|
66 | + $columns = apply_filters('sensei_analysis_user_profile_columns_sortable', $columns); |
|
67 | 67 | return $columns; |
68 | 68 | } |
69 | 69 | |
@@ -77,32 +77,32 @@ discard block |
||
77 | 77 | |
78 | 78 | // Handle orderby (needs work) |
79 | 79 | $orderby = ''; |
80 | - if ( !empty( $_GET['orderby'] ) ) { |
|
81 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
82 | - $orderby = esc_html( $_GET['orderby'] ); |
|
80 | + if ( ! empty($_GET['orderby'])) { |
|
81 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
82 | + $orderby = esc_html($_GET['orderby']); |
|
83 | 83 | } // End If Statement |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Handle order |
87 | 87 | $order = 'ASC'; |
88 | - if ( !empty( $_GET['order'] ) ) { |
|
89 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
88 | + if ( ! empty($_GET['order'])) { |
|
89 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | // Handle search, need 4.1 version of WP to be able to restrict statuses to known post_ids |
93 | 93 | $search = false; |
94 | - if ( !empty( $_GET['s'] ) ) { |
|
95 | - $search = esc_html( $_GET['s'] ); |
|
94 | + if ( ! empty($_GET['s'])) { |
|
95 | + $search = esc_html($_GET['s']); |
|
96 | 96 | } // End If Statement |
97 | 97 | $this->search = $search; |
98 | 98 | |
99 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
100 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
99 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
100 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
101 | 101 | |
102 | 102 | $paged = $this->get_pagenum(); |
103 | 103 | $offset = 0; |
104 | - if ( !empty($paged) ) { |
|
105 | - $offset = $per_page * ( $paged - 1 ); |
|
104 | + if ( ! empty($paged)) { |
|
105 | + $offset = $per_page * ($paged - 1); |
|
106 | 106 | } // End If Statement |
107 | 107 | |
108 | 108 | $args = array( |
@@ -111,19 +111,19 @@ discard block |
||
111 | 111 | 'orderby' => $orderby, |
112 | 112 | 'order' => $order, |
113 | 113 | ); |
114 | - if ( $this->search ) { |
|
114 | + if ($this->search) { |
|
115 | 115 | $args['search'] = $this->search; |
116 | 116 | } // End If Statement |
117 | 117 | |
118 | - $this->items = $this->get_course_statuses( $args ); |
|
118 | + $this->items = $this->get_course_statuses($args); |
|
119 | 119 | |
120 | 120 | $total_items = $this->total_items; |
121 | - $total_pages = ceil( $total_items / $per_page ); |
|
122 | - $this->set_pagination_args( array( |
|
121 | + $total_pages = ceil($total_items / $per_page); |
|
122 | + $this->set_pagination_args(array( |
|
123 | 123 | 'total_items' => $total_items, |
124 | 124 | 'total_pages' => $total_pages, |
125 | 125 | 'per_page' => $per_page |
126 | - ) ); |
|
126 | + )); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * @since 1.7.0 |
132 | 132 | * @return data |
133 | 133 | */ |
134 | - public function generate_report( $report ) { |
|
134 | + public function generate_report($report) { |
|
135 | 135 | |
136 | 136 | $data = array(); |
137 | 137 | |
@@ -139,22 +139,22 @@ discard block |
||
139 | 139 | |
140 | 140 | // Handle orderby |
141 | 141 | $orderby = ''; |
142 | - if ( !empty( $_GET['orderby'] ) ) { |
|
143 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
144 | - $orderby = esc_html( $_GET['orderby'] ); |
|
142 | + if ( ! empty($_GET['orderby'])) { |
|
143 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
144 | + $orderby = esc_html($_GET['orderby']); |
|
145 | 145 | } // End If Statement |
146 | 146 | } |
147 | 147 | |
148 | 148 | // Handle order |
149 | 149 | $order = 'ASC'; |
150 | - if ( !empty( $_GET['order'] ) ) { |
|
151 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
150 | + if ( ! empty($_GET['order'])) { |
|
151 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // Handle search |
155 | 155 | $search = false; |
156 | - if ( !empty( $_GET['s'] ) ) { |
|
157 | - $search = esc_html( $_GET['s'] ); |
|
156 | + if ( ! empty($_GET['s'])) { |
|
157 | + $search = esc_html($_GET['s']); |
|
158 | 158 | } // End If Statement |
159 | 159 | $this->search = $search; |
160 | 160 | |
@@ -162,23 +162,23 @@ discard block |
||
162 | 162 | 'orderby' => $orderby, |
163 | 163 | 'order' => $order, |
164 | 164 | ); |
165 | - if ( $this->search ) { |
|
165 | + if ($this->search) { |
|
166 | 166 | $args['search'] = $this->search; |
167 | 167 | } // End If Statement |
168 | 168 | |
169 | 169 | // Start the csv with the column headings |
170 | 170 | $column_headers = array(); |
171 | 171 | $columns = $this->get_columns(); |
172 | - foreach( $columns AS $key => $title ) { |
|
172 | + foreach ($columns AS $key => $title) { |
|
173 | 173 | $column_headers[] = $title; |
174 | 174 | } |
175 | 175 | $data[] = $column_headers; |
176 | 176 | |
177 | - $this->items = $this->get_course_statuses( $args ); |
|
177 | + $this->items = $this->get_course_statuses($args); |
|
178 | 178 | |
179 | 179 | // Process each row |
180 | - foreach( $this->items AS $item) { |
|
181 | - $data[] = $this->get_row_data( $item ); |
|
180 | + foreach ($this->items AS $item) { |
|
181 | + $data[] = $this->get_row_data($item); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | return $data; |
@@ -189,43 +189,43 @@ discard block |
||
189 | 189 | * @since 1.7.0 |
190 | 190 | * @param object $item The current item |
191 | 191 | */ |
192 | - protected function get_row_data( $item ) { |
|
192 | + protected function get_row_data($item) { |
|
193 | 193 | |
194 | - $course_title = get_the_title( $item->comment_post_ID ); |
|
195 | - $course_percent = get_comment_meta( $item->comment_ID, 'percent', true ); |
|
196 | - $course_start_date = get_comment_meta( $item->comment_ID, 'start', true ); |
|
194 | + $course_title = get_the_title($item->comment_post_ID); |
|
195 | + $course_percent = get_comment_meta($item->comment_ID, 'percent', true); |
|
196 | + $course_start_date = get_comment_meta($item->comment_ID, 'start', true); |
|
197 | 197 | $course_end_date = ''; |
198 | 198 | |
199 | - if( 'complete' == $item->comment_approved ) { |
|
199 | + if ('complete' == $item->comment_approved) { |
|
200 | 200 | |
201 | - $status = __( 'Completed', 'woothemes-sensei' ); |
|
201 | + $status = __('Completed', 'woothemes-sensei'); |
|
202 | 202 | $status_class = 'graded'; |
203 | 203 | |
204 | 204 | $course_end_date = $item->comment_date; |
205 | 205 | |
206 | 206 | } else { |
207 | 207 | |
208 | - $status = __( 'In Progress', 'woothemes-sensei' ); |
|
208 | + $status = __('In Progress', 'woothemes-sensei'); |
|
209 | 209 | $status_class = 'in-progress'; |
210 | 210 | |
211 | 211 | } |
212 | 212 | |
213 | 213 | // Output users data |
214 | - if ( !$this->csv_output ) { |
|
215 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $this->user_id, 'course_id' => $item->comment_post_ID ), admin_url( 'admin.php' ) ); |
|
214 | + if ( ! $this->csv_output) { |
|
215 | + $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $this->user_id, 'course_id' => $item->comment_post_ID), admin_url('admin.php')); |
|
216 | 216 | |
217 | - $course_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $course_title . '</a></strong>'; |
|
218 | - $status = sprintf( '<span class="%s">%s</span>', $status_class, $status ); |
|
219 | - if ( is_numeric($course_percent) ) { |
|
217 | + $course_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.$course_title.'</a></strong>'; |
|
218 | + $status = sprintf('<span class="%s">%s</span>', $status_class, $status); |
|
219 | + if (is_numeric($course_percent)) { |
|
220 | 220 | $course_percent .= '%'; |
221 | 221 | } |
222 | 222 | } // End If Statement |
223 | - $column_data = apply_filters( 'sensei_analysis_user_profile_column_data', array( 'title' => $course_title, |
|
223 | + $column_data = apply_filters('sensei_analysis_user_profile_column_data', array('title' => $course_title, |
|
224 | 224 | 'started' => $course_start_date, |
225 | 225 | 'completed' => $course_end_date, |
226 | 226 | 'status' => $status, |
227 | 227 | 'percent' => $course_percent, |
228 | - ), $item ); |
|
228 | + ), $item); |
|
229 | 229 | |
230 | 230 | return $column_data; |
231 | 231 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @since 1.7.0 |
236 | 236 | * @return array statuses |
237 | 237 | */ |
238 | - private function get_course_statuses( $args ) { |
|
238 | + private function get_course_statuses($args) { |
|
239 | 239 | |
240 | 240 | $activity_args = array( |
241 | 241 | 'user_id' => $this->user_id, |
@@ -247,23 +247,23 @@ discard block |
||
247 | 247 | 'status' => 'any', |
248 | 248 | ); |
249 | 249 | |
250 | - $activity_args = apply_filters( 'sensei_analysis_user_profile_filter_statuses', $activity_args ); |
|
250 | + $activity_args = apply_filters('sensei_analysis_user_profile_filter_statuses', $activity_args); |
|
251 | 251 | |
252 | 252 | // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice |
253 | - $this->total_items = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); |
|
253 | + $this->total_items = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); |
|
254 | 254 | |
255 | 255 | // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? |
256 | - if ( $this->total_items < $activity_args['offset'] ) { |
|
256 | + if ($this->total_items < $activity_args['offset']) { |
|
257 | 257 | |
258 | - $new_paged = floor( $this->total_items / $activity_args['number'] ); |
|
258 | + $new_paged = floor($this->total_items / $activity_args['number']); |
|
259 | 259 | $activity_args['offset'] = $new_paged * $activity_args['number']; |
260 | 260 | |
261 | 261 | } |
262 | - $statuses = Sensei_Utils::sensei_check_for_activity( $activity_args, true ); |
|
262 | + $statuses = Sensei_Utils::sensei_check_for_activity($activity_args, true); |
|
263 | 263 | |
264 | 264 | // Need to always return an array, even with only 1 item |
265 | - if ( !is_array($statuses) ) { |
|
266 | - $statuses = array( $statuses ); |
|
265 | + if ( ! is_array($statuses)) { |
|
266 | + $statuses = array($statuses); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | return $statuses; |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @return void |
277 | 277 | */ |
278 | 278 | public function no_items() { |
279 | - echo __( 'No courses found.', 'woothemes-sensei' ); |
|
279 | + echo __('No courses found.', 'woothemes-sensei'); |
|
280 | 280 | } // End no_items() |
281 | 281 | |
282 | 282 | /** |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @return void |
286 | 286 | */ |
287 | 287 | public function data_table_header() { |
288 | - echo '<strong>' . __( 'Courses', 'woothemes-sensei' ) . '</strong>'; |
|
288 | + echo '<strong>'.__('Courses', 'woothemes-sensei').'</strong>'; |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -294,10 +294,10 @@ discard block |
||
294 | 294 | * @return void |
295 | 295 | */ |
296 | 296 | public function data_table_footer() { |
297 | - $user = get_user_by( 'id', $this->user_id ); |
|
298 | - $report = sanitize_title( $user->display_name ) . '-course-overview'; |
|
299 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $this->user_id, 'sensei_report_download' => $report ), admin_url( 'admin.php' ) ); |
|
300 | - echo '<a class="button button-primary" href="' . esc_url( wp_nonce_url( $url, 'sensei_csv_download-' . $report, '_sdl_nonce' ) ) . '">' . __( 'Export all rows (CSV)', 'woothemes-sensei' ) . '</a>'; |
|
297 | + $user = get_user_by('id', $this->user_id); |
|
298 | + $report = sanitize_title($user->display_name).'-course-overview'; |
|
299 | + $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $this->user_id, 'sensei_report_download' => $report), admin_url('admin.php')); |
|
300 | + echo '<a class="button button-primary" href="'.esc_url(wp_nonce_url($url, 'sensei_csv_download-'.$report, '_sdl_nonce')).'">'.__('Export all rows (CSV)', 'woothemes-sensei').'</a>'; |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | * @since 1.7.0 |
306 | 306 | * @return string |
307 | 307 | */ |
308 | - public function search_button( $text = '' ) { |
|
309 | - return __( 'Search Courses', 'woothemes-sensei' ); |
|
308 | + public function search_button($text = '') { |
|
309 | + return __('Search Courses', 'woothemes-sensei'); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | } // End Class |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
3 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
4 | 4 | |
5 | -if ( ! class_exists( 'WooThemes_Sensei_Email_New_Message_Reply' ) ) : |
|
5 | +if ( ! class_exists('WooThemes_Sensei_Email_New_Message_Reply')) : |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * Teacher New Message |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | function __construct() { |
59 | 59 | $this->template = 'new-message-reply'; |
60 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have a new message', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
61 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'You have received a reply to your private message', 'woothemes-sensei' ), $this->template ); |
|
60 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have a new message', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
61 | + $this->heading = apply_filters('sensei_email_heading', __('You have received a reply to your private message', 'woothemes-sensei'), $this->template); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -69,35 +69,35 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return void |
71 | 71 | */ |
72 | - function trigger ( $comment, $message ) { |
|
72 | + function trigger($comment, $message) { |
|
73 | 73 | |
74 | 74 | global $sensei_email_data; |
75 | 75 | |
76 | 76 | $this->comment = $comment; |
77 | 77 | $this->message = $message; |
78 | 78 | |
79 | - $this->commenter = get_userdata( $comment->user_id ); |
|
79 | + $this->commenter = get_userdata($comment->user_id); |
|
80 | 80 | |
81 | - $original_sender = get_post_meta( $this->message->ID, '_sender', true ); |
|
82 | - $this->original_sender = get_user_by( 'login', $original_sender ); |
|
81 | + $original_sender = get_post_meta($this->message->ID, '_sender', true); |
|
82 | + $this->original_sender = get_user_by('login', $original_sender); |
|
83 | 83 | |
84 | - $original_receiver = get_post_meta( $this->message->ID, '_receiver', true ); |
|
85 | - $this->original_receiver = get_user_by( 'login', $original_receiver ); |
|
84 | + $original_receiver = get_post_meta($this->message->ID, '_receiver', true); |
|
85 | + $this->original_receiver = get_user_by('login', $original_receiver); |
|
86 | 86 | |
87 | - $content_type = get_post_meta( $this->message->ID, '_posttype', true ); |
|
88 | - $content_id = get_post_meta( $this->message->ID, '_post', true ); |
|
89 | - $content_title = get_the_title( $content_id ); |
|
87 | + $content_type = get_post_meta($this->message->ID, '_posttype', true); |
|
88 | + $content_id = get_post_meta($this->message->ID, '_post', true); |
|
89 | + $content_title = get_the_title($content_id); |
|
90 | 90 | |
91 | - $comment_link = get_comment_link( $comment ); |
|
91 | + $comment_link = get_comment_link($comment); |
|
92 | 92 | |
93 | 93 | // setup the post type parameter |
94 | - $content_type = get_post_type( $content_id ); |
|
95 | - if( !$content_type ){ |
|
96 | - $content_type =''; |
|
94 | + $content_type = get_post_type($content_id); |
|
95 | + if ( ! $content_type) { |
|
96 | + $content_type = ''; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // Construct data array |
100 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
100 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
101 | 101 | 'template' => $this->template, |
102 | 102 | $content_type.'_id' => $content_id, |
103 | 103 | 'heading' => $this->heading, |
@@ -106,17 +106,17 @@ discard block |
||
106 | 106 | 'comment_link' => $comment_link, |
107 | 107 | 'content_title' => $content_title, |
108 | 108 | 'content_type' => $content_type, |
109 | - ), $this->template ); |
|
109 | + ), $this->template); |
|
110 | 110 | |
111 | 111 | // Set recipient |
112 | - if( $this->commenter->user_login == $original_sender ) { |
|
113 | - $this->recipient = stripslashes( $this->original_receiver->user_email ); |
|
112 | + if ($this->commenter->user_login == $original_sender) { |
|
113 | + $this->recipient = stripslashes($this->original_receiver->user_email); |
|
114 | 114 | } else { |
115 | - $this->recipient = stripslashes( $this->original_sender->user_email ); |
|
115 | + $this->recipient = stripslashes($this->original_sender->user_email); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // Send mail |
119 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
119 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
3 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
4 | 4 | |
5 | -if ( ! class_exists( 'WooThemes_Sensei_Email_Learner_Graded_Quiz' ) ) : |
|
5 | +if ( ! class_exists('WooThemes_Sensei_Email_Learner_Graded_Quiz')) : |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * Learner Graded Quiz |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | */ |
30 | 30 | function __construct() { |
31 | 31 | $this->template = 'learner-graded-quiz'; |
32 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your quiz has been graded', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
33 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'Your quiz has been graded', 'woothemes-sensei' ), $this->template ); |
|
32 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] Your quiz has been graded', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
33 | + $this->heading = apply_filters('sensei_email_heading', __('Your quiz has been graded', 'woothemes-sensei'), $this->template); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -43,48 +43,48 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return void |
45 | 45 | */ |
46 | - function trigger ( $user_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0 ) { |
|
46 | + function trigger($user_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0) { |
|
47 | 47 | |
48 | 48 | global $sensei_email_data; |
49 | 49 | |
50 | 50 | // Get learner user object |
51 | - $this->user = new WP_User( $user_id ); |
|
51 | + $this->user = new WP_User($user_id); |
|
52 | 52 | |
53 | 53 | // Get passed flag |
54 | - $passed = __( 'failed', 'woothemes-sensei' ); |
|
55 | - if( $grade >= $passmark ) { |
|
56 | - $passed = __( 'passed', 'woothemes-sensei' ); |
|
54 | + $passed = __('failed', 'woothemes-sensei'); |
|
55 | + if ($grade >= $passmark) { |
|
56 | + $passed = __('passed', 'woothemes-sensei'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | // Get grade tye (auto/manual) |
60 | - $grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
60 | + $grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
61 | 61 | |
62 | - if( 'auto' == $grade_type ) { |
|
63 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have completed a quiz', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
64 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'You have completed a quiz', 'woothemes-sensei' ), $this->template ); |
|
62 | + if ('auto' == $grade_type) { |
|
63 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have completed a quiz', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
64 | + $this->heading = apply_filters('sensei_email_heading', __('You have completed a quiz', 'woothemes-sensei'), $this->template); |
|
65 | 65 | } |
66 | 66 | |
67 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
67 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
68 | 68 | |
69 | 69 | // Construct data array |
70 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
70 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
71 | 71 | 'template' => $this->template, |
72 | 72 | 'heading' => $this->heading, |
73 | 73 | 'user_id' => $user_id, |
74 | - 'user_name' => stripslashes( $this->user->display_name ), |
|
74 | + 'user_name' => stripslashes($this->user->display_name), |
|
75 | 75 | 'lesson_id' => $lesson_id, |
76 | 76 | 'quiz_id' => $quiz_id, |
77 | 77 | 'grade' => $grade, |
78 | 78 | 'passmark' => $passmark, |
79 | 79 | 'passed' => $passed, |
80 | 80 | 'grade_type' => $grade_type, |
81 | - ), $this->template ); |
|
81 | + ), $this->template); |
|
82 | 82 | |
83 | 83 | // Set recipient (learner) |
84 | - $this->recipient = stripslashes( $this->user->user_email ); |
|
84 | + $this->recipient = stripslashes($this->user->user_email); |
|
85 | 85 | |
86 | 86 | // Send mail |
87 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
87 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 |
@@ -3,9 +3,9 @@ discard block |
||
3 | 3 | * This email will be sent to a teacher when a course is assigned to them. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
6 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
7 | 7 | |
8 | -if ( class_exists('Sensei_Email_Teacher_New_Course_Assignment') ){ |
|
8 | +if (class_exists('Sensei_Email_Teacher_New_Course_Assignment')) { |
|
9 | 9 | return; |
10 | 10 | } |
11 | 11 | |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | function __construct() { |
37 | 37 | |
38 | 38 | $this->template = 'teacher-new-course-assignment'; |
39 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have been assigned to a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
40 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'Course assigned to you', 'woothemes-sensei' ), $this->template ); |
|
39 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have been assigned to a course', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
40 | + $this->heading = apply_filters('sensei_email_heading', __('Course assigned to you', 'woothemes-sensei'), $this->template); |
|
41 | 41 | return; |
42 | 42 | } |
43 | 43 | |
@@ -49,30 +49,30 @@ discard block |
||
49 | 49 | * @param $course_id |
50 | 50 | * @return void |
51 | 51 | */ |
52 | - function trigger( $teacher_id = 0, $course_id = 0 ) { |
|
52 | + function trigger($teacher_id = 0, $course_id = 0) { |
|
53 | 53 | global $sensei_email_data; |
54 | 54 | |
55 | - $this->teacher = new WP_User( $teacher_id ); |
|
56 | - $this->recipient = stripslashes( $this->teacher->user_email ); |
|
57 | - $this->subject = __( 'New course assigned to you', 'woothemes-sensei' ); |
|
55 | + $this->teacher = new WP_User($teacher_id); |
|
56 | + $this->recipient = stripslashes($this->teacher->user_email); |
|
57 | + $this->subject = __('New course assigned to you', 'woothemes-sensei'); |
|
58 | 58 | |
59 | 59 | //course edit link |
60 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
60 | + $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit'); |
|
61 | 61 | |
62 | 62 | // Course name |
63 | - $course = get_post( $course_id); |
|
63 | + $course = get_post($course_id); |
|
64 | 64 | // Construct data array |
65 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
65 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
66 | 66 | 'template' => $this->template, |
67 | 67 | 'heading' => $this->heading, |
68 | 68 | 'teacher_id' => $teacher_id, |
69 | 69 | 'course_id' => $course_id, |
70 | 70 | 'course_name' => $course->post_title, |
71 | 71 | 'course_edit_link' => $course_edit_link, |
72 | - ), $this->template ); |
|
72 | + ), $this->template); |
|
73 | 73 | |
74 | 74 | // Send mail |
75 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
75 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Sensei Teacher class |
@@ -40,58 +40,58 @@ discard block |
||
40 | 40 | * @since 1.8.0 |
41 | 41 | * @access public |
42 | 42 | */ |
43 | - public function __construct ( ) { |
|
43 | + public function __construct( ) { |
|
44 | 44 | |
45 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
46 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
47 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
48 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
49 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
45 | + add_action('add_meta_boxes', array($this, 'add_teacher_meta_boxes'), 10, 2); |
|
46 | + add_action('save_post', array($this, 'save_teacher_meta_box')); |
|
47 | + add_filter('parse_query', array($this, 'limit_teacher_edit_screen_post_types')); |
|
48 | + add_filter('pre_get_posts', array($this, 'course_analysis_teacher_access_limit')); |
|
49 | + add_filter('wp_count_posts', array($this, 'list_table_counts'), 10, 3); |
|
50 | 50 | |
51 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
51 | + add_action('pre_get_posts', array($this, 'filter_queries')); |
|
52 | 52 | |
53 | 53 | //filter the quiz submissions |
54 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
54 | + add_filter('sensei_check_for_activity', array($this, 'filter_grading_activity_queries')); |
|
55 | 55 | |
56 | 56 | //grading totals count only those belonging to the teacher |
57 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
57 | + add_filter('sensei_count_statuses_args', array($this, 'limit_grading_totals')); |
|
58 | 58 | |
59 | 59 | // show the courses owned by a user on his author archive page |
60 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
60 | + add_filter('pre_get_posts', array($this, 'add_courses_to_author_archive')); |
|
61 | 61 | |
62 | 62 | // notify admin when a teacher creates a course |
63 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
63 | + add_action('transition_post_status', array($this, 'notify_admin_teacher_course_creation'), 10, 3); |
|
64 | 64 | |
65 | 65 | // limit the analysis view to only the users taking courses belong to this teacher |
66 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
66 | + add_filter('sensei_analysis_overview_filter_users', array($this, 'limit_analysis_learners'), 5, 1); |
|
67 | 67 | |
68 | 68 | // give teacher access to question post type |
69 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
69 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
70 | 70 | |
71 | 71 | // Teacher column on the courses list on the admin edit screen |
72 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
73 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
72 | + add_filter('manage_edit-course_columns', array($this, 'course_column_heading'), 10, 1); |
|
73 | + add_filter('manage_course_posts_custom_column', array($this, 'course_column_data'), 10, 2); |
|
74 | 74 | |
75 | 75 | //admin edit messages query limit teacher |
76 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
76 | + add_filter('pre_get_posts', array($this, 'limit_edit_messages_query')); |
|
77 | 77 | |
78 | 78 | //add filter by teacher on courses list |
79 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
80 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
79 | + add_action('restrict_manage_posts', array($this, 'course_teacher_filter_options')); |
|
80 | + add_filter('request', array($this, 'teacher_filter_query_modify')); |
|
81 | 81 | |
82 | 82 | // Handle media library restrictions |
83 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
84 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
83 | + add_filter('request', array($this, 'restrict_media_library'), 10, 1); |
|
84 | + add_filter('ajax_query_attachments_args', array($this, 'restrict_media_library_modal'), 10, 1); |
|
85 | 85 | |
86 | 86 | // update lesson owner to course teacher when saved |
87 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
87 | + add_action('save_post', array($this, 'update_lesson_teacher')); |
|
88 | 88 | |
89 | 89 | // If a Teacher logs in, redirect to /wp-admin/ |
90 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
90 | + add_filter('wp_login', array($this, 'teacher_login_redirect'), 10, 2); |
|
91 | 91 | |
92 | 92 | |
93 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
94 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
93 | + add_action('admin_menu', array($this, 'restrict_posts_menu_page'), 10); |
|
94 | + add_filter('pre_get_comments', array($this, 'restrict_comment_moderation'), 10, 1); |
|
95 | 95 | |
96 | 96 | |
97 | 97 | } // end __constructor() |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | * @access public |
107 | 107 | * @return void |
108 | 108 | */ |
109 | - public function create_role ( ) { |
|
109 | + public function create_role( ) { |
|
110 | 110 | |
111 | 111 | // check if the role exists |
112 | - $this->teacher_role = get_role( 'teacher' ); |
|
112 | + $this->teacher_role = get_role('teacher'); |
|
113 | 113 | |
114 | 114 | // if the the teacher is not a valid WordPress role create it |
115 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
115 | + if ( ! is_a($this->teacher_role, 'WP_Role')) { |
|
116 | 116 | // create the role |
117 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
117 | + $this->teacher_role = add_role('teacher', __('Teacher', 'woothemes-sensei')); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | // add the capabilities before returning |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | * @since 1.8.0 |
129 | 129 | * @access protected |
130 | 130 | */ |
131 | - protected function add_capabilities ( ) { |
|
131 | + protected function add_capabilities( ) { |
|
132 | 132 | |
133 | 133 | // if this is not a valid WP_Role object exit without adding anything |
134 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
134 | + if ( ! is_a($this->teacher_role, 'WP_Role') || empty($this->teacher_role)) { |
|
135 | 135 | return; |
136 | 136 | } |
137 | 137 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param array $capabilities |
143 | 143 | * keys: (string) $cap_name => (bool) $grant |
144 | 144 | */ |
145 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
145 | + $caps = apply_filters('sensei_teacher_role_capabilities', array( |
|
146 | 146 | // General access rules |
147 | 147 | 'read' => true, |
148 | 148 | 'manage_sensei_grades' => true, |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | |
200 | 200 | )); |
201 | 201 | |
202 | - foreach ( $caps as $cap => $grant ) { |
|
202 | + foreach ($caps as $cap => $grant) { |
|
203 | 203 | |
204 | 204 | // load the capability on to the teacher role |
205 | 205 | $this->teacher_role->add_cap($cap, $grant); |
@@ -219,12 +219,12 @@ discard block |
||
219 | 219 | * @parameter WP_Post $post |
220 | 220 | * @return void |
221 | 221 | */ |
222 | - public function add_teacher_meta_boxes ( $post ) { |
|
222 | + public function add_teacher_meta_boxes($post) { |
|
223 | 223 | |
224 | - if( !current_user_can('manage_options') ){ |
|
224 | + if ( ! current_user_can('manage_options')) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
227 | + add_meta_box('sensei-teacher', __('Teacher', 'woothemes-sensei'), array($this, 'teacher_meta_box_content'), |
|
228 | 228 | 'course', |
229 | 229 | 'side', |
230 | 230 | 'core' |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @access public |
242 | 242 | * @parameters |
243 | 243 | */ |
244 | - public function teacher_meta_box_content ( $post ) { |
|
244 | + public function teacher_meta_box_content($post) { |
|
245 | 245 | |
246 | 246 | // get the current author |
247 | 247 | $current_author = $post->post_author; |
@@ -252,12 +252,12 @@ discard block |
||
252 | 252 | ?> |
253 | 253 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
254 | 254 | |
255 | - <?php foreach ( $users as $user_id ) { ?> |
|
255 | + <?php foreach ($users as $user_id) { ?> |
|
256 | 256 | |
257 | 257 | <?php |
258 | 258 | $user = get_user_by('id', $user_id); |
259 | 259 | ?> |
260 | - <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
|
260 | + <option <?php selected($current_author, $user_id, true); ?> value="<?php echo $user_id; ?>" > |
|
261 | 261 | <?php echo $user->display_name; ?> |
262 | 262 | </option> |
263 | 263 | |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | * @parameters |
280 | 280 | * @return array $users user id array |
281 | 281 | */ |
282 | - public function get_teachers_and_authors ( ){ |
|
282 | + public function get_teachers_and_authors( ) { |
|
283 | 283 | |
284 | 284 | $author_query_args = array( |
285 | 285 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | 'who' => 'authors' |
288 | 288 | ); |
289 | 289 | |
290 | - $authors = get_users( $author_query_args ); |
|
290 | + $authors = get_users($author_query_args); |
|
291 | 291 | |
292 | 292 | $teacher_query_args = array( |
293 | 293 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | 'role' => 'teacher', |
296 | 296 | ); |
297 | 297 | |
298 | - $teachers = get_users( $teacher_query_args ); |
|
298 | + $teachers = get_users($teacher_query_args); |
|
299 | 299 | |
300 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
300 | + return array_unique(array_merge($teachers, $authors)); |
|
301 | 301 | |
302 | 302 | }// end get_teachers_and_authors |
303 | 303 | |
@@ -313,43 +313,43 @@ discard block |
||
313 | 313 | * @parameters |
314 | 314 | * @return array $users user id array |
315 | 315 | */ |
316 | - public function save_teacher_meta_box ( $course_id ){ |
|
316 | + public function save_teacher_meta_box($course_id) { |
|
317 | 317 | |
318 | 318 | // check if this is a post from saving the teacher, if not exit early |
319 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
319 | + if ( ! isset($_POST['sensei-course-teacher-author']) || ! isset($_POST['post_ID'])) { |
|
320 | 320 | return; |
321 | 321 | } |
322 | 322 | |
323 | 323 | //don't fire this hook again |
324 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
324 | + remove_action('save_post', array($this, 'save_teacher_meta_box')); |
|
325 | 325 | |
326 | 326 | // get the current post object |
327 | - $post = get_post( $course_id ); |
|
327 | + $post = get_post($course_id); |
|
328 | 328 | |
329 | 329 | // get the current teacher/author |
330 | - $current_author = absint( $post->post_author ); |
|
331 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
330 | + $current_author = absint($post->post_author); |
|
331 | + $new_author = absint($_POST['sensei-course-teacher-author']); |
|
332 | 332 | |
333 | 333 | // loop through all post lessons to update their authors as well |
334 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
334 | + $this->update_course_lessons_author($course_id, $new_author); |
|
335 | 335 | |
336 | 336 | // do not do any processing if the selected author is the same as the current author |
337 | - if( $current_author == $new_author ){ |
|
337 | + if ($current_author == $new_author) { |
|
338 | 338 | return; |
339 | 339 | } |
340 | 340 | |
341 | 341 | // save the course author |
342 | 342 | $post_updates = array( |
343 | - 'ID' => $post->ID , |
|
343 | + 'ID' => $post->ID, |
|
344 | 344 | 'post_author' => $new_author |
345 | 345 | ); |
346 | - wp_update_post( $post_updates ); |
|
346 | + wp_update_post($post_updates); |
|
347 | 347 | |
348 | 348 | // ensure the the modules are update so that then new teacher has access to them |
349 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
349 | + Sensei_Teacher::update_course_modules_author($course_id, $new_author); |
|
350 | 350 | |
351 | 351 | // notify the new teacher |
352 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
352 | + $this->teacher_course_assigned_notification($new_author, $course_id); |
|
353 | 353 | |
354 | 354 | } // end save_teacher_meta_box |
355 | 355 | |
@@ -363,56 +363,56 @@ discard block |
||
363 | 363 | * @param $new_teacher_id |
364 | 364 | * @return void |
365 | 365 | */ |
366 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
366 | + public static function update_course_modules_author($course_id, $new_teacher_id) { |
|
367 | 367 | |
368 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
368 | + if (empty($course_id) || empty($new_teacher_id)) { |
|
369 | 369 | return; |
370 | 370 | } |
371 | 371 | |
372 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
372 | + $terms_selected_on_course = wp_get_object_terms($course_id, 'module'); |
|
373 | 373 | |
374 | - if( empty( $terms_selected_on_course ) ){ |
|
374 | + if (empty($terms_selected_on_course)) { |
|
375 | 375 | return; |
376 | 376 | } |
377 | 377 | |
378 | - foreach( $terms_selected_on_course as $term ){ |
|
378 | + foreach ($terms_selected_on_course as $term) { |
|
379 | 379 | |
380 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
381 | - if( $new_teacher_id != $term_author->ID ){ |
|
380 | + $term_author = Sensei_Core_Modules::get_term_author($term->slug); |
|
381 | + if ($new_teacher_id != $term_author->ID) { |
|
382 | 382 | |
383 | 383 | $new_term = ''; |
384 | 384 | |
385 | 385 | //if the new teacher is admin first check to see if the term with this name already exists |
386 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
386 | + if (user_can($new_teacher_id, 'manage_options')) { |
|
387 | 387 | |
388 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
389 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
390 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
391 | - if( !empty( $existing_admin_terms ) ){ |
|
388 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim($term->name)); |
|
389 | + $term_args = array('slug'=> $slug_without_teacher_id, 'hide_empty' => false,); |
|
390 | + $existing_admin_terms = get_terms('module', $term_args); |
|
391 | + if ( ! empty($existing_admin_terms)) { |
|
392 | 392 | // insert it even if it exists |
393 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
393 | + $new_term = get_term($existing_admin_terms[0]->term_id, 'module', ARRAY_A); |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
397 | - if( empty ( $new_term ) ){ |
|
397 | + if (empty ($new_term)) { |
|
398 | 398 | |
399 | 399 | //setup the new slug |
400 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
400 | + $new_author_term_slug = $new_teacher_id.'-'.str_ireplace(' ', '-', trim($term->name)); |
|
401 | 401 | |
402 | 402 | // create new term and set it |
403 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
403 | + $new_term = wp_insert_term($term->name, 'module', array('slug'=> $new_author_term_slug)); |
|
404 | 404 | |
405 | 405 | } |
406 | 406 | |
407 | 407 | |
408 | 408 | |
409 | 409 | // if term exists |
410 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
410 | + if (is_wp_error($new_term) && isset($new_term->errors['term_exists'])) { |
|
411 | 411 | |
412 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
412 | + $existing_term = get_term_by('slug', $new_author_term_slug, 'module'); |
|
413 | 413 | $term_id = $existing_term->term_id; |
414 | 414 | |
415 | - }else{ |
|
415 | + } else { |
|
416 | 416 | |
417 | 417 | // for a new term simply get the term from the returned value |
418 | 418 | $term_id = $new_term['term_id']; |
@@ -420,21 +420,21 @@ discard block |
||
420 | 420 | } // end if term exist |
421 | 421 | |
422 | 422 | // set the terms selected on the course |
423 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
423 | + wp_set_object_terms($course_id, $term_id, 'module', true); |
|
424 | 424 | |
425 | 425 | // remove old term |
426 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
426 | + wp_remove_object_terms($course_id, $term->term_id, 'module'); |
|
427 | 427 | |
428 | 428 | // update the lessons within the current module term |
429 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
430 | - foreach( $lessons as $lesson ){ |
|
429 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
430 | + foreach ($lessons as $lesson) { |
|
431 | 431 | |
432 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
432 | + if (has_term($term->slug, 'module', $lesson)) { |
|
433 | 433 | |
434 | 434 | // add the new term, the false at the end says to replace all terms on this module |
435 | 435 | // with the new term. |
436 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
437 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
436 | + wp_set_object_terms($lesson->ID, $term_id, 'module', false); |
|
437 | + update_post_meta($lesson->ID, '_order_module_'.intval($term_id), 0); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | }// end for each |
@@ -454,50 +454,50 @@ discard block |
||
454 | 454 | * @parameters |
455 | 455 | * @return array $users user id array |
456 | 456 | */ |
457 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
457 | + public function update_course_lessons_author($course_id, $new_author) { |
|
458 | 458 | |
459 | 459 | |
460 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
460 | + if (empty($course_id) || empty($new_author)) { |
|
461 | 461 | return false; |
462 | 462 | } |
463 | 463 | |
464 | 464 | //get a list of course lessons |
465 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
465 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
466 | 466 | |
467 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
467 | + if (empty($lessons) || ! is_array($lessons)) { |
|
468 | 468 | return false; |
469 | 469 | } |
470 | 470 | |
471 | 471 | // update each lesson and quiz author |
472 | - foreach( $lessons as $lesson ){ |
|
472 | + foreach ($lessons as $lesson) { |
|
473 | 473 | |
474 | 474 | // don't update if the author is tha same as the new author |
475 | - if( $new_author == $lesson->post_author ){ |
|
475 | + if ($new_author == $lesson->post_author) { |
|
476 | 476 | continue; |
477 | 477 | } |
478 | 478 | |
479 | 479 | // update lesson author |
480 | - wp_update_post( array( |
|
480 | + wp_update_post(array( |
|
481 | 481 | 'ID'=> $lesson->ID, |
482 | 482 | 'post_author' => $new_author |
483 | - ) ); |
|
483 | + )); |
|
484 | 484 | |
485 | 485 | // update quiz author |
486 | 486 | //get the lessons quiz |
487 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
488 | - if( is_array( $lesson_quizzes ) ){ |
|
489 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
487 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
488 | + if (is_array($lesson_quizzes)) { |
|
489 | + foreach ($lesson_quizzes as $quiz_id) { |
|
490 | 490 | // update quiz with new author |
491 | - wp_update_post( array( |
|
491 | + wp_update_post(array( |
|
492 | 492 | 'ID' => $quiz_id, |
493 | 493 | 'post_author' => $new_author |
494 | - ) ); |
|
494 | + )); |
|
495 | 495 | } |
496 | - }else{ |
|
497 | - wp_update_post( array( |
|
496 | + } else { |
|
497 | + wp_update_post(array( |
|
498 | 498 | 'ID' => $lesson_quizzes, |
499 | 499 | 'post_author' => $new_author |
500 | - ) ); |
|
500 | + )); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | } // end for each lessons |
@@ -518,30 +518,30 @@ discard block |
||
518 | 518 | * @parameters $query |
519 | 519 | * @return array $users user id array |
520 | 520 | */ |
521 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
521 | + public function course_analysis_teacher_access_limit($query) { |
|
522 | 522 | |
523 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
523 | + if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
524 | 524 | return $query; |
525 | 525 | } |
526 | 526 | |
527 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
527 | + if ( ! function_exists('get_current_screen')) { |
|
528 | 528 | return $query; |
529 | 529 | } |
530 | 530 | |
531 | 531 | $screen = get_current_screen(); |
532 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
532 | + $sensei_post_types = array('course', 'lesson', 'question'); |
|
533 | 533 | |
534 | 534 | // exit early for the following conditions |
535 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
535 | + $limit_screen_ids = array('sensei_page_sensei_analysis', 'course_page_module-order'); |
|
536 | 536 | |
537 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
538 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
537 | + if ( ! $this->is_admin_teacher() || empty($screen) || ! in_array($screen->id, $limit_screen_ids) |
|
538 | + || ! in_array($query->query['post_type'], $sensei_post_types)) { |
|
539 | 539 | return $query; |
540 | 540 | } |
541 | 541 | |
542 | 542 | global $current_user; |
543 | 543 | // set the query author to the current user to only show those those posts |
544 | - $query->set( 'author', $current_user->ID ); |
|
544 | + $query->set('author', $current_user->ID); |
|
545 | 545 | return $query; |
546 | 546 | |
547 | 547 | }// end course_analysis_teacher_access_limit |
@@ -557,14 +557,14 @@ discard block |
||
557 | 557 | * @parameters array $wp_query |
558 | 558 | * @return bool $is_admin_teacher |
559 | 559 | */ |
560 | - public function is_admin_teacher ( ){ |
|
560 | + public function is_admin_teacher( ) { |
|
561 | 561 | |
562 | - if( ! is_user_logged_in()){ |
|
562 | + if ( ! is_user_logged_in()) { |
|
563 | 563 | return false; |
564 | 564 | } |
565 | 565 | $is_admin_teacher = false; |
566 | 566 | |
567 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
567 | + if (is_admin() && Sensei_Teacher::is_a_teacher(get_current_user_id())) { |
|
568 | 568 | |
569 | 569 | $is_admin_teacher = true; |
570 | 570 | |
@@ -584,14 +584,14 @@ discard block |
||
584 | 584 | * @param string $perm User permission level |
585 | 585 | * @return object Modified status counts |
586 | 586 | */ |
587 | - public function list_table_counts( $counts, $type, $perm ) { |
|
587 | + public function list_table_counts($counts, $type, $perm) { |
|
588 | 588 | global $current_user; |
589 | 589 | |
590 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
590 | + if ( ! in_array($type, array('course', 'lesson', 'question'))) { |
|
591 | 591 | return $counts; |
592 | 592 | } |
593 | 593 | |
594 | - if( ! $this->is_admin_teacher() ) { |
|
594 | + if ( ! $this->is_admin_teacher()) { |
|
595 | 595 | return $counts; |
596 | 596 | } |
597 | 597 | |
@@ -605,10 +605,10 @@ discard block |
||
605 | 605 | $stati = get_post_stati(); |
606 | 606 | |
607 | 607 | // Update count object |
608 | - foreach( $stati as $status ) { |
|
608 | + foreach ($stati as $status) { |
|
609 | 609 | $args['post_status'] = $status; |
610 | - $posts = get_posts( $args ); |
|
611 | - $counts->$status = count( $posts ); |
|
610 | + $posts = get_posts($args); |
|
611 | + $counts->$status = count($posts); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | return $counts; |
@@ -622,22 +622,22 @@ discard block |
||
622 | 622 | * @since 1.8.0 |
623 | 623 | * |
624 | 624 | */ |
625 | - public function filter_queries ( $query ) { |
|
625 | + public function filter_queries($query) { |
|
626 | 626 | global $current_user; |
627 | 627 | |
628 | - if( ! $this->is_admin_teacher() ) { |
|
628 | + if ( ! $this->is_admin_teacher()) { |
|
629 | 629 | return; |
630 | 630 | } |
631 | 631 | |
632 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
632 | + if ( ! function_exists('get_current_screen')) { |
|
633 | 633 | return; |
634 | 634 | } |
635 | 635 | |
636 | 636 | $screen = get_current_screen(); |
637 | - if( empty( $screen ) ) { |
|
637 | + if (empty($screen)) { |
|
638 | 638 | return $query; |
639 | 639 | } |
640 | - switch( $screen->id ) { |
|
640 | + switch ($screen->id) { |
|
641 | 641 | case 'sensei_page_sensei_grading': |
642 | 642 | case 'sensei_page_sensei_analysis': |
643 | 643 | case 'sensei_page_sensei_learners': |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | * @param string $screen_id |
657 | 657 | * |
658 | 658 | */ |
659 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
659 | + $query->set('author', apply_filters('sensei_filter_queries_set_author', $current_user->ID, $screen->id)); |
|
660 | 660 | break; |
661 | 661 | } |
662 | 662 | } |
@@ -671,31 +671,31 @@ discard block |
||
671 | 671 | * |
672 | 672 | * @return array $comments |
673 | 673 | */ |
674 | - public function filter_grading_activity_queries( $comments ){ |
|
674 | + public function filter_grading_activity_queries($comments) { |
|
675 | 675 | |
676 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
677 | - return $comments ; |
|
676 | + if ( ! is_admin() || ! $this->is_admin_teacher() || is_numeric($comments) || ! is_array($comments)) { |
|
677 | + return $comments; |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | //check if we're on the grading screen |
681 | 681 | $screen = get_current_screen(); |
682 | 682 | |
683 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
683 | + if (empty($screen) || 'sensei_page_sensei_grading' != $screen->id) { |
|
684 | 684 | return $comments; |
685 | 685 | } |
686 | 686 | |
687 | 687 | // get the course and determine if the current teacher is the owner |
688 | 688 | // if not remove it from the list of comments to be returned |
689 | - foreach( $comments as $key => $comment){ |
|
690 | - $lesson = get_post( $comment->comment_post_ID ); |
|
691 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
692 | - $course = get_post( $course_id ); |
|
693 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
689 | + foreach ($comments as $key => $comment) { |
|
690 | + $lesson = get_post($comment->comment_post_ID); |
|
691 | + $course_id = Sensei()->lesson->get_course_id($lesson->ID); |
|
692 | + $course = get_post($course_id); |
|
693 | + if ( ! isset($course->post_author) || intval($course->post_author) != intval(get_current_user_id())) { |
|
694 | 694 | //remove this as the teacher should see this. |
695 | - unset( $comments[ $key ] ); |
|
695 | + unset($comments[$key]); |
|
696 | 696 | } |
697 | 697 | } |
698 | - return $comments ; |
|
698 | + return $comments; |
|
699 | 699 | |
700 | 700 | }// end function filter grading |
701 | 701 | |
@@ -711,34 +711,34 @@ discard block |
||
711 | 711 | * |
712 | 712 | * @return array $args |
713 | 713 | */ |
714 | - public function limit_grading_totals( $args ){ |
|
714 | + public function limit_grading_totals($args) { |
|
715 | 715 | |
716 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
717 | - return $args ; |
|
716 | + if ( ! is_admin() || ! $this->is_admin_teacher() || ! is_array($args)) { |
|
717 | + return $args; |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | //get the teachers courses |
721 | 721 | // the query is already filtered to only the teacher |
722 | - $courses = Sensei()->course->get_all_courses(); |
|
722 | + $courses = Sensei()->course->get_all_courses(); |
|
723 | 723 | |
724 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
724 | + if (empty($courses) || ! is_array($courses)) { |
|
725 | 725 | return $args; |
726 | 726 | } |
727 | 727 | |
728 | 728 | //setup the lessons quizzes to limit the grading totals to |
729 | 729 | $quiz_scope = array(); |
730 | - foreach( $courses as $course ){ |
|
730 | + foreach ($courses as $course) { |
|
731 | 731 | |
732 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
732 | + $course_lessons = Sensei()->course->course_lessons($course->ID); |
|
733 | 733 | |
734 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
734 | + if ( ! empty($course_lessons) && is_array($course_lessons)) { |
|
735 | 735 | |
736 | - foreach( $course_lessons as $lesson ){ |
|
736 | + foreach ($course_lessons as $lesson) { |
|
737 | 737 | |
738 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
739 | - if( !empty( $quiz_id ) ) { |
|
738 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
739 | + if ( ! empty($quiz_id)) { |
|
740 | 740 | |
741 | - array_push( $quiz_scope, $quiz_id ); |
|
741 | + array_push($quiz_scope, $quiz_id); |
|
742 | 742 | |
743 | 743 | } |
744 | 744 | |
@@ -761,41 +761,41 @@ discard block |
||
761 | 761 | * @param WP_Query $query |
762 | 762 | * @return WP_Query $query |
763 | 763 | */ |
764 | - public function add_courses_to_author_archive( $query ) { |
|
764 | + public function add_courses_to_author_archive($query) { |
|
765 | 765 | |
766 | - if ( is_admin() || ! $query->is_author() ){ |
|
766 | + if (is_admin() || ! $query->is_author()) { |
|
767 | 767 | return $query; |
768 | 768 | } |
769 | 769 | |
770 | 770 | // this should only apply to users with the teacher role |
771 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
772 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
771 | + $current_page_user = get_user_by('login', $query->get('author_name')); |
|
772 | + if ( ! $current_page_user || ! in_array('teacher', $current_page_user->roles)) { |
|
773 | 773 | |
774 | 774 | return $query; |
775 | 775 | |
776 | 776 | } |
777 | 777 | |
778 | 778 | // Change post types depending on what is set already |
779 | - $current_post_types = $query->get( 'post_type' ); |
|
780 | - if( empty( $current_post_types ) ){ |
|
779 | + $current_post_types = $query->get('post_type'); |
|
780 | + if (empty($current_post_types)) { |
|
781 | 781 | |
782 | 782 | // if empty it means post by default, so add post so that it also includes that for now |
783 | - $new_post_types = array( 'post', 'course' ); |
|
783 | + $new_post_types = array('post', 'course'); |
|
784 | 784 | |
785 | - } elseif( is_array( $current_post_types ) ) { |
|
785 | + } elseif (is_array($current_post_types)) { |
|
786 | 786 | |
787 | 787 | // merge the post types instead of overwriting it |
788 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
788 | + $new_post_types = array_merge($current_post_types, array('course')); |
|
789 | 789 | |
790 | - }else{ |
|
790 | + } else { |
|
791 | 791 | |
792 | 792 | // in this instance it is probably just one post type in string format |
793 | - $new_post_types = array( $current_post_types , 'course'); |
|
793 | + $new_post_types = array($current_post_types, 'course'); |
|
794 | 794 | |
795 | 795 | } |
796 | 796 | |
797 | 797 | // change the query before returning it |
798 | - $query->set('post_type', $new_post_types ); |
|
798 | + $query->set('post_type', $new_post_types); |
|
799 | 799 | |
800 | 800 | /** |
801 | 801 | * Change the query on the teacher author archive template |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | * @since 1.8.4 |
804 | 804 | * @param WP_Query $query |
805 | 805 | */ |
806 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
806 | + return apply_filters('sensei_teacher_archive_query', $query); |
|
807 | 807 | |
808 | 808 | } |
809 | 809 | |
@@ -816,21 +816,21 @@ discard block |
||
816 | 816 | * @param $course_id |
817 | 817 | * @return bool |
818 | 818 | */ |
819 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
819 | + public function teacher_course_assigned_notification($teacher_id, $course_id) { |
|
820 | 820 | |
821 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
821 | + if ('course' != get_post_type($course_id) || ! get_userdata($teacher_id)) { |
|
822 | 822 | return false; |
823 | 823 | } |
824 | 824 | |
825 | 825 | // if new user is the same as the current logged user, they don't need an email |
826 | - if( $teacher_id == get_current_user_id() ){ |
|
826 | + if ($teacher_id == get_current_user_id()) { |
|
827 | 827 | return true; |
828 | 828 | } |
829 | 829 | |
830 | 830 | // load the email class |
831 | 831 | include('emails/class-sensei-email-teacher-new-course-assignment.php'); |
832 | 832 | $email = new Sensei_Email_Teacher_New_Course_Assignment(); |
833 | - $email->trigger( $teacher_id, $course_id ); |
|
833 | + $email->trigger($teacher_id, $course_id); |
|
834 | 834 | |
835 | 835 | return true; |
836 | 836 | } // end teacher_course_assigned_notification |
@@ -844,12 +844,12 @@ discard block |
||
844 | 844 | * @param int $course_id |
845 | 845 | * @return bool |
846 | 846 | */ |
847 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
847 | + public function notify_admin_teacher_course_creation($new_status, $old_status, $post) { |
|
848 | 848 | |
849 | 849 | $course_id = $post->ID; |
850 | 850 | |
851 | - if( 'publish'== $old_status || 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
852 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
851 | + if ('publish' == $old_status || 'course' != get_post_type($course_id) || 'auto-draft' == get_post_status($course_id) |
|
852 | + || 'trash' == get_post_status($course_id) || 'draft' == get_post_status($course_id)) { |
|
853 | 853 | |
854 | 854 | return false; |
855 | 855 | |
@@ -863,19 +863,19 @@ discard block |
||
863 | 863 | * |
864 | 864 | * @param bool $on default true |
865 | 865 | */ |
866 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
866 | + if ( ! apply_filters('sensei_notify_admin_new_course_creation', true)) { |
|
867 | 867 | return false; |
868 | 868 | } |
869 | 869 | |
870 | 870 | // setting up the data needed by the email template |
871 | 871 | global $sensei_email_data; |
872 | 872 | $template = 'admin-teacher-new-course-created'; |
873 | - $course = get_post( $course_id ); |
|
874 | - $teacher = new WP_User( $course->post_author ); |
|
873 | + $course = get_post($course_id); |
|
874 | + $teacher = new WP_User($course->post_author); |
|
875 | 875 | $recipient = get_option('admin_email', true); |
876 | 876 | |
877 | 877 | // don't send if the course is created by admin |
878 | - if( $recipient == $teacher->user_email || current_user_can( 'manage_options' )){ |
|
878 | + if ($recipient == $teacher->user_email || current_user_can('manage_options')) { |
|
879 | 879 | return false; |
880 | 880 | } |
881 | 881 | |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | * @since 1.8.0 |
886 | 886 | * @param string $template |
887 | 887 | */ |
888 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
888 | + $heading = apply_filters('sensei_email_heading', __('New course created.', 'woothemes-sensei'), $template); |
|
889 | 889 | |
890 | 890 | /** |
891 | 891 | * Filter the email subject for the the |
@@ -896,11 +896,11 @@ discard block |
||
896 | 896 | * @param string $template |
897 | 897 | */ |
898 | 898 | $subject = apply_filters('sensei_email_subject', |
899 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
900 | - $template ); |
|
899 | + '['.get_bloginfo('name', 'display').'] '.__('New course created by', 'woothemes-sensei').' '.$teacher->display_name, |
|
900 | + $template); |
|
901 | 901 | |
902 | 902 | //course edit link |
903 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
903 | + $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit'); |
|
904 | 904 | |
905 | 905 | // Construct data array |
906 | 906 | $email_data = array( |
@@ -919,10 +919,10 @@ discard block |
||
919 | 919 | * @param array $email_data |
920 | 920 | * @param string $template |
921 | 921 | */ |
922 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
922 | + $sensei_email_data = apply_filters('sensei_email_data', $email_data, $template); |
|
923 | 923 | |
924 | 924 | // Send mail |
925 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
925 | + Sensei()->emails->send($recipient, $subject, Sensei()->emails->get_content($template)); |
|
926 | 926 | |
927 | 927 | }// end notify admin of course creation |
928 | 928 | |
@@ -933,10 +933,10 @@ discard block |
||
933 | 933 | * @param array $args WP_User_Query arguments |
934 | 934 | * @return array $learners_query_results |
935 | 935 | */ |
936 | - public function limit_analysis_learners( $args ){ |
|
936 | + public function limit_analysis_learners($args) { |
|
937 | 937 | |
938 | 938 | // show default for none teachers |
939 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
939 | + if ( ! Sensei()->teacher->is_admin_teacher()) { |
|
940 | 940 | return $args; |
941 | 941 | } |
942 | 942 | |
@@ -945,31 +945,31 @@ discard block |
||
945 | 945 | $teacher_courses = Sensei()->course->get_all_courses(); |
946 | 946 | |
947 | 947 | // if the user has no courses they should see no users |
948 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
948 | + if (empty($teacher_courses) || ! is_array($teacher_courses)) { |
|
949 | 949 | // tell the query to return 0 students |
950 | - $args[ 'include'] = array( 0 ); |
|
950 | + $args['include'] = array(0); |
|
951 | 951 | return $args; |
952 | 952 | |
953 | 953 | } |
954 | 954 | |
955 | 955 | $learner_ids_for_teacher_courses = array(); |
956 | - foreach( $teacher_courses as $course ){ |
|
956 | + foreach ($teacher_courses as $course) { |
|
957 | 957 | |
958 | 958 | $course_learner_ids = array(); |
959 | - $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
959 | + $activity_comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id'), true); |
|
960 | 960 | |
961 | - if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
961 | + if (empty($activity_comments) || (is_array($activity_comments) && ! (count($activity_comments) > 0))) { |
|
962 | 962 | continue; // skip to the next course as there are no users on this course |
963 | 963 | } |
964 | 964 | |
965 | 965 | // it could be an array of comments or a single comment |
966 | - if( is_array( $activity_comments ) ){ |
|
966 | + if (is_array($activity_comments)) { |
|
967 | 967 | |
968 | - foreach( $activity_comments as $comment ){ |
|
968 | + foreach ($activity_comments as $comment) { |
|
969 | 969 | |
970 | - $user = get_userdata( $comment->user_id ); |
|
970 | + $user = get_userdata($comment->user_id); |
|
971 | 971 | |
972 | - if( empty( $user ) ){ |
|
972 | + if (empty($user)) { |
|
973 | 973 | // next comment in this array |
974 | 974 | continue; |
975 | 975 | } |
@@ -977,26 +977,26 @@ discard block |
||
977 | 977 | $course_learner_ids[] = $user->ID; |
978 | 978 | } |
979 | 979 | |
980 | - }else{ |
|
980 | + } else { |
|
981 | 981 | |
982 | - $user = get_userdata( $activity_comments->user_id ); |
|
982 | + $user = get_userdata($activity_comments->user_id); |
|
983 | 983 | $course_learner_ids[] = $user->ID; |
984 | 984 | |
985 | 985 | } |
986 | 986 | |
987 | 987 | // add learners on this course to the all courses learner list |
988 | - $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
988 | + $learner_ids_for_teacher_courses = array_merge($learner_ids_for_teacher_courses, $course_learner_ids); |
|
989 | 989 | |
990 | 990 | } |
991 | 991 | |
992 | 992 | // if there are no students taking the courses by this teacher don't show them any of the other users |
993 | - if( empty( $learner_ids_for_teacher_courses ) ){ |
|
993 | + if (empty($learner_ids_for_teacher_courses)) { |
|
994 | 994 | |
995 | - $args[ 'include'] = array( 0 ); |
|
995 | + $args['include'] = array(0); |
|
996 | 996 | |
997 | - }else{ |
|
997 | + } else { |
|
998 | 998 | |
999 | - $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
999 | + $args['include'] = $learner_ids_for_teacher_courses; |
|
1000 | 1000 | |
1001 | 1001 | } |
1002 | 1002 | |
@@ -1013,35 +1013,35 @@ discard block |
||
1013 | 1013 | * @param $questions |
1014 | 1014 | * @return mixed |
1015 | 1015 | */ |
1016 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
1016 | + public function allow_teacher_access_to_questions($questions, $quiz_id) { |
|
1017 | 1017 | |
1018 | - if( ! $this->is_admin_teacher() ){ |
|
1018 | + if ( ! $this->is_admin_teacher()) { |
|
1019 | 1019 | return $questions; |
1020 | 1020 | } |
1021 | 1021 | |
1022 | 1022 | $screen = get_current_screen(); |
1023 | 1023 | |
1024 | 1024 | // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
1025 | - remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
1025 | + remove_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20); |
|
1026 | 1026 | |
1027 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
1027 | + if ( ! empty($screen) && 'lesson' == $screen->post_type) { |
|
1028 | 1028 | |
1029 | 1029 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
1030 | - if( ! empty($admin_user) ){ |
|
1030 | + if ( ! empty($admin_user)) { |
|
1031 | 1031 | |
1032 | 1032 | $current_teacher_id = get_current_user_id(); |
1033 | 1033 | |
1034 | 1034 | // set current user to admin so teacher can view all questions |
1035 | - wp_set_current_user( $admin_user->ID ); |
|
1036 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
1035 | + wp_set_current_user($admin_user->ID); |
|
1036 | + $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id); |
|
1037 | 1037 | |
1038 | 1038 | // set the teacher as the current use again |
1039 | - wp_set_current_user( $current_teacher_id ); |
|
1039 | + wp_set_current_user($current_teacher_id); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | } |
1043 | 1043 | // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
1044 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
1044 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
1045 | 1045 | |
1046 | 1046 | return $questions; |
1047 | 1047 | } |
@@ -1053,30 +1053,30 @@ discard block |
||
1053 | 1053 | * @param $wp_query |
1054 | 1054 | * @return mixed |
1055 | 1055 | */ |
1056 | - public function give_access_to_all_questions( $wp_query ){ |
|
1056 | + public function give_access_to_all_questions($wp_query) { |
|
1057 | 1057 | |
1058 | - if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
1058 | + if ( ! $this->is_admin_teacher() || ! function_exists('get_current_screen') || 'question' != $wp_query->get('post_type')) { |
|
1059 | 1059 | |
1060 | 1060 | return $wp_query; |
1061 | 1061 | } |
1062 | 1062 | |
1063 | 1063 | $screen = get_current_screen(); |
1064 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
1065 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
1064 | + if ((isset($screen->id) && 'lesson' == $screen->id) |
|
1065 | + || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
1066 | 1066 | |
1067 | 1067 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
1068 | - if( ! empty($admin_user) ){ |
|
1068 | + if ( ! empty($admin_user)) { |
|
1069 | 1069 | |
1070 | 1070 | $current_teacher_id = get_current_user_id(); |
1071 | 1071 | |
1072 | 1072 | // set current user to admin so teacher can view all questions |
1073 | - wp_set_current_user( $admin_user->ID ); |
|
1073 | + wp_set_current_user($admin_user->ID); |
|
1074 | 1074 | |
1075 | 1075 | //run new query as admin |
1076 | - $wp_query = new WP_Query( $wp_query->query ); |
|
1076 | + $wp_query = new WP_Query($wp_query->query); |
|
1077 | 1077 | |
1078 | 1078 | //set the teache as current use again |
1079 | - wp_set_current_user( $current_teacher_id ); |
|
1079 | + wp_set_current_user($current_teacher_id); |
|
1080 | 1080 | |
1081 | 1081 | } |
1082 | 1082 | } |
@@ -1093,7 +1093,7 @@ discard block |
||
1093 | 1093 | */ |
1094 | 1094 | public function course_column_heading($columns) { |
1095 | 1095 | |
1096 | - if( $this->is_admin_teacher() ){ |
|
1096 | + if ($this->is_admin_teacher()) { |
|
1097 | 1097 | return $columns; |
1098 | 1098 | } |
1099 | 1099 | $new_columns = array( |
@@ -1110,20 +1110,20 @@ discard block |
||
1110 | 1110 | * @param $column |
1111 | 1111 | * @param $course_id |
1112 | 1112 | */ |
1113 | - public function course_column_data( $column, $course_id ){ |
|
1113 | + public function course_column_data($column, $course_id) { |
|
1114 | 1114 | |
1115 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
1115 | + if ($this->is_admin_teacher() || 'teacher' != $column) { |
|
1116 | 1116 | return; |
1117 | 1117 | } |
1118 | 1118 | |
1119 | - $course = get_post( $course_id ); |
|
1120 | - $teacher = get_userdata( $course->post_author ); |
|
1119 | + $course = get_post($course_id); |
|
1120 | + $teacher = get_userdata($course->post_author); |
|
1121 | 1121 | |
1122 | - if( !$teacher ){ |
|
1122 | + if ( ! $teacher) { |
|
1123 | 1123 | return; |
1124 | 1124 | } |
1125 | 1125 | |
1126 | - echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
1126 | + echo '<a href="'.get_edit_user_link($teacher->ID).'" >'.$teacher->display_name.'</a>'; |
|
1127 | 1127 | |
1128 | 1128 | }// end course_column_ data |
1129 | 1129 | |
@@ -1138,31 +1138,31 @@ discard block |
||
1138 | 1138 | * |
1139 | 1139 | * @return array $teachers_courses |
1140 | 1140 | */ |
1141 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
1141 | + public function get_teacher_courses($teacher_id, $return_ids_only = false) { |
|
1142 | 1142 | |
1143 | 1143 | $teachers_courses = array(); |
1144 | 1144 | |
1145 | - if( empty( $teacher_id ) ){ |
|
1145 | + if (empty($teacher_id)) { |
|
1146 | 1146 | $teacher_id = get_current_user_id(); |
1147 | 1147 | } |
1148 | 1148 | |
1149 | 1149 | $all_courses = Sensei()->course->get_all_courses(); |
1150 | 1150 | |
1151 | - if( empty( $all_courses ) ){ |
|
1151 | + if (empty($all_courses)) { |
|
1152 | 1152 | return $all_courses; |
1153 | 1153 | } |
1154 | 1154 | |
1155 | - foreach( $all_courses as $course ){ |
|
1155 | + foreach ($all_courses as $course) { |
|
1156 | 1156 | |
1157 | - if( $course->post_author != $teacher_id ){ |
|
1157 | + if ($course->post_author != $teacher_id) { |
|
1158 | 1158 | continue; |
1159 | 1159 | } |
1160 | 1160 | |
1161 | - if( $return_ids_only ){ |
|
1161 | + if ($return_ids_only) { |
|
1162 | 1162 | |
1163 | 1163 | $teachers_courses[] = $course->ID; |
1164 | 1164 | |
1165 | - }else{ |
|
1165 | + } else { |
|
1166 | 1166 | |
1167 | 1167 | $teachers_courses[] = $course; |
1168 | 1168 | |
@@ -1182,21 +1182,21 @@ discard block |
||
1182 | 1182 | * @param $query |
1183 | 1183 | * @return mixed |
1184 | 1184 | */ |
1185 | - public function limit_edit_messages_query( $query ){ |
|
1186 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
1185 | + public function limit_edit_messages_query($query) { |
|
1186 | + if ( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type')) { |
|
1187 | 1187 | return $query; |
1188 | 1188 | } |
1189 | 1189 | |
1190 | 1190 | $teacher = wp_get_current_user(); |
1191 | 1191 | |
1192 | - $query->set( 'meta_key', '_receiver' ); |
|
1192 | + $query->set('meta_key', '_receiver'); |
|
1193 | 1193 | $meta_query_args = array( |
1194 | 1194 | 'key' => '_receiver', |
1195 | - 'value' => $teacher->get('user_login') , |
|
1195 | + 'value' => $teacher->get('user_login'), |
|
1196 | 1196 | 'compare' => '=' |
1197 | 1197 | ); |
1198 | 1198 | |
1199 | - $query->set('meta_query', $meta_query_args ); |
|
1199 | + $query->set('meta_query', $meta_query_args); |
|
1200 | 1200 | |
1201 | 1201 | return $query; |
1202 | 1202 | } |
@@ -1212,7 +1212,7 @@ discard block |
||
1212 | 1212 | public function course_teacher_filter_options() { |
1213 | 1213 | global $typenow; |
1214 | 1214 | |
1215 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
1215 | + if ( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
1216 | 1216 | return; |
1217 | 1217 | } |
1218 | 1218 | |
@@ -1222,31 +1222,31 @@ discard block |
||
1222 | 1222 | // get roles with the course edit capability |
1223 | 1223 | // and then get the users with those roles |
1224 | 1224 | $users_who_can_edit_courses = array(); |
1225 | - foreach( $roles as $role_item ){ |
|
1225 | + foreach ($roles as $role_item) { |
|
1226 | 1226 | |
1227 | - $role = get_role( strtolower( $role_item['name'] ) ); |
|
1227 | + $role = get_role(strtolower($role_item['name'])); |
|
1228 | 1228 | |
1229 | - if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
1229 | + if (is_a($role, 'WP_Role') && $role->has_cap('edit_courses')) { |
|
1230 | 1230 | |
1231 | - $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
1232 | - $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
1231 | + $user_query_args = array('role' => $role->name, 'fields' => array('ID', 'display_name')); |
|
1232 | + $role_users_who_can_edit_courses = get_users($user_query_args); |
|
1233 | 1233 | |
1234 | 1234 | // add user from the current $user_role to all users |
1235 | - $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
1235 | + $users_who_can_edit_courses = array_merge($users_who_can_edit_courses, $role_users_who_can_edit_courses); |
|
1236 | 1236 | |
1237 | 1237 | } |
1238 | 1238 | |
1239 | 1239 | } |
1240 | 1240 | |
1241 | 1241 | // Create the select element with the given users who can edit course |
1242 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
1242 | + $selected = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
1243 | 1243 | $course_options = ''; |
1244 | - foreach( $users_who_can_edit_courses as $user ) { |
|
1245 | - $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
1244 | + foreach ($users_who_can_edit_courses as $user) { |
|
1245 | + $course_options .= '<option value="'.esc_attr($user->ID).'" '.selected($selected, $user->ID, false).'>'.$user->display_name.'</option>'; |
|
1246 | 1246 | } |
1247 | 1247 | |
1248 | 1248 | $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
1249 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
1249 | + $output .= '<option value="">'.__('Show all teachers', 'woothemes-sensei').'</option>'; |
|
1250 | 1250 | $output .= $course_options; |
1251 | 1251 | $output .= '</select>'; |
1252 | 1252 | |
@@ -1261,15 +1261,15 @@ discard block |
||
1261 | 1261 | * @param $query |
1262 | 1262 | * @return $query |
1263 | 1263 | */ |
1264 | - public function teacher_filter_query_modify( $query ){ |
|
1264 | + public function teacher_filter_query_modify($query) { |
|
1265 | 1265 | global $typenow; |
1266 | 1266 | |
1267 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
1267 | + if ( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
1268 | 1268 | return $query; |
1269 | 1269 | } |
1270 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
1270 | + $course_teacher = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
1271 | 1271 | |
1272 | - if( empty( $course_teacher ) ) { |
|
1272 | + if (empty($course_teacher)) { |
|
1273 | 1273 | return $query; |
1274 | 1274 | } |
1275 | 1275 | |
@@ -1282,23 +1282,23 @@ discard block |
||
1282 | 1282 | * @param array $request Default request arguments |
1283 | 1283 | * @return array Modified request arguments |
1284 | 1284 | */ |
1285 | - public function restrict_media_library( $request = array() ) { |
|
1285 | + public function restrict_media_library($request = array()) { |
|
1286 | 1286 | |
1287 | - if( ! is_admin() ) { |
|
1287 | + if ( ! is_admin()) { |
|
1288 | 1288 | return $request; |
1289 | 1289 | } |
1290 | 1290 | |
1291 | - if( ! $this->is_admin_teacher() ) { |
|
1291 | + if ( ! $this->is_admin_teacher()) { |
|
1292 | 1292 | return $request; |
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 | $screen = get_current_screen(); |
1296 | 1296 | |
1297 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
1298 | - $teacher = intval( get_current_user_id() ); |
|
1297 | + if (in_array($screen->id, array('upload', 'course', 'lesson', 'question'))) { |
|
1298 | + $teacher = intval(get_current_user_id()); |
|
1299 | 1299 | |
1300 | - if( $teacher ) { |
|
1301 | - $request['author__in'] = array( $teacher ); |
|
1300 | + if ($teacher) { |
|
1301 | + $request['author__in'] = array($teacher); |
|
1302 | 1302 | } |
1303 | 1303 | } |
1304 | 1304 | |
@@ -1310,20 +1310,20 @@ discard block |
||
1310 | 1310 | * @param array $query Default query arguments |
1311 | 1311 | * @return array Modified query arguments |
1312 | 1312 | */ |
1313 | - public function restrict_media_library_modal( $query = array() ) { |
|
1313 | + public function restrict_media_library_modal($query = array()) { |
|
1314 | 1314 | |
1315 | - if( ! is_admin() ) { |
|
1315 | + if ( ! is_admin()) { |
|
1316 | 1316 | return $query; |
1317 | 1317 | } |
1318 | 1318 | |
1319 | - if( ! $this->is_admin_teacher() ) { |
|
1319 | + if ( ! $this->is_admin_teacher()) { |
|
1320 | 1320 | return $query; |
1321 | 1321 | } |
1322 | 1322 | |
1323 | - $teacher = intval( get_current_user_id() ); |
|
1323 | + $teacher = intval(get_current_user_id()); |
|
1324 | 1324 | |
1325 | - if( $teacher ) { |
|
1326 | - $query['author__in'] = array( $teacher ); |
|
1325 | + if ($teacher) { |
|
1326 | + $query['author__in'] = array($teacher); |
|
1327 | 1327 | } |
1328 | 1328 | |
1329 | 1329 | return $query; |
@@ -1336,28 +1336,28 @@ discard block |
||
1336 | 1336 | * |
1337 | 1337 | * @param int $lesson_id |
1338 | 1338 | */ |
1339 | - public function update_lesson_teacher( $lesson_id ){ |
|
1339 | + public function update_lesson_teacher($lesson_id) { |
|
1340 | 1340 | |
1341 | - if( 'lesson'!= get_post_type() ){ |
|
1341 | + if ('lesson' != get_post_type()) { |
|
1342 | 1342 | return; |
1343 | 1343 | } |
1344 | 1344 | |
1345 | 1345 | // this should only run once per request cycle |
1346 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
1346 | + remove_action('save_post', array($this, 'update_lesson_teacher')); |
|
1347 | 1347 | |
1348 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
1348 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
1349 | 1349 | |
1350 | - if( empty( $course_id ) || ! $course_id ){ |
|
1350 | + if (empty($course_id) || ! $course_id) { |
|
1351 | 1351 | return; |
1352 | 1352 | } |
1353 | 1353 | |
1354 | - $course = get_post( $course_id ); |
|
1354 | + $course = get_post($course_id); |
|
1355 | 1355 | |
1356 | - $lesson_update_args= array( |
|
1357 | - 'ID' => $lesson_id , |
|
1356 | + $lesson_update_args = array( |
|
1357 | + 'ID' => $lesson_id, |
|
1358 | 1358 | 'post_author' => $course->post_author |
1359 | 1359 | ); |
1360 | - wp_update_post( $lesson_update_args ); |
|
1360 | + wp_update_post($lesson_update_args); |
|
1361 | 1361 | |
1362 | 1362 | } // end update_lesson_teacher |
1363 | 1363 | |
@@ -1371,21 +1371,21 @@ discard block |
||
1371 | 1371 | * @parameters array $wp_query |
1372 | 1372 | * @return WP_Query $wp_query |
1373 | 1373 | */ |
1374 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
1374 | + public function limit_teacher_edit_screen_post_types($wp_query) { |
|
1375 | 1375 | global $current_user; |
1376 | 1376 | |
1377 | 1377 | //exit early |
1378 | - if( ! $this->is_admin_teacher() ){ |
|
1378 | + if ( ! $this->is_admin_teacher()) { |
|
1379 | 1379 | return $wp_query; |
1380 | 1380 | } |
1381 | 1381 | |
1382 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
1382 | + if ( ! function_exists('get_current_screen')) { |
|
1383 | 1383 | return $wp_query; |
1384 | 1384 | } |
1385 | 1385 | |
1386 | 1386 | $screen = get_current_screen(); |
1387 | 1387 | |
1388 | - if( empty( $screen ) ){ |
|
1388 | + if (empty($screen)) { |
|
1389 | 1389 | return $wp_query; |
1390 | 1390 | } |
1391 | 1391 | |
@@ -1398,10 +1398,10 @@ discard block |
||
1398 | 1398 | 'lesson_page_lesson-order', |
1399 | 1399 | ); |
1400 | 1400 | |
1401 | - if( in_array($screen->id , $limit_screens ) ) { |
|
1401 | + if (in_array($screen->id, $limit_screens)) { |
|
1402 | 1402 | |
1403 | 1403 | // set the query author to the current user to only show those those posts |
1404 | - $wp_query->set( 'author', $current_user->ID ); |
|
1404 | + $wp_query->set('author', $current_user->ID); |
|
1405 | 1405 | } |
1406 | 1406 | |
1407 | 1407 | return $wp_query; |
@@ -1421,7 +1421,7 @@ discard block |
||
1421 | 1421 | * @return void |
1422 | 1422 | */ |
1423 | 1423 | |
1424 | - public function teacher_login_redirect( $user_login, $user ) { |
|
1424 | + public function teacher_login_redirect($user_login, $user) { |
|
1425 | 1425 | |
1426 | 1426 | if (user_can($user, 'edit_courses')) { |
1427 | 1427 | |
@@ -1471,9 +1471,9 @@ discard block |
||
1471 | 1471 | * @param bool $restrict default true |
1472 | 1472 | */ |
1473 | 1473 | |
1474 | - $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
1474 | + $restrict = apply_filters('sensei_restrict_posts_menu_page', true); |
|
1475 | 1475 | |
1476 | - if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
1476 | + if (in_array('teacher', (array) $user->roles) && ! current_user_can('delete_posts') && $restrict) { |
|
1477 | 1477 | |
1478 | 1478 | remove_menu_page('edit.php'); |
1479 | 1479 | |
@@ -1503,11 +1503,11 @@ discard block |
||
1503 | 1503 | * @return WP_Comment_Query $clauses |
1504 | 1504 | */ |
1505 | 1505 | |
1506 | - public function restrict_comment_moderation ( $clauses ) { |
|
1506 | + public function restrict_comment_moderation($clauses) { |
|
1507 | 1507 | |
1508 | 1508 | global $pagenow; |
1509 | 1509 | |
1510 | - if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
1510 | + if (self::is_a_teacher(get_current_user_id()) && $pagenow == "edit-comments.php") { |
|
1511 | 1511 | |
1512 | 1512 | $clauses->query_vars['post_author'] = get_current_user_id(); |
1513 | 1513 | |
@@ -1524,15 +1524,15 @@ discard block |
||
1524 | 1524 | * |
1525 | 1525 | * @return bool |
1526 | 1526 | */ |
1527 | - public static function is_a_teacher( $user_id ){ |
|
1527 | + public static function is_a_teacher($user_id) { |
|
1528 | 1528 | |
1529 | 1529 | $user = get_user_by('id', $user_id); |
1530 | 1530 | |
1531 | - if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
1531 | + if (isset($user->roles) && in_array('teacher', $user->roles)) { |
|
1532 | 1532 | |
1533 | 1533 | return true; |
1534 | 1534 | |
1535 | - }else{ |
|
1535 | + } else { |
|
1536 | 1536 | |
1537 | 1537 | return false; |
1538 | 1538 | |
@@ -1545,14 +1545,14 @@ discard block |
||
1545 | 1545 | * |
1546 | 1546 | * @since 1.9.0 |
1547 | 1547 | */ |
1548 | - public static function archive_title(){ |
|
1548 | + public static function archive_title() { |
|
1549 | 1549 | |
1550 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
1550 | + $author = get_user_by('id', get_query_var('author')); |
|
1551 | 1551 | $author_name = $author->display_name; |
1552 | 1552 | ?> |
1553 | 1553 | <h2 class="teacher-archive-title"> |
1554 | 1554 | |
1555 | - <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
|
1555 | + <?php echo sprintf(__('All courses by %s', 'woothemes-sensei'), $author_name); ?> |
|
1556 | 1556 | |
1557 | 1557 | </h2> |
1558 | 1558 | <?php |
@@ -1564,9 +1564,9 @@ discard block |
||
1564 | 1564 | * |
1565 | 1565 | * @since 1.9.0 |
1566 | 1566 | */ |
1567 | - public static function remove_course_meta_on_teacher_archive(){ |
|
1567 | + public static function remove_course_meta_on_teacher_archive() { |
|
1568 | 1568 | |
1569 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
1569 | + remove_action('sensei_course_content_inside_before', array(Sensei()->course, 'the_course_meta')); |
|
1570 | 1570 | |
1571 | 1571 | } |
1572 | 1572 |