@@ -1,36 +1,36 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Class Sensei_Twentyeleven |
|
4 | - * |
|
5 | - * Responsible for wrapping twenty eleven theme Sensei content |
|
6 | - * with the correct markup |
|
7 | - * |
|
8 | - * @package Views |
|
9 | - * @subpackage Theme-Integration |
|
10 | - * @author Automattic |
|
11 | - * |
|
12 | - * @since 1.9.0 |
|
3 | + * Class Sensei_Twentyeleven |
|
4 | + * |
|
5 | + * Responsible for wrapping twenty eleven theme Sensei content |
|
6 | + * with the correct markup |
|
7 | + * |
|
8 | + * @package Views |
|
9 | + * @subpackage Theme-Integration |
|
10 | + * @author Automattic |
|
11 | + * |
|
12 | + * @since 1.9.0 |
|
13 | 13 | */ |
14 | 14 | Class Sensei_Twentyeleven { |
15 | 15 | |
16 | - /** |
|
17 | - * Output opening wrappers |
|
18 | - * @since 1.9.0 |
|
19 | - */ |
|
20 | - public function wrapper_start(){ |
|
21 | - ?> |
|
16 | + /** |
|
17 | + * Output opening wrappers |
|
18 | + * @since 1.9.0 |
|
19 | + */ |
|
20 | + public function wrapper_start(){ |
|
21 | + ?> |
|
22 | 22 | |
23 | 23 | <div id="primary"> |
24 | 24 | <div id="content" role="main"> |
25 | 25 | |
26 | 26 | <?php } |
27 | 27 | |
28 | - /** |
|
29 | - * Output closing wrappers |
|
30 | - * |
|
31 | - * @since 1.9.0 |
|
32 | - */ |
|
33 | - public function wrapper_end(){ ?> |
|
28 | + /** |
|
29 | + * Output closing wrappers |
|
30 | + * |
|
31 | + * @since 1.9.0 |
|
32 | + */ |
|
33 | + public function wrapper_end(){ ?> |
|
34 | 34 | |
35 | 35 | </div> |
36 | 36 | </div> |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * |
9 | 9 | * @since 1.9.0 |
10 | 10 | */ |
11 | -class Sensei_Learner{ |
|
11 | +class Sensei_Learner { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Get the students full name |
@@ -19,25 +19,25 @@ discard block |
||
19 | 19 | * @param $user_id |
20 | 20 | * @return bool|mixed|void |
21 | 21 | */ |
22 | - public static function get_full_name( $user_id ){ |
|
22 | + public static function get_full_name($user_id) { |
|
23 | 23 | |
24 | 24 | $full_name = ''; |
25 | 25 | |
26 | - if( empty( $user_id ) || ! ( 0 < intval( $user_id ) ) |
|
27 | - || !( get_userdata( $user_id ) ) ){ |
|
26 | + if (empty($user_id) || ! (0 < intval($user_id)) |
|
27 | + || ! (get_userdata($user_id))) { |
|
28 | 28 | return false; |
29 | 29 | } |
30 | 30 | |
31 | 31 | // get the user details |
32 | - $user = get_user_by( 'id', $user_id ); |
|
32 | + $user = get_user_by('id', $user_id); |
|
33 | 33 | |
34 | - if( ! empty( $user->first_name ) && ! empty( $user->last_name ) ){ |
|
34 | + if ( ! empty($user->first_name) && ! empty($user->last_name)) { |
|
35 | 35 | |
36 | - $full_name = trim( $user->first_name ) . ' ' . trim( $user->last_name ); |
|
36 | + $full_name = trim($user->first_name).' '.trim($user->last_name); |
|
37 | 37 | |
38 | - }else{ |
|
38 | + } else { |
|
39 | 39 | |
40 | - $full_name = $user->display_name; |
|
40 | + $full_name = $user->display_name; |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param $full_name |
49 | 49 | * @param $user_id |
50 | 50 | */ |
51 | - return apply_filters( 'sensei_learner_full_name' , $full_name , $user_id ); |
|
51 | + return apply_filters('sensei_learner_full_name', $full_name, $user_id); |
|
52 | 52 | |
53 | 53 | }// end get_full_name |
54 | 54 |
@@ -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 Utilities Class |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | * @since 1.0.0 |
19 | 19 | * @return string The URL to the placeholder thumbnail image. |
20 | 20 | */ |
21 | - public static function get_placeholder_image () { |
|
21 | + public static function get_placeholder_image() { |
|
22 | 22 | |
23 | - return esc_url( apply_filters( 'sensei_placeholder_thumbnail', Sensei()->plugin_url . 'assets/images/placeholder.png' ) ); |
|
23 | + return esc_url(apply_filters('sensei_placeholder_thumbnail', Sensei()->plugin_url.'assets/images/placeholder.png')); |
|
24 | 24 | } // End get_placeholder_image() |
25 | 25 | |
26 | 26 | /** |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @static |
33 | 33 | * @return bool |
34 | 34 | */ |
35 | - public static function sensei_is_woocommerce_present () { |
|
35 | + public static function sensei_is_woocommerce_present() { |
|
36 | 36 | |
37 | 37 | return Sensei_WC::is_woocommerce_present(); |
38 | 38 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @static |
48 | 48 | * @return boolean |
49 | 49 | */ |
50 | - public static function sensei_is_woocommerce_activated () { |
|
50 | + public static function sensei_is_woocommerce_activated() { |
|
51 | 51 | |
52 | 52 | return Sensei_WC::is_woocommerce_active(); |
53 | 53 | |
@@ -60,70 +60,70 @@ discard block |
||
60 | 60 | * @param array $args (default: array()) |
61 | 61 | * @return bool | int |
62 | 62 | */ |
63 | - public static function sensei_log_activity ( $args = array() ) { |
|
63 | + public static function sensei_log_activity($args = array()) { |
|
64 | 64 | global $wpdb; |
65 | 65 | |
66 | 66 | // Args, minimum data required for WP |
67 | 67 | $data = array( |
68 | - 'comment_post_ID' => intval( $args['post_id'] ), |
|
68 | + 'comment_post_ID' => intval($args['post_id']), |
|
69 | 69 | 'comment_author' => '', // Not needed |
70 | 70 | 'comment_author_email' => '', // Not needed |
71 | 71 | 'comment_author_url' => '', // Not needed |
72 | - 'comment_content' => !empty($args['data']) ? esc_html( $args['data'] ) : '', |
|
73 | - 'comment_type' => esc_attr( $args['type'] ), |
|
74 | - 'user_id' => intval( $args['user_id'] ), |
|
75 | - 'comment_approved' => !empty($args['status']) ? esc_html( $args['status'] ) : 'log', // 'log' == 'sensei_user_answer' |
|
72 | + 'comment_content' => ! empty($args['data']) ? esc_html($args['data']) : '', |
|
73 | + 'comment_type' => esc_attr($args['type']), |
|
74 | + 'user_id' => intval($args['user_id']), |
|
75 | + 'comment_approved' => ! empty($args['status']) ? esc_html($args['status']) : 'log', // 'log' == 'sensei_user_answer' |
|
76 | 76 | ); |
77 | 77 | // Allow extra data |
78 | - if ( !empty($args['username']) ) { |
|
79 | - $data['comment_author'] = sanitize_user( $args['username'] ); |
|
78 | + if ( ! empty($args['username'])) { |
|
79 | + $data['comment_author'] = sanitize_user($args['username']); |
|
80 | 80 | } |
81 | - if ( !empty($args['user_email']) ) { |
|
82 | - $data['comment_author_email'] = sanitize_email( $args['user_email'] ); |
|
81 | + if ( ! empty($args['user_email'])) { |
|
82 | + $data['comment_author_email'] = sanitize_email($args['user_email']); |
|
83 | 83 | } |
84 | - if ( !empty($args['user_url']) ) { |
|
85 | - $data['comment_author_url'] = esc_url( $args['user_url'] ); |
|
84 | + if ( ! empty($args['user_url'])) { |
|
85 | + $data['comment_author_url'] = esc_url($args['user_url']); |
|
86 | 86 | } |
87 | - if ( !empty($args['parent']) ) { |
|
87 | + if ( ! empty($args['parent'])) { |
|
88 | 88 | $data['comment_parent'] = $args['parent']; |
89 | 89 | } |
90 | 90 | // Sanity check |
91 | - if ( empty($args['user_id']) ) { |
|
92 | - _deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') ); |
|
91 | + if (empty($args['user_id'])) { |
|
92 | + _deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei')); |
|
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | |
96 | - do_action( 'sensei_log_activity_before', $args, $data ); |
|
96 | + do_action('sensei_log_activity_before', $args, $data); |
|
97 | 97 | |
98 | 98 | $flush_cache = false; |
99 | 99 | |
100 | 100 | // Custom Logic |
101 | 101 | // Check if comment exists first |
102 | - $comment_id = $wpdb->get_var( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type'] ) ); |
|
103 | - if ( ! $comment_id ) { |
|
102 | + $comment_id = $wpdb->get_var($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type'])); |
|
103 | + if ( ! $comment_id) { |
|
104 | 104 | // Add the comment |
105 | - $comment_id = wp_insert_comment( $data ); |
|
105 | + $comment_id = wp_insert_comment($data); |
|
106 | 106 | |
107 | 107 | $flush_cache = true; |
108 | - } elseif ( isset( $args['action'] ) && 'update' == $args['action'] ) { |
|
108 | + } elseif (isset($args['action']) && 'update' == $args['action']) { |
|
109 | 109 | // Update the comment if an update was requested |
110 | 110 | $data['comment_ID'] = $comment_id; |
111 | 111 | // By default update the timestamp of the comment |
112 | - if ( empty($args['keep_time']) ) { |
|
112 | + if (empty($args['keep_time'])) { |
|
113 | 113 | $data['comment_date'] = current_time('mysql'); |
114 | 114 | } |
115 | - wp_update_comment( $data ); |
|
115 | + wp_update_comment($data); |
|
116 | 116 | $flush_cache = true; |
117 | 117 | } // End If Statement |
118 | 118 | |
119 | 119 | // Manually Flush the Cache |
120 | - if ( $flush_cache ) { |
|
120 | + if ($flush_cache) { |
|
121 | 121 | wp_cache_flush(); |
122 | 122 | } |
123 | 123 | |
124 | - do_action( 'sensei_log_activity_after', $args, $data, $comment_id ); |
|
124 | + do_action('sensei_log_activity_after', $args, $data, $comment_id); |
|
125 | 125 | |
126 | - if ( 0 < $comment_id ) { |
|
126 | + if (0 < $comment_id) { |
|
127 | 127 | // Return the ID so that it can be used for meta data storage |
128 | 128 | return $comment_id; |
129 | 129 | } else { |
@@ -140,41 +140,41 @@ discard block |
||
140 | 140 | * @param bool $return_comments (default: false) |
141 | 141 | * @return mixed | int |
142 | 142 | */ |
143 | - public static function sensei_check_for_activity ( $args = array(), $return_comments = false ) { |
|
143 | + public static function sensei_check_for_activity($args = array(), $return_comments = false) { |
|
144 | 144 | |
145 | 145 | global $wp_version; |
146 | - if ( !$return_comments ) { |
|
146 | + if ( ! $return_comments) { |
|
147 | 147 | $args['count'] = true; |
148 | 148 | } |
149 | 149 | |
150 | 150 | // Are we only retrieving a single entry, or not care about the order... |
151 | - if ( isset( $args['count'] ) || isset( $args['post_id'] ) ){ |
|
151 | + if (isset($args['count']) || isset($args['post_id'])) { |
|
152 | 152 | |
153 | 153 | // ...then we don't need to ask the db to order the results, this overrides WP default behaviour |
154 | - if ( version_compare( $wp_version, '4.1', '>=' ) ) { |
|
154 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
155 | 155 | $args['order'] = false; |
156 | 156 | $args['orderby'] = false; |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | 160 | // A user ID of 0 is in valid, so shortcut this |
161 | - if ( isset( $args['user_id'] ) && 0 == intval ( $args['user_id'] ) ) { |
|
162 | - _deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') ); |
|
161 | + if (isset($args['user_id']) && 0 == intval($args['user_id'])) { |
|
162 | + _deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei')); |
|
163 | 163 | return false; |
164 | 164 | } |
165 | 165 | // Check for legacy code |
166 | - if ( isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes') ) ) { |
|
167 | - _deprecated_argument( __FUNCTION__, '1.7', sprintf( __('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'] ) ); |
|
166 | + if (isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes'))) { |
|
167 | + _deprecated_argument(__FUNCTION__, '1.7', sprintf(__('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'])); |
|
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | // Are we checking for specific comment_approved statuses? |
171 | - if ( isset($args['status']) ) { |
|
171 | + if (isset($args['status'])) { |
|
172 | 172 | // Temporarily store as a custom status if requesting an array... |
173 | - if ( is_array( $args['status'] ) && version_compare($wp_version, '4.1', '<') ) { |
|
173 | + if (is_array($args['status']) && version_compare($wp_version, '4.1', '<')) { |
|
174 | 174 | // Encode now, decode later |
175 | - $args['status'] = implode( ",", $args['status'] ); |
|
175 | + $args['status'] = implode(",", $args['status']); |
|
176 | 176 | // ...use a filter to switch the encoding back |
177 | - add_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
|
177 | + add_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter')); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | else { |
@@ -182,8 +182,8 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | // Take into account WP < 4.1 will automatically add ' comment_approved = 1 OR comment_approved = 0 ' |
185 | - if ( ( is_array( $args['status'] ) || 'any' == $args['status'] ) && version_compare($wp_version, '4.1', '<') ) { |
|
186 | - add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
|
185 | + if ((is_array($args['status']) || 'any' == $args['status']) && version_compare($wp_version, '4.1', '<')) { |
|
186 | + add_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter')); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | //Get the comments |
@@ -194,14 +194,14 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @param int|array $comments |
196 | 196 | */ |
197 | - $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
197 | + $comments = apply_filters('sensei_check_for_activity', get_comments($args)); |
|
198 | 198 | |
199 | - remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
|
200 | - remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
|
199 | + remove_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter')); |
|
200 | + remove_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter')); |
|
201 | 201 | // Return comments |
202 | - if ( $return_comments ) { |
|
202 | + if ($return_comments) { |
|
203 | 203 | // Could check for array of 1 and just return the 1 item? |
204 | - if ( is_array($comments) && 1 == count($comments) ) { |
|
204 | + if (is_array($comments) && 1 == count($comments)) { |
|
205 | 205 | $comments = array_shift($comments); |
206 | 206 | } |
207 | 207 | |
@@ -219,31 +219,31 @@ discard block |
||
219 | 219 | * @param array $args (default: array()) |
220 | 220 | * @return array |
221 | 221 | */ |
222 | - public static function sensei_activity_ids ( $args = array() ) { |
|
222 | + public static function sensei_activity_ids($args = array()) { |
|
223 | 223 | |
224 | 224 | |
225 | - $comments = Sensei_Utils::sensei_check_for_activity( $args, true ); |
|
225 | + $comments = Sensei_Utils::sensei_check_for_activity($args, true); |
|
226 | 226 | // Need to always use an array, even with only 1 item |
227 | - if ( !is_array($comments) ) { |
|
228 | - $comments = array( $comments ); |
|
227 | + if ( ! is_array($comments)) { |
|
228 | + $comments = array($comments); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | $post_ids = array(); |
232 | 232 | // Count comments |
233 | - if ( is_array( $comments ) && ( 0 < intval( count( $comments ) ) ) ) { |
|
234 | - foreach ( $comments as $key => $value ) { |
|
233 | + if (is_array($comments) && (0 < intval(count($comments)))) { |
|
234 | + foreach ($comments as $key => $value) { |
|
235 | 235 | // Add matches to id array |
236 | - if ( isset( $args['field'] ) && 'comment' == $args['field'] ) { |
|
237 | - array_push( $post_ids, $value->comment_ID ); |
|
238 | - } elseif( isset( $args['field'] ) && 'user_id' == $args['field'] ) { |
|
239 | - array_push( $post_ids, $value->user_id ); |
|
236 | + if (isset($args['field']) && 'comment' == $args['field']) { |
|
237 | + array_push($post_ids, $value->comment_ID); |
|
238 | + } elseif (isset($args['field']) && 'user_id' == $args['field']) { |
|
239 | + array_push($post_ids, $value->user_id); |
|
240 | 240 | } else { |
241 | - array_push( $post_ids, $value->comment_post_ID ); |
|
241 | + array_push($post_ids, $value->comment_post_ID); |
|
242 | 242 | } // End If Statement |
243 | 243 | } // End For Loop |
244 | 244 | // Reset array indexes |
245 | - $post_ids = array_unique( $post_ids ); |
|
246 | - $post_ids = array_values( $post_ids ); |
|
245 | + $post_ids = array_unique($post_ids); |
|
246 | + $post_ids = array_values($post_ids); |
|
247 | 247 | } // End If Statement |
248 | 248 | |
249 | 249 | return $post_ids; |
@@ -257,20 +257,20 @@ discard block |
||
257 | 257 | * @param array $args (default: array()) |
258 | 258 | * @return boolean |
259 | 259 | */ |
260 | - public static function sensei_delete_activities ( $args = array() ) { |
|
260 | + public static function sensei_delete_activities($args = array()) { |
|
261 | 261 | |
262 | 262 | $dataset_changes = false; |
263 | 263 | |
264 | 264 | // If activity exists remove activity from log |
265 | - $comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => intval( $args['post_id'] ), 'user_id' => intval( $args['user_id'] ), 'type' => esc_attr( $args['type'] ) ), true ); |
|
266 | - if( $comments ) { |
|
265 | + $comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => intval($args['post_id']), 'user_id' => intval($args['user_id']), 'type' => esc_attr($args['type'])), true); |
|
266 | + if ($comments) { |
|
267 | 267 | // Need to always return an array, even with only 1 item |
268 | - if ( !is_array( $comments ) ) { |
|
269 | - $comments = array( $comments ); |
|
268 | + if ( ! is_array($comments)) { |
|
269 | + $comments = array($comments); |
|
270 | 270 | } |
271 | - foreach ( $comments as $key => $value ) { |
|
272 | - if ( isset( $value->comment_ID ) && 0 < $value->comment_ID ) { |
|
273 | - $dataset_changes = wp_delete_comment( intval( $value->comment_ID ), true ); |
|
271 | + foreach ($comments as $key => $value) { |
|
272 | + if (isset($value->comment_ID) && 0 < $value->comment_ID) { |
|
273 | + $dataset_changes = wp_delete_comment(intval($value->comment_ID), true); |
|
274 | 274 | } // End If Statement |
275 | 275 | } // End For Loop |
276 | 276 | // Manually flush the cache |
@@ -286,25 +286,25 @@ discard block |
||
286 | 286 | * @param integer $user_id User ID |
287 | 287 | * @return boolean |
288 | 288 | */ |
289 | - public static function delete_all_user_activity( $user_id = 0 ) { |
|
289 | + public static function delete_all_user_activity($user_id = 0) { |
|
290 | 290 | |
291 | 291 | $dataset_changes = false; |
292 | 292 | |
293 | - if( $user_id ) { |
|
293 | + if ($user_id) { |
|
294 | 294 | |
295 | - $activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true ); |
|
295 | + $activities = Sensei_Utils::sensei_check_for_activity(array('user_id' => $user_id), true); |
|
296 | 296 | |
297 | - if( $activities ) { |
|
297 | + if ($activities) { |
|
298 | 298 | |
299 | 299 | // Need to always return an array, even with only 1 item |
300 | - if ( ! is_array( $activities ) ) { |
|
301 | - $activities = array( $activities ); |
|
300 | + if ( ! is_array($activities)) { |
|
301 | + $activities = array($activities); |
|
302 | 302 | } |
303 | 303 | |
304 | - foreach( $activities as $activity ) { |
|
305 | - if( '' == $activity->comment_type ) continue; |
|
306 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
307 | - $dataset_changes = wp_delete_comment( intval( $activity->comment_ID ), true ); |
|
304 | + foreach ($activities as $activity) { |
|
305 | + if ('' == $activity->comment_type) continue; |
|
306 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
307 | + $dataset_changes = wp_delete_comment(intval($activity->comment_ID), true); |
|
308 | 308 | wp_cache_flush(); |
309 | 309 | } |
310 | 310 | } |
@@ -321,14 +321,14 @@ discard block |
||
321 | 321 | * @param array $args (default: array()) |
322 | 322 | * @return string |
323 | 323 | */ |
324 | - public static function sensei_get_activity_value ( $args = array() ) { |
|
324 | + public static function sensei_get_activity_value($args = array()) { |
|
325 | 325 | |
326 | 326 | |
327 | 327 | $activity_value = false; |
328 | - if ( !empty($args['field']) ) { |
|
329 | - $comment = Sensei_Utils::sensei_check_for_activity( $args, true ); |
|
328 | + if ( ! empty($args['field'])) { |
|
329 | + $comment = Sensei_Utils::sensei_check_for_activity($args, true); |
|
330 | 330 | |
331 | - if ( isset( $comment->{$args['field']} ) && '' != $comment->{$args['field']} ) { |
|
331 | + if (isset($comment->{$args['field']} ) && '' != $comment->{$args['field']} ) { |
|
332 | 332 | $activity_value = $comment->{$args['field']}; |
333 | 333 | } // End If Statement |
334 | 334 | } |
@@ -346,22 +346,22 @@ discard block |
||
346 | 346 | * @param int $product_id |
347 | 347 | * @return bool |
348 | 348 | */ |
349 | - public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
349 | + public static function sensei_customer_bought_product($customer_email, $user_id, $product_id) { |
|
350 | 350 | |
351 | 351 | $emails = array(); |
352 | 352 | |
353 | - if ( $user_id ) { |
|
354 | - $user = get_user_by( 'id', intval( $user_id ) ); |
|
353 | + if ($user_id) { |
|
354 | + $user = get_user_by('id', intval($user_id)); |
|
355 | 355 | $emails[] = $user->user_email; |
356 | 356 | } |
357 | 357 | |
358 | - if ( is_email( $customer_email ) ) |
|
358 | + if (is_email($customer_email)) |
|
359 | 359 | $emails[] = $customer_email; |
360 | 360 | |
361 | - if ( sizeof( $emails ) == 0 ) |
|
361 | + if (sizeof($emails) == 0) |
|
362 | 362 | return false; |
363 | 363 | |
364 | - return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
364 | + return Sensei_WC::has_customer_bought_product($user_id, $product_id); |
|
365 | 365 | |
366 | 366 | } // End sensei_customer_bought_product() |
367 | 367 | |
@@ -372,9 +372,9 @@ discard block |
||
372 | 372 | * @param string $input_name Name for text area form element |
373 | 373 | * @return void |
374 | 374 | */ |
375 | - public static function sensei_text_editor( $content = '', $editor_id = 'senseitexteditor', $input_name = '' ) { |
|
375 | + public static function sensei_text_editor($content = '', $editor_id = 'senseitexteditor', $input_name = '') { |
|
376 | 376 | |
377 | - if( ! $input_name ) $input_name = $editor_id; |
|
377 | + if ( ! $input_name) $input_name = $editor_id; |
|
378 | 378 | |
379 | 379 | $buttons = 'bold,italic,underline,strikethrough,blockquote,bullist,numlist,justifyleft,justifycenter,justifyright,undo,redo,pastetext'; |
380 | 380 | |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | 'quicktags' => false |
393 | 393 | ); |
394 | 394 | |
395 | - wp_editor( $content, $editor_id, $settings ); |
|
395 | + wp_editor($content, $editor_id, $settings); |
|
396 | 396 | |
397 | 397 | } // End sensei_text_editor() |
398 | 398 | |
@@ -402,57 +402,57 @@ discard block |
||
402 | 402 | * @param int $user_id |
403 | 403 | * @return boolean Whether the answers were saved or not |
404 | 404 | */ |
405 | - public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) { |
|
405 | + public static function sensei_save_quiz_answers($submitted = array(), $user_id = 0) { |
|
406 | 406 | |
407 | - if( intval( $user_id ) == 0 ) { |
|
407 | + if (intval($user_id) == 0) { |
|
408 | 408 | $user_id = get_current_user_id(); |
409 | 409 | } |
410 | 410 | |
411 | 411 | $answers_saved = false; |
412 | 412 | |
413 | - if( $submitted && intval( $user_id ) > 0 ) { |
|
413 | + if ($submitted && intval($user_id) > 0) { |
|
414 | 414 | |
415 | - foreach( $submitted as $question_id => $answer ) { |
|
415 | + foreach ($submitted as $question_id => $answer) { |
|
416 | 416 | |
417 | 417 | // Get question type |
418 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
418 | + $question_type = Sensei()->question->get_question_type($question_id); |
|
419 | 419 | |
420 | 420 | // Sanitise answer |
421 | - if( 0 == get_magic_quotes_gpc() ) { |
|
422 | - $answer = wp_unslash( $answer ); |
|
421 | + if (0 == get_magic_quotes_gpc()) { |
|
422 | + $answer = wp_unslash($answer); |
|
423 | 423 | } |
424 | - switch( $question_type ) { |
|
425 | - case 'multi-line': $answer = nl2br( $answer ); break; |
|
424 | + switch ($question_type) { |
|
425 | + case 'multi-line': $answer = nl2br($answer); break; |
|
426 | 426 | case 'single-line': break; |
427 | 427 | case 'gap-fill': break; |
428 | - default: $answer = maybe_serialize( $answer ); break; |
|
428 | + default: $answer = maybe_serialize($answer); break; |
|
429 | 429 | } |
430 | 430 | $args = array( |
431 | 431 | 'post_id' => $question_id, |
432 | - 'data' => base64_encode( $answer ), |
|
432 | + 'data' => base64_encode($answer), |
|
433 | 433 | 'type' => 'sensei_user_answer', /* FIELD SIZE 20 */ |
434 | 434 | 'user_id' => $user_id, |
435 | 435 | 'action' => 'update' |
436 | 436 | ); |
437 | - $answers_saved = Sensei_Utils::sensei_log_activity( $args ); |
|
437 | + $answers_saved = Sensei_Utils::sensei_log_activity($args); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | // Handle file upload questions |
441 | - if( isset( $_FILES ) ) { |
|
442 | - foreach( $_FILES as $field => $file ) { |
|
443 | - if( strpos( $field, 'file_upload_' ) !== false ) { |
|
444 | - $question_id = str_replace( 'file_upload_', '', $field ); |
|
445 | - if( $file && $question_id ) { |
|
446 | - $attachment_id = self::upload_file( $file ); |
|
447 | - if( $attachment_id ) { |
|
441 | + if (isset($_FILES)) { |
|
442 | + foreach ($_FILES as $field => $file) { |
|
443 | + if (strpos($field, 'file_upload_') !== false) { |
|
444 | + $question_id = str_replace('file_upload_', '', $field); |
|
445 | + if ($file && $question_id) { |
|
446 | + $attachment_id = self::upload_file($file); |
|
447 | + if ($attachment_id) { |
|
448 | 448 | $args = array( |
449 | 449 | 'post_id' => $question_id, |
450 | - 'data' => base64_encode( $attachment_id ), |
|
450 | + 'data' => base64_encode($attachment_id), |
|
451 | 451 | 'type' => 'sensei_user_answer', /* FIELD SIZE 20 */ |
452 | 452 | 'user_id' => $user_id, |
453 | 453 | 'action' => 'update' |
454 | 454 | ); |
455 | - $answers_saved = Sensei_Utils::sensei_log_activity( $args ); |
|
455 | + $answers_saved = Sensei_Utils::sensei_log_activity($args); |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | } |
@@ -464,9 +464,9 @@ discard block |
||
464 | 464 | |
465 | 465 | } // End sensei_save_quiz_answers() |
466 | 466 | |
467 | - public static function upload_file( $file = array() ) { |
|
467 | + public static function upload_file($file = array()) { |
|
468 | 468 | |
469 | - require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
|
469 | + require_once(ABSPATH.'wp-admin/includes/admin.php'); |
|
470 | 470 | |
471 | 471 | /** |
472 | 472 | * Filter the data array for the Sensei wp_handle_upload function call |
@@ -481,11 +481,11 @@ discard block |
||
481 | 481 | * @type string test_form set to false by default |
482 | 482 | * } |
483 | 483 | */ |
484 | - $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
484 | + $file_upload_args = apply_filters('sensei_file_upload_args', array('test_form' => false)); |
|
485 | 485 | |
486 | - $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
486 | + $file_return = wp_handle_upload($file, $file_upload_args); |
|
487 | 487 | |
488 | - if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
488 | + if (isset($file_return['error']) || isset($file_return['upload_error_handler'])) { |
|
489 | 489 | return false; |
490 | 490 | } else { |
491 | 491 | |
@@ -493,19 +493,19 @@ discard block |
||
493 | 493 | |
494 | 494 | $attachment = array( |
495 | 495 | 'post_mime_type' => $file_return['type'], |
496 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
496 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), |
|
497 | 497 | 'post_content' => '', |
498 | 498 | 'post_status' => 'inherit', |
499 | 499 | 'guid' => $file_return['url'] |
500 | 500 | ); |
501 | 501 | |
502 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
502 | + $attachment_id = wp_insert_attachment($attachment, $filename); |
|
503 | 503 | |
504 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
505 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
506 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
504 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
505 | + $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
506 | + wp_update_attachment_metadata($attachment_id, $attachment_data); |
|
507 | 507 | |
508 | - if( 0 < intval( $attachment_id ) ) { |
|
508 | + if (0 < intval($attachment_id)) { |
|
509 | 509 | return $attachment_id; |
510 | 510 | } |
511 | 511 | } |
@@ -531,9 +531,9 @@ discard block |
||
531 | 531 | * |
532 | 532 | * @return int $quiz_grade total sum of all question grades |
533 | 533 | */ |
534 | - public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
534 | + public static function sensei_grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') { |
|
535 | 535 | |
536 | - return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
536 | + return Sensei_Grading::grade_quiz_auto($quiz_id, $submitted, $total_questions, $quiz_grade_type); |
|
537 | 537 | |
538 | 538 | } // End sensei_grade_quiz_auto() |
539 | 539 | |
@@ -545,20 +545,20 @@ discard block |
||
545 | 545 | * @param string $quiz_grade_type default 'auto' |
546 | 546 | * @return boolean |
547 | 547 | */ |
548 | - public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) { |
|
549 | - if( intval( $user_id ) == 0 ) { |
|
548 | + public static function sensei_grade_quiz($quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto') { |
|
549 | + if (intval($user_id) == 0) { |
|
550 | 550 | $user_id = get_current_user_id(); |
551 | 551 | } |
552 | 552 | |
553 | 553 | $activity_logged = false; |
554 | - if( intval( $quiz_id ) > 0 && intval( $user_id ) > 0 ) { |
|
555 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
556 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
557 | - $activity_logged = update_comment_meta( $user_lesson_status->comment_ID, 'grade', $grade ); |
|
554 | + if (intval($quiz_id) > 0 && intval($user_id) > 0) { |
|
555 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
556 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
557 | + $activity_logged = update_comment_meta($user_lesson_status->comment_ID, 'grade', $grade); |
|
558 | 558 | |
559 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
559 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
560 | 560 | |
561 | - do_action( 'sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type ); |
|
561 | + do_action('sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type); |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | return $activity_logged; |
@@ -578,9 +578,9 @@ discard block |
||
578 | 578 | * |
579 | 579 | * @return int $question_grade |
580 | 580 | */ |
581 | - public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
581 | + public static function sensei_grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) { |
|
582 | 582 | |
583 | - return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
583 | + return WooThemes_Sensei_Grading::grade_question_auto($question_id, $question_type, $answer, $user_id); |
|
584 | 584 | |
585 | 585 | } // end sensei_grade_question_auto |
586 | 586 | |
@@ -591,20 +591,20 @@ discard block |
||
591 | 591 | * @param int $user_id |
592 | 592 | * @return boolean |
593 | 593 | */ |
594 | - public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) { |
|
595 | - if( intval( $user_id ) == 0 ) { |
|
594 | + public static function sensei_grade_question($question_id = 0, $grade = 0, $user_id = 0) { |
|
595 | + if (intval($user_id) == 0) { |
|
596 | 596 | $user_id = get_current_user_id(); |
597 | 597 | } |
598 | 598 | |
599 | 599 | $activity_logged = false; |
600 | - if( intval( $question_id ) > 0 && intval( $user_id ) > 0 ) { |
|
600 | + if (intval($question_id) > 0 && intval($user_id) > 0) { |
|
601 | 601 | |
602 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
603 | - $activity_logged = update_comment_meta( $user_answer_id, 'user_grade', $grade ); |
|
602 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
603 | + $activity_logged = update_comment_meta($user_answer_id, 'user_grade', $grade); |
|
604 | 604 | |
605 | - $answer_notes = get_post_meta( $question_id, '_answer_feedback', true ); |
|
606 | - if ( !empty($answer_notes) ) { |
|
607 | - update_comment_meta( $user_answer_id, 'answer_note', base64_encode( $answer_notes ) ); |
|
605 | + $answer_notes = get_post_meta($question_id, '_answer_feedback', true); |
|
606 | + if ( ! empty($answer_notes)) { |
|
607 | + update_comment_meta($user_answer_id, 'answer_note', base64_encode($answer_notes)); |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | } |
@@ -612,15 +612,15 @@ discard block |
||
612 | 612 | return $activity_logged; |
613 | 613 | } |
614 | 614 | |
615 | - public static function sensei_delete_question_grade( $question_id = 0, $user_id = 0 ) { |
|
616 | - if( intval( $user_id ) == 0 ) { |
|
615 | + public static function sensei_delete_question_grade($question_id = 0, $user_id = 0) { |
|
616 | + if (intval($user_id) == 0) { |
|
617 | 617 | $user_id = get_current_user_id(); |
618 | 618 | } |
619 | 619 | |
620 | 620 | $activity_logged = false; |
621 | - if( intval( $question_id ) > 0 ) { |
|
622 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
623 | - $activity_logged = delete_comment_meta( $user_answer_id, 'user_grade' ); |
|
621 | + if (intval($question_id) > 0) { |
|
622 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
623 | + $activity_logged = delete_comment_meta($user_answer_id, 'user_grade'); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | return $activity_logged; |
@@ -638,9 +638,9 @@ discard block |
||
638 | 638 | * |
639 | 639 | * @return mixed boolean or comment_ID |
640 | 640 | */ |
641 | - public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
641 | + public static function user_start_lesson($user_id = 0, $lesson_id = 0, $complete = false) { |
|
642 | 642 | |
643 | - return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
643 | + return self::sensei_start_lesson($lesson_id, $user_id, $complete); |
|
644 | 644 | |
645 | 645 | }// end user_start_lesson() |
646 | 646 | |
@@ -657,22 +657,22 @@ discard block |
||
657 | 657 | * |
658 | 658 | * @return mixed boolean or comment_ID |
659 | 659 | */ |
660 | - public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
|
660 | + public static function sensei_start_lesson($lesson_id = 0, $user_id = 0, $complete = false) { |
|
661 | 661 | |
662 | 662 | |
663 | - if( intval( $user_id ) == 0 ) { |
|
663 | + if (intval($user_id) == 0) { |
|
664 | 664 | $user_id = get_current_user_id(); |
665 | 665 | } |
666 | 666 | |
667 | 667 | $activity_logged = false; |
668 | 668 | |
669 | - if( intval( $lesson_id ) > 0 ) { |
|
669 | + if (intval($lesson_id) > 0) { |
|
670 | 670 | |
671 | - $course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
672 | - if( $course_id ) { |
|
673 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
674 | - if( ! $is_user_taking_course ) { |
|
675 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
671 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
672 | + if ($course_id) { |
|
673 | + $is_user_taking_course = Sensei_Utils::user_started_course($course_id, $user_id); |
|
674 | + if ( ! $is_user_taking_course) { |
|
675 | + Sensei_Utils::user_start_course($user_id, $course_id); |
|
676 | 676 | } |
677 | 677 | } |
678 | 678 | |
@@ -680,12 +680,12 @@ discard block |
||
680 | 680 | $status = 'in-progress'; |
681 | 681 | |
682 | 682 | // Note: When this action runs the lesson status may not yet exist |
683 | - do_action( 'sensei_user_lesson_start', $user_id, $lesson_id ); |
|
683 | + do_action('sensei_user_lesson_start', $user_id, $lesson_id); |
|
684 | 684 | |
685 | - if( $complete ) { |
|
685 | + if ($complete) { |
|
686 | 686 | |
687 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
688 | - if ( $has_questions ) { |
|
687 | + $has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
688 | + if ($has_questions) { |
|
689 | 689 | $status = 'passed'; // Force a pass |
690 | 690 | $metadata['grade'] = 0; |
691 | 691 | } |
@@ -695,31 +695,31 @@ discard block |
||
695 | 695 | } |
696 | 696 | |
697 | 697 | // Check if user is already taking the lesson |
698 | - $activity_logged = Sensei_Utils::user_started_lesson( $lesson_id, $user_id ); |
|
699 | - if( ! $activity_logged ) { |
|
698 | + $activity_logged = Sensei_Utils::user_started_lesson($lesson_id, $user_id); |
|
699 | + if ( ! $activity_logged) { |
|
700 | 700 | |
701 | 701 | $metadata['start'] = current_time('mysql'); |
702 | - $activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata ); |
|
702 | + $activity_logged = Sensei_Utils::update_lesson_status($user_id, $lesson_id, $status, $metadata); |
|
703 | 703 | |
704 | 704 | } else { |
705 | 705 | |
706 | 706 | // if users is already taking the lesson and the status changes to complete update it |
707 | 707 | $current_user_activity = get_comment($activity_logged); |
708 | - if( $status=='complete' && |
|
709 | - $status != $current_user_activity->comment_approved ){ |
|
708 | + if ($status == 'complete' && |
|
709 | + $status != $current_user_activity->comment_approved) { |
|
710 | 710 | |
711 | 711 | $comment = array(); |
712 | 712 | $comment['comment_ID'] = $activity_logged; |
713 | 713 | $comment['comment_approved'] = $status; |
714 | - wp_update_comment( $comment ); |
|
714 | + wp_update_comment($comment); |
|
715 | 715 | |
716 | 716 | } |
717 | 717 | |
718 | 718 | } |
719 | 719 | |
720 | - if ( $complete ) { |
|
720 | + if ($complete) { |
|
721 | 721 | // Run this *after* the lesson status has been created/updated |
722 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
722 | + do_action('sensei_user_lesson_end', $user_id, $lesson_id); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | } |
@@ -734,20 +734,20 @@ discard block |
||
734 | 734 | * @param int $user_id |
735 | 735 | * @return boolean |
736 | 736 | */ |
737 | - public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) { |
|
737 | + public static function sensei_remove_user_from_lesson($lesson_id = 0, $user_id = 0, $from_course = false) { |
|
738 | 738 | |
739 | 739 | |
740 | - if( ! $lesson_id ) return false; |
|
740 | + if ( ! $lesson_id) return false; |
|
741 | 741 | |
742 | - if( intval( $user_id ) == 0 ) { |
|
742 | + if (intval($user_id) == 0) { |
|
743 | 743 | $user_id = get_current_user_id(); |
744 | 744 | } |
745 | 745 | |
746 | 746 | // Process quiz |
747 | - $lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
747 | + $lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
748 | 748 | |
749 | 749 | // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
750 | - Sensei_Utils::sensei_delete_quiz_answers( $lesson_quiz_id, $user_id ); |
|
750 | + Sensei_Utils::sensei_delete_quiz_answers($lesson_quiz_id, $user_id); |
|
751 | 751 | |
752 | 752 | // Delete lesson status |
753 | 753 | $args = array( |
@@ -756,10 +756,10 @@ discard block |
||
756 | 756 | 'user_id' => $user_id, |
757 | 757 | ); |
758 | 758 | // This auto deletes the corresponding meta data, such as the quiz grade, and questions asked |
759 | - Sensei_Utils::sensei_delete_activities( $args ); |
|
759 | + Sensei_Utils::sensei_delete_activities($args); |
|
760 | 760 | |
761 | - if( ! $from_course ) { |
|
762 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
761 | + if ( ! $from_course) { |
|
762 | + do_action('sensei_user_lesson_reset', $user_id, $lesson_id); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | return true; |
@@ -772,19 +772,19 @@ discard block |
||
772 | 772 | * @param int $user_id |
773 | 773 | * @return boolean |
774 | 774 | */ |
775 | - public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) { |
|
775 | + public static function sensei_remove_user_from_course($course_id = 0, $user_id = 0) { |
|
776 | 776 | |
777 | 777 | |
778 | - if( ! $course_id ) return false; |
|
778 | + if ( ! $course_id) return false; |
|
779 | 779 | |
780 | - if( intval( $user_id ) == 0 ) { |
|
780 | + if (intval($user_id) == 0) { |
|
781 | 781 | $user_id = get_current_user_id(); |
782 | 782 | } |
783 | 783 | |
784 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
784 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
785 | 785 | |
786 | - foreach( $lesson_ids as $lesson_id ) { |
|
787 | - Sensei_Utils::sensei_remove_user_from_lesson( $lesson_id, $user_id, true ); |
|
786 | + foreach ($lesson_ids as $lesson_id) { |
|
787 | + Sensei_Utils::sensei_remove_user_from_lesson($lesson_id, $user_id, true); |
|
788 | 788 | } |
789 | 789 | |
790 | 790 | // Delete course status |
@@ -794,36 +794,36 @@ discard block |
||
794 | 794 | 'user_id' => $user_id, |
795 | 795 | ); |
796 | 796 | |
797 | - Sensei_Utils::sensei_delete_activities( $args ); |
|
797 | + Sensei_Utils::sensei_delete_activities($args); |
|
798 | 798 | |
799 | - do_action( 'sensei_user_course_reset', $user_id, $course_id ); |
|
799 | + do_action('sensei_user_course_reset', $user_id, $course_id); |
|
800 | 800 | |
801 | 801 | return true; |
802 | 802 | } |
803 | 803 | |
804 | - public static function sensei_get_quiz_questions( $quiz_id = 0 ) { |
|
804 | + public static function sensei_get_quiz_questions($quiz_id = 0) { |
|
805 | 805 | |
806 | 806 | |
807 | 807 | $questions = array(); |
808 | 808 | |
809 | - if( intval( $quiz_id ) > 0 ) { |
|
810 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
811 | - $questions = Sensei_Utils::array_sort_reorder( $questions ); |
|
809 | + if (intval($quiz_id) > 0) { |
|
810 | + $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id); |
|
811 | + $questions = Sensei_Utils::array_sort_reorder($questions); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | return $questions; |
815 | 815 | } |
816 | 816 | |
817 | - public static function sensei_get_quiz_total( $quiz_id = 0 ) { |
|
817 | + public static function sensei_get_quiz_total($quiz_id = 0) { |
|
818 | 818 | |
819 | 819 | |
820 | 820 | $quiz_total = 0; |
821 | 821 | |
822 | - if( $quiz_id > 0 ) { |
|
823 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
822 | + if ($quiz_id > 0) { |
|
823 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
824 | 824 | $question_grade = 0; |
825 | - foreach( $questions as $question ) { |
|
826 | - $question_grade = Sensei()->question->get_question_grade( $question->ID ); |
|
825 | + foreach ($questions as $question) { |
|
826 | + $question_grade = Sensei()->question->get_question_grade($question->ID); |
|
827 | 827 | $quiz_total += $question_grade; |
828 | 828 | } |
829 | 829 | } |
@@ -838,20 +838,20 @@ discard block |
||
838 | 838 | * @param int $user_id |
839 | 839 | * @return string |
840 | 840 | */ |
841 | - public static function sensei_get_user_question_grade( $question = 0, $user_id = 0 ) { |
|
841 | + public static function sensei_get_user_question_grade($question = 0, $user_id = 0) { |
|
842 | 842 | $question_grade = false; |
843 | - if( $question ) { |
|
844 | - if ( is_object( $question ) ) { |
|
843 | + if ($question) { |
|
844 | + if (is_object($question)) { |
|
845 | 845 | $user_answer_id = $question->comment_ID; |
846 | 846 | } |
847 | 847 | else { |
848 | - if( intval( $user_id ) == 0 ) { |
|
848 | + if (intval($user_id) == 0) { |
|
849 | 849 | $user_id = get_current_user_id(); |
850 | 850 | } |
851 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
851 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
852 | 852 | } |
853 | - if ( $user_answer_id ) { |
|
854 | - $question_grade = get_comment_meta( $user_answer_id, 'user_grade', true ); |
|
853 | + if ($user_answer_id) { |
|
854 | + $question_grade = get_comment_meta($user_answer_id, 'user_grade', true); |
|
855 | 855 | } |
856 | 856 | } |
857 | 857 | |
@@ -866,52 +866,52 @@ discard block |
||
866 | 866 | * @param int $user_id |
867 | 867 | * @return string |
868 | 868 | */ |
869 | - public static function sensei_get_user_question_answer_notes( $question = 0, $user_id = 0 ) { |
|
869 | + public static function sensei_get_user_question_answer_notes($question = 0, $user_id = 0) { |
|
870 | 870 | $answer_notes = false; |
871 | - if( $question ) { |
|
872 | - if ( is_object( $question ) ) { |
|
871 | + if ($question) { |
|
872 | + if (is_object($question)) { |
|
873 | 873 | $user_answer_id = $question->comment_ID; |
874 | 874 | } |
875 | 875 | else { |
876 | - if( intval( $user_id ) == 0 ) { |
|
876 | + if (intval($user_id) == 0) { |
|
877 | 877 | $user_id = get_current_user_id(); |
878 | 878 | } |
879 | - $user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
879 | + $user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
880 | 880 | } |
881 | - if ( $user_answer_id ) { |
|
882 | - $answer_notes = base64_decode( get_comment_meta( $user_answer_id, 'answer_note', true ) ); |
|
881 | + if ($user_answer_id) { |
|
882 | + $answer_notes = base64_decode(get_comment_meta($user_answer_id, 'answer_note', true)); |
|
883 | 883 | } |
884 | 884 | } |
885 | 885 | |
886 | 886 | return $answer_notes; |
887 | 887 | } |
888 | 888 | |
889 | - public static function sensei_delete_quiz_answers( $quiz_id = 0, $user_id = 0 ) { |
|
890 | - if( intval( $user_id ) == 0 ) { |
|
889 | + public static function sensei_delete_quiz_answers($quiz_id = 0, $user_id = 0) { |
|
890 | + if (intval($user_id) == 0) { |
|
891 | 891 | $user_id = get_current_user_id(); |
892 | 892 | } |
893 | 893 | |
894 | 894 | $delete_answers = false; |
895 | - if( intval( $quiz_id ) > 0 ) { |
|
896 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
897 | - foreach( $questions as $question ) { |
|
898 | - $delete_answers = Sensei_Utils::sensei_delete_activities( array( 'post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ) ); |
|
895 | + if (intval($quiz_id) > 0) { |
|
896 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
897 | + foreach ($questions as $question) { |
|
898 | + $delete_answers = Sensei_Utils::sensei_delete_activities(array('post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer')); |
|
899 | 899 | } |
900 | 900 | } |
901 | 901 | |
902 | 902 | return $delete_answers; |
903 | 903 | } |
904 | 904 | |
905 | - public static function sensei_delete_quiz_grade( $quiz_id = 0, $user_id = 0 ) { |
|
906 | - if( intval( $user_id ) == 0 ) { |
|
905 | + public static function sensei_delete_quiz_grade($quiz_id = 0, $user_id = 0) { |
|
906 | + if (intval($user_id) == 0) { |
|
907 | 907 | $user_id = get_current_user_id(); |
908 | 908 | } |
909 | 909 | |
910 | 910 | $delete_grade = false; |
911 | - if( intval( $quiz_id ) > 0 ) { |
|
912 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
913 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
914 | - $delete_grade = delete_comment_meta( $user_lesson_status->comment_ID, 'grade' ); |
|
911 | + if (intval($quiz_id) > 0) { |
|
912 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
913 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
914 | + $delete_grade = delete_comment_meta($user_lesson_status->comment_ID, 'grade'); |
|
915 | 915 | } |
916 | 916 | |
917 | 917 | return $delete_grade; |
@@ -924,20 +924,20 @@ discard block |
||
924 | 924 | * @param string $notes |
925 | 925 | * @return boolean |
926 | 926 | */ |
927 | - public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) { |
|
928 | - if( intval( $user_id ) == 0 ) { |
|
927 | + public static function sensei_add_answer_notes($question_id = 0, $user_id = 0, $notes = '') { |
|
928 | + if (intval($user_id) == 0) { |
|
929 | 929 | $user_id = get_current_user_id(); |
930 | 930 | } |
931 | 931 | |
932 | 932 | $activity_logged = false; |
933 | 933 | |
934 | - if( intval( $question_id ) > 0 ) { |
|
935 | - $notes = base64_encode( $notes ); |
|
934 | + if (intval($question_id) > 0) { |
|
935 | + $notes = base64_encode($notes); |
|
936 | 936 | |
937 | 937 | // Don't store empty values, no point |
938 | - if ( !empty($notes) ) { |
|
939 | - $user_lesson_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) ); |
|
940 | - $activity_logged = update_comment_meta( $user_lesson_id, 'answer_note', $notes ); |
|
938 | + if ( ! empty($notes)) { |
|
939 | + $user_lesson_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID')); |
|
940 | + $activity_logged = update_comment_meta($user_lesson_id, 'answer_note', $notes); |
|
941 | 941 | } |
942 | 942 | else { |
943 | 943 | $activity_logged = true; |
@@ -953,16 +953,16 @@ discard block |
||
953 | 953 | * @param array $return_array data to be ordered |
954 | 954 | * @return array $return_array ordered data |
955 | 955 | */ |
956 | - public static function array_sort_reorder( $return_array ) { |
|
957 | - if ( isset( $_GET['orderby'] ) && '' != esc_html( $_GET['orderby'] ) ) { |
|
956 | + public static function array_sort_reorder($return_array) { |
|
957 | + if (isset($_GET['orderby']) && '' != esc_html($_GET['orderby'])) { |
|
958 | 958 | $sort_key = ''; |
959 | 959 | // if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->sortable_columns ) ) { |
960 | 960 | // $sort_key = esc_html( $_GET['orderby'] ); |
961 | 961 | // } // End If Statement |
962 | - if ( '' != $sort_key ) { |
|
963 | - Sensei_Utils::sort_array_by_key($return_array,$sort_key); |
|
964 | - if ( isset( $_GET['order'] ) && 'desc' == esc_html( $_GET['order'] ) ) { |
|
965 | - $return_array = array_reverse( $return_array, true ); |
|
962 | + if ('' != $sort_key) { |
|
963 | + Sensei_Utils::sort_array_by_key($return_array, $sort_key); |
|
964 | + if (isset($_GET['order']) && 'desc' == esc_html($_GET['order'])) { |
|
965 | + $return_array = array_reverse($return_array, true); |
|
966 | 966 | } // End If Statement |
967 | 967 | } // End If Statement |
968 | 968 | return $return_array; |
@@ -978,15 +978,15 @@ discard block |
||
978 | 978 | * @param $key string column name in array |
979 | 979 | * @return void |
980 | 980 | */ |
981 | - public static function sort_array_by_key( $array, $key ) { |
|
981 | + public static function sort_array_by_key($array, $key) { |
|
982 | 982 | $sorter = array(); |
983 | 983 | $ret = array(); |
984 | - reset( $array ); |
|
985 | - foreach ( $array as $ii => $va ) { |
|
984 | + reset($array); |
|
985 | + foreach ($array as $ii => $va) { |
|
986 | 986 | $sorter[$ii] = $va[$key]; |
987 | 987 | } // End For Loop |
988 | - asort( $sorter ); |
|
989 | - foreach ( $sorter as $ii => $va ) { |
|
988 | + asort($sorter); |
|
989 | + foreach ($sorter as $ii => $va) { |
|
990 | 990 | $ret[$ii] = $array[$ii]; |
991 | 991 | } // End For Loop |
992 | 992 | $array = $ret; |
@@ -998,10 +998,10 @@ discard block |
||
998 | 998 | * @param integer $quiz_id |
999 | 999 | * @return array of quiz questions |
1000 | 1000 | */ |
1001 | - public static function lesson_quiz_questions( $quiz_id = 0 ) { |
|
1001 | + public static function lesson_quiz_questions($quiz_id = 0) { |
|
1002 | 1002 | $questions_array = array(); |
1003 | - if ( 0 < $quiz_id ) { |
|
1004 | - $question_args = array( 'post_type' => 'question', |
|
1003 | + if (0 < $quiz_id) { |
|
1004 | + $question_args = array('post_type' => 'question', |
|
1005 | 1005 | 'posts_per_page' => -1, |
1006 | 1006 | 'orderby' => 'ID', |
1007 | 1007 | 'order' => 'ASC', |
@@ -1014,7 +1014,7 @@ discard block |
||
1014 | 1014 | 'post_status' => 'any', |
1015 | 1015 | 'suppress_filters' => 0 |
1016 | 1016 | ); |
1017 | - $questions_array = get_posts( $question_args ); |
|
1017 | + $questions_array = get_posts($question_args); |
|
1018 | 1018 | } // End If Statement |
1019 | 1019 | return $questions_array; |
1020 | 1020 | } // End lesson_quiz_questions() |
@@ -1024,25 +1024,25 @@ discard block |
||
1024 | 1024 | * @param integer $course_id ID of course |
1025 | 1025 | * @return integer Pass mark for course |
1026 | 1026 | */ |
1027 | - public static function sensei_course_pass_grade( $course_id = 0 ) { |
|
1027 | + public static function sensei_course_pass_grade($course_id = 0) { |
|
1028 | 1028 | |
1029 | 1029 | |
1030 | 1030 | $course_passmark = 0; |
1031 | 1031 | |
1032 | - if( $course_id > 0 ) { |
|
1033 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
1032 | + if ($course_id > 0) { |
|
1033 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
1034 | 1034 | $lesson_count = 0; |
1035 | 1035 | $total_passmark = 0; |
1036 | - foreach( $lessons as $lesson ) { |
|
1036 | + foreach ($lessons as $lesson) { |
|
1037 | 1037 | |
1038 | 1038 | // Get Quiz ID |
1039 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
1039 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
1040 | 1040 | |
1041 | 1041 | // Check for a pass being required |
1042 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
1043 | - if ( $pass_required ) { |
|
1042 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
1043 | + if ($pass_required) { |
|
1044 | 1044 | // Get quiz passmark |
1045 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
1045 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
1046 | 1046 | |
1047 | 1047 | // Add up total passmark |
1048 | 1048 | $total_passmark += $quiz_passmark; |
@@ -1051,12 +1051,12 @@ discard block |
||
1051 | 1051 | } |
1052 | 1052 | } |
1053 | 1053 | // Might be a case of no required lessons |
1054 | - if ( $lesson_count ) { |
|
1055 | - $course_passmark = ( $total_passmark / $lesson_count ); |
|
1054 | + if ($lesson_count) { |
|
1055 | + $course_passmark = ($total_passmark / $lesson_count); |
|
1056 | 1056 | } |
1057 | 1057 | } |
1058 | 1058 | |
1059 | - return Sensei_Utils::round( $course_passmark ); |
|
1059 | + return Sensei_Utils::round($course_passmark); |
|
1060 | 1060 | } |
1061 | 1061 | |
1062 | 1062 | /** |
@@ -1065,27 +1065,27 @@ discard block |
||
1065 | 1065 | * @param integer $user_id ID of user |
1066 | 1066 | * @return integer User's total grade |
1067 | 1067 | */ |
1068 | - public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) { |
|
1068 | + public static function sensei_course_user_grade($course_id = 0, $user_id = 0) { |
|
1069 | 1069 | |
1070 | 1070 | |
1071 | - if( intval( $user_id ) == 0 ) { |
|
1071 | + if (intval($user_id) == 0) { |
|
1072 | 1072 | $user_id = get_current_user_id(); |
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | $total_grade = 0; |
1076 | 1076 | |
1077 | - if( $course_id > 0 && $user_id > 0 ) { |
|
1078 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
1077 | + if ($course_id > 0 && $user_id > 0) { |
|
1078 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
1079 | 1079 | $lesson_count = 0; |
1080 | 1080 | $total_grade = 0; |
1081 | - foreach( $lessons as $lesson ) { |
|
1081 | + foreach ($lessons as $lesson) { |
|
1082 | 1082 | |
1083 | 1083 | // Check for lesson having questions, thus a quiz, thus having a grade |
1084 | - $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true ); |
|
1085 | - if ( $has_questions ) { |
|
1086 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, $user_id ); |
|
1084 | + $has_questions = get_post_meta($lesson->ID, '_quiz_has_questions', true); |
|
1085 | + if ($has_questions) { |
|
1086 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson->ID, $user_id); |
|
1087 | 1087 | // Get user quiz grade |
1088 | - $quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1088 | + $quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
1089 | 1089 | |
1090 | 1090 | // Add up total grade |
1091 | 1091 | $total_grade += $quiz_grade; |
@@ -1095,13 +1095,13 @@ discard block |
||
1095 | 1095 | } |
1096 | 1096 | |
1097 | 1097 | // Might be a case of no lessons with quizzes |
1098 | - if ( $lesson_count ) { |
|
1099 | - $total_grade = ( $total_grade / $lesson_count ); |
|
1098 | + if ($lesson_count) { |
|
1099 | + $total_grade = ($total_grade / $lesson_count); |
|
1100 | 1100 | } |
1101 | 1101 | |
1102 | 1102 | } |
1103 | 1103 | |
1104 | - return Sensei_Utils::round( $total_grade ); |
|
1104 | + return Sensei_Utils::round($total_grade); |
|
1105 | 1105 | } |
1106 | 1106 | |
1107 | 1107 | /** |
@@ -1110,18 +1110,18 @@ discard block |
||
1110 | 1110 | * @param integer $user_id ID of user |
1111 | 1111 | * @return boolean |
1112 | 1112 | */ |
1113 | - public static function sensei_user_passed_course( $course_id = 0, $user_id = 0 ) { |
|
1114 | - if( intval( $user_id ) == 0 ) { |
|
1113 | + public static function sensei_user_passed_course($course_id = 0, $user_id = 0) { |
|
1114 | + if (intval($user_id) == 0) { |
|
1115 | 1115 | $user_id = get_current_user_id(); |
1116 | 1116 | } |
1117 | 1117 | |
1118 | 1118 | $pass = false; |
1119 | 1119 | |
1120 | - if( $course_id > 0 && $user_id > 0 ) { |
|
1121 | - $passmark = Sensei_Utils::sensei_course_pass_grade( $course_id ); |
|
1122 | - $user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); |
|
1120 | + if ($course_id > 0 && $user_id > 0) { |
|
1121 | + $passmark = Sensei_Utils::sensei_course_pass_grade($course_id); |
|
1122 | + $user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id); |
|
1123 | 1123 | |
1124 | - if( $user_grade >= $passmark ) { |
|
1124 | + if ($user_grade >= $passmark) { |
|
1125 | 1125 | $pass = true; |
1126 | 1126 | } |
1127 | 1127 | } |
@@ -1136,38 +1136,38 @@ discard block |
||
1136 | 1136 | * @param integer $user_id ID of user |
1137 | 1137 | * @return array Status code and message |
1138 | 1138 | */ |
1139 | - public static function sensei_user_course_status_message( $course_id = 0, $user_id = 0 ) { |
|
1140 | - if( intval( $user_id ) == 0 ) { |
|
1139 | + public static function sensei_user_course_status_message($course_id = 0, $user_id = 0) { |
|
1140 | + if (intval($user_id) == 0) { |
|
1141 | 1141 | $user_id = get_current_user_id(); |
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | $status = 'not_started'; |
1145 | 1145 | $box_class = 'info'; |
1146 | - $message = __( 'You have not started this course yet.', 'woothemes-sensei' ); |
|
1146 | + $message = __('You have not started this course yet.', 'woothemes-sensei'); |
|
1147 | 1147 | |
1148 | - if( $course_id > 0 && $user_id > 0 ) { |
|
1148 | + if ($course_id > 0 && $user_id > 0) { |
|
1149 | 1149 | |
1150 | - $started_course = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
1150 | + $started_course = Sensei_Utils::user_started_course($course_id, $user_id); |
|
1151 | 1151 | |
1152 | - if( $started_course ) { |
|
1153 | - $passmark = Sensei_Utils::sensei_course_pass_grade( $course_id ); // This happens inside sensei_user_passed_course()! |
|
1154 | - $user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); // This happens inside sensei_user_passed_course()! |
|
1155 | - if( $user_grade >= $passmark ) { |
|
1152 | + if ($started_course) { |
|
1153 | + $passmark = Sensei_Utils::sensei_course_pass_grade($course_id); // This happens inside sensei_user_passed_course()! |
|
1154 | + $user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id); // This happens inside sensei_user_passed_course()! |
|
1155 | + if ($user_grade >= $passmark) { |
|
1156 | 1156 | $status = 'passed'; |
1157 | 1157 | $box_class = 'tick'; |
1158 | - $message = sprintf( __( 'You have passed this course with a grade of %1$d%%.', 'woothemes-sensei' ), $user_grade ); |
|
1158 | + $message = sprintf(__('You have passed this course with a grade of %1$d%%.', 'woothemes-sensei'), $user_grade); |
|
1159 | 1159 | } else { |
1160 | 1160 | $status = 'failed'; |
1161 | 1161 | $box_class = 'alert'; |
1162 | - $message = sprintf( __( 'You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei' ), $passmark, $user_grade ); |
|
1162 | + $message = sprintf(__('You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei'), $passmark, $user_grade); |
|
1163 | 1163 | } |
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | } |
1167 | 1167 | |
1168 | - $message = apply_filters( 'sensei_user_course_status_' . $status, $message ); |
|
1168 | + $message = apply_filters('sensei_user_course_status_'.$status, $message); |
|
1169 | 1169 | |
1170 | - return array( 'status' => $status, 'box_class' => $box_class, 'message' => $message ); |
|
1170 | + return array('status' => $status, 'box_class' => $box_class, 'message' => $message); |
|
1171 | 1171 | } |
1172 | 1172 | |
1173 | 1173 | /** |
@@ -1177,94 +1177,94 @@ discard block |
||
1177 | 1177 | * @param bool $is_lesson |
1178 | 1178 | * @return array Status code and message |
1179 | 1179 | */ |
1180 | - public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) { |
|
1180 | + public static function sensei_user_quiz_status_message($lesson_id = 0, $user_id = 0, $is_lesson = false) { |
|
1181 | 1181 | global $current_user; |
1182 | - if( intval( $user_id ) == 0 ) { |
|
1182 | + if (intval($user_id) == 0) { |
|
1183 | 1183 | $user_id = $current_user->ID; |
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | $status = 'not_started'; |
1187 | 1187 | $box_class = 'info'; |
1188 | - $message = __( "You have not taken this lesson's quiz yet", 'woothemes-sensei' ); |
|
1188 | + $message = __("You have not taken this lesson's quiz yet", 'woothemes-sensei'); |
|
1189 | 1189 | $extra = ''; |
1190 | 1190 | |
1191 | - if( $lesson_id > 0 && $user_id > 0 ) { |
|
1191 | + if ($lesson_id > 0 && $user_id > 0) { |
|
1192 | 1192 | |
1193 | 1193 | // Prerequisite lesson |
1194 | - $prerequisite = get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
1194 | + $prerequisite = get_post_meta($lesson_id, '_lesson_prerequisite', true); |
|
1195 | 1195 | |
1196 | 1196 | // Course ID |
1197 | - $course_id = absint( get_post_meta( $lesson_id, '_lesson_course', true ) ); |
|
1197 | + $course_id = absint(get_post_meta($lesson_id, '_lesson_course', true)); |
|
1198 | 1198 | |
1199 | 1199 | // Has user started course |
1200 | - $started_course = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
1200 | + $started_course = Sensei_Utils::user_started_course($course_id, $user_id); |
|
1201 | 1201 | |
1202 | 1202 | // Has user completed lesson |
1203 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
1204 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
1203 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
1204 | + $lesson_complete = Sensei_Utils::user_completed_lesson($user_lesson_status); |
|
1205 | 1205 | |
1206 | 1206 | // Quiz ID |
1207 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1207 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
1208 | 1208 | |
1209 | 1209 | // Quiz grade |
1210 | 1210 | $quiz_grade = 0; |
1211 | - if ( $user_lesson_status ) { |
|
1212 | - $quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1211 | + if ($user_lesson_status) { |
|
1212 | + $quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
1213 | 1213 | } |
1214 | 1214 | |
1215 | 1215 | // Quiz passmark |
1216 | - $quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) ); |
|
1216 | + $quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true)); |
|
1217 | 1217 | $quiz_passmark_float = (float) $quiz_passmark; |
1218 | 1218 | |
1219 | 1219 | // Pass required |
1220 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
1220 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
1221 | 1221 | |
1222 | 1222 | // Quiz questions |
1223 | - $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
1223 | + $has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
1224 | 1224 | |
1225 | - if ( ! $started_course ) { |
|
1225 | + if ( ! $started_course) { |
|
1226 | 1226 | |
1227 | 1227 | $status = 'not_started_course'; |
1228 | 1228 | $box_class = 'info'; |
1229 | - $message = sprintf( __( 'Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . esc_attr( __( 'Sign Up', 'woothemes-sensei' ) ) . '">', '</a>' ); |
|
1229 | + $message = sprintf(__('Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($course_id)).'" title="'.esc_attr(__('Sign Up', 'woothemes-sensei')).'">', '</a>'); |
|
1230 | 1230 | |
1231 | - } elseif ( ! is_user_logged_in() ) { |
|
1231 | + } elseif ( ! is_user_logged_in()) { |
|
1232 | 1232 | |
1233 | 1233 | $status = 'login_required'; |
1234 | 1234 | $box_class = 'info'; |
1235 | - $message = __( 'You must be logged in to take this quiz', 'woothemes-sensei' ); |
|
1235 | + $message = __('You must be logged in to take this quiz', 'woothemes-sensei'); |
|
1236 | 1236 | |
1237 | 1237 | } |
1238 | 1238 | // Lesson/Quiz is marked as complete thus passing any quiz restrictions |
1239 | - elseif ( $lesson_complete ) { |
|
1239 | + elseif ($lesson_complete) { |
|
1240 | 1240 | |
1241 | 1241 | $status = 'passed'; |
1242 | 1242 | $box_class = 'tick'; |
1243 | 1243 | // Lesson status will be "complete" (has no Quiz) |
1244 | - if ( ! $has_quiz_questions ) { |
|
1245 | - $message = sprintf( __( 'Congratulations! You have passed this lesson.', 'woothemes-sensei' ) ); |
|
1244 | + if ( ! $has_quiz_questions) { |
|
1245 | + $message = sprintf(__('Congratulations! You have passed this lesson.', 'woothemes-sensei')); |
|
1246 | 1246 | } |
1247 | 1247 | // Lesson status will be "graded" (no passmark required so might have failed all the questions) |
1248 | - elseif ( empty( $quiz_grade ) ) { |
|
1249 | - $message = sprintf( __( 'Congratulations! You have completed this lesson.', 'woothemes-sensei' ) ); |
|
1248 | + elseif (empty($quiz_grade)) { |
|
1249 | + $message = sprintf(__('Congratulations! You have completed this lesson.', 'woothemes-sensei')); |
|
1250 | 1250 | } |
1251 | 1251 | // Lesson status will be "passed" (passmark reached) |
1252 | - elseif ( ! empty( $quiz_grade ) && abs( $quiz_grade ) >= 0 ) { |
|
1253 | - if( $is_lesson ) { |
|
1254 | - $message = sprintf( __( 'Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_grade ) ); |
|
1252 | + elseif ( ! empty($quiz_grade) && abs($quiz_grade) >= 0) { |
|
1253 | + if ($is_lesson) { |
|
1254 | + $message = sprintf(__('Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade)); |
|
1255 | 1255 | } else { |
1256 | - $message = sprintf( __( 'Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_grade ) ); |
|
1256 | + $message = sprintf(__('Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade)); |
|
1257 | 1257 | } |
1258 | 1258 | } |
1259 | 1259 | |
1260 | 1260 | // add next lesson button |
1261 | - $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
1262 | - $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
1261 | + $nav_id_array = sensei_get_prev_next_lessons($lesson_id); |
|
1262 | + $next_lesson_id = absint($nav_id_array['next_lesson']); |
|
1263 | 1263 | |
1264 | 1264 | // Output HTML |
1265 | - if ( ( 0 < $next_lesson_id ) ) { |
|
1266 | - $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
1267 | - . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
1265 | + if ((0 < $next_lesson_id)) { |
|
1266 | + $message .= ' '.'<a class="next-lesson" href="'.esc_url(get_permalink($next_lesson_id)) |
|
1267 | + . '" rel="next"><span class="meta-nav"></span>'.__('Next Lesson', 'woothemes-sensei') |
|
1268 | 1268 | .'</a>'; |
1269 | 1269 | |
1270 | 1270 | } |
@@ -1273,33 +1273,33 @@ discard block |
||
1273 | 1273 | // Lesson/Quiz not complete |
1274 | 1274 | else { |
1275 | 1275 | // Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete) |
1276 | - if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) { |
|
1276 | + if (isset($user_lesson_status->comment_approved) && 'ungraded' == $user_lesson_status->comment_approved) { |
|
1277 | 1277 | $status = 'complete'; |
1278 | 1278 | $box_class = 'info'; |
1279 | - if( $is_lesson ) { |
|
1280 | - $message = sprintf( __( 'You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . esc_attr( get_the_title( $quiz_id ) ) . '">', '</a>' ); |
|
1279 | + if ($is_lesson) { |
|
1280 | + $message = sprintf(__('You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($quiz_id)).'" title="'.esc_attr(get_the_title($quiz_id)).'">', '</a>'); |
|
1281 | 1281 | } else { |
1282 | - $message = sprintf( __( 'You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ) ); |
|
1282 | + $message = sprintf(__('You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark)); |
|
1283 | 1283 | } |
1284 | 1284 | } |
1285 | 1285 | // Lesson status must be "failed" |
1286 | - elseif ( isset( $user_lesson_status->comment_approved ) && 'failed' == $user_lesson_status->comment_approved ) { |
|
1286 | + elseif (isset($user_lesson_status->comment_approved) && 'failed' == $user_lesson_status->comment_approved) { |
|
1287 | 1287 | $status = 'failed'; |
1288 | 1288 | $box_class = 'alert'; |
1289 | - if( $is_lesson ) { |
|
1290 | - $message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ), Sensei_Utils::round( $quiz_grade ) ); |
|
1289 | + if ($is_lesson) { |
|
1290 | + $message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade)); |
|
1291 | 1291 | } else { |
1292 | - $message = sprintf( __( 'You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ), Sensei_Utils::round( $quiz_grade ) ); |
|
1292 | + $message = sprintf(__('You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade)); |
|
1293 | 1293 | } |
1294 | 1294 | } |
1295 | 1295 | // Lesson/Quiz requires a pass |
1296 | - elseif( $pass_required ) { |
|
1296 | + elseif ($pass_required) { |
|
1297 | 1297 | $status = 'not_started'; |
1298 | 1298 | $box_class = 'info'; |
1299 | - if( $is_lesson ) { |
|
1300 | - $message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ) ); |
|
1299 | + if ($is_lesson) { |
|
1300 | + $message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark)); |
|
1301 | 1301 | } else { |
1302 | - $message = sprintf( __( 'You require %1$d%% to pass this quiz.', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_passmark ) ); |
|
1302 | + $message = sprintf(__('You require %1$d%% to pass this quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark)); |
|
1303 | 1303 | } |
1304 | 1304 | } |
1305 | 1305 | } |
@@ -1307,15 +1307,15 @@ discard block |
||
1307 | 1307 | } |
1308 | 1308 | |
1309 | 1309 | // Legacy filter |
1310 | - $message = apply_filters( 'sensei_user_quiz_status_' . $status, $message ); |
|
1310 | + $message = apply_filters('sensei_user_quiz_status_'.$status, $message); |
|
1311 | 1311 | |
1312 | - if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) { |
|
1313 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1314 | - $extra = '<p><a class="button" href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '">' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '</a></p>'; |
|
1312 | + if ($is_lesson && ! in_array($status, array('login_required', 'not_started_course'))) { |
|
1313 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
1314 | + $extra = '<p><a class="button" href="'.esc_url(get_permalink($quiz_id)).'" title="'.__('View the lesson quiz', 'woothemes-sensei').'">'.__('View the lesson quiz', 'woothemes-sensei').'</a></p>'; |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | // Filter of all messages |
1318 | - return apply_filters( 'sensei_user_quiz_status', array( 'status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra ), $lesson_id, $user_id, $is_lesson ); |
|
1318 | + return apply_filters('sensei_user_quiz_status', array('status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra), $lesson_id, $user_id, $is_lesson); |
|
1319 | 1319 | } |
1320 | 1320 | |
1321 | 1321 | /** |
@@ -1325,14 +1325,14 @@ discard block |
||
1325 | 1325 | * @param integer $course_id Course ID |
1326 | 1326 | * @return mixed boolean or comment_ID |
1327 | 1327 | */ |
1328 | - public static function user_start_course( $user_id = 0, $course_id = 0 ) { |
|
1328 | + public static function user_start_course($user_id = 0, $course_id = 0) { |
|
1329 | 1329 | |
1330 | 1330 | $activity_logged = false; |
1331 | 1331 | |
1332 | - if( $user_id && $course_id ) { |
|
1332 | + if ($user_id && $course_id) { |
|
1333 | 1333 | // Check if user is already on the Course |
1334 | - $activity_logged = Sensei_Utils::user_started_course( $course_id, $user_id ); |
|
1335 | - if ( ! $activity_logged ) { |
|
1334 | + $activity_logged = Sensei_Utils::user_started_course($course_id, $user_id); |
|
1335 | + if ( ! $activity_logged) { |
|
1336 | 1336 | |
1337 | 1337 | // Add user to course |
1338 | 1338 | $course_metadata = array( |
@@ -1341,11 +1341,11 @@ discard block |
||
1341 | 1341 | 'complete' => 0, |
1342 | 1342 | ); |
1343 | 1343 | |
1344 | - $activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status = 'in-progress', $course_metadata ); |
|
1344 | + $activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status = 'in-progress', $course_metadata); |
|
1345 | 1345 | |
1346 | 1346 | // Allow further actions |
1347 | - if ( $activity_logged ) { |
|
1348 | - do_action( 'sensei_user_course_start', $user_id, $course_id ); |
|
1347 | + if ($activity_logged) { |
|
1348 | + do_action('sensei_user_course_start', $user_id, $course_id); |
|
1349 | 1349 | } |
1350 | 1350 | } |
1351 | 1351 | } |
@@ -1361,19 +1361,19 @@ discard block |
||
1361 | 1361 | * @param int $user_id |
1362 | 1362 | * @return mixed false or comment_ID |
1363 | 1363 | */ |
1364 | - public static function user_started_course( $course_id = 0, $user_id = 0 ) { |
|
1364 | + public static function user_started_course($course_id = 0, $user_id = 0) { |
|
1365 | 1365 | |
1366 | - if( $course_id ) { |
|
1367 | - if( ! $user_id ) { |
|
1366 | + if ($course_id) { |
|
1367 | + if ( ! $user_id) { |
|
1368 | 1368 | $user_id = get_current_user_id(); |
1369 | 1369 | } |
1370 | 1370 | |
1371 | - if( ! $user_id > 0 ){ |
|
1371 | + if ( ! $user_id > 0) { |
|
1372 | 1372 | return false; |
1373 | 1373 | } |
1374 | 1374 | |
1375 | - $user_course_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) ); |
|
1376 | - if( $user_course_status_id ) { |
|
1375 | + $user_course_status_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID')); |
|
1376 | + if ($user_course_status_id) { |
|
1377 | 1377 | return $user_course_status_id; |
1378 | 1378 | } |
1379 | 1379 | } |
@@ -1388,17 +1388,17 @@ discard block |
||
1388 | 1388 | * @param integer $user_id User ID |
1389 | 1389 | * @return int |
1390 | 1390 | */ |
1391 | - public static function user_complete_course( $course_id = 0, $user_id = 0 ) { |
|
1391 | + public static function user_complete_course($course_id = 0, $user_id = 0) { |
|
1392 | 1392 | global $wp_version; |
1393 | 1393 | |
1394 | - if( $course_id ) { |
|
1395 | - if( ! $user_id ) { |
|
1394 | + if ($course_id) { |
|
1395 | + if ( ! $user_id) { |
|
1396 | 1396 | $user_id = get_current_user_id(); |
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | $course_status = 'in-progress'; |
1400 | 1400 | $course_metadata = array(); |
1401 | - $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
|
1401 | + $course_completion = Sensei()->settings->settings['course_completion']; |
|
1402 | 1402 | $lessons_completed = $total_lessons = 0; |
1403 | 1403 | $lesson_status_args = array( |
1404 | 1404 | 'user_id' => $user_id, |
@@ -1407,8 +1407,8 @@ discard block |
||
1407 | 1407 | ); |
1408 | 1408 | |
1409 | 1409 | // Grab all of this Courses' lessons, looping through each... |
1410 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
1411 | - $total_lessons = count( $lesson_ids ); |
|
1410 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
1411 | + $total_lessons = count($lesson_ids); |
|
1412 | 1412 | // ...if course completion not set to 'passed', and all lessons are complete or graded, |
1413 | 1413 | // ......then all lessons are 'passed' |
1414 | 1414 | // ...else if course completion is set to 'passed', check if each lesson has questions... |
@@ -1421,29 +1421,29 @@ discard block |
||
1421 | 1421 | // The below checks if a lesson is fully completed, though maybe should be Utils::user_completed_lesson() |
1422 | 1422 | $all_lesson_statuses = array(); |
1423 | 1423 | // In WordPress 4.1 get_comments() allows a single query to cover multiple comment_post_IDs |
1424 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
1424 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
1425 | 1425 | $lesson_status_args['post__in'] = $lesson_ids; |
1426 | - $all_lesson_statuses = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true ); |
|
1426 | + $all_lesson_statuses = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true); |
|
1427 | 1427 | // Need to always return an array, even with only 1 item |
1428 | - if ( !is_array($all_lesson_statuses) ) { |
|
1429 | - $all_lesson_statuses = array( $all_lesson_statuses ); |
|
1428 | + if ( ! is_array($all_lesson_statuses)) { |
|
1429 | + $all_lesson_statuses = array($all_lesson_statuses); |
|
1430 | 1430 | } |
1431 | 1431 | } |
1432 | 1432 | // ...otherwise check each one |
1433 | 1433 | else { |
1434 | - foreach( $lesson_ids as $lesson_id ) { |
|
1434 | + foreach ($lesson_ids as $lesson_id) { |
|
1435 | 1435 | $lesson_status_args['post_id'] = $lesson_id; |
1436 | - $each_lesson_status = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true ); |
|
1436 | + $each_lesson_status = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true); |
|
1437 | 1437 | // Check for valid return before using |
1438 | - if ( !empty($each_lesson_status->comment_approved) ) { |
|
1438 | + if ( ! empty($each_lesson_status->comment_approved)) { |
|
1439 | 1439 | $all_lesson_statuses[] = $each_lesson_status; |
1440 | 1440 | } |
1441 | 1441 | } |
1442 | 1442 | } |
1443 | - foreach( $all_lesson_statuses as $lesson_status ) { |
|
1443 | + foreach ($all_lesson_statuses as $lesson_status) { |
|
1444 | 1444 | // If lessons are complete without needing quizzes to be passed |
1445 | - if ( 'passed' != $course_completion ) { |
|
1446 | - switch ( $lesson_status->comment_approved ) { |
|
1445 | + if ('passed' != $course_completion) { |
|
1446 | + switch ($lesson_status->comment_approved) { |
|
1447 | 1447 | // A user cannot 'complete' a course if a lesson... |
1448 | 1448 | case 'in-progress': // ...is still in progress |
1449 | 1449 | case 'ungraded': // ...hasn't yet been graded |
@@ -1455,7 +1455,7 @@ discard block |
||
1455 | 1455 | } |
1456 | 1456 | } |
1457 | 1457 | else { |
1458 | - switch ( $lesson_status->comment_approved ) { |
|
1458 | + switch ($lesson_status->comment_approved) { |
|
1459 | 1459 | case 'complete': // Lesson has no quiz/questions |
1460 | 1460 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
1461 | 1461 | case 'passed': // Lesson has quiz and the user passed |
@@ -1469,20 +1469,20 @@ discard block |
||
1469 | 1469 | } |
1470 | 1470 | } |
1471 | 1471 | } // Each lesson |
1472 | - if ( $lessons_completed == $total_lessons ) { |
|
1472 | + if ($lessons_completed == $total_lessons) { |
|
1473 | 1473 | $course_status = 'complete'; |
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | // Update meta data on how many lessons have been completed |
1477 | 1477 | $course_metadata['complete'] = $lessons_completed; |
1478 | 1478 | // update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above |
1479 | - $course_metadata['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ); |
|
1479 | + $course_metadata['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)); |
|
1480 | 1480 | |
1481 | - $activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status, $course_metadata ); |
|
1481 | + $activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status, $course_metadata); |
|
1482 | 1482 | |
1483 | 1483 | // Allow further actions |
1484 | - if ( 'complete' == $course_status ) { |
|
1485 | - do_action( 'sensei_user_course_end', $user_id, $course_id ); |
|
1484 | + if ('complete' == $course_status) { |
|
1485 | + do_action('sensei_user_course_end', $user_id, $course_id); |
|
1486 | 1486 | } |
1487 | 1487 | return $activity_logged; |
1488 | 1488 | } |
@@ -1498,31 +1498,31 @@ discard block |
||
1498 | 1498 | * @param int $user_id |
1499 | 1499 | * @return boolean |
1500 | 1500 | */ |
1501 | - public static function user_completed_course( $course , $user_id = 0 ) { |
|
1501 | + public static function user_completed_course($course, $user_id = 0) { |
|
1502 | 1502 | |
1503 | - if( $course ) { |
|
1504 | - if ( is_object( $course ) && is_a( $course,'WP_Comment') ) { |
|
1503 | + if ($course) { |
|
1504 | + if (is_object($course) && is_a($course, 'WP_Comment')) { |
|
1505 | 1505 | $user_course_status = $course->comment_approved; |
1506 | 1506 | } |
1507 | - elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) { |
|
1507 | + elseif ( ! is_numeric($course) && ! is_a($course, 'WP_Post')) { |
|
1508 | 1508 | $user_course_status = $course; |
1509 | 1509 | } |
1510 | 1510 | else { |
1511 | - if( ! $user_id ) { |
|
1511 | + if ( ! $user_id) { |
|
1512 | 1512 | $user_id = get_current_user_id(); |
1513 | 1513 | } |
1514 | 1514 | |
1515 | - if( is_a( $course, 'WP_Post' ) ){ |
|
1516 | - $course = $course->ID; |
|
1515 | + if (is_a($course, 'WP_Post')) { |
|
1516 | + $course = $course->ID; |
|
1517 | 1517 | } |
1518 | 1518 | |
1519 | - $user_course_status = Sensei_Utils::user_course_status( $course , $user_id ); |
|
1520 | - if( isset( $user_course_status->comment_approved ) ){ |
|
1519 | + $user_course_status = Sensei_Utils::user_course_status($course, $user_id); |
|
1520 | + if (isset($user_course_status->comment_approved)) { |
|
1521 | 1521 | $user_course_status = $user_course_status->comment_approved; |
1522 | 1522 | } |
1523 | 1523 | |
1524 | 1524 | } |
1525 | - if( $user_course_status && 'complete' == $user_course_status ) { |
|
1525 | + if ($user_course_status && 'complete' == $user_course_status) { |
|
1526 | 1526 | return true; |
1527 | 1527 | } |
1528 | 1528 | } |
@@ -1537,10 +1537,10 @@ discard block |
||
1537 | 1537 | * @param int $user_id |
1538 | 1538 | * @return mixed false or comment_ID |
1539 | 1539 | */ |
1540 | - public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) { |
|
1540 | + public static function user_started_lesson($lesson_id = 0, $user_id = 0) { |
|
1541 | 1541 | |
1542 | - if( $lesson_id ) { |
|
1543 | - if( ! $user_id ) { |
|
1542 | + if ($lesson_id) { |
|
1543 | + if ( ! $user_id) { |
|
1544 | 1544 | $user_id = get_current_user_id(); |
1545 | 1545 | } |
1546 | 1546 | |
@@ -1550,8 +1550,8 @@ discard block |
||
1550 | 1550 | 'type' => 'sensei_lesson_status', |
1551 | 1551 | 'field' => 'comment_ID' ); |
1552 | 1552 | |
1553 | - $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args ); |
|
1554 | - if( $user_lesson_status_id ) { |
|
1553 | + $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value($activity_args); |
|
1554 | + if ($user_lesson_status_id) { |
|
1555 | 1555 | return $user_lesson_status_id; |
1556 | 1556 | } |
1557 | 1557 | } |
@@ -1566,29 +1566,29 @@ discard block |
||
1566 | 1566 | * @param int $user_id |
1567 | 1567 | * @return boolean |
1568 | 1568 | */ |
1569 | - public static function user_completed_lesson( $lesson = 0, $user_id = 0 ) { |
|
1569 | + public static function user_completed_lesson($lesson = 0, $user_id = 0) { |
|
1570 | 1570 | |
1571 | - if( $lesson ) { |
|
1571 | + if ($lesson) { |
|
1572 | 1572 | $lesson_id = 0; |
1573 | - if ( is_object( $lesson ) ) { |
|
1573 | + if (is_object($lesson)) { |
|
1574 | 1574 | $user_lesson_status = $lesson->comment_approved; |
1575 | 1575 | $lesson_id = $lesson->comment_post_ID; |
1576 | 1576 | } |
1577 | - elseif ( ! is_numeric( $lesson ) ) { |
|
1577 | + elseif ( ! is_numeric($lesson)) { |
|
1578 | 1578 | $user_lesson_status = $lesson; |
1579 | 1579 | } |
1580 | 1580 | else { |
1581 | - if( ! $user_id ) { |
|
1581 | + if ( ! $user_id) { |
|
1582 | 1582 | $user_id = get_current_user_id(); |
1583 | 1583 | } |
1584 | 1584 | |
1585 | 1585 | // the user is not logged in |
1586 | - if( ! $user_id > 0 ){ |
|
1586 | + if ( ! $user_id > 0) { |
|
1587 | 1587 | return false; |
1588 | 1588 | } |
1589 | - $_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id ); |
|
1589 | + $_user_lesson_status = Sensei_Utils::user_lesson_status($lesson, $user_id); |
|
1590 | 1590 | |
1591 | - if ( $_user_lesson_status ) { |
|
1591 | + if ($_user_lesson_status) { |
|
1592 | 1592 | $user_lesson_status = $_user_lesson_status->comment_approved; |
1593 | 1593 | } |
1594 | 1594 | else { |
@@ -1596,12 +1596,12 @@ discard block |
||
1596 | 1596 | } |
1597 | 1597 | $lesson_id = $lesson; |
1598 | 1598 | } |
1599 | - if ( 'in-progress' != $user_lesson_status ) { |
|
1599 | + if ('in-progress' != $user_lesson_status) { |
|
1600 | 1600 | // Check for Passed or Completed Setting |
1601 | 1601 | // Should we be checking for the Course completion setting? Surely that should only affect the Course completion, not bypass each Lesson setting |
1602 | 1602 | // $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
1603 | 1603 | // if ( 'passed' == $course_completion ) { |
1604 | - switch( $user_lesson_status ) { |
|
1604 | + switch ($user_lesson_status) { |
|
1605 | 1605 | case 'complete': |
1606 | 1606 | case 'graded': |
1607 | 1607 | case 'passed': |
@@ -1610,13 +1610,13 @@ discard block |
||
1610 | 1610 | |
1611 | 1611 | case 'failed': |
1612 | 1612 | // This may be 'completed' depending on... |
1613 | - if ( $lesson_id ) { |
|
1613 | + if ($lesson_id) { |
|
1614 | 1614 | // Get Quiz ID, this won't be needed once all Quiz meta fields are stored on the Lesson |
1615 | - $lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1616 | - if ( $lesson_quiz_id ) { |
|
1615 | + $lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
1616 | + if ($lesson_quiz_id) { |
|
1617 | 1617 | // ...the quiz pass setting |
1618 | - $pass_required = get_post_meta( $lesson_quiz_id, '_pass_required', true ); |
|
1619 | - if ( empty($pass_required) ) { |
|
1618 | + $pass_required = get_post_meta($lesson_quiz_id, '_pass_required', true); |
|
1619 | + if (empty($pass_required)) { |
|
1620 | 1620 | // We just require the user to have done the quiz, not to have passed |
1621 | 1621 | return true; |
1622 | 1622 | } |
@@ -1639,15 +1639,15 @@ discard block |
||
1639 | 1639 | * @param int $user_id |
1640 | 1640 | * @return object |
1641 | 1641 | */ |
1642 | - public static function user_course_status( $course_id = 0, $user_id = 0 ) { |
|
1642 | + public static function user_course_status($course_id = 0, $user_id = 0) { |
|
1643 | 1643 | |
1644 | 1644 | |
1645 | - if( $course_id ) { |
|
1646 | - if( ! $user_id ) { |
|
1645 | + if ($course_id) { |
|
1646 | + if ( ! $user_id) { |
|
1647 | 1647 | $user_id = get_current_user_id(); |
1648 | 1648 | } |
1649 | 1649 | |
1650 | - $user_course_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status' ), true ); |
|
1650 | + $user_course_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status'), true); |
|
1651 | 1651 | return $user_course_status; |
1652 | 1652 | } |
1653 | 1653 | |
@@ -1662,27 +1662,27 @@ discard block |
||
1662 | 1662 | * @param int $user_id |
1663 | 1663 | * @return object | bool |
1664 | 1664 | */ |
1665 | - public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
|
1665 | + public static function user_lesson_status($lesson_id = 0, $user_id = 0) { |
|
1666 | 1666 | |
1667 | - if( ! $user_id ) { |
|
1667 | + if ( ! $user_id) { |
|
1668 | 1668 | $user_id = get_current_user_id(); |
1669 | 1669 | } |
1670 | 1670 | |
1671 | - if( $lesson_id > 0 && $user_id > 0 ) { |
|
1671 | + if ($lesson_id > 0 && $user_id > 0) { |
|
1672 | 1672 | |
1673 | - $user_lesson_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status' ), true ); |
|
1673 | + $user_lesson_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status'), true); |
|
1674 | 1674 | return $user_lesson_status; |
1675 | 1675 | } |
1676 | 1676 | |
1677 | 1677 | return false; |
1678 | 1678 | } |
1679 | 1679 | |
1680 | - public static function is_preview_lesson( $lesson_id ) { |
|
1680 | + public static function is_preview_lesson($lesson_id) { |
|
1681 | 1681 | $is_preview = false; |
1682 | 1682 | |
1683 | - if( 'lesson' == get_post_type( $lesson_id ) ) { |
|
1684 | - $lesson_preview = get_post_meta( $lesson_id, '_lesson_preview', true ); |
|
1685 | - if ( isset( $lesson_preview ) && '' != $lesson_preview ) { |
|
1683 | + if ('lesson' == get_post_type($lesson_id)) { |
|
1684 | + $lesson_preview = get_post_meta($lesson_id, '_lesson_preview', true); |
|
1685 | + if (isset($lesson_preview) && '' != $lesson_preview) { |
|
1686 | 1686 | $is_preview = true; |
1687 | 1687 | } |
1688 | 1688 | } |
@@ -1690,22 +1690,22 @@ discard block |
||
1690 | 1690 | return $is_preview; |
1691 | 1691 | } |
1692 | 1692 | |
1693 | - public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) { |
|
1693 | + public static function user_passed_quiz($quiz_id = 0, $user_id = 0) { |
|
1694 | 1694 | |
1695 | - if( ! $quiz_id ) return false; |
|
1695 | + if ( ! $quiz_id) return false; |
|
1696 | 1696 | |
1697 | - if( ! $user_id ) { |
|
1697 | + if ( ! $user_id) { |
|
1698 | 1698 | $user_id = get_current_user_id(); |
1699 | 1699 | } |
1700 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
1700 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
1701 | 1701 | |
1702 | 1702 | // Quiz Grade |
1703 | - $lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
1704 | - $quiz_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true ); |
|
1703 | + $lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
1704 | + $quiz_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true); |
|
1705 | 1705 | |
1706 | 1706 | // Check if Grade is greater than or equal to pass percentage |
1707 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
1708 | - if ( $quiz_passmark <= intval( $quiz_grade ) ) { |
|
1707 | + $quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); |
|
1708 | + if ($quiz_passmark <= intval($quiz_grade)) { |
|
1709 | 1709 | return true; |
1710 | 1710 | } |
1711 | 1711 | |
@@ -1725,9 +1725,9 @@ discard block |
||
1725 | 1725 | * |
1726 | 1726 | * @return mixed false or comment_ID |
1727 | 1727 | */ |
1728 | - public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
|
1728 | + public static function update_lesson_status($user_id, $lesson_id, $status = 'in-progress', $metadata = array()) { |
|
1729 | 1729 | $comment_id = false; |
1730 | - if ( !empty($status) ) { |
|
1730 | + if ( ! empty($status)) { |
|
1731 | 1731 | $args = array( |
1732 | 1732 | 'user_id' => $user_id, |
1733 | 1733 | 'post_id' => $lesson_id, |
@@ -1736,18 +1736,18 @@ discard block |
||
1736 | 1736 | 'action' => 'update', // Update the existing status... |
1737 | 1737 | 'keep_time' => true, // ...but don't change the existing timestamp |
1738 | 1738 | ); |
1739 | - if( 'in-progress' == $status ) { |
|
1740 | - unset( $args['keep_time'] ); // Keep updating what's happened |
|
1739 | + if ('in-progress' == $status) { |
|
1740 | + unset($args['keep_time']); // Keep updating what's happened |
|
1741 | 1741 | } |
1742 | 1742 | |
1743 | - $comment_id = Sensei_Utils::sensei_log_activity( $args ); |
|
1744 | - if ( $comment_id && !empty($metadata) ) { |
|
1745 | - foreach( $metadata as $key => $value ) { |
|
1746 | - update_comment_meta( $comment_id, $key, $value ); |
|
1743 | + $comment_id = Sensei_Utils::sensei_log_activity($args); |
|
1744 | + if ($comment_id && ! empty($metadata)) { |
|
1745 | + foreach ($metadata as $key => $value) { |
|
1746 | + update_comment_meta($comment_id, $key, $value); |
|
1747 | 1747 | } |
1748 | 1748 | } |
1749 | 1749 | |
1750 | - do_action( 'sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id ); |
|
1750 | + do_action('sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id); |
|
1751 | 1751 | } |
1752 | 1752 | return $comment_id; |
1753 | 1753 | } |
@@ -1763,9 +1763,9 @@ discard block |
||
1763 | 1763 | * @param array $metadata |
1764 | 1764 | * @return mixed false or comment_ID |
1765 | 1765 | */ |
1766 | - public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) { |
|
1766 | + public static function update_course_status($user_id, $course_id, $status = 'in-progress', $metadata = array()) { |
|
1767 | 1767 | $comment_id = false; |
1768 | - if ( !empty($status) ) { |
|
1768 | + if ( ! empty($status)) { |
|
1769 | 1769 | $args = array( |
1770 | 1770 | 'user_id' => $user_id, |
1771 | 1771 | 'post_id' => $course_id, |
@@ -1774,17 +1774,17 @@ discard block |
||
1774 | 1774 | 'action' => 'update', // Update the existing status... |
1775 | 1775 | 'keep_time' => true, // ...but don't change the existing timestamp |
1776 | 1776 | ); |
1777 | - if( 'in-progress' == $status ) { |
|
1778 | - unset( $args['keep_time'] ); // Keep updating what's happened |
|
1777 | + if ('in-progress' == $status) { |
|
1778 | + unset($args['keep_time']); // Keep updating what's happened |
|
1779 | 1779 | } |
1780 | 1780 | |
1781 | - $comment_id = Sensei_Utils::sensei_log_activity( $args ); |
|
1782 | - if ( $comment_id && !empty($metadata) ) { |
|
1783 | - foreach( $metadata as $key => $value ) { |
|
1784 | - update_comment_meta( $comment_id, $key, $value ); |
|
1781 | + $comment_id = Sensei_Utils::sensei_log_activity($args); |
|
1782 | + if ($comment_id && ! empty($metadata)) { |
|
1783 | + foreach ($metadata as $key => $value) { |
|
1784 | + update_comment_meta($comment_id, $key, $value); |
|
1785 | 1785 | } |
1786 | 1786 | } |
1787 | - do_action( 'sensei_course_status_updated', $status, $user_id, $course_id, $comment_id ); |
|
1787 | + do_action('sensei_course_status_updated', $status, $user_id, $course_id, $comment_id); |
|
1788 | 1788 | } |
1789 | 1789 | return $comment_id; |
1790 | 1790 | } |
@@ -1796,9 +1796,9 @@ discard block |
||
1796 | 1796 | * @param array $pieces (default: array()) |
1797 | 1797 | * @return array |
1798 | 1798 | */ |
1799 | - public static function single_comment_filter( $pieces ) { |
|
1800 | - unset( $pieces['orderby'] ); |
|
1801 | - unset( $pieces['order'] ); |
|
1799 | + public static function single_comment_filter($pieces) { |
|
1800 | + unset($pieces['orderby']); |
|
1801 | + unset($pieces['order']); |
|
1802 | 1802 | |
1803 | 1803 | return $pieces; |
1804 | 1804 | } |
@@ -1810,9 +1810,9 @@ discard block |
||
1810 | 1810 | * @param array $pieces (default: array()) |
1811 | 1811 | * @return array |
1812 | 1812 | */ |
1813 | - public static function comment_any_status_filter( $pieces ) { |
|
1813 | + public static function comment_any_status_filter($pieces) { |
|
1814 | 1814 | |
1815 | - $pieces['where'] = str_replace( array( "( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND" ), '', $pieces['where'] ); |
|
1815 | + $pieces['where'] = str_replace(array("( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND"), '', $pieces['where']); |
|
1816 | 1816 | |
1817 | 1817 | return $pieces; |
1818 | 1818 | } |
@@ -1824,12 +1824,12 @@ discard block |
||
1824 | 1824 | * @param array $pieces (default: array()) |
1825 | 1825 | * @return array |
1826 | 1826 | */ |
1827 | - public static function comment_multiple_status_filter( $pieces ) { |
|
1827 | + public static function comment_multiple_status_filter($pieces) { |
|
1828 | 1828 | |
1829 | - preg_match( "/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder ); |
|
1830 | - if ( !empty($placeholder[1]) ) { |
|
1831 | - $statuses = explode( ',', $placeholder[1] ); |
|
1832 | - $pieces['where'] = str_replace( "comment_approved = '" . $placeholder[1] . "'", "comment_approved IN ('". implode( "', '", $statuses ) . "')", $pieces['where'] ); |
|
1829 | + preg_match("/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder); |
|
1830 | + if ( ! empty($placeholder[1])) { |
|
1831 | + $statuses = explode(',', $placeholder[1]); |
|
1832 | + $pieces['where'] = str_replace("comment_approved = '".$placeholder[1]."'", "comment_approved IN ('".implode("', '", $statuses)."')", $pieces['where']); |
|
1833 | 1833 | } |
1834 | 1834 | |
1835 | 1835 | return $pieces; |
@@ -1841,12 +1841,12 @@ discard block |
||
1841 | 1841 | * @param array $pieces |
1842 | 1842 | * @return array $pieces |
1843 | 1843 | */ |
1844 | - public static function comment_total_sum_meta_value_filter( $pieces ) { |
|
1844 | + public static function comment_total_sum_meta_value_filter($pieces) { |
|
1845 | 1845 | global $wpdb, $wp_version; |
1846 | 1846 | |
1847 | 1847 | $pieces['fields'] = " COUNT(*) AS total, SUM($wpdb->commentmeta.meta_value) AS meta_sum "; |
1848 | - unset( $pieces['groupby'] ); |
|
1849 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
1848 | + unset($pieces['groupby']); |
|
1849 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
1850 | 1850 | $args['order'] = false; |
1851 | 1851 | $args['orderby'] = false; |
1852 | 1852 | } |
@@ -1861,12 +1861,12 @@ discard block |
||
1861 | 1861 | * @param array $pieces (default: array()) |
1862 | 1862 | * @return array |
1863 | 1863 | */ |
1864 | - public static function get_posts_count_only_filter( $pieces ) { |
|
1864 | + public static function get_posts_count_only_filter($pieces) { |
|
1865 | 1865 | global $wp_version; |
1866 | 1866 | |
1867 | 1867 | $pieces['fields'] = " COUNT(*) AS total "; |
1868 | - unset( $pieces['groupby'] ); |
|
1869 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
1868 | + unset($pieces['groupby']); |
|
1869 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
1870 | 1870 | $args['order'] = false; |
1871 | 1871 | $args['orderby'] = false; |
1872 | 1872 | } |
@@ -1885,9 +1885,9 @@ discard block |
||
1885 | 1885 | * |
1886 | 1886 | * @return bool $success |
1887 | 1887 | */ |
1888 | - public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
1888 | + public static function add_user_data($data_key, $post_id, $value = '', $user_id = 0) { |
|
1889 | 1889 | |
1890 | - return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
1890 | + return self::update_user_data($data_key, $post_id, $value, $user_id); |
|
1891 | 1891 | |
1892 | 1892 | }// end add_user_data |
1893 | 1893 | |
@@ -1906,18 +1906,18 @@ discard block |
||
1906 | 1906 | * |
1907 | 1907 | * @return bool $success |
1908 | 1908 | */ |
1909 | - public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
1909 | + public static function update_user_data($data_key, $post_id, $value = '', $user_id = 0) { |
|
1910 | 1910 | |
1911 | - if( ! ( $user_id > 0 ) ){ |
|
1911 | + if ( ! ($user_id > 0)) { |
|
1912 | 1912 | $user_id = get_current_user_id(); |
1913 | 1913 | } |
1914 | 1914 | |
1915 | - $supported_post_types = array( 'course', 'lesson' ); |
|
1916 | - $post_type = get_post_type( $post_id ); |
|
1917 | - if( empty( $post_id ) || empty( $data_key ) |
|
1918 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
1919 | - || !get_userdata( $user_id ) |
|
1920 | - || ! in_array( $post_type, $supported_post_types ) ){ |
|
1915 | + $supported_post_types = array('course', 'lesson'); |
|
1916 | + $post_type = get_post_type($post_id); |
|
1917 | + if (empty($post_id) || empty($data_key) |
|
1918 | + || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
1919 | + || ! get_userdata($user_id) |
|
1920 | + || ! in_array($post_type, $supported_post_types)) { |
|
1921 | 1921 | |
1922 | 1922 | return false; |
1923 | 1923 | } |
@@ -1925,20 +1925,20 @@ discard block |
||
1925 | 1925 | // check if there and existing Sensei status on this post type if not create it |
1926 | 1926 | // and get the activity ID |
1927 | 1927 | $status_function = 'user_'.$post_type.'_status'; |
1928 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
1929 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
1928 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
1929 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
1930 | 1930 | |
1931 | 1931 | $start_function = 'user_start_'.$post_type; |
1932 | - $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
1932 | + $sensei_user_activity_id = self::$start_function($user_id, $post_id); |
|
1933 | 1933 | |
1934 | - }else{ |
|
1934 | + } else { |
|
1935 | 1935 | |
1936 | 1936 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
1937 | 1937 | |
1938 | 1938 | } |
1939 | 1939 | |
1940 | 1940 | // store the data |
1941 | - $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
1941 | + $success = update_comment_meta($sensei_user_activity_id, $data_key, $value); |
|
1942 | 1942 | |
1943 | 1943 | return $success; |
1944 | 1944 | |
@@ -1957,20 +1957,20 @@ discard block |
||
1957 | 1957 | * |
1958 | 1958 | * @return mixed $user_data_value |
1959 | 1959 | */ |
1960 | - public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
1960 | + public static function get_user_data($data_key, $post_id, $user_id = 0) { |
|
1961 | 1961 | |
1962 | 1962 | $user_data_value = true; |
1963 | 1963 | |
1964 | - if( ! ( $user_id > 0 ) ){ |
|
1964 | + if ( ! ($user_id > 0)) { |
|
1965 | 1965 | $user_id = get_current_user_id(); |
1966 | 1966 | } |
1967 | 1967 | |
1968 | - $supported_post_types = array( 'course', 'lesson' ); |
|
1969 | - $post_type = get_post_type( $post_id ); |
|
1970 | - if( empty( $post_id ) || empty( $data_key ) |
|
1971 | - || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
1972 | - || ! get_userdata( $user_id ) |
|
1973 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
1968 | + $supported_post_types = array('course', 'lesson'); |
|
1969 | + $post_type = get_post_type($post_id); |
|
1970 | + if (empty($post_id) || empty($data_key) |
|
1971 | + || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
1972 | + || ! get_userdata($user_id) |
|
1973 | + || ! in_array($post_type, $supported_post_types)) { |
|
1974 | 1974 | |
1975 | 1975 | return false; |
1976 | 1976 | } |
@@ -1978,13 +1978,13 @@ discard block |
||
1978 | 1978 | // check if there and existing Sensei status on this post type if not create it |
1979 | 1979 | // and get the activity ID |
1980 | 1980 | $status_function = 'user_'.$post_type.'_status'; |
1981 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
1982 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
1981 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
1982 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
1983 | 1983 | return false; |
1984 | 1984 | } |
1985 | 1985 | |
1986 | 1986 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
1987 | - $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
1987 | + $user_data_value = get_comment_meta($sensei_user_activity_id, $data_key, true); |
|
1988 | 1988 | |
1989 | 1989 | return $user_data_value; |
1990 | 1990 | |
@@ -1999,19 +1999,19 @@ discard block |
||
1999 | 1999 | * |
2000 | 2000 | * @return bool $deleted |
2001 | 2001 | */ |
2002 | - public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
2002 | + public static function delete_user_data($data_key, $post_id, $user_id) { |
|
2003 | 2003 | $deleted = true; |
2004 | 2004 | |
2005 | - if( ! ( $user_id > 0 ) ){ |
|
2005 | + if ( ! ($user_id > 0)) { |
|
2006 | 2006 | $user_id = get_current_user_id(); |
2007 | 2007 | } |
2008 | 2008 | |
2009 | - $supported_post_types = array( 'course', 'lesson' ); |
|
2010 | - $post_type = get_post_type( $post_id ); |
|
2011 | - if( empty( $post_id ) || empty( $data_key ) |
|
2012 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
2013 | - || ! get_userdata( $user_id ) |
|
2014 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
2009 | + $supported_post_types = array('course', 'lesson'); |
|
2010 | + $post_type = get_post_type($post_id); |
|
2011 | + if (empty($post_id) || empty($data_key) |
|
2012 | + || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0) |
|
2013 | + || ! get_userdata($user_id) |
|
2014 | + || ! in_array($post_type, $supported_post_types)) { |
|
2015 | 2015 | |
2016 | 2016 | return false; |
2017 | 2017 | } |
@@ -2019,13 +2019,13 @@ discard block |
||
2019 | 2019 | // check if there and existing Sensei status on this post type if not create it |
2020 | 2020 | // and get the activity ID |
2021 | 2021 | $status_function = 'user_'.$post_type.'_status'; |
2022 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
2023 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
2022 | + $sensei_user_status = self::$status_function($post_id, $user_id); |
|
2023 | + if ( ! isset($sensei_user_status->comment_ID)) { |
|
2024 | 2024 | return false; |
2025 | 2025 | } |
2026 | 2026 | |
2027 | 2027 | $sensei_user_activity_id = $sensei_user_status->comment_ID; |
2028 | - $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
2028 | + $deleted = delete_comment_meta($sensei_user_activity_id, $data_key); |
|
2029 | 2029 | |
2030 | 2030 | return $deleted; |
2031 | 2031 | |
@@ -2050,62 +2050,62 @@ discard block |
||
2050 | 2050 | * |
2051 | 2051 | * @return string $drop_down_element |
2052 | 2052 | */ |
2053 | - public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
2053 | + public static function generate_drop_down($selected_value, $options = array(), $attributes = array(), $enable_none_option = true) { |
|
2054 | 2054 | |
2055 | 2055 | $drop_down_element = ''; |
2056 | 2056 | |
2057 | 2057 | // setup the basic attributes |
2058 | - if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
2058 | + if ( ! isset($attributes['name']) || empty($attributes['name'])) { |
|
2059 | 2059 | |
2060 | 2060 | $attributes['name'] = 'sensei-options'; |
2061 | 2061 | |
2062 | 2062 | } |
2063 | 2063 | |
2064 | - if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
2064 | + if ( ! isset($attributes['id']) || empty($attributes['id'])) { |
|
2065 | 2065 | |
2066 | 2066 | $attributes['id'] = 'sensei-options'; |
2067 | 2067 | |
2068 | 2068 | } |
2069 | 2069 | |
2070 | - if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
2070 | + if ( ! isset($attributes['class']) || empty($attributes['class'])) { |
|
2071 | 2071 | |
2072 | - $attributes['class'] ='chosen_select widefat'; |
|
2072 | + $attributes['class'] = 'chosen_select widefat'; |
|
2073 | 2073 | |
2074 | 2074 | } |
2075 | 2075 | |
2076 | 2076 | // create element attributes |
2077 | 2077 | $combined_attributes = ''; |
2078 | - foreach( $attributes as $attribute => $value ){ |
|
2078 | + foreach ($attributes as $attribute => $value) { |
|
2079 | 2079 | |
2080 | - $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
2080 | + $combined_attributes .= $attribute.'="'.$value.'"'.' '; |
|
2081 | 2081 | |
2082 | 2082 | }// end for each |
2083 | 2083 | |
2084 | 2084 | |
2085 | 2085 | // create the select element |
2086 | - $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
2086 | + $drop_down_element .= '<select '.$combined_attributes.' >'."\n"; |
|
2087 | 2087 | |
2088 | 2088 | // show the none option if the client requested |
2089 | - if( $enable_none_option ) { |
|
2090 | - $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
2089 | + if ($enable_none_option) { |
|
2090 | + $drop_down_element .= '<option value="">'.__('None', 'woothemes-sensei').'</option>'; |
|
2091 | 2091 | } |
2092 | 2092 | |
2093 | - if ( count( $options ) > 0 ) { |
|
2093 | + if (count($options) > 0) { |
|
2094 | 2094 | |
2095 | - foreach ($options as $value => $option ){ |
|
2095 | + foreach ($options as $value => $option) { |
|
2096 | 2096 | |
2097 | 2097 | $element = ''; |
2098 | - $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
2099 | - $element .= selected( $value, $selected_value, false ) . '>'; |
|
2100 | - $element .= esc_html( $option ) . '</option>' . "\n"; |
|
2098 | + $element .= '<option value="'.esc_attr($value).'"'; |
|
2099 | + $element .= selected($value, $selected_value, false).'>'; |
|
2100 | + $element .= esc_html($option).'</option>'."\n"; |
|
2101 | 2101 | |
2102 | 2102 | // add the element to the select html |
2103 | - $drop_down_element.= $element; |
|
2103 | + $drop_down_element .= $element; |
|
2104 | 2104 | } // End For Loop |
2105 | 2105 | |
2106 | 2106 | } // End If Statement |
2107 | 2107 | |
2108 | - $drop_down_element .= '</select>' . "\n"; |
|
2108 | + $drop_down_element .= '</select>'."\n"; |
|
2109 | 2109 | |
2110 | 2110 | return $drop_down_element; |
2111 | 2111 | |
@@ -2125,14 +2125,14 @@ discard block |
||
2125 | 2125 | * |
2126 | 2126 | * @return double $val |
2127 | 2127 | */ |
2128 | - public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
2128 | + public static function round($val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '') { |
|
2129 | 2129 | |
2130 | 2130 | /**å |
2131 | 2131 | * Change the precision for the Sensei_Utils::round function. |
2132 | 2132 | * the precision given will be passed into the php round function |
2133 | 2133 | * @since 1.8.5 |
2134 | 2134 | */ |
2135 | - $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
2135 | + $precision = apply_filters('sensei_round_precision', $precision, $val, $context, $mode); |
|
2136 | 2136 | |
2137 | 2137 | /** |
2138 | 2138 | * Change the mode for the Sensei_Utils::round function. |
@@ -2142,15 +2142,15 @@ discard block |
||
2142 | 2142 | * |
2143 | 2143 | * @since 1.8.5 |
2144 | 2144 | */ |
2145 | - $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
2145 | + $mode = apply_filters('sensei_round_mode', $mode, $val, $context, $precision); |
|
2146 | 2146 | |
2147 | - if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
2147 | + if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
2148 | 2148 | |
2149 | - return round( $val, $precision, $mode ); |
|
2149 | + return round($val, $precision, $mode); |
|
2150 | 2150 | |
2151 | - }else{ |
|
2151 | + } else { |
|
2152 | 2152 | |
2153 | - return round( $val, $precision ); |
|
2153 | + return round($val, $precision); |
|
2154 | 2154 | |
2155 | 2155 | } |
2156 | 2156 | |
@@ -2162,15 +2162,15 @@ discard block |
||
2162 | 2162 | * @since 1.9.0 |
2163 | 2163 | * @return string $url |
2164 | 2164 | */ |
2165 | - public static function get_current_url(){ |
|
2165 | + public static function get_current_url() { |
|
2166 | 2166 | |
2167 | 2167 | global $wp; |
2168 | - $current_url = trailingslashit( home_url( $wp->request ) ); |
|
2169 | - if ( isset( $_GET ) ) { |
|
2168 | + $current_url = trailingslashit(home_url($wp->request)); |
|
2169 | + if (isset($_GET)) { |
|
2170 | 2170 | |
2171 | - foreach ($_GET as $param => $val ) { |
|
2171 | + foreach ($_GET as $param => $val) { |
|
2172 | 2172 | |
2173 | - $current_url = add_query_arg( $param, $val , $current_url ); |
|
2173 | + $current_url = add_query_arg($param, $val, $current_url); |
|
2174 | 2174 | |
2175 | 2175 | } |
2176 | 2176 | } |
@@ -2200,27 +2200,27 @@ discard block |
||
2200 | 2200 | * @param array $array_b |
2201 | 2201 | * @return array $merged_array |
2202 | 2202 | */ |
2203 | - public static function array_zip_merge( $array_a, $array_b ){ |
|
2203 | + public static function array_zip_merge($array_a, $array_b) { |
|
2204 | 2204 | |
2205 | - if( ! isset( $array_a[0] ) || ! isset( $array_b[0] ) ){ |
|
2205 | + if ( ! isset($array_a[0]) || ! isset($array_b[0])) { |
|
2206 | 2206 | trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
2207 | 2207 | } |
2208 | 2208 | |
2209 | 2209 | $merged_array = array(); |
2210 | - $total_elements = count( $array_a ) + count( $array_b ); |
|
2210 | + $total_elements = count($array_a) + count($array_b); |
|
2211 | 2211 | |
2212 | 2212 | // Zip arrays |
2213 | - for ( $i = 0; $i < $total_elements; $i++) { |
|
2213 | + for ($i = 0; $i < $total_elements; $i++) { |
|
2214 | 2214 | |
2215 | 2215 | // if has an element at current index push a on top |
2216 | - if( isset( $array_a[ $i ] ) ){ |
|
2217 | - $merged_array[] = $array_a[ $i ] ; |
|
2216 | + if (isset($array_a[$i])) { |
|
2217 | + $merged_array[] = $array_a[$i]; |
|
2218 | 2218 | } |
2219 | 2219 | |
2220 | 2220 | // next if $array_b has an element at current index push a on top of the element |
2221 | 2221 | // from a if there was one, if not the element before that. |
2222 | - if( isset( $array_b[ $i ] ) ){ |
|
2223 | - $merged_array[] = $array_b[ $i ] ; |
|
2222 | + if (isset($array_b[$i])) { |
|
2223 | + $merged_array[] = $array_b[$i]; |
|
2224 | 2224 | } |
2225 | 2225 | |
2226 | 2226 | } |
@@ -2235,4 +2235,4 @@ discard block |
||
2235 | 2235 | * @ignore only for backward compatibility |
2236 | 2236 | * @since 1.9.0 |
2237 | 2237 | */ |
2238 | -class WooThemes_Sensei_Utils extends Sensei_Utils{} |
|
2239 | 2238 | \ No newline at end of file |
2239 | +class WooThemes_Sensei_Utils extends Sensei_Utils {} |
|
2240 | 2240 | \ No newline at end of file |
@@ -627,7 +627,7 @@ |
||
627 | 627 | $course = get_post( $this->course_id ); |
628 | 628 | $report = sanitize_title( $course->post_title ) . '-' . $this->view . 's-overview'; |
629 | 629 | if ( $this->user_id ) { |
630 | - $user_name = Sensei_Learner::get_full_name( $this->user_id ); |
|
630 | + $user_name = Sensei_Learner::get_full_name( $this->user_id ); |
|
631 | 631 | $report = sanitize_title( $user_name ) . '-' . $report; |
632 | 632 | } |
633 | 633 |
@@ -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 |
@@ -69,10 +69,10 @@ discard block |
||
69 | 69 | // Only show course & lesson excerpts in search results |
70 | 70 | add_filter( 'the_content', array( $this, 'sensei_search_results_excerpt' ) ); |
71 | 71 | |
72 | - //Use WooCommerce filter to show admin bar to Teachers. |
|
73 | - add_action( 'init', array( $this, 'sensei_show_admin_bar') ); |
|
72 | + //Use WooCommerce filter to show admin bar to Teachers. |
|
73 | + add_action( 'init', array( $this, 'sensei_show_admin_bar') ); |
|
74 | 74 | |
75 | - // Remove course from active courses if an order is cancelled or refunded |
|
75 | + // Remove course from active courses if an order is cancelled or refunded |
|
76 | 76 | add_action( 'woocommerce_order_status_processing_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 ); |
77 | 77 | add_action( 'woocommerce_order_status_completed_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 ); |
78 | 78 | add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 ); |
@@ -133,13 +133,13 @@ discard block |
||
133 | 133 | wp_enqueue_script( Sensei()->token . '-user-dashboard' ); |
134 | 134 | |
135 | 135 | |
136 | - // Course Archive javascript |
|
137 | - if( is_post_type_archive( 'course' ) ){ |
|
136 | + // Course Archive javascript |
|
137 | + if( is_post_type_archive( 'course' ) ){ |
|
138 | 138 | |
139 | - wp_register_script( 'sensei-course-archive-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/course-archive' . $suffix . '.js' ), array( 'jquery' ), '1', true ); |
|
140 | - wp_enqueue_script( 'sensei-course-archive-js' ); |
|
139 | + wp_register_script( 'sensei-course-archive-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/course-archive' . $suffix . '.js' ), array( 'jquery' ), '1', true ); |
|
140 | + wp_enqueue_script( 'sensei-course-archive-js' ); |
|
141 | 141 | |
142 | - } |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | 145 | // Allow additional scripts to be loaded |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | /** |
181 | 181 | * sensei_get_template_part function. |
182 | 182 | * |
183 | - * @deprecated sine 1.9.0 |
|
183 | + * @deprecated sine 1.9.0 |
|
184 | 184 | * @access public |
185 | 185 | * @param mixed $slug |
186 | 186 | * @param string $name (default: '') |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | */ |
189 | 189 | function sensei_get_template_part( $slug, $name = '' ) { |
190 | 190 | |
191 | - _deprecated_function( 'class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part' ); |
|
192 | - Sensei_Templates::get_part( $slug, $name ); |
|
191 | + _deprecated_function( 'class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part' ); |
|
192 | + Sensei_Templates::get_part( $slug, $name ); |
|
193 | 193 | |
194 | 194 | } // End sensei_get_template_part() |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * sensei_get_template function. |
198 | 198 | * |
199 | - * @deprecated since 1.9.0 |
|
199 | + * @deprecated since 1.9.0 |
|
200 | 200 | * @access public |
201 | 201 | * @param mixed $template_name |
202 | 202 | * @param array $args (default: array()) |
@@ -206,8 +206,8 @@ discard block |
||
206 | 206 | */ |
207 | 207 | function sensei_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
208 | 208 | |
209 | - _deprecated_function( 'sensei_get_template', '1.9.0', 'Sensei_Templates::get_template' ); |
|
210 | - Sensei_Templates::get_template($template_name, $args, $template_path, $default_path ); |
|
209 | + _deprecated_function( 'sensei_get_template', '1.9.0', 'Sensei_Templates::get_template' ); |
|
210 | + Sensei_Templates::get_template($template_name, $args, $template_path, $default_path ); |
|
211 | 211 | |
212 | 212 | } // End sensei_get_template() |
213 | 213 | |
@@ -223,33 +223,33 @@ discard block |
||
223 | 223 | */ |
224 | 224 | function sensei_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
225 | 225 | |
226 | - _deprecated_function( 'sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template' ); |
|
227 | - Sensei_Templates::locate_template( $template_name, $template_path, $default_path ); |
|
226 | + _deprecated_function( 'sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template' ); |
|
227 | + Sensei_Templates::locate_template( $template_name, $template_path, $default_path ); |
|
228 | 228 | |
229 | 229 | } // End sensei_locate_template() |
230 | 230 | |
231 | 231 | |
232 | 232 | /** |
233 | 233 | * sensei_output_content_wrapper function. |
234 | - * |
|
234 | + * |
|
235 | 235 | * @access public |
236 | 236 | * @return void |
237 | 237 | */ |
238 | 238 | function sensei_output_content_wrapper() { |
239 | 239 | |
240 | - // backwards compatibility check for old location under the wrappers directory of the active theme |
|
241 | - $backwards_compatible_wrapper_location = array( |
|
242 | - Sensei()->template_url . 'wrappers/wrapper-start.php', |
|
243 | - 'wrappers/wrapper-start.php' |
|
244 | - ); |
|
240 | + // backwards compatibility check for old location under the wrappers directory of the active theme |
|
241 | + $backwards_compatible_wrapper_location = array( |
|
242 | + Sensei()->template_url . 'wrappers/wrapper-start.php', |
|
243 | + 'wrappers/wrapper-start.php' |
|
244 | + ); |
|
245 | 245 | |
246 | - $template = locate_template( $backwards_compatible_wrapper_location ); |
|
247 | - if( !empty( $template ) ){ |
|
246 | + $template = locate_template( $backwards_compatible_wrapper_location ); |
|
247 | + if( !empty( $template ) ){ |
|
248 | 248 | |
249 | - Sensei_Templates::get_template( 'wrappers/wrapper-start.php' ); |
|
250 | - return; |
|
249 | + Sensei_Templates::get_template( 'wrappers/wrapper-start.php' ); |
|
250 | + return; |
|
251 | 251 | |
252 | - } |
|
252 | + } |
|
253 | 253 | |
254 | 254 | Sensei_Templates::get_template( 'globals/wrapper-start.php' ); |
255 | 255 | |
@@ -258,25 +258,25 @@ discard block |
||
258 | 258 | |
259 | 259 | /** |
260 | 260 | * sensei_output_content_wrapper_end function. |
261 | - * |
|
261 | + * |
|
262 | 262 | * @access public |
263 | 263 | * @return void |
264 | 264 | */ |
265 | 265 | function sensei_output_content_wrapper_end() { |
266 | 266 | |
267 | - // backwards compatibility check for old location under the wrappers directory of the active theme |
|
268 | - $backwards_compatible_wrapper_location = array( |
|
269 | - Sensei()->template_url . 'wrappers/wrapper-end.php', |
|
270 | - 'wrappers/wrapper-end.php' |
|
271 | - ); |
|
267 | + // backwards compatibility check for old location under the wrappers directory of the active theme |
|
268 | + $backwards_compatible_wrapper_location = array( |
|
269 | + Sensei()->template_url . 'wrappers/wrapper-end.php', |
|
270 | + 'wrappers/wrapper-end.php' |
|
271 | + ); |
|
272 | 272 | |
273 | - $backwards_compatible_template = locate_template( $backwards_compatible_wrapper_location ); |
|
274 | - if( !empty( $backwards_compatible_template ) ){ |
|
273 | + $backwards_compatible_template = locate_template( $backwards_compatible_wrapper_location ); |
|
274 | + if( !empty( $backwards_compatible_template ) ){ |
|
275 | 275 | |
276 | - Sensei_Templates::get_template( 'wrappers/wrapper-end.php' ); |
|
277 | - return; |
|
276 | + Sensei_Templates::get_template( 'wrappers/wrapper-end.php' ); |
|
277 | + return; |
|
278 | 278 | |
279 | - } |
|
279 | + } |
|
280 | 280 | |
281 | 281 | |
282 | 282 | Sensei_Templates::get_template( 'globals/wrapper-end.php' ); |
@@ -292,55 +292,55 @@ discard block |
||
292 | 292 | */ |
293 | 293 | public static function load_content_pagination() { |
294 | 294 | |
295 | - if( is_singular('course') ) { |
|
295 | + if( is_singular('course') ) { |
|
296 | 296 | |
297 | - // backwards compatibility check for old location under the wrappers directory of the active theme |
|
298 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-posts.php' ) ); |
|
299 | - if( !empty( $template ) ){ |
|
297 | + // backwards compatibility check for old location under the wrappers directory of the active theme |
|
298 | + $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-posts.php' ) ); |
|
299 | + if( !empty( $template ) ){ |
|
300 | 300 | |
301 | - Sensei_Templates::get_template( 'wrappers/pagination-posts.php' ); |
|
302 | - return; |
|
301 | + Sensei_Templates::get_template( 'wrappers/pagination-posts.php' ); |
|
302 | + return; |
|
303 | 303 | |
304 | - } |
|
304 | + } |
|
305 | 305 | |
306 | 306 | Sensei_Templates::get_template( 'globals/pagination-posts.php' ); |
307 | 307 | |
308 | 308 | } elseif( is_singular('lesson') ) { |
309 | 309 | |
310 | - // backwards compatibility check for old location under the wrappers directory of the active theme |
|
311 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-lesson.php' ) ); |
|
312 | - if( !empty( $template ) ){ |
|
310 | + // backwards compatibility check for old location under the wrappers directory of the active theme |
|
311 | + $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-lesson.php' ) ); |
|
312 | + if( !empty( $template ) ){ |
|
313 | 313 | |
314 | - Sensei_Templates::get_template( 'wrappers/pagination-lesson.php' ); |
|
315 | - return; |
|
314 | + Sensei_Templates::get_template( 'wrappers/pagination-lesson.php' ); |
|
315 | + return; |
|
316 | 316 | |
317 | - } |
|
317 | + } |
|
318 | 318 | |
319 | 319 | Sensei_Templates::get_template( 'globals/pagination-lesson.php' ); |
320 | 320 | |
321 | 321 | } elseif( is_singular('quiz') ) { |
322 | 322 | |
323 | - // backwards compatibility check for old location under the wrappers directory of the active theme |
|
324 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-quiz.php' ) ); |
|
325 | - if( !empty( $template ) ){ |
|
323 | + // backwards compatibility check for old location under the wrappers directory of the active theme |
|
324 | + $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-quiz.php' ) ); |
|
325 | + if( !empty( $template ) ){ |
|
326 | 326 | |
327 | - Sensei_Templates::get_template( 'wrappers/pagination-quiz.php' ); |
|
328 | - return; |
|
327 | + Sensei_Templates::get_template( 'wrappers/pagination-quiz.php' ); |
|
328 | + return; |
|
329 | 329 | |
330 | - } |
|
330 | + } |
|
331 | 331 | |
332 | 332 | Sensei_Templates::get_template( 'globals/pagination-quiz.php' ); |
333 | 333 | |
334 | 334 | } else { |
335 | 335 | |
336 | - // backwards compatibility check for old location under the wrappers directory of the active theme |
|
337 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination.php' ) ); |
|
338 | - if( !empty( $template ) ){ |
|
336 | + // backwards compatibility check for old location under the wrappers directory of the active theme |
|
337 | + $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination.php' ) ); |
|
338 | + if( !empty( $template ) ){ |
|
339 | 339 | |
340 | - Sensei_Templates::get_template( 'wrappers/pagination.php' ); |
|
341 | - return; |
|
340 | + Sensei_Templates::get_template( 'wrappers/pagination.php' ); |
|
341 | + return; |
|
342 | 342 | |
343 | - } |
|
343 | + } |
|
344 | 344 | |
345 | 345 | Sensei_Templates::get_template( 'globals/pagination.php' ); |
346 | 346 | |
@@ -397,13 +397,13 @@ discard block |
||
397 | 397 | |
398 | 398 | case '#senseimymessages': |
399 | 399 | $item->url = $my_messages_url; |
400 | - // if no archive link exist for sensei_message |
|
401 | - // set it back to the place holder |
|
402 | - if( ! $item->url ){ |
|
400 | + // if no archive link exist for sensei_message |
|
401 | + // set it back to the place holder |
|
402 | + if( ! $item->url ){ |
|
403 | 403 | |
404 | - $item->url = '#senseimymessages'; |
|
404 | + $item->url = '#senseimymessages'; |
|
405 | 405 | |
406 | - } |
|
406 | + } |
|
407 | 407 | break; |
408 | 408 | |
409 | 409 | case '#senseilearnerprofile': |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | |
470 | 470 | // Remove the My Messages link for logged out users or if Private Messages are disabled |
471 | 471 | if( ! get_post_type_archive_link( 'sensei_message' ) |
472 | - && '#senseimymessages' == $item->url ) { |
|
472 | + && '#senseimymessages' == $item->url ) { |
|
473 | 473 | |
474 | 474 | if ( !is_user_logged_in() || ( isset( Sensei()->settings->settings['messages_disable'] ) && Sensei()->settings->settings['messages_disable'] ) ) { |
475 | 475 | |
@@ -492,42 +492,42 @@ discard block |
||
492 | 492 | |
493 | 493 | // add category nicenames in body and post class |
494 | 494 | function sensei_search_results_classes($classes) { |
495 | - global $post; |
|
496 | - // Handle Search Classes for Courses, Lessons, and WC Products |
|
497 | - if ( isset( $post->post_type ) && ( ( 'course' == $post->post_type ) || ( 'lesson' == $post->post_type ) || ( 'product' == $post->post_type ) ) ) { |
|
498 | - $classes[] = 'post'; |
|
495 | + global $post; |
|
496 | + // Handle Search Classes for Courses, Lessons, and WC Products |
|
497 | + if ( isset( $post->post_type ) && ( ( 'course' == $post->post_type ) || ( 'lesson' == $post->post_type ) || ( 'product' == $post->post_type ) ) ) { |
|
498 | + $classes[] = 'post'; |
|
499 | 499 | } // End If Statement |
500 | - return $classes; |
|
500 | + return $classes; |
|
501 | 501 | } // End sensei_search_results_classes() |
502 | 502 | |
503 | - /** |
|
504 | - * sensei_single_title output for single page title |
|
505 | - * @since 1.1.0 |
|
506 | - * @return void |
|
507 | - * @deprecated |
|
508 | - */ |
|
509 | - function the_single_title() { |
|
503 | + /** |
|
504 | + * sensei_single_title output for single page title |
|
505 | + * @since 1.1.0 |
|
506 | + * @return void |
|
507 | + * @deprecated |
|
508 | + */ |
|
509 | + function the_single_title() { |
|
510 | 510 | |
511 | - _deprecated_function(' WooThemes_Sensei_Frontend::the_single_title', '1.9.0'); |
|
511 | + _deprecated_function(' WooThemes_Sensei_Frontend::the_single_title', '1.9.0'); |
|
512 | 512 | |
513 | - } // End sensei_single_title() |
|
513 | + } // End sensei_single_title() |
|
514 | 514 | |
515 | 515 | /** |
516 | 516 | * sensei_course_image output for course image Please use Sensei()->course->course_image instead. |
517 | - * |
|
518 | - * @deprecated since 1.9.0 |
|
519 | - * @param $course_id |
|
520 | - * @param string $width |
|
521 | - * @param string $height |
|
522 | - * @param bool|false $return |
|
523 | - * @return string|void |
|
517 | + * |
|
518 | + * @deprecated since 1.9.0 |
|
519 | + * @param $course_id |
|
520 | + * @param string $width |
|
521 | + * @param string $height |
|
522 | + * @param bool|false $return |
|
523 | + * @return string|void |
|
524 | 524 | */ |
525 | 525 | function sensei_course_image( $course_id, $width = '100', $height = '100', $return = false ) { |
526 | 526 | |
527 | - if ( ! $return ) { |
|
527 | + if ( ! $return ) { |
|
528 | 528 | |
529 | 529 | echo Sensei()->course->course_image( $course_id, $width, $height ); |
530 | - return ''; |
|
530 | + return ''; |
|
531 | 531 | |
532 | 532 | } // End If Statement |
533 | 533 | |
@@ -538,31 +538,31 @@ discard block |
||
538 | 538 | /** |
539 | 539 | * sensei_lesson_image output for lesson image |
540 | 540 | * @since 1.2.0 |
541 | - * @deprecated since 1.9.0 |
|
542 | - * @param $lesson_id |
|
543 | - * @param string $width |
|
544 | - * @param string $height |
|
545 | - * @param bool|false $return |
|
546 | - * @param bool|false $widget |
|
547 | - * @return string |
|
541 | + * @deprecated since 1.9.0 |
|
542 | + * @param $lesson_id |
|
543 | + * @param string $width |
|
544 | + * @param string $height |
|
545 | + * @param bool|false $return |
|
546 | + * @param bool|false $widget |
|
547 | + * @return string |
|
548 | 548 | */ |
549 | 549 | function sensei_lesson_image( $lesson_id, $width = '100', $height = '100', $return = false, $widget = false ) { |
550 | 550 | |
551 | - if( ! $return ){ |
|
551 | + if( ! $return ){ |
|
552 | 552 | |
553 | - echo Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget ); |
|
554 | - return ''; |
|
555 | - } |
|
553 | + echo Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget ); |
|
554 | + return ''; |
|
555 | + } |
|
556 | 556 | |
557 | - return Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget ); |
|
557 | + return Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget ); |
|
558 | 558 | |
559 | 559 | } // End sensei_lesson_image() |
560 | 560 | |
561 | - /** |
|
562 | - * @since 1.0.0 |
|
563 | - * @param WP_Query $query |
|
564 | - */ |
|
565 | - function sensei_course_archive_pagination( $query ) { |
|
561 | + /** |
|
562 | + * @since 1.0.0 |
|
563 | + * @param WP_Query $query |
|
564 | + */ |
|
565 | + function sensei_course_archive_pagination( $query ) { |
|
566 | 566 | |
567 | 567 | if( ! is_admin() && $query->is_main_query() && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'newcourses', 'featuredcourses', 'freecourses', 'paidcourses' ) ) ) { |
568 | 568 | |
@@ -585,50 +585,50 @@ discard block |
||
585 | 585 | * |
586 | 586 | * @access public |
587 | 587 | * @since 1.2.0 |
588 | - * @deprecated since 1.9.0 use WooThemes_Sensei_Course::archive_header |
|
588 | + * @deprecated since 1.9.0 use WooThemes_Sensei_Course::archive_header |
|
589 | 589 | * @return void |
590 | 590 | */ |
591 | 591 | function sensei_course_archive_header( ) { |
592 | 592 | |
593 | - trigger_error('This function sensei_course_archive_header has been depricated. Please use: WooThemes_Sensei_Course::course_archive_header '); |
|
594 | - WooThemes_Sensei_Course::archive_header( '', '<header class="archive-header"><h1>', '</h1></header>' ); |
|
593 | + trigger_error('This function sensei_course_archive_header has been depricated. Please use: WooThemes_Sensei_Course::course_archive_header '); |
|
594 | + WooThemes_Sensei_Course::archive_header( '', '<header class="archive-header"><h1>', '</h1></header>' ); |
|
595 | 595 | |
596 | 596 | } // sensei_course_archive_header() |
597 | 597 | |
598 | 598 | /** |
599 | 599 | * sensei_lesson_archive_header function. |
600 | 600 | * |
601 | - * @deprecated since 1.9.0 |
|
601 | + * @deprecated since 1.9.0 |
|
602 | 602 | * @access public |
603 | 603 | * @since 1.2.1 |
604 | 604 | * @return void |
605 | 605 | */ |
606 | 606 | public function sensei_lesson_archive_header( ) { |
607 | - _deprecated_function( 'WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header' ); |
|
608 | - Sensei()->lesson->the_archive_header(); |
|
607 | + _deprecated_function( 'WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header' ); |
|
608 | + Sensei()->lesson->the_archive_header(); |
|
609 | 609 | } // sensei_course_archive_header() |
610 | 610 | |
611 | - /** |
|
612 | - * @deprecated since 1.9.0 |
|
613 | - */ |
|
611 | + /** |
|
612 | + * @deprecated since 1.9.0 |
|
613 | + */ |
|
614 | 614 | public function sensei_message_archive_header( ){ |
615 | - _deprecated_function('Sensei_Frontend::sensei_message_archive_header','Please use: Sense'); |
|
616 | - Sensei_Messages::the_archive_header(); |
|
615 | + _deprecated_function('Sensei_Frontend::sensei_message_archive_header','Please use: Sense'); |
|
616 | + Sensei_Messages::the_archive_header(); |
|
617 | 617 | } // sensei_message_archive_header() |
618 | 618 | |
619 | 619 | /** |
620 | 620 | * sensei_course_archive_course_title output for course archive page individual course title |
621 | 621 | * @since 1.2.0 |
622 | - * @param WP_Post $post_item |
|
622 | + * @param WP_Post $post_item |
|
623 | 623 | * @return void |
624 | 624 | */ |
625 | 625 | function sensei_course_archive_course_title( $post_item ) { |
626 | 626 | if ( isset( $post_item->ID ) && ( 0 < $post_item->ID ) ) { |
627 | 627 | $post_id = absint( $post_item->ID ); |
628 | - $post_title = $post_item->post_title; |
|
628 | + $post_title = $post_item->post_title; |
|
629 | 629 | } else { |
630 | 630 | $post_id = get_the_ID(); |
631 | - $post_title = get_the_title(); |
|
631 | + $post_title = get_the_title(); |
|
632 | 632 | } // End If Statement |
633 | 633 | ?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php |
634 | 634 | } // End sensei_course_archive_course_title() |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | */ |
641 | 641 | public function sensei_lesson_archive_lesson_title() { |
642 | 642 | $post_id = get_the_ID(); |
643 | - $post_title = get_the_title(); |
|
643 | + $post_title = get_the_title(); |
|
644 | 644 | ?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php |
645 | 645 | } // End sensei_lesson_archive_lesson_title() |
646 | 646 | |
@@ -657,9 +657,9 @@ discard block |
||
657 | 657 | |
658 | 658 | if( empty( $id ) ){ |
659 | 659 | |
660 | - $id = get_the_ID(); |
|
660 | + $id = get_the_ID(); |
|
661 | 661 | |
662 | - } |
|
662 | + } |
|
663 | 663 | |
664 | 664 | $sensei_breadcrumb_prefix = __( 'Back to: ', 'woothemes-sensei' ); |
665 | 665 | $separator = apply_filters( 'sensei_breadcrumb_separator', '>' ); |
@@ -672,31 +672,31 @@ discard block |
||
672 | 672 | return; |
673 | 673 | } |
674 | 674 | $html .= '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Back to the course', 'woothemes-sensei' ) . '">' . get_the_title( $course_id ) . '</a>'; |
675 | - } // End If Statement |
|
676 | - // Quiz |
|
675 | + } // End If Statement |
|
676 | + // Quiz |
|
677 | 677 | if ( is_singular( 'quiz' ) && 0 < intval( $id ) ) { |
678 | 678 | $lesson_id = intval( get_post_meta( $id, '_quiz_lesson', true ) ); |
679 | 679 | if( ! $lesson_id ) { |
680 | 680 | return; |
681 | 681 | } |
682 | 682 | $html .= '<a href="' . esc_url( get_permalink( $lesson_id ) ) . '" title="' . __( 'Back to the lesson', 'woothemes-sensei' ) . '">' . get_the_title( $lesson_id ) . '</a>'; |
683 | - } // End If Statement |
|
683 | + } // End If Statement |
|
684 | 684 | |
685 | - // Allow other plugins to filter html |
|
686 | - $html = apply_filters ( 'sensei_breadcrumb_output', $html, $separator ); |
|
687 | - $html .= '</section>'; |
|
685 | + // Allow other plugins to filter html |
|
686 | + $html = apply_filters ( 'sensei_breadcrumb_output', $html, $separator ); |
|
687 | + $html .= '</section>'; |
|
688 | 688 | |
689 | - echo $html; |
|
689 | + echo $html; |
|
690 | 690 | } // End sensei_breadcrumb() |
691 | 691 | |
692 | 692 | |
693 | - /** |
|
694 | - * @deprecated since 1.9.0 use WooThemes_Sensei_Lesson::course_signup_link instead |
|
695 | - */ |
|
693 | + /** |
|
694 | + * @deprecated since 1.9.0 use WooThemes_Sensei_Lesson::course_signup_link instead |
|
695 | + */ |
|
696 | 696 | public function sensei_lesson_course_signup_link( ) { |
697 | 697 | |
698 | - _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link' ); |
|
699 | - WooThemes_Sensei_Lesson::course_signup_link(); |
|
698 | + _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link' ); |
|
699 | + WooThemes_Sensei_Lesson::course_signup_link(); |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | public function lesson_tags_display( $lesson_id = 0 ) { |
@@ -715,27 +715,27 @@ discard block |
||
715 | 715 | ?><section class="lesson-tags"> |
716 | 716 | <?php printf( __( 'Lesson tags: %1$s', 'woothemes-sensei' ), $tag_list ); ?> |
717 | 717 | </section><?php |
718 | - } |
|
719 | - } |
|
718 | + } |
|
719 | + } |
|
720 | 720 | } |
721 | 721 | } |
722 | 722 | |
723 | - /** |
|
724 | - * @param WP_Query $query |
|
725 | - */ |
|
723 | + /** |
|
724 | + * @param WP_Query $query |
|
725 | + */ |
|
726 | 726 | public function lesson_tag_archive_filter( $query ) { |
727 | - if( is_tax( 'lesson-tag' ) && $query->is_main_query() ) { |
|
728 | - // Limit to lessons only |
|
729 | - $query->set( 'post_type', 'lesson' ); |
|
727 | + if( is_tax( 'lesson-tag' ) && $query->is_main_query() ) { |
|
728 | + // Limit to lessons only |
|
729 | + $query->set( 'post_type', 'lesson' ); |
|
730 | 730 | |
731 | - // Set order of lessons |
|
732 | - $query->set( 'orderby', 'menu_order' ); |
|
733 | - $query->set( 'order', 'ASC' ); |
|
731 | + // Set order of lessons |
|
732 | + $query->set( 'orderby', 'menu_order' ); |
|
733 | + $query->set( 'order', 'ASC' ); |
|
734 | 734 | |
735 | - } |
|
736 | - } |
|
735 | + } |
|
736 | + } |
|
737 | 737 | |
738 | - public function lesson_tag_archive_header( $title ) { |
|
738 | + public function lesson_tag_archive_header( $title ) { |
|
739 | 739 | if( is_tax( 'lesson-tag' ) ) { |
740 | 740 | $title = sprintf( __( 'Lesson tag: %1$s', 'woothemes-sensei' ), apply_filters( 'sensei_lesson_tag_archive_title', get_queried_object()->name ) ); |
741 | 741 | } |
@@ -757,13 +757,13 @@ discard block |
||
757 | 757 | $sanitized_submit = esc_html( $_POST['quiz_action'] ); |
758 | 758 | |
759 | 759 | switch ($sanitized_submit) { |
760 | - case 'lesson-complete': |
|
760 | + case 'lesson-complete': |
|
761 | 761 | |
762 | 762 | Sensei_Utils::sensei_start_lesson( $post->ID, $current_user->ID, $complete = true ); |
763 | 763 | |
764 | 764 | break; |
765 | 765 | |
766 | - case 'lesson-reset': |
|
766 | + case 'lesson-reset': |
|
767 | 767 | |
768 | 768 | Sensei_Utils::sensei_remove_user_from_lesson( $post->ID, $current_user->ID ); |
769 | 769 | |
@@ -875,13 +875,13 @@ discard block |
||
875 | 875 | if ( 0 < intval( $post_id ) ) { |
876 | 876 | $lesson_video_embed = get_post_meta( $post_id, '_lesson_video_embed', true ); |
877 | 877 | if ( 'http' == substr( $lesson_video_embed, 0, 4) ) { |
878 | - // V2 - make width and height a setting for video embed |
|
879 | - $lesson_video_embed = wp_oembed_get( esc_url( $lesson_video_embed )/*, array( 'width' => 100 , 'height' => 100)*/ ); |
|
880 | - } // End If Statement |
|
881 | - if ( '' != $lesson_video_embed ) { |
|
882 | - ?><div class="video"><?php echo html_entity_decode($lesson_video_embed); ?></div><?php |
|
883 | - } // End If Statement |
|
884 | - } // End If Statement |
|
878 | + // V2 - make width and height a setting for video embed |
|
879 | + $lesson_video_embed = wp_oembed_get( esc_url( $lesson_video_embed )/*, array( 'width' => 100 , 'height' => 100)*/ ); |
|
880 | + } // End If Statement |
|
881 | + if ( '' != $lesson_video_embed ) { |
|
882 | + ?><div class="video"><?php echo html_entity_decode($lesson_video_embed); ?></div><?php |
|
883 | + } // End If Statement |
|
884 | + } // End If Statement |
|
885 | 885 | } // End sensei_lesson_video() |
886 | 886 | |
887 | 887 | public function sensei_complete_lesson_button() { |
@@ -894,8 +894,8 @@ discard block |
||
894 | 894 | $pass_required = true; |
895 | 895 | if( $quiz_id ) { |
896 | 896 | // Get quiz pass setting |
897 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
898 | - } |
|
897 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
898 | + } |
|
899 | 899 | if( ! $quiz_id || ( $quiz_id && ! $pass_required ) ) { |
900 | 900 | ?> |
901 | 901 | <form class="lesson_button_form" method="POST" action="<?php echo esc_url( get_permalink() ); ?>"> |
@@ -948,12 +948,12 @@ discard block |
||
948 | 948 | } // End If Statement |
949 | 949 | } // End sensei_reset_lesson_button() |
950 | 950 | |
951 | - /** |
|
952 | - * @deprecated since 1.9.0 |
|
953 | - */ |
|
954 | - public function sensei_lesson_quiz_meta( ) { |
|
951 | + /** |
|
952 | + * @deprecated since 1.9.0 |
|
953 | + */ |
|
954 | + public function sensei_lesson_quiz_meta( ) { |
|
955 | 955 | |
956 | - Sensei_Lesson::footer_quiz_call_to_action(); |
|
956 | + Sensei_Lesson::footer_quiz_call_to_action(); |
|
957 | 957 | |
958 | 958 | } // End sensei_lesson_quiz_meta() |
959 | 959 | |
@@ -979,38 +979,38 @@ discard block |
||
979 | 979 | </p> |
980 | 980 | <p class="course-excerpt"><?php the_excerpt(); ?></p> |
981 | 981 | <?php if ( 0 < $free_lesson_count ) { |
982 | - $free_lessons = sprintf( __( 'You can access %d of this course\'s lessons for free', 'woothemes-sensei' ), $free_lesson_count ); ?> |
|
982 | + $free_lessons = sprintf( __( 'You can access %d of this course\'s lessons for free', 'woothemes-sensei' ), $free_lesson_count ); ?> |
|
983 | 983 | <p class="sensei-free-lessons"><a href="<?php echo get_permalink( $post_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?></a> - <?php echo $free_lessons; ?></p> |
984 | 984 | <?php } ?> |
985 | 985 | </section><?php |
986 | 986 | } // End sensei_course_archive_meta() |
987 | 987 | |
988 | - /** |
|
989 | - * @deprecated since 1.9.0 |
|
990 | - */ |
|
988 | + /** |
|
989 | + * @deprecated since 1.9.0 |
|
990 | + */ |
|
991 | 991 | public function sensei_single_main_content() { |
992 | - _deprecated_function('Woothemes_Sensei_Frontend::sensei_single_main_content', '1.9.0'); |
|
992 | + _deprecated_function('Woothemes_Sensei_Frontend::sensei_single_main_content', '1.9.0'); |
|
993 | 993 | } // End sensei_single_main_content() |
994 | 994 | |
995 | - /** |
|
996 | - * @deprecated since 1.9.0 |
|
997 | - */ |
|
995 | + /** |
|
996 | + * @deprecated since 1.9.0 |
|
997 | + */ |
|
998 | 998 | public function sensei_lesson_archive_main_content() { |
999 | - _deprecated_function('Sensei_Frontend::sensei_lesson_archive_main_content', '1.9.0', 'Please include loop-lesson.php directly'); |
|
999 | + _deprecated_function('Sensei_Frontend::sensei_lesson_archive_main_content', '1.9.0', 'Please include loop-lesson.php directly'); |
|
1000 | 1000 | } // End sensei_lesson_archive_main_content() |
1001 | 1001 | |
1002 | - /** |
|
1003 | - * @deprecated since 1.9.0 |
|
1004 | - */ |
|
1002 | + /** |
|
1003 | + * @deprecated since 1.9.0 |
|
1004 | + */ |
|
1005 | 1005 | public function sensei_message_archive_main_content() { |
1006 | 1006 | _deprecated_function( 'Sensei_Frontend::sensei_message_archive_main_content', 'This method is no longer needed' ); |
1007 | 1007 | } // End sensei_lesson_archive_main_content() |
1008 | 1008 | |
1009 | - /** |
|
1010 | - * @deprecated since 1.9.0 |
|
1011 | - */ |
|
1009 | + /** |
|
1010 | + * @deprecated since 1.9.0 |
|
1011 | + */ |
|
1012 | 1012 | public function sensei_no_permissions_main_content() { |
1013 | - _deprecated_function( 'Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed' ); |
|
1013 | + _deprecated_function( 'Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed' ); |
|
1014 | 1014 | } // End sensei_no_permissions_main_content() |
1015 | 1015 | |
1016 | 1016 | public function sensei_course_category_main_content() { |
@@ -1058,7 +1058,7 @@ discard block |
||
1058 | 1058 | <div class="col-1"> |
1059 | 1059 | <?php |
1060 | 1060 | // output the actual form markup |
1061 | - Sensei_Templates::get_template( 'user/login-form.php'); |
|
1061 | + Sensei_Templates::get_template( 'user/login-form.php'); |
|
1062 | 1062 | ?> |
1063 | 1063 | </div> |
1064 | 1064 | |
@@ -1139,12 +1139,12 @@ discard block |
||
1139 | 1139 | |
1140 | 1140 | //if this is a paid course |
1141 | 1141 | if ( Sensei_WC::is_woocommerce_active() ) { |
1142 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
1143 | - if ( 0 < $wc_post_id ) { |
|
1144 | - $preview_text = __( ' (Free Preview)', 'woothemes-sensei' ); |
|
1145 | - } // End If Statement |
|
1146 | - } |
|
1147 | - return $preview_text; |
|
1142 | + $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
1143 | + if ( 0 < $wc_post_id ) { |
|
1144 | + $preview_text = __( ' (Free Preview)', 'woothemes-sensei' ); |
|
1145 | + } // End If Statement |
|
1146 | + } |
|
1147 | + return $preview_text; |
|
1148 | 1148 | } |
1149 | 1149 | |
1150 | 1150 | public function sensei_lesson_preview_title( $title = '', $id = 0 ) { |
@@ -1176,8 +1176,8 @@ discard block |
||
1176 | 1176 | $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
1177 | 1177 | // Handle user starting the course |
1178 | 1178 | if ( isset( $_POST['course_start'] ) |
1179 | - && wp_verify_nonce( $_POST[ 'woothemes_sensei_start_course_noonce' ], 'woothemes_sensei_start_course_noonce' ) |
|
1180 | - && !$is_user_taking_course ) { |
|
1179 | + && wp_verify_nonce( $_POST[ 'woothemes_sensei_start_course_noonce' ], 'woothemes_sensei_start_course_noonce' ) |
|
1180 | + && !$is_user_taking_course ) { |
|
1181 | 1181 | |
1182 | 1182 | // Start the course |
1183 | 1183 | $activity_logged = Sensei_Utils::user_start_course( $current_user->ID, $post->ID ); |
@@ -1196,35 +1196,35 @@ discard block |
||
1196 | 1196 | } // End If Statement |
1197 | 1197 | } // End sensei_course_start() |
1198 | 1198 | |
1199 | - /** |
|
1200 | - * @deprecated since 1.9.0 |
|
1201 | - */ |
|
1199 | + /** |
|
1200 | + * @deprecated since 1.9.0 |
|
1201 | + */ |
|
1202 | 1202 | public function sensei_course_meta() { |
1203 | - _deprecated_function( 'Sensei_Frontend::sensei_course_meta', '1.9.0' , 'Sensei_Course::the_course_meta()' ); |
|
1204 | - Sensei()->course->the_course_meta( get_post() ); |
|
1203 | + _deprecated_function( 'Sensei_Frontend::sensei_course_meta', '1.9.0' , 'Sensei_Course::the_course_meta()' ); |
|
1204 | + Sensei()->course->the_course_meta( get_post() ); |
|
1205 | 1205 | } // End sensei_course_meta() |
1206 | 1206 | |
1207 | - /** |
|
1208 | - * @deprecated since 1.9.0 |
|
1209 | - */ |
|
1207 | + /** |
|
1208 | + * @deprecated since 1.9.0 |
|
1209 | + */ |
|
1210 | 1210 | public function sensei_course_meta_video() { |
1211 | - _deprecated_function( 'Sensei_Frontend::sensei_course_meta_video', '1.9.0' , 'Sensei_Course::the_course_video()' ); |
|
1212 | - Sensei_Course::the_course_video(); |
|
1211 | + _deprecated_function( 'Sensei_Frontend::sensei_course_meta_video', '1.9.0' , 'Sensei_Course::the_course_video()' ); |
|
1212 | + Sensei_Course::the_course_video(); |
|
1213 | 1213 | } // End sensei_course_meta_video() |
1214 | 1214 | |
1215 | - /** |
|
1216 | - * This function shows the WooCommerce cart notice if the user has |
|
1217 | - * added the current course to cart. It does not show if the user is already taking |
|
1218 | - * the course. |
|
1219 | - * |
|
1220 | - * @since 1.0.2 |
|
1221 | - * @return void; |
|
1222 | - */ |
|
1223 | - public function sensei_woocommerce_in_cart_message() { |
|
1215 | + /** |
|
1216 | + * This function shows the WooCommerce cart notice if the user has |
|
1217 | + * added the current course to cart. It does not show if the user is already taking |
|
1218 | + * the course. |
|
1219 | + * |
|
1220 | + * @since 1.0.2 |
|
1221 | + * @return void; |
|
1222 | + */ |
|
1223 | + public function sensei_woocommerce_in_cart_message() { |
|
1224 | 1224 | global $post, $woocommerce; |
1225 | 1225 | |
1226 | 1226 | $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
1227 | - $user_course_status_id = Sensei_Utils::user_started_course($post->ID , get_current_user_id() ); |
|
1227 | + $user_course_status_id = Sensei_Utils::user_started_course($post->ID , get_current_user_id() ); |
|
1228 | 1228 | if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
1229 | 1229 | |
1230 | 1230 | if ( Sensei_WC::is_product_in_cart( $wc_post_id ) ) { |
@@ -1272,7 +1272,7 @@ discard block |
||
1272 | 1272 | $item_id = $item['product_id']; |
1273 | 1273 | } |
1274 | 1274 | |
1275 | - if ( $item_id > 0 ) { |
|
1275 | + if ( $item_id > 0 ) { |
|
1276 | 1276 | |
1277 | 1277 | $user_id = get_post_meta( $order_id, '_customer_user', true ); |
1278 | 1278 | |
@@ -1352,15 +1352,15 @@ discard block |
||
1352 | 1352 | |
1353 | 1353 | $items = $order->get_items(); |
1354 | 1354 | foreach( $items as $item ) { |
1355 | - if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
1356 | - $item_id = $item['variation_id']; |
|
1357 | - $product_type = 'variation'; |
|
1358 | - } else { |
|
1359 | - $item_id = $item['product_id']; |
|
1360 | - } |
|
1355 | + if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
1356 | + $item_id = $item['variation_id']; |
|
1357 | + $product_type = 'variation'; |
|
1358 | + } else { |
|
1359 | + $item_id = $item['product_id']; |
|
1360 | + } |
|
1361 | 1361 | |
1362 | - $product_ids[] = $item_id; |
|
1363 | - } |
|
1362 | + $product_ids[] = $item_id; |
|
1363 | + } |
|
1364 | 1364 | |
1365 | 1365 | $order_ids[] = $post_id; |
1366 | 1366 | } |
@@ -1467,32 +1467,32 @@ discard block |
||
1467 | 1467 | |
1468 | 1468 | $items = $order->get_items(); |
1469 | 1469 | foreach( $items as $item ) { |
1470 | - $product = wc_get_product( $item['product_id'] ); |
|
1470 | + $product = wc_get_product( $item['product_id'] ); |
|
1471 | 1471 | |
1472 | - // handle product bundles |
|
1473 | - if( $product->is_type('bundle') ){ |
|
1472 | + // handle product bundles |
|
1473 | + if( $product->is_type('bundle') ){ |
|
1474 | 1474 | |
1475 | - $bundled_product = new WC_Product_Bundle( $product->id ); |
|
1476 | - $bundled_items = $bundled_product->get_bundled_items(); |
|
1475 | + $bundled_product = new WC_Product_Bundle( $product->id ); |
|
1476 | + $bundled_items = $bundled_product->get_bundled_items(); |
|
1477 | 1477 | |
1478 | - foreach( $bundled_items as $bundled_item ){ |
|
1478 | + foreach( $bundled_items as $bundled_item ){ |
|
1479 | 1479 | |
1480 | - if( $bundled_item->product_id == $course_product_id ) { |
|
1481 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
1482 | - return; |
|
1483 | - } |
|
1480 | + if( $bundled_item->product_id == $course_product_id ) { |
|
1481 | + Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
1482 | + return; |
|
1483 | + } |
|
1484 | 1484 | |
1485 | - } |
|
1485 | + } |
|
1486 | 1486 | |
1487 | - } else { |
|
1487 | + } else { |
|
1488 | 1488 | |
1489 | - // handle regular products |
|
1490 | - if( $item['product_id'] == $course_product_id ) { |
|
1491 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
1492 | - return; |
|
1493 | - } |
|
1489 | + // handle regular products |
|
1490 | + if( $item['product_id'] == $course_product_id ) { |
|
1491 | + Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
1492 | + return; |
|
1493 | + } |
|
1494 | 1494 | |
1495 | - } |
|
1495 | + } |
|
1496 | 1496 | } |
1497 | 1497 | } |
1498 | 1498 | |
@@ -1523,21 +1523,21 @@ discard block |
||
1523 | 1523 | |
1524 | 1524 | //if not posted from the sensei login form let |
1525 | 1525 | // WordPress or any other party handle the failed request |
1526 | - if( ! isset( $_REQUEST['form'] ) || 'sensei-login' != $_REQUEST['form'] ){ |
|
1526 | + if( ! isset( $_REQUEST['form'] ) || 'sensei-login' != $_REQUEST['form'] ){ |
|
1527 | 1527 | |
1528 | - return ; |
|
1528 | + return ; |
|
1529 | 1529 | |
1530 | - } |
|
1530 | + } |
|
1531 | 1531 | |
1532 | - // Get the reffering page, where did the post submission come from? |
|
1533 | - $referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']); |
|
1532 | + // Get the reffering page, where did the post submission come from? |
|
1533 | + $referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']); |
|
1534 | 1534 | |
1535 | 1535 | // if there's a valid referrer, and it's not the default log-in screen |
1536 | - if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){ |
|
1537 | - // let's append some information (login=failed) to the URL for the theme to use |
|
1538 | - wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
1539 | - exit; |
|
1540 | - } |
|
1536 | + if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){ |
|
1537 | + // let's append some information (login=failed) to the URL for the theme to use |
|
1538 | + wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
1539 | + exit; |
|
1540 | + } |
|
1541 | 1541 | }// End sensei_login_fail_redirect_to_front_end_login |
1542 | 1542 | |
1543 | 1543 | /** |
@@ -1548,46 +1548,46 @@ discard block |
||
1548 | 1548 | function sensei_handle_login_request( ) { |
1549 | 1549 | |
1550 | 1550 | // Check that it is a sensei login request and if it has a valid nonce |
1551 | - if( isset( $_REQUEST['form'] ) && 'sensei-login' == $_REQUEST['form'] ) { |
|
1551 | + if( isset( $_REQUEST['form'] ) && 'sensei-login' == $_REQUEST['form'] ) { |
|
1552 | 1552 | |
1553 | - // Validate the login request nonce |
|
1554 | - if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'sensei-login' ) ){ |
|
1555 | - return; |
|
1556 | - } |
|
1553 | + // Validate the login request nonce |
|
1554 | + if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'sensei-login' ) ){ |
|
1555 | + return; |
|
1556 | + } |
|
1557 | 1557 | |
1558 | - //get the page where the sensei log form is located |
|
1559 | - $referrer = $_REQUEST['_wp_http_referer']; |
|
1560 | - //$redirect = $_REQUEST['_sensei_redirect']; |
|
1558 | + //get the page where the sensei log form is located |
|
1559 | + $referrer = $_REQUEST['_wp_http_referer']; |
|
1560 | + //$redirect = $_REQUEST['_sensei_redirect']; |
|
1561 | 1561 | |
1562 | - if ( ( isset( $_REQUEST['log'] ) && !empty( $_REQUEST['log'] ) ) |
|
1563 | - && ( isset( $_REQUEST['pwd'] ) && !empty( $_REQUEST['pwd'] ) ) ){ |
|
1562 | + if ( ( isset( $_REQUEST['log'] ) && !empty( $_REQUEST['log'] ) ) |
|
1563 | + && ( isset( $_REQUEST['pwd'] ) && !empty( $_REQUEST['pwd'] ) ) ){ |
|
1564 | 1564 | |
1565 | - // when the user has entered a password or username do the sensei login |
|
1566 | - $creds = array(); |
|
1565 | + // when the user has entered a password or username do the sensei login |
|
1566 | + $creds = array(); |
|
1567 | 1567 | |
1568 | - // check if the requests login is an email address |
|
1569 | - if( is_email( trim( $_REQUEST['log'] ) ) ){ |
|
1570 | - // query wordpress for the users details |
|
1571 | - $user = get_user_by( 'email', sanitize_email( $_REQUEST['log'] ) ); |
|
1568 | + // check if the requests login is an email address |
|
1569 | + if( is_email( trim( $_REQUEST['log'] ) ) ){ |
|
1570 | + // query wordpress for the users details |
|
1571 | + $user = get_user_by( 'email', sanitize_email( $_REQUEST['log'] ) ); |
|
1572 | 1572 | |
1573 | - // validate the user object |
|
1574 | - if( !$user ){ |
|
1573 | + // validate the user object |
|
1574 | + if( !$user ){ |
|
1575 | 1575 | |
1576 | - // the email doesnt exist |
|
1577 | - wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
1578 | - exit; |
|
1576 | + // the email doesnt exist |
|
1577 | + wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
1578 | + exit; |
|
1579 | 1579 | |
1580 | - } |
|
1580 | + } |
|
1581 | 1581 | |
1582 | - //assigne the username to the creds array for further processing |
|
1583 | - $creds['user_login'] = $user->user_login ; |
|
1582 | + //assigne the username to the creds array for further processing |
|
1583 | + $creds['user_login'] = $user->user_login ; |
|
1584 | 1584 | |
1585 | - }else{ |
|
1585 | + }else{ |
|
1586 | 1586 | |
1587 | - // process this as a default username login |
|
1588 | - $creds['user_login'] = sanitize_text_field( $_REQUEST['log'] ) ; |
|
1587 | + // process this as a default username login |
|
1588 | + $creds['user_login'] = sanitize_text_field( $_REQUEST['log'] ) ; |
|
1589 | 1589 | |
1590 | - } |
|
1590 | + } |
|
1591 | 1591 | |
1592 | 1592 | // get setup the rest of the creds array |
1593 | 1593 | $creds['user_password'] = sanitize_text_field( $_REQUEST['pwd'] ); |
@@ -1597,42 +1597,42 @@ discard block |
||
1597 | 1597 | $user = wp_signon( $creds, false ); |
1598 | 1598 | |
1599 | 1599 | if ( is_wp_error($user) ){ // on login failure |
1600 | - wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
1601 | - exit; |
|
1600 | + wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
1601 | + exit; |
|
1602 | 1602 | }else{ // on login success |
1603 | 1603 | |
1604 | 1604 | /** |
1605 | - * change the redirect url programatically |
|
1606 | - * |
|
1607 | - * @since 1.6.1 |
|
1608 | - * |
|
1609 | - * @param string $referrer the page where the current url wheresensei login form was posted from |
|
1610 | - */ |
|
1605 | + * change the redirect url programatically |
|
1606 | + * |
|
1607 | + * @since 1.6.1 |
|
1608 | + * |
|
1609 | + * @param string $referrer the page where the current url wheresensei login form was posted from |
|
1610 | + */ |
|
1611 | 1611 | |
1612 | 1612 | $success_redirect_url = apply_filters('sesei_login_success_redirect_url', remove_query_arg( 'login', $referrer ) ); |
1613 | 1613 | |
1614 | 1614 | wp_redirect( esc_url_raw( $success_redirect_url ) ); |
1615 | - exit; |
|
1615 | + exit; |
|
1616 | 1616 | |
1617 | 1617 | } // end is_wp_error($user) |
1618 | 1618 | |
1619 | - }else{ // if username or password is empty |
|
1619 | + }else{ // if username or password is empty |
|
1620 | 1620 | |
1621 | - wp_redirect( esc_url_raw( add_query_arg('login', 'emptyfields', $referrer) ) ); |
|
1622 | - exit; |
|
1621 | + wp_redirect( esc_url_raw( add_query_arg('login', 'emptyfields', $referrer) ) ); |
|
1622 | + exit; |
|
1623 | 1623 | |
1624 | - } // end if username $_REQUEST['log'] and password $_REQUEST['pwd'] is empty |
|
1624 | + } // end if username $_REQUEST['log'] and password $_REQUEST['pwd'] is empty |
|
1625 | 1625 | |
1626 | - }elseif( ( isset( $_GET['login'] ) ) ) { |
|
1627 | - // else if this request is a redircect from a previously faile login request |
|
1628 | - $this->login_message_process(); |
|
1626 | + }elseif( ( isset( $_GET['login'] ) ) ) { |
|
1627 | + // else if this request is a redircect from a previously faile login request |
|
1628 | + $this->login_message_process(); |
|
1629 | 1629 | |
1630 | 1630 | //exit the handle login request function |
1631 | 1631 | return; |
1632 | - } |
|
1632 | + } |
|
1633 | 1633 | |
1634 | - // if none of the above |
|
1635 | - return; |
|
1634 | + // if none of the above |
|
1635 | + return; |
|
1636 | 1636 | |
1637 | 1637 | } // End sensei_login_fail_redirect_to_front_end_login |
1638 | 1638 | |
@@ -1735,7 +1735,7 @@ discard block |
||
1735 | 1735 | */ |
1736 | 1736 | public function login_message_process(){ |
1737 | 1737 | |
1738 | - // setup the message variables |
|
1738 | + // setup the message variables |
|
1739 | 1739 | $message = ''; |
1740 | 1740 | |
1741 | 1741 | //only output message if the url contains login=failed and login=emptyfields |
@@ -1754,22 +1754,22 @@ discard block |
||
1754 | 1754 | }// end login_message_process |
1755 | 1755 | |
1756 | 1756 | |
1757 | - /** |
|
1758 | - * sensei_show_admin_bar(). Use WooCommerce filter |
|
1759 | - * to show admin bar to Teachers as well. |
|
1760 | - * |
|
1761 | - * @return void redirect |
|
1762 | - * |
|
1763 | - */ |
|
1764 | - public function sensei_show_admin_bar () { |
|
1757 | + /** |
|
1758 | + * sensei_show_admin_bar(). Use WooCommerce filter |
|
1759 | + * to show admin bar to Teachers as well. |
|
1760 | + * |
|
1761 | + * @return void redirect |
|
1762 | + * |
|
1763 | + */ |
|
1764 | + public function sensei_show_admin_bar () { |
|
1765 | 1765 | |
1766 | - if (current_user_can('edit_courses')) { |
|
1766 | + if (current_user_can('edit_courses')) { |
|
1767 | 1767 | |
1768 | - add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1); |
|
1768 | + add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1); |
|
1769 | 1769 | |
1770 | - } |
|
1770 | + } |
|
1771 | 1771 | |
1772 | - } |
|
1772 | + } |
|
1773 | 1773 | |
1774 | 1774 | } // End Class |
1775 | 1775 |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | |
79 | 79 | // Load Learners JS |
80 | 80 | wp_enqueue_script( 'sensei-learners-general', |
81 | - Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js', |
|
82 | - array('jquery','select2','sensei-chosen-ajax' ), Sensei()->version, true ); |
|
81 | + Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js', |
|
82 | + array('jquery','select2','sensei-chosen-ajax' ), Sensei()->version, true ); |
|
83 | 83 | |
84 | 84 | $data = array( |
85 | 85 | 'remove_generic_confirm' => __( 'Are you sure you want to remove this user?', 'woothemes-sensei' ), |
86 | 86 | 'remove_from_lesson_confirm' => __( 'Are you sure you want to remove the user from this lesson?', 'woothemes-sensei' ), |
87 | 87 | 'remove_from_course_confirm' => __( 'Are you sure you want to remove the user from this course?', 'woothemes-sensei' ), |
88 | 88 | 'remove_user_from_post_nonce' => wp_create_nonce( 'remove_user_from_post_nonce' ), |
89 | - 'search_users_nonce' => wp_create_nonce( 'search-users' ), |
|
90 | - 'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' ) |
|
89 | + 'search_users_nonce' => wp_create_nonce( 'search-users' ), |
|
90 | + 'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' ) |
|
91 | 91 | ); |
92 | 92 | |
93 | 93 | wp_localize_script( 'sensei-learners-general', 'woo_learners_general_data', $data ); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | /** |
187 | 187 | * learners_headers outputs Learners general headers |
188 | 188 | * @since 1.6.0 |
189 | - * @param array $args |
|
189 | + * @param array $args |
|
190 | 190 | * @return void |
191 | 191 | */ |
192 | 192 | public function learners_headers( $args = array( 'nav' => 'default' ) ) { |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | |
282 | 282 | case 'course': |
283 | 283 | |
284 | - $removed = Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id ); |
|
284 | + $removed = Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id ); |
|
285 | 285 | |
286 | 286 | break; |
287 | 287 | |
@@ -328,19 +328,19 @@ discard block |
||
328 | 328 | |
329 | 329 | if ( $users ) { |
330 | 330 | foreach ( $users as $user ) { |
331 | - $full_name = Sensei_Learner::get_full_name( $user->ID ); |
|
331 | + $full_name = Sensei_Learner::get_full_name( $user->ID ); |
|
332 | 332 | |
333 | - if( trim($user->display_name ) == trim( $full_name ) ){ |
|
333 | + if( trim($user->display_name ) == trim( $full_name ) ){ |
|
334 | 334 | |
335 | - $name = $full_name; |
|
335 | + $name = $full_name; |
|
336 | 336 | |
337 | - }else{ |
|
337 | + }else{ |
|
338 | 338 | |
339 | - $name = $full_name . ' ['. $user->display_name .']'; |
|
339 | + $name = $full_name . ' ['. $user->display_name .']'; |
|
340 | 340 | |
341 | - } |
|
341 | + } |
|
342 | 342 | |
343 | - $found_users[ $user->ID ] = $name . ' (#' . $user->ID . ' – ' . sanitize_email( $user->user_email ) . ')'; |
|
343 | + $found_users[ $user->ID ] = $name . ' (#' . $user->ID . ' – ' . sanitize_email( $user->user_email ) . ')'; |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | break; |
385 | 385 | |
386 | 386 | case 'lesson': |
387 | - $lesson_id = absint( $_POST['add_lesson_id'] ); |
|
387 | + $lesson_id = absint( $_POST['add_lesson_id'] ); |
|
388 | 388 | $complete = false; |
389 | 389 | if( isset( $_POST['add_complete_lesson'] ) && 'yes' == $_POST['add_complete_lesson'] ) { |
390 | 390 | $complete = true; |
@@ -444,23 +444,23 @@ discard block |
||
444 | 444 | } |
445 | 445 | } |
446 | 446 | |
447 | - /** |
|
448 | - * Return the full name and surname or the display name of the user. |
|
449 | - * |
|
450 | - * The user must have both name and surname otherwise display name will be returned. |
|
451 | - * |
|
452 | - * @deprecated since 1.9.0 use Se |
|
453 | - * @since 1.8.0 |
|
454 | - * |
|
455 | - * @param int $user_id | bool false for an invalid $user_id |
|
456 | - * |
|
457 | - * @return string $full_name |
|
458 | - */ |
|
459 | - public function get_learner_full_name( $user_id ){ |
|
460 | - |
|
461 | - return Sensei_Learner::get_full_name( $user_id ); |
|
462 | - |
|
463 | - } // end get_learner_full_name |
|
447 | + /** |
|
448 | + * Return the full name and surname or the display name of the user. |
|
449 | + * |
|
450 | + * The user must have both name and surname otherwise display name will be returned. |
|
451 | + * |
|
452 | + * @deprecated since 1.9.0 use Se |
|
453 | + * @since 1.8.0 |
|
454 | + * |
|
455 | + * @param int $user_id | bool false for an invalid $user_id |
|
456 | + * |
|
457 | + * @return string $full_name |
|
458 | + */ |
|
459 | + public function get_learner_full_name( $user_id ){ |
|
460 | + |
|
461 | + return Sensei_Learner::get_full_name( $user_id ); |
|
462 | + |
|
463 | + } // end get_learner_full_name |
|
464 | 464 | |
465 | 465 | } // End Class |
466 | 466 |
@@ -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 Class |
@@ -22,30 +22,30 @@ discard block |
||
22 | 22 | * @since 1.6.0 |
23 | 23 | * @return void |
24 | 24 | */ |
25 | - public function __construct ( $file ) { |
|
26 | - $this->name = __( 'Learner Management', 'woothemes-sensei' );; |
|
25 | + public function __construct($file) { |
|
26 | + $this->name = __('Learner Management', 'woothemes-sensei'); ; |
|
27 | 27 | $this->file = $file; |
28 | 28 | $this->page_slug = 'sensei_learners'; |
29 | 29 | |
30 | 30 | // Admin functions |
31 | - if ( is_admin() ) { |
|
32 | - add_action( 'admin_menu', array( $this, 'learners_admin_menu' ), 30); |
|
33 | - add_action( 'learners_wrapper_container', array( $this, 'wrapper_container' ) ); |
|
34 | - if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) { |
|
35 | - add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) ); |
|
36 | - add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) ); |
|
31 | + if (is_admin()) { |
|
32 | + add_action('admin_menu', array($this, 'learners_admin_menu'), 30); |
|
33 | + add_action('learners_wrapper_container', array($this, 'wrapper_container')); |
|
34 | + if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) { |
|
35 | + add_action('admin_print_scripts', array($this, 'enqueue_scripts')); |
|
36 | + add_action('admin_print_styles', array($this, 'enqueue_styles')); |
|
37 | 37 | } |
38 | 38 | |
39 | - add_action( 'admin_init', array( $this, 'add_new_learners' ) ); |
|
39 | + add_action('admin_init', array($this, 'add_new_learners')); |
|
40 | 40 | |
41 | - add_action( 'admin_notices', array( $this, 'add_learner_notices' ) ); |
|
41 | + add_action('admin_notices', array($this, 'add_learner_notices')); |
|
42 | 42 | } // End If Statement |
43 | 43 | |
44 | 44 | // Ajax functions |
45 | - if ( is_admin() ) { |
|
46 | - add_action( 'wp_ajax_get_redirect_url_learners', array( $this, 'get_redirect_url' ) ); |
|
47 | - add_action( 'wp_ajax_remove_user_from_post', array( $this, 'remove_user_from_post' ) ); |
|
48 | - add_action( 'wp_ajax_sensei_json_search_users', array( $this, 'json_search_users' ) ); |
|
45 | + if (is_admin()) { |
|
46 | + add_action('wp_ajax_get_redirect_url_learners', array($this, 'get_redirect_url')); |
|
47 | + add_action('wp_ajax_remove_user_from_post', array($this, 'remove_user_from_post')); |
|
48 | + add_action('wp_ajax_sensei_json_search_users', array($this, 'json_search_users')); |
|
49 | 49 | } |
50 | 50 | } // End __construct() |
51 | 51 | |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | public function learners_admin_menu() { |
59 | 59 | global $menu; |
60 | 60 | |
61 | - if ( current_user_can( 'manage_sensei_grades' ) ) { |
|
62 | - $learners_page = add_submenu_page( 'sensei', $this->name, $this->name, 'manage_sensei_grades', $this->page_slug, array( $this, 'learners_page' ) ); |
|
61 | + if (current_user_can('manage_sensei_grades')) { |
|
62 | + $learners_page = add_submenu_page('sensei', $this->name, $this->name, 'manage_sensei_grades', $this->page_slug, array($this, 'learners_page')); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | } // End learners_admin_menu() |
@@ -72,25 +72,25 @@ discard block |
||
72 | 72 | * @since 1.6.0 |
73 | 73 | * @return void |
74 | 74 | */ |
75 | - public function enqueue_scripts () { |
|
75 | + public function enqueue_scripts() { |
|
76 | 76 | |
77 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
77 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
78 | 78 | |
79 | 79 | // Load Learners JS |
80 | - wp_enqueue_script( 'sensei-learners-general', |
|
81 | - Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js', |
|
82 | - array('jquery','select2','sensei-chosen-ajax' ), Sensei()->version, true ); |
|
80 | + wp_enqueue_script('sensei-learners-general', |
|
81 | + Sensei()->plugin_url.'assets/js/learners-general'.$suffix.'.js', |
|
82 | + array('jquery', 'select2', 'sensei-chosen-ajax'), Sensei()->version, true); |
|
83 | 83 | |
84 | 84 | $data = array( |
85 | - 'remove_generic_confirm' => __( 'Are you sure you want to remove this user?', 'woothemes-sensei' ), |
|
86 | - 'remove_from_lesson_confirm' => __( 'Are you sure you want to remove the user from this lesson?', 'woothemes-sensei' ), |
|
87 | - 'remove_from_course_confirm' => __( 'Are you sure you want to remove the user from this course?', 'woothemes-sensei' ), |
|
88 | - 'remove_user_from_post_nonce' => wp_create_nonce( 'remove_user_from_post_nonce' ), |
|
89 | - 'search_users_nonce' => wp_create_nonce( 'search-users' ), |
|
90 | - 'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' ) |
|
85 | + 'remove_generic_confirm' => __('Are you sure you want to remove this user?', 'woothemes-sensei'), |
|
86 | + 'remove_from_lesson_confirm' => __('Are you sure you want to remove the user from this lesson?', 'woothemes-sensei'), |
|
87 | + 'remove_from_course_confirm' => __('Are you sure you want to remove the user from this course?', 'woothemes-sensei'), |
|
88 | + 'remove_user_from_post_nonce' => wp_create_nonce('remove_user_from_post_nonce'), |
|
89 | + 'search_users_nonce' => wp_create_nonce('search-users'), |
|
90 | + 'selectplaceholder'=> __('Select Learner', 'woothemes-sensei') |
|
91 | 91 | ); |
92 | 92 | |
93 | - wp_localize_script( 'sensei-learners-general', 'woo_learners_general_data', $data ); |
|
93 | + wp_localize_script('sensei-learners-general', 'woo_learners_general_data', $data); |
|
94 | 94 | |
95 | 95 | } // End enqueue_scripts() |
96 | 96 | |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | * @since 1.6.0 |
103 | 103 | * @return void |
104 | 104 | */ |
105 | - public function enqueue_styles () { |
|
105 | + public function enqueue_styles() { |
|
106 | 106 | |
107 | - wp_enqueue_style( 'woothemes-sensei-admin' ); |
|
107 | + wp_enqueue_style('woothemes-sensei-admin'); |
|
108 | 108 | |
109 | 109 | } // End enqueue_styles() |
110 | 110 | |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | public function load_data_table_files() { |
117 | 117 | |
118 | 118 | // Load Learners Classes |
119 | - $classes_to_load = array( 'list-table', |
|
119 | + $classes_to_load = array('list-table', |
|
120 | 120 | 'learners-main', |
121 | 121 | ); |
122 | - foreach ( $classes_to_load as $class_file ) { |
|
123 | - Sensei()->load_class( $class_file ); |
|
122 | + foreach ($classes_to_load as $class_file) { |
|
123 | + Sensei()->load_class($class_file); |
|
124 | 124 | } // End For Loop |
125 | 125 | |
126 | 126 | } // End load_data_table_files() |
@@ -133,15 +133,15 @@ discard block |
||
133 | 133 | * @param undefined $optional_data optional constructor arguments |
134 | 134 | * @return object class instance object |
135 | 135 | */ |
136 | - public function load_data_object( $name = '', $data = 0, $optional_data = null ) { |
|
136 | + public function load_data_object($name = '', $data = 0, $optional_data = null) { |
|
137 | 137 | // Load Analysis data |
138 | - $object_name = 'WooThemes_Sensei_Learners_' . $name; |
|
139 | - if ( is_null($optional_data) ) { |
|
140 | - $sensei_learners_object = new $object_name( $data ); |
|
138 | + $object_name = 'WooThemes_Sensei_Learners_'.$name; |
|
139 | + if (is_null($optional_data)) { |
|
140 | + $sensei_learners_object = new $object_name($data); |
|
141 | 141 | } else { |
142 | - $sensei_learners_object = new $object_name( $data, $optional_data ); |
|
142 | + $sensei_learners_object = new $object_name($data, $optional_data); |
|
143 | 143 | } // End If Statement |
144 | - if ( 'Main' == $name ) { |
|
144 | + if ('Main' == $name) { |
|
145 | 145 | $sensei_learners_object->prepare_items(); |
146 | 146 | } // End If Statement |
147 | 147 | return $sensei_learners_object; |
@@ -158,16 +158,16 @@ discard block |
||
158 | 158 | // Load Learners data |
159 | 159 | $course_id = 0; |
160 | 160 | $lesson_id = 0; |
161 | - if( isset( $_GET['course_id'] ) ) { |
|
162 | - $course_id = intval( $_GET['course_id'] ); |
|
161 | + if (isset($_GET['course_id'])) { |
|
162 | + $course_id = intval($_GET['course_id']); |
|
163 | 163 | } |
164 | - if( isset( $_GET['lesson_id'] ) ) { |
|
165 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
164 | + if (isset($_GET['lesson_id'])) { |
|
165 | + $lesson_id = intval($_GET['lesson_id']); |
|
166 | 166 | } |
167 | - $sensei_learners_main = $this->load_data_object( 'Main', $course_id, $lesson_id ); |
|
167 | + $sensei_learners_main = $this->load_data_object('Main', $course_id, $lesson_id); |
|
168 | 168 | // Wrappers |
169 | - do_action( 'learners_before_container' ); |
|
170 | - do_action( 'learners_wrapper_container', 'top' ); |
|
169 | + do_action('learners_before_container'); |
|
170 | + do_action('learners_wrapper_container', 'top'); |
|
171 | 171 | $this->learners_headers(); |
172 | 172 | ?> |
173 | 173 | <div id="poststuff" class="sensei-learners-wrap"> |
@@ -175,12 +175,12 @@ discard block |
||
175 | 175 | <?php $sensei_learners_main->display(); ?> |
176 | 176 | </div> |
177 | 177 | <div class="sensei-learners-extra"> |
178 | - <?php do_action( 'sensei_learners_extra' ); ?> |
|
178 | + <?php do_action('sensei_learners_extra'); ?> |
|
179 | 179 | </div> |
180 | 180 | </div> |
181 | 181 | <?php |
182 | - do_action( 'learners_wrapper_container', 'bottom' ); |
|
183 | - do_action( 'learners_after_container' ); |
|
182 | + do_action('learners_wrapper_container', 'bottom'); |
|
183 | + do_action('learners_after_container'); |
|
184 | 184 | } // End learners_default_view() |
185 | 185 | |
186 | 186 | /** |
@@ -189,14 +189,14 @@ discard block |
||
189 | 189 | * @param array $args |
190 | 190 | * @return void |
191 | 191 | */ |
192 | - public function learners_headers( $args = array( 'nav' => 'default' ) ) { |
|
192 | + public function learners_headers($args = array('nav' => 'default')) { |
|
193 | 193 | |
194 | - $function = 'learners_' . $args['nav'] . '_nav'; |
|
194 | + $function = 'learners_'.$args['nav'].'_nav'; |
|
195 | 195 | $this->$function(); |
196 | 196 | ?> |
197 | - <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> |
|
197 | + <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> |
|
198 | 198 | <?php |
199 | - do_action( 'sensei_learners_after_headers' ); |
|
199 | + do_action('sensei_learners_after_headers'); |
|
200 | 200 | |
201 | 201 | } // End learners_headers() |
202 | 202 | |
@@ -206,10 +206,10 @@ discard block |
||
206 | 206 | * @param $which string |
207 | 207 | * @return void |
208 | 208 | */ |
209 | - public function wrapper_container( $which ) { |
|
210 | - if ( 'top' == $which ) { |
|
209 | + public function wrapper_container($which) { |
|
210 | + if ('top' == $which) { |
|
211 | 211 | ?><div id="woothemes-sensei" class="wrap woothemes-sensei"><?php |
212 | - } elseif ( 'bottom' == $which ) { |
|
212 | + } elseif ('bottom' == $which) { |
|
213 | 213 | ?></div><!--/#woothemes-sensei--><?php |
214 | 214 | } // End If Statement |
215 | 215 | } // End wrapper_container() |
@@ -220,18 +220,18 @@ discard block |
||
220 | 220 | * @return void |
221 | 221 | */ |
222 | 222 | public function learners_default_nav() { |
223 | - $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 ) ); |
|
224 | - if ( isset( $_GET['course_id'] ) ) { |
|
225 | - $course_id = intval( $_GET['course_id'] ); |
|
226 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id, 'view' => 'learners' ), admin_url( 'admin.php' ) ); |
|
227 | - $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
|
223 | + $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)); |
|
224 | + if (isset($_GET['course_id'])) { |
|
225 | + $course_id = intval($_GET['course_id']); |
|
226 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id, 'view' => 'learners'), admin_url('admin.php')); |
|
227 | + $title .= sprintf(' <span class="course-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); |
|
228 | 228 | } |
229 | - if ( isset( $_GET['lesson_id'] ) ) { |
|
230 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
231 | - $title .= ' <span class="lesson-title">> ' . get_the_title( intval( $lesson_id ) ) . '</span>'; |
|
229 | + if (isset($_GET['lesson_id'])) { |
|
230 | + $lesson_id = intval($_GET['lesson_id']); |
|
231 | + $title .= ' <span class="lesson-title">> '.get_the_title(intval($lesson_id)).'</span>'; |
|
232 | 232 | } |
233 | 233 | ?> |
234 | - <h2><?php echo apply_filters( 'sensei_learners_nav_title', $title ); ?></h2> |
|
234 | + <h2><?php echo apply_filters('sensei_learners_nav_title', $title); ?></h2> |
|
235 | 235 | <?php |
236 | 236 | } // End learners_default_nav() |
237 | 237 | |
@@ -240,13 +240,13 @@ discard block |
||
240 | 240 | // Parse POST data |
241 | 241 | $data = $_POST['data']; |
242 | 242 | $course_data = array(); |
243 | - parse_str( $data, $course_data ); |
|
243 | + parse_str($data, $course_data); |
|
244 | 244 | |
245 | - $course_cat = intval( $course_data['course_cat'] ); |
|
245 | + $course_cat = intval($course_data['course_cat']); |
|
246 | 246 | |
247 | - $redirect_url = apply_filters( 'sensei_ajax_redirect_url', add_query_arg( array( 'page' => $this->page_slug, 'course_cat' => $course_cat ), admin_url( 'admin.php' ) ) ); |
|
247 | + $redirect_url = apply_filters('sensei_ajax_redirect_url', add_query_arg(array('page' => $this->page_slug, 'course_cat' => $course_cat), admin_url('admin.php'))); |
|
248 | 248 | |
249 | - echo esc_url_raw( $redirect_url ); |
|
249 | + echo esc_url_raw($redirect_url); |
|
250 | 250 | die(); |
251 | 251 | } |
252 | 252 | |
@@ -257,157 +257,157 @@ discard block |
||
257 | 257 | |
258 | 258 | // Security check |
259 | 259 | $nonce = ''; |
260 | - if ( isset($_POST['remove_user_from_post_nonce']) ) { |
|
261 | - $nonce = esc_html( $_POST['remove_user_from_post_nonce'] ); |
|
260 | + if (isset($_POST['remove_user_from_post_nonce'])) { |
|
261 | + $nonce = esc_html($_POST['remove_user_from_post_nonce']); |
|
262 | 262 | } |
263 | - if ( ! wp_verify_nonce( $nonce, 'remove_user_from_post_nonce' ) ) { |
|
264 | - die( $return ); |
|
263 | + if ( ! wp_verify_nonce($nonce, 'remove_user_from_post_nonce')) { |
|
264 | + die($return); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Parse POST data |
268 | 268 | $data = $_POST['data']; |
269 | 269 | $action_data = array(); |
270 | - parse_str( $data, $action_data ); |
|
270 | + parse_str($data, $action_data); |
|
271 | 271 | |
272 | - if( $action_data['user_id'] && $action_data['post_id'] && $action_data['post_type'] ) { |
|
272 | + if ($action_data['user_id'] && $action_data['post_id'] && $action_data['post_type']) { |
|
273 | 273 | |
274 | - $user_id = intval( $action_data['user_id'] ); |
|
275 | - $post_id = intval( $action_data['post_id'] ); |
|
276 | - $post_type = sanitize_text_field( $action_data['post_type'] ); |
|
274 | + $user_id = intval($action_data['user_id']); |
|
275 | + $post_id = intval($action_data['post_id']); |
|
276 | + $post_type = sanitize_text_field($action_data['post_type']); |
|
277 | 277 | |
278 | - $user = get_userdata( $user_id ); |
|
278 | + $user = get_userdata($user_id); |
|
279 | 279 | |
280 | - switch( $post_type ) { |
|
280 | + switch ($post_type) { |
|
281 | 281 | |
282 | 282 | case 'course': |
283 | 283 | |
284 | - $removed = Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id ); |
|
284 | + $removed = Sensei_Utils::sensei_remove_user_from_course($post_id, $user_id); |
|
285 | 285 | |
286 | 286 | break; |
287 | 287 | |
288 | 288 | case 'lesson': |
289 | 289 | |
290 | - $removed = Sensei_Utils::sensei_remove_user_from_lesson( $post_id, $user_id ); |
|
290 | + $removed = Sensei_Utils::sensei_remove_user_from_lesson($post_id, $user_id); |
|
291 | 291 | |
292 | 292 | break; |
293 | 293 | |
294 | 294 | } |
295 | 295 | |
296 | - if( $removed ) { |
|
296 | + if ($removed) { |
|
297 | 297 | $return = 'removed'; |
298 | 298 | } |
299 | 299 | |
300 | 300 | } |
301 | 301 | |
302 | - die( $return ); |
|
302 | + die($return); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | public function json_search_users() { |
306 | 306 | |
307 | 307 | |
308 | - check_ajax_referer( 'search-users', 'security' ); |
|
308 | + check_ajax_referer('search-users', 'security'); |
|
309 | 309 | |
310 | - $term = sanitize_text_field( stripslashes( $_GET['term'] ) ); |
|
310 | + $term = sanitize_text_field(stripslashes($_GET['term'])); |
|
311 | 311 | |
312 | - if ( empty( $term ) ) { |
|
312 | + if (empty($term)) { |
|
313 | 313 | die(); |
314 | 314 | } |
315 | 315 | |
316 | - $default = isset( $_GET['default'] ) ? $_GET['default'] : __( 'None', 'woocommerce' ); |
|
316 | + $default = isset($_GET['default']) ? $_GET['default'] : __('None', 'woocommerce'); |
|
317 | 317 | |
318 | - $found_users = array( '' => $default ); |
|
318 | + $found_users = array('' => $default); |
|
319 | 319 | |
320 | - $users_query = new WP_User_Query( apply_filters( 'sensei_json_search_users_query', array( |
|
320 | + $users_query = new WP_User_Query(apply_filters('sensei_json_search_users_query', array( |
|
321 | 321 | 'fields' => 'all', |
322 | 322 | 'orderby' => 'display_name', |
323 | - 'search' => '*' . $term . '*', |
|
324 | - 'search_columns' => array( 'ID', 'user_login', 'user_email', 'user_nicename','user_firstname','user_lastname' ) |
|
325 | - ), $term ) ); |
|
323 | + 'search' => '*'.$term.'*', |
|
324 | + 'search_columns' => array('ID', 'user_login', 'user_email', 'user_nicename', 'user_firstname', 'user_lastname') |
|
325 | + ), $term)); |
|
326 | 326 | |
327 | 327 | $users = $users_query->get_results(); |
328 | 328 | |
329 | - if ( $users ) { |
|
330 | - foreach ( $users as $user ) { |
|
331 | - $full_name = Sensei_Learner::get_full_name( $user->ID ); |
|
329 | + if ($users) { |
|
330 | + foreach ($users as $user) { |
|
331 | + $full_name = Sensei_Learner::get_full_name($user->ID); |
|
332 | 332 | |
333 | - if( trim($user->display_name ) == trim( $full_name ) ){ |
|
333 | + if (trim($user->display_name) == trim($full_name)) { |
|
334 | 334 | |
335 | 335 | $name = $full_name; |
336 | 336 | |
337 | - }else{ |
|
337 | + } else { |
|
338 | 338 | |
339 | - $name = $full_name . ' ['. $user->display_name .']'; |
|
339 | + $name = $full_name.' ['.$user->display_name.']'; |
|
340 | 340 | |
341 | 341 | } |
342 | 342 | |
343 | - $found_users[ $user->ID ] = $name . ' (#' . $user->ID . ' – ' . sanitize_email( $user->user_email ) . ')'; |
|
343 | + $found_users[$user->ID] = $name.' (#'.$user->ID.' – '.sanitize_email($user->user_email).')'; |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | - wp_send_json( $found_users ); |
|
347 | + wp_send_json($found_users); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | public function add_new_learners() { |
351 | 351 | |
352 | 352 | $result = false; |
353 | 353 | |
354 | - if( ! isset( $_POST['add_learner_submit'] ) ) return $result; |
|
354 | + if ( ! isset($_POST['add_learner_submit'])) return $result; |
|
355 | 355 | |
356 | - if ( ! isset( $_POST['add_learner_nonce'] ) || ! wp_verify_nonce( $_POST['add_learner_nonce'], 'add_learner_to_sensei' ) ) return $result; |
|
356 | + if ( ! isset($_POST['add_learner_nonce']) || ! wp_verify_nonce($_POST['add_learner_nonce'], 'add_learner_to_sensei')) return $result; |
|
357 | 357 | |
358 | - if( ( ! isset( $_POST['add_user_id'] ) || '' == $_POST['add_user_id'] ) || ! isset( $_POST['add_post_type'] ) || ! isset( $_POST['add_course_id'] ) || ! isset( $_POST['add_lesson_id'] ) ) return $result; |
|
358 | + if (( ! isset($_POST['add_user_id']) || '' == $_POST['add_user_id']) || ! isset($_POST['add_post_type']) || ! isset($_POST['add_course_id']) || ! isset($_POST['add_lesson_id'])) return $result; |
|
359 | 359 | |
360 | 360 | $post_type = $_POST['add_post_type']; |
361 | - $user_id = absint( $_POST['add_user_id'] ); |
|
362 | - $course_id = absint( $_POST['add_course_id'] ); |
|
361 | + $user_id = absint($_POST['add_user_id']); |
|
362 | + $course_id = absint($_POST['add_course_id']); |
|
363 | 363 | |
364 | - switch( $post_type ) { |
|
364 | + switch ($post_type) { |
|
365 | 365 | case 'course': |
366 | 366 | |
367 | - $result = Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
367 | + $result = Sensei_Utils::user_start_course($user_id, $course_id); |
|
368 | 368 | |
369 | 369 | // Complete each lesson if course is set to be completed |
370 | - if( isset( $_POST['add_complete_course'] ) && 'yes' == $_POST['add_complete_course'] ) { |
|
370 | + if (isset($_POST['add_complete_course']) && 'yes' == $_POST['add_complete_course']) { |
|
371 | 371 | |
372 | - $lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' ); |
|
372 | + $lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids'); |
|
373 | 373 | |
374 | - foreach( $lesson_ids as $id ) { |
|
375 | - Sensei_Utils::sensei_start_lesson( $id, $user_id, true ); |
|
374 | + foreach ($lesson_ids as $id) { |
|
375 | + Sensei_Utils::sensei_start_lesson($id, $user_id, true); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | // Updates the Course status and it's meta data |
379 | - Sensei_Utils::user_complete_course( $course_id, $user_id ); |
|
379 | + Sensei_Utils::user_complete_course($course_id, $user_id); |
|
380 | 380 | |
381 | - do_action( 'sensei_user_course_end', $user_id, $course_id ); |
|
381 | + do_action('sensei_user_course_end', $user_id, $course_id); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | break; |
385 | 385 | |
386 | 386 | case 'lesson': |
387 | - $lesson_id = absint( $_POST['add_lesson_id'] ); |
|
387 | + $lesson_id = absint($_POST['add_lesson_id']); |
|
388 | 388 | $complete = false; |
389 | - if( isset( $_POST['add_complete_lesson'] ) && 'yes' == $_POST['add_complete_lesson'] ) { |
|
389 | + if (isset($_POST['add_complete_lesson']) && 'yes' == $_POST['add_complete_lesson']) { |
|
390 | 390 | $complete = true; |
391 | 391 | } |
392 | 392 | |
393 | - $result = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
393 | + $result = Sensei_Utils::sensei_start_lesson($lesson_id, $user_id, $complete); |
|
394 | 394 | |
395 | 395 | // Updates the Course status and it's meta data |
396 | - Sensei_Utils::user_complete_course( $course_id, $user_id ); |
|
396 | + Sensei_Utils::user_complete_course($course_id, $user_id); |
|
397 | 397 | |
398 | 398 | break; |
399 | 399 | } |
400 | 400 | |
401 | 401 | // Set redirect URL after adding user to course/lesson |
402 | - $query_args = array( 'page' => $this->page_slug, 'view' => 'learners' ); |
|
402 | + $query_args = array('page' => $this->page_slug, 'view' => 'learners'); |
|
403 | 403 | |
404 | - if( $result ) { |
|
404 | + if ($result) { |
|
405 | 405 | |
406 | - if( $course_id ) { |
|
406 | + if ($course_id) { |
|
407 | 407 | $query_args['course_id'] = $course_id; |
408 | 408 | } |
409 | 409 | |
410 | - if( $lesson_id ) { |
|
410 | + if ($lesson_id) { |
|
411 | 411 | $query_args['lesson_id'] = $lesson_id; |
412 | 412 | } |
413 | 413 | |
@@ -417,23 +417,23 @@ discard block |
||
417 | 417 | $query_args['message'] = 'error'; |
418 | 418 | } |
419 | 419 | |
420 | - $redirect_url = apply_filters( 'sensei_learners_add_learner_redirect_url', add_query_arg( $query_args, admin_url( 'admin.php' ) ) ); |
|
420 | + $redirect_url = apply_filters('sensei_learners_add_learner_redirect_url', add_query_arg($query_args, admin_url('admin.php'))); |
|
421 | 421 | |
422 | - wp_safe_redirect( esc_url_raw( $redirect_url ) ); |
|
422 | + wp_safe_redirect(esc_url_raw($redirect_url)); |
|
423 | 423 | exit; |
424 | 424 | } |
425 | 425 | |
426 | 426 | public function add_learner_notices() { |
427 | - if( isset( $_GET['page'] ) && $this->page_slug == $_GET['page'] && isset( $_GET['message'] ) && $_GET['message'] ) { |
|
428 | - if( 'success' == $_GET['message'] ) { |
|
427 | + if (isset($_GET['page']) && $this->page_slug == $_GET['page'] && isset($_GET['message']) && $_GET['message']) { |
|
428 | + if ('success' == $_GET['message']) { |
|
429 | 429 | $msg = array( |
430 | 430 | 'updated', |
431 | - __( 'Learner added successfully!', 'woothemes-sensei' ), |
|
431 | + __('Learner added successfully!', 'woothemes-sensei'), |
|
432 | 432 | ); |
433 | 433 | } else { |
434 | 434 | $msg = array( |
435 | 435 | 'error', |
436 | - __( 'Error adding learner.', 'woothemes-sensei' ), |
|
436 | + __('Error adding learner.', 'woothemes-sensei'), |
|
437 | 437 | ); |
438 | 438 | } |
439 | 439 | ?> |
@@ -456,9 +456,9 @@ discard block |
||
456 | 456 | * |
457 | 457 | * @return string $full_name |
458 | 458 | */ |
459 | - public function get_learner_full_name( $user_id ){ |
|
459 | + public function get_learner_full_name($user_id) { |
|
460 | 460 | |
461 | - return Sensei_Learner::get_full_name( $user_id ); |
|
461 | + return Sensei_Learner::get_full_name($user_id); |
|
462 | 462 | |
463 | 463 | } // end get_learner_full_name |
464 | 464 | |
@@ -469,4 +469,4 @@ discard block |
||
469 | 469 | * @ignore only for backward compatibility |
470 | 470 | * @since 1.9.0 |
471 | 471 | */ |
472 | -class WooThemes_Sensei_Learners extends Sensei_Learner_Management{} |
|
472 | +class WooThemes_Sensei_Learners extends Sensei_Learner_Management {} |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; // Exit if accessed directly |
|
3 | + exit; // Exit if accessed directly |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -17,45 +17,45 @@ discard block |
||
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Hook in tabs. |
20 | - * @since 1.8.0 |
|
20 | + * @since 1.8.0 |
|
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | 23 | |
24 | - add_action( 'admin_menu', array( $this, 'admin_menus') ); |
|
24 | + add_action( 'admin_menu', array( $this, 'admin_menus') ); |
|
25 | 25 | add_action( 'admin_head', array( $this, 'admin_head' ) ); |
26 | 26 | |
27 | 27 | } |
28 | 28 | |
29 | - /** |
|
30 | - * Sends user to the welcome page on first activation. |
|
31 | - * |
|
32 | - * Hooked into activated_plugin |
|
33 | - * @since 1.8.0 |
|
34 | - */ |
|
35 | - public static function redirect( $plugin ) { |
|
29 | + /** |
|
30 | + * Sends user to the welcome page on first activation. |
|
31 | + * |
|
32 | + * Hooked into activated_plugin |
|
33 | + * @since 1.8.0 |
|
34 | + */ |
|
35 | + public static function redirect( $plugin ) { |
|
36 | 36 | |
37 | - // Bail if activating from network, or bulk, or within an iFrame |
|
38 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) ) { |
|
37 | + // Bail if activating from network, or bulk, or within an iFrame |
|
38 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) ) { |
|
39 | 39 | |
40 | - return; |
|
40 | + return; |
|
41 | 41 | |
42 | - } |
|
43 | - // don't run for upgrades and for pages already on the welcome screen |
|
44 | - if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action'] ) |
|
45 | - || ( ! empty( $_GET['page'] ) && $_GET['page'] === 'sensei-welcome' ) ) { |
|
42 | + } |
|
43 | + // don't run for upgrades and for pages already on the welcome screen |
|
44 | + if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action'] ) |
|
45 | + || ( ! empty( $_GET['page'] ) && $_GET['page'] === 'sensei-welcome' ) ) { |
|
46 | 46 | |
47 | - return; |
|
47 | + return; |
|
48 | 48 | |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - wp_redirect( admin_url( 'index.php?page=sensei-welcome' ) ); |
|
52 | - exit; |
|
53 | - } |
|
51 | + wp_redirect( admin_url( 'index.php?page=sensei-welcome' ) ); |
|
52 | + exit; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Add admin menus/screens. |
57 | - * |
|
58 | - * @since 1.8.0 |
|
57 | + * |
|
58 | + * @since 1.8.0 |
|
59 | 59 | */ |
60 | 60 | public function admin_menus() { |
61 | 61 | |
@@ -65,17 +65,17 @@ discard block |
||
65 | 65 | |
66 | 66 | $welcome_page_name = __( 'Sensei Activation', 'woothemes-sensei' ); |
67 | 67 | $welcome_page_title = __( 'Welcome to Sensei', 'woothemes-sensei' ); |
68 | - add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sensei-welcome', array( $this, 'welcome_screen' ) ); |
|
68 | + add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sensei-welcome', array( $this, 'welcome_screen' ) ); |
|
69 | 69 | |
70 | 70 | } |
71 | 71 | |
72 | - /** |
|
73 | - * Output the Welcome screen. |
|
74 | - * |
|
75 | - * @since 1.8.0 |
|
76 | - */ |
|
77 | - public function welcome_screen() { |
|
78 | - ?> |
|
72 | + /** |
|
73 | + * Output the Welcome screen. |
|
74 | + * |
|
75 | + * @since 1.8.0 |
|
76 | + */ |
|
77 | + public function welcome_screen() { |
|
78 | + ?> |
|
79 | 79 | <div class="wrap about-wrap"> |
80 | 80 | |
81 | 81 | <?php $this->intro(); ?> |
@@ -128,13 +128,13 @@ discard block |
||
128 | 128 | </div> |
129 | 129 | </div> |
130 | 130 | <?php |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * Add styles just for this page, and remove dashboard page links. |
135 | 135 | */ |
136 | 136 | public function admin_head() { |
137 | - // remove the menu page so it is not visible in the admin side bar |
|
137 | + // remove the menu page so it is not visible in the admin side bar |
|
138 | 138 | remove_submenu_page( 'index.php', 'sensei-welcome' ); |
139 | 139 | ?> |
140 | 140 | <style type="text/css"> |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | |
259 | 259 | // Random tweet - must be kept to 102 chars to "fit" |
260 | 260 | $tweets = array( |
261 | - 'I\'ve just installed Sensei - A premium Learning Management plugin for #WordPress.' |
|
261 | + 'I\'ve just installed Sensei - A premium Learning Management plugin for #WordPress.' |
|
262 | 262 | ); |
263 | 263 | shuffle( $tweets ); |
264 | 264 | ?> |
@@ -280,11 +280,11 @@ discard block |
||
280 | 280 | |
281 | 281 | <div class="sensei-badge"> |
282 | 282 | <?php |
283 | - _e('Sensei by WooThemes','woothemes-sensei'); |
|
284 | - echo '<br />'; |
|
283 | + _e('Sensei by WooThemes','woothemes-sensei'); |
|
284 | + echo '<br />'; |
|
285 | 285 | |
286 | - printf( __( 'Version %s', 'woothemes-sensei' ), Sensei()->version ); |
|
287 | - ?> |
|
286 | + printf( __( 'Version %s', 'woothemes-sensei' ), Sensei()->version ); |
|
287 | + ?> |
|
288 | 288 | </div> |
289 | 289 | |
290 | 290 | <p class="sensei-actions"> |
@@ -24,69 +24,69 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct ( $file = __FILE__ ) { |
26 | 26 | $this->file = $file; |
27 | - $this->token = 'quiz'; |
|
27 | + $this->token = 'quiz'; |
|
28 | 28 | $this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' ); |
29 | 29 | add_action( 'save_post', array( $this, 'update_author' )); |
30 | 30 | |
31 | 31 | // listen to the reset button click |
32 | 32 | add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
33 | 33 | |
34 | - // fire the complete quiz button submit for grading action |
|
35 | - add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); |
|
34 | + // fire the complete quiz button submit for grading action |
|
35 | + add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); |
|
36 | 36 | |
37 | 37 | // fire the save user answers quiz button click responder |
38 | 38 | add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) ); |
39 | 39 | |
40 | - // fire the load global data function |
|
41 | - add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); |
|
40 | + // fire the load global data function |
|
41 | + add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); |
|
42 | 42 | |
43 | - add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
43 | + add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
44 | 44 | |
45 | 45 | |
46 | - } // End __construct() |
|
46 | + } // End __construct() |
|
47 | 47 | |
48 | 48 | /** |
49 | - * Update the quiz author when the lesson post type is save |
|
50 | - * |
|
51 | - * @param int $post_id |
|
52 | - * @return void |
|
53 | - */ |
|
49 | + * Update the quiz author when the lesson post type is save |
|
50 | + * |
|
51 | + * @param int $post_id |
|
52 | + * @return void |
|
53 | + */ |
|
54 | 54 | public function update_author( $post_id ){ |
55 | 55 | |
56 | 56 | // If this isn't a 'lesson' post, don't update it. |
57 | - // if this is a revision don't save it |
|
58 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
59 | - || wp_is_post_revision( $post_id ) ) { |
|
57 | + // if this is a revision don't save it |
|
58 | + if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
59 | + || wp_is_post_revision( $post_id ) ) { |
|
60 | 60 | |
61 | - return; |
|
61 | + return; |
|
62 | 62 | |
63 | - } |
|
64 | - // get the lesson author id to be use late |
|
65 | - $saved_post = get_post( $post_id ); |
|
66 | - $new_lesson_author_id = $saved_post->post_author; |
|
63 | + } |
|
64 | + // get the lesson author id to be use late |
|
65 | + $saved_post = get_post( $post_id ); |
|
66 | + $new_lesson_author_id = $saved_post->post_author; |
|
67 | 67 | |
68 | - //get the lessons quiz |
|
68 | + //get the lessons quiz |
|
69 | 69 | $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); |
70 | - foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
70 | + foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
71 | 71 | |
72 | - if( ! $quiz_item ) { |
|
73 | - continue; |
|
74 | - } |
|
72 | + if( ! $quiz_item ) { |
|
73 | + continue; |
|
74 | + } |
|
75 | 75 | |
76 | - // setup the quiz items new author value |
|
76 | + // setup the quiz items new author value |
|
77 | 77 | $my_post = array( |
78 | - 'ID' => $quiz_item, |
|
79 | - 'post_author' => $new_lesson_author_id |
|
78 | + 'ID' => $quiz_item, |
|
79 | + 'post_author' => $new_lesson_author_id |
|
80 | 80 | ); |
81 | 81 | |
82 | - // remove the action so that it doesn't fire again |
|
83 | - remove_action( 'save_post', array( $this, 'update_author' )); |
|
82 | + // remove the action so that it doesn't fire again |
|
83 | + remove_action( 'save_post', array( $this, 'update_author' )); |
|
84 | 84 | |
85 | 85 | // Update the post into the database |
86 | 86 | wp_update_post( $my_post ); |
87 | - } |
|
87 | + } |
|
88 | 88 | |
89 | - return; |
|
89 | + return; |
|
90 | 90 | }// end update_author |
91 | 91 | |
92 | 92 | |
@@ -117,32 +117,32 @@ discard block |
||
117 | 117 | } // end lesson |
118 | 118 | |
119 | 119 | |
120 | - /** |
|
121 | - * user_save_quiz_answers_listener |
|
122 | - * |
|
123 | - * This function hooks into the quiz page and accepts the answer form save post. |
|
124 | - * @since 1.7.3 |
|
125 | - * @return bool $saved; |
|
126 | - */ |
|
127 | - public function user_save_quiz_answers_listener(){ |
|
120 | + /** |
|
121 | + * user_save_quiz_answers_listener |
|
122 | + * |
|
123 | + * This function hooks into the quiz page and accepts the answer form save post. |
|
124 | + * @since 1.7.3 |
|
125 | + * @return bool $saved; |
|
126 | + */ |
|
127 | + public function user_save_quiz_answers_listener(){ |
|
128 | 128 | |
129 | - if( ! isset( $_POST[ 'quiz_save' ]) |
|
130 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
131 | - || empty( $_POST[ 'sensei_question' ] ) |
|
132 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
133 | - return; |
|
134 | - } |
|
129 | + if( ! isset( $_POST[ 'quiz_save' ]) |
|
130 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
131 | + || empty( $_POST[ 'sensei_question' ] ) |
|
132 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
133 | + return; |
|
134 | + } |
|
135 | 135 | |
136 | - global $post; |
|
137 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
138 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
139 | - // call the save function |
|
140 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
136 | + global $post; |
|
137 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
138 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
139 | + // call the save function |
|
140 | + self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
141 | 141 | |
142 | - // remove the hook as it should only fire once per click |
|
143 | - remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); |
|
142 | + // remove the hook as it should only fire once per click |
|
143 | + remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); |
|
144 | 144 | |
145 | - } // end user_save_quiz_answers_listener |
|
145 | + } // end user_save_quiz_answers_listener |
|
146 | 146 | |
147 | 147 | /** |
148 | 148 | * Save the user answers for the given lesson's quiz |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @access public |
154 | 154 | * |
155 | 155 | * @param array $quiz_answers |
156 | - * @param array $files from global $_FILES |
|
156 | + * @param array $files from global $_FILES |
|
157 | 157 | * @param int $lesson_id |
158 | 158 | * @param int $user_id |
159 | 159 | * |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ |
163 | 163 | |
164 | - if( ! ( $user_id > 0 ) ){ |
|
165 | - $user_id = get_current_user_id(); |
|
166 | - } |
|
164 | + if( ! ( $user_id > 0 ) ){ |
|
165 | + $user_id = get_current_user_id(); |
|
166 | + } |
|
167 | 167 | |
168 | - // make sure the parameters are valid before continuing |
|
168 | + // make sure the parameters are valid before continuing |
|
169 | 169 | if( empty( $lesson_id ) || empty( $user_id ) |
170 | 170 | || 'lesson' != get_post_type( $lesson_id ) |
171 | 171 | ||!get_userdata( $user_id ) |
@@ -176,25 +176,25 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | |
179 | - // start the lesson before saving the data in case the user has not started the lesson |
|
180 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
179 | + // start the lesson before saving the data in case the user has not started the lesson |
|
180 | + $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
181 | 181 | |
182 | 182 | //prepare the answers |
183 | 183 | $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); |
184 | 184 | |
185 | 185 | // save the user data |
186 | - $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
186 | + $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
187 | 187 | |
188 | 188 | // were the answers saved correctly? |
189 | 189 | if( intval( $answers_saved ) > 0){ |
190 | 190 | |
191 | - // save transient to make retrieval faster |
|
192 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
193 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
191 | + // save transient to make retrieval faster |
|
192 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
193 | + set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
194 | 194 | |
195 | - // update the message showed to user |
|
196 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
197 | - } |
|
195 | + // update the message showed to user |
|
196 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
197 | + } |
|
198 | 198 | |
199 | 199 | return $answers_saved; |
200 | 200 | |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | |
203 | 203 | /** |
204 | 204 | * Get the user answers for the given lesson's quiz. |
205 | - * |
|
206 | - * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
207 | - * retrieving data for quiz answer before sensei 1.7.4 |
|
205 | + * |
|
206 | + * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
207 | + * retrieving data for quiz answer before sensei 1.7.4 |
|
208 | 208 | * |
209 | 209 | * |
210 | 210 | * @since 1.7.4 |
@@ -224,27 +224,27 @@ discard block |
||
224 | 224 | return false; |
225 | 225 | } |
226 | 226 | |
227 | - // save some time and get the transient cached data |
|
228 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
229 | - $transient_cached_answers = get_transient( $transient_key ); |
|
227 | + // save some time and get the transient cached data |
|
228 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
229 | + $transient_cached_answers = get_transient( $transient_key ); |
|
230 | 230 | |
231 | - // return the transient or get the values get the values from the comment meta |
|
232 | - if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
231 | + // return the transient or get the values get the values from the comment meta |
|
232 | + if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
233 | 233 | |
234 | - $encoded_user_answers = $transient_cached_answers; |
|
234 | + $encoded_user_answers = $transient_cached_answers; |
|
235 | 235 | |
236 | - }else{ |
|
236 | + }else{ |
|
237 | 237 | |
238 | - $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
238 | + $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
239 | 239 | |
240 | - } // end if transient check |
|
240 | + } // end if transient check |
|
241 | 241 | |
242 | 242 | if( ! is_array( $encoded_user_answers ) ){ |
243 | 243 | return false; |
244 | 244 | } |
245 | 245 | |
246 | - //set the transient with the new valid data for faster retrieval in future |
|
247 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
246 | + //set the transient with the new valid data for faster retrieval in future |
|
247 | + set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
248 | 248 | |
249 | 249 | // decode an unserialize all answers |
250 | 250 | foreach( $encoded_user_answers as $question_id => $encoded_answer ) { |
@@ -278,8 +278,8 @@ discard block |
||
278 | 278 | $current_quiz_id = $post->ID; |
279 | 279 | $lesson_id = $this->get_lesson_id( $current_quiz_id ); |
280 | 280 | |
281 | - // reset all user data |
|
282 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
281 | + // reset all user data |
|
282 | + $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
283 | 283 | |
284 | 284 | //this function should only run once |
285 | 285 | remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * Complete/ submit quiz hooked function |
291 | 291 | * |
292 | 292 | * This function listens to the complete button submit action and processes the users submitted answers |
293 | - * not that this function submits the given users quiz answers for grading. |
|
293 | + * not that this function submits the given users quiz answers for grading. |
|
294 | 294 | * |
295 | 295 | * @since 1.7.4 |
296 | 296 | * @access public |
@@ -300,90 +300,90 @@ discard block |
||
300 | 300 | */ |
301 | 301 | public function user_quiz_submit_listener() { |
302 | 302 | |
303 | - // only respond to valid quiz completion submissions |
|
304 | - if( ! isset( $_POST[ 'quiz_complete' ]) |
|
305 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
306 | - || empty( $_POST[ 'sensei_question' ] ) |
|
307 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
308 | - return; |
|
309 | - } |
|
303 | + // only respond to valid quiz completion submissions |
|
304 | + if( ! isset( $_POST[ 'quiz_complete' ]) |
|
305 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
306 | + || empty( $_POST[ 'sensei_question' ] ) |
|
307 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
308 | + return; |
|
309 | + } |
|
310 | 310 | |
311 | - global $post, $current_user; |
|
312 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
313 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
311 | + global $post, $current_user; |
|
312 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
313 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
314 | 314 | |
315 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
315 | + self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
316 | 316 | |
317 | 317 | } // End sensei_complete_quiz() |
318 | 318 | |
319 | - /** |
|
320 | - * This function set's up the data need for the quiz page |
|
321 | - * |
|
322 | - * This function hooks into sensei_complete_quiz and load the global data for the |
|
323 | - * current quiz. |
|
324 | - * |
|
325 | - * @since 1.7.4 |
|
326 | - * @access public |
|
327 | - * |
|
328 | - */ |
|
329 | - public function load_global_quiz_data(){ |
|
319 | + /** |
|
320 | + * This function set's up the data need for the quiz page |
|
321 | + * |
|
322 | + * This function hooks into sensei_complete_quiz and load the global data for the |
|
323 | + * current quiz. |
|
324 | + * |
|
325 | + * @since 1.7.4 |
|
326 | + * @access public |
|
327 | + * |
|
328 | + */ |
|
329 | + public function load_global_quiz_data(){ |
|
330 | 330 | |
331 | - global $post, $current_user; |
|
332 | - $this->data = new stdClass(); |
|
331 | + global $post, $current_user; |
|
332 | + $this->data = new stdClass(); |
|
333 | 333 | |
334 | - // Default grade |
|
335 | - $grade = 0; |
|
334 | + // Default grade |
|
335 | + $grade = 0; |
|
336 | 336 | |
337 | - // Get Quiz Questions |
|
338 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
337 | + // Get Quiz Questions |
|
338 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
339 | 339 | |
340 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
340 | + $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
341 | 341 | |
342 | - // Get quiz grade type |
|
343 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
342 | + // Get quiz grade type |
|
343 | + $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
344 | 344 | |
345 | - // Get quiz pass setting |
|
346 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
345 | + // Get quiz pass setting |
|
346 | + $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
347 | 347 | |
348 | - // Get quiz pass mark |
|
349 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
348 | + // Get quiz pass mark |
|
349 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
350 | 350 | |
351 | - // Get latest quiz answers and grades |
|
352 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
353 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
354 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
355 | - $user_quiz_grade = 0; |
|
356 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
357 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
358 | - } |
|
351 | + // Get latest quiz answers and grades |
|
352 | + $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
353 | + $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
354 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
355 | + $user_quiz_grade = 0; |
|
356 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
357 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
358 | + } |
|
359 | 359 | |
360 | - if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
360 | + if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
361 | 361 | |
362 | - // Check again that the lesson is complete |
|
363 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
364 | - $user_lesson_complete = false; |
|
365 | - if ( $user_lesson_end ) { |
|
366 | - $user_lesson_complete = true; |
|
367 | - } // End If Statement |
|
362 | + // Check again that the lesson is complete |
|
363 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
364 | + $user_lesson_complete = false; |
|
365 | + if ( $user_lesson_end ) { |
|
366 | + $user_lesson_complete = true; |
|
367 | + } // End If Statement |
|
368 | 368 | |
369 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
370 | - //backwards compatibility |
|
371 | - if( 'on' == $reset_allowed ) { |
|
372 | - $reset_allowed = 1; |
|
373 | - } |
|
369 | + $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
370 | + //backwards compatibility |
|
371 | + if( 'on' == $reset_allowed ) { |
|
372 | + $reset_allowed = 1; |
|
373 | + } |
|
374 | 374 | |
375 | - // Build frontend data object for backwards compatibility |
|
376 | - // using this is no longer recommended |
|
377 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
378 | - $this->data->quiz_passmark = $quiz_passmark; |
|
379 | - $this->data->quiz_lesson = $quiz_lesson_id; |
|
380 | - $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
381 | - $this->data->user_lesson_end = $user_lesson_end; |
|
382 | - $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
383 | - $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
384 | - $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
375 | + // Build frontend data object for backwards compatibility |
|
376 | + // using this is no longer recommended |
|
377 | + $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
378 | + $this->data->quiz_passmark = $quiz_passmark; |
|
379 | + $this->data->quiz_lesson = $quiz_lesson_id; |
|
380 | + $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
381 | + $this->data->user_lesson_end = $user_lesson_end; |
|
382 | + $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
383 | + $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
384 | + $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
385 | 385 | |
386 | - } // end load_global_quiz_data |
|
386 | + } // end load_global_quiz_data |
|
387 | 387 | |
388 | 388 | |
389 | 389 | /** |
@@ -413,25 +413,25 @@ discard block |
||
413 | 413 | foreach( $unprepared_answers as $question_id => $answer ) { |
414 | 414 | |
415 | 415 | //get the current questions question type |
416 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
416 | + $question_type = Sensei()->question->get_question_type( $question_id ); |
|
417 | 417 | |
418 | 418 | // Sanitise answer |
419 | 419 | if( 0 == get_magic_quotes_gpc() ) { |
420 | 420 | $answer = wp_unslash( $answer ); |
421 | 421 | } |
422 | 422 | |
423 | - // compress the answer for saving |
|
423 | + // compress the answer for saving |
|
424 | 424 | if( 'multi-line' == $question_type ) { |
425 | - $answer = esc_html( $answer ); |
|
426 | - }elseif( 'file-upload' == $question_type ){ |
|
427 | - $file_key = 'file_upload_' . $question_id; |
|
428 | - if( isset( $files[ $file_key ] ) ) { |
|
429 | - $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
430 | - if( $attachment_id ) { |
|
431 | - $answer = $attachment_id; |
|
432 | - } |
|
433 | - } |
|
434 | - } // end if |
|
425 | + $answer = esc_html( $answer ); |
|
426 | + }elseif( 'file-upload' == $question_type ){ |
|
427 | + $file_key = 'file_upload_' . $question_id; |
|
428 | + if( isset( $files[ $file_key ] ) ) { |
|
429 | + $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
430 | + if( $attachment_id ) { |
|
431 | + $answer = $attachment_id; |
|
432 | + } |
|
433 | + } |
|
434 | + } // end if |
|
435 | 435 | |
436 | 436 | $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); |
437 | 437 | |
@@ -440,813 +440,813 @@ discard block |
||
440 | 440 | return $prepared_answers; |
441 | 441 | } // prepare_form_submitted_answers |
442 | 442 | |
443 | - /** |
|
444 | - * Reset user submitted questions |
|
445 | - * |
|
446 | - * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
447 | - * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
448 | - * |
|
449 | - * @since 1.7.4 |
|
450 | - * @access public |
|
451 | - * |
|
452 | - * @return bool $reset_success |
|
453 | - * @param int $user_id |
|
454 | - * @param int $lesson_id |
|
455 | - */ |
|
456 | - public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
443 | + /** |
|
444 | + * Reset user submitted questions |
|
445 | + * |
|
446 | + * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
447 | + * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
448 | + * |
|
449 | + * @since 1.7.4 |
|
450 | + * @access public |
|
451 | + * |
|
452 | + * @return bool $reset_success |
|
453 | + * @param int $user_id |
|
454 | + * @param int $lesson_id |
|
455 | + */ |
|
456 | + public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
457 | + |
|
458 | + //make sure the parameters are valid |
|
459 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
460 | + || 'lesson' != get_post_type( $lesson_id ) |
|
461 | + || ! get_userdata( $user_id ) ){ |
|
462 | + return false; |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + |
|
467 | + //get the users lesson status to make |
|
468 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
469 | + if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
470 | + // this user is not taking this lesson so this process is not needed |
|
471 | + return false; |
|
472 | + } |
|
473 | + |
|
474 | + //get the lesson quiz and course |
|
475 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
476 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
477 | + |
|
478 | + // reset the transients |
|
479 | + $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
480 | + $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
481 | + $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
482 | + delete_transient( $answers_transient_key ); |
|
483 | + delete_transient( $grades_transient_key ); |
|
484 | + delete_transient( $answers_feedback_transient_key ); |
|
485 | + |
|
486 | + // reset the quiz answers and feedback notes |
|
487 | + $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
488 | + $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
489 | + $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
490 | + |
|
491 | + // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
492 | + Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
493 | + |
|
494 | + Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
495 | + |
|
496 | + // Update course completion |
|
497 | + Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
457 | 498 | |
458 | - //make sure the parameters are valid |
|
459 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
460 | - || 'lesson' != get_post_type( $lesson_id ) |
|
461 | - || ! get_userdata( $user_id ) ){ |
|
462 | - return false; |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - |
|
467 | - //get the users lesson status to make |
|
468 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
469 | - if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
470 | - // this user is not taking this lesson so this process is not needed |
|
471 | - return false; |
|
472 | - } |
|
499 | + // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
500 | + do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
501 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
473 | 502 | |
474 | - //get the lesson quiz and course |
|
475 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
476 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
503 | + return ( $deleted_answers && $deleted_grades ) ; |
|
477 | 504 | |
478 | - // reset the transients |
|
479 | - $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
480 | - $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
481 | - $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
482 | - delete_transient( $answers_transient_key ); |
|
483 | - delete_transient( $grades_transient_key ); |
|
484 | - delete_transient( $answers_feedback_transient_key ); |
|
505 | + } // end reset_user_lesson_data |
|
485 | 506 | |
486 | - // reset the quiz answers and feedback notes |
|
487 | - $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
488 | - $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
489 | - $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
507 | + /** |
|
508 | + * Submit the users quiz answers for grading |
|
509 | + * |
|
510 | + * This function accepts users answers and stores it but also initiates the grading |
|
511 | + * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
512 | + * |
|
513 | + * @since 1.7.4 |
|
514 | + * @access public |
|
515 | + * |
|
516 | + * @param array $quiz_answers |
|
517 | + * @param array $files from $_FILES |
|
518 | + * @param int $user_id |
|
519 | + * @param int $lesson_id |
|
520 | + * |
|
521 | + * @return bool $answers_submitted |
|
522 | + */ |
|
523 | + public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
490 | 524 | |
491 | - // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
492 | - Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
525 | + $answers_submitted = false; |
|
493 | 526 | |
494 | - Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
527 | + // get the user_id if none was passed in use the current logged in user |
|
528 | + if( ! intval( $user_id ) > 0 ) { |
|
529 | + $user_id = get_current_user_id(); |
|
530 | + } |
|
495 | 531 | |
496 | - // Update course completion |
|
497 | - Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
532 | + // make sure the parameters are valid before continuing |
|
533 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
534 | + || 'lesson' != get_post_type( $lesson_id ) |
|
535 | + ||!get_userdata( $user_id ) |
|
536 | + || !is_array( $quiz_answers ) ){ |
|
498 | 537 | |
499 | - // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
500 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
501 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
538 | + return false; |
|
502 | 539 | |
503 | - return ( $deleted_answers && $deleted_grades ) ; |
|
540 | + } |
|
504 | 541 | |
505 | - } // end reset_user_lesson_data |
|
542 | + // Default grade |
|
543 | + $grade = 0; |
|
506 | 544 | |
507 | - /** |
|
508 | - * Submit the users quiz answers for grading |
|
509 | - * |
|
510 | - * This function accepts users answers and stores it but also initiates the grading |
|
511 | - * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
512 | - * |
|
513 | - * @since 1.7.4 |
|
514 | - * @access public |
|
515 | - * |
|
516 | - * @param array $quiz_answers |
|
517 | - * @param array $files from $_FILES |
|
518 | - * @param int $user_id |
|
519 | - * @param int $lesson_id |
|
520 | - * |
|
521 | - * @return bool $answers_submitted |
|
522 | - */ |
|
523 | - public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
545 | + // Get Quiz ID |
|
546 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
524 | 547 | |
525 | - $answers_submitted = false; |
|
548 | + // Get quiz grade type |
|
549 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
526 | 550 | |
527 | - // get the user_id if none was passed in use the current logged in user |
|
528 | - if( ! intval( $user_id ) > 0 ) { |
|
529 | - $user_id = get_current_user_id(); |
|
530 | - } |
|
551 | + // Get quiz pass setting |
|
552 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
531 | 553 | |
532 | - // make sure the parameters are valid before continuing |
|
533 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
534 | - || 'lesson' != get_post_type( $lesson_id ) |
|
535 | - ||!get_userdata( $user_id ) |
|
536 | - || !is_array( $quiz_answers ) ){ |
|
554 | + // Get the minimum percentage need to pass this quiz |
|
555 | + $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
537 | 556 | |
538 | - return false; |
|
557 | + // Handle Quiz Questions asked |
|
558 | + // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
559 | + // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
560 | + // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
561 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
562 | + $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
563 | + if( empty( $questions_asked ) ){ |
|
539 | 564 | |
540 | - } |
|
565 | + $questions_asked = array_keys( $quiz_answers ); |
|
566 | + $questions_asked_string = implode( ',', $questions_asked ); |
|
541 | 567 | |
542 | - // Default grade |
|
543 | - $grade = 0; |
|
568 | + // Save questions that were asked in this quiz |
|
569 | + update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
544 | 570 | |
545 | - // Get Quiz ID |
|
546 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
571 | + } |
|
547 | 572 | |
548 | - // Get quiz grade type |
|
549 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
573 | + // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
574 | + self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
550 | 575 | |
551 | - // Get quiz pass setting |
|
552 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
576 | + // Grade quiz |
|
577 | + $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
553 | 578 | |
554 | - // Get the minimum percentage need to pass this quiz |
|
555 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
579 | + // Get Lesson Grading Setting |
|
580 | + $lesson_metadata = array(); |
|
581 | + $lesson_status = 'ungraded'; // Default when completing a quiz |
|
556 | 582 | |
557 | - // Handle Quiz Questions asked |
|
558 | - // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
559 | - // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
560 | - // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
561 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
562 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
563 | - if( empty( $questions_asked ) ){ |
|
583 | + // At this point the answers have been submitted |
|
584 | + $answers_submitted = true; |
|
564 | 585 | |
565 | - $questions_asked = array_keys( $quiz_answers ); |
|
566 | - $questions_asked_string = implode( ',', $questions_asked ); |
|
567 | - |
|
568 | - // Save questions that were asked in this quiz |
|
569 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
586 | + // if this condition is false the quiz should manually be graded by admin |
|
587 | + if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
570 | 588 | |
571 | - } |
|
589 | + // Quiz has been automatically Graded |
|
590 | + if ( 'on' == $pass_required ) { |
|
572 | 591 | |
573 | - // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
574 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
592 | + // Student has reached the pass mark and lesson is complete |
|
593 | + if ( $quiz_pass_percentage <= $grade ) { |
|
575 | 594 | |
576 | - // Grade quiz |
|
577 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
595 | + $lesson_status = 'passed'; |
|
578 | 596 | |
579 | - // Get Lesson Grading Setting |
|
580 | - $lesson_metadata = array(); |
|
581 | - $lesson_status = 'ungraded'; // Default when completing a quiz |
|
597 | + } else { |
|
582 | 598 | |
583 | - // At this point the answers have been submitted |
|
584 | - $answers_submitted = true; |
|
599 | + $lesson_status = 'failed'; |
|
585 | 600 | |
586 | - // if this condition is false the quiz should manually be graded by admin |
|
587 | - if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
601 | + } // End If Statement |
|
588 | 602 | |
589 | - // Quiz has been automatically Graded |
|
590 | - if ( 'on' == $pass_required ) { |
|
603 | + } else { |
|
591 | 604 | |
592 | - // Student has reached the pass mark and lesson is complete |
|
593 | - if ( $quiz_pass_percentage <= $grade ) { |
|
605 | + // Student only has to partake the quiz |
|
606 | + $lesson_status = 'graded'; |
|
607 | + |
|
608 | + } |
|
609 | + |
|
610 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
611 | + |
|
612 | + } // end if ! is_wp_error( $grade ... |
|
613 | + |
|
614 | + Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
594 | 615 | |
595 | - $lesson_status = 'passed'; |
|
616 | + if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
596 | 617 | |
597 | - } else { |
|
618 | + /** |
|
619 | + * Lesson end action hook |
|
620 | + * |
|
621 | + * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
622 | + * |
|
623 | + * @param int $user_id |
|
624 | + * @param int $lesson_id |
|
625 | + */ |
|
626 | + do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
598 | 627 | |
599 | - $lesson_status = 'failed'; |
|
628 | + } |
|
600 | 629 | |
601 | - } // End If Statement |
|
630 | + /** |
|
631 | + * User quiz has been submitted |
|
632 | + * |
|
633 | + * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
634 | + * results. |
|
635 | + * |
|
636 | + * @param int $user_id |
|
637 | + * @param int $quiz_id |
|
638 | + * @param string $grade |
|
639 | + * @param string $quiz_pass_percentage |
|
640 | + * @param string $quiz_grade_type |
|
641 | + */ |
|
642 | + do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
602 | 643 | |
603 | - } else { |
|
644 | + return $answers_submitted; |
|
604 | 645 | |
605 | - // Student only has to partake the quiz |
|
606 | - $lesson_status = 'graded'; |
|
607 | - |
|
608 | - } |
|
609 | - |
|
610 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
611 | - |
|
612 | - } // end if ! is_wp_error( $grade ... |
|
613 | - |
|
614 | - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
646 | + }// end submit_answers_for_grading |
|
615 | 647 | |
616 | - if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
648 | + /** |
|
649 | + * Get the user question answer |
|
650 | + * |
|
651 | + * This function gets the the users saved answer on given quiz for the given question parameter |
|
652 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
653 | + * |
|
654 | + * @since 1.7.4 |
|
655 | + * |
|
656 | + * @param int $lesson_id |
|
657 | + * @param int $question_id |
|
658 | + * @param int $user_id ( optional ) |
|
659 | + * |
|
660 | + * @return bool $answers_submitted |
|
661 | + */ |
|
662 | + public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
617 | 663 | |
618 | - /** |
|
619 | - * Lesson end action hook |
|
620 | - * |
|
621 | - * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
622 | - * |
|
623 | - * @param int $user_id |
|
624 | - * @param int $lesson_id |
|
625 | - */ |
|
626 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
664 | + // parameter validation |
|
665 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
666 | + || ! ( intval( $lesson_id ) > 0 ) |
|
667 | + || ! ( intval( $question_id ) > 0 ) |
|
668 | + || 'lesson' != get_post_type( $lesson_id ) |
|
669 | + || 'question' != get_post_type( $question_id )) { |
|
627 | 670 | |
628 | - } |
|
671 | + return false; |
|
672 | + } |
|
673 | + |
|
674 | + if( ! ( intval( $user_id ) > 0 ) ){ |
|
675 | + $user_id = get_current_user_id(); |
|
676 | + } |
|
677 | + |
|
678 | + $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
679 | + |
|
680 | + if( !$users_answers || empty( $users_answers ) |
|
681 | + || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
682 | + |
|
683 | + //Fallback for pre 1.7.4 data |
|
684 | + $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
685 | + |
|
686 | + if( ! isset( $comment->comment_content ) ){ |
|
687 | + return false; |
|
688 | + } |
|
689 | + |
|
690 | + return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
691 | + } |
|
692 | + |
|
693 | + return $users_answers[ $question_id ]; |
|
694 | + |
|
695 | + }// end get_user_question_answer |
|
696 | + |
|
697 | + /** |
|
698 | + * Saving the users quiz question grades |
|
699 | + * |
|
700 | + * This function save all the grades for all the question in a given quiz on the lesson |
|
701 | + * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
702 | + * |
|
703 | + * @since 1.7.4 |
|
704 | + * |
|
705 | + * @param array $quiz_grades{ |
|
706 | + * @type int $question_id |
|
707 | + * @type int $question_grade |
|
708 | + * } |
|
709 | + * @param $lesson_id |
|
710 | + * @param $user_id (Optional) will use the current user if not supplied |
|
711 | + * |
|
712 | + * @return bool |
|
713 | + */ |
|
714 | + public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
715 | + |
|
716 | + // get the user_id if none was passed in use the current logged in user |
|
717 | + if( ! intval( $user_id ) > 0 ) { |
|
718 | + $user_id = get_current_user_id(); |
|
719 | + } |
|
720 | + |
|
721 | + // make sure the parameters are valid before continuing |
|
722 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
723 | + || 'lesson' != get_post_type( $lesson_id ) |
|
724 | + ||!get_userdata( $user_id ) |
|
725 | + || !is_array( $quiz_grades ) ){ |
|
726 | + |
|
727 | + return false; |
|
728 | + |
|
729 | + } |
|
730 | + |
|
731 | + $success = false; |
|
732 | + |
|
733 | + // save that data for the user on the lesson comment meta |
|
734 | + $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
735 | + |
|
736 | + // were the grades save successfully ? |
|
737 | + if( intval( $comment_meta_id ) > 0 ) { |
|
738 | + |
|
739 | + $success = true; |
|
740 | + // save transient |
|
741 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
742 | + set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
743 | + } |
|
744 | + |
|
745 | + return $success; |
|
746 | + |
|
747 | + }// end set_user_grades |
|
748 | + |
|
749 | + /** |
|
750 | + * Retrieve the users quiz question grades |
|
751 | + * |
|
752 | + * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
753 | + * |
|
754 | + * @since 1.7.4 |
|
755 | + * |
|
756 | + * @param $lesson_id |
|
757 | + * @param $user_id (Optional) will use the current user if not supplied |
|
758 | + * |
|
759 | + * @return array $user_quiz_grades or false if none exists for this users |
|
760 | + */ |
|
761 | + public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
762 | + |
|
763 | + $user_grades = array(); |
|
764 | + |
|
765 | + // get the user_id if none was passed in use the current logged in user |
|
766 | + if( ! intval( $user_id ) > 0 ) { |
|
767 | + $user_id = get_current_user_id(); |
|
768 | + } |
|
769 | + |
|
770 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
771 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
772 | + return false; |
|
773 | + } |
|
774 | + |
|
775 | + // save some time and get the transient cached data |
|
776 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
777 | + $user_grades = get_transient( $transient_key ); |
|
778 | + |
|
779 | + // get the data if nothing was stored in the transient |
|
780 | + if( empty( $user_grades ) || false != $user_grades ){ |
|
781 | + |
|
782 | + $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
783 | + |
|
784 | + //set the transient with the new valid data for faster retrieval in future |
|
785 | + set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
786 | + |
|
787 | + } // end if transient check |
|
788 | + |
|
789 | + // if there is no data for this user |
|
790 | + if( ! is_array( $user_grades ) ){ |
|
791 | + return false; |
|
792 | + } |
|
793 | + |
|
794 | + return $user_grades; |
|
795 | + |
|
796 | + }// end get_user_grades |
|
797 | + |
|
798 | + /** |
|
799 | + * Get the user question grade |
|
800 | + * |
|
801 | + * This function gets the grade on a quiz for the given question parameter |
|
802 | + * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
803 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
804 | + * |
|
805 | + * @since 1.7.4 |
|
806 | + * |
|
807 | + * @param int $lesson_id |
|
808 | + * @param int $question_id |
|
809 | + * @param int $user_id ( optional ) |
|
810 | + * |
|
811 | + * @return bool $question_grade |
|
812 | + */ |
|
813 | + public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
814 | + |
|
815 | + // parameter validation |
|
816 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
817 | + || ! ( intval( $lesson_id ) > 0 ) |
|
818 | + || ! ( intval( $question_id ) > 0 ) |
|
819 | + || 'lesson' != get_post_type( $lesson_id ) |
|
820 | + || 'question' != get_post_type( $question_id )) { |
|
821 | + |
|
822 | + return false; |
|
823 | + } |
|
824 | + |
|
825 | + $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
826 | + |
|
827 | + if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
828 | + |
|
829 | + //fallback to data pre 1.7.4 |
|
830 | + $args = array( |
|
831 | + 'post_id' => $question_id, |
|
832 | + 'user_id' => $user_id, |
|
833 | + 'type' => 'sensei_user_answer' |
|
834 | + ); |
|
835 | + |
|
836 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
837 | + $fall_back_grade = false; |
|
838 | + if( isset( $question_activity->comment_ID ) ){ |
|
839 | + $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
840 | + } |
|
841 | + |
|
842 | + return $fall_back_grade; |
|
843 | + |
|
844 | + } // end if $all_user_grades... |
|
845 | + |
|
846 | + return $all_user_grades[ $question_id ]; |
|
847 | + |
|
848 | + }// end get_user_question_grade |
|
849 | + |
|
850 | + /** |
|
851 | + * Save the user's answers feedback |
|
852 | + * |
|
853 | + * For this function you must supply all three parameters. If will return false one is left out. |
|
854 | + * The data will be saved on the lesson ID supplied. |
|
855 | + * |
|
856 | + * @since 1.7.5 |
|
857 | + * @access public |
|
858 | + * |
|
859 | + * @param array $answers_feedback{ |
|
860 | + * $type int $question_id |
|
861 | + * $type string $question_feedback |
|
862 | + * } |
|
863 | + * @param int $lesson_id |
|
864 | + * @param int $user_id |
|
865 | + * |
|
866 | + * @return false or int $feedback_saved |
|
867 | + */ |
|
868 | + public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
869 | + |
|
870 | + // make sure the parameters are valid before continuing |
|
871 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
872 | + || 'lesson' != get_post_type( $lesson_id ) |
|
873 | + ||!get_userdata( $user_id ) |
|
874 | + || !is_array( $answers_feedback ) ){ |
|
875 | + |
|
876 | + return false; |
|
877 | + |
|
878 | + } |
|
879 | + |
|
880 | + |
|
881 | + // check if the lesson is started before saving, if not start the lesson for the user |
|
882 | + if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
883 | + Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
884 | + } |
|
629 | 885 | |
630 | - /** |
|
631 | - * User quiz has been submitted |
|
632 | - * |
|
633 | - * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
634 | - * results. |
|
635 | - * |
|
636 | - * @param int $user_id |
|
637 | - * @param int $quiz_id |
|
638 | - * @param string $grade |
|
639 | - * @param string $quiz_pass_percentage |
|
640 | - * @param string $quiz_grade_type |
|
641 | - */ |
|
642 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
886 | + // encode the feedback |
|
887 | + $encoded_answers_feedback = array(); |
|
888 | + foreach( $answers_feedback as $question_id => $feedback ){ |
|
889 | + $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
890 | + } |
|
891 | + |
|
892 | + // save the user data |
|
893 | + $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
894 | + |
|
895 | + //Were the the question feedback save correctly? |
|
896 | + if( intval( $feedback_saved ) > 0){ |
|
897 | + |
|
898 | + // save transient to make retrieval faster in future |
|
899 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
900 | + set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
643 | 901 | |
644 | - return $answers_submitted; |
|
902 | + } |
|
903 | + |
|
904 | + return $feedback_saved; |
|
905 | + |
|
906 | + } // end save_user_answers_feedback |
|
907 | + |
|
908 | + /** |
|
909 | + * Get the user's answers feedback. |
|
910 | + * |
|
911 | + * This function returns the feedback submitted by the teacher/admin |
|
912 | + * during grading. Grading occurs manually or automatically. |
|
913 | + * |
|
914 | + * @since 1.7.5 |
|
915 | + * @access public |
|
916 | + * |
|
917 | + * @param int $lesson_id |
|
918 | + * @param int $user_id |
|
919 | + * |
|
920 | + * @return false | array $answers_feedback{ |
|
921 | + * $type int $question_id |
|
922 | + * $type string $question_feedback |
|
923 | + * } |
|
924 | + */ |
|
925 | + public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
926 | + |
|
927 | + $answers_feedback = array(); |
|
645 | 928 | |
646 | - }// end submit_answers_for_grading |
|
929 | + // get the user_id if none was passed in use the current logged in user |
|
930 | + if( ! intval( $user_id ) > 0 ) { |
|
931 | + $user_id = get_current_user_id(); |
|
932 | + } |
|
647 | 933 | |
648 | - /** |
|
649 | - * Get the user question answer |
|
650 | - * |
|
651 | - * This function gets the the users saved answer on given quiz for the given question parameter |
|
652 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
653 | - * |
|
654 | - * @since 1.7.4 |
|
655 | - * |
|
656 | - * @param int $lesson_id |
|
657 | - * @param int $question_id |
|
658 | - * @param int $user_id ( optional ) |
|
659 | - * |
|
660 | - * @return bool $answers_submitted |
|
661 | - */ |
|
662 | - public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
934 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
935 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
936 | + return false; |
|
937 | + } |
|
938 | + |
|
939 | + // first check the transient to save a few split seconds |
|
940 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
941 | + $encoded_feedback = get_transient( $transient_key ); |
|
942 | + |
|
943 | + // get the data if nothing was stored in the transient |
|
944 | + if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
945 | + |
|
946 | + $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
947 | + |
|
948 | + //set the transient with the new valid data for faster retrieval in future |
|
949 | + set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
950 | + |
|
951 | + } // end if transient check |
|
663 | 952 | |
664 | - // parameter validation |
|
665 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
666 | - || ! ( intval( $lesson_id ) > 0 ) |
|
667 | - || ! ( intval( $question_id ) > 0 ) |
|
668 | - || 'lesson' != get_post_type( $lesson_id ) |
|
669 | - || 'question' != get_post_type( $question_id )) { |
|
953 | + // if there is no data for this user |
|
954 | + if( ! is_array( $encoded_feedback ) ){ |
|
955 | + return false; |
|
956 | + } |
|
670 | 957 | |
671 | - return false; |
|
672 | - } |
|
673 | - |
|
674 | - if( ! ( intval( $user_id ) > 0 ) ){ |
|
675 | - $user_id = get_current_user_id(); |
|
676 | - } |
|
677 | - |
|
678 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
679 | - |
|
680 | - if( !$users_answers || empty( $users_answers ) |
|
681 | - || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
682 | - |
|
683 | - //Fallback for pre 1.7.4 data |
|
684 | - $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
685 | - |
|
686 | - if( ! isset( $comment->comment_content ) ){ |
|
687 | - return false; |
|
688 | - } |
|
689 | - |
|
690 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
691 | - } |
|
692 | - |
|
693 | - return $users_answers[ $question_id ]; |
|
694 | - |
|
695 | - }// end get_user_question_answer |
|
696 | - |
|
697 | - /** |
|
698 | - * Saving the users quiz question grades |
|
699 | - * |
|
700 | - * This function save all the grades for all the question in a given quiz on the lesson |
|
701 | - * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
702 | - * |
|
703 | - * @since 1.7.4 |
|
704 | - * |
|
705 | - * @param array $quiz_grades{ |
|
706 | - * @type int $question_id |
|
707 | - * @type int $question_grade |
|
708 | - * } |
|
709 | - * @param $lesson_id |
|
710 | - * @param $user_id (Optional) will use the current user if not supplied |
|
711 | - * |
|
712 | - * @return bool |
|
713 | - */ |
|
714 | - public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
715 | - |
|
716 | - // get the user_id if none was passed in use the current logged in user |
|
717 | - if( ! intval( $user_id ) > 0 ) { |
|
718 | - $user_id = get_current_user_id(); |
|
719 | - } |
|
720 | - |
|
721 | - // make sure the parameters are valid before continuing |
|
722 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
723 | - || 'lesson' != get_post_type( $lesson_id ) |
|
724 | - ||!get_userdata( $user_id ) |
|
725 | - || !is_array( $quiz_grades ) ){ |
|
726 | - |
|
727 | - return false; |
|
728 | - |
|
729 | - } |
|
730 | - |
|
731 | - $success = false; |
|
732 | - |
|
733 | - // save that data for the user on the lesson comment meta |
|
734 | - $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
735 | - |
|
736 | - // were the grades save successfully ? |
|
737 | - if( intval( $comment_meta_id ) > 0 ) { |
|
738 | - |
|
739 | - $success = true; |
|
740 | - // save transient |
|
741 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
742 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
743 | - } |
|
744 | - |
|
745 | - return $success; |
|
746 | - |
|
747 | - }// end set_user_grades |
|
748 | - |
|
749 | - /** |
|
750 | - * Retrieve the users quiz question grades |
|
751 | - * |
|
752 | - * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
753 | - * |
|
754 | - * @since 1.7.4 |
|
755 | - * |
|
756 | - * @param $lesson_id |
|
757 | - * @param $user_id (Optional) will use the current user if not supplied |
|
758 | - * |
|
759 | - * @return array $user_quiz_grades or false if none exists for this users |
|
760 | - */ |
|
761 | - public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
762 | - |
|
763 | - $user_grades = array(); |
|
764 | - |
|
765 | - // get the user_id if none was passed in use the current logged in user |
|
766 | - if( ! intval( $user_id ) > 0 ) { |
|
767 | - $user_id = get_current_user_id(); |
|
768 | - } |
|
769 | - |
|
770 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
771 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
772 | - return false; |
|
773 | - } |
|
774 | - |
|
775 | - // save some time and get the transient cached data |
|
776 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
777 | - $user_grades = get_transient( $transient_key ); |
|
778 | - |
|
779 | - // get the data if nothing was stored in the transient |
|
780 | - if( empty( $user_grades ) || false != $user_grades ){ |
|
781 | - |
|
782 | - $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
783 | - |
|
784 | - //set the transient with the new valid data for faster retrieval in future |
|
785 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
786 | - |
|
787 | - } // end if transient check |
|
788 | - |
|
789 | - // if there is no data for this user |
|
790 | - if( ! is_array( $user_grades ) ){ |
|
791 | - return false; |
|
792 | - } |
|
793 | - |
|
794 | - return $user_grades; |
|
795 | - |
|
796 | - }// end get_user_grades |
|
797 | - |
|
798 | - /** |
|
799 | - * Get the user question grade |
|
800 | - * |
|
801 | - * This function gets the grade on a quiz for the given question parameter |
|
802 | - * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
803 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
804 | - * |
|
805 | - * @since 1.7.4 |
|
806 | - * |
|
807 | - * @param int $lesson_id |
|
808 | - * @param int $question_id |
|
809 | - * @param int $user_id ( optional ) |
|
810 | - * |
|
811 | - * @return bool $question_grade |
|
812 | - */ |
|
813 | - public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
814 | - |
|
815 | - // parameter validation |
|
816 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
817 | - || ! ( intval( $lesson_id ) > 0 ) |
|
818 | - || ! ( intval( $question_id ) > 0 ) |
|
819 | - || 'lesson' != get_post_type( $lesson_id ) |
|
820 | - || 'question' != get_post_type( $question_id )) { |
|
821 | - |
|
822 | - return false; |
|
823 | - } |
|
824 | - |
|
825 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
826 | - |
|
827 | - if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
828 | - |
|
829 | - //fallback to data pre 1.7.4 |
|
830 | - $args = array( |
|
831 | - 'post_id' => $question_id, |
|
832 | - 'user_id' => $user_id, |
|
833 | - 'type' => 'sensei_user_answer' |
|
834 | - ); |
|
835 | - |
|
836 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
837 | - $fall_back_grade = false; |
|
838 | - if( isset( $question_activity->comment_ID ) ){ |
|
839 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
840 | - } |
|
841 | - |
|
842 | - return $fall_back_grade; |
|
843 | - |
|
844 | - } // end if $all_user_grades... |
|
845 | - |
|
846 | - return $all_user_grades[ $question_id ]; |
|
847 | - |
|
848 | - }// end get_user_question_grade |
|
849 | - |
|
850 | - /** |
|
851 | - * Save the user's answers feedback |
|
852 | - * |
|
853 | - * For this function you must supply all three parameters. If will return false one is left out. |
|
854 | - * The data will be saved on the lesson ID supplied. |
|
855 | - * |
|
856 | - * @since 1.7.5 |
|
857 | - * @access public |
|
858 | - * |
|
859 | - * @param array $answers_feedback{ |
|
860 | - * $type int $question_id |
|
861 | - * $type string $question_feedback |
|
862 | - * } |
|
863 | - * @param int $lesson_id |
|
864 | - * @param int $user_id |
|
865 | - * |
|
866 | - * @return false or int $feedback_saved |
|
867 | - */ |
|
868 | - public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
869 | - |
|
870 | - // make sure the parameters are valid before continuing |
|
871 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
872 | - || 'lesson' != get_post_type( $lesson_id ) |
|
873 | - ||!get_userdata( $user_id ) |
|
874 | - || !is_array( $answers_feedback ) ){ |
|
875 | - |
|
876 | - return false; |
|
877 | - |
|
878 | - } |
|
879 | - |
|
880 | - |
|
881 | - // check if the lesson is started before saving, if not start the lesson for the user |
|
882 | - if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
883 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
884 | - } |
|
885 | - |
|
886 | - // encode the feedback |
|
887 | - $encoded_answers_feedback = array(); |
|
888 | - foreach( $answers_feedback as $question_id => $feedback ){ |
|
889 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
890 | - } |
|
891 | - |
|
892 | - // save the user data |
|
893 | - $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
894 | - |
|
895 | - //Were the the question feedback save correctly? |
|
896 | - if( intval( $feedback_saved ) > 0){ |
|
897 | - |
|
898 | - // save transient to make retrieval faster in future |
|
899 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
900 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
901 | - |
|
902 | - } |
|
903 | - |
|
904 | - return $feedback_saved; |
|
905 | - |
|
906 | - } // end save_user_answers_feedback |
|
907 | - |
|
908 | - /** |
|
909 | - * Get the user's answers feedback. |
|
910 | - * |
|
911 | - * This function returns the feedback submitted by the teacher/admin |
|
912 | - * during grading. Grading occurs manually or automatically. |
|
913 | - * |
|
914 | - * @since 1.7.5 |
|
915 | - * @access public |
|
916 | - * |
|
917 | - * @param int $lesson_id |
|
918 | - * @param int $user_id |
|
919 | - * |
|
920 | - * @return false | array $answers_feedback{ |
|
921 | - * $type int $question_id |
|
922 | - * $type string $question_feedback |
|
923 | - * } |
|
924 | - */ |
|
925 | - public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
926 | - |
|
927 | - $answers_feedback = array(); |
|
928 | - |
|
929 | - // get the user_id if none was passed in use the current logged in user |
|
930 | - if( ! intval( $user_id ) > 0 ) { |
|
931 | - $user_id = get_current_user_id(); |
|
932 | - } |
|
933 | - |
|
934 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
935 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
936 | - return false; |
|
937 | - } |
|
938 | - |
|
939 | - // first check the transient to save a few split seconds |
|
940 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
941 | - $encoded_feedback = get_transient( $transient_key ); |
|
942 | - |
|
943 | - // get the data if nothing was stored in the transient |
|
944 | - if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
945 | - |
|
946 | - $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
947 | - |
|
948 | - //set the transient with the new valid data for faster retrieval in future |
|
949 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
950 | - |
|
951 | - } // end if transient check |
|
952 | - |
|
953 | - // if there is no data for this user |
|
954 | - if( ! is_array( $encoded_feedback ) ){ |
|
955 | - return false; |
|
956 | - } |
|
957 | - |
|
958 | - foreach( $encoded_feedback as $question_id => $feedback ){ |
|
958 | + foreach( $encoded_feedback as $question_id => $feedback ){ |
|
959 | 959 | |
960 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
960 | + $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
961 | 961 | |
962 | - } |
|
962 | + } |
|
963 | 963 | |
964 | - return $answers_feedback; |
|
964 | + return $answers_feedback; |
|
965 | 965 | |
966 | - } // end get_user_answers_feedback |
|
966 | + } // end get_user_answers_feedback |
|
967 | 967 | |
968 | - /** |
|
969 | - * Get the user's answer feedback for a specific question. |
|
970 | - * |
|
971 | - * This function gives you a single answer note/feedback string |
|
972 | - * for the user on the given question. |
|
973 | - * |
|
974 | - * @since 1.7.5 |
|
975 | - * @access public |
|
976 | - * |
|
977 | - * @param int $lesson_id |
|
978 | - * @param int $question_id |
|
979 | - * @param int $user_id |
|
980 | - * |
|
981 | - * @return string $feedback or bool if false |
|
982 | - */ |
|
983 | - public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
968 | + /** |
|
969 | + * Get the user's answer feedback for a specific question. |
|
970 | + * |
|
971 | + * This function gives you a single answer note/feedback string |
|
972 | + * for the user on the given question. |
|
973 | + * |
|
974 | + * @since 1.7.5 |
|
975 | + * @access public |
|
976 | + * |
|
977 | + * @param int $lesson_id |
|
978 | + * @param int $question_id |
|
979 | + * @param int $user_id |
|
980 | + * |
|
981 | + * @return string $feedback or bool if false |
|
982 | + */ |
|
983 | + public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
984 | 984 | |
985 | - $feedback = false; |
|
985 | + $feedback = false; |
|
986 | 986 | |
987 | - // parameter validation |
|
988 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
989 | - || ! ( intval( $lesson_id ) > 0 ) |
|
990 | - || ! ( intval( $question_id ) > 0 ) |
|
991 | - || 'lesson' != get_post_type( $lesson_id ) |
|
992 | - || 'question' != get_post_type( $question_id )) { |
|
987 | + // parameter validation |
|
988 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
989 | + || ! ( intval( $lesson_id ) > 0 ) |
|
990 | + || ! ( intval( $question_id ) > 0 ) |
|
991 | + || 'lesson' != get_post_type( $lesson_id ) |
|
992 | + || 'question' != get_post_type( $question_id )) { |
|
993 | 993 | |
994 | - return false; |
|
995 | - } |
|
994 | + return false; |
|
995 | + } |
|
996 | 996 | |
997 | - // get all the feedback for the user on the given lesson |
|
998 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
997 | + // get all the feedback for the user on the given lesson |
|
998 | + $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
999 | 999 | |
1000 | - if( !$all_feedback || empty( $all_feedback ) |
|
1001 | - || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
1000 | + if( !$all_feedback || empty( $all_feedback ) |
|
1001 | + || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
1002 | 1002 | |
1003 | - //fallback to data pre 1.7.4 |
|
1003 | + //fallback to data pre 1.7.4 |
|
1004 | 1004 | |
1005 | - // setup the sensei data query |
|
1006 | - $args = array( |
|
1007 | - 'post_id' => $question_id, |
|
1008 | - 'user_id' => $user_id, |
|
1009 | - 'type' => 'sensei_user_answer' |
|
1010 | - ); |
|
1011 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
1005 | + // setup the sensei data query |
|
1006 | + $args = array( |
|
1007 | + 'post_id' => $question_id, |
|
1008 | + 'user_id' => $user_id, |
|
1009 | + 'type' => 'sensei_user_answer' |
|
1010 | + ); |
|
1011 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
1012 | 1012 | |
1013 | - // set the default to false and return that if no old data is available. |
|
1014 | - if( isset( $question_activity->comment_ID ) ){ |
|
1015 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
1016 | - } |
|
1013 | + // set the default to false and return that if no old data is available. |
|
1014 | + if( isset( $question_activity->comment_ID ) ){ |
|
1015 | + $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
1016 | + } |
|
1017 | 1017 | |
1018 | - // finally use the default question feedback |
|
1019 | - if( empty( $feedback ) ){ |
|
1020 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
1021 | - } |
|
1018 | + // finally use the default question feedback |
|
1019 | + if( empty( $feedback ) ){ |
|
1020 | + $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
1021 | + } |
|
1022 | 1022 | |
1023 | - return $feedback; |
|
1023 | + return $feedback; |
|
1024 | 1024 | |
1025 | - } |
|
1025 | + } |
|
1026 | 1026 | |
1027 | - return $all_feedback[ $question_id ]; |
|
1027 | + return $all_feedback[ $question_id ]; |
|
1028 | 1028 | |
1029 | - } // end get_user_question_feedback |
|
1029 | + } // end get_user_question_feedback |
|
1030 | 1030 | |
1031 | - /** |
|
1032 | - * Check if a quiz has no questions, and redirect back to lesson. |
|
1033 | - * |
|
1034 | - * Though a quiz is created for each lesson, it should not be visible |
|
1035 | - * unless it has questions. |
|
1036 | - * |
|
1037 | - * @since 1.9.0 |
|
1038 | - * @access public |
|
1039 | - * @param none |
|
1040 | - * @return void |
|
1041 | - */ |
|
1031 | + /** |
|
1032 | + * Check if a quiz has no questions, and redirect back to lesson. |
|
1033 | + * |
|
1034 | + * Though a quiz is created for each lesson, it should not be visible |
|
1035 | + * unless it has questions. |
|
1036 | + * |
|
1037 | + * @since 1.9.0 |
|
1038 | + * @access public |
|
1039 | + * @param none |
|
1040 | + * @return void |
|
1041 | + */ |
|
1042 | 1042 | |
1043 | - public function quiz_has_no_questions() { |
|
1043 | + public function quiz_has_no_questions() { |
|
1044 | 1044 | |
1045 | - if( ! is_singular( 'quiz' ) ) { |
|
1046 | - return; |
|
1047 | - } |
|
1045 | + if( ! is_singular( 'quiz' ) ) { |
|
1046 | + return; |
|
1047 | + } |
|
1048 | 1048 | |
1049 | - global $post; |
|
1049 | + global $post; |
|
1050 | 1050 | |
1051 | - $lesson_id = $this->get_lesson_id($post->ID); |
|
1051 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
1052 | 1052 | |
1053 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
1053 | + $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
1054 | 1054 | |
1055 | - $lesson = get_post($lesson_id); |
|
1055 | + $lesson = get_post($lesson_id); |
|
1056 | 1056 | |
1057 | - if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
1057 | + if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
1058 | 1058 | |
1059 | - wp_redirect(get_permalink($lesson->ID), 301); |
|
1060 | - exit; |
|
1059 | + wp_redirect(get_permalink($lesson->ID), 301); |
|
1060 | + exit; |
|
1061 | 1061 | |
1062 | - } |
|
1062 | + } |
|
1063 | 1063 | |
1064 | - } // end quiz_has_no_questions |
|
1064 | + } // end quiz_has_no_questions |
|
1065 | 1065 | |
1066 | 1066 | /** |
1067 | - * Deprecate the sensei_single_main_content on the single-quiz template. |
|
1068 | - * |
|
1069 | - * @deprecated since 1.9.0 |
|
1070 | - */ |
|
1067 | + * Deprecate the sensei_single_main_content on the single-quiz template. |
|
1068 | + * |
|
1069 | + * @deprecated since 1.9.0 |
|
1070 | + */ |
|
1071 | 1071 | public static function deprecate_quiz_sensei_single_main_content_hook(){ |
1072 | 1072 | |
1073 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
1073 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
1074 | 1074 | |
1075 | 1075 | } |
1076 | - /* |
|
1076 | + /* |
|
1077 | 1077 | * Deprecate the sensei_quiz_single_title on the single-quiz template. |
1078 | 1078 | * |
1079 | 1079 | * @deprecated since 1.9.0 |
1080 | 1080 | */ |
1081 | - public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
1081 | + public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
1082 | 1082 | |
1083 | - sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
1083 | + sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
1084 | 1084 | |
1085 | - } |
|
1085 | + } |
|
1086 | 1086 | |
1087 | - /** |
|
1088 | - * Filter the single title and add the Quiz to it. |
|
1089 | - * |
|
1090 | - * @param string $title |
|
1091 | - * @param int $id title post id |
|
1092 | - * @return string $quiz_title |
|
1093 | - */ |
|
1094 | - public static function single_quiz_title( $title, $post_id ){ |
|
1087 | + /** |
|
1088 | + * Filter the single title and add the Quiz to it. |
|
1089 | + * |
|
1090 | + * @param string $title |
|
1091 | + * @param int $id title post id |
|
1092 | + * @return string $quiz_title |
|
1093 | + */ |
|
1094 | + public static function single_quiz_title( $title, $post_id ){ |
|
1095 | 1095 | |
1096 | - if( 'quiz' == get_post_type( $post_id ) ){ |
|
1096 | + if( 'quiz' == get_post_type( $post_id ) ){ |
|
1097 | 1097 | |
1098 | - $title_with_no_quizzes = $title; |
|
1098 | + $title_with_no_quizzes = $title; |
|
1099 | 1099 | |
1100 | - // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
1101 | - if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
1100 | + // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
1101 | + if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
1102 | 1102 | |
1103 | - // remove all possible appearances of quiz |
|
1104 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
1105 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
1106 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
1103 | + // remove all possible appearances of quiz |
|
1104 | + $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
1105 | + $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
1106 | + $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
1107 | 1107 | |
1108 | - } |
|
1108 | + } |
|
1109 | 1109 | |
1110 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
1111 | - } |
|
1110 | + $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
1111 | + } |
|
1112 | 1112 | |
1113 | - /** |
|
1114 | - * hook document in class-woothemes-sensei-message.php |
|
1115 | - */ |
|
1116 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
1113 | + /** |
|
1114 | + * hook document in class-woothemes-sensei-message.php |
|
1115 | + */ |
|
1116 | + return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
1117 | 1117 | |
1118 | - } |
|
1118 | + } |
|
1119 | 1119 | |
1120 | - /** |
|
1121 | - * Initialize the quiz question loop on the single quiz template |
|
1122 | - * |
|
1123 | - * The function will create a global quiz loop varialbe. |
|
1124 | - * |
|
1125 | - * @since 1.9.0 |
|
1126 | - * |
|
1127 | - */ |
|
1128 | - public static function start_quiz_questions_loop(){ |
|
1120 | + /** |
|
1121 | + * Initialize the quiz question loop on the single quiz template |
|
1122 | + * |
|
1123 | + * The function will create a global quiz loop varialbe. |
|
1124 | + * |
|
1125 | + * @since 1.9.0 |
|
1126 | + * |
|
1127 | + */ |
|
1128 | + public static function start_quiz_questions_loop(){ |
|
1129 | 1129 | |
1130 | - global $sensei_question_loop; |
|
1130 | + global $sensei_question_loop; |
|
1131 | 1131 | |
1132 | - //intialize the questions loop object |
|
1133 | - $sensei_question_loop['current'] = -1; |
|
1134 | - $sensei_question_loop['total'] = 0; |
|
1135 | - $sensei_question_loop['questions'] = array(); |
|
1132 | + //intialize the questions loop object |
|
1133 | + $sensei_question_loop['current'] = -1; |
|
1134 | + $sensei_question_loop['total'] = 0; |
|
1135 | + $sensei_question_loop['questions'] = array(); |
|
1136 | 1136 | |
1137 | 1137 | |
1138 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
1138 | + $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
1139 | 1139 | |
1140 | - if( count( $questions ) > 0 ){ |
|
1140 | + if( count( $questions ) > 0 ){ |
|
1141 | 1141 | |
1142 | - $sensei_question_loop['total'] = count( $questions ); |
|
1143 | - $sensei_question_loop['questions'] = $questions; |
|
1144 | - $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
1142 | + $sensei_question_loop['total'] = count( $questions ); |
|
1143 | + $sensei_question_loop['questions'] = $questions; |
|
1144 | + $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
1145 | 1145 | |
1146 | - } |
|
1146 | + } |
|
1147 | 1147 | |
1148 | - }// static function |
|
1148 | + }// static function |
|
1149 | 1149 | |
1150 | - /** |
|
1151 | - * Initialize the quiz question loop on the single quiz template |
|
1152 | - * |
|
1153 | - * The function will create a global quiz loop varialbe. |
|
1154 | - * |
|
1155 | - * @since 1.9.0 |
|
1156 | - * |
|
1157 | - */ |
|
1158 | - public static function stop_quiz_questions_loop(){ |
|
1150 | + /** |
|
1151 | + * Initialize the quiz question loop on the single quiz template |
|
1152 | + * |
|
1153 | + * The function will create a global quiz loop varialbe. |
|
1154 | + * |
|
1155 | + * @since 1.9.0 |
|
1156 | + * |
|
1157 | + */ |
|
1158 | + public static function stop_quiz_questions_loop(){ |
|
1159 | 1159 | |
1160 | - $sensei_question_loop['total'] = 0; |
|
1161 | - $sensei_question_loop['questions'] = array(); |
|
1162 | - $sensei_question_loop['quiz_id'] = ''; |
|
1160 | + $sensei_question_loop['total'] = 0; |
|
1161 | + $sensei_question_loop['questions'] = array(); |
|
1162 | + $sensei_question_loop['quiz_id'] = ''; |
|
1163 | 1163 | |
1164 | - } |
|
1164 | + } |
|
1165 | 1165 | |
1166 | - /** |
|
1167 | - * Output the title for the single quiz page |
|
1168 | - * |
|
1169 | - * @since 1.9.0 |
|
1170 | - */ |
|
1171 | - public static function the_title(){ |
|
1172 | - ?> |
|
1166 | + /** |
|
1167 | + * Output the title for the single quiz page |
|
1168 | + * |
|
1169 | + * @since 1.9.0 |
|
1170 | + */ |
|
1171 | + public static function the_title(){ |
|
1172 | + ?> |
|
1173 | 1173 | <header> |
1174 | 1174 | |
1175 | 1175 | <h1> |
1176 | 1176 | |
1177 | 1177 | <?php |
1178 | - /** |
|
1179 | - * Filter documented in class-sensei-messages.php the_title |
|
1180 | - */ |
|
1181 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
1182 | - ?> |
|
1178 | + /** |
|
1179 | + * Filter documented in class-sensei-messages.php the_title |
|
1180 | + */ |
|
1181 | + echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
1182 | + ?> |
|
1183 | 1183 | |
1184 | 1184 | </h1> |
1185 | 1185 | |
1186 | 1186 | </header> |
1187 | 1187 | |
1188 | 1188 | <?php |
1189 | - }//the_title |
|
1189 | + }//the_title |
|
1190 | 1190 | |
1191 | - /** |
|
1192 | - * Output the sensei quiz status message. |
|
1193 | - * |
|
1194 | - * @param $quiz_id |
|
1195 | - */ |
|
1196 | - public static function the_user_status_message( $quiz_id ){ |
|
1191 | + /** |
|
1192 | + * Output the sensei quiz status message. |
|
1193 | + * |
|
1194 | + * @param $quiz_id |
|
1195 | + */ |
|
1196 | + public static function the_user_status_message( $quiz_id ){ |
|
1197 | 1197 | |
1198 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
1199 | - $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
1200 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
1198 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
1199 | + $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
1200 | + echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
1201 | 1201 | |
1202 | - } |
|
1202 | + } |
|
1203 | 1203 | |
1204 | - /** |
|
1205 | - * This functions runs the old sensei_quiz_action_buttons action |
|
1206 | - * for backwards compatiblity sake. |
|
1207 | - * |
|
1208 | - * @since 1.9.0 |
|
1209 | - * @deprecated |
|
1210 | - */ |
|
1211 | - public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
1204 | + /** |
|
1205 | + * This functions runs the old sensei_quiz_action_buttons action |
|
1206 | + * for backwards compatiblity sake. |
|
1207 | + * |
|
1208 | + * @since 1.9.0 |
|
1209 | + * @deprecated |
|
1210 | + */ |
|
1211 | + public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
1212 | 1212 | |
1213 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
1213 | + sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
1214 | 1214 | |
1215 | - } |
|
1215 | + } |
|
1216 | 1216 | |
1217 | - /** |
|
1218 | - * The quiz action buttons needed to ouput quiz |
|
1219 | - * action such as reset complete and save. |
|
1220 | - * |
|
1221 | - * @since 1.3.0 |
|
1222 | - */ |
|
1223 | - public static function action_buttons() { |
|
1217 | + /** |
|
1218 | + * The quiz action buttons needed to ouput quiz |
|
1219 | + * action such as reset complete and save. |
|
1220 | + * |
|
1221 | + * @since 1.3.0 |
|
1222 | + */ |
|
1223 | + public static function action_buttons() { |
|
1224 | 1224 | |
1225 | - global $post, $current_user; |
|
1225 | + global $post, $current_user; |
|
1226 | 1226 | |
1227 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
1228 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
1229 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
1230 | - $show_actions = true; |
|
1231 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
1227 | + $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
1228 | + $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
1229 | + $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
1230 | + $show_actions = true; |
|
1231 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
1232 | 1232 | |
1233 | - //setup quiz grade |
|
1234 | - $user_quiz_grade = ''; |
|
1235 | - if( ! empty( $user_lesson_status ) ){ |
|
1236 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1237 | - } |
|
1233 | + //setup quiz grade |
|
1234 | + $user_quiz_grade = ''; |
|
1235 | + if( ! empty( $user_lesson_status ) ){ |
|
1236 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1237 | + } |
|
1238 | 1238 | |
1239 | 1239 | |
1240 | - if( intval( $lesson_prerequisite ) > 0 ) { |
|
1240 | + if( intval( $lesson_prerequisite ) > 0 ) { |
|
1241 | 1241 | |
1242 | - // If the user hasn't completed the prereq then hide the current actions |
|
1243 | - $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
1242 | + // If the user hasn't completed the prereq then hide the current actions |
|
1243 | + $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
1244 | 1244 | |
1245 | - } |
|
1246 | - if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
1245 | + } |
|
1246 | + if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
1247 | 1247 | |
1248 | - // Get Reset Settings |
|
1249 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
1248 | + // Get Reset Settings |
|
1249 | + $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
1250 | 1250 | |
1251 | 1251 | <!-- Action Nonce's --> |
1252 | 1252 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" |
@@ -1273,55 +1273,55 @@ discard block |
||
1273 | 1273 | |
1274 | 1274 | <?php } |
1275 | 1275 | |
1276 | - } // End sensei_quiz_action_buttons() |
|
1277 | - |
|
1278 | - /** |
|
1279 | - * Fetch the quiz grade |
|
1280 | - * |
|
1281 | - * @since 1.9.0 |
|
1282 | - * |
|
1283 | - * @param int $lesson_id |
|
1284 | - * @param int $user_id |
|
1285 | - * |
|
1286 | - * @return double $user_quiz_grade |
|
1287 | - */ |
|
1288 | - public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
1289 | - |
|
1290 | - // get the quiz grade |
|
1291 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
1292 | - $user_quiz_grade = 0; |
|
1293 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
1294 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1295 | - } |
|
1296 | - |
|
1297 | - return (double) $user_quiz_grade; |
|
1298 | - |
|
1299 | - } |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * Check the quiz reset property for a given lesson's quiz. |
|
1303 | - * |
|
1304 | - * The data is stored on the quiz but going forward the quiz post |
|
1305 | - * type will be retired, hence the lesson_id is a require parameter. |
|
1306 | - * |
|
1307 | - * @since 1.9.0 |
|
1308 | - * |
|
1309 | - * @param int $lesson_id |
|
1310 | - * @return bool |
|
1311 | - */ |
|
1312 | - public static function is_reset_allowed( $lesson_id ){ |
|
1313 | - |
|
1314 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1315 | - |
|
1316 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
1317 | - //backwards compatibility |
|
1318 | - if( 'on' == $reset_allowed ) { |
|
1319 | - $reset_allowed = 1; |
|
1320 | - } |
|
1321 | - |
|
1322 | - return (bool) $reset_allowed; |
|
1323 | - |
|
1324 | - } |
|
1276 | + } // End sensei_quiz_action_buttons() |
|
1277 | + |
|
1278 | + /** |
|
1279 | + * Fetch the quiz grade |
|
1280 | + * |
|
1281 | + * @since 1.9.0 |
|
1282 | + * |
|
1283 | + * @param int $lesson_id |
|
1284 | + * @param int $user_id |
|
1285 | + * |
|
1286 | + * @return double $user_quiz_grade |
|
1287 | + */ |
|
1288 | + public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
1289 | + |
|
1290 | + // get the quiz grade |
|
1291 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
1292 | + $user_quiz_grade = 0; |
|
1293 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
1294 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
1295 | + } |
|
1296 | + |
|
1297 | + return (double) $user_quiz_grade; |
|
1298 | + |
|
1299 | + } |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * Check the quiz reset property for a given lesson's quiz. |
|
1303 | + * |
|
1304 | + * The data is stored on the quiz but going forward the quiz post |
|
1305 | + * type will be retired, hence the lesson_id is a require parameter. |
|
1306 | + * |
|
1307 | + * @since 1.9.0 |
|
1308 | + * |
|
1309 | + * @param int $lesson_id |
|
1310 | + * @return bool |
|
1311 | + */ |
|
1312 | + public static function is_reset_allowed( $lesson_id ){ |
|
1313 | + |
|
1314 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1315 | + |
|
1316 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
1317 | + //backwards compatibility |
|
1318 | + if( 'on' == $reset_allowed ) { |
|
1319 | + $reset_allowed = 1; |
|
1320 | + } |
|
1321 | + |
|
1322 | + return (bool) $reset_allowed; |
|
1323 | + |
|
1324 | + } |
|
1325 | 1325 | |
1326 | 1326 | } // End Class WooThemes_Sensei_Quiz |
1327 | 1327 |
@@ -205,13 +205,13 @@ discard block |
||
205 | 205 | |
206 | 206 | /** |
207 | 207 | * Generates content for a single row of the table in the user management |
208 | - * screen. |
|
209 | - * |
|
208 | + * screen. |
|
209 | + * |
|
210 | 210 | * @since 1.7.0 |
211 | - * |
|
211 | + * |
|
212 | 212 | * @param object $item The current item |
213 | - * |
|
214 | - * @return void |
|
213 | + * |
|
214 | + * @return void |
|
215 | 215 | */ |
216 | 216 | protected function get_row_data( $item ) { |
217 | 217 | global $wp_version; |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | switch ( $this->view ) { |
220 | 220 | case 'learners' : |
221 | 221 | |
222 | - // in this case the item passed in is actually the users activity on course of lesson |
|
223 | - $user_activity = $item; |
|
222 | + // in this case the item passed in is actually the users activity on course of lesson |
|
223 | + $user_activity = $item; |
|
224 | 224 | $post_id = false; |
225 | 225 | |
226 | 226 | if( $this->lesson_id ) { |
@@ -239,30 +239,30 @@ discard block |
||
239 | 239 | |
240 | 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 ); |
|
250 | + $title = Sensei_Learner::get_full_name( $user_activity->user_id ); |
|
251 | 251 | $a_title = sprintf( __( 'Edit “%s”' ), $title ); |
252 | 252 | |
253 | - /** |
|
254 | - * sensei_learners_main_column_data filter |
|
255 | - * |
|
256 | - * This filter runs on the learner management screen for a specific course. |
|
257 | - * It provides the learner row column details. |
|
258 | - * |
|
259 | - * @param array $columns{ |
|
260 | - * type string $title |
|
261 | - * type string $date_started |
|
262 | - * type string $course_status (completed, started etc) |
|
263 | - * type html $action_buttons |
|
264 | - * } |
|
265 | - */ |
|
253 | + /** |
|
254 | + * sensei_learners_main_column_data filter |
|
255 | + * |
|
256 | + * This filter runs on the learner management screen for a specific course. |
|
257 | + * It provides the learner row column details. |
|
258 | + * |
|
259 | + * @param array $columns{ |
|
260 | + * type string $title |
|
261 | + * type string $date_started |
|
262 | + * type string $course_status (completed, started etc) |
|
263 | + * type html $action_buttons |
|
264 | + * } |
|
265 | + */ |
|
266 | 266 | $column_data = apply_filters( 'sensei_learners_main_column_data', array( |
267 | 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 | 268 | 'date_started' => get_comment_meta( $user_activity->comment_ID, 'start', true), |
@@ -292,7 +292,7 @@ discard block |
||
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' ) ) ); |
|
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 | 296 | $title = get_the_title( $item ); |
297 | 297 | $a_title = sprintf( __( 'Edit “%s”' ), $title ); |
298 | 298 |
@@ -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 |