@@ -40,6 +40,7 @@ discard block |
||
| 40 | 40 | * Constructor for the email class hooks in all emails that can be sent. |
| 41 | 41 | * |
| 42 | 42 | * @access public |
| 43 | + * @param string $file |
|
| 43 | 44 | * @return void |
| 44 | 45 | */ |
| 45 | 46 | function __construct( $file ) { |
@@ -140,7 +141,7 @@ discard block |
||
| 140 | 141 | * Wraps a message in the sensei mail template. |
| 141 | 142 | * |
| 142 | 143 | * @access public |
| 143 | - * @param mixed $content |
|
| 144 | + * @param null|string $content |
|
| 144 | 145 | * @return string |
| 145 | 146 | */ |
| 146 | 147 | function wrap_message( $content ) { |
@@ -198,6 +199,9 @@ discard block |
||
| 198 | 199 | remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); |
| 199 | 200 | } |
| 200 | 201 | |
| 202 | + /** |
|
| 203 | + * @param string $email_template |
|
| 204 | + */ |
|
| 201 | 205 | function get_content( $email_template ) { |
| 202 | 206 | |
| 203 | 207 | $message = $this->load_template( $email_template ); |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | add_action( 'sensei_course_status_updated', array( $this, 'learner_completed_course' ), 10, 4 ); |
| 52 | 52 | add_action( 'sensei_course_status_updated', array( $this, 'teacher_completed_course' ), 10, 4 ); |
| 53 | 53 | add_action( 'sensei_user_course_start', array( $this, 'teacher_started_course' ), 10, 2 ); |
| 54 | - add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 ); |
|
| 54 | + add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 ); |
|
| 55 | 55 | add_action( 'sensei_user_quiz_submitted', array( $this, 'teacher_quiz_submitted' ), 10, 5 ); |
| 56 | 56 | add_action( 'sensei_new_private_message', array( $this, 'teacher_new_message' ), 10, 1 ); |
| 57 | 57 | add_action( 'sensei_private_message_reply', array( $this, 'new_message_reply' ), 10, 2 ); |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | $this->emails['learner-graded-quiz'] = include( 'emails/class-woothemes-sensei-email-learner-graded-quiz.php' ); |
| 69 | 69 | $this->emails['learner-completed-course'] = include( 'emails/class-woothemes-sensei-email-learner-completed-course.php' ); |
| 70 | 70 | $this->emails['teacher-completed-course'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-course.php' ); |
| 71 | - $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' ); |
|
| 72 | - $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' ); |
|
| 73 | - $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' ); |
|
| 71 | + $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' ); |
|
| 72 | + $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' ); |
|
| 73 | + $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' ); |
|
| 74 | 74 | $this->emails['teacher-new-message'] = include( 'emails/class-woothemes-sensei-email-teacher-new-message.php' ); |
| 75 | 75 | $this->emails['new-message-reply'] = include( 'emails/class-woothemes-sensei-email-new-message-reply.php' ); |
| 76 | 76 | $this->emails = apply_filters( 'sensei_email_classes', $this->emails ); |
@@ -177,20 +177,20 @@ discard block |
||
| 177 | 177 | add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); |
| 178 | 178 | add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); |
| 179 | 179 | |
| 180 | - // Send |
|
| 181 | - $send_email = true; |
|
| 180 | + // Send |
|
| 181 | + $send_email = true; |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Filter Sensei's ability to send out emails. |
|
| 185 | - * |
|
| 186 | - * @since 1.8.0 |
|
| 187 | - * @param bool $send_email default true |
|
| 188 | - */ |
|
| 189 | - if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message ) ){ |
|
| 183 | + /** |
|
| 184 | + * Filter Sensei's ability to send out emails. |
|
| 185 | + * |
|
| 186 | + * @since 1.8.0 |
|
| 187 | + * @param bool $send_email default true |
|
| 188 | + */ |
|
| 189 | + if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message ) ){ |
|
| 190 | 190 | |
| 191 | - wp_mail( $to, $subject, $message, $headers, $attachments ); |
|
| 191 | + wp_mail( $to, $subject, $message, $headers, $attachments ); |
|
| 192 | 192 | |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | 195 | // Unhook filters |
| 196 | 196 | remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); |
@@ -332,33 +332,33 @@ discard block |
||
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - /** |
|
| 336 | - * teacher_completed_lesson() |
|
| 337 | - * |
|
| 338 | - * Send email to teacher on student completing lesson |
|
| 339 | - * |
|
| 340 | - * @access public |
|
| 341 | - * @return void |
|
| 342 | - * @since 1.9.0 |
|
| 343 | - */ |
|
| 344 | - function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) { |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - $send = false; |
|
| 348 | - |
|
| 349 | - if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) { |
|
| 350 | - if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) { |
|
| 351 | - $send = true; |
|
| 352 | - } |
|
| 353 | - } else { |
|
| 354 | - $send = true; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - if( $send ) { |
|
| 358 | - $email = $this->emails['teacher-completed-lesson']; |
|
| 359 | - $email->trigger( $learner_id, $lesson_id ); |
|
| 360 | - } |
|
| 361 | - } |
|
| 335 | + /** |
|
| 336 | + * teacher_completed_lesson() |
|
| 337 | + * |
|
| 338 | + * Send email to teacher on student completing lesson |
|
| 339 | + * |
|
| 340 | + * @access public |
|
| 341 | + * @return void |
|
| 342 | + * @since 1.9.0 |
|
| 343 | + */ |
|
| 344 | + function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) { |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + $send = false; |
|
| 348 | + |
|
| 349 | + if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) { |
|
| 350 | + if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) { |
|
| 351 | + $send = true; |
|
| 352 | + } |
|
| 353 | + } else { |
|
| 354 | + $send = true; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + if( $send ) { |
|
| 358 | + $email = $this->emails['teacher-completed-lesson']; |
|
| 359 | + $email->trigger( $learner_id, $lesson_id ); |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | 363 | /** |
| 364 | 364 | * Send email to teacher on quiz submission |
@@ -42,22 +42,22 @@ discard block |
||
| 42 | 42 | * @access public |
| 43 | 43 | * @return void |
| 44 | 44 | */ |
| 45 | - function __construct( $file ) { |
|
| 45 | + function __construct($file) { |
|
| 46 | 46 | |
| 47 | 47 | $this->init(); |
| 48 | 48 | |
| 49 | 49 | // Hooks for sending emails during Sensei events |
| 50 | - add_action( 'sensei_user_quiz_grade', array( $this, 'learner_graded_quiz' ), 10, 4 ); |
|
| 51 | - add_action( 'sensei_course_status_updated', array( $this, 'learner_completed_course' ), 10, 4 ); |
|
| 52 | - add_action( 'sensei_course_status_updated', array( $this, 'teacher_completed_course' ), 10, 4 ); |
|
| 53 | - add_action( 'sensei_user_course_start', array( $this, 'teacher_started_course' ), 10, 2 ); |
|
| 54 | - add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 ); |
|
| 55 | - add_action( 'sensei_user_quiz_submitted', array( $this, 'teacher_quiz_submitted' ), 10, 5 ); |
|
| 56 | - add_action( 'sensei_new_private_message', array( $this, 'teacher_new_message' ), 10, 1 ); |
|
| 57 | - add_action( 'sensei_private_message_reply', array( $this, 'new_message_reply' ), 10, 2 ); |
|
| 50 | + add_action('sensei_user_quiz_grade', array($this, 'learner_graded_quiz'), 10, 4); |
|
| 51 | + add_action('sensei_course_status_updated', array($this, 'learner_completed_course'), 10, 4); |
|
| 52 | + add_action('sensei_course_status_updated', array($this, 'teacher_completed_course'), 10, 4); |
|
| 53 | + add_action('sensei_user_course_start', array($this, 'teacher_started_course'), 10, 2); |
|
| 54 | + add_action('sensei_user_lesson_end', array($this, 'teacher_completed_lesson'), 10, 2); |
|
| 55 | + add_action('sensei_user_quiz_submitted', array($this, 'teacher_quiz_submitted'), 10, 5); |
|
| 56 | + add_action('sensei_new_private_message', array($this, 'teacher_new_message'), 10, 1); |
|
| 57 | + add_action('sensei_private_message_reply', array($this, 'new_message_reply'), 10, 2); |
|
| 58 | 58 | |
| 59 | 59 | // Let 3rd parties unhook the above via this hook |
| 60 | - do_action( 'sensei_emails', $this ); |
|
| 60 | + do_action('sensei_emails', $this); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | function init() { |
| 67 | 67 | |
| 68 | - $this->emails['learner-graded-quiz'] = include( 'emails/class-woothemes-sensei-email-learner-graded-quiz.php' ); |
|
| 69 | - $this->emails['learner-completed-course'] = include( 'emails/class-woothemes-sensei-email-learner-completed-course.php' ); |
|
| 70 | - $this->emails['teacher-completed-course'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-course.php' ); |
|
| 71 | - $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' ); |
|
| 72 | - $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' ); |
|
| 73 | - $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' ); |
|
| 74 | - $this->emails['teacher-new-message'] = include( 'emails/class-woothemes-sensei-email-teacher-new-message.php' ); |
|
| 75 | - $this->emails['new-message-reply'] = include( 'emails/class-woothemes-sensei-email-new-message-reply.php' ); |
|
| 76 | - $this->emails = apply_filters( 'sensei_email_classes', $this->emails ); |
|
| 68 | + $this->emails['learner-graded-quiz'] = include('emails/class-woothemes-sensei-email-learner-graded-quiz.php'); |
|
| 69 | + $this->emails['learner-completed-course'] = include('emails/class-woothemes-sensei-email-learner-completed-course.php'); |
|
| 70 | + $this->emails['teacher-completed-course'] = include('emails/class-woothemes-sensei-email-teacher-completed-course.php'); |
|
| 71 | + $this->emails['teacher-started-course'] = include('emails/class-woothemes-sensei-email-teacher-started-course.php'); |
|
| 72 | + $this->emails['teacher-completed-lesson'] = include('emails/class-woothemes-sensei-email-teacher-completed-lesson.php'); |
|
| 73 | + $this->emails['teacher-quiz-submitted'] = include('emails/class-woothemes-sensei-email-teacher-quiz-submitted.php'); |
|
| 74 | + $this->emails['teacher-new-message'] = include('emails/class-woothemes-sensei-email-teacher-new-message.php'); |
|
| 75 | + $this->emails['new-message-reply'] = include('emails/class-woothemes-sensei-email-new-message-reply.php'); |
|
| 76 | + $this->emails = apply_filters('sensei_email_classes', $this->emails); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -95,15 +95,15 @@ discard block |
||
| 95 | 95 | function get_from_name() { |
| 96 | 96 | |
| 97 | 97 | |
| 98 | - if ( ! $this->_from_name ) { |
|
| 99 | - if( isset( Sensei()->settings->settings['email_from_name'] ) && '' != Sensei()->settings->settings['email_from_name'] ) { |
|
| 98 | + if ( ! $this->_from_name) { |
|
| 99 | + if (isset(Sensei()->settings->settings['email_from_name']) && '' != Sensei()->settings->settings['email_from_name']) { |
|
| 100 | 100 | $this->_from_name = Sensei()->settings->settings['email_from_name']; |
| 101 | 101 | } else { |
| 102 | - $this->_from_name = get_bloginfo( 'name' ); |
|
| 102 | + $this->_from_name = get_bloginfo('name'); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - return wp_specialchars_decode( $this->_from_name ); |
|
| 106 | + return wp_specialchars_decode($this->_from_name); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -115,11 +115,11 @@ discard block |
||
| 115 | 115 | function get_from_address() { |
| 116 | 116 | |
| 117 | 117 | |
| 118 | - if ( ! $this->_from_address ) { |
|
| 119 | - if( isset( Sensei()->settings->settings['email_from_address'] ) && '' != Sensei()->settings->settings['email_from_address'] ) { |
|
| 118 | + if ( ! $this->_from_address) { |
|
| 119 | + if (isset(Sensei()->settings->settings['email_from_address']) && '' != Sensei()->settings->settings['email_from_address']) { |
|
| 120 | 120 | $this->_from_address = Sensei()->settings->settings['email_from_address']; |
| 121 | 121 | } else { |
| 122 | - $this->_from_address = get_bloginfo( 'admin_email' ); |
|
| 122 | + $this->_from_address = get_bloginfo('admin_email'); |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
@@ -143,13 +143,13 @@ discard block |
||
| 143 | 143 | * @param mixed $content |
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | - function wrap_message( $content ) { |
|
| 146 | + function wrap_message($content) { |
|
| 147 | 147 | |
| 148 | 148 | $html = ''; |
| 149 | 149 | |
| 150 | - $html .= $this->load_template( 'header' ); |
|
| 151 | - $html .= wpautop( wptexturize( $content ) ); |
|
| 152 | - $html .= $this->load_template( 'footer' ); |
|
| 150 | + $html .= $this->load_template('header'); |
|
| 151 | + $html .= wpautop(wptexturize($content)); |
|
| 152 | + $html .= $this->load_template('footer'); |
|
| 153 | 153 | |
| 154 | 154 | return $html; |
| 155 | 155 | } |
@@ -166,16 +166,16 @@ discard block |
||
| 166 | 166 | * @param string $content_type (default: "text/html") |
| 167 | 167 | * @return void |
| 168 | 168 | */ |
| 169 | - function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "", $content_type = 'text/html' ) { |
|
| 169 | + function send($to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "", $content_type = 'text/html') { |
|
| 170 | 170 | global $email_template; |
| 171 | 171 | |
| 172 | 172 | // Set content type |
| 173 | 173 | $this->_content_type = $content_type; |
| 174 | 174 | |
| 175 | 175 | // Filters for the email |
| 176 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); |
|
| 177 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); |
|
| 178 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); |
|
| 176 | + add_filter('wp_mail_from', array($this, 'get_from_address')); |
|
| 177 | + add_filter('wp_mail_from_name', array($this, 'get_from_name')); |
|
| 178 | + add_filter('wp_mail_content_type', array($this, 'get_content_type')); |
|
| 179 | 179 | |
| 180 | 180 | // Send |
| 181 | 181 | $send_email = true; |
@@ -186,40 +186,40 @@ discard block |
||
| 186 | 186 | * @since 1.8.0 |
| 187 | 187 | * @param bool $send_email default true |
| 188 | 188 | */ |
| 189 | - if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message ) ){ |
|
| 189 | + if (apply_filters('sensei_send_emails', $send_email, $to, $subject, $message)) { |
|
| 190 | 190 | |
| 191 | - wp_mail( $to, $subject, $message, $headers, $attachments ); |
|
| 191 | + wp_mail($to, $subject, $message, $headers, $attachments); |
|
| 192 | 192 | |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // Unhook filters |
| 196 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); |
|
| 197 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); |
|
| 198 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); |
|
| 196 | + remove_filter('wp_mail_from', array($this, 'get_from_address')); |
|
| 197 | + remove_filter('wp_mail_from_name', array($this, 'get_from_name')); |
|
| 198 | + remove_filter('wp_mail_content_type', array($this, 'get_content_type')); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - function get_content( $email_template ) { |
|
| 201 | + function get_content($email_template) { |
|
| 202 | 202 | |
| 203 | - $message = $this->load_template( $email_template ); |
|
| 203 | + $message = $this->load_template($email_template); |
|
| 204 | 204 | |
| 205 | - $html = $this->wrap_message( $message ); |
|
| 205 | + $html = $this->wrap_message($message); |
|
| 206 | 206 | |
| 207 | - return apply_filters( 'sensei_email', $html, $email_template ); |
|
| 207 | + return apply_filters('sensei_email', $html, $email_template); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - function load_template( $template = '' ) { |
|
| 210 | + function load_template($template = '') { |
|
| 211 | 211 | global $email_template; |
| 212 | 212 | |
| 213 | - if( ! $template ) return; |
|
| 213 | + if ( ! $template) return; |
|
| 214 | 214 | |
| 215 | - $email_template = $template . '.php'; |
|
| 216 | - $template = Sensei_Templates::template_loader( '' ); |
|
| 215 | + $email_template = $template.'.php'; |
|
| 216 | + $template = Sensei_Templates::template_loader(''); |
|
| 217 | 217 | |
| 218 | 218 | ob_start(); |
| 219 | 219 | |
| 220 | - do_action( 'sensei_before_email_template', $email_template ); |
|
| 221 | - include( $template ); |
|
| 222 | - do_action( 'sensei_after_email_template', $email_template ); |
|
| 220 | + do_action('sensei_before_email_template', $email_template); |
|
| 221 | + include($template); |
|
| 222 | + do_action('sensei_after_email_template', $email_template); |
|
| 223 | 223 | |
| 224 | 224 | return ob_get_clean(); |
| 225 | 225 | } |
@@ -230,22 +230,22 @@ discard block |
||
| 230 | 230 | * @access public |
| 231 | 231 | * @return void |
| 232 | 232 | */ |
| 233 | - function learner_graded_quiz( $user_id, $quiz_id, $grade, $passmark ) { |
|
| 233 | + function learner_graded_quiz($user_id, $quiz_id, $grade, $passmark) { |
|
| 234 | 234 | |
| 235 | 235 | |
| 236 | 236 | $send = false; |
| 237 | 237 | |
| 238 | - if( isset( Sensei()->settings->settings['email_learners'] ) ) { |
|
| 239 | - if( in_array( 'learner-graded-quiz', (array) Sensei()->settings->settings['email_learners'] ) ) { |
|
| 238 | + if (isset(Sensei()->settings->settings['email_learners'])) { |
|
| 239 | + if (in_array('learner-graded-quiz', (array) Sensei()->settings->settings['email_learners'])) { |
|
| 240 | 240 | $send = true; |
| 241 | 241 | } |
| 242 | 242 | } else { |
| 243 | 243 | $send = true; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - if( $send ) { |
|
| 246 | + if ($send) { |
|
| 247 | 247 | $email = $this->emails['learner-graded-quiz']; |
| 248 | - $email->trigger( $user_id, $quiz_id, $grade, $passmark ); |
|
| 248 | + $email->trigger($user_id, $quiz_id, $grade, $passmark); |
|
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | |
@@ -255,26 +255,26 @@ discard block |
||
| 255 | 255 | * @access public |
| 256 | 256 | * @return void |
| 257 | 257 | */ |
| 258 | - function learner_completed_course( $status = 'in-progress', $user_id = 0, $course_id = 0, $comment_id = 0 ) { |
|
| 258 | + function learner_completed_course($status = 'in-progress', $user_id = 0, $course_id = 0, $comment_id = 0) { |
|
| 259 | 259 | |
| 260 | 260 | |
| 261 | - if( 'complete' != $status ) { |
|
| 261 | + if ('complete' != $status) { |
|
| 262 | 262 | return; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | $send = false; |
| 266 | 266 | |
| 267 | - if( isset( Sensei()->settings->settings['email_learners'] ) ) { |
|
| 268 | - if( in_array( 'learner-completed-course', (array) Sensei()->settings->settings['email_learners'] ) ) { |
|
| 267 | + if (isset(Sensei()->settings->settings['email_learners'])) { |
|
| 268 | + if (in_array('learner-completed-course', (array) Sensei()->settings->settings['email_learners'])) { |
|
| 269 | 269 | $send = true; |
| 270 | 270 | } |
| 271 | 271 | } else { |
| 272 | 272 | $send = true; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - if( $send ) { |
|
| 275 | + if ($send) { |
|
| 276 | 276 | $email = $this->emails['learner-completed-course']; |
| 277 | - $email->trigger( $user_id, $course_id ); |
|
| 277 | + $email->trigger($user_id, $course_id); |
|
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
@@ -284,26 +284,26 @@ discard block |
||
| 284 | 284 | * @access public |
| 285 | 285 | * @return void |
| 286 | 286 | */ |
| 287 | - function teacher_completed_course( $status = 'in-progress', $learner_id = 0, $course_id = 0, $comment_id = 0 ) { |
|
| 287 | + function teacher_completed_course($status = 'in-progress', $learner_id = 0, $course_id = 0, $comment_id = 0) { |
|
| 288 | 288 | |
| 289 | 289 | |
| 290 | - if( 'complete' != $status ) { |
|
| 290 | + if ('complete' != $status) { |
|
| 291 | 291 | return; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | $send = false; |
| 295 | 295 | |
| 296 | - if( isset( Sensei()->settings->settings['email_teachers'] ) ) { |
|
| 297 | - if( in_array( 'teacher-completed-course', (array) Sensei()->settings->settings['email_teachers'] ) ) { |
|
| 296 | + if (isset(Sensei()->settings->settings['email_teachers'])) { |
|
| 297 | + if (in_array('teacher-completed-course', (array) Sensei()->settings->settings['email_teachers'])) { |
|
| 298 | 298 | $send = true; |
| 299 | 299 | } |
| 300 | 300 | } else { |
| 301 | 301 | $send = true; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - if( $send ) { |
|
| 304 | + if ($send) { |
|
| 305 | 305 | $email = $this->emails['teacher-completed-course']; |
| 306 | - $email->trigger( $learner_id, $course_id ); |
|
| 306 | + $email->trigger($learner_id, $course_id); |
|
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | 309 | |
@@ -313,22 +313,22 @@ discard block |
||
| 313 | 313 | * @access public |
| 314 | 314 | * @return void |
| 315 | 315 | */ |
| 316 | - function teacher_started_course( $learner_id = 0, $course_id = 0 ) { |
|
| 316 | + function teacher_started_course($learner_id = 0, $course_id = 0) { |
|
| 317 | 317 | |
| 318 | 318 | |
| 319 | 319 | $send = false; |
| 320 | 320 | |
| 321 | - if( isset( Sensei()->settings->settings['email_teachers'] ) ) { |
|
| 322 | - if( in_array( 'teacher-started-course', (array) Sensei()->settings->settings['email_teachers'] ) ) { |
|
| 321 | + if (isset(Sensei()->settings->settings['email_teachers'])) { |
|
| 322 | + if (in_array('teacher-started-course', (array) Sensei()->settings->settings['email_teachers'])) { |
|
| 323 | 323 | $send = true; |
| 324 | 324 | } |
| 325 | 325 | } else { |
| 326 | 326 | $send = true; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - if( $send ) { |
|
| 329 | + if ($send) { |
|
| 330 | 330 | $email = $this->emails['teacher-started-course']; |
| 331 | - $email->trigger( $learner_id, $course_id ); |
|
| 331 | + $email->trigger($learner_id, $course_id); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
@@ -341,22 +341,22 @@ discard block |
||
| 341 | 341 | * @return void |
| 342 | 342 | * @since 1.9.0 |
| 343 | 343 | */ |
| 344 | - function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) { |
|
| 344 | + function teacher_completed_lesson($learner_id = 0, $lesson_id = 0) { |
|
| 345 | 345 | |
| 346 | 346 | |
| 347 | 347 | $send = false; |
| 348 | 348 | |
| 349 | - if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) { |
|
| 350 | - if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) { |
|
| 349 | + if (isset(Sensei()->settings->settings['email_teachers'])) { |
|
| 350 | + if (in_array('teacher-completed-lesson', (array) Sensei()->settings->settings['email_teachers'])) { |
|
| 351 | 351 | $send = true; |
| 352 | 352 | } |
| 353 | 353 | } else { |
| 354 | 354 | $send = true; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - if( $send ) { |
|
| 357 | + if ($send) { |
|
| 358 | 358 | $email = $this->emails['teacher-completed-lesson']; |
| 359 | - $email->trigger( $learner_id, $lesson_id ); |
|
| 359 | + $email->trigger($learner_id, $lesson_id); |
|
| 360 | 360 | } |
| 361 | 361 | } |
| 362 | 362 | |
@@ -366,25 +366,25 @@ discard block |
||
| 366 | 366 | * @access public |
| 367 | 367 | * @return void |
| 368 | 368 | */ |
| 369 | - function teacher_quiz_submitted( $learner_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0, $quiz_grade_type = 'manual' ) { |
|
| 369 | + function teacher_quiz_submitted($learner_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0, $quiz_grade_type = 'manual') { |
|
| 370 | 370 | |
| 371 | 371 | |
| 372 | 372 | |
| 373 | 373 | $send = false; |
| 374 | 374 | |
| 375 | 375 | // Only trigger if the quiz was marked as manual grading, or auto grading didn't complete |
| 376 | - if( 'manual' == $quiz_grade_type || is_wp_error( $grade ) ) { |
|
| 377 | - if( isset( Sensei()->settings->settings['email_teachers'] ) ) { |
|
| 378 | - if( in_array( 'teacher-quiz-submitted', (array) Sensei()->settings->settings['email_teachers'] ) ) { |
|
| 376 | + if ('manual' == $quiz_grade_type || is_wp_error($grade)) { |
|
| 377 | + if (isset(Sensei()->settings->settings['email_teachers'])) { |
|
| 378 | + if (in_array('teacher-quiz-submitted', (array) Sensei()->settings->settings['email_teachers'])) { |
|
| 379 | 379 | $send = true; |
| 380 | 380 | } |
| 381 | 381 | } else { |
| 382 | 382 | $send = true; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - if( $send ) { |
|
| 385 | + if ($send) { |
|
| 386 | 386 | $email = $this->emails['teacher-quiz-submitted']; |
| 387 | - $email->trigger( $learner_id, $quiz_id ); |
|
| 387 | + $email->trigger($learner_id, $quiz_id); |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | } |
@@ -396,22 +396,22 @@ discard block |
||
| 396 | 396 | * @access public |
| 397 | 397 | * @return void |
| 398 | 398 | */ |
| 399 | - function teacher_new_message( $message_id = 0 ) { |
|
| 399 | + function teacher_new_message($message_id = 0) { |
|
| 400 | 400 | |
| 401 | 401 | |
| 402 | 402 | $send = false; |
| 403 | 403 | |
| 404 | - if( isset( Sensei()->settings->settings['email_teachers'] ) ) { |
|
| 405 | - if( in_array( 'teacher-new-message', (array) Sensei()->settings->settings['email_teachers'] ) ) { |
|
| 404 | + if (isset(Sensei()->settings->settings['email_teachers'])) { |
|
| 405 | + if (in_array('teacher-new-message', (array) Sensei()->settings->settings['email_teachers'])) { |
|
| 406 | 406 | $send = true; |
| 407 | 407 | } |
| 408 | 408 | } else { |
| 409 | 409 | $send = true; |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - if( $send ) { |
|
| 412 | + if ($send) { |
|
| 413 | 413 | $email = $this->emails['teacher-new-message']; |
| 414 | - $email->trigger( $message_id ); |
|
| 414 | + $email->trigger($message_id); |
|
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | 417 | |
@@ -421,22 +421,22 @@ discard block |
||
| 421 | 421 | * @access public |
| 422 | 422 | * @return void |
| 423 | 423 | */ |
| 424 | - function new_message_reply( $comment, $message ) { |
|
| 424 | + function new_message_reply($comment, $message) { |
|
| 425 | 425 | |
| 426 | 426 | |
| 427 | 427 | $send = false; |
| 428 | 428 | |
| 429 | - if( isset( Sensei()->settings->settings['email_global'] ) ) { |
|
| 430 | - if( in_array( 'new-message-reply', (array) Sensei()->settings->settings['email_global'] ) ) { |
|
| 429 | + if (isset(Sensei()->settings->settings['email_global'])) { |
|
| 430 | + if (in_array('new-message-reply', (array) Sensei()->settings->settings['email_global'])) { |
|
| 431 | 431 | $send = true; |
| 432 | 432 | } |
| 433 | 433 | } else { |
| 434 | 434 | $send = true; |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - if( $send ) { |
|
| 437 | + if ($send) { |
|
| 438 | 438 | $email = $this->emails['new-message-reply']; |
| 439 | - $email->trigger( $comment, $message ); |
|
| 439 | + $email->trigger($comment, $message); |
|
| 440 | 440 | } |
| 441 | 441 | } |
| 442 | 442 | |
@@ -447,4 +447,4 @@ discard block |
||
| 447 | 447 | * for backward compatibility |
| 448 | 448 | * @since 1.9.0 |
| 449 | 449 | */ |
| 450 | -class WooThemes_Sensei_Emails extends Sensei_Emails{} |
|
| 450 | +class WooThemes_Sensei_Emails extends Sensei_Emails {} |
|
@@ -210,7 +210,9 @@ |
||
| 210 | 210 | function load_template( $template = '' ) { |
| 211 | 211 | global $email_template; |
| 212 | 212 | |
| 213 | - if( ! $template ) return; |
|
| 213 | + if( ! $template ) { |
|
| 214 | + return; |
|
| 215 | + } |
|
| 214 | 216 | |
| 215 | 217 | $email_template = $template . '.php'; |
| 216 | 218 | $template = Sensei_Templates::template_loader( '' ); |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * Constructor |
| 23 | 23 | * @since 1.3.0 |
| 24 | 24 | * |
| 25 | - * @param $file |
|
| 25 | + * @param string $file |
|
| 26 | 26 | */ |
| 27 | 27 | public function __construct ( $file ) { |
| 28 | 28 | $this->name = __( 'Grading', 'woothemes-sensei' ); |
@@ -330,6 +330,7 @@ discard block |
||
| 330 | 330 | /** |
| 331 | 331 | * Return array of valid statuses for either Course or Lesson |
| 332 | 332 | * @since 1.7.0 |
| 333 | + * @param string $type |
|
| 333 | 334 | * @return array |
| 334 | 335 | */ |
| 335 | 336 | public function get_stati( $type ) { |
@@ -529,7 +530,7 @@ discard block |
||
| 529 | 530 | * the grades as the Grader selected theme and saves the total grade and |
| 530 | 531 | * individual question grades. |
| 531 | 532 | * |
| 532 | - * @return bool |
|
| 533 | + * @return false|null |
|
| 533 | 534 | */ |
| 534 | 535 | public function admin_process_grading_submission() { |
| 535 | 536 | |
@@ -906,8 +907,8 @@ discard block |
||
| 906 | 907 | * Grading logic specifically for the gap fill questions |
| 907 | 908 | * |
| 908 | 909 | * @since 1.9.0 |
| 909 | - * @param $question_id |
|
| 910 | - * @param $user_answer |
|
| 910 | + * @param integer $question_id |
|
| 911 | + * @param string $user_answer |
|
| 911 | 912 | * |
| 912 | 913 | * @return bool | int false or the grade given to the user answer |
| 913 | 914 | */ |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Grading Class |
@@ -130,8 +133,7 @@ discard block |
||
| 130 | 133 | $object_name = 'WooThemes_Sensei_Grading_' . $name; |
| 131 | 134 | if ( is_null($optional_data) ) { |
| 132 | 135 | $sensei_grading_object = new $object_name( $data ); |
| 133 | - } |
|
| 134 | - else { |
|
| 136 | + } else { |
|
| 135 | 137 | $sensei_grading_object = new $object_name( $data, $optional_data ); |
| 136 | 138 | } // End If Statement |
| 137 | 139 | if ( 'Main' == $name ) { |
@@ -150,8 +152,7 @@ discard block |
||
| 150 | 152 | |
| 151 | 153 | if ( isset( $_GET['quiz_id'] ) && 0 < intval( $_GET['quiz_id'] ) && isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { |
| 152 | 154 | $this->grading_user_quiz_view(); |
| 153 | - } |
|
| 154 | - else { |
|
| 155 | + } else { |
|
| 155 | 156 | $this->grading_default_view(); |
| 156 | 157 | } // End If Statement |
| 157 | 158 | } // End grading_page() |
@@ -273,8 +274,7 @@ discard block |
||
| 273 | 274 | if ( version_compare($wp_version, '4.1', '>=') ) { |
| 274 | 275 | $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
| 275 | 276 | $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
| 276 | - } |
|
| 277 | - else { |
|
| 277 | + } else { |
|
| 278 | 278 | $title .= sprintf( ' <span class="course-title">> %s</span>', get_the_title( $course_id ) ); |
| 279 | 279 | } |
| 280 | 280 | } |
@@ -309,8 +309,7 @@ discard block |
||
| 309 | 309 | if ( version_compare($wp_version, '4.1', '>=') ) { |
| 310 | 310 | $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
| 311 | 311 | $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
| 312 | - } |
|
| 313 | - else { |
|
| 312 | + } else { |
|
| 314 | 313 | $title .= sprintf( ' <span class="course-title">> %s</span>', get_the_title( $course_id ) ); |
| 315 | 314 | } |
| 316 | 315 | $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id ), admin_url( 'admin.php' ) ); |
@@ -379,8 +378,7 @@ discard block |
||
| 379 | 378 | |
| 380 | 379 | if ( 'course' == $args['type'] ) { |
| 381 | 380 | $type = 'sensei_course_status'; |
| 382 | - } |
|
| 383 | - else { |
|
| 381 | + } else { |
|
| 384 | 382 | $type = 'sensei_lesson_status'; |
| 385 | 383 | } |
| 386 | 384 | $cache_key = 'sensei-' . $args['type'] . '-statuses'; |
@@ -390,15 +388,13 @@ discard block |
||
| 390 | 388 | // Restrict to specific posts |
| 391 | 389 | if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) { |
| 392 | 390 | $query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')'; |
| 393 | - } |
|
| 394 | - elseif ( !empty( $args['post_id'] ) ) { |
|
| 391 | + } elseif ( !empty( $args['post_id'] ) ) { |
|
| 395 | 392 | $query .= $wpdb->prepare( ' AND comment_post_ID = %d', $args['post_id'] ); |
| 396 | 393 | } |
| 397 | 394 | // Restrict to specific users |
| 398 | 395 | if ( isset( $args['user_id'] ) && is_array( $args['user_id'] ) ) { |
| 399 | 396 | $query .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $args['user_id'] ) ) . ')'; |
| 400 | - } |
|
| 401 | - elseif ( !empty( $args['user_id'] ) ) { |
|
| 397 | + } elseif ( !empty( $args['user_id'] ) ) { |
|
| 402 | 398 | $query .= $wpdb->prepare( ' AND user_id = %d', $args['user_id'] ); |
| 403 | 399 | } |
| 404 | 400 | $query .= ' GROUP BY comment_approved'; |
@@ -601,8 +597,7 @@ discard block |
||
| 601 | 597 | // set the users total quiz grade |
| 602 | 598 | if ( 0 < intval( $quiz_grade_total ) ) { |
| 603 | 599 | $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); |
| 604 | - } |
|
| 605 | - else { |
|
| 600 | + } else { |
|
| 606 | 601 | $grade = 0; |
| 607 | 602 | } |
| 608 | 603 | WooThemes_Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); |
@@ -615,8 +610,7 @@ discard block |
||
| 615 | 610 | // Student has reached the pass mark and lesson is complete |
| 616 | 611 | if ( $quiz_passmark <= $grade ) { |
| 617 | 612 | $lesson_status = 'passed'; |
| 618 | - } |
|
| 619 | - else { |
|
| 613 | + } else { |
|
| 620 | 614 | $lesson_status = 'failed'; |
| 621 | 615 | } // End If Statement |
| 622 | 616 | } |
@@ -761,8 +755,7 @@ discard block |
||
| 761 | 755 | // Question has a zero grade, so skip grading |
| 762 | 756 | if ( 0 == $achievable_grade ) { |
| 763 | 757 | $all_question_grades[ $question_id ] = $achievable_grade; |
| 764 | - } |
|
| 765 | - elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
| 758 | + } elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
| 766 | 759 | // Get user question grade |
| 767 | 760 | $question_grade = WooThemes_Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
| 768 | 761 | $all_question_grades[ $question_id ] = $question_grade; |
@@ -784,8 +777,7 @@ discard block |
||
| 784 | 777 | // Check for zero total from grades |
| 785 | 778 | if ( 0 < $quiz_total ) { |
| 786 | 779 | $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); |
| 787 | - } |
|
| 788 | - else { |
|
| 780 | + } else { |
|
| 789 | 781 | $grade = 0; |
| 790 | 782 | } |
| 791 | 783 | WooThemes_Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); |
@@ -945,19 +937,19 @@ discard block |
||
| 945 | 937 | |
| 946 | 938 | return Sensei()->question->get_question_grade($question_id); |
| 947 | 939 | |
| 948 | - }else{ |
|
| 940 | + } else{ |
|
| 949 | 941 | |
| 950 | 942 | return false; |
| 951 | 943 | |
| 952 | 944 | } |
| 953 | 945 | |
| 954 | - }else{ |
|
| 946 | + } else{ |
|
| 955 | 947 | |
| 956 | 948 | return false; |
| 957 | 949 | |
| 958 | 950 | } |
| 959 | 951 | |
| 960 | - }else{ |
|
| 952 | + } else{ |
|
| 961 | 953 | |
| 962 | 954 | // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
| 963 | 955 | if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { |
@@ -970,13 +962,13 @@ discard block |
||
| 970 | 962 | |
| 971 | 963 | return Sensei()->question->get_question_grade( $question_id ); |
| 972 | 964 | |
| 973 | - }else{ |
|
| 965 | + } else{ |
|
| 974 | 966 | |
| 975 | 967 | return false; |
| 976 | 968 | |
| 977 | 969 | } |
| 978 | 970 | |
| 979 | - }else{ |
|
| 971 | + } else{ |
|
| 980 | 972 | |
| 981 | 973 | return false; |
| 982 | 974 | |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * Constructor |
| 23 | 23 | * @since 1.3.0 |
| 24 | - * |
|
| 25 | - * @param $file |
|
| 24 | + * |
|
| 25 | + * @param $file |
|
| 26 | 26 | */ |
| 27 | 27 | public function __construct ( $file ) { |
| 28 | 28 | $this->name = __( 'Grading', 'woothemes-sensei' ); |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | } |
| 285 | 285 | if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) { |
| 286 | 286 | |
| 287 | - $user_name = Sensei_Student::get_full_name( $_GET['user_id'] ); |
|
| 287 | + $user_name = Sensei_Student::get_full_name( $_GET['user_id'] ); |
|
| 288 | 288 | $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
| 289 | 289 | |
| 290 | 290 | } // End If Statement |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | } |
| 319 | 319 | if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { |
| 320 | 320 | |
| 321 | - $user_name = Sensei_Student::get_full_name( $_GET['user'] ); |
|
| 321 | + $user_name = Sensei_Student::get_full_name( $_GET['user'] ); |
|
| 322 | 322 | $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
| 323 | 323 | |
| 324 | 324 | } // End If Statement |
@@ -367,15 +367,15 @@ discard block |
||
| 367 | 367 | public function count_statuses( $args = array() ) { |
| 368 | 368 | global $wpdb; |
| 369 | 369 | |
| 370 | - /** |
|
| 371 | - * Filter fires inside Sensei_Grading::count_statuses |
|
| 372 | - * |
|
| 373 | - * Alter the the post_in array to determine which posts the |
|
| 374 | - * comment query should be limited to. |
|
| 375 | - * @since 1.8.0 |
|
| 376 | - * @param array $args |
|
| 377 | - */ |
|
| 378 | - $args = apply_filters( 'sensei_count_statuses_args', $args ); |
|
| 370 | + /** |
|
| 371 | + * Filter fires inside Sensei_Grading::count_statuses |
|
| 372 | + * |
|
| 373 | + * Alter the the post_in array to determine which posts the |
|
| 374 | + * comment query should be limited to. |
|
| 375 | + * @since 1.8.0 |
|
| 376 | + * @param array $args |
|
| 377 | + */ |
|
| 378 | + $args = apply_filters( 'sensei_count_statuses_args', $args ); |
|
| 379 | 379 | |
| 380 | 380 | if ( 'course' == $args['type'] ) { |
| 381 | 381 | $type = 'sensei_course_status'; |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | |
| 388 | 388 | $query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s "; |
| 389 | 389 | |
| 390 | - // Restrict to specific posts |
|
| 390 | + // Restrict to specific posts |
|
| 391 | 391 | if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) { |
| 392 | 392 | $query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')'; |
| 393 | 393 | } |
@@ -522,148 +522,148 @@ discard block |
||
| 522 | 522 | return $html; |
| 523 | 523 | } // End lessons_drop_down_html() |
| 524 | 524 | |
| 525 | - /** |
|
| 526 | - * The process grading function handles admin grading submissions. |
|
| 527 | - * |
|
| 528 | - * This function is hooked on to admin_init. It simply accepts |
|
| 529 | - * the grades as the Grader selected theme and saves the total grade and |
|
| 530 | - * individual question grades. |
|
| 531 | - * |
|
| 532 | - * @return bool |
|
| 533 | - */ |
|
| 534 | - public function admin_process_grading_submission() { |
|
| 525 | + /** |
|
| 526 | + * The process grading function handles admin grading submissions. |
|
| 527 | + * |
|
| 528 | + * This function is hooked on to admin_init. It simply accepts |
|
| 529 | + * the grades as the Grader selected theme and saves the total grade and |
|
| 530 | + * individual question grades. |
|
| 531 | + * |
|
| 532 | + * @return bool |
|
| 533 | + */ |
|
| 534 | + public function admin_process_grading_submission() { |
|
| 535 | 535 | |
| 536 | - // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry |
|
| 537 | - if( ! isset( $_POST['sensei_manual_grade'] ) |
|
| 538 | - || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) |
|
| 539 | - || ! isset( $_GET['quiz_id'] ) |
|
| 540 | - || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { |
|
| 536 | + // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry |
|
| 537 | + if( ! isset( $_POST['sensei_manual_grade'] ) |
|
| 538 | + || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) |
|
| 539 | + || ! isset( $_GET['quiz_id'] ) |
|
| 540 | + || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { |
|
| 541 | 541 | |
| 542 | - return false; //exit and do not grade |
|
| 542 | + return false; //exit and do not grade |
|
| 543 | 543 | |
| 544 | - } |
|
| 544 | + } |
|
| 545 | 545 | |
| 546 | - $quiz_id = $_GET['quiz_id']; |
|
| 547 | - $user_id = $_GET['user']; |
|
| 546 | + $quiz_id = $_GET['quiz_id']; |
|
| 547 | + $user_id = $_GET['user']; |
|
| 548 | 548 | |
| 549 | 549 | |
| 550 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 551 | - $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 552 | - $quiz_grade = 0; |
|
| 553 | - $count = 0; |
|
| 554 | - $quiz_grade_total = $_POST['quiz_grade_total']; |
|
| 555 | - $all_question_grades = array(); |
|
| 556 | - $all_answers_feedback = array(); |
|
| 550 | + $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 551 | + $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 552 | + $quiz_grade = 0; |
|
| 553 | + $count = 0; |
|
| 554 | + $quiz_grade_total = $_POST['quiz_grade_total']; |
|
| 555 | + $all_question_grades = array(); |
|
| 556 | + $all_answers_feedback = array(); |
|
| 557 | 557 | |
| 558 | - foreach( $questions as $question ) { |
|
| 558 | + foreach( $questions as $question ) { |
|
| 559 | 559 | |
| 560 | - ++$count; |
|
| 561 | - $question_id = $question->ID; |
|
| 560 | + ++$count; |
|
| 561 | + $question_id = $question->ID; |
|
| 562 | 562 | |
| 563 | - if( isset( $_POST[ 'question_' . $question_id ] ) ) { |
|
| 563 | + if( isset( $_POST[ 'question_' . $question_id ] ) ) { |
|
| 564 | 564 | |
| 565 | - $question_grade = 0; |
|
| 566 | - if( $_POST[ 'question_' . $question_id ] == 'right' ) { |
|
| 565 | + $question_grade = 0; |
|
| 566 | + if( $_POST[ 'question_' . $question_id ] == 'right' ) { |
|
| 567 | 567 | |
| 568 | - $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; |
|
| 568 | + $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; |
|
| 569 | 569 | |
| 570 | - } |
|
| 570 | + } |
|
| 571 | 571 | |
| 572 | - // add data to the array that will, after the loop, be stored on the lesson status |
|
| 573 | - $all_question_grades[ $question_id ] = $question_grade; |
|
| 572 | + // add data to the array that will, after the loop, be stored on the lesson status |
|
| 573 | + $all_question_grades[ $question_id ] = $question_grade; |
|
| 574 | 574 | |
| 575 | - // tally up the total quiz grade |
|
| 576 | - $quiz_grade += $question_grade; |
|
| 575 | + // tally up the total quiz grade |
|
| 576 | + $quiz_grade += $question_grade; |
|
| 577 | 577 | |
| 578 | - } // endif |
|
| 578 | + } // endif |
|
| 579 | 579 | |
| 580 | - // Question answer feedback / notes |
|
| 581 | - $question_feedback = ''; |
|
| 582 | - if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ |
|
| 580 | + // Question answer feedback / notes |
|
| 581 | + $question_feedback = ''; |
|
| 582 | + if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ |
|
| 583 | 583 | |
| 584 | - $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); |
|
| 584 | + $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); |
|
| 585 | 585 | |
| 586 | - } |
|
| 587 | - $all_answers_feedback[ $question_id ] = $question_feedback; |
|
| 586 | + } |
|
| 587 | + $all_answers_feedback[ $question_id ] = $question_feedback; |
|
| 588 | 588 | |
| 589 | - } // end for each $questions |
|
| 589 | + } // end for each $questions |
|
| 590 | 590 | |
| 591 | - //store all question grades on the lesson status |
|
| 592 | - Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); |
|
| 591 | + //store all question grades on the lesson status |
|
| 592 | + Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); |
|
| 593 | 593 | |
| 594 | - //store the feedback from grading |
|
| 595 | - Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); |
|
| 594 | + //store the feedback from grading |
|
| 595 | + Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); |
|
| 596 | 596 | |
| 597 | - // $_POST['all_questions_graded'] is set when all questions have been graded |
|
| 598 | - // in the class sensei grading user quiz -> display() |
|
| 599 | - if( $_POST['all_questions_graded'] == 'yes' ) { |
|
| 597 | + // $_POST['all_questions_graded'] is set when all questions have been graded |
|
| 598 | + // in the class sensei grading user quiz -> display() |
|
| 599 | + if( $_POST['all_questions_graded'] == 'yes' ) { |
|
| 600 | 600 | |
| 601 | - // set the users total quiz grade |
|
| 601 | + // set the users total quiz grade |
|
| 602 | 602 | if ( 0 < intval( $quiz_grade_total ) ) { |
| 603 | - $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); |
|
| 603 | + $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); |
|
| 604 | 604 | } |
| 605 | 605 | else { |
| 606 | 606 | $grade = 0; |
| 607 | 607 | } |
| 608 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); |
|
| 609 | - |
|
| 610 | - // Duplicating what Frontend->sensei_complete_quiz() does |
|
| 611 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 612 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 613 | - $lesson_metadata = array(); |
|
| 614 | - if ( $pass_required ) { |
|
| 615 | - // Student has reached the pass mark and lesson is complete |
|
| 616 | - if ( $quiz_passmark <= $grade ) { |
|
| 617 | - $lesson_status = 'passed'; |
|
| 618 | - } |
|
| 619 | - else { |
|
| 620 | - $lesson_status = 'failed'; |
|
| 621 | - } // End If Statement |
|
| 622 | - } |
|
| 623 | - // Student only has to partake the quiz |
|
| 624 | - else { |
|
| 625 | - $lesson_status = 'graded'; |
|
| 626 | - } |
|
| 627 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above |
|
| 608 | + Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); |
|
| 609 | + |
|
| 610 | + // Duplicating what Frontend->sensei_complete_quiz() does |
|
| 611 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 612 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 613 | + $lesson_metadata = array(); |
|
| 614 | + if ( $pass_required ) { |
|
| 615 | + // Student has reached the pass mark and lesson is complete |
|
| 616 | + if ( $quiz_passmark <= $grade ) { |
|
| 617 | + $lesson_status = 'passed'; |
|
| 618 | + } |
|
| 619 | + else { |
|
| 620 | + $lesson_status = 'failed'; |
|
| 621 | + } // End If Statement |
|
| 622 | + } |
|
| 623 | + // Student only has to partake the quiz |
|
| 624 | + else { |
|
| 625 | + $lesson_status = 'graded'; |
|
| 626 | + } |
|
| 627 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above |
|
| 628 | 628 | |
| 629 | - Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); |
|
| 629 | + Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); |
|
| 630 | 630 | |
| 631 | - if( in_array( $lesson_status, array( 'passed', 'graded' ) ) ) { |
|
| 631 | + if( in_array( $lesson_status, array( 'passed', 'graded' ) ) ) { |
|
| 632 | 632 | |
| 633 | - /** |
|
| 634 | - * Summary. |
|
| 635 | - * |
|
| 636 | - * Description. |
|
| 637 | - * |
|
| 638 | - * @since 1.7.0 |
|
| 639 | - * |
|
| 640 | - * @param int $user_id |
|
| 641 | - * @param int $quiz_lesson_id |
|
| 642 | - */ |
|
| 643 | - do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); |
|
| 633 | + /** |
|
| 634 | + * Summary. |
|
| 635 | + * |
|
| 636 | + * Description. |
|
| 637 | + * |
|
| 638 | + * @since 1.7.0 |
|
| 639 | + * |
|
| 640 | + * @param int $user_id |
|
| 641 | + * @param int $quiz_lesson_id |
|
| 642 | + */ |
|
| 643 | + do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); |
|
| 644 | 644 | |
| 645 | - } // end if in_array |
|
| 645 | + } // end if in_array |
|
| 646 | 646 | |
| 647 | - }// end if $_POST['all_que... |
|
| 647 | + }// end if $_POST['all_que... |
|
| 648 | 648 | |
| 649 | - if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { |
|
| 649 | + if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { |
|
| 650 | 650 | |
| 651 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 651 | + $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 652 | 652 | |
| 653 | - } elseif ( isset( $_POST['_wp_http_referer'] ) ) { |
|
| 653 | + } elseif ( isset( $_POST['_wp_http_referer'] ) ) { |
|
| 654 | 654 | |
| 655 | - $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); |
|
| 655 | + $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); |
|
| 656 | 656 | |
| 657 | - } else { |
|
| 657 | + } else { |
|
| 658 | 658 | |
| 659 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 659 | + $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 660 | 660 | |
| 661 | - } |
|
| 661 | + } |
|
| 662 | 662 | |
| 663 | - wp_safe_redirect( esc_url_raw( $load_url ) ); |
|
| 664 | - exit; |
|
| 663 | + wp_safe_redirect( esc_url_raw( $load_url ) ); |
|
| 664 | + exit; |
|
| 665 | 665 | |
| 666 | - } // end admin_process_grading_submission |
|
| 666 | + } // end admin_process_grading_submission |
|
| 667 | 667 | |
| 668 | 668 | public function get_redirect_url() { |
| 669 | 669 | // Parse POST data |
@@ -708,283 +708,283 @@ discard block |
||
| 708 | 708 | } // End If Statement |
| 709 | 709 | } // End sensei_grading_notices() |
| 710 | 710 | |
| 711 | - /** |
|
| 712 | - * Grade quiz automatically |
|
| 713 | - * |
|
| 714 | - * This function grades each question automatically if there all questions are auto gradable. If not |
|
| 715 | - * the quiz will not be auto gradable. |
|
| 716 | - * |
|
| 717 | - * @since 1.7.4 |
|
| 718 | - * |
|
| 719 | - * @param integer $quiz_id ID of quiz |
|
| 720 | - * @param array $submitted questions id ans answers { |
|
| 721 | - * @type int $question_id |
|
| 722 | - * @type mixed $answer |
|
| 723 | - * } |
|
| 724 | - * @param integer $total_questions Total questions in quiz (not used) |
|
| 725 | - * @param string $quiz_grade_type Optional defaults to auto |
|
| 726 | - * |
|
| 727 | - * @return int $quiz_grade total sum of all question grades |
|
| 728 | - */ |
|
| 729 | - public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 730 | - |
|
| 731 | - if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted |
|
| 732 | - || $quiz_grade_type != 'auto' ) { |
|
| 733 | - return false; // exit early |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - $user_id = get_current_user_id(); |
|
| 738 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; |
|
| 739 | - $quiz_autogradable = true; |
|
| 740 | - |
|
| 741 | - /** |
|
| 742 | - * Filter the types of question types that can be automatically graded. |
|
| 743 | - * |
|
| 744 | - * This filter fires inside the auto grade quiz function and provides you with the default list. |
|
| 745 | - * |
|
| 746 | - * @param array { |
|
| 747 | - * 'multiple-choice', |
|
| 748 | - * 'boolean', |
|
| 749 | - * 'gap-fill'. |
|
| 750 | - * } |
|
| 751 | - */ |
|
| 752 | - $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); |
|
| 753 | - |
|
| 754 | - $grade_total = 0; |
|
| 755 | - $all_question_grades = array(); |
|
| 756 | - foreach( $submitted as $question_id => $answer ) { |
|
| 757 | - |
|
| 758 | - // check if the question is autogradable, either by type, or because the grade is 0 |
|
| 759 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 711 | + /** |
|
| 712 | + * Grade quiz automatically |
|
| 713 | + * |
|
| 714 | + * This function grades each question automatically if there all questions are auto gradable. If not |
|
| 715 | + * the quiz will not be auto gradable. |
|
| 716 | + * |
|
| 717 | + * @since 1.7.4 |
|
| 718 | + * |
|
| 719 | + * @param integer $quiz_id ID of quiz |
|
| 720 | + * @param array $submitted questions id ans answers { |
|
| 721 | + * @type int $question_id |
|
| 722 | + * @type mixed $answer |
|
| 723 | + * } |
|
| 724 | + * @param integer $total_questions Total questions in quiz (not used) |
|
| 725 | + * @param string $quiz_grade_type Optional defaults to auto |
|
| 726 | + * |
|
| 727 | + * @return int $quiz_grade total sum of all question grades |
|
| 728 | + */ |
|
| 729 | + public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 730 | + |
|
| 731 | + if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted |
|
| 732 | + || $quiz_grade_type != 'auto' ) { |
|
| 733 | + return false; // exit early |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + $user_id = get_current_user_id(); |
|
| 738 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; |
|
| 739 | + $quiz_autogradable = true; |
|
| 740 | + |
|
| 741 | + /** |
|
| 742 | + * Filter the types of question types that can be automatically graded. |
|
| 743 | + * |
|
| 744 | + * This filter fires inside the auto grade quiz function and provides you with the default list. |
|
| 745 | + * |
|
| 746 | + * @param array { |
|
| 747 | + * 'multiple-choice', |
|
| 748 | + * 'boolean', |
|
| 749 | + * 'gap-fill'. |
|
| 750 | + * } |
|
| 751 | + */ |
|
| 752 | + $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); |
|
| 753 | + |
|
| 754 | + $grade_total = 0; |
|
| 755 | + $all_question_grades = array(); |
|
| 756 | + foreach( $submitted as $question_id => $answer ) { |
|
| 757 | + |
|
| 758 | + // check if the question is autogradable, either by type, or because the grade is 0 |
|
| 759 | + $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 760 | 760 | $achievable_grade = Sensei()->question->get_question_grade( $question_id ); |
| 761 | 761 | // Question has a zero grade, so skip grading |
| 762 | 762 | if ( 0 == $achievable_grade ) { |
| 763 | 763 | $all_question_grades[ $question_id ] = $achievable_grade; |
| 764 | 764 | } |
| 765 | - elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
| 766 | - // Get user question grade |
|
| 767 | - $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 768 | - $all_question_grades[ $question_id ] = $question_grade; |
|
| 769 | - $grade_total += $question_grade; |
|
| 765 | + elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
| 766 | + // Get user question grade |
|
| 767 | + $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 768 | + $all_question_grades[ $question_id ] = $question_grade; |
|
| 769 | + $grade_total += $question_grade; |
|
| 770 | 770 | |
| 771 | - } else { |
|
| 771 | + } else { |
|
| 772 | 772 | |
| 773 | - // There is a question that cannot be autograded |
|
| 774 | - $quiz_autogradable = false; |
|
| 773 | + // There is a question that cannot be autograded |
|
| 774 | + $quiz_autogradable = false; |
|
| 775 | 775 | |
| 776 | - } // end if in_array( $question_type... |
|
| 776 | + } // end if in_array( $question_type... |
|
| 777 | 777 | |
| 778 | - }// end for each question |
|
| 778 | + }// end for each question |
|
| 779 | 779 | |
| 780 | - // Only if the whole quiz was autogradable do we set a grade |
|
| 781 | - if ( $quiz_autogradable ) { |
|
| 780 | + // Only if the whole quiz was autogradable do we set a grade |
|
| 781 | + if ( $quiz_autogradable ) { |
|
| 782 | 782 | |
| 783 | - $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); |
|
| 783 | + $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); |
|
| 784 | 784 | // Check for zero total from grades |
| 785 | 785 | if ( 0 < $quiz_total ) { |
| 786 | - $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); |
|
| 786 | + $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); |
|
| 787 | 787 | } |
| 788 | 788 | else { |
| 789 | 789 | $grade = 0; |
| 790 | 790 | } |
| 791 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); |
|
| 791 | + Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); |
|
| 792 | 792 | |
| 793 | - } else { |
|
| 793 | + } else { |
|
| 794 | 794 | |
| 795 | - $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); |
|
| 795 | + $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); |
|
| 796 | 796 | |
| 797 | - } |
|
| 798 | - |
|
| 799 | - // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default |
|
| 800 | - // when doing manual grading. |
|
| 801 | - Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); |
|
| 797 | + } |
|
| 802 | 798 | |
| 803 | - return $grade; |
|
| 799 | + // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default |
|
| 800 | + // when doing manual grading. |
|
| 801 | + Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); |
|
| 804 | 802 | |
| 805 | - } // End grade_quiz_auto() |
|
| 803 | + return $grade; |
|
| 806 | 804 | |
| 807 | - /** |
|
| 808 | - * Grade question automatically |
|
| 809 | - * |
|
| 810 | - * This function checks the question typ and then grades it accordingly. |
|
| 811 | - * |
|
| 812 | - * @since 1.7.4 |
|
| 813 | - * |
|
| 814 | - * @param integer $question_id |
|
| 815 | - * @param string $question_type of the standard Sensei question types |
|
| 816 | - * @param string $answer |
|
| 817 | - * @param int $user_id |
|
| 818 | - * |
|
| 819 | - * @return int $question_grade |
|
| 820 | - */ |
|
| 821 | - public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 822 | - |
|
| 823 | - if( intval( $user_id ) == 0 ) { |
|
| 824 | - |
|
| 825 | - $user_id = get_current_user_id(); |
|
| 826 | - |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - if( ! ( intval( $question_id ) > 0 ) ) { |
|
| 830 | - |
|
| 831 | - return false; |
|
| 832 | - |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - Sensei()->question->get_question_type( $question_id ); |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * Applying a grade before the auto grading takes place. |
|
| 840 | - * |
|
| 841 | - * This filter is applied just before the question is auto graded. It fires in the context of a single question |
|
| 842 | - * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value |
|
| 843 | - * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question. |
|
| 844 | - * |
|
| 845 | - * @param int $question_grade default false |
|
| 846 | - * @param int $question_id |
|
| 847 | - * @param string $question_type one of the Sensei question type. |
|
| 848 | - * @param string $answer user supplied question answer |
|
| 849 | - */ |
|
| 850 | - $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); |
|
| 805 | + } // End grade_quiz_auto() |
|
| 851 | 806 | |
| 852 | - if ( false !== $question_grade ) { |
|
| 807 | + /** |
|
| 808 | + * Grade question automatically |
|
| 809 | + * |
|
| 810 | + * This function checks the question typ and then grades it accordingly. |
|
| 811 | + * |
|
| 812 | + * @since 1.7.4 |
|
| 813 | + * |
|
| 814 | + * @param integer $question_id |
|
| 815 | + * @param string $question_type of the standard Sensei question types |
|
| 816 | + * @param string $answer |
|
| 817 | + * @param int $user_id |
|
| 818 | + * |
|
| 819 | + * @return int $question_grade |
|
| 820 | + */ |
|
| 821 | + public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 822 | + |
|
| 823 | + if( intval( $user_id ) == 0 ) { |
|
| 824 | + |
|
| 825 | + $user_id = get_current_user_id(); |
|
| 826 | + |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + if( ! ( intval( $question_id ) > 0 ) ) { |
|
| 830 | + |
|
| 831 | + return false; |
|
| 832 | + |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + Sensei()->question->get_question_type( $question_id ); |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * Applying a grade before the auto grading takes place. |
|
| 840 | + * |
|
| 841 | + * This filter is applied just before the question is auto graded. It fires in the context of a single question |
|
| 842 | + * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value |
|
| 843 | + * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question. |
|
| 844 | + * |
|
| 845 | + * @param int $question_grade default false |
|
| 846 | + * @param int $question_id |
|
| 847 | + * @param string $question_type one of the Sensei question type. |
|
| 848 | + * @param string $answer user supplied question answer |
|
| 849 | + */ |
|
| 850 | + $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); |
|
| 853 | 851 | |
| 854 | - return $question_grade; |
|
| 852 | + if ( false !== $question_grade ) { |
|
| 855 | 853 | |
| 856 | - } |
|
| 854 | + return $question_grade; |
|
| 857 | 855 | |
| 858 | - // auto grading core |
|
| 859 | - if( in_array( $question_type , array( 'multiple-choice' , 'boolean' ) ) ){ |
|
| 856 | + } |
|
| 860 | 857 | |
| 861 | - $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 858 | + // auto grading core |
|
| 859 | + if( in_array( $question_type , array( 'multiple-choice' , 'boolean' ) ) ){ |
|
| 862 | 860 | |
| 863 | - if( 0 == get_magic_quotes_gpc() ) { |
|
| 864 | - $answer = wp_unslash( $answer ); |
|
| 865 | - } |
|
| 866 | - $answer = (array) $answer; |
|
| 867 | - if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { |
|
| 868 | - // Loop through all answers ensure none are 'missing' |
|
| 869 | - $all_correct = true; |
|
| 870 | - foreach ( $answer as $check_answer ) { |
|
| 871 | - if ( !in_array( $check_answer, $right_answer ) ) { |
|
| 872 | - $all_correct = false; |
|
| 873 | - } |
|
| 874 | - } |
|
| 875 | - // If all correct then grade |
|
| 876 | - if ( $all_correct ) { |
|
| 877 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 878 | - } |
|
| 879 | - } |
|
| 861 | + $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 880 | 862 | |
| 881 | - } elseif( 'gap-fill' == $question_type ){ |
|
| 863 | + if( 0 == get_magic_quotes_gpc() ) { |
|
| 864 | + $answer = wp_unslash( $answer ); |
|
| 865 | + } |
|
| 866 | + $answer = (array) $answer; |
|
| 867 | + if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { |
|
| 868 | + // Loop through all answers ensure none are 'missing' |
|
| 869 | + $all_correct = true; |
|
| 870 | + foreach ( $answer as $check_answer ) { |
|
| 871 | + if ( !in_array( $check_answer, $right_answer ) ) { |
|
| 872 | + $all_correct = false; |
|
| 873 | + } |
|
| 874 | + } |
|
| 875 | + // If all correct then grade |
|
| 876 | + if ( $all_correct ) { |
|
| 877 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 878 | + } |
|
| 879 | + } |
|
| 882 | 880 | |
| 883 | - $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); |
|
| 881 | + } elseif( 'gap-fill' == $question_type ){ |
|
| 884 | 882 | |
| 885 | - } else{ |
|
| 883 | + $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); |
|
| 886 | 884 | |
| 887 | - /** |
|
| 888 | - * Grading questions that are not auto gradable. |
|
| 889 | - * |
|
| 890 | - * This filter is applied the context of ta single question within the sensei_grade_question_auto function. |
|
| 891 | - * It fires for all other questions types. It does not apply to 'multiple-choice' , 'boolean' and gap-fill. |
|
| 892 | - * |
|
| 893 | - * @param int $question_grade default zero |
|
| 894 | - * @param int $question_id |
|
| 895 | - * @param string $question_type one of the Sensei question type. |
|
| 896 | - * @param string $answer user supplied question answer |
|
| 897 | - */ |
|
| 898 | - $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); |
|
| 885 | + } else{ |
|
| 899 | 886 | |
| 900 | - } // end if $question_type |
|
| 887 | + /** |
|
| 888 | + * Grading questions that are not auto gradable. |
|
| 889 | + * |
|
| 890 | + * This filter is applied the context of ta single question within the sensei_grade_question_auto function. |
|
| 891 | + * It fires for all other questions types. It does not apply to 'multiple-choice' , 'boolean' and gap-fill. |
|
| 892 | + * |
|
| 893 | + * @param int $question_grade default zero |
|
| 894 | + * @param int $question_id |
|
| 895 | + * @param string $question_type one of the Sensei question type. |
|
| 896 | + * @param string $answer user supplied question answer |
|
| 897 | + */ |
|
| 898 | + $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); |
|
| 901 | 899 | |
| 902 | - return $question_grade; |
|
| 903 | - } // end grade_question_auto |
|
| 900 | + } // end if $question_type |
|
| 904 | 901 | |
| 905 | - /** |
|
| 906 | - * Grading logic specifically for the gap fill questions |
|
| 907 | - * |
|
| 908 | - * @since 1.9.0 |
|
| 909 | - * @param $question_id |
|
| 910 | - * @param $user_answer |
|
| 911 | - * |
|
| 912 | - * @return bool | int false or the grade given to the user answer |
|
| 913 | - */ |
|
| 914 | - public static function grade_gap_fill_question( $question_id, $user_answer ){ |
|
| 902 | + return $question_grade; |
|
| 903 | + } // end grade_question_auto |
|
| 915 | 904 | |
| 916 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 917 | - $gapfill_array = explode( '||', $right_answer ); |
|
| 905 | + /** |
|
| 906 | + * Grading logic specifically for the gap fill questions |
|
| 907 | + * |
|
| 908 | + * @since 1.9.0 |
|
| 909 | + * @param $question_id |
|
| 910 | + * @param $user_answer |
|
| 911 | + * |
|
| 912 | + * @return bool | int false or the grade given to the user answer |
|
| 913 | + */ |
|
| 914 | + public static function grade_gap_fill_question( $question_id, $user_answer ){ |
|
| 918 | 915 | |
| 919 | - if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
| 920 | - $user_answer = wp_unslash( $user_answer ); |
|
| 921 | - } |
|
| 916 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 917 | + $gapfill_array = explode( '||', $right_answer ); |
|
| 922 | 918 | |
| 923 | - /** |
|
| 924 | - * case sensitive grading filter |
|
| 925 | - * |
|
| 926 | - * alter the value simply use this code in your plugin or the themes functions.php |
|
| 927 | - * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); |
|
| 928 | - * |
|
| 929 | - * @param bool $do_case_sensitive_comparison default false. |
|
| 930 | - * |
|
| 931 | - * @since 1.9.0 |
|
| 932 | - */ |
|
| 933 | - $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); |
|
| 919 | + if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
| 920 | + $user_answer = wp_unslash( $user_answer ); |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * case sensitive grading filter |
|
| 925 | + * |
|
| 926 | + * alter the value simply use this code in your plugin or the themes functions.php |
|
| 927 | + * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); |
|
| 928 | + * |
|
| 929 | + * @param bool $do_case_sensitive_comparison default false. |
|
| 930 | + * |
|
| 931 | + * @since 1.9.0 |
|
| 932 | + */ |
|
| 933 | + $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); |
|
| 934 | 934 | |
| 935 | - if( $do_case_sensitive_comparison ){ |
|
| 935 | + if( $do_case_sensitive_comparison ){ |
|
| 936 | 936 | |
| 937 | - // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 938 | - if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { |
|
| 937 | + // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 938 | + if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { |
|
| 939 | 939 | |
| 940 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 940 | + return Sensei()->question->get_question_grade( $question_id ); |
|
| 941 | 941 | |
| 942 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 942 | + } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 943 | 943 | |
| 944 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 944 | + if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 945 | 945 | |
| 946 | - return Sensei()->question->get_question_grade($question_id); |
|
| 946 | + return Sensei()->question->get_question_grade($question_id); |
|
| 947 | 947 | |
| 948 | - }else{ |
|
| 948 | + }else{ |
|
| 949 | 949 | |
| 950 | - return false; |
|
| 950 | + return false; |
|
| 951 | 951 | |
| 952 | - } |
|
| 952 | + } |
|
| 953 | 953 | |
| 954 | - }else{ |
|
| 954 | + }else{ |
|
| 955 | 955 | |
| 956 | - return false; |
|
| 956 | + return false; |
|
| 957 | 957 | |
| 958 | - } |
|
| 958 | + } |
|
| 959 | 959 | |
| 960 | - }else{ |
|
| 960 | + }else{ |
|
| 961 | 961 | |
| 962 | - // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 963 | - if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { |
|
| 962 | + // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
|
| 963 | + if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { |
|
| 964 | 964 | |
| 965 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 965 | + return Sensei()->question->get_question_grade( $question_id ); |
|
| 966 | 966 | |
| 967 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 967 | + } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 968 | 968 | |
| 969 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 969 | + if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 970 | 970 | |
| 971 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 971 | + return Sensei()->question->get_question_grade( $question_id ); |
|
| 972 | 972 | |
| 973 | - }else{ |
|
| 973 | + }else{ |
|
| 974 | 974 | |
| 975 | - return false; |
|
| 975 | + return false; |
|
| 976 | 976 | |
| 977 | - } |
|
| 977 | + } |
|
| 978 | 978 | |
| 979 | - }else{ |
|
| 979 | + }else{ |
|
| 980 | 980 | |
| 981 | - return false; |
|
| 981 | + return false; |
|
| 982 | 982 | |
| 983 | - } |
|
| 983 | + } |
|
| 984 | 984 | |
| 985 | - } |
|
| 985 | + } |
|
| 986 | 986 | |
| 987 | - } |
|
| 987 | + } |
|
| 988 | 988 | |
| 989 | 989 | } // End Class |
| 990 | 990 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Grading Class |
@@ -24,30 +24,30 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @param $file |
| 26 | 26 | */ |
| 27 | - public function __construct ( $file ) { |
|
| 28 | - $this->name = __( 'Grading', 'woothemes-sensei' ); |
|
| 27 | + public function __construct($file) { |
|
| 28 | + $this->name = __('Grading', 'woothemes-sensei'); |
|
| 29 | 29 | $this->file = $file; |
| 30 | 30 | $this->page_slug = 'sensei_grading'; |
| 31 | 31 | |
| 32 | 32 | // Admin functions |
| 33 | - if ( is_admin() ) { |
|
| 34 | - add_action( 'admin_menu', array( $this, 'grading_admin_menu' ), 20); |
|
| 35 | - add_action( 'grading_wrapper_container', array( $this, 'wrapper_container' ) ); |
|
| 36 | - if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) { |
|
| 37 | - add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 38 | - add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) ); |
|
| 33 | + if (is_admin()) { |
|
| 34 | + add_action('admin_menu', array($this, 'grading_admin_menu'), 20); |
|
| 35 | + add_action('grading_wrapper_container', array($this, 'wrapper_container')); |
|
| 36 | + if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) { |
|
| 37 | + add_action('admin_print_scripts', array($this, 'enqueue_scripts')); |
|
| 38 | + add_action('admin_print_styles', array($this, 'enqueue_styles')); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - add_action( 'admin_init', array( $this, 'admin_process_grading_submission' ) ); |
|
| 41 | + add_action('admin_init', array($this, 'admin_process_grading_submission')); |
|
| 42 | 42 | |
| 43 | - add_action( 'admin_notices', array( $this, 'add_grading_notices' ) ); |
|
| 43 | + add_action('admin_notices', array($this, 'add_grading_notices')); |
|
| 44 | 44 | // add_action( 'sensei_grading_notices', array( $this, 'sensei_grading_notices' ) ); |
| 45 | 45 | } // End If Statement |
| 46 | 46 | |
| 47 | 47 | // Ajax functions |
| 48 | - if ( is_admin() ) { |
|
| 49 | - add_action( 'wp_ajax_get_lessons_dropdown', array( $this, 'get_lessons_dropdown' ) ); |
|
| 50 | - add_action( 'wp_ajax_get_redirect_url', array( $this, 'get_redirect_url' ) ); |
|
| 48 | + if (is_admin()) { |
|
| 49 | + add_action('wp_ajax_get_lessons_dropdown', array($this, 'get_lessons_dropdown')); |
|
| 50 | + add_action('wp_ajax_get_redirect_url', array($this, 'get_redirect_url')); |
|
| 51 | 51 | } // End If Statement |
| 52 | 52 | } // End __construct() |
| 53 | 53 | |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | public function grading_admin_menu() { |
| 61 | 61 | global $menu; |
| 62 | 62 | |
| 63 | - if ( current_user_can( 'manage_sensei_grades' ) ) { |
|
| 64 | - $grading_page = add_submenu_page('sensei', __('Grading', 'woothemes-sensei'), __('Grading', 'woothemes-sensei') , 'manage_sensei_grades', $this->page_slug, array( $this, 'grading_page' ) ); |
|
| 63 | + if (current_user_can('manage_sensei_grades')) { |
|
| 64 | + $grading_page = add_submenu_page('sensei', __('Grading', 'woothemes-sensei'), __('Grading', 'woothemes-sensei'), 'manage_sensei_grades', $this->page_slug, array($this, 'grading_page')); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | } // End grading_admin_menu() |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | * @since 1.3.0 |
| 75 | 75 | * @return void |
| 76 | 76 | */ |
| 77 | - public function enqueue_scripts () { |
|
| 77 | + public function enqueue_scripts() { |
|
| 78 | 78 | |
| 79 | 79 | |
| 80 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 80 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 81 | 81 | |
| 82 | 82 | // Load Grading JS |
| 83 | - wp_enqueue_script( 'sensei-grading-general', Sensei()->plugin_url . 'assets/js/grading-general' . $suffix . '.js', array( 'jquery' ), Sensei()->version ); |
|
| 83 | + wp_enqueue_script('sensei-grading-general', Sensei()->plugin_url.'assets/js/grading-general'.$suffix.'.js', array('jquery'), Sensei()->version); |
|
| 84 | 84 | |
| 85 | 85 | } // End enqueue_scripts() |
| 86 | 86 | |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | * @since 1.0.0 |
| 93 | 93 | * @return void |
| 94 | 94 | */ |
| 95 | - public function enqueue_styles () { |
|
| 95 | + public function enqueue_styles() { |
|
| 96 | 96 | |
| 97 | - wp_enqueue_style( Sensei()->token . '-admin' ); |
|
| 97 | + wp_enqueue_style(Sensei()->token.'-admin'); |
|
| 98 | 98 | |
| 99 | - wp_enqueue_style( 'woothemes-sensei-settings-api', Sensei()->plugin_url . 'assets/css/settings.css', '', Sensei()->version ); |
|
| 99 | + wp_enqueue_style('woothemes-sensei-settings-api', Sensei()->plugin_url.'assets/css/settings.css', '', Sensei()->version); |
|
| 100 | 100 | |
| 101 | 101 | } // End enqueue_styles() |
| 102 | 102 | |
@@ -108,12 +108,12 @@ discard block |
||
| 108 | 108 | public function load_data_table_files() { |
| 109 | 109 | |
| 110 | 110 | // Load Grading Classes |
| 111 | - $classes_to_load = array( 'list-table', |
|
| 111 | + $classes_to_load = array('list-table', |
|
| 112 | 112 | 'grading-main', |
| 113 | 113 | 'grading-user-quiz' |
| 114 | 114 | ); |
| 115 | - foreach ( $classes_to_load as $class_file ) { |
|
| 116 | - Sensei()->load_class( $class_file ); |
|
| 115 | + foreach ($classes_to_load as $class_file) { |
|
| 116 | + Sensei()->load_class($class_file); |
|
| 117 | 117 | } // End For Loop |
| 118 | 118 | } // End load_data_table_files() |
| 119 | 119 | |
@@ -125,16 +125,16 @@ discard block |
||
| 125 | 125 | * @param undefined $optional_data optional constructor arguments |
| 126 | 126 | * @return object class instance object |
| 127 | 127 | */ |
| 128 | - public function load_data_object( $name = '', $data = 0, $optional_data = null ) { |
|
| 128 | + public function load_data_object($name = '', $data = 0, $optional_data = null) { |
|
| 129 | 129 | // Load Analysis data |
| 130 | - $object_name = 'WooThemes_Sensei_Grading_' . $name; |
|
| 131 | - if ( is_null($optional_data) ) { |
|
| 132 | - $sensei_grading_object = new $object_name( $data ); |
|
| 130 | + $object_name = 'WooThemes_Sensei_Grading_'.$name; |
|
| 131 | + if (is_null($optional_data)) { |
|
| 132 | + $sensei_grading_object = new $object_name($data); |
|
| 133 | 133 | } |
| 134 | 134 | else { |
| 135 | - $sensei_grading_object = new $object_name( $data, $optional_data ); |
|
| 135 | + $sensei_grading_object = new $object_name($data, $optional_data); |
|
| 136 | 136 | } // End If Statement |
| 137 | - if ( 'Main' == $name ) { |
|
| 137 | + if ('Main' == $name) { |
|
| 138 | 138 | $sensei_grading_object->prepare_items(); |
| 139 | 139 | } // End If Statement |
| 140 | 140 | return $sensei_grading_object; |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function grading_page() { |
| 150 | 150 | |
| 151 | - if ( isset( $_GET['quiz_id'] ) && 0 < intval( $_GET['quiz_id'] ) && isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { |
|
| 151 | + if (isset($_GET['quiz_id']) && 0 < intval($_GET['quiz_id']) && isset($_GET['user']) && 0 < intval($_GET['user'])) { |
|
| 152 | 152 | $this->grading_user_quiz_view(); |
| 153 | 153 | } |
| 154 | 154 | else { |
@@ -164,23 +164,23 @@ discard block |
||
| 164 | 164 | public function grading_default_view() { |
| 165 | 165 | |
| 166 | 166 | // Load Grading data |
| 167 | - if( !empty( $_GET['course_id'] ) ) { |
|
| 168 | - $course_id = intval( $_GET['course_id'] ); |
|
| 167 | + if ( ! empty($_GET['course_id'])) { |
|
| 168 | + $course_id = intval($_GET['course_id']); |
|
| 169 | 169 | } |
| 170 | - if( !empty( $_GET['lesson_id'] ) ) { |
|
| 171 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
| 170 | + if ( ! empty($_GET['lesson_id'])) { |
|
| 171 | + $lesson_id = intval($_GET['lesson_id']); |
|
| 172 | 172 | } |
| 173 | - if( !empty( $_GET['user_id'] ) ) { |
|
| 174 | - $user_id = intval( $_GET['user_id'] ); |
|
| 173 | + if ( ! empty($_GET['user_id'])) { |
|
| 174 | + $user_id = intval($_GET['user_id']); |
|
| 175 | 175 | } |
| 176 | - if( !empty( $_GET['view'] ) ) { |
|
| 177 | - $view = esc_html( $_GET['view'] ); |
|
| 176 | + if ( ! empty($_GET['view'])) { |
|
| 177 | + $view = esc_html($_GET['view']); |
|
| 178 | 178 | } |
| 179 | - $sensei_grading_overview = $this->load_data_object( 'Main', compact( 'course_id', 'lesson_id', 'user_id', 'view' ) ); |
|
| 179 | + $sensei_grading_overview = $this->load_data_object('Main', compact('course_id', 'lesson_id', 'user_id', 'view')); |
|
| 180 | 180 | |
| 181 | 181 | // Wrappers |
| 182 | - do_action( 'grading_before_container' ); |
|
| 183 | - do_action( 'grading_wrapper_container', 'top' ); |
|
| 182 | + do_action('grading_before_container'); |
|
| 183 | + do_action('grading_wrapper_container', 'top'); |
|
| 184 | 184 | $this->grading_headers(); |
| 185 | 185 | ?> |
| 186 | 186 | <div id="poststuff" class="sensei-grading-wrap"> |
@@ -188,12 +188,12 @@ discard block |
||
| 188 | 188 | <?php $sensei_grading_overview->display(); ?> |
| 189 | 189 | </div> |
| 190 | 190 | <div class="sensei-grading-extra"> |
| 191 | - <?php do_action( 'sensei_grading_extra' ); ?> |
|
| 191 | + <?php do_action('sensei_grading_extra'); ?> |
|
| 192 | 192 | </div> |
| 193 | 193 | </div> |
| 194 | 194 | <?php |
| 195 | - do_action( 'grading_wrapper_container', 'bottom' ); |
|
| 196 | - do_action( 'grading_after_container' ); |
|
| 195 | + do_action('grading_wrapper_container', 'bottom'); |
|
| 196 | + do_action('grading_after_container'); |
|
| 197 | 197 | } // End grading_default_view() |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -206,17 +206,17 @@ discard block |
||
| 206 | 206 | // Load Grading data |
| 207 | 207 | $user_id = 0; |
| 208 | 208 | $quiz_id = 0; |
| 209 | - if( isset( $_GET['user'] ) ) { |
|
| 210 | - $user_id = intval( $_GET['user'] ); |
|
| 209 | + if (isset($_GET['user'])) { |
|
| 210 | + $user_id = intval($_GET['user']); |
|
| 211 | 211 | } |
| 212 | - if( isset( $_GET['quiz_id'] ) ) { |
|
| 213 | - $quiz_id = intval( $_GET['quiz_id'] ); |
|
| 212 | + if (isset($_GET['quiz_id'])) { |
|
| 213 | + $quiz_id = intval($_GET['quiz_id']); |
|
| 214 | 214 | } |
| 215 | - $sensei_grading_user_profile = $this->load_data_object( 'User_Quiz', $user_id, $quiz_id ); |
|
| 215 | + $sensei_grading_user_profile = $this->load_data_object('User_Quiz', $user_id, $quiz_id); |
|
| 216 | 216 | // Wrappers |
| 217 | - do_action( 'grading_before_container' ); |
|
| 218 | - do_action( 'grading_wrapper_container', 'top' ); |
|
| 219 | - $this->grading_headers( array( 'nav' => 'user_quiz' ) ); |
|
| 217 | + do_action('grading_before_container'); |
|
| 218 | + do_action('grading_wrapper_container', 'top'); |
|
| 219 | + $this->grading_headers(array('nav' => 'user_quiz')); |
|
| 220 | 220 | ?> |
| 221 | 221 | <div id="poststuff" class="sensei-grading-wrap user-profile"> |
| 222 | 222 | <div class="sensei-grading-main"> |
@@ -225,8 +225,8 @@ discard block |
||
| 225 | 225 | </div> |
| 226 | 226 | </div> |
| 227 | 227 | <?php |
| 228 | - do_action( 'grading_wrapper_container', 'bottom' ); |
|
| 229 | - do_action( 'grading_after_container' ); |
|
| 228 | + do_action('grading_wrapper_container', 'bottom'); |
|
| 229 | + do_action('grading_after_container'); |
|
| 230 | 230 | } // End grading_user_quiz_view() |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -234,15 +234,15 @@ discard block |
||
| 234 | 234 | * @since 1.3.0 |
| 235 | 235 | * @return void |
| 236 | 236 | */ |
| 237 | - public function grading_headers( $args = array( 'nav' => 'default' ) ) { |
|
| 237 | + public function grading_headers($args = array('nav' => 'default')) { |
|
| 238 | 238 | |
| 239 | 239 | |
| 240 | - $function = 'grading_' . $args['nav'] . '_nav'; |
|
| 240 | + $function = 'grading_'.$args['nav'].'_nav'; |
|
| 241 | 241 | $this->$function(); |
| 242 | 242 | ?> |
| 243 | - <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> |
|
| 243 | + <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> |
|
| 244 | 244 | <?php |
| 245 | - do_action( 'sensei_grading_after_headers' ); |
|
| 245 | + do_action('sensei_grading_after_headers'); |
|
| 246 | 246 | } // End grading_headers() |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -251,10 +251,10 @@ discard block |
||
| 251 | 251 | * @param $which string |
| 252 | 252 | * @return void |
| 253 | 253 | */ |
| 254 | - public function wrapper_container( $which ) { |
|
| 255 | - if ( 'top' == $which ) { |
|
| 254 | + public function wrapper_container($which) { |
|
| 255 | + if ('top' == $which) { |
|
| 256 | 256 | ?><div id="woothemes-sensei" class="wrap woothemes-sensei"><?php |
| 257 | - } elseif ( 'bottom' == $which ) { |
|
| 257 | + } elseif ('bottom' == $which) { |
|
| 258 | 258 | ?></div><!--/#woothemes-sensei--><?php |
| 259 | 259 | } // End If Statement |
| 260 | 260 | } // End wrapper_container() |
@@ -267,29 +267,29 @@ discard block |
||
| 267 | 267 | public function grading_default_nav() { |
| 268 | 268 | global $wp_version; |
| 269 | 269 | |
| 270 | - $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 ) ); |
|
| 271 | - if ( isset( $_GET['course_id'] ) ) { |
|
| 272 | - $course_id = intval( $_GET['course_id'] ); |
|
| 273 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 274 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
| 275 | - $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
|
| 270 | + $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)); |
|
| 271 | + if (isset($_GET['course_id'])) { |
|
| 272 | + $course_id = intval($_GET['course_id']); |
|
| 273 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 274 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
| 275 | + $title .= sprintf(' <span class="course-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); |
|
| 276 | 276 | } |
| 277 | 277 | else { |
| 278 | - $title .= sprintf( ' <span class="course-title">> %s</span>', get_the_title( $course_id ) ); |
|
| 278 | + $title .= sprintf(' <span class="course-title">> %s</span>', get_the_title($course_id)); |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | - if ( isset( $_GET['lesson_id'] ) ) { |
|
| 282 | - $lesson_id = intval( $_GET['lesson_id'] ); |
|
| 283 | - $title .= ' <span class="lesson-title">> ' . get_the_title( intval( $lesson_id ) ) . '</span>'; |
|
| 281 | + if (isset($_GET['lesson_id'])) { |
|
| 282 | + $lesson_id = intval($_GET['lesson_id']); |
|
| 283 | + $title .= ' <span class="lesson-title">> '.get_the_title(intval($lesson_id)).'</span>'; |
|
| 284 | 284 | } |
| 285 | - if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) { |
|
| 285 | + if (isset($_GET['user_id']) && 0 < intval($_GET['user_id'])) { |
|
| 286 | 286 | |
| 287 | - $user_name = Sensei_Student::get_full_name( $_GET['user_id'] ); |
|
| 288 | - $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
|
| 287 | + $user_name = Sensei_Student::get_full_name($_GET['user_id']); |
|
| 288 | + $title .= ' <span class="user-title">> '.$user_name.'</span>'; |
|
| 289 | 289 | |
| 290 | 290 | } // End If Statement |
| 291 | 291 | ?> |
| 292 | - <h2><?php echo apply_filters( 'sensei_grading_nav_title', $title ); ?></h2> |
|
| 292 | + <h2><?php echo apply_filters('sensei_grading_nav_title', $title); ?></h2> |
|
| 293 | 293 | <?php |
| 294 | 294 | } // End grading_default_nav() |
| 295 | 295 | |
@@ -301,29 +301,29 @@ discard block |
||
| 301 | 301 | public function grading_user_quiz_nav() { |
| 302 | 302 | global $wp_version; |
| 303 | 303 | |
| 304 | - $title = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ), esc_html( $this->name ) ); |
|
| 305 | - if ( isset( $_GET['quiz_id'] ) ) { |
|
| 306 | - $quiz_id = intval( $_GET['quiz_id'] ); |
|
| 307 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 308 | - $course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 309 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 310 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
| 311 | - $title .= sprintf( ' <span class="course-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) ); |
|
| 304 | + $title = sprintf('<a href="%s">%s</a>', add_query_arg(array('page' => $this->page_slug), admin_url('admin.php')), esc_html($this->name)); |
|
| 305 | + if (isset($_GET['quiz_id'])) { |
|
| 306 | + $quiz_id = intval($_GET['quiz_id']); |
|
| 307 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 308 | + $course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 309 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 310 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
| 311 | + $title .= sprintf(' <span class="course-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id)); |
|
| 312 | 312 | } |
| 313 | 313 | else { |
| 314 | - $title .= sprintf( ' <span class="course-title">> %s</span>', get_the_title( $course_id ) ); |
|
| 314 | + $title .= sprintf(' <span class="course-title">> %s</span>', get_the_title($course_id)); |
|
| 315 | 315 | } |
| 316 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id ), admin_url( 'admin.php' ) ); |
|
| 317 | - $title .= sprintf( ' <span class="lesson-title">> <a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $lesson_id ) ); |
|
| 316 | + $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id), admin_url('admin.php')); |
|
| 317 | + $title .= sprintf(' <span class="lesson-title">> <a href="%s">%s</a></span>', esc_url($url), get_the_title($lesson_id)); |
|
| 318 | 318 | } |
| 319 | - if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { |
|
| 319 | + if (isset($_GET['user']) && 0 < intval($_GET['user'])) { |
|
| 320 | 320 | |
| 321 | - $user_name = Sensei_Student::get_full_name( $_GET['user'] ); |
|
| 322 | - $title .= ' <span class="user-title">> ' . $user_name . '</span>'; |
|
| 321 | + $user_name = Sensei_Student::get_full_name($_GET['user']); |
|
| 322 | + $title .= ' <span class="user-title">> '.$user_name.'</span>'; |
|
| 323 | 323 | |
| 324 | 324 | } // End If Statement |
| 325 | 325 | ?> |
| 326 | - <h2><?php echo apply_filters( 'sensei_grading_nav_title', $title ); ?></h2> |
|
| 326 | + <h2><?php echo apply_filters('sensei_grading_nav_title', $title); ?></h2> |
|
| 327 | 327 | <?php |
| 328 | 328 | } // End grading_user_quiz_nav() |
| 329 | 329 | |
@@ -332,9 +332,9 @@ discard block |
||
| 332 | 332 | * @since 1.7.0 |
| 333 | 333 | * @return array |
| 334 | 334 | */ |
| 335 | - public function get_stati( $type ) { |
|
| 335 | + public function get_stati($type) { |
|
| 336 | 336 | $statuses = array(); |
| 337 | - switch( $type ) { |
|
| 337 | + switch ($type) { |
|
| 338 | 338 | case 'course' : |
| 339 | 339 | $statuses = array( |
| 340 | 340 | 'in-progress', |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | * @param array $args (default: array()) |
| 365 | 365 | * @return object |
| 366 | 366 | */ |
| 367 | - public function count_statuses( $args = array() ) { |
|
| 367 | + public function count_statuses($args = array()) { |
|
| 368 | 368 | global $wpdb; |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -375,71 +375,71 @@ discard block |
||
| 375 | 375 | * @since 1.8.0 |
| 376 | 376 | * @param array $args |
| 377 | 377 | */ |
| 378 | - $args = apply_filters( 'sensei_count_statuses_args', $args ); |
|
| 378 | + $args = apply_filters('sensei_count_statuses_args', $args); |
|
| 379 | 379 | |
| 380 | - if ( 'course' == $args['type'] ) { |
|
| 380 | + if ('course' == $args['type']) { |
|
| 381 | 381 | $type = 'sensei_course_status'; |
| 382 | 382 | } |
| 383 | 383 | else { |
| 384 | 384 | $type = 'sensei_lesson_status'; |
| 385 | 385 | } |
| 386 | - $cache_key = 'sensei-' . $args['type'] . '-statuses'; |
|
| 386 | + $cache_key = 'sensei-'.$args['type'].'-statuses'; |
|
| 387 | 387 | |
| 388 | 388 | $query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s "; |
| 389 | 389 | |
| 390 | 390 | // Restrict to specific posts |
| 391 | - if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) { |
|
| 392 | - $query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')'; |
|
| 391 | + if (isset($args['post__in']) && ! empty($args['post__in']) && is_array($args['post__in'])) { |
|
| 392 | + $query .= ' AND comment_post_ID IN ('.implode(',', array_map('absint', $args['post__in'])).')'; |
|
| 393 | 393 | } |
| 394 | - elseif ( !empty( $args['post_id'] ) ) { |
|
| 395 | - $query .= $wpdb->prepare( ' AND comment_post_ID = %d', $args['post_id'] ); |
|
| 394 | + elseif ( ! empty($args['post_id'])) { |
|
| 395 | + $query .= $wpdb->prepare(' AND comment_post_ID = %d', $args['post_id']); |
|
| 396 | 396 | } |
| 397 | 397 | // Restrict to specific users |
| 398 | - if ( isset( $args['user_id'] ) && is_array( $args['user_id'] ) ) { |
|
| 399 | - $query .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $args['user_id'] ) ) . ')'; |
|
| 398 | + if (isset($args['user_id']) && is_array($args['user_id'])) { |
|
| 399 | + $query .= ' AND user_id IN ('.implode(',', array_map('absint', $args['user_id'])).')'; |
|
| 400 | 400 | } |
| 401 | - elseif ( !empty( $args['user_id'] ) ) { |
|
| 402 | - $query .= $wpdb->prepare( ' AND user_id = %d', $args['user_id'] ); |
|
| 401 | + elseif ( ! empty($args['user_id'])) { |
|
| 402 | + $query .= $wpdb->prepare(' AND user_id = %d', $args['user_id']); |
|
| 403 | 403 | } |
| 404 | 404 | $query .= ' GROUP BY comment_approved'; |
| 405 | 405 | |
| 406 | - $counts = wp_cache_get( $cache_key, 'counts' ); |
|
| 407 | - if ( false === $counts ) { |
|
| 408 | - $sql = $wpdb->prepare( $query, $type ); |
|
| 409 | - $results = (array) $wpdb->get_results( $sql, ARRAY_A ); |
|
| 410 | - $counts = array_fill_keys( $this->get_stati( $type ), 0 ); |
|
| 406 | + $counts = wp_cache_get($cache_key, 'counts'); |
|
| 407 | + if (false === $counts) { |
|
| 408 | + $sql = $wpdb->prepare($query, $type); |
|
| 409 | + $results = (array) $wpdb->get_results($sql, ARRAY_A); |
|
| 410 | + $counts = array_fill_keys($this->get_stati($type), 0); |
|
| 411 | 411 | |
| 412 | - foreach ( $results as $row ) { |
|
| 413 | - $counts[ $row['comment_approved'] ] = $row['total']; |
|
| 412 | + foreach ($results as $row) { |
|
| 413 | + $counts[$row['comment_approved']] = $row['total']; |
|
| 414 | 414 | } |
| 415 | - wp_cache_set( $cache_key, $counts, 'counts' ); |
|
| 415 | + wp_cache_set($cache_key, $counts, 'counts'); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - if( ! isset( $counts['graded'] ) ) { |
|
| 418 | + if ( ! isset($counts['graded'])) { |
|
| 419 | 419 | $counts['graded'] = 0; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - if( ! isset( $counts['ungraded'] ) ) { |
|
| 422 | + if ( ! isset($counts['ungraded'])) { |
|
| 423 | 423 | $counts['ungraded'] = 0; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - if( ! isset( $counts['passed'] ) ) { |
|
| 426 | + if ( ! isset($counts['passed'])) { |
|
| 427 | 427 | $counts['passed'] = 0; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - if( ! isset( $counts['failed'] ) ) { |
|
| 430 | + if ( ! isset($counts['failed'])) { |
|
| 431 | 431 | $counts['failed'] = 0; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - if( ! isset( $counts['in-progress'] ) ) { |
|
| 434 | + if ( ! isset($counts['in-progress'])) { |
|
| 435 | 435 | $counts['in-progress'] = 0; |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - if( ! isset( $counts['complete'] ) ) { |
|
| 438 | + if ( ! isset($counts['complete'])) { |
|
| 439 | 439 | $counts['complete'] = 0; |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - return apply_filters( 'sensei_count_statuses', $counts, $type ); |
|
| 442 | + return apply_filters('sensei_count_statuses', $counts, $type); |
|
| 443 | 443 | } // End sensei_count_statuses() |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -447,11 +447,11 @@ discard block |
||
| 447 | 447 | * @since 1.7.0 |
| 448 | 448 | * @return string |
| 449 | 449 | */ |
| 450 | - public function courses_drop_down_html( $selected_course_id = 0 ) { |
|
| 450 | + public function courses_drop_down_html($selected_course_id = 0) { |
|
| 451 | 451 | |
| 452 | 452 | $html = ''; |
| 453 | 453 | |
| 454 | - $course_args = array( 'post_type' => 'course', |
|
| 454 | + $course_args = array('post_type' => 'course', |
|
| 455 | 455 | 'posts_per_page' => -1, |
| 456 | 456 | 'orderby' => 'title', |
| 457 | 457 | 'order' => 'ASC', |
@@ -459,12 +459,12 @@ discard block |
||
| 459 | 459 | 'suppress_filters' => 0, |
| 460 | 460 | 'fields' => 'ids', |
| 461 | 461 | ); |
| 462 | - $courses = get_posts( apply_filters( 'sensei_grading_filter_courses', $course_args ) ); |
|
| 462 | + $courses = get_posts(apply_filters('sensei_grading_filter_courses', $course_args)); |
|
| 463 | 463 | |
| 464 | - $html .= '<option value="">' . __( 'Select a course', 'woothemes-sensei' ) . '</option>'; |
|
| 465 | - if ( count( $courses ) > 0 ) { |
|
| 466 | - foreach ($courses as $course_id){ |
|
| 467 | - $html .= '<option value="' . esc_attr( absint( $course_id ) ) . '" ' . selected( $course_id, $selected_course_id, false ) . '>' . esc_html( get_the_title( $course_id ) ) . '</option>' . "\n"; |
|
| 464 | + $html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'; |
|
| 465 | + if (count($courses) > 0) { |
|
| 466 | + foreach ($courses as $course_id) { |
|
| 467 | + $html .= '<option value="'.esc_attr(absint($course_id)).'" '.selected($course_id, $selected_course_id, false).'>'.esc_html(get_the_title($course_id)).'</option>'."\n"; |
|
| 468 | 468 | } // End For Loop |
| 469 | 469 | } // End If Statement |
| 470 | 470 | |
@@ -485,20 +485,20 @@ discard block |
||
| 485 | 485 | $course_data = array(); |
| 486 | 486 | parse_str($data, $course_data); |
| 487 | 487 | |
| 488 | - $course_id = intval( $course_data['course_id'] ); |
|
| 488 | + $course_id = intval($course_data['course_id']); |
|
| 489 | 489 | |
| 490 | - $html = $this->lessons_drop_down_html( $course_id ); |
|
| 490 | + $html = $this->lessons_drop_down_html($course_id); |
|
| 491 | 491 | |
| 492 | 492 | echo $html; |
| 493 | 493 | die(); // WordPress may print out a spurious zero without this can be particularly bad if using JSON |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - public function lessons_drop_down_html( $course_id = 0, $selected_lesson_id = 0 ) { |
|
| 496 | + public function lessons_drop_down_html($course_id = 0, $selected_lesson_id = 0) { |
|
| 497 | 497 | |
| 498 | 498 | $html = ''; |
| 499 | - if ( 0 < intval( $course_id ) ) { |
|
| 499 | + if (0 < intval($course_id)) { |
|
| 500 | 500 | |
| 501 | - $lesson_args = array( 'post_type' => 'lesson', |
|
| 501 | + $lesson_args = array('post_type' => 'lesson', |
|
| 502 | 502 | 'posts_per_page' => -1, |
| 503 | 503 | 'orderby' => 'title', |
| 504 | 504 | 'order' => 'ASC', |
@@ -508,12 +508,12 @@ discard block |
||
| 508 | 508 | 'suppress_filters' => 0, |
| 509 | 509 | 'fields' => 'ids', |
| 510 | 510 | ); |
| 511 | - $lessons = get_posts( apply_filters( 'sensei_grading_filter_lessons', $lesson_args ) ); |
|
| 511 | + $lessons = get_posts(apply_filters('sensei_grading_filter_lessons', $lesson_args)); |
|
| 512 | 512 | |
| 513 | - $html .= '<option value="">' . __( 'Select a lesson', 'woothemes-sensei' ) . '</option>'; |
|
| 514 | - if ( count( $lessons ) > 0 ) { |
|
| 515 | - foreach ( $lessons as $lesson_id ){ |
|
| 516 | - $html .= '<option value="' . esc_attr( absint( $lesson_id ) ) . '" ' . selected( $lesson_id, $selected_lesson_id, false ) . '>' . esc_html( get_the_title( $lesson_id ) ) . '</option>' . "\n"; |
|
| 513 | + $html .= '<option value="">'.__('Select a lesson', 'woothemes-sensei').'</option>'; |
|
| 514 | + if (count($lessons) > 0) { |
|
| 515 | + foreach ($lessons as $lesson_id) { |
|
| 516 | + $html .= '<option value="'.esc_attr(absint($lesson_id)).'" '.selected($lesson_id, $selected_lesson_id, false).'>'.esc_html(get_the_title($lesson_id)).'</option>'."\n"; |
|
| 517 | 517 | } // End For Loop |
| 518 | 518 | } // End If Statement |
| 519 | 519 | |
@@ -534,10 +534,10 @@ discard block |
||
| 534 | 534 | public function admin_process_grading_submission() { |
| 535 | 535 | |
| 536 | 536 | // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry |
| 537 | - if( ! isset( $_POST['sensei_manual_grade'] ) |
|
| 538 | - || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) |
|
| 539 | - || ! isset( $_GET['quiz_id'] ) |
|
| 540 | - || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { |
|
| 537 | + if ( ! isset($_POST['sensei_manual_grade']) |
|
| 538 | + || ! wp_verify_nonce($_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading') |
|
| 539 | + || ! isset($_GET['quiz_id']) |
|
| 540 | + || $_GET['quiz_id'] != $_POST['sensei_manual_grade']) { |
|
| 541 | 541 | |
| 542 | 542 | return false; //exit and do not grade |
| 543 | 543 | |
@@ -547,30 +547,30 @@ discard block |
||
| 547 | 547 | $user_id = $_GET['user']; |
| 548 | 548 | |
| 549 | 549 | |
| 550 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 551 | - $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 550 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
| 551 | + $quiz_lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 552 | 552 | $quiz_grade = 0; |
| 553 | 553 | $count = 0; |
| 554 | 554 | $quiz_grade_total = $_POST['quiz_grade_total']; |
| 555 | 555 | $all_question_grades = array(); |
| 556 | 556 | $all_answers_feedback = array(); |
| 557 | 557 | |
| 558 | - foreach( $questions as $question ) { |
|
| 558 | + foreach ($questions as $question) { |
|
| 559 | 559 | |
| 560 | 560 | ++$count; |
| 561 | 561 | $question_id = $question->ID; |
| 562 | 562 | |
| 563 | - if( isset( $_POST[ 'question_' . $question_id ] ) ) { |
|
| 563 | + if (isset($_POST['question_'.$question_id])) { |
|
| 564 | 564 | |
| 565 | 565 | $question_grade = 0; |
| 566 | - if( $_POST[ 'question_' . $question_id ] == 'right' ) { |
|
| 566 | + if ($_POST['question_'.$question_id] == 'right') { |
|
| 567 | 567 | |
| 568 | - $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; |
|
| 568 | + $question_grade = $_POST['question_'.$question_id.'_grade']; |
|
| 569 | 569 | |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | // add data to the array that will, after the loop, be stored on the lesson status |
| 573 | - $all_question_grades[ $question_id ] = $question_grade; |
|
| 573 | + $all_question_grades[$question_id] = $question_grade; |
|
| 574 | 574 | |
| 575 | 575 | // tally up the total quiz grade |
| 576 | 576 | $quiz_grade += $question_grade; |
@@ -579,41 +579,41 @@ discard block |
||
| 579 | 579 | |
| 580 | 580 | // Question answer feedback / notes |
| 581 | 581 | $question_feedback = ''; |
| 582 | - if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ |
|
| 582 | + if (isset($_POST['questions_feedback'][$question_id])) { |
|
| 583 | 583 | |
| 584 | - $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); |
|
| 584 | + $question_feedback = wp_unslash($_POST['questions_feedback'][$question_id]); |
|
| 585 | 585 | |
| 586 | 586 | } |
| 587 | - $all_answers_feedback[ $question_id ] = $question_feedback; |
|
| 587 | + $all_answers_feedback[$question_id] = $question_feedback; |
|
| 588 | 588 | |
| 589 | 589 | } // end for each $questions |
| 590 | 590 | |
| 591 | 591 | //store all question grades on the lesson status |
| 592 | - Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); |
|
| 592 | + Sensei()->quiz->set_user_grades($all_question_grades, $quiz_lesson_id, $user_id); |
|
| 593 | 593 | |
| 594 | 594 | //store the feedback from grading |
| 595 | - Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); |
|
| 595 | + Sensei()->quiz->save_user_answers_feedback($all_answers_feedback, $quiz_lesson_id, $user_id); |
|
| 596 | 596 | |
| 597 | 597 | // $_POST['all_questions_graded'] is set when all questions have been graded |
| 598 | 598 | // in the class sensei grading user quiz -> display() |
| 599 | - if( $_POST['all_questions_graded'] == 'yes' ) { |
|
| 599 | + if ($_POST['all_questions_graded'] == 'yes') { |
|
| 600 | 600 | |
| 601 | 601 | // set the users total quiz grade |
| 602 | - if ( 0 < intval( $quiz_grade_total ) ) { |
|
| 603 | - $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); |
|
| 602 | + if (0 < intval($quiz_grade_total)) { |
|
| 603 | + $grade = abs(round((doubleval($quiz_grade) * 100) / ($quiz_grade_total), 2)); |
|
| 604 | 604 | } |
| 605 | 605 | else { |
| 606 | 606 | $grade = 0; |
| 607 | 607 | } |
| 608 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); |
|
| 608 | + Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id); |
|
| 609 | 609 | |
| 610 | 610 | // Duplicating what Frontend->sensei_complete_quiz() does |
| 611 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 612 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 611 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
| 612 | + $quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); |
|
| 613 | 613 | $lesson_metadata = array(); |
| 614 | - if ( $pass_required ) { |
|
| 614 | + if ($pass_required) { |
|
| 615 | 615 | // Student has reached the pass mark and lesson is complete |
| 616 | - if ( $quiz_passmark <= $grade ) { |
|
| 616 | + if ($quiz_passmark <= $grade) { |
|
| 617 | 617 | $lesson_status = 'passed'; |
| 618 | 618 | } |
| 619 | 619 | else { |
@@ -626,9 +626,9 @@ discard block |
||
| 626 | 626 | } |
| 627 | 627 | $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above |
| 628 | 628 | |
| 629 | - Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); |
|
| 629 | + Sensei_Utils::update_lesson_status($user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata); |
|
| 630 | 630 | |
| 631 | - if( in_array( $lesson_status, array( 'passed', 'graded' ) ) ) { |
|
| 631 | + if (in_array($lesson_status, array('passed', 'graded'))) { |
|
| 632 | 632 | |
| 633 | 633 | /** |
| 634 | 634 | * Summary. |
@@ -640,27 +640,27 @@ discard block |
||
| 640 | 640 | * @param int $user_id |
| 641 | 641 | * @param int $quiz_lesson_id |
| 642 | 642 | */ |
| 643 | - do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); |
|
| 643 | + do_action('sensei_user_lesson_end', $user_id, $quiz_lesson_id); |
|
| 644 | 644 | |
| 645 | 645 | } // end if in_array |
| 646 | 646 | |
| 647 | 647 | }// end if $_POST['all_que... |
| 648 | 648 | |
| 649 | - if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { |
|
| 649 | + if (isset($_POST['sensei_grade_next_learner']) && strlen($_POST['sensei_grade_next_learner']) > 0) { |
|
| 650 | 650 | |
| 651 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 651 | + $load_url = add_query_arg(array('message' => 'graded')); |
|
| 652 | 652 | |
| 653 | - } elseif ( isset( $_POST['_wp_http_referer'] ) ) { |
|
| 653 | + } elseif (isset($_POST['_wp_http_referer'])) { |
|
| 654 | 654 | |
| 655 | - $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); |
|
| 655 | + $load_url = add_query_arg(array('message' => 'graded'), $_POST['_wp_http_referer']); |
|
| 656 | 656 | |
| 657 | 657 | } else { |
| 658 | 658 | |
| 659 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); |
|
| 659 | + $load_url = add_query_arg(array('message' => 'graded')); |
|
| 660 | 660 | |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - wp_safe_redirect( esc_url_raw( $load_url ) ); |
|
| 663 | + wp_safe_redirect(esc_url_raw($load_url)); |
|
| 664 | 664 | exit; |
| 665 | 665 | |
| 666 | 666 | } // end admin_process_grading_submission |
@@ -671,13 +671,13 @@ discard block |
||
| 671 | 671 | $lesson_data = array(); |
| 672 | 672 | parse_str($data, $lesson_data); |
| 673 | 673 | |
| 674 | - $lesson_id = intval( $lesson_data['lesson_id'] ); |
|
| 675 | - $course_id = intval( $lesson_data['course_id'] ); |
|
| 676 | - $grading_view = sanitize_text_field( $lesson_data['view'] ); |
|
| 674 | + $lesson_id = intval($lesson_data['lesson_id']); |
|
| 675 | + $course_id = intval($lesson_data['course_id']); |
|
| 676 | + $grading_view = sanitize_text_field($lesson_data['view']); |
|
| 677 | 677 | |
| 678 | 678 | $redirect_url = ''; |
| 679 | - if ( 0 < $lesson_id && 0 < $course_id ) { |
|
| 680 | - $redirect_url = esc_url_raw( apply_filters( 'sensei_ajax_redirect_url', add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id, 'course_id' => $course_id, 'view' => $grading_view ), admin_url( 'admin.php' ) ) ) ); |
|
| 679 | + if (0 < $lesson_id && 0 < $course_id) { |
|
| 680 | + $redirect_url = esc_url_raw(apply_filters('sensei_ajax_redirect_url', add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id, 'course_id' => $course_id, 'view' => $grading_view), admin_url('admin.php')))); |
|
| 681 | 681 | } // End If Statement |
| 682 | 682 | |
| 683 | 683 | echo $redirect_url; |
@@ -685,11 +685,11 @@ discard block |
||
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | public function add_grading_notices() { |
| 688 | - if( isset( $_GET['page'] ) && $this->page_slug == $_GET['page'] && isset( $_GET['message'] ) && $_GET['message'] ) { |
|
| 689 | - if( 'graded' == $_GET['message'] ) { |
|
| 688 | + if (isset($_GET['page']) && $this->page_slug == $_GET['page'] && isset($_GET['message']) && $_GET['message']) { |
|
| 689 | + if ('graded' == $_GET['message']) { |
|
| 690 | 690 | $msg = array( |
| 691 | 691 | 'updated', |
| 692 | - __( 'Quiz Graded Successfully!', 'woothemes-sensei' ), |
|
| 692 | + __('Quiz Graded Successfully!', 'woothemes-sensei'), |
|
| 693 | 693 | ); |
| 694 | 694 | } |
| 695 | 695 | ?> |
@@ -701,9 +701,9 @@ discard block |
||
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | public function sensei_grading_notices() { |
| 704 | - if ( isset( $_GET['action'] ) && 'graded' == $_GET['action'] ) { |
|
| 704 | + if (isset($_GET['action']) && 'graded' == $_GET['action']) { |
|
| 705 | 705 | echo '<div class="grading-notice updated">'; |
| 706 | - echo '<p>' . __( 'Quiz Graded Successfully!', 'woothemes-sensei' ) . '</p>'; |
|
| 706 | + echo '<p>'.__('Quiz Graded Successfully!', 'woothemes-sensei').'</p>'; |
|
| 707 | 707 | echo '</div>'; |
| 708 | 708 | } // End If Statement |
| 709 | 709 | } // End sensei_grading_notices() |
@@ -726,16 +726,16 @@ discard block |
||
| 726 | 726 | * |
| 727 | 727 | * @return int $quiz_grade total sum of all question grades |
| 728 | 728 | */ |
| 729 | - public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
|
| 729 | + public static function grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') { |
|
| 730 | 730 | |
| 731 | - if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted |
|
| 732 | - || $quiz_grade_type != 'auto' ) { |
|
| 731 | + if ( ! (intval($quiz_id) > 0) || ! $submitted |
|
| 732 | + || $quiz_grade_type != 'auto') { |
|
| 733 | 733 | return false; // exit early |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | |
| 737 | 737 | $user_id = get_current_user_id(); |
| 738 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; |
|
| 738 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 739 | 739 | $quiz_autogradable = true; |
| 740 | 740 | |
| 741 | 741 | /** |
@@ -749,23 +749,23 @@ discard block |
||
| 749 | 749 | * 'gap-fill'. |
| 750 | 750 | * } |
| 751 | 751 | */ |
| 752 | - $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); |
|
| 752 | + $autogradable_question_types = apply_filters('sensei_autogradable_question_types', array('multiple-choice', 'boolean', 'gap-fill')); |
|
| 753 | 753 | |
| 754 | 754 | $grade_total = 0; |
| 755 | 755 | $all_question_grades = array(); |
| 756 | - foreach( $submitted as $question_id => $answer ) { |
|
| 756 | + foreach ($submitted as $question_id => $answer) { |
|
| 757 | 757 | |
| 758 | 758 | // check if the question is autogradable, either by type, or because the grade is 0 |
| 759 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 760 | - $achievable_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 759 | + $question_type = Sensei()->question->get_question_type($question_id); |
|
| 760 | + $achievable_grade = Sensei()->question->get_question_grade($question_id); |
|
| 761 | 761 | // Question has a zero grade, so skip grading |
| 762 | - if ( 0 == $achievable_grade ) { |
|
| 763 | - $all_question_grades[ $question_id ] = $achievable_grade; |
|
| 762 | + if (0 == $achievable_grade) { |
|
| 763 | + $all_question_grades[$question_id] = $achievable_grade; |
|
| 764 | 764 | } |
| 765 | - elseif ( in_array( $question_type, $autogradable_question_types ) ) { |
|
| 765 | + elseif (in_array($question_type, $autogradable_question_types)) { |
|
| 766 | 766 | // Get user question grade |
| 767 | - $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 768 | - $all_question_grades[ $question_id ] = $question_grade; |
|
| 767 | + $question_grade = Sensei_Utils::sensei_grade_question_auto($question_id, $question_type, $answer, $user_id); |
|
| 768 | + $all_question_grades[$question_id] = $question_grade; |
|
| 769 | 769 | $grade_total += $question_grade; |
| 770 | 770 | |
| 771 | 771 | } else { |
@@ -778,27 +778,27 @@ discard block |
||
| 778 | 778 | }// end for each question |
| 779 | 779 | |
| 780 | 780 | // Only if the whole quiz was autogradable do we set a grade |
| 781 | - if ( $quiz_autogradable ) { |
|
| 781 | + if ($quiz_autogradable) { |
|
| 782 | 782 | |
| 783 | - $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); |
|
| 783 | + $quiz_total = Sensei_Utils::sensei_get_quiz_total($quiz_id); |
|
| 784 | 784 | // Check for zero total from grades |
| 785 | - if ( 0 < $quiz_total ) { |
|
| 786 | - $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); |
|
| 785 | + if (0 < $quiz_total) { |
|
| 786 | + $grade = abs(round((doubleval($grade_total) * 100) / ($quiz_total), 2)); |
|
| 787 | 787 | } |
| 788 | 788 | else { |
| 789 | 789 | $grade = 0; |
| 790 | 790 | } |
| 791 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); |
|
| 791 | + Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id, $quiz_grade_type); |
|
| 792 | 792 | |
| 793 | 793 | } else { |
| 794 | 794 | |
| 795 | - $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); |
|
| 795 | + $grade = new WP_Error('autograde', __('This quiz is not able to be automatically graded.', 'woothemes-sensei')); |
|
| 796 | 796 | |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default |
| 800 | 800 | // when doing manual grading. |
| 801 | - Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); |
|
| 801 | + Sensei()->quiz-> set_user_grades($all_question_grades, $lesson_id, $user_id); |
|
| 802 | 802 | |
| 803 | 803 | return $grade; |
| 804 | 804 | |
@@ -818,22 +818,22 @@ discard block |
||
| 818 | 818 | * |
| 819 | 819 | * @return int $question_grade |
| 820 | 820 | */ |
| 821 | - public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
|
| 821 | + public static function grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) { |
|
| 822 | 822 | |
| 823 | - if( intval( $user_id ) == 0 ) { |
|
| 823 | + if (intval($user_id) == 0) { |
|
| 824 | 824 | |
| 825 | 825 | $user_id = get_current_user_id(); |
| 826 | 826 | |
| 827 | 827 | } |
| 828 | 828 | |
| 829 | - if( ! ( intval( $question_id ) > 0 ) ) { |
|
| 829 | + if ( ! (intval($question_id) > 0)) { |
|
| 830 | 830 | |
| 831 | 831 | return false; |
| 832 | 832 | |
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | |
| 836 | - Sensei()->question->get_question_type( $question_id ); |
|
| 836 | + Sensei()->question->get_question_type($question_id); |
|
| 837 | 837 | |
| 838 | 838 | /** |
| 839 | 839 | * Applying a grade before the auto grading takes place. |
@@ -847,42 +847,42 @@ discard block |
||
| 847 | 847 | * @param string $question_type one of the Sensei question type. |
| 848 | 848 | * @param string $answer user supplied question answer |
| 849 | 849 | */ |
| 850 | - $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); |
|
| 850 | + $question_grade = apply_filters('sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer); |
|
| 851 | 851 | |
| 852 | - if ( false !== $question_grade ) { |
|
| 852 | + if (false !== $question_grade) { |
|
| 853 | 853 | |
| 854 | 854 | return $question_grade; |
| 855 | 855 | |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | // auto grading core |
| 859 | - if( in_array( $question_type , array( 'multiple-choice' , 'boolean' ) ) ){ |
|
| 859 | + if (in_array($question_type, array('multiple-choice', 'boolean'))) { |
|
| 860 | 860 | |
| 861 | - $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 861 | + $right_answer = (array) get_post_meta($question_id, '_question_right_answer', true); |
|
| 862 | 862 | |
| 863 | - if( 0 == get_magic_quotes_gpc() ) { |
|
| 864 | - $answer = wp_unslash( $answer ); |
|
| 863 | + if (0 == get_magic_quotes_gpc()) { |
|
| 864 | + $answer = wp_unslash($answer); |
|
| 865 | 865 | } |
| 866 | 866 | $answer = (array) $answer; |
| 867 | - if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { |
|
| 867 | + if (is_array($right_answer) && count($right_answer) == count($answer)) { |
|
| 868 | 868 | // Loop through all answers ensure none are 'missing' |
| 869 | 869 | $all_correct = true; |
| 870 | - foreach ( $answer as $check_answer ) { |
|
| 871 | - if ( !in_array( $check_answer, $right_answer ) ) { |
|
| 870 | + foreach ($answer as $check_answer) { |
|
| 871 | + if ( ! in_array($check_answer, $right_answer)) { |
|
| 872 | 872 | $all_correct = false; |
| 873 | 873 | } |
| 874 | 874 | } |
| 875 | 875 | // If all correct then grade |
| 876 | - if ( $all_correct ) { |
|
| 877 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 876 | + if ($all_correct) { |
|
| 877 | + $question_grade = Sensei()->question->get_question_grade($question_id); |
|
| 878 | 878 | } |
| 879 | 879 | } |
| 880 | 880 | |
| 881 | - } elseif( 'gap-fill' == $question_type ){ |
|
| 881 | + } elseif ('gap-fill' == $question_type) { |
|
| 882 | 882 | |
| 883 | - $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); |
|
| 883 | + $question_grade = self::grade_gap_fill_question($question_id, $answer); |
|
| 884 | 884 | |
| 885 | - } else{ |
|
| 885 | + } else { |
|
| 886 | 886 | |
| 887 | 887 | /** |
| 888 | 888 | * Grading questions that are not auto gradable. |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | * @param string $question_type one of the Sensei question type. |
| 896 | 896 | * @param string $answer user supplied question answer |
| 897 | 897 | */ |
| 898 | - $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); |
|
| 898 | + $question_grade = (int) apply_filters('sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer); |
|
| 899 | 899 | |
| 900 | 900 | } // end if $question_type |
| 901 | 901 | |
@@ -911,13 +911,13 @@ discard block |
||
| 911 | 911 | * |
| 912 | 912 | * @return bool | int false or the grade given to the user answer |
| 913 | 913 | */ |
| 914 | - public static function grade_gap_fill_question( $question_id, $user_answer ){ |
|
| 914 | + public static function grade_gap_fill_question($question_id, $user_answer) { |
|
| 915 | 915 | |
| 916 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 917 | - $gapfill_array = explode( '||', $right_answer ); |
|
| 916 | + $right_answer = get_post_meta($question_id, '_question_right_answer', true); |
|
| 917 | + $gapfill_array = explode('||', $right_answer); |
|
| 918 | 918 | |
| 919 | - if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
| 920 | - $user_answer = wp_unslash( $user_answer ); |
|
| 919 | + if (0 == get_magic_quotes_gpc()) { // deprecated from PHP 5.4 but we still support PHP 5.2 |
|
| 920 | + $user_answer = wp_unslash($user_answer); |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | /** |
@@ -930,53 +930,53 @@ discard block |
||
| 930 | 930 | * |
| 931 | 931 | * @since 1.9.0 |
| 932 | 932 | */ |
| 933 | - $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); |
|
| 933 | + $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false); |
|
| 934 | 934 | |
| 935 | - if( $do_case_sensitive_comparison ){ |
|
| 935 | + if ($do_case_sensitive_comparison) { |
|
| 936 | 936 | |
| 937 | 937 | // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
| 938 | - if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { |
|
| 938 | + if (trim(($gapfill_array[1])) == trim($user_answer)) { |
|
| 939 | 939 | |
| 940 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 940 | + return Sensei()->question->get_question_grade($question_id); |
|
| 941 | 941 | |
| 942 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 942 | + } else if (@preg_match('/'.$gapfill_array[1].'/i', null) !== FALSE) { |
|
| 943 | 943 | |
| 944 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 944 | + if (preg_match('/'.$gapfill_array[1].'/i', $user_answer)) { |
|
| 945 | 945 | |
| 946 | 946 | return Sensei()->question->get_question_grade($question_id); |
| 947 | 947 | |
| 948 | - }else{ |
|
| 948 | + } else { |
|
| 949 | 949 | |
| 950 | 950 | return false; |
| 951 | 951 | |
| 952 | 952 | } |
| 953 | 953 | |
| 954 | - }else{ |
|
| 954 | + } else { |
|
| 955 | 955 | |
| 956 | 956 | return false; |
| 957 | 957 | |
| 958 | 958 | } |
| 959 | 959 | |
| 960 | - }else{ |
|
| 960 | + } else { |
|
| 961 | 961 | |
| 962 | 962 | // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer |
| 963 | - if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { |
|
| 963 | + if (trim(strtolower($gapfill_array[1])) == trim(strtolower($user_answer))) { |
|
| 964 | 964 | |
| 965 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 965 | + return Sensei()->question->get_question_grade($question_id); |
|
| 966 | 966 | |
| 967 | - } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { |
|
| 967 | + } else if (@preg_match('/'.$gapfill_array[1].'/i', null) !== FALSE) { |
|
| 968 | 968 | |
| 969 | - if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { |
|
| 969 | + if (preg_match('/'.$gapfill_array[1].'/i', $user_answer)) { |
|
| 970 | 970 | |
| 971 | - return Sensei()->question->get_question_grade( $question_id ); |
|
| 971 | + return Sensei()->question->get_question_grade($question_id); |
|
| 972 | 972 | |
| 973 | - }else{ |
|
| 973 | + } else { |
|
| 974 | 974 | |
| 975 | 975 | return false; |
| 976 | 976 | |
| 977 | 977 | } |
| 978 | 978 | |
| 979 | - }else{ |
|
| 979 | + } else { |
|
| 980 | 980 | |
| 981 | 981 | return false; |
| 982 | 982 | |
@@ -993,4 +993,4 @@ discard block |
||
| 993 | 993 | * for backward compatibility |
| 994 | 994 | * @since 1.9.0 |
| 995 | 995 | */ |
| 996 | -class WooThemes_Sensei_Grading extends Sensei_Grading{} |
|
| 996 | +class WooThemes_Sensei_Grading extends Sensei_Grading {} |
|
@@ -44,6 +44,7 @@ |
||
| 44 | 44 | /** |
| 45 | 45 | * Constructor |
| 46 | 46 | * @since 1.2.0 |
| 47 | + * @param string $token |
|
| 47 | 48 | * @return void |
| 48 | 49 | */ |
| 49 | 50 | public function __construct ( $token ) { |
@@ -162,8 +162,8 @@ |
||
| 162 | 162 | $sortable[$id] = $data; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - $primary = $this->get_primary_column_name(); |
|
| 166 | - $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); |
|
| 165 | + $primary = $this->get_primary_column_name(); |
|
| 166 | + $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); |
|
| 167 | 167 | |
| 168 | 168 | return $this->_column_headers; |
| 169 | 169 | } |
@@ -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 Generic List Table Class |
@@ -46,17 +46,17 @@ discard block |
||
| 46 | 46 | * @since 1.2.0 |
| 47 | 47 | * @return void |
| 48 | 48 | */ |
| 49 | - public function __construct ( $token ) { |
|
| 49 | + public function __construct($token) { |
|
| 50 | 50 | // Class Variables |
| 51 | 51 | $this->token = $token; |
| 52 | 52 | |
| 53 | - parent::__construct( array( |
|
| 54 | - 'singular' => 'wp_list_table_' . $this->token, // Singular label |
|
| 55 | - 'plural' => 'wp_list_table_' . $this->token . 's', // Plural label |
|
| 53 | + parent::__construct(array( |
|
| 54 | + 'singular' => 'wp_list_table_'.$this->token, // Singular label |
|
| 55 | + 'plural' => 'wp_list_table_'.$this->token.'s', // Plural label |
|
| 56 | 56 | 'ajax' => false // No Ajax for this table |
| 57 | - ) ); |
|
| 57 | + )); |
|
| 58 | 58 | // Actions |
| 59 | - add_action( 'sensei_before_list_table', array( $this, 'table_search_form' ), 5 ); |
|
| 59 | + add_action('sensei_before_list_table', array($this, 'table_search_form'), 5); |
|
| 60 | 60 | } // End __construct() |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @param array $columns Existing columns |
| 65 | 65 | * @return array Modified columns |
| 66 | 66 | */ |
| 67 | - public function remove_sortable_columns( $columns ) { |
|
| 67 | + public function remove_sortable_columns($columns) { |
|
| 68 | 68 | return array(); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -73,14 +73,14 @@ discard block |
||
| 73 | 73 | * @since 1.2.0 |
| 74 | 74 | * @param string $which, helps you decide if you add the markup after (bottom) or before (top) the list |
| 75 | 75 | */ |
| 76 | - public function extra_tablenav( $which ) { |
|
| 77 | - if ( $which == "top" ){ |
|
| 76 | + public function extra_tablenav($which) { |
|
| 77 | + if ($which == "top") { |
|
| 78 | 78 | //The code that goes before the table is here |
| 79 | - do_action( 'sensei_before_list_table' ); |
|
| 79 | + do_action('sensei_before_list_table'); |
|
| 80 | 80 | } // End If Statement |
| 81 | - if ( $which == "bottom" ){ |
|
| 81 | + if ($which == "bottom") { |
|
| 82 | 82 | //The code that goes after the table is there |
| 83 | - do_action( 'sensei_after_list_table' ); |
|
| 83 | + do_action('sensei_after_list_table'); |
|
| 84 | 84 | } // End If Statement |
| 85 | 85 | } // End extra_tablenav() |
| 86 | 86 | |
@@ -90,20 +90,20 @@ discard block |
||
| 90 | 90 | * @return void |
| 91 | 91 | */ |
| 92 | 92 | public function table_search_form() { |
| 93 | - if ( empty( $_REQUEST['s'] ) && !$this->has_items() ) { |
|
| 93 | + if (empty($_REQUEST['s']) && ! $this->has_items()) { |
|
| 94 | 94 | return; |
| 95 | 95 | } |
| 96 | 96 | ?><form method="get"> |
| 97 | 97 | <?php |
| 98 | - if( isset( $_GET ) && count( $_GET ) > 0 ) { |
|
| 99 | - foreach( $_GET as $k => $v ) { |
|
| 100 | - if( 's' != $k ) { |
|
| 98 | + if (isset($_GET) && count($_GET) > 0) { |
|
| 99 | + foreach ($_GET as $k => $v) { |
|
| 100 | + if ('s' != $k) { |
|
| 101 | 101 | ?><input type="hidden" name="<?php echo $k; ?>" value="<?php echo $v; ?>" /><?php |
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | ?> |
| 106 | - <?php $this->search_box( __( 'Search Users' ,'woothemes-sensei' ), 'search_id'); ?> |
|
| 106 | + <?php $this->search_box(__('Search Users', 'woothemes-sensei'), 'search_id'); ?> |
|
| 107 | 107 | </form><?php |
| 108 | 108 | } // End table_search_form() |
| 109 | 109 | |
@@ -131,11 +131,11 @@ discard block |
||
| 131 | 131 | * @return array |
| 132 | 132 | */ |
| 133 | 133 | function get_column_info() { |
| 134 | - if ( isset( $this->_column_headers ) ) |
|
| 134 | + if (isset($this->_column_headers)) |
|
| 135 | 135 | return $this->_column_headers; |
| 136 | 136 | |
| 137 | 137 | $columns = $this->get_columns(); |
| 138 | - $hidden = get_hidden_columns( $this->screen ); |
|
| 138 | + $hidden = get_hidden_columns($this->screen); |
|
| 139 | 139 | |
| 140 | 140 | $sortable_columns = $this->get_sortable_columns(); |
| 141 | 141 | /** |
@@ -148,22 +148,22 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @param array $sortable_columns An array of sortable columns. |
| 150 | 150 | */ |
| 151 | - $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns ); |
|
| 151 | + $_sortable = apply_filters("manage_{$this->screen->id}_sortable_columns", $sortable_columns); |
|
| 152 | 152 | |
| 153 | 153 | $sortable = array(); |
| 154 | - foreach ( $_sortable as $id => $data ) { |
|
| 155 | - if ( empty( $data ) ) |
|
| 154 | + foreach ($_sortable as $id => $data) { |
|
| 155 | + if (empty($data)) |
|
| 156 | 156 | continue; |
| 157 | 157 | |
| 158 | 158 | $data = (array) $data; |
| 159 | - if ( !isset( $data[1] ) ) |
|
| 159 | + if ( ! isset($data[1])) |
|
| 160 | 160 | $data[1] = false; |
| 161 | 161 | |
| 162 | 162 | $sortable[$id] = $data; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | $primary = $this->get_primary_column_name(); |
| 166 | - $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); |
|
| 166 | + $this->_column_headers = array($columns, $hidden, $sortable, $primary); |
|
| 167 | 167 | |
| 168 | 168 | return $this->_column_headers; |
| 169 | 169 | } |
@@ -174,27 +174,27 @@ discard block |
||
| 174 | 174 | * @since 1.7.0 |
| 175 | 175 | * @param object $item The current item |
| 176 | 176 | */ |
| 177 | - function single_row( $item ) { |
|
| 177 | + function single_row($item) { |
|
| 178 | 178 | static $row_class = ''; |
| 179 | - $row_class = ( $row_class == '' ? ' class="alternate"' : '' ); |
|
| 179 | + $row_class = ($row_class == '' ? ' class="alternate"' : ''); |
|
| 180 | 180 | |
| 181 | - echo '<tr' . $row_class . '>'; |
|
| 181 | + echo '<tr'.$row_class.'>'; |
|
| 182 | 182 | |
| 183 | - $column_data = $this->get_row_data( $item ); |
|
| 183 | + $column_data = $this->get_row_data($item); |
|
| 184 | 184 | |
| 185 | - list( $columns, $hidden ) = $this->get_column_info(); |
|
| 185 | + list($columns, $hidden) = $this->get_column_info(); |
|
| 186 | 186 | |
| 187 | - foreach ( $columns as $column_name => $column_display_name ) { |
|
| 187 | + foreach ($columns as $column_name => $column_display_name) { |
|
| 188 | 188 | $class = "class='$column_name column-$column_name'"; |
| 189 | 189 | |
| 190 | 190 | $style = ''; |
| 191 | - if ( in_array( $column_name, $hidden ) ) |
|
| 191 | + if (in_array($column_name, $hidden)) |
|
| 192 | 192 | $style = ' style="display:none;"'; |
| 193 | 193 | |
| 194 | 194 | $attributes = "$class$style"; |
| 195 | 195 | |
| 196 | 196 | echo "<td $attributes>"; |
| 197 | - if ( isset($column_data[$column_name]) ) { |
|
| 197 | + if (isset($column_data[$column_name])) { |
|
| 198 | 198 | echo $column_data[$column_name]; |
| 199 | 199 | } |
| 200 | 200 | echo "</td>"; |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | * @access public |
| 209 | 209 | * @abstract |
| 210 | 210 | */ |
| 211 | - protected function get_row_data( $item ) { |
|
| 212 | - die( 'either function WooThemes_Sensei_List_Table::get_row_data() must be over-ridden in a sub-class or WooThemes_Sensei_List_Table::single_row() should be.' ); |
|
| 211 | + protected function get_row_data($item) { |
|
| 212 | + die('either function WooThemes_Sensei_List_Table::get_row_data() must be over-ridden in a sub-class or WooThemes_Sensei_List_Table::single_row() should be.'); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | function no_items() { |
| 222 | 222 | |
| 223 | - _e( 'No items found.', 'woothemes-sensei' ); |
|
| 223 | + _e('No items found.', 'woothemes-sensei'); |
|
| 224 | 224 | |
| 225 | 225 | } // End no_items() |
| 226 | 226 | |
@@ -238,9 +238,9 @@ discard block |
||
| 238 | 238 | * @since 1.2.0 |
| 239 | 239 | * @return void |
| 240 | 240 | */ |
| 241 | - public function bulk_actions( $which = '' ) { |
|
| 241 | + public function bulk_actions($which = '') { |
|
| 242 | 242 | // This will be output Above the table headers on the left |
| 243 | - echo apply_filters( 'sensei_list_bulk_actions', '' ); |
|
| 243 | + echo apply_filters('sensei_list_bulk_actions', ''); |
|
| 244 | 244 | } // End bulk_actions() |
| 245 | 245 | |
| 246 | 246 | } // End Class |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Generic List Table Class |
@@ -131,8 +134,9 @@ discard block |
||
| 131 | 134 | * @return array |
| 132 | 135 | */ |
| 133 | 136 | function get_column_info() { |
| 134 | - if ( isset( $this->_column_headers ) ) |
|
| 135 | - return $this->_column_headers; |
|
| 137 | + if ( isset( $this->_column_headers ) ) { |
|
| 138 | + return $this->_column_headers; |
|
| 139 | + } |
|
| 136 | 140 | |
| 137 | 141 | $columns = $this->get_columns(); |
| 138 | 142 | $hidden = get_hidden_columns( $this->screen ); |
@@ -152,12 +156,14 @@ discard block |
||
| 152 | 156 | |
| 153 | 157 | $sortable = array(); |
| 154 | 158 | foreach ( $_sortable as $id => $data ) { |
| 155 | - if ( empty( $data ) ) |
|
| 156 | - continue; |
|
| 159 | + if ( empty( $data ) ) { |
|
| 160 | + continue; |
|
| 161 | + } |
|
| 157 | 162 | |
| 158 | 163 | $data = (array) $data; |
| 159 | - if ( !isset( $data[1] ) ) |
|
| 160 | - $data[1] = false; |
|
| 164 | + if ( !isset( $data[1] ) ) { |
|
| 165 | + $data[1] = false; |
|
| 166 | + } |
|
| 161 | 167 | |
| 162 | 168 | $sortable[$id] = $data; |
| 163 | 169 | } |
@@ -188,8 +194,9 @@ discard block |
||
| 188 | 194 | $class = "class='$column_name column-$column_name'"; |
| 189 | 195 | |
| 190 | 196 | $style = ''; |
| 191 | - if ( in_array( $column_name, $hidden ) ) |
|
| 192 | - $style = ' style="display:none;"'; |
|
| 197 | + if ( in_array( $column_name, $hidden ) ) { |
|
| 198 | + $style = ' style="display:none;"'; |
|
| 199 | + } |
|
| 193 | 200 | |
| 194 | 201 | $attributes = "$class$style"; |
| 195 | 202 | |
@@ -299,7 +299,7 @@ |
||
| 299 | 299 | * @param integer $sender_id ID of sender |
| 300 | 300 | * @param integer $receiver_id ID of receiver |
| 301 | 301 | * @param string $message Message content |
| 302 | - * @param string $post_id ID of post related to message |
|
| 302 | + * @param integer $post_id ID of post related to message |
|
| 303 | 303 | * @return mixed Message ID on success, boolean false on failure |
| 304 | 304 | */ |
| 305 | 305 | private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { |
@@ -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 Messages Class |
@@ -21,61 +21,61 @@ discard block |
||
| 21 | 21 | * Constructor. |
| 22 | 22 | * @since 1.6.0 |
| 23 | 23 | */ |
| 24 | - public function __construct () { |
|
| 24 | + public function __construct() { |
|
| 25 | 25 | $this->post_type = 'sensei_message'; |
| 26 | - $this->meta_fields = array( 'sender', 'receiver' ); |
|
| 26 | + $this->meta_fields = array('sender', 'receiver'); |
|
| 27 | 27 | |
| 28 | 28 | // Add Messages page to admin menu |
| 29 | - add_action( 'admin_menu', array( $this, 'add_menu_item' ), 40 ); |
|
| 30 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ), 10, 2 ); |
|
| 31 | - add_action( 'admin_menu', array( $this, 'remove_meta_box' ) ); |
|
| 29 | + add_action('admin_menu', array($this, 'add_menu_item'), 40); |
|
| 30 | + add_action('add_meta_boxes', array($this, 'add_meta_box'), 10, 2); |
|
| 31 | + add_action('admin_menu', array($this, 'remove_meta_box')); |
|
| 32 | 32 | |
| 33 | 33 | // Save new private message |
| 34 | - add_action( 'init', array( $this, 'save_new_message' ), 1 ); |
|
| 34 | + add_action('init', array($this, 'save_new_message'), 1); |
|
| 35 | 35 | |
| 36 | 36 | // Monitor when new reply is posted |
| 37 | - add_action( 'comment_post', array( $this, 'message_reply_received' ), 10, 1 ); |
|
| 37 | + add_action('comment_post', array($this, 'message_reply_received'), 10, 1); |
|
| 38 | 38 | |
| 39 | 39 | // Block WordPress from sending comment update emails for the messages post type |
| 40 | - add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 40 | + add_filter('comment_notification_recipients', array($this, 'stop_wp_comment_emails'), 20, 2); |
|
| 41 | 41 | |
| 42 | 42 | // Block WordPress from sending comment moderator emails on the sensei messages post types |
| 43 | - add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 43 | + add_filter('comment_moderation_recipients', array($this, 'stop_wp_comment_emails'), 20, 2); |
|
| 44 | 44 | |
| 45 | 45 | // Process saving of message posts |
| 46 | - add_action( 'save_post', array( $this, 'save_message' ) ); |
|
| 46 | + add_action('save_post', array($this, 'save_message')); |
|
| 47 | 47 | |
| 48 | 48 | // Add message links to courses & lessons |
| 49 | - add_action( 'sensei_single_course_content_inside_before', array( $this, 'send_message_link' ), 35 ); |
|
| 49 | + add_action('sensei_single_course_content_inside_before', array($this, 'send_message_link'), 35); |
|
| 50 | 50 | |
| 51 | 51 | // add message link to lesson |
| 52 | - add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); |
|
| 52 | + add_action('sensei_single_lesson_content_inside_before', array($this, 'send_message_link'), 30, 2); |
|
| 53 | 53 | |
| 54 | 54 | // add message link to lesson |
| 55 | - add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); |
|
| 55 | + add_action('sensei_single_quiz_questions_before', array($this, 'send_message_link'), 10, 2); |
|
| 56 | 56 | |
| 57 | 57 | // Hide messages and replies from users who do not have access |
| 58 | - add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); |
|
| 59 | - add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); |
|
| 60 | - add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); |
|
| 61 | - add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); |
|
| 62 | - add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); |
|
| 63 | - add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); |
|
| 64 | - add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); |
|
| 58 | + add_action('template_redirect', array($this, 'message_login'), 10, 1); |
|
| 59 | + add_action('pre_get_posts', array($this, 'message_list'), 10, 1); |
|
| 60 | + add_filter('the_title', array($this, 'message_title'), 10, 2); |
|
| 61 | + add_filter('the_content', array($this, 'message_content'), 10, 1); |
|
| 62 | + add_filter('comments_array', array($this, 'message_replies'), 100, 1); |
|
| 63 | + add_filter('get_comments_number', array($this, 'message_reply_count'), 100, 2); |
|
| 64 | + add_filter('comments_open', array($this, 'message_replies_open'), 100, 2); |
|
| 65 | 65 | } // End __construct() |
| 66 | 66 | |
| 67 | 67 | public function add_menu_item() { |
| 68 | 68 | |
| 69 | - if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
|
| 70 | - add_submenu_page( 'sensei', __( 'Messages', 'woothemes-sensei'), __( 'Messages', 'woothemes-sensei') , 'edit_courses', 'edit.php?post_type=sensei_message' ); |
|
| 69 | + if ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable']) { |
|
| 70 | + add_submenu_page('sensei', __('Messages', 'woothemes-sensei'), __('Messages', 'woothemes-sensei'), 'edit_courses', 'edit.php?post_type=sensei_message'); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - public function add_meta_box( $post_type, $post ) { |
|
| 74 | + public function add_meta_box($post_type, $post) { |
|
| 75 | 75 | |
| 76 | - if( ! $post_type == $this->post_type ) return; |
|
| 76 | + if ( ! $post_type == $this->post_type) return; |
|
| 77 | 77 | |
| 78 | - add_meta_box( $this->post_type . '-data', __( 'Message Information', 'woothemes-sensei' ), array( $this, 'meta_box_content' ), $this->post_type, 'normal', 'default' ); |
|
| 78 | + add_meta_box($this->post_type.'-data', __('Message Information', 'woothemes-sensei'), array($this, 'meta_box_content'), $this->post_type, 'normal', 'default'); |
|
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | |
@@ -85,25 +85,25 @@ discard block |
||
| 85 | 85 | $settings = array( |
| 86 | 86 | array( |
| 87 | 87 | 'id' => 'sender', |
| 88 | - 'label' => __( 'Message sent by:', 'woothemes-sensei' ), |
|
| 89 | - 'description' => __( 'The username of the learner who sent this message.', 'woothemes-sensei' ), |
|
| 88 | + 'label' => __('Message sent by:', 'woothemes-sensei'), |
|
| 89 | + 'description' => __('The username of the learner who sent this message.', 'woothemes-sensei'), |
|
| 90 | 90 | 'type' => 'text', |
| 91 | 91 | 'default' => '', |
| 92 | - 'placeholder' => __( 'Learner username', 'woothemes-sensei' ), |
|
| 92 | + 'placeholder' => __('Learner username', 'woothemes-sensei'), |
|
| 93 | 93 | ), |
| 94 | 94 | array( |
| 95 | 95 | 'id' => 'receiver', |
| 96 | - 'label' => __( 'Message received by:', 'woothemes-sensei' ), |
|
| 97 | - 'description' => __( 'The username of the teacher who received this message.', 'woothemes-sensei' ), |
|
| 96 | + 'label' => __('Message received by:', 'woothemes-sensei'), |
|
| 97 | + 'description' => __('The username of the teacher who received this message.', 'woothemes-sensei'), |
|
| 98 | 98 | 'type' => 'text', |
| 99 | 99 | 'default' => '', |
| 100 | - 'placeholder' => __( 'Teacher username', 'woothemes-sensei' ), |
|
| 100 | + 'placeholder' => __('Teacher username', 'woothemes-sensei'), |
|
| 101 | 101 | ), |
| 102 | 102 | ); |
| 103 | 103 | |
| 104 | - $message_posttype = get_post_meta( $post->ID, '_posttype', true ); |
|
| 104 | + $message_posttype = get_post_meta($post->ID, '_posttype', true); |
|
| 105 | 105 | |
| 106 | - if( isset( $message_posttype ) && $message_posttype ) { |
|
| 106 | + if (isset($message_posttype) && $message_posttype) { |
|
| 107 | 107 | |
| 108 | 108 | $args = array( |
| 109 | 109 | 'post_type' => $message_posttype, |
@@ -113,58 +113,58 @@ discard block |
||
| 113 | 113 | 'post_status' => 'publish', |
| 114 | 114 | ); |
| 115 | 115 | |
| 116 | - $posts = get_posts( $args ); |
|
| 116 | + $posts = get_posts($args); |
|
| 117 | 117 | |
| 118 | - $post_options[0] = sprintf( __( 'Select %1$s', 'woothemes-sensei' ), $message_posttype ); |
|
| 119 | - foreach( $posts as $post_item ) { |
|
| 120 | - $post_options[ $post_item->ID ] = $post_item->post_title; |
|
| 118 | + $post_options[0] = sprintf(__('Select %1$s', 'woothemes-sensei'), $message_posttype); |
|
| 119 | + foreach ($posts as $post_item) { |
|
| 120 | + $post_options[$post_item->ID] = $post_item->post_title; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $settings[] = array( |
| 124 | 124 | 'id' => 'post', |
| 125 | - 'label' => sprintf( __( 'Message from %1$s:', 'woothemes-sensei' ), $message_posttype ), |
|
| 126 | - 'description' => sprintf( __( 'The %1$s to which this message relates.', 'woothemes-sensei' ), $message_posttype ), |
|
| 125 | + 'label' => sprintf(__('Message from %1$s:', 'woothemes-sensei'), $message_posttype), |
|
| 126 | + 'description' => sprintf(__('The %1$s to which this message relates.', 'woothemes-sensei'), $message_posttype), |
|
| 127 | 127 | 'type' => 'select', |
| 128 | 128 | 'default' => 0, |
| 129 | 129 | 'options' => $post_options, |
| 130 | 130 | ); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $html = Sensei()->admin->render_settings( $settings, $post->ID, 'message-info' ); |
|
| 133 | + $html = Sensei()->admin->render_settings($settings, $post->ID, 'message-info'); |
|
| 134 | 134 | |
| 135 | 135 | echo $html; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - public function save_message( $post_id = 0 ) { |
|
| 138 | + public function save_message($post_id = 0) { |
|
| 139 | 139 | global $post; |
| 140 | 140 | |
| 141 | - if( $this->post_type != get_post_type() ) return; |
|
| 141 | + if ($this->post_type != get_post_type()) return; |
|
| 142 | 142 | |
| 143 | - if( isset( $_POST['sender'] ) && $_POST['sender'] ) { |
|
| 144 | - update_post_meta( $post_id, '_sender', $_POST['sender'] ); |
|
| 143 | + if (isset($_POST['sender']) && $_POST['sender']) { |
|
| 144 | + update_post_meta($post_id, '_sender', $_POST['sender']); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - if( isset( $_POST['receiver'] ) && $_POST['receiver'] ) { |
|
| 148 | - update_post_meta( $post_id, '_receiver', $_POST['receiver'] ); |
|
| 147 | + if (isset($_POST['receiver']) && $_POST['receiver']) { |
|
| 148 | + update_post_meta($post_id, '_receiver', $_POST['receiver']); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if( isset( $_POST['post'] ) && $_POST['post'] ) { |
|
| 152 | - update_post_meta( $post_id, '_post', $_POST['post'] ); |
|
| 151 | + if (isset($_POST['post']) && $_POST['post']) { |
|
| 152 | + update_post_meta($post_id, '_post', $_POST['post']); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - remove_action( 'save_post', array( $this, 'save_message' ) ); |
|
| 155 | + remove_action('save_post', array($this, 'save_message')); |
|
| 156 | 156 | |
| 157 | - wp_update_post( array( 'ID' => $post_id, 'comment_status' => 'open' ) ); |
|
| 157 | + wp_update_post(array('ID' => $post_id, 'comment_status' => 'open')); |
|
| 158 | 158 | |
| 159 | - add_action( 'save_post', array( $this, 'save_message' ) ); |
|
| 159 | + add_action('save_post', array($this, 'save_message')); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - public function send_message_link( $post_id = 0, $user_id = 0 ) { |
|
| 162 | + public function send_message_link($post_id = 0, $user_id = 0) { |
|
| 163 | 163 | global $post; |
| 164 | 164 | |
| 165 | 165 | // only show the link for the allowed post types: |
| 166 | 166 | $allowed_post_types = array('lesson', 'course', 'quiz'); |
| 167 | - if ( ! in_array( get_post_type() , $allowed_post_types ) ) { |
|
| 167 | + if ( ! in_array(get_post_type(), $allowed_post_types)) { |
|
| 168 | 168 | |
| 169 | 169 | return; |
| 170 | 170 | |
@@ -172,28 +172,28 @@ discard block |
||
| 172 | 172 | |
| 173 | 173 | $html = ''; |
| 174 | 174 | |
| 175 | - if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
|
| 175 | + if ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable']) { |
|
| 176 | 176 | |
| 177 | - if( ! is_user_logged_in() ) return; |
|
| 177 | + if ( ! is_user_logged_in()) return; |
|
| 178 | 178 | |
| 179 | - if( isset( $_GET['contact'] ) ) { |
|
| 180 | - $html .= $this->teacher_contact_form( $post ); |
|
| 179 | + if (isset($_GET['contact'])) { |
|
| 180 | + $html .= $this->teacher_contact_form($post); |
|
| 181 | 181 | } else { |
| 182 | - $href = add_query_arg( array( 'contact' => $post->post_type ) ); |
|
| 183 | - |
|
| 184 | - if( 'lesson' == $post->post_type ) { |
|
| 185 | - $contact_button_text = __( 'Contact Lesson Teacher', 'woothemes-sensei' ); |
|
| 186 | - } elseif( 'course' == $post->post_type ) { |
|
| 187 | - $contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' ); |
|
| 188 | - }else{ |
|
| 189 | - $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); |
|
| 182 | + $href = add_query_arg(array('contact' => $post->post_type)); |
|
| 183 | + |
|
| 184 | + if ('lesson' == $post->post_type) { |
|
| 185 | + $contact_button_text = __('Contact Lesson Teacher', 'woothemes-sensei'); |
|
| 186 | + } elseif ('course' == $post->post_type) { |
|
| 187 | + $contact_button_text = __('Contact Course Teacher', 'woothemes-sensei'); |
|
| 188 | + } else { |
|
| 189 | + $contact_button_text = __('Contact Teacher', 'woothemes-sensei'); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - $html .= '<p><a class="button send-message-button" href="' . esc_url($href) . '#private_message">' . $contact_button_text . '</a></p>'; |
|
| 192 | + $html .= '<p><a class="button send-message-button" href="'.esc_url($href).'#private_message">'.$contact_button_text.'</a></p>'; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if( isset( $this->message_notice ) && isset( $this->message_notice['type'] ) && isset( $this->message_notice['notice'] ) ) { |
|
| 196 | - $html .= '<div class="sensei-message ' . $this->message_notice['type'] . '">' . $this->message_notice['notice'] . '</div>'; |
|
| 195 | + if (isset($this->message_notice) && isset($this->message_notice['type']) && isset($this->message_notice['notice'])) { |
|
| 196 | + $html .= '<div class="sensei-message '.$this->message_notice['type'].'">'.$this->message_notice['notice'].'</div>'; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | } |
@@ -201,40 +201,40 @@ discard block |
||
| 201 | 201 | echo $html; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - public function teacher_contact_form( $post ) { |
|
| 204 | + public function teacher_contact_form($post) { |
|
| 205 | 205 | |
| 206 | - if( ! is_user_logged_in() ) return; |
|
| 206 | + if ( ! is_user_logged_in()) return; |
|
| 207 | 207 | |
| 208 | 208 | global $current_user; |
| 209 | 209 | wp_get_current_user(); |
| 210 | 210 | |
| 211 | 211 | $html = ''; |
| 212 | 212 | |
| 213 | - if( ! isset( $post->ID ) ) return $html; |
|
| 213 | + if ( ! isset($post->ID)) return $html; |
|
| 214 | 214 | |
| 215 | 215 | //confirm private message |
| 216 | 216 | $confirmation = ''; |
| 217 | - if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { |
|
| 217 | + if (isset($_GET['send']) && 'complete' == $_GET['send']) { |
|
| 218 | 218 | |
| 219 | 219 | $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); |
| 220 | - $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; |
|
| 220 | + $confirmation = '<div class="sensei-message tick">'.$confirmation_message.'</div>'; |
|
| 221 | 221 | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - $html .= '<h3 id="private_message">' . __( 'Send Private Message', 'woothemes-sensei' ) . '</h3>'; |
|
| 224 | + $html .= '<h3 id="private_message">'.__('Send Private Message', 'woothemes-sensei').'</h3>'; |
|
| 225 | 225 | $html .= '<p>'; |
| 226 | - $html .= $confirmation; |
|
| 226 | + $html .= $confirmation; |
|
| 227 | 227 | $html .= '</p>'; |
| 228 | 228 | $html .= '<form name="contact-teacher" action="" method="post" class="contact-teacher">'; |
| 229 | 229 | $html .= '<p class="form-row form-row-wide">'; |
| 230 | - $html .= '<textarea name="contact_message" placeholder="' . __( 'Enter your private message.', 'woothemes-sensei' ) . '"></textarea>'; |
|
| 230 | + $html .= '<textarea name="contact_message" placeholder="'.__('Enter your private message.', 'woothemes-sensei').'"></textarea>'; |
|
| 231 | 231 | $html .= '</p>'; |
| 232 | 232 | $html .= '<p class="form-row">'; |
| 233 | - $html .= '<input type="hidden" name="post_id" value="' . $post->ID . '" />'; |
|
| 234 | - $html .= '<input type="hidden" name="sender_id" value="' . $current_user->ID . '" />'; |
|
| 235 | - $html .= '<input type="hidden" name="receiver_id" value="' . $post->post_author . '" />'; |
|
| 236 | - $html .= wp_nonce_field( 'message_teacher', 'sensei_message_teacher_nonce', true, false ); |
|
| 237 | - $html .= '<input type="submit" class="send_message" value="' . __( 'Send Message', 'woothemes-sensei' ) . '" />'; |
|
| 233 | + $html .= '<input type="hidden" name="post_id" value="'.$post->ID.'" />'; |
|
| 234 | + $html .= '<input type="hidden" name="sender_id" value="'.$current_user->ID.'" />'; |
|
| 235 | + $html .= '<input type="hidden" name="receiver_id" value="'.$post->post_author.'" />'; |
|
| 236 | + $html .= wp_nonce_field('message_teacher', 'sensei_message_teacher_nonce', true, false); |
|
| 237 | + $html .= '<input type="submit" class="send_message" value="'.__('Send Message', 'woothemes-sensei').'" />'; |
|
| 238 | 238 | $html .= '</p>'; |
| 239 | 239 | $html .= '<div class="fix"></div>'; |
| 240 | 240 | $html .= '</form>'; |
@@ -244,30 +244,30 @@ discard block |
||
| 244 | 244 | |
| 245 | 245 | public function save_new_message() { |
| 246 | 246 | |
| 247 | - if( ! isset( $_POST['sensei_message_teacher_nonce'] ) ) return; |
|
| 247 | + if ( ! isset($_POST['sensei_message_teacher_nonce'])) return; |
|
| 248 | 248 | |
| 249 | - if( ! wp_verify_nonce( $_POST['sensei_message_teacher_nonce'], 'message_teacher' ) ) return; |
|
| 249 | + if ( ! wp_verify_nonce($_POST['sensei_message_teacher_nonce'], 'message_teacher')) return; |
|
| 250 | 250 | |
| 251 | - $message_id = $this->save_new_message_post( $_POST['sender_id'], $_POST['receiver_id'], $_POST['contact_message'], $_POST['post_id'] ); |
|
| 251 | + $message_id = $this->save_new_message_post($_POST['sender_id'], $_POST['receiver_id'], $_POST['contact_message'], $_POST['post_id']); |
|
| 252 | 252 | |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - public function message_reply_received( $comment_id = 0 ) { |
|
| 255 | + public function message_reply_received($comment_id = 0) { |
|
| 256 | 256 | |
| 257 | 257 | // Get comment object |
| 258 | - $comment = get_comment( $comment_id ); |
|
| 258 | + $comment = get_comment($comment_id); |
|
| 259 | 259 | |
| 260 | - if( is_null( $comment ) ) return; |
|
| 260 | + if (is_null($comment)) return; |
|
| 261 | 261 | |
| 262 | 262 | // Get message post object |
| 263 | - $message = get_post( $comment->comment_post_ID ); |
|
| 263 | + $message = get_post($comment->comment_post_ID); |
|
| 264 | 264 | |
| 265 | - if( $message->post_type != $this->post_type ) return; |
|
| 265 | + if ($message->post_type != $this->post_type) return; |
|
| 266 | 266 | |
| 267 | 267 | // Force comment to be approved |
| 268 | - wp_set_comment_status( $comment_id, 'approve' ); |
|
| 268 | + wp_set_comment_status($comment_id, 'approve'); |
|
| 269 | 269 | |
| 270 | - do_action( 'sensei_private_message_reply', $comment, $message ); |
|
| 270 | + do_action('sensei_private_message_reply', $comment, $message); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -280,11 +280,11 @@ discard block |
||
| 280 | 280 | * @param int $comment_id |
| 281 | 281 | * @return array; |
| 282 | 282 | */ |
| 283 | - public function stop_wp_comment_emails( $emails , $comment_id ){ |
|
| 283 | + public function stop_wp_comment_emails($emails, $comment_id) { |
|
| 284 | 284 | |
| 285 | - $comment = get_comment( $comment_id ); |
|
| 286 | - if( isset( $comment->comment_post_ID ) && |
|
| 287 | - 'sensei_message' == get_post_type( $comment->comment_post_ID ) ){ |
|
| 285 | + $comment = get_comment($comment_id); |
|
| 286 | + if (isset($comment->comment_post_ID) && |
|
| 287 | + 'sensei_message' == get_post_type($comment->comment_post_ID)) { |
|
| 288 | 288 | |
| 289 | 289 | // empty the emails array to ensure no emails are sent for this comment |
| 290 | 290 | $emails = array(); |
@@ -302,45 +302,45 @@ discard block |
||
| 302 | 302 | * @param string $post_id ID of post related to message |
| 303 | 303 | * @return mixed Message ID on success, boolean false on failure |
| 304 | 304 | */ |
| 305 | - private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { |
|
| 305 | + private function save_new_message_post($sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0) { |
|
| 306 | 306 | |
| 307 | 307 | $message_id = false; |
| 308 | 308 | |
| 309 | - if( $sender_id && $receiver_id && $message && $post_id ) { |
|
| 309 | + if ($sender_id && $receiver_id && $message && $post_id) { |
|
| 310 | 310 | |
| 311 | - $title = wp_trim_words( $message, 8, '...' ); |
|
| 311 | + $title = wp_trim_words($message, 8, '...'); |
|
| 312 | 312 | |
| 313 | 313 | // Set up post data for message |
| 314 | 314 | $message_data = array( |
| 315 | 315 | 'post_type' => $this->post_type, |
| 316 | - 'post_title' => esc_html( $title ), |
|
| 317 | - 'post_content' => esc_html( $message ), |
|
| 316 | + 'post_title' => esc_html($title), |
|
| 317 | + 'post_content' => esc_html($message), |
|
| 318 | 318 | 'post_status' => 'publish', |
| 319 | 319 | 'ping_status' => 'closed', |
| 320 | 320 | 'comment_status' => 'open', |
| 321 | 321 | 'post_excerpt' => '', |
| 322 | - 'post_author' => intval( $sender_id ) |
|
| 322 | + 'post_author' => intval($sender_id) |
|
| 323 | 323 | ); |
| 324 | 324 | |
| 325 | 325 | // Insert post |
| 326 | - $message_id = wp_insert_post( $message_data ); |
|
| 326 | + $message_id = wp_insert_post($message_data); |
|
| 327 | 327 | |
| 328 | - if( ! is_wp_error( $message_id ) ) { |
|
| 328 | + if ( ! is_wp_error($message_id)) { |
|
| 329 | 329 | |
| 330 | 330 | // Add sender to message meta |
| 331 | - $sender = get_userdata( $sender_id ); |
|
| 332 | - add_post_meta( $message_id, '_sender', $sender->user_login ); |
|
| 331 | + $sender = get_userdata($sender_id); |
|
| 332 | + add_post_meta($message_id, '_sender', $sender->user_login); |
|
| 333 | 333 | |
| 334 | 334 | // Add receiver to message meta |
| 335 | - $receiver = get_userdata( $receiver_id ); |
|
| 336 | - add_post_meta( $message_id, '_receiver', $receiver->user_login ); |
|
| 335 | + $receiver = get_userdata($receiver_id); |
|
| 336 | + add_post_meta($message_id, '_receiver', $receiver->user_login); |
|
| 337 | 337 | |
| 338 | 338 | // Add lesson/course ID to message meta |
| 339 | - $post = get_post( $post_id ); |
|
| 340 | - add_post_meta( $message_id, '_posttype', $post->post_type ); |
|
| 341 | - add_post_meta( $message_id, '_post', $post->ID ); |
|
| 339 | + $post = get_post($post_id); |
|
| 340 | + add_post_meta($message_id, '_posttype', $post->post_type); |
|
| 341 | + add_post_meta($message_id, '_post', $post->ID); |
|
| 342 | 342 | |
| 343 | - do_action( 'sensei_new_private_message', $message_id ); |
|
| 343 | + do_action('sensei_new_private_message', $message_id); |
|
| 344 | 344 | |
| 345 | 345 | } else { |
| 346 | 346 | |
@@ -358,22 +358,22 @@ discard block |
||
| 358 | 358 | * @param integer $user_id ID of user |
| 359 | 359 | * @return boolean True if user has access to this message |
| 360 | 360 | */ |
| 361 | - private function view_message( $message_id, $user_id = 0) { |
|
| 361 | + private function view_message($message_id, $user_id = 0) { |
|
| 362 | 362 | |
| 363 | - if( ! is_user_logged_in() ) return false; |
|
| 363 | + if ( ! is_user_logged_in()) return false; |
|
| 364 | 364 | |
| 365 | - if( $user_id == 0 ) { |
|
| 365 | + if ($user_id == 0) { |
|
| 366 | 366 | global $current_user; |
| 367 | 367 | wp_get_current_user(); |
| 368 | 368 | $user_login = $current_user->user_login; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | // Get allowed users |
| 372 | - $receiver = get_post_meta( $message_id, '_receiver', true ); |
|
| 373 | - $sender = get_post_meta( $message_id, '_sender', true ); |
|
| 372 | + $receiver = get_post_meta($message_id, '_receiver', true); |
|
| 373 | + $sender = get_post_meta($message_id, '_sender', true); |
|
| 374 | 374 | |
| 375 | 375 | // Check if user is allowed to view the message |
| 376 | - if( in_array( $user_login, array( $receiver, $sender ) ) ) { |
|
| 376 | + if (in_array($user_login, array($receiver, $sender))) { |
|
| 377 | 377 | return true; |
| 378 | 378 | } |
| 379 | 379 | |
@@ -400,27 +400,27 @@ discard block |
||
| 400 | 400 | * @return void |
| 401 | 401 | */ |
| 402 | 402 | |
| 403 | - public function message_login () { |
|
| 403 | + public function message_login() { |
|
| 404 | 404 | |
| 405 | - if ( is_user_logged_in() ) { |
|
| 405 | + if (is_user_logged_in()) { |
|
| 406 | 406 | |
| 407 | 407 | return; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | $settings = Sensei()->settings->get_settings(); |
| 411 | - if( isset( $settings[ 'my_course_page' ] ) |
|
| 412 | - && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 411 | + if (isset($settings['my_course_page']) |
|
| 412 | + && 0 < intval($settings['my_course_page'])) { |
|
| 413 | 413 | |
| 414 | - $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 414 | + $my_courses_page_id = $settings['my_course_page']; |
|
| 415 | 415 | |
| 416 | 416 | $my_courses_url = get_permalink($my_courses_page_id); |
| 417 | 417 | |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | - if ( is_single() && is_singular( $this->post_type ) |
|
| 421 | - || is_post_type_archive( $this->post_type ) ) { |
|
| 420 | + if (is_single() && is_singular($this->post_type) |
|
| 421 | + || is_post_type_archive($this->post_type)) { |
|
| 422 | 422 | |
| 423 | - if ( isset($my_courses_url) ) { |
|
| 423 | + if (isset($my_courses_url)) { |
|
| 424 | 424 | |
| 425 | 425 | wp_redirect($my_courses_url, 303); |
| 426 | 426 | exit; |
@@ -439,12 +439,12 @@ discard block |
||
| 439 | 439 | * @param array $query Original query |
| 440 | 440 | * @return void |
| 441 | 441 | */ |
| 442 | - public function message_list( $query ) { |
|
| 442 | + public function message_list($query) { |
|
| 443 | 443 | global $current_user; |
| 444 | 444 | |
| 445 | - if( is_admin() ) return; |
|
| 445 | + if (is_admin()) return; |
|
| 446 | 446 | |
| 447 | - if( is_post_type_archive( $this->post_type ) && $query->is_main_query() ) { |
|
| 447 | + if (is_post_type_archive($this->post_type) && $query->is_main_query()) { |
|
| 448 | 448 | wp_get_current_user(); |
| 449 | 449 | $username = $current_user->user_login; |
| 450 | 450 | |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | 'compare' => '=' |
| 463 | 463 | ); |
| 464 | 464 | |
| 465 | - $query->set( 'meta_query', $meta_query ); |
|
| 465 | + $query->set('meta_query', $meta_query); |
|
| 466 | 466 | |
| 467 | 467 | return; |
| 468 | 468 | } |
@@ -474,11 +474,11 @@ discard block |
||
| 474 | 474 | * @param integer $post_id ID of post |
| 475 | 475 | * @return string Modified string if user does not have access to this message |
| 476 | 476 | */ |
| 477 | - public function message_title( $title = '', $post_id = null ) { |
|
| 477 | + public function message_title($title = '', $post_id = null) { |
|
| 478 | 478 | |
| 479 | - if( is_single() && is_singular( $this->post_type ) && in_the_loop() && get_post_type( $post_id ) == $this->post_type ) { |
|
| 480 | - if( ! is_user_logged_in() || ! $this->view_message( $post_id ) ) { |
|
| 481 | - $title = __( 'You are not allowed to view this message.', 'woothemes-sensei' ); |
|
| 479 | + if (is_single() && is_singular($this->post_type) && in_the_loop() && get_post_type($post_id) == $this->post_type) { |
|
| 480 | + if ( ! is_user_logged_in() || ! $this->view_message($post_id)) { |
|
| 481 | + $title = __('You are not allowed to view this message.', 'woothemes-sensei'); |
|
| 482 | 482 | } |
| 483 | 483 | } |
| 484 | 484 | |
@@ -490,12 +490,12 @@ discard block |
||
| 490 | 490 | * @param string $content Original message content |
| 491 | 491 | * @return string Empty string if user does not have access to this message |
| 492 | 492 | */ |
| 493 | - public function message_content( $content ) { |
|
| 493 | + public function message_content($content) { |
|
| 494 | 494 | global $post; |
| 495 | 495 | |
| 496 | - if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) { |
|
| 497 | - if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) { |
|
| 498 | - $content = __( 'Please log in to view your messages.', 'woothemes-sensei' ); |
|
| 496 | + if (is_single() && is_singular($this->post_type) && in_the_loop()) { |
|
| 497 | + if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) { |
|
| 498 | + $content = __('Please log in to view your messages.', 'woothemes-sensei'); |
|
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | |
@@ -507,11 +507,11 @@ discard block |
||
| 507 | 507 | * @param array $comments Array of replies |
| 508 | 508 | * @return array Empty array if user does not have access to this message |
| 509 | 509 | */ |
| 510 | - public function message_replies( $comments ) { |
|
| 510 | + public function message_replies($comments) { |
|
| 511 | 511 | global $post; |
| 512 | 512 | |
| 513 | - if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) { |
|
| 514 | - if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) { |
|
| 513 | + if (is_single() && is_singular($this->post_type) && in_the_loop()) { |
|
| 514 | + if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) { |
|
| 515 | 515 | $comments = array(); |
| 516 | 516 | } |
| 517 | 517 | } |
@@ -525,11 +525,11 @@ discard block |
||
| 525 | 525 | * @param integer $post_id ID of post |
| 526 | 526 | * @return integer 0 if user does not have access to this message |
| 527 | 527 | */ |
| 528 | - public function message_reply_count( $count, $post_id ) { |
|
| 528 | + public function message_reply_count($count, $post_id) { |
|
| 529 | 529 | global $post; |
| 530 | 530 | |
| 531 | - if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) { |
|
| 532 | - if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) { |
|
| 531 | + if (is_single() && is_singular($this->post_type) && in_the_loop()) { |
|
| 532 | + if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) { |
|
| 533 | 533 | $count = 0; |
| 534 | 534 | } |
| 535 | 535 | } |
@@ -543,11 +543,11 @@ discard block |
||
| 543 | 543 | * @param integer $post_id ID of post |
| 544 | 544 | * @return boolean False if user does not have access to this message |
| 545 | 545 | */ |
| 546 | - public function message_replies_open( $open, $post_id ) { |
|
| 546 | + public function message_replies_open($open, $post_id) { |
|
| 547 | 547 | global $post; |
| 548 | 548 | |
| 549 | - if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) { |
|
| 550 | - if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) { |
|
| 549 | + if (is_single() && is_singular($this->post_type) && in_the_loop()) { |
|
| 550 | + if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) { |
|
| 551 | 551 | $open = false; |
| 552 | 552 | } |
| 553 | 553 | } |
@@ -560,17 +560,17 @@ discard block |
||
| 560 | 560 | * |
| 561 | 561 | * @since 1.9.0 |
| 562 | 562 | */ |
| 563 | - public static function the_message_sent_by_title(){ |
|
| 563 | + public static function the_message_sent_by_title() { |
|
| 564 | 564 | |
| 565 | - $sender_username = get_post_meta( get_the_ID() , '_sender', true ); |
|
| 566 | - if( $sender_username ) { |
|
| 565 | + $sender_username = get_post_meta(get_the_ID(), '_sender', true); |
|
| 566 | + if ($sender_username) { |
|
| 567 | 567 | |
| 568 | - $sender = get_user_by( 'login', $sender_username ); ?> |
|
| 568 | + $sender = get_user_by('login', $sender_username); ?> |
|
| 569 | 569 | |
| 570 | 570 | <p class="message-meta"> |
| 571 | 571 | <small> |
| 572 | 572 | <em> |
| 573 | - <?php printf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); ?> |
|
| 573 | + <?php printf(__('Sent by %1$s on %2$s.', 'woothemes-sensei'), $sender->display_name, get_the_date()); ?> |
|
| 574 | 574 | </em> |
| 575 | 575 | </small> |
| 576 | 576 | </p> |
@@ -589,11 +589,11 @@ discard block |
||
| 589 | 589 | |
| 590 | 590 | global $post; |
| 591 | 591 | |
| 592 | - $content_post_id = get_post_meta( $post->ID, '_post', true ); |
|
| 593 | - if( $content_post_id ) { |
|
| 594 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); |
|
| 592 | + $content_post_id = get_post_meta($post->ID, '_post', true); |
|
| 593 | + if ($content_post_id) { |
|
| 594 | + $title = sprintf(__('Re: %1$s', 'woothemes-sensei'), '<a href="'.get_permalink($content_post_id).'">'.get_the_title($content_post_id).'</a>'); |
|
| 595 | 595 | } else { |
| 596 | - $title = get_the_title( $post->ID ); |
|
| 596 | + $title = get_the_title($post->ID); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | ?> |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | * @param string $template |
| 611 | 611 | * @param string $post_type |
| 612 | 612 | */ |
| 613 | - echo apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 613 | + echo apply_filters('sensei_single_title', $title, $post->post_type); |
|
| 614 | 614 | ?> |
| 615 | 615 | |
| 616 | 616 | </h1> |
@@ -629,18 +629,18 @@ discard block |
||
| 629 | 629 | * |
| 630 | 630 | * @return string |
| 631 | 631 | */ |
| 632 | - public static function the_archive_header( ){ |
|
| 632 | + public static function the_archive_header( ) { |
|
| 633 | 633 | |
| 634 | 634 | $html = ''; |
| 635 | 635 | $html .= '<header class="archive-header"><h1>'; |
| 636 | - $html .= __( 'My Messages', 'woothemes-sensei' ); |
|
| 636 | + $html .= __('My Messages', 'woothemes-sensei'); |
|
| 637 | 637 | $html .= '</h1></header>'; |
| 638 | 638 | |
| 639 | 639 | /** |
| 640 | 640 | * Filter the sensei messages archive title. |
| 641 | 641 | * @since 1.0.0 |
| 642 | 642 | */ |
| 643 | - echo apply_filters( 'sensei_message_archive_title', $html ); |
|
| 643 | + echo apply_filters('sensei_message_archive_title', $html); |
|
| 644 | 644 | |
| 645 | 645 | } // get_archive_header() |
| 646 | 646 | |
@@ -650,23 +650,23 @@ discard block |
||
| 650 | 650 | * @since 1.9.0 |
| 651 | 651 | * @param $post_id |
| 652 | 652 | */ |
| 653 | - public static function the_message_title( $message_post_id ){ |
|
| 653 | + public static function the_message_title($message_post_id) { |
|
| 654 | 654 | |
| 655 | - $content_post_id = get_post_meta( $message_post_id, '_post', true ); |
|
| 655 | + $content_post_id = get_post_meta($message_post_id, '_post', true); |
|
| 656 | 656 | |
| 657 | - if( $content_post_id ) { |
|
| 657 | + if ($content_post_id) { |
|
| 658 | 658 | |
| 659 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); |
|
| 659 | + $title = sprintf(__('Re: %1$s', 'woothemes-sensei'), get_the_title($content_post_id)); |
|
| 660 | 660 | |
| 661 | 661 | } else { |
| 662 | 662 | |
| 663 | - $title = get_the_title( $message_post_id ); |
|
| 663 | + $title = get_the_title($message_post_id); |
|
| 664 | 664 | |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | ?> |
| 668 | 668 | <h2> |
| 669 | - <a href="<?php esc_url( get_permalink( $message_post_id ) );?>"> |
|
| 669 | + <a href="<?php esc_url(get_permalink($message_post_id)); ?>"> |
|
| 670 | 670 | <?php echo $title; ?> |
| 671 | 671 | </a> |
| 672 | 672 | |
@@ -680,13 +680,13 @@ discard block |
||
| 680 | 680 | * |
| 681 | 681 | * @param $message_post_id |
| 682 | 682 | */ |
| 683 | - public static function the_message_sender( $message_post_id ){ |
|
| 683 | + public static function the_message_sender($message_post_id) { |
|
| 684 | 684 | |
| 685 | - $sender_username = get_post_meta( $message_post_id, '_sender', true ); |
|
| 686 | - $sender = get_user_by( 'login', $sender_username ); |
|
| 685 | + $sender_username = get_post_meta($message_post_id, '_sender', true); |
|
| 686 | + $sender = get_user_by('login', $sender_username); |
|
| 687 | 687 | |
| 688 | - if( $sender_username && $sender instanceof WP_User ) { |
|
| 689 | - $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); |
|
| 688 | + if ($sender_username && $sender instanceof WP_User) { |
|
| 689 | + $sender_display_name = sprintf(__('Sent by %1$s on %2$s.', 'woothemes-sensei'), $sender->display_name, get_the_date()); |
|
| 690 | 690 | ?> |
| 691 | 691 | <p class="message-meta"> |
| 692 | 692 | <small> |
@@ -704,13 +704,13 @@ discard block |
||
| 704 | 704 | * |
| 705 | 705 | * @since 1.9.0 |
| 706 | 706 | */ |
| 707 | - public static function the_my_messages_link(){ |
|
| 708 | - if( ! Sensei()->settings->get('messages_disable') ) { |
|
| 707 | + public static function the_my_messages_link() { |
|
| 708 | + if ( ! Sensei()->settings->get('messages_disable')) { |
|
| 709 | 709 | ?> |
| 710 | 710 | <p class="my-messages-link-container"> |
| 711 | - <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>" |
|
| 712 | - title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>"> |
|
| 713 | - <?php _e( 'My Messages', 'woothemes-sensei' ); ?> |
|
| 711 | + <a class="my-messages-link" href="<?php echo get_post_type_archive_link('sensei_message'); ?>" |
|
| 712 | + title="<?php _e('View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei'); ?>"> |
|
| 713 | + <?php _e('My Messages', 'woothemes-sensei'); ?> |
|
| 714 | 714 | </a> |
| 715 | 715 | </p> |
| 716 | 716 | <?php |
@@ -724,4 +724,4 @@ discard block |
||
| 724 | 724 | * for backward compatibility |
| 725 | 725 | * @since 1.9.0 |
| 726 | 726 | */ |
| 727 | -class WooThemes_Sensei_Messages extends Sensei_Messages{} |
|
| 727 | +class WooThemes_Sensei_Messages extends Sensei_Messages {} |
|
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Messages Class |
@@ -73,7 +76,9 @@ discard block |
||
| 73 | 76 | |
| 74 | 77 | public function add_meta_box( $post_type, $post ) { |
| 75 | 78 | |
| 76 | - if( ! $post_type == $this->post_type ) return; |
|
| 79 | + if( ! $post_type == $this->post_type ) { |
|
| 80 | + return; |
|
| 81 | + } |
|
| 77 | 82 | |
| 78 | 83 | add_meta_box( $this->post_type . '-data', __( 'Message Information', 'woothemes-sensei' ), array( $this, 'meta_box_content' ), $this->post_type, 'normal', 'default' ); |
| 79 | 84 | |
@@ -138,7 +143,9 @@ discard block |
||
| 138 | 143 | public function save_message( $post_id = 0 ) { |
| 139 | 144 | global $post; |
| 140 | 145 | |
| 141 | - if( $this->post_type != get_post_type() ) return; |
|
| 146 | + if( $this->post_type != get_post_type() ) { |
|
| 147 | + return; |
|
| 148 | + } |
|
| 142 | 149 | |
| 143 | 150 | if( isset( $_POST['sender'] ) && $_POST['sender'] ) { |
| 144 | 151 | update_post_meta( $post_id, '_sender', $_POST['sender'] ); |
@@ -174,7 +181,9 @@ discard block |
||
| 174 | 181 | |
| 175 | 182 | if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
| 176 | 183 | |
| 177 | - if( ! is_user_logged_in() ) return; |
|
| 184 | + if( ! is_user_logged_in() ) { |
|
| 185 | + return; |
|
| 186 | + } |
|
| 178 | 187 | |
| 179 | 188 | if( isset( $_GET['contact'] ) ) { |
| 180 | 189 | $html .= $this->teacher_contact_form( $post ); |
@@ -185,7 +194,7 @@ discard block |
||
| 185 | 194 | $contact_button_text = __( 'Contact Lesson Teacher', 'woothemes-sensei' ); |
| 186 | 195 | } elseif( 'course' == $post->post_type ) { |
| 187 | 196 | $contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' ); |
| 188 | - }else{ |
|
| 197 | + } else{ |
|
| 189 | 198 | $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); |
| 190 | 199 | } |
| 191 | 200 | |
@@ -203,14 +212,18 @@ discard block |
||
| 203 | 212 | |
| 204 | 213 | public function teacher_contact_form( $post ) { |
| 205 | 214 | |
| 206 | - if( ! is_user_logged_in() ) return; |
|
| 215 | + if( ! is_user_logged_in() ) { |
|
| 216 | + return; |
|
| 217 | + } |
|
| 207 | 218 | |
| 208 | 219 | global $current_user; |
| 209 | 220 | wp_get_current_user(); |
| 210 | 221 | |
| 211 | 222 | $html = ''; |
| 212 | 223 | |
| 213 | - if( ! isset( $post->ID ) ) return $html; |
|
| 224 | + if( ! isset( $post->ID ) ) { |
|
| 225 | + return $html; |
|
| 226 | + } |
|
| 214 | 227 | |
| 215 | 228 | //confirm private message |
| 216 | 229 | $confirmation = ''; |
@@ -244,9 +257,13 @@ discard block |
||
| 244 | 257 | |
| 245 | 258 | public function save_new_message() { |
| 246 | 259 | |
| 247 | - if( ! isset( $_POST['sensei_message_teacher_nonce'] ) ) return; |
|
| 260 | + if( ! isset( $_POST['sensei_message_teacher_nonce'] ) ) { |
|
| 261 | + return; |
|
| 262 | + } |
|
| 248 | 263 | |
| 249 | - if( ! wp_verify_nonce( $_POST['sensei_message_teacher_nonce'], 'message_teacher' ) ) return; |
|
| 264 | + if( ! wp_verify_nonce( $_POST['sensei_message_teacher_nonce'], 'message_teacher' ) ) { |
|
| 265 | + return; |
|
| 266 | + } |
|
| 250 | 267 | |
| 251 | 268 | $message_id = $this->save_new_message_post( $_POST['sender_id'], $_POST['receiver_id'], $_POST['contact_message'], $_POST['post_id'] ); |
| 252 | 269 | |
@@ -257,12 +274,16 @@ discard block |
||
| 257 | 274 | // Get comment object |
| 258 | 275 | $comment = get_comment( $comment_id ); |
| 259 | 276 | |
| 260 | - if( is_null( $comment ) ) return; |
|
| 277 | + if( is_null( $comment ) ) { |
|
| 278 | + return; |
|
| 279 | + } |
|
| 261 | 280 | |
| 262 | 281 | // Get message post object |
| 263 | 282 | $message = get_post( $comment->comment_post_ID ); |
| 264 | 283 | |
| 265 | - if( $message->post_type != $this->post_type ) return; |
|
| 284 | + if( $message->post_type != $this->post_type ) { |
|
| 285 | + return; |
|
| 286 | + } |
|
| 266 | 287 | |
| 267 | 288 | // Force comment to be approved |
| 268 | 289 | wp_set_comment_status( $comment_id, 'approve' ); |
@@ -360,7 +381,9 @@ discard block |
||
| 360 | 381 | */ |
| 361 | 382 | private function view_message( $message_id, $user_id = 0) { |
| 362 | 383 | |
| 363 | - if( ! is_user_logged_in() ) return false; |
|
| 384 | + if( ! is_user_logged_in() ) { |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 364 | 387 | |
| 365 | 388 | if( $user_id == 0 ) { |
| 366 | 389 | global $current_user; |
@@ -424,9 +447,7 @@ discard block |
||
| 424 | 447 | |
| 425 | 448 | wp_redirect($my_courses_url, 303); |
| 426 | 449 | exit; |
| 427 | - } |
|
| 428 | - |
|
| 429 | - else { |
|
| 450 | + } else { |
|
| 430 | 451 | |
| 431 | 452 | wp_redirect(home_url('/wp-login.php'), 303); |
| 432 | 453 | exit; |
@@ -442,7 +463,9 @@ discard block |
||
| 442 | 463 | public function message_list( $query ) { |
| 443 | 464 | global $current_user; |
| 444 | 465 | |
| 445 | - if( is_admin() ) return; |
|
| 466 | + if( is_admin() ) { |
|
| 467 | + return; |
|
| 468 | + } |
|
| 446 | 469 | |
| 447 | 470 | if( is_post_type_archive( $this->post_type ) && $query->is_main_query() ) { |
| 448 | 471 | wp_get_current_user(); |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @since 1.6.0 |
| 23 | 23 | */ |
| 24 | 24 | public function __construct () { |
| 25 | - $this->token = 'messages'; |
|
| 25 | + $this->token = 'messages'; |
|
| 26 | 26 | $this->post_type = 'sensei_message'; |
| 27 | 27 | $this->meta_fields = array( 'sender', 'receiver' ); |
| 28 | 28 | |
@@ -37,11 +37,11 @@ discard block |
||
| 37 | 37 | // Monitor when new reply is posted |
| 38 | 38 | add_action( 'comment_post', array( $this, 'message_reply_received' ), 10, 1 ); |
| 39 | 39 | |
| 40 | - // Block WordPress from sending comment update emails for the messages post type |
|
| 41 | - add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 40 | + // Block WordPress from sending comment update emails for the messages post type |
|
| 41 | + add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 42 | 42 | |
| 43 | - // Block WordPress from sending comment moderator emails on the sensei messages post types |
|
| 44 | - add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 43 | + // Block WordPress from sending comment moderator emails on the sensei messages post types |
|
| 44 | + add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ), 20, 2 ); |
|
| 45 | 45 | |
| 46 | 46 | // Process saving of message posts |
| 47 | 47 | add_action( 'save_post', array( $this, 'save_message' ) ); |
@@ -49,20 +49,20 @@ discard block |
||
| 49 | 49 | // Add message links to courses & lessons |
| 50 | 50 | add_action( 'sensei_single_course_content_inside_before', array( $this, 'send_message_link' ), 35 ); |
| 51 | 51 | |
| 52 | - // add message link to lesson |
|
| 53 | - add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); |
|
| 52 | + // add message link to lesson |
|
| 53 | + add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); |
|
| 54 | 54 | |
| 55 | - // add message link to lesson |
|
| 56 | - add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); |
|
| 55 | + // add message link to lesson |
|
| 56 | + add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); |
|
| 57 | 57 | |
| 58 | 58 | // Hide messages and replies from users who do not have access |
| 59 | - add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); |
|
| 60 | - add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); |
|
| 61 | - add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); |
|
| 62 | - add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); |
|
| 63 | - add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); |
|
| 64 | - add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); |
|
| 65 | - add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); |
|
| 59 | + add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); |
|
| 60 | + add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); |
|
| 61 | + add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); |
|
| 62 | + add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); |
|
| 63 | + add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); |
|
| 64 | + add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); |
|
| 65 | + add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); |
|
| 66 | 66 | } // End __construct() |
| 67 | 67 | |
| 68 | 68 | public function add_menu_item() { |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | public function send_message_link( $post_id = 0, $user_id = 0 ) { |
| 164 | 164 | global $post; |
| 165 | 165 | |
| 166 | - // only show the link for the allowed post types: |
|
| 167 | - $allowed_post_types = array('lesson', 'course', 'quiz'); |
|
| 166 | + // only show the link for the allowed post types: |
|
| 167 | + $allowed_post_types = array('lesson', 'course', 'quiz'); |
|
| 168 | 168 | if ( ! in_array( get_post_type() , $allowed_post_types ) ) { |
| 169 | 169 | |
| 170 | 170 | return; |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | } elseif( 'course' == $post->post_type ) { |
| 188 | 188 | $contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' ); |
| 189 | 189 | }else{ |
| 190 | - $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); |
|
| 191 | - } |
|
| 190 | + $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | $html .= '<p><a class="button send-message-button" href="' . esc_url($href) . '#private_message">' . $contact_button_text . '</a></p>'; |
| 194 | 194 | } |
@@ -213,19 +213,19 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | if( ! isset( $post->ID ) ) return $html; |
| 215 | 215 | |
| 216 | - //confirm private message |
|
| 217 | - $confirmation = ''; |
|
| 218 | - if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { |
|
| 216 | + //confirm private message |
|
| 217 | + $confirmation = ''; |
|
| 218 | + if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { |
|
| 219 | 219 | |
| 220 | - $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); |
|
| 221 | - $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; |
|
| 220 | + $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); |
|
| 221 | + $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; |
|
| 222 | 222 | |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | 225 | $html .= '<h3 id="private_message">' . __( 'Send Private Message', 'woothemes-sensei' ) . '</h3>'; |
| 226 | - $html .= '<p>'; |
|
| 227 | - $html .= $confirmation; |
|
| 228 | - $html .= '</p>'; |
|
| 226 | + $html .= '<p>'; |
|
| 227 | + $html .= $confirmation; |
|
| 228 | + $html .= '</p>'; |
|
| 229 | 229 | $html .= '<form name="contact-teacher" action="" method="post" class="contact-teacher">'; |
| 230 | 230 | $html .= '<p class="form-row form-row-wide">'; |
| 231 | 231 | $html .= '<textarea name="contact_message" placeholder="' . __( 'Enter your private message.', 'woothemes-sensei' ) . '"></textarea>'; |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | public function message_reply_received( $comment_id = 0 ) { |
| 257 | 257 | |
| 258 | 258 | // Get comment object |
| 259 | - $comment = get_comment( $comment_id ); |
|
| 259 | + $comment = get_comment( $comment_id ); |
|
| 260 | 260 | |
| 261 | 261 | if( is_null( $comment ) ) return; |
| 262 | 262 | |
@@ -271,87 +271,87 @@ discard block |
||
| 271 | 271 | do_action( 'sensei_private_message_reply', $comment, $message ); |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * This function stops WordPress from sending the default comment update emails. |
|
| 276 | - * |
|
| 277 | - * This function is hooked into comment_notification_recipients. It will simply return |
|
| 278 | - * an empty array if the current passed in comment is on a message post type. |
|
| 279 | - * |
|
| 280 | - * @param array $emails |
|
| 281 | - * @param int $comment_id |
|
| 282 | - * @return array; |
|
| 283 | - */ |
|
| 284 | - public function stop_wp_comment_emails( $emails , $comment_id ){ |
|
| 274 | + /** |
|
| 275 | + * This function stops WordPress from sending the default comment update emails. |
|
| 276 | + * |
|
| 277 | + * This function is hooked into comment_notification_recipients. It will simply return |
|
| 278 | + * an empty array if the current passed in comment is on a message post type. |
|
| 279 | + * |
|
| 280 | + * @param array $emails |
|
| 281 | + * @param int $comment_id |
|
| 282 | + * @return array; |
|
| 283 | + */ |
|
| 284 | + public function stop_wp_comment_emails( $emails , $comment_id ){ |
|
| 285 | 285 | |
| 286 | - $comment = get_comment( $comment_id ); |
|
| 287 | - if( isset( $comment->comment_post_ID ) && |
|
| 288 | - 'sensei_message' == get_post_type( $comment->comment_post_ID ) ){ |
|
| 286 | + $comment = get_comment( $comment_id ); |
|
| 287 | + if( isset( $comment->comment_post_ID ) && |
|
| 288 | + 'sensei_message' == get_post_type( $comment->comment_post_ID ) ){ |
|
| 289 | 289 | |
| 290 | - // empty the emails array to ensure no emails are sent for this comment |
|
| 291 | - $emails = array(); |
|
| 290 | + // empty the emails array to ensure no emails are sent for this comment |
|
| 291 | + $emails = array(); |
|
| 292 | 292 | |
| 293 | - } |
|
| 294 | - return $emails; |
|
| 293 | + } |
|
| 294 | + return $emails; |
|
| 295 | 295 | |
| 296 | - }// end stop_wp_comment_emails |
|
| 296 | + }// end stop_wp_comment_emails |
|
| 297 | 297 | |
| 298 | 298 | /** |
| 299 | - * Save new message post |
|
| 300 | - * @param integer $sender_id ID of sender |
|
| 301 | - * @param integer $receiver_id ID of receiver |
|
| 302 | - * @param string $message Message content |
|
| 303 | - * @param string $post_id ID of post related to message |
|
| 304 | - * @return mixed Message ID on success, boolean false on failure |
|
| 305 | - */ |
|
| 306 | - private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { |
|
| 299 | + * Save new message post |
|
| 300 | + * @param integer $sender_id ID of sender |
|
| 301 | + * @param integer $receiver_id ID of receiver |
|
| 302 | + * @param string $message Message content |
|
| 303 | + * @param string $post_id ID of post related to message |
|
| 304 | + * @return mixed Message ID on success, boolean false on failure |
|
| 305 | + */ |
|
| 306 | + private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { |
|
| 307 | 307 | |
| 308 | - $message_id = false; |
|
| 308 | + $message_id = false; |
|
| 309 | 309 | |
| 310 | - if( $sender_id && $receiver_id && $message && $post_id ) { |
|
| 310 | + if( $sender_id && $receiver_id && $message && $post_id ) { |
|
| 311 | 311 | |
| 312 | - $title = wp_trim_words( $message, 8, '...' ); |
|
| 312 | + $title = wp_trim_words( $message, 8, '...' ); |
|
| 313 | 313 | |
| 314 | - // Set up post data for message |
|
| 315 | - $message_data = array( |
|
| 316 | - 'post_type' => $this->post_type, |
|
| 317 | - 'post_title' => esc_html( $title ), |
|
| 318 | - 'post_content' => esc_html( $message ), |
|
| 319 | - 'post_status' => 'publish', |
|
| 320 | - 'ping_status' => 'closed', |
|
| 321 | - 'comment_status' => 'open', |
|
| 322 | - 'post_excerpt' => '', |
|
| 323 | - 'post_author' => intval( $sender_id ) |
|
| 324 | - ); |
|
| 314 | + // Set up post data for message |
|
| 315 | + $message_data = array( |
|
| 316 | + 'post_type' => $this->post_type, |
|
| 317 | + 'post_title' => esc_html( $title ), |
|
| 318 | + 'post_content' => esc_html( $message ), |
|
| 319 | + 'post_status' => 'publish', |
|
| 320 | + 'ping_status' => 'closed', |
|
| 321 | + 'comment_status' => 'open', |
|
| 322 | + 'post_excerpt' => '', |
|
| 323 | + 'post_author' => intval( $sender_id ) |
|
| 324 | + ); |
|
| 325 | 325 | |
| 326 | - // Insert post |
|
| 327 | - $message_id = wp_insert_post( $message_data ); |
|
| 326 | + // Insert post |
|
| 327 | + $message_id = wp_insert_post( $message_data ); |
|
| 328 | 328 | |
| 329 | - if( ! is_wp_error( $message_id ) ) { |
|
| 329 | + if( ! is_wp_error( $message_id ) ) { |
|
| 330 | 330 | |
| 331 | - // Add sender to message meta |
|
| 332 | - $sender = get_userdata( $sender_id ); |
|
| 333 | - add_post_meta( $message_id, '_sender', $sender->user_login ); |
|
| 331 | + // Add sender to message meta |
|
| 332 | + $sender = get_userdata( $sender_id ); |
|
| 333 | + add_post_meta( $message_id, '_sender', $sender->user_login ); |
|
| 334 | 334 | |
| 335 | - // Add receiver to message meta |
|
| 336 | - $receiver = get_userdata( $receiver_id ); |
|
| 337 | - add_post_meta( $message_id, '_receiver', $receiver->user_login ); |
|
| 335 | + // Add receiver to message meta |
|
| 336 | + $receiver = get_userdata( $receiver_id ); |
|
| 337 | + add_post_meta( $message_id, '_receiver', $receiver->user_login ); |
|
| 338 | 338 | |
| 339 | - // Add lesson/course ID to message meta |
|
| 340 | - $post = get_post( $post_id ); |
|
| 341 | - add_post_meta( $message_id, '_posttype', $post->post_type ); |
|
| 342 | - add_post_meta( $message_id, '_post', $post->ID ); |
|
| 339 | + // Add lesson/course ID to message meta |
|
| 340 | + $post = get_post( $post_id ); |
|
| 341 | + add_post_meta( $message_id, '_posttype', $post->post_type ); |
|
| 342 | + add_post_meta( $message_id, '_post', $post->ID ); |
|
| 343 | 343 | |
| 344 | - do_action( 'sensei_new_private_message', $message_id ); |
|
| 344 | + do_action( 'sensei_new_private_message', $message_id ); |
|
| 345 | 345 | |
| 346 | - } else { |
|
| 346 | + } else { |
|
| 347 | 347 | |
| 348 | - $message_id = false; |
|
| 348 | + $message_id = false; |
|
| 349 | 349 | |
| 350 | - } |
|
| 351 | - } |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | - return $message_id; |
|
| 354 | - } |
|
| 353 | + return $message_id; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | /** |
| 357 | 357 | * Check if user has access to view this message |
@@ -390,56 +390,56 @@ discard block |
||
| 390 | 390 | remove_meta_box('commentstatusdiv', $this->post_type, 'normal'); |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - /** |
|
| 394 | - * Function message_login() |
|
| 395 | - * |
|
| 396 | - * Only show /messages/* to logged in users, and |
|
| 397 | - * redirect logged out users to wp-login.php |
|
| 398 | - * |
|
| 399 | - * @since 1.9.0 |
|
| 400 | - * @param none |
|
| 401 | - * @return void |
|
| 402 | - */ |
|
| 393 | + /** |
|
| 394 | + * Function message_login() |
|
| 395 | + * |
|
| 396 | + * Only show /messages/* to logged in users, and |
|
| 397 | + * redirect logged out users to wp-login.php |
|
| 398 | + * |
|
| 399 | + * @since 1.9.0 |
|
| 400 | + * @param none |
|
| 401 | + * @return void |
|
| 402 | + */ |
|
| 403 | 403 | |
| 404 | - public function message_login () { |
|
| 404 | + public function message_login () { |
|
| 405 | 405 | |
| 406 | - if ( is_user_logged_in() ) { |
|
| 406 | + if ( is_user_logged_in() ) { |
|
| 407 | 407 | |
| 408 | - return; |
|
| 409 | - } |
|
| 408 | + return; |
|
| 409 | + } |
|
| 410 | 410 | |
| 411 | - $settings = Sensei()->settings->get_settings(); |
|
| 412 | - if( isset( $settings[ 'my_course_page' ] ) |
|
| 413 | - && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 411 | + $settings = Sensei()->settings->get_settings(); |
|
| 412 | + if( isset( $settings[ 'my_course_page' ] ) |
|
| 413 | + && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 414 | 414 | |
| 415 | - $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 415 | + $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 416 | 416 | |
| 417 | - $my_courses_url = get_permalink($my_courses_page_id); |
|
| 417 | + $my_courses_url = get_permalink($my_courses_page_id); |
|
| 418 | 418 | |
| 419 | - } |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - if ( is_single() && is_singular( $this->post_type ) |
|
| 422 | - || is_post_type_archive( $this->post_type ) ) { |
|
| 421 | + if ( is_single() && is_singular( $this->post_type ) |
|
| 422 | + || is_post_type_archive( $this->post_type ) ) { |
|
| 423 | 423 | |
| 424 | - if ( isset($my_courses_url) ) { |
|
| 424 | + if ( isset($my_courses_url) ) { |
|
| 425 | 425 | |
| 426 | - wp_redirect($my_courses_url, 303); |
|
| 427 | - exit; |
|
| 428 | - } |
|
| 426 | + wp_redirect($my_courses_url, 303); |
|
| 427 | + exit; |
|
| 428 | + } |
|
| 429 | 429 | |
| 430 | - else { |
|
| 430 | + else { |
|
| 431 | 431 | |
| 432 | - wp_redirect(home_url('/wp-login.php'), 303); |
|
| 433 | - exit; |
|
| 434 | - } |
|
| 432 | + wp_redirect(home_url('/wp-login.php'), 303); |
|
| 433 | + exit; |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - } |
|
| 437 | - } |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | 438 | /** |
| 439 | - * Only show allowed messages in messages archive |
|
| 440 | - * @param array $query Original query |
|
| 441 | - * @return void |
|
| 442 | - */ |
|
| 439 | + * Only show allowed messages in messages archive |
|
| 440 | + * @param array $query Original query |
|
| 441 | + * @return void |
|
| 442 | + */ |
|
| 443 | 443 | public function message_list( $query ) { |
| 444 | 444 | global $current_user; |
| 445 | 445 | |
@@ -556,17 +556,17 @@ discard block |
||
| 556 | 556 | return $open; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - /** |
|
| 560 | - * Print outthe message was sent by $sender_username on the |
|
| 561 | - * |
|
| 562 | - * @since 1.9.0 |
|
| 563 | - */ |
|
| 564 | - public static function the_message_sent_by_title(){ |
|
| 559 | + /** |
|
| 560 | + * Print outthe message was sent by $sender_username on the |
|
| 561 | + * |
|
| 562 | + * @since 1.9.0 |
|
| 563 | + */ |
|
| 564 | + public static function the_message_sent_by_title(){ |
|
| 565 | 565 | |
| 566 | - $sender_username = get_post_meta( get_the_ID() , '_sender', true ); |
|
| 567 | - if( $sender_username ) { |
|
| 566 | + $sender_username = get_post_meta( get_the_ID() , '_sender', true ); |
|
| 567 | + if( $sender_username ) { |
|
| 568 | 568 | |
| 569 | - $sender = get_user_by( 'login', $sender_username ); ?> |
|
| 569 | + $sender = get_user_by( 'login', $sender_username ); ?> |
|
| 570 | 570 | |
| 571 | 571 | <p class="message-meta"> |
| 572 | 572 | <small> |
@@ -578,41 +578,41 @@ discard block |
||
| 578 | 578 | |
| 579 | 579 | <?php } |
| 580 | 580 | |
| 581 | - } |
|
| 581 | + } |
|
| 582 | 582 | |
| 583 | - /** |
|
| 584 | - * sensei_single_title output for single page title |
|
| 585 | - * @since 1.1.0 |
|
| 586 | - * @return void |
|
| 587 | - * @deprecate |
|
| 588 | - */ |
|
| 589 | - public static function the_title() { |
|
| 583 | + /** |
|
| 584 | + * sensei_single_title output for single page title |
|
| 585 | + * @since 1.1.0 |
|
| 586 | + * @return void |
|
| 587 | + * @deprecate |
|
| 588 | + */ |
|
| 589 | + public static function the_title() { |
|
| 590 | 590 | |
| 591 | - global $post; |
|
| 591 | + global $post; |
|
| 592 | 592 | |
| 593 | - $content_post_id = get_post_meta( $post->ID, '_post', true ); |
|
| 594 | - if( $content_post_id ) { |
|
| 595 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); |
|
| 596 | - } else { |
|
| 597 | - $title = get_the_title( $post->ID ); |
|
| 598 | - } |
|
| 593 | + $content_post_id = get_post_meta( $post->ID, '_post', true ); |
|
| 594 | + if( $content_post_id ) { |
|
| 595 | + $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); |
|
| 596 | + } else { |
|
| 597 | + $title = get_the_title( $post->ID ); |
|
| 598 | + } |
|
| 599 | 599 | |
| 600 | - ?> |
|
| 600 | + ?> |
|
| 601 | 601 | <header> |
| 602 | 602 | |
| 603 | 603 | <h1> |
| 604 | 604 | |
| 605 | 605 | <?php |
| 606 | - /** |
|
| 607 | - * Filter Sensei single title |
|
| 608 | - * |
|
| 609 | - * @since 1.8.0 |
|
| 610 | - * @param string $title |
|
| 611 | - * @param string $template |
|
| 612 | - * @param string $post_type |
|
| 613 | - */ |
|
| 614 | - echo apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 615 | - ?> |
|
| 606 | + /** |
|
| 607 | + * Filter Sensei single title |
|
| 608 | + * |
|
| 609 | + * @since 1.8.0 |
|
| 610 | + * @param string $title |
|
| 611 | + * @param string $template |
|
| 612 | + * @param string $post_type |
|
| 613 | + */ |
|
| 614 | + echo apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 615 | + ?> |
|
| 616 | 616 | |
| 617 | 617 | </h1> |
| 618 | 618 | |
@@ -620,52 +620,52 @@ discard block |
||
| 620 | 620 | |
| 621 | 621 | <?php |
| 622 | 622 | |
| 623 | - } // End sensei_single_title() |
|
| 623 | + } // End sensei_single_title() |
|
| 624 | 624 | |
| 625 | - /** |
|
| 626 | - * Generates the my messages |
|
| 627 | - * archive header. |
|
| 628 | - * |
|
| 629 | - * @since 1.9.0 |
|
| 630 | - * |
|
| 631 | - * @return string |
|
| 632 | - */ |
|
| 633 | - public static function the_archive_header( ){ |
|
| 625 | + /** |
|
| 626 | + * Generates the my messages |
|
| 627 | + * archive header. |
|
| 628 | + * |
|
| 629 | + * @since 1.9.0 |
|
| 630 | + * |
|
| 631 | + * @return string |
|
| 632 | + */ |
|
| 633 | + public static function the_archive_header( ){ |
|
| 634 | 634 | |
| 635 | - $html = ''; |
|
| 636 | - $html .= '<header class="archive-header"><h1>'; |
|
| 637 | - $html .= __( 'My Messages', 'woothemes-sensei' ); |
|
| 638 | - $html .= '</h1></header>'; |
|
| 635 | + $html = ''; |
|
| 636 | + $html .= '<header class="archive-header"><h1>'; |
|
| 637 | + $html .= __( 'My Messages', 'woothemes-sensei' ); |
|
| 638 | + $html .= '</h1></header>'; |
|
| 639 | 639 | |
| 640 | - /** |
|
| 641 | - * Filter the sensei messages archive title. |
|
| 642 | - * @since 1.0.0 |
|
| 643 | - */ |
|
| 644 | - echo apply_filters( 'sensei_message_archive_title', $html ); |
|
| 640 | + /** |
|
| 641 | + * Filter the sensei messages archive title. |
|
| 642 | + * @since 1.0.0 |
|
| 643 | + */ |
|
| 644 | + echo apply_filters( 'sensei_message_archive_title', $html ); |
|
| 645 | 645 | |
| 646 | - } // get_archive_header() |
|
| 646 | + } // get_archive_header() |
|
| 647 | 647 | |
| 648 | - /** |
|
| 649 | - * Output the title for a message given the post_id. |
|
| 650 | - * |
|
| 651 | - * @since 1.9.0 |
|
| 652 | - * @param $post_id |
|
| 653 | - */ |
|
| 654 | - public static function the_message_title( $message_post_id ){ |
|
| 648 | + /** |
|
| 649 | + * Output the title for a message given the post_id. |
|
| 650 | + * |
|
| 651 | + * @since 1.9.0 |
|
| 652 | + * @param $post_id |
|
| 653 | + */ |
|
| 654 | + public static function the_message_title( $message_post_id ){ |
|
| 655 | 655 | |
| 656 | - $content_post_id = get_post_meta( $message_post_id, '_post', true ); |
|
| 656 | + $content_post_id = get_post_meta( $message_post_id, '_post', true ); |
|
| 657 | 657 | |
| 658 | - if( $content_post_id ) { |
|
| 658 | + if( $content_post_id ) { |
|
| 659 | 659 | |
| 660 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); |
|
| 660 | + $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); |
|
| 661 | 661 | |
| 662 | - } else { |
|
| 662 | + } else { |
|
| 663 | 663 | |
| 664 | - $title = get_the_title( $message_post_id ); |
|
| 664 | + $title = get_the_title( $message_post_id ); |
|
| 665 | 665 | |
| 666 | - } |
|
| 666 | + } |
|
| 667 | 667 | |
| 668 | - ?> |
|
| 668 | + ?> |
|
| 669 | 669 | <h2> |
| 670 | 670 | <a href="<?php esc_url( get_permalink( $message_post_id ) );?>"> |
| 671 | 671 | <?php echo $title; ?> |
@@ -674,21 +674,21 @@ discard block |
||
| 674 | 674 | </h2> |
| 675 | 675 | |
| 676 | 676 | <?php |
| 677 | - } //end the_message_header |
|
| 677 | + } //end the_message_header |
|
| 678 | 678 | |
| 679 | - /** |
|
| 680 | - * Output the message sender given the post id. |
|
| 681 | - * |
|
| 682 | - * @param $message_post_id |
|
| 683 | - */ |
|
| 684 | - public static function the_message_sender( $message_post_id ){ |
|
| 679 | + /** |
|
| 680 | + * Output the message sender given the post id. |
|
| 681 | + * |
|
| 682 | + * @param $message_post_id |
|
| 683 | + */ |
|
| 684 | + public static function the_message_sender( $message_post_id ){ |
|
| 685 | 685 | |
| 686 | - $sender_username = get_post_meta( $message_post_id, '_sender', true ); |
|
| 687 | - $sender = get_user_by( 'login', $sender_username ); |
|
| 686 | + $sender_username = get_post_meta( $message_post_id, '_sender', true ); |
|
| 687 | + $sender = get_user_by( 'login', $sender_username ); |
|
| 688 | 688 | |
| 689 | - if( $sender_username && $sender instanceof WP_User ) { |
|
| 690 | - $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); |
|
| 691 | - ?> |
|
| 689 | + if( $sender_username && $sender instanceof WP_User ) { |
|
| 690 | + $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); |
|
| 691 | + ?> |
|
| 692 | 692 | <p class="message-meta"> |
| 693 | 693 | <small> |
| 694 | 694 | <em> <?php echo $sender_display_name; ?> </em> |
@@ -696,18 +696,18 @@ discard block |
||
| 696 | 696 | </p> |
| 697 | 697 | |
| 698 | 698 | <?php |
| 699 | - } // end if |
|
| 700 | - |
|
| 701 | - } // end the_message_archive_sender |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * Link to the users my messages page |
|
| 705 | - * |
|
| 706 | - * @since 1.9.0 |
|
| 707 | - */ |
|
| 708 | - public static function the_my_messages_link(){ |
|
| 709 | - if( ! Sensei()->settings->get('messages_disable') ) { |
|
| 710 | - ?> |
|
| 699 | + } // end if |
|
| 700 | + |
|
| 701 | + } // end the_message_archive_sender |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * Link to the users my messages page |
|
| 705 | + * |
|
| 706 | + * @since 1.9.0 |
|
| 707 | + */ |
|
| 708 | + public static function the_my_messages_link(){ |
|
| 709 | + if( ! Sensei()->settings->get('messages_disable') ) { |
|
| 710 | + ?> |
|
| 711 | 711 | <p class="my-messages-link-container"> |
| 712 | 712 | <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>" |
| 713 | 713 | title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>"> |
@@ -715,8 +715,8 @@ discard block |
||
| 715 | 715 | </a> |
| 716 | 716 | </p> |
| 717 | 717 | <?php |
| 718 | - } |
|
| 719 | - } |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | 720 | |
| 721 | 721 | } // End Class |
| 722 | 722 | |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | * This function simply loads the question type template |
| 403 | 403 | * |
| 404 | 404 | * @since 1.9.0 |
| 405 | - * @param $question_type |
|
| 405 | + * @param string $question_type |
|
| 406 | 406 | */ |
| 407 | 407 | public static function load_question_template( $question_type ){ |
| 408 | 408 | |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | * Get the questions media markup |
| 488 | 488 | * |
| 489 | 489 | * @since 1.9.0 |
| 490 | - * @param $question_id |
|
| 490 | + * @param string $question_id |
|
| 491 | 491 | * @return string |
| 492 | 492 | */ |
| 493 | 493 | public static function get_the_question_media( $question_id ){ |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Question Class |
@@ -211,7 +214,9 @@ discard block |
||
| 211 | 214 | |
| 212 | 215 | $lesson_id = get_post_meta( $quiz, '_quiz_lesson', true ); |
| 213 | 216 | |
| 214 | - if( ! $lesson_id ) continue; |
|
| 217 | + if( ! $lesson_id ) { |
|
| 218 | + continue; |
|
| 219 | + } |
|
| 215 | 220 | |
| 216 | 221 | $lessons[ $lesson_id ]['title'] = get_the_title( $lesson_id ); |
| 217 | 222 | $lessons[ $lesson_id ]['link'] = admin_url( 'post.php?post=' . $lesson_id . '&action=edit' ); |
@@ -880,7 +885,7 @@ discard block |
||
| 880 | 885 | |
| 881 | 886 | $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
| 882 | 887 | |
| 883 | - } else { |
|
| 888 | + } else { |
|
| 884 | 889 | |
| 885 | 890 | array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
| 886 | 891 | $merged_options = $question_data[ 'question_wrong_answers' ]; |
@@ -908,7 +913,7 @@ discard block |
||
| 908 | 913 | |
| 909 | 914 | $user_correct = true; |
| 910 | 915 | |
| 911 | - } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 916 | + } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 912 | 917 | |
| 913 | 918 | $user_correct = true; |
| 914 | 919 | |
@@ -923,7 +928,7 @@ discard block |
||
| 923 | 928 | |
| 924 | 929 | $answer_class .= ' right_answer'; |
| 925 | 930 | |
| 926 | - } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 931 | + } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 927 | 932 | |
| 928 | 933 | $answer_class .= ' right_answer'; |
| 929 | 934 | |
@@ -1006,13 +1011,13 @@ discard block |
||
| 1006 | 1011 | } |
| 1007 | 1012 | } |
| 1008 | 1013 | |
| 1009 | - }else{ |
|
| 1014 | + } else{ |
|
| 1010 | 1015 | |
| 1011 | 1016 | $answer_options_sorted = $question_answers_options; |
| 1012 | 1017 | |
| 1013 | 1018 | } |
| 1014 | 1019 | |
| 1015 | - }else{ |
|
| 1020 | + } else{ |
|
| 1016 | 1021 | |
| 1017 | 1022 | $answer_options_sorted = $question_answers_options; |
| 1018 | 1023 | |
@@ -1075,12 +1080,12 @@ discard block |
||
| 1075 | 1080 | |
| 1076 | 1081 | $right_answer = ucfirst($right_answer); |
| 1077 | 1082 | |
| 1078 | - }elseif( 'multiple-choice' == $type ) { |
|
| 1083 | + } elseif( 'multiple-choice' == $type ) { |
|
| 1079 | 1084 | |
| 1080 | 1085 | $right_answer = (array) $right_answer; |
| 1081 | 1086 | $right_answer = implode( ', ', $right_answer ); |
| 1082 | 1087 | |
| 1083 | - }elseif( 'gap-fill' == $type ) { |
|
| 1088 | + } elseif( 'gap-fill' == $type ) { |
|
| 1084 | 1089 | |
| 1085 | 1090 | $right_answer_array = explode( '||', $right_answer ); |
| 1086 | 1091 | if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
@@ -1089,7 +1094,7 @@ discard block |
||
| 1089 | 1094 | |
| 1090 | 1095 | $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
| 1091 | 1096 | |
| 1092 | - }else{ |
|
| 1097 | + } else{ |
|
| 1093 | 1098 | |
| 1094 | 1099 | // for non auto gradable question types no answer should be returned. |
| 1095 | 1100 | $right_answer = ''; |
@@ -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 Question Class |
@@ -20,34 +20,34 @@ discard block |
||
| 20 | 20 | * Constructor. |
| 21 | 21 | * @since 1.0.0 |
| 22 | 22 | */ |
| 23 | - public function __construct () { |
|
| 23 | + public function __construct() { |
|
| 24 | 24 | $this->question_types = $this->question_types(); |
| 25 | - $this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' ); |
|
| 26 | - if ( is_admin() ) { |
|
| 25 | + $this->meta_fields = array('question_right_answer', 'question_wrong_answers'); |
|
| 26 | + if (is_admin()) { |
|
| 27 | 27 | // Custom Write Panel Columns |
| 28 | - add_filter( 'manage_edit-question_columns', array( $this, 'add_column_headings' ), 10, 1 ); |
|
| 29 | - add_action( 'manage_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 ); |
|
| 30 | - add_action( 'add_meta_boxes', array( $this, 'question_edit_panel_metabox' ), 10, 2 ); |
|
| 28 | + add_filter('manage_edit-question_columns', array($this, 'add_column_headings'), 10, 1); |
|
| 29 | + add_action('manage_posts_custom_column', array($this, 'add_column_data'), 10, 2); |
|
| 30 | + add_action('add_meta_boxes', array($this, 'question_edit_panel_metabox'), 10, 2); |
|
| 31 | 31 | |
| 32 | 32 | // Quesitno list table filters |
| 33 | - add_action( 'restrict_manage_posts', array( $this, 'filter_options' ) ); |
|
| 34 | - add_filter( 'request', array( $this, 'filter_actions' ) ); |
|
| 33 | + add_action('restrict_manage_posts', array($this, 'filter_options')); |
|
| 34 | + add_filter('request', array($this, 'filter_actions')); |
|
| 35 | 35 | |
| 36 | - add_action( 'save_post', array( $this, 'save_question' ), 10, 1 ); |
|
| 36 | + add_action('save_post', array($this, 'save_question'), 10, 1); |
|
| 37 | 37 | } // End If Statement |
| 38 | 38 | } // End __construct() |
| 39 | 39 | |
| 40 | 40 | public function question_types() { |
| 41 | 41 | $types = array( |
| 42 | - 'multiple-choice' => __( 'Multiple Choice', 'woothemes-sensei' ), |
|
| 43 | - 'boolean' => __( 'True/False', 'woothemes-sensei' ), |
|
| 44 | - 'gap-fill' => __( 'Gap Fill', 'woothemes-sensei' ), |
|
| 45 | - 'single-line' => __( 'Single Line', 'woothemes-sensei' ), |
|
| 46 | - 'multi-line' => __( 'Multi Line', 'woothemes-sensei' ), |
|
| 47 | - 'file-upload' => __( 'File Upload', 'woothemes-sensei' ), |
|
| 42 | + 'multiple-choice' => __('Multiple Choice', 'woothemes-sensei'), |
|
| 43 | + 'boolean' => __('True/False', 'woothemes-sensei'), |
|
| 44 | + 'gap-fill' => __('Gap Fill', 'woothemes-sensei'), |
|
| 45 | + 'single-line' => __('Single Line', 'woothemes-sensei'), |
|
| 46 | + 'multi-line' => __('Multi Line', 'woothemes-sensei'), |
|
| 47 | + 'file-upload' => __('File Upload', 'woothemes-sensei'), |
|
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | - return apply_filters( 'sensei_question_types', $types ); |
|
| 50 | + return apply_filters('sensei_question_types', $types); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | * @param array $defaults |
| 58 | 58 | * @return array $new_columns |
| 59 | 59 | */ |
| 60 | - public function add_column_headings ( $defaults ) { |
|
| 60 | + public function add_column_headings($defaults) { |
|
| 61 | 61 | $new_columns['cb'] = '<input type="checkbox" />'; |
| 62 | - $new_columns['title'] = _x( 'Question', 'column name', 'woothemes-sensei' ); |
|
| 63 | - $new_columns['question-type'] = _x( 'Type', 'column name', 'woothemes-sensei' ); |
|
| 64 | - $new_columns['question-category'] = _x( 'Categories', 'column name', 'woothemes-sensei' ); |
|
| 65 | - if ( isset( $defaults['date'] ) ) { |
|
| 62 | + $new_columns['title'] = _x('Question', 'column name', 'woothemes-sensei'); |
|
| 63 | + $new_columns['question-type'] = _x('Type', 'column name', 'woothemes-sensei'); |
|
| 64 | + $new_columns['question-category'] = _x('Categories', 'column name', 'woothemes-sensei'); |
|
| 65 | + if (isset($defaults['date'])) { |
|
| 66 | 66 | $new_columns['date'] = $defaults['date']; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -77,27 +77,27 @@ discard block |
||
| 77 | 77 | * @param int $id |
| 78 | 78 | * @return void |
| 79 | 79 | */ |
| 80 | - public function add_column_data ( $column_name, $id ) { |
|
| 80 | + public function add_column_data($column_name, $id) { |
|
| 81 | 81 | global $wpdb, $post; |
| 82 | 82 | |
| 83 | - switch ( $column_name ) { |
|
| 83 | + switch ($column_name) { |
|
| 84 | 84 | |
| 85 | 85 | case 'id': |
| 86 | 86 | echo $id; |
| 87 | 87 | break; |
| 88 | 88 | |
| 89 | 89 | case 'question-type': |
| 90 | - $question_type = strip_tags( get_the_term_list( $id, 'question-type', '', ', ', '' ) ); |
|
| 90 | + $question_type = strip_tags(get_the_term_list($id, 'question-type', '', ', ', '')); |
|
| 91 | 91 | $output = '—'; |
| 92 | - if( isset( $this->question_types[ $question_type ] ) ) { |
|
| 93 | - $output = $this->question_types[ $question_type ]; |
|
| 92 | + if (isset($this->question_types[$question_type])) { |
|
| 93 | + $output = $this->question_types[$question_type]; |
|
| 94 | 94 | } |
| 95 | 95 | echo $output; |
| 96 | 96 | break; |
| 97 | 97 | |
| 98 | 98 | case 'question-category': |
| 99 | - $output = strip_tags( get_the_term_list( $id, 'question-category', '', ', ', '' ) ); |
|
| 100 | - if( ! $output ) { |
|
| 99 | + $output = strip_tags(get_the_term_list($id, 'question-category', '', ', ', '')); |
|
| 100 | + if ( ! $output) { |
|
| 101 | 101 | $output = '—'; |
| 102 | 102 | } |
| 103 | 103 | echo $output; |
@@ -110,49 +110,49 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | } // End add_column_data() |
| 112 | 112 | |
| 113 | - public function question_edit_panel_metabox( $post_type, $post ) { |
|
| 114 | - if( in_array( $post_type, array( 'question', 'multiple_question' ) ) ) { |
|
| 113 | + public function question_edit_panel_metabox($post_type, $post) { |
|
| 114 | + if (in_array($post_type, array('question', 'multiple_question'))) { |
|
| 115 | 115 | |
| 116 | - $metabox_title = __( 'Question', 'woothemes-sensei' ); |
|
| 116 | + $metabox_title = __('Question', 'woothemes-sensei'); |
|
| 117 | 117 | |
| 118 | - if( isset( $post->ID ) ) { |
|
| 118 | + if (isset($post->ID)) { |
|
| 119 | 119 | |
| 120 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 120 | + $question_type = Sensei()->question->get_question_type($post->ID); |
|
| 121 | 121 | |
| 122 | - if( $question_type ) { |
|
| 123 | - $type = $this->question_types[ $question_type ]; |
|
| 124 | - if( $type ) { |
|
| 122 | + if ($question_type) { |
|
| 123 | + $type = $this->question_types[$question_type]; |
|
| 124 | + if ($type) { |
|
| 125 | 125 | $metabox_title = $type; |
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | - add_meta_box( 'question-edit-panel', $metabox_title, array( $this, 'question_edit_panel' ), 'question', 'normal', 'high' ); |
|
| 130 | - add_meta_box( 'question-lessons-panel', __( 'Quizzes', 'woothemes-sensei' ), array( $this, 'question_lessons_panel' ), 'question', 'side', 'default' ); |
|
| 131 | - add_meta_box( 'multiple-question-lessons-panel', __( 'Quizzes', 'woothemes-sensei' ), array( $this, 'question_lessons_panel' ), 'multiple_question', 'side', 'default' ); |
|
| 129 | + add_meta_box('question-edit-panel', $metabox_title, array($this, 'question_edit_panel'), 'question', 'normal', 'high'); |
|
| 130 | + add_meta_box('question-lessons-panel', __('Quizzes', 'woothemes-sensei'), array($this, 'question_lessons_panel'), 'question', 'side', 'default'); |
|
| 131 | + add_meta_box('multiple-question-lessons-panel', __('Quizzes', 'woothemes-sensei'), array($this, 'question_lessons_panel'), 'multiple_question', 'side', 'default'); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | public function question_edit_panel() { |
| 136 | 136 | global $post, $pagenow; |
| 137 | 137 | |
| 138 | - add_action( 'admin_enqueue_scripts', array( Sensei()->lesson, 'enqueue_scripts' ) ); |
|
| 139 | - add_action( 'admin_enqueue_scripts', array( Sensei()->lesson, 'enqueue_styles' ) ); |
|
| 138 | + add_action('admin_enqueue_scripts', array(Sensei()->lesson, 'enqueue_scripts')); |
|
| 139 | + add_action('admin_enqueue_scripts', array(Sensei()->lesson, 'enqueue_styles')); |
|
| 140 | 140 | |
| 141 | 141 | $html = '<div id="lesson-quiz" class="single-question"><div id="add-question-main">'; |
| 142 | 142 | |
| 143 | - if( 'post-new.php' == $pagenow ) { |
|
| 143 | + if ('post-new.php' == $pagenow) { |
|
| 144 | 144 | |
| 145 | 145 | $html .= '<div id="add-question-actions">'; |
| 146 | - $html .= Sensei()->lesson->quiz_panel_add( 'question' ); |
|
| 146 | + $html .= Sensei()->lesson->quiz_panel_add('question'); |
|
| 147 | 147 | $html .= '</div>'; |
| 148 | 148 | |
| 149 | 149 | } else { |
| 150 | 150 | $question_id = $post->ID; |
| 151 | 151 | |
| 152 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 152 | + $question_type = Sensei()->question->get_question_type($post->ID); |
|
| 153 | 153 | |
| 154 | 154 | $html .= '<div id="add-question-metadata"><table class="widefat">'; |
| 155 | - $html .= Sensei()->lesson->quiz_panel_question( $question_type, 0, $question_id, 'question' ); |
|
| 155 | + $html .= Sensei()->lesson->quiz_panel_question($question_type, 0, $question_id, 'question'); |
|
| 156 | 156 | $html .= '</table></div>'; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -164,20 +164,20 @@ discard block |
||
| 164 | 164 | public function question_lessons_panel() { |
| 165 | 165 | global $post; |
| 166 | 166 | |
| 167 | - $no_lessons = sprintf( __( '%1$sThis question does not appear in any quizzes yet.%2$s', 'woothemes-sensei' ), '<em>', '</em>' ); |
|
| 167 | + $no_lessons = sprintf(__('%1$sThis question does not appear in any quizzes yet.%2$s', 'woothemes-sensei'), '<em>', '</em>'); |
|
| 168 | 168 | |
| 169 | - if( ! isset( $post->ID ) ) { |
|
| 169 | + if ( ! isset($post->ID)) { |
|
| 170 | 170 | echo $no_lessons; |
| 171 | 171 | return; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // This retrieves those quizzes the question is directly connected to. |
| 175 | - $quizzes = get_post_meta( $post->ID, '_quiz_id', false ); |
|
| 175 | + $quizzes = get_post_meta($post->ID, '_quiz_id', false); |
|
| 176 | 176 | |
| 177 | 177 | // Collate all 'multiple_question' quizzes the question is part of. |
| 178 | - $categories_of_question = wp_get_post_terms( $post->ID, 'question-category', array( 'fields' => 'ids' ) ); |
|
| 179 | - if ( ! empty( $categories_of_question ) ) { |
|
| 180 | - foreach ( $categories_of_question as $term_id ) { |
|
| 178 | + $categories_of_question = wp_get_post_terms($post->ID, 'question-category', array('fields' => 'ids')); |
|
| 179 | + if ( ! empty($categories_of_question)) { |
|
| 180 | + foreach ($categories_of_question as $term_id) { |
|
| 181 | 181 | $qargs = array( |
| 182 | 182 | 'fields' => 'ids', |
| 183 | 183 | 'post_type' => 'multiple_question', |
@@ -191,41 +191,41 @@ discard block |
||
| 191 | 191 | 'post_status' => 'any', |
| 192 | 192 | 'suppress_filters' => 0, |
| 193 | 193 | ); |
| 194 | - $cat_question_ids = get_posts( $qargs ); |
|
| 195 | - foreach( $cat_question_ids as $cat_question_id ) { |
|
| 196 | - $cat_quizzes = get_post_meta( $cat_question_id, '_quiz_id', false ); |
|
| 197 | - $quizzes = array_merge( $quizzes, $cat_quizzes ); |
|
| 194 | + $cat_question_ids = get_posts($qargs); |
|
| 195 | + foreach ($cat_question_ids as $cat_question_id) { |
|
| 196 | + $cat_quizzes = get_post_meta($cat_question_id, '_quiz_id', false); |
|
| 197 | + $quizzes = array_merge($quizzes, $cat_quizzes); |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | - $quizzes = array_unique( array_filter( $quizzes ) ); |
|
| 200 | + $quizzes = array_unique(array_filter($quizzes)); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if( 0 == count( $quizzes ) ) { |
|
| 203 | + if (0 == count($quizzes)) { |
|
| 204 | 204 | echo $no_lessons; |
| 205 | 205 | return; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | $lessons = false; |
| 209 | 209 | |
| 210 | - foreach( $quizzes as $quiz ) { |
|
| 210 | + foreach ($quizzes as $quiz) { |
|
| 211 | 211 | |
| 212 | - $lesson_id = get_post_meta( $quiz, '_quiz_lesson', true ); |
|
| 212 | + $lesson_id = get_post_meta($quiz, '_quiz_lesson', true); |
|
| 213 | 213 | |
| 214 | - if( ! $lesson_id ) continue; |
|
| 214 | + if ( ! $lesson_id) continue; |
|
| 215 | 215 | |
| 216 | - $lessons[ $lesson_id ]['title'] = get_the_title( $lesson_id ); |
|
| 217 | - $lessons[ $lesson_id ]['link'] = admin_url( 'post.php?post=' . $lesson_id . '&action=edit' ); |
|
| 216 | + $lessons[$lesson_id]['title'] = get_the_title($lesson_id); |
|
| 217 | + $lessons[$lesson_id]['link'] = admin_url('post.php?post='.$lesson_id.'&action=edit'); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if( ! $lessons ) { |
|
| 220 | + if ( ! $lessons) { |
|
| 221 | 221 | echo $no_lessons; |
| 222 | 222 | return; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | $html = '<ul>'; |
| 226 | 226 | |
| 227 | - foreach( $lessons as $id => $lesson ) { |
|
| 228 | - $html .= '<li><a href="' . esc_url( $lesson['link'] ) . '">' . esc_html( $lesson['title'] ) . '</a></li>'; |
|
| 227 | + foreach ($lessons as $id => $lesson) { |
|
| 228 | + $html .= '<li><a href="'.esc_url($lesson['link']).'">'.esc_html($lesson['title']).'</a></li>'; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | $html .= '</ul>'; |
@@ -234,30 +234,30 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - public function save_question( $post_id = 0 ) { |
|
| 237 | + public function save_question($post_id = 0) { |
|
| 238 | 238 | |
| 239 | - if( ! isset( $_POST['post_type'] |
|
| 240 | - ) || 'question' != $_POST['post_type'] ) { |
|
| 239 | + if ( ! isset($_POST['post_type'] |
|
| 240 | + ) || 'question' != $_POST['post_type']) { |
|
| 241 | 241 | return; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | //setup the data for saving |
| 247 | - $data = $_POST ; |
|
| 247 | + $data = $_POST; |
|
| 248 | 248 | $data['quiz_id'] = 0; |
| 249 | 249 | $data['question_id'] = $post_id; |
| 250 | 250 | |
| 251 | - if ( ! wp_is_post_revision( $post_id ) ){ |
|
| 251 | + if ( ! wp_is_post_revision($post_id)) { |
|
| 252 | 252 | |
| 253 | 253 | // Unhook function to prevent infinite loops |
| 254 | - remove_action( 'save_post', array( $this, 'save_question' ) ); |
|
| 254 | + remove_action('save_post', array($this, 'save_question')); |
|
| 255 | 255 | |
| 256 | 256 | // Update question data |
| 257 | - $question_id = Sensei()->lesson->lesson_save_question( $data, 'question' ); |
|
| 257 | + $question_id = Sensei()->lesson->lesson_save_question($data, 'question'); |
|
| 258 | 258 | |
| 259 | 259 | // Re-hook same function |
| 260 | - add_action( 'save_post', array( $this, 'save_question' ) ); |
|
| 260 | + add_action('save_post', array($this, 'save_question')); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | return; |
@@ -270,15 +270,15 @@ discard block |
||
| 270 | 270 | public function filter_options() { |
| 271 | 271 | global $typenow; |
| 272 | 272 | |
| 273 | - if( is_admin() && 'question' == $typenow ) { |
|
| 273 | + if (is_admin() && 'question' == $typenow) { |
|
| 274 | 274 | |
| 275 | 275 | $output = ''; |
| 276 | 276 | |
| 277 | 277 | // Question type |
| 278 | - $selected = isset( $_GET['question_type'] ) ? $_GET['question_type'] : ''; |
|
| 279 | - $type_options = '<option value="">' . __( 'All types', 'woothemes-sensei' ) . '</option>'; |
|
| 280 | - foreach( $this->question_types as $label => $type ) { |
|
| 281 | - $type_options .= '<option value="' . esc_attr( $label ) . '" ' . selected( $selected, $label, false ) . '>' . esc_html( $type ) . '</option>'; |
|
| 278 | + $selected = isset($_GET['question_type']) ? $_GET['question_type'] : ''; |
|
| 279 | + $type_options = '<option value="">'.__('All types', 'woothemes-sensei').'</option>'; |
|
| 280 | + foreach ($this->question_types as $label => $type) { |
|
| 281 | + $type_options .= '<option value="'.esc_attr($label).'" '.selected($selected, $label, false).'>'.esc_html($type).'</option>'; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | $output .= '<select name="question_type" id="dropdown_question_type">'; |
@@ -286,12 +286,12 @@ discard block |
||
| 286 | 286 | $output .= '</select>'; |
| 287 | 287 | |
| 288 | 288 | // Question category |
| 289 | - $cats = get_terms( 'question-category', array( 'hide_empty' => false ) ); |
|
| 290 | - if ( ! empty( $cats ) && ! is_wp_error( $cats ) ) { |
|
| 291 | - $selected = isset( $_GET['question_cat'] ) ? $_GET['question_cat'] : ''; |
|
| 292 | - $cat_options = '<option value="">' . __( 'All categories', 'woothemes-sensei' ) . '</option>'; |
|
| 293 | - foreach( $cats as $cat ) { |
|
| 294 | - $cat_options .= '<option value="' . esc_attr( $cat->slug ) . '" ' . selected( $selected, $cat->slug, false ) . '>' . esc_html( $cat->name ) . '</option>'; |
|
| 289 | + $cats = get_terms('question-category', array('hide_empty' => false)); |
|
| 290 | + if ( ! empty($cats) && ! is_wp_error($cats)) { |
|
| 291 | + $selected = isset($_GET['question_cat']) ? $_GET['question_cat'] : ''; |
|
| 292 | + $cat_options = '<option value="">'.__('All categories', 'woothemes-sensei').'</option>'; |
|
| 293 | + foreach ($cats as $cat) { |
|
| 294 | + $cat_options .= '<option value="'.esc_attr($cat->slug).'" '.selected($selected, $cat->slug, false).'>'.esc_html($cat->name).'</option>'; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | $output .= '<select name="question_cat" id="dropdown_question_cat">'; |
@@ -308,14 +308,14 @@ discard block |
||
| 308 | 308 | * @param array $request Current request |
| 309 | 309 | * @return array Modified request |
| 310 | 310 | */ |
| 311 | - public function filter_actions( $request ) { |
|
| 311 | + public function filter_actions($request) { |
|
| 312 | 312 | global $typenow; |
| 313 | 313 | |
| 314 | - if( is_admin() && 'question' == $typenow ) { |
|
| 314 | + if (is_admin() && 'question' == $typenow) { |
|
| 315 | 315 | |
| 316 | 316 | // Question type |
| 317 | - $question_type = isset( $_GET['question_type'] ) ? $_GET['question_type'] : ''; |
|
| 318 | - if( $question_type ) { |
|
| 317 | + $question_type = isset($_GET['question_type']) ? $_GET['question_type'] : ''; |
|
| 318 | + if ($question_type) { |
|
| 319 | 319 | $type_query = array( |
| 320 | 320 | 'taxonomy' => 'question-type', |
| 321 | 321 | 'terms' => $question_type, |
@@ -325,8 +325,8 @@ discard block |
||
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | // Question category |
| 328 | - $question_cat = isset( $_GET['question_cat'] ) ? $_GET['question_cat'] : ''; |
|
| 329 | - if( $question_cat ) { |
|
| 328 | + $question_cat = isset($_GET['question_cat']) ? $_GET['question_cat'] : ''; |
|
| 329 | + if ($question_cat) { |
|
| 330 | 330 | $cat_query = array( |
| 331 | 331 | 'taxonomy' => 'question-category', |
| 332 | 332 | 'terms' => $question_cat, |
@@ -351,16 +351,16 @@ discard block |
||
| 351 | 351 | * |
| 352 | 352 | * @return string $question_type | bool |
| 353 | 353 | */ |
| 354 | - public function get_question_type( $question_id ){ |
|
| 354 | + public function get_question_type($question_id) { |
|
| 355 | 355 | |
| 356 | - if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 357 | - || 'question' != get_post_type( $question_id ) ){ |
|
| 356 | + if (empty($question_id) || ! intval($question_id) > 0 |
|
| 357 | + || 'question' != get_post_type($question_id)) { |
|
| 358 | 358 | return false; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | $question_type = 'multiple-choice'; |
| 362 | - $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 363 | - foreach( $question_types as $type ) { |
|
| 362 | + $question_types = wp_get_post_terms($question_id, 'question-type'); |
|
| 363 | + foreach ($question_types as $type) { |
|
| 364 | 364 | $question_type = $type->slug; |
| 365 | 365 | } |
| 366 | 366 | |
@@ -377,21 +377,21 @@ discard block |
||
| 377 | 377 | * |
| 378 | 378 | * @return int $question_grade | bool |
| 379 | 379 | */ |
| 380 | - public function get_question_grade( $question_id ) { |
|
| 380 | + public function get_question_grade($question_id) { |
|
| 381 | 381 | |
| 382 | - if ( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 383 | - || 'question' != get_post_type( $question_id ) ) { |
|
| 382 | + if (empty($question_id) || ! intval($question_id) > 0 |
|
| 383 | + || 'question' != get_post_type($question_id)) { |
|
| 384 | 384 | return false; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - $question_grade_raw = get_post_meta( $question_id, '_question_grade', true ); |
|
| 387 | + $question_grade_raw = get_post_meta($question_id, '_question_grade', true); |
|
| 388 | 388 | // If not set then default to 1... |
| 389 | - if ( false === $question_grade_raw || $question_grade_raw == '' ) { |
|
| 389 | + if (false === $question_grade_raw || $question_grade_raw == '') { |
|
| 390 | 390 | $question_grade = 1; |
| 391 | 391 | } |
| 392 | 392 | // ...but allow a grade of 0 for non-marked questions |
| 393 | 393 | else { |
| 394 | - $question_grade = intval( $question_grade_raw ); |
|
| 394 | + $question_grade = intval($question_grade_raw); |
|
| 395 | 395 | } |
| 396 | 396 | return $question_grade; |
| 397 | 397 | |
@@ -404,9 +404,9 @@ discard block |
||
| 404 | 404 | * @since 1.9.0 |
| 405 | 405 | * @param $question_type |
| 406 | 406 | */ |
| 407 | - public static function load_question_template( $question_type ){ |
|
| 407 | + public static function load_question_template($question_type) { |
|
| 408 | 408 | |
| 409 | - Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 409 | + Sensei_Templates::get_template('single-quiz/question_type-'.$question_type.'.php'); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -417,9 +417,9 @@ discard block |
||
| 417 | 417 | * @since 1.9.0 |
| 418 | 418 | * @param $question_id |
| 419 | 419 | */ |
| 420 | - public static function the_question_title( $question_id ){ |
|
| 420 | + public static function the_question_title($question_id) { |
|
| 421 | 421 | |
| 422 | - echo self::get_the_question_title( $question_id ); |
|
| 422 | + echo self::get_the_question_title($question_id); |
|
| 423 | 423 | |
| 424 | 424 | }// end the_question_title |
| 425 | 425 | |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | * @param $question_id |
| 432 | 432 | * @return string |
| 433 | 433 | */ |
| 434 | - public static function get_the_question_title( $question_id ){ |
|
| 434 | + public static function get_the_question_title($question_id) { |
|
| 435 | 435 | |
| 436 | 436 | /** |
| 437 | 437 | * Filter the sensei question title |
@@ -439,17 +439,17 @@ discard block |
||
| 439 | 439 | * @since 1.3.0 |
| 440 | 440 | * @param $question_title |
| 441 | 441 | */ |
| 442 | - $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 442 | + $title = apply_filters('sensei_question_title', get_the_title($question_id)); |
|
| 443 | 443 | |
| 444 | 444 | /** |
| 445 | 445 | * hook document in class-woothemes-sensei-message.php the_title() |
| 446 | 446 | */ |
| 447 | - $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 447 | + $title = apply_filters('sensei_single_title', $title, 'question'); |
|
| 448 | 448 | |
| 449 | 449 | $title_html = '<span class="question question-title">'; |
| 450 | 450 | $title_html .= $title; |
| 451 | 451 | $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
| 452 | - $title_html .='</span>'; |
|
| 452 | + $title_html .= '</span>'; |
|
| 453 | 453 | |
| 454 | 454 | return $title_html; |
| 455 | 455 | } |
@@ -460,14 +460,14 @@ discard block |
||
| 460 | 460 | * @param $question_id |
| 461 | 461 | * @return string |
| 462 | 462 | */ |
| 463 | - public static function get_the_question_description( $question_id ){ |
|
| 463 | + public static function get_the_question_description($question_id) { |
|
| 464 | 464 | |
| 465 | - $question = get_post( $question_id ); |
|
| 465 | + $question = get_post($question_id); |
|
| 466 | 466 | |
| 467 | 467 | /** |
| 468 | 468 | * Already documented within WordPress Core |
| 469 | 469 | */ |
| 470 | - return apply_filters( 'the_content', $question->post_content ); |
|
| 470 | + return apply_filters('the_content', $question->post_content); |
|
| 471 | 471 | |
| 472 | 472 | } |
| 473 | 473 | |
@@ -477,9 +477,9 @@ discard block |
||
| 477 | 477 | * @since 1.9.0 |
| 478 | 478 | * @param $question_id |
| 479 | 479 | */ |
| 480 | - public static function the_question_description( $question_id ){ |
|
| 480 | + public static function the_question_description($question_id) { |
|
| 481 | 481 | |
| 482 | - echo self::get_the_question_description( $question_id ); |
|
| 482 | + echo self::get_the_question_description($question_id); |
|
| 483 | 483 | |
| 484 | 484 | } |
| 485 | 485 | |
@@ -490,38 +490,38 @@ discard block |
||
| 490 | 490 | * @param $question_id |
| 491 | 491 | * @return string |
| 492 | 492 | */ |
| 493 | - public static function get_the_question_media( $question_id ){ |
|
| 493 | + public static function get_the_question_media($question_id) { |
|
| 494 | 494 | |
| 495 | - $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 495 | + $question_media = get_post_meta($question_id, '_question_media', true); |
|
| 496 | 496 | $question_media_link = ''; |
| 497 | - if( 0 < intval( $question_media ) ) { |
|
| 498 | - $mimetype = get_post_mime_type( $question_media ); |
|
| 499 | - if( $mimetype ) { |
|
| 500 | - $mimetype_array = explode( '/', $mimetype); |
|
| 501 | - if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
| 497 | + if (0 < intval($question_media)) { |
|
| 498 | + $mimetype = get_post_mime_type($question_media); |
|
| 499 | + if ($mimetype) { |
|
| 500 | + $mimetype_array = explode('/', $mimetype); |
|
| 501 | + if (isset($mimetype_array[0]) && $mimetype_array[0]) { |
|
| 502 | 502 | $question_media_type = $mimetype_array[0]; |
| 503 | - $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 504 | - $attachment = get_post( $question_media ); |
|
| 503 | + $question_media_url = wp_get_attachment_url($question_media); |
|
| 504 | + $attachment = get_post($question_media); |
|
| 505 | 505 | $question_media_title = $attachment->post_title; |
| 506 | 506 | $question_media_description = $attachment->post_content; |
| 507 | - switch( $question_media_type ) { |
|
| 507 | + switch ($question_media_type) { |
|
| 508 | 508 | case 'image': |
| 509 | - $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
| 510 | - $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
| 511 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
| 509 | + $image_size = apply_filters('sensei_question_image_size', 'medium', $question_id); |
|
| 510 | + $attachment_src = wp_get_attachment_image_src($question_media, $image_size); |
|
| 511 | + $question_media_link = '<a class="'.esc_attr($question_media_type).'" title="'.esc_attr($question_media_title).'" href="'.esc_url($question_media_url).'" target="_blank"><img src="'.$attachment_src[0].'" width="'.$attachment_src[1].'" height="'.$attachment_src[2].'" /></a>'; |
|
| 512 | 512 | break; |
| 513 | 513 | |
| 514 | 514 | case 'audio': |
| 515 | - $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 515 | + $question_media_link = wp_audio_shortcode(array('src' => $question_media_url)); |
|
| 516 | 516 | break; |
| 517 | 517 | |
| 518 | 518 | case 'video': |
| 519 | - $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 519 | + $question_media_link = wp_video_shortcode(array('src' => $question_media_url)); |
|
| 520 | 520 | break; |
| 521 | 521 | |
| 522 | 522 | default: |
| 523 | - $question_media_filename = basename( $question_media_url ); |
|
| 524 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
| 523 | + $question_media_filename = basename($question_media_url); |
|
| 524 | + $question_media_link = '<a class="'.esc_attr($question_media_type).'" title="'.esc_attr($question_media_title).'" href="'.esc_url($question_media_url).'" target="_blank">'.$question_media_filename.'</a>'; |
|
| 525 | 525 | break; |
| 526 | 526 | } |
| 527 | 527 | } |
@@ -529,21 +529,21 @@ discard block |
||
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | $output = ''; |
| 532 | - if( $question_media_link ) { |
|
| 532 | + if ($question_media_link) { |
|
| 533 | 533 | |
| 534 | 534 | $output .= '<div class="question_media_display">'; |
| 535 | - $output .= $question_media_link; |
|
| 535 | + $output .= $question_media_link; |
|
| 536 | 536 | $output .= '<dl>'; |
| 537 | 537 | |
| 538 | - if( $question_media_title ) { |
|
| 538 | + if ($question_media_title) { |
|
| 539 | 539 | |
| 540 | - $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 540 | + $output .= '<dt>'.$question_media_title.'</dt>'; |
|
| 541 | 541 | |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - if( $question_media_description ) { |
|
| 544 | + if ($question_media_description) { |
|
| 545 | 545 | |
| 546 | - $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 546 | + $output .= '<dd>'.$question_media_description.'</dd>'; |
|
| 547 | 547 | |
| 548 | 548 | } |
| 549 | 549 | |
@@ -564,9 +564,9 @@ discard block |
||
| 564 | 564 | * @since 1.9.0 |
| 565 | 565 | * @param string $question_id |
| 566 | 566 | */ |
| 567 | - public static function the_question_media( $question_id ){ |
|
| 567 | + public static function the_question_media($question_id) { |
|
| 568 | 568 | |
| 569 | - echo self::get_the_question_media( $question_id ); |
|
| 569 | + echo self::get_the_question_media($question_id); |
|
| 570 | 570 | |
| 571 | 571 | } |
| 572 | 572 | |
@@ -577,11 +577,11 @@ discard block |
||
| 577 | 577 | * |
| 578 | 578 | * @param $question_id |
| 579 | 579 | */ |
| 580 | - public static function the_question_hidden_fields( $question_id ){ |
|
| 580 | + public static function the_question_hidden_fields($question_id) { |
|
| 581 | 581 | ?> |
| 582 | 582 | |
| 583 | - <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" /> |
|
| 584 | - <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" /> |
|
| 583 | + <input type="hidden" name="question_id_<?php $question_id; ?>" value="<?php $question_id; ?>" /> |
|
| 584 | + <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e($question_id); ?>" /> |
|
| 585 | 585 | |
| 586 | 586 | <?php |
| 587 | 587 | } |
@@ -592,27 +592,27 @@ discard block |
||
| 592 | 592 | * @since 1.9.0 |
| 593 | 593 | * @param $question_id |
| 594 | 594 | */ |
| 595 | - public static function answer_feedback_notes( $question_id ){ |
|
| 595 | + public static function answer_feedback_notes($question_id) { |
|
| 596 | 596 | |
| 597 | 597 | //IDS |
| 598 | 598 | $quiz_id = get_the_ID(); |
| 599 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 599 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 600 | 600 | |
| 601 | 601 | // Data to check before showing feedback |
| 602 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
| 603 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 604 | - $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
| 605 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 606 | - $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
| 607 | - $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 602 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, get_current_user_id()); |
|
| 603 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade($lesson_id, get_current_user_id()); |
|
| 604 | + $not_empty_user_quiz_grade = ! empty($user_quiz_grade); |
|
| 605 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed($lesson_id); |
|
| 606 | + $lesson_completed = Sensei_Utils::user_completed_lesson($lesson_id); |
|
| 607 | + $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
| 608 | 608 | |
| 609 | - if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
| 610 | - || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
| 611 | - || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
| 609 | + if (($lesson_completed && $not_empty_user_quiz_grade) |
|
| 610 | + || ($lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type) |
|
| 611 | + || ('auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade)) { |
|
| 612 | 612 | |
| 613 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
| 613 | + $answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, get_current_user_id()); |
|
| 614 | 614 | |
| 615 | - if( $answer_notes ) { ?> |
|
| 615 | + if ($answer_notes) { ?> |
|
| 616 | 616 | |
| 617 | 617 | <div class="sensei-message info info-special answer-feedback"> |
| 618 | 618 | |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | * @param string $question_id |
| 627 | 627 | * @param string $lesson_id |
| 628 | 628 | */ |
| 629 | - echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 629 | + echo apply_filters('sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id); |
|
| 630 | 630 | |
| 631 | 631 | ?> |
| 632 | 632 | |
@@ -645,72 +645,72 @@ discard block |
||
| 645 | 645 | * @since 1.9.0 |
| 646 | 646 | * @param string $question_id |
| 647 | 647 | */ |
| 648 | - public static function the_answer_result_indication( $question_id ){ |
|
| 648 | + public static function the_answer_result_indication($question_id) { |
|
| 649 | 649 | |
| 650 | - global $post, $current_user, $sensei_question_loop; |
|
| 650 | + global $post, $current_user, $sensei_question_loop; |
|
| 651 | 651 | |
| 652 | 652 | // Post Data |
| 653 | 653 | $quiz_id = $sensei_question_loop['quiz_id']; |
| 654 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 654 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 655 | 655 | $question_item = $sensei_question_loop['current_question']; |
| 656 | 656 | |
| 657 | 657 | // Setup variable needed to determine if the message should show and what it should show |
| 658 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 659 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 660 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 661 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 658 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade($lesson_id, get_current_user_id()); |
|
| 659 | + $lesson_complete = Sensei_Utils::user_completed_lesson($lesson_id, get_current_user_id()); |
|
| 660 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed($lesson_id); |
|
| 661 | + $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
| 662 | 662 | |
| 663 | 663 | // retrieve the question total grade |
| 664 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 664 | + $question_grade = Sensei()->question->get_question_grade($question_id); |
|
| 665 | 665 | |
| 666 | 666 | // retrieve grade the user achieved |
| 667 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 667 | + $user_question_grade = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, get_current_user_id()); |
|
| 668 | 668 | |
| 669 | 669 | // Question ID |
| 670 | 670 | $question_id = $question_item->ID; |
| 671 | 671 | |
| 672 | 672 | // conditions to check |
| 673 | - $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
| 674 | - $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
| 675 | - $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
| 673 | + $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != ''; |
|
| 674 | + $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed; |
|
| 675 | + $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != ''; |
|
| 676 | 676 | |
| 677 | - if ( $completed_with_valid_grade |
|
| 677 | + if ($completed_with_valid_grade |
|
| 678 | 678 | || $completed_with_valid_grade_and_reset_not_allowed |
| 679 | - || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 679 | + || $grade_type_auto_a_valid_grade_and_reset_not_allowed) { |
|
| 680 | 680 | |
| 681 | 681 | $user_correct = false; |
| 682 | - $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 682 | + $answer_message = __('Incorrect', 'woothemes-sensei'); |
|
| 683 | 683 | $answer_message_class = 'user_wrong'; |
| 684 | 684 | // For zero grade mark as 'correct' but add no classes |
| 685 | - if ( 0 == $question_grade ) { |
|
| 685 | + if (0 == $question_grade) { |
|
| 686 | 686 | |
| 687 | 687 | $user_correct = true; |
| 688 | 688 | $answer_message = ''; |
| 689 | 689 | $answer_message_class = ''; |
| 690 | 690 | |
| 691 | - } else if( $user_question_grade > 0 ) { |
|
| 691 | + } else if ($user_question_grade > 0) { |
|
| 692 | 692 | |
| 693 | 693 | $user_correct = true; |
| 694 | - $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 694 | + $answer_message = sprintf(__('Grade: %d', 'woothemes-sensei'), $user_question_grade); |
|
| 695 | 695 | $answer_message_class = 'user_right'; |
| 696 | 696 | |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | // attach the correct answer if the question is auto gradable and user got it wrong |
| 700 | - if( !$reset_quiz_allowed && !$user_correct ){ |
|
| 700 | + if ( ! $reset_quiz_allowed && ! $user_correct) { |
|
| 701 | 701 | |
| 702 | - $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
| 702 | + $answer_message .= ' - '.__('Right Answer:', 'woothemes-sensei').' '.self::get_correct_answer($question_item->ID); |
|
| 703 | 703 | |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | // answer feedback |
| 707 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 708 | - if( $answer_notes ) { |
|
| 707 | + $answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, $current_user->ID); |
|
| 708 | + if ($answer_notes) { |
|
| 709 | 709 | $answer_message_class .= ' has_notes'; |
| 710 | 710 | } |
| 711 | 711 | ?> |
| 712 | 712 | |
| 713 | - <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>"> |
|
| 713 | + <div class="answer_message <?php esc_attr_e($answer_message_class); ?>"> |
|
| 714 | 714 | |
| 715 | 715 | <span><?php echo $answer_message; ?></span> |
| 716 | 716 | |
@@ -731,39 +731,39 @@ discard block |
||
| 731 | 731 | * @param $quiz_id |
| 732 | 732 | * @return array $question_data |
| 733 | 733 | */ |
| 734 | - public static function get_template_data( $question_id, $quiz_id ){ |
|
| 734 | + public static function get_template_data($question_id, $quiz_id) { |
|
| 735 | 735 | |
| 736 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 736 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 737 | 737 | |
| 738 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 738 | + $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true); |
|
| 739 | 739 | //backwards compatibility |
| 740 | - if( 'on' == $reset_allowed ) { |
|
| 740 | + if ('on' == $reset_allowed) { |
|
| 741 | 741 | $reset_allowed = 1; |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | // Check again that the lesson is complete |
| 745 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
| 745 | + $user_lesson_end = Sensei_Utils::user_completed_lesson(Sensei()->quiz->get_lesson_id($quiz_id), get_current_user_id()); |
|
| 746 | 746 | $user_lesson_complete = false; |
| 747 | - if ( $user_lesson_end ) { |
|
| 747 | + if ($user_lesson_end) { |
|
| 748 | 748 | $user_lesson_complete = true; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | //setup the question data |
| 752 | - $data[ 'ID' ] = $question_id; |
|
| 753 | - $data[ 'title' ] = get_the_title( $question_id ); |
|
| 754 | - $data[ 'content' ] = get_post( $question_id )->post_content; |
|
| 755 | - $data[ 'quiz_id' ] = $quiz_id; |
|
| 756 | - $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 757 | - $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
| 758 | - $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
| 759 | - $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
| 760 | - $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
| 761 | - $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
| 762 | - $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
| 763 | - $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
| 764 | - $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 765 | - $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
| 766 | - $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
| 752 | + $data['ID'] = $question_id; |
|
| 753 | + $data['title'] = get_the_title($question_id); |
|
| 754 | + $data['content'] = get_post($question_id)->post_content; |
|
| 755 | + $data['quiz_id'] = $quiz_id; |
|
| 756 | + $data['lesson_id'] = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 757 | + $data['type'] = Sensei()->question->get_question_type($question_id); |
|
| 758 | + $data['question_grade'] = Sensei()->question->get_question_grade($question_id); |
|
| 759 | + $data['user_question_grade'] = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, get_current_user_id()); |
|
| 760 | + $data['question_right_answer'] = get_post_meta($question_id, '_question_right_answer', true); |
|
| 761 | + $data['question_wrong_answers'] = get_post_meta($question_id, '_question_wrong_answers', true); |
|
| 762 | + $data['user_answer_entry'] = Sensei()->quiz->get_user_question_answer($lesson_id, $question_id, get_current_user_id()); |
|
| 763 | + $data['lesson_completed'] = Sensei_Utils::user_completed_course($lesson_id, get_current_user_id( )); |
|
| 764 | + $data['quiz_grade_type'] = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
| 765 | + $data['reset_quiz_allowed'] = $reset_allowed; |
|
| 766 | + $data['lesson_complete'] = $user_lesson_complete; |
|
| 767 | 767 | |
| 768 | 768 | /** |
| 769 | 769 | * Filter the question template data. This filter fires in |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | * @param string $question_id |
| 778 | 778 | * @param string $quiz_id |
| 779 | 779 | */ |
| 780 | - return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 780 | + return apply_filters('sensei_get_question_template_data', $data, $question_id, $quiz_id); |
|
| 781 | 781 | |
| 782 | 782 | } |
| 783 | 783 | |
@@ -793,28 +793,28 @@ discard block |
||
| 793 | 793 | * |
| 794 | 794 | * @return array() |
| 795 | 795 | */ |
| 796 | - public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 796 | + public static function file_upload_load_question_data($question_data, $question_id, $quiz_id) { |
|
| 797 | 797 | |
| 798 | 798 | |
| 799 | - if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 799 | + if ('file-upload' == Sensei()->question->get_question_type($question_id)) { |
|
| 800 | 800 | |
| 801 | 801 | // Get uploaded file |
| 802 | - $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 802 | + $attachment_id = $question_data['user_answer_entry']; |
|
| 803 | 803 | $answer_media_url = $answer_media_filename = ''; |
| 804 | 804 | |
| 805 | 805 | |
| 806 | 806 | $question_helptext = ''; |
| 807 | - if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 807 | + if (isset($question_data['question_wrong_answers'][0])) { |
|
| 808 | 808 | |
| 809 | - $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 809 | + $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 810 | 810 | |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | |
| 814 | - if( 0 < intval( $attachment_id ) ) { |
|
| 814 | + if (0 < intval($attachment_id)) { |
|
| 815 | 815 | |
| 816 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 817 | - $answer_media_filename = basename( $answer_media_url ); |
|
| 816 | + $answer_media_url = wp_get_attachment_url($attachment_id); |
|
| 817 | + $answer_media_filename = basename($answer_media_url); |
|
| 818 | 818 | |
| 819 | 819 | } |
| 820 | 820 | |
@@ -822,11 +822,11 @@ discard block |
||
| 822 | 822 | // Get max upload file size, formatted for display |
| 823 | 823 | // Code copied from wp-admin/includes/media.php:1515 |
| 824 | 824 | $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
| 825 | - $sizes = array( 'KB', 'MB', 'GB' ); |
|
| 826 | - for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
| 825 | + $sizes = array('KB', 'MB', 'GB'); |
|
| 826 | + for ($u = -1; $upload_size_unit > 1024 && $u < count($sizes) - 1; $u++) { |
|
| 827 | 827 | $upload_size_unit /= 1024; |
| 828 | 828 | } |
| 829 | - if ( $u < 0 ) { |
|
| 829 | + if ($u < 0) { |
|
| 830 | 830 | |
| 831 | 831 | $upload_size_unit = 0; |
| 832 | 832 | $u = 0; |
@@ -836,14 +836,14 @@ discard block |
||
| 836 | 836 | $upload_size_unit = (int) $upload_size_unit; |
| 837 | 837 | |
| 838 | 838 | } |
| 839 | - $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 839 | + $max_upload_size = sprintf(__('Maximum upload file size: %d%s'), esc_html($upload_size_unit), esc_html($sizes[$u])); |
|
| 840 | 840 | |
| 841 | 841 | // Assemble all the data needed by the file upload template |
| 842 | - $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
| 843 | - $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
| 844 | - $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
| 842 | + $question_data['answer_media_url'] = $answer_media_url; |
|
| 843 | + $question_data['answer_media_filename'] = $answer_media_filename; |
|
| 844 | + $question_data['max_upload_size'] = $max_upload_size; |
|
| 845 | 845 | |
| 846 | - $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 846 | + $question_data['question_helptext'] = $question_helptext; |
|
| 847 | 847 | |
| 848 | 848 | }// end if is file upload type |
| 849 | 849 | |
@@ -863,27 +863,27 @@ discard block |
||
| 863 | 863 | * |
| 864 | 864 | * @return array() |
| 865 | 865 | */ |
| 866 | - public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 866 | + public static function multiple_choice_load_question_data($question_data, $question_id, $quiz_id) { |
|
| 867 | 867 | |
| 868 | - if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 868 | + if ('multiple-choice' == Sensei()->question->get_question_type($question_id)) { |
|
| 869 | 869 | |
| 870 | 870 | |
| 871 | 871 | $answer_type = 'radio'; |
| 872 | - if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 872 | + if (is_array($question_data['question_right_answer']) && (1 < count($question_data['question_right_answer']))) { |
|
| 873 | 873 | |
| 874 | 874 | $answer_type = 'checkbox'; |
| 875 | 875 | |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | // Merge right and wrong answers |
| 879 | - if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 879 | + if (is_array($question_data['question_right_answer'])) { |
|
| 880 | 880 | |
| 881 | - $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 881 | + $merged_options = array_merge($question_data['question_wrong_answers'], $question_data['question_right_answer']); |
|
| 882 | 882 | |
| 883 | - } else { |
|
| 883 | + } else { |
|
| 884 | 884 | |
| 885 | - array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 886 | - $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 885 | + array_push($question_data['question_wrong_answers'], $question_data['question_right_answer']); |
|
| 886 | + $merged_options = $question_data['question_wrong_answers']; |
|
| 887 | 887 | |
| 888 | 888 | } |
| 889 | 889 | |
@@ -891,24 +891,24 @@ discard block |
||
| 891 | 891 | $question_answers_options = array(); |
| 892 | 892 | $count = 0; |
| 893 | 893 | |
| 894 | - foreach( $merged_options as $answer ) { |
|
| 894 | + foreach ($merged_options as $answer) { |
|
| 895 | 895 | |
| 896 | 896 | $count++; |
| 897 | 897 | $question_option = array(); |
| 898 | 898 | |
| 899 | - if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 900 | - || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 901 | - || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
| 899 | + if (($question_data['lesson_completed'] && $question_data['user_quiz_grade'] != '') |
|
| 900 | + || ($question_data['lesson_completed'] && ! $question_data['reset_quiz_allowed'] && $question_data['user_quiz_grade'] != '') |
|
| 901 | + || ('auto' == $question_data['quiz_grade_type'] && ! $question_data['reset_quiz_allowed'] && ! empty($question_data['user_quiz_grade']))) { |
|
| 902 | 902 | |
| 903 | 903 | $user_correct = false; |
| 904 | 904 | |
| 905 | 905 | |
| 906 | 906 | // For zero grade mark as 'correct' but add no classes |
| 907 | - if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 907 | + if (0 == $question_data['question_grade']) { |
|
| 908 | 908 | |
| 909 | 909 | $user_correct = true; |
| 910 | 910 | |
| 911 | - } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 911 | + } else if ($question_data['user_question_grade'] > 0) { |
|
| 912 | 912 | |
| 913 | 913 | $user_correct = true; |
| 914 | 914 | |
@@ -918,20 +918,20 @@ discard block |
||
| 918 | 918 | |
| 919 | 919 | // setup the option specific classes |
| 920 | 920 | $answer_class = ''; |
| 921 | - if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
| 922 | - if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
| 921 | + if (isset($user_correct) && 0 < $question_data['question_grade']) { |
|
| 922 | + if (is_array($question_data['question_right_answer']) && in_array($answer, $question_data['question_right_answer'])) { |
|
| 923 | 923 | |
| 924 | 924 | $answer_class .= ' right_answer'; |
| 925 | 925 | |
| 926 | - } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 926 | + } elseif ( ! is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer) { |
|
| 927 | 927 | |
| 928 | 928 | $answer_class .= ' right_answer'; |
| 929 | 929 | |
| 930 | - } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
| 931 | - || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
| 930 | + } elseif ((is_array($question_data['user_answer_entry']) && in_array($answer, $question_data['user_answer_entry'])) |
|
| 931 | + || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer)) { |
|
| 932 | 932 | |
| 933 | 933 | $answer_class = 'user_wrong'; |
| 934 | - if( $user_correct ) { |
|
| 934 | + if ($user_correct) { |
|
| 935 | 935 | |
| 936 | 936 | $answer_class = 'user_right'; |
| 937 | 937 | |
@@ -943,26 +943,26 @@ discard block |
||
| 943 | 943 | |
| 944 | 944 | // determine if the current option must be checked |
| 945 | 945 | $checked = ''; |
| 946 | - if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
| 947 | - if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
| 946 | + if (isset($question_data['user_answer_entry']) && 0 < count($question_data['user_answer_entry'])) { |
|
| 947 | + if (is_array($question_data['user_answer_entry']) && in_array($answer, $question_data['user_answer_entry'])) { |
|
| 948 | 948 | |
| 949 | 949 | $checked = 'checked="checked"'; |
| 950 | 950 | |
| 951 | - } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 951 | + } elseif ( ! is_array($question_data['user_answer_entry'])) { |
|
| 952 | 952 | |
| 953 | - $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 953 | + $checked = checked($answer, $question_data['user_answer_entry'], false); |
|
| 954 | 954 | |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | 957 | } // End If Statement |
| 958 | 958 | |
| 959 | 959 | //Load the answer option data |
| 960 | - $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
| 961 | - $question_option[ 'answer' ] = $answer; |
|
| 962 | - $question_option[ 'option_class'] = $answer_class; |
|
| 963 | - $question_option[ 'checked'] = $checked; |
|
| 964 | - $question_option[ 'count' ] = $count; |
|
| 965 | - $question_option[ 'type' ] = $answer_type; |
|
| 960 | + $question_option['ID'] = Sensei()->lesson->get_answer_id($answer); |
|
| 961 | + $question_option['answer'] = $answer; |
|
| 962 | + $question_option['option_class'] = $answer_class; |
|
| 963 | + $question_option['checked'] = $checked; |
|
| 964 | + $question_option['count'] = $count; |
|
| 965 | + $question_option['type'] = $answer_type; |
|
| 966 | 966 | |
| 967 | 967 | // add the speci fic option to the list of options for this question |
| 968 | 968 | $question_answers_options[] = $question_option; |
@@ -972,47 +972,47 @@ discard block |
||
| 972 | 972 | |
| 973 | 973 | // Shuffle the array depending on the settings |
| 974 | 974 | $answer_options_sorted = array(); |
| 975 | - $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 976 | - if( $random_order && $random_order == 'yes' ) { |
|
| 975 | + $random_order = get_post_meta($question_data['ID'], '_random_order', true); |
|
| 976 | + if ($random_order && $random_order == 'yes') { |
|
| 977 | 977 | |
| 978 | 978 | $answer_options_sorted = $question_answers_options; |
| 979 | - shuffle( $answer_options_sorted ); |
|
| 979 | + shuffle($answer_options_sorted); |
|
| 980 | 980 | |
| 981 | 981 | } else { |
| 982 | 982 | |
| 983 | 983 | $answer_order = array(); |
| 984 | - $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 985 | - if( $answer_order_string ) { |
|
| 984 | + $answer_order_string = get_post_meta($question_data['ID'], '_answer_order', true); |
|
| 985 | + if ($answer_order_string) { |
|
| 986 | 986 | |
| 987 | - $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 988 | - if( count( $answer_order ) > 0 ) { |
|
| 987 | + $answer_order = array_filter(explode(',', $answer_order_string)); |
|
| 988 | + if (count($answer_order) > 0) { |
|
| 989 | 989 | |
| 990 | - foreach( $answer_order as $answer_id ) { |
|
| 990 | + foreach ($answer_order as $answer_id) { |
|
| 991 | 991 | |
| 992 | - if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 992 | + if (isset($question_answers_options[$answer_id])) { |
|
| 993 | 993 | |
| 994 | - $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 995 | - unset( $question_answers_options[ $answer_id ] ); |
|
| 994 | + $answer_options_sorted[$answer_id] = $question_answers_options[$answer_id]; |
|
| 995 | + unset($question_answers_options[$answer_id]); |
|
| 996 | 996 | |
| 997 | 997 | } |
| 998 | 998 | |
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | - if( count( $question_answers_options ) > 0 ) { |
|
| 1002 | - foreach( $question_answers_options as $id => $answer ) { |
|
| 1001 | + if (count($question_answers_options) > 0) { |
|
| 1002 | + foreach ($question_answers_options as $id => $answer) { |
|
| 1003 | 1003 | |
| 1004 | - $answer_options_sorted[ $id ] = $answer; |
|
| 1004 | + $answer_options_sorted[$id] = $answer; |
|
| 1005 | 1005 | |
| 1006 | 1006 | } |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - }else{ |
|
| 1009 | + } else { |
|
| 1010 | 1010 | |
| 1011 | 1011 | $answer_options_sorted = $question_answers_options; |
| 1012 | 1012 | |
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | - }else{ |
|
| 1015 | + } else { |
|
| 1016 | 1016 | |
| 1017 | 1017 | $answer_options_sorted = $question_answers_options; |
| 1018 | 1018 | |
@@ -1022,7 +1022,7 @@ discard block |
||
| 1022 | 1022 | |
| 1023 | 1023 | |
| 1024 | 1024 | // assemble and setup the data for the templates data array |
| 1025 | - $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1025 | + $question_data['answer_options'] = $answer_options_sorted; |
|
| 1026 | 1026 | |
| 1027 | 1027 | } |
| 1028 | 1028 | |
@@ -1042,14 +1042,14 @@ discard block |
||
| 1042 | 1042 | * |
| 1043 | 1043 | * @return array() |
| 1044 | 1044 | */ |
| 1045 | - public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1045 | + public static function gap_fill_load_question_data($question_data, $question_id, $quiz_id) { |
|
| 1046 | 1046 | |
| 1047 | - if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 1047 | + if ('gap-fill' == Sensei()->question->get_question_type($question_id)) { |
|
| 1048 | 1048 | |
| 1049 | - $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
| 1050 | - $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
| 1051 | - $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
| 1052 | - $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
| 1049 | + $gapfill_array = explode('||', $question_data['question_right_answer']); |
|
| 1050 | + $question_data['gapfill_pre'] = isset($gapfill_array[0]) ? $gapfill_array[0] : ''; |
|
| 1051 | + $question_data['gapfill_gap'] = isset($gapfill_array[1]) ? $gapfill_array[1] : ''; |
|
| 1052 | + $question_data['gapfill_post'] = isset($gapfill_array[2]) ? $gapfill_array[2] : ''; |
|
| 1053 | 1053 | |
| 1054 | 1054 | } |
| 1055 | 1055 | |
@@ -1064,32 +1064,32 @@ discard block |
||
| 1064 | 1064 | * @param $question_id |
| 1065 | 1065 | * @return string $correct_answer or empty |
| 1066 | 1066 | */ |
| 1067 | - public static function get_correct_answer( $question_id ){ |
|
| 1067 | + public static function get_correct_answer($question_id) { |
|
| 1068 | 1068 | |
| 1069 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 1070 | - $type = Sensei()->question->get_question_type( $question_id ); |
|
| 1071 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 1069 | + $right_answer = get_post_meta($question_id, '_question_right_answer', true); |
|
| 1070 | + $type = Sensei()->question->get_question_type($question_id); |
|
| 1071 | + $type_name = __('Multiple Choice', 'woothemes-sensei'); |
|
| 1072 | 1072 | $grade_type = 'manual-grade'; |
| 1073 | 1073 | |
| 1074 | - if ('boolean'== $type ) { |
|
| 1074 | + if ('boolean' == $type) { |
|
| 1075 | 1075 | |
| 1076 | 1076 | $right_answer = ucfirst($right_answer); |
| 1077 | 1077 | |
| 1078 | - }elseif( 'multiple-choice' == $type ) { |
|
| 1078 | + }elseif ('multiple-choice' == $type) { |
|
| 1079 | 1079 | |
| 1080 | 1080 | $right_answer = (array) $right_answer; |
| 1081 | - $right_answer = implode( ', ', $right_answer ); |
|
| 1081 | + $right_answer = implode(', ', $right_answer); |
|
| 1082 | 1082 | |
| 1083 | - }elseif( 'gap-fill' == $type ) { |
|
| 1083 | + }elseif ('gap-fill' == $type) { |
|
| 1084 | 1084 | |
| 1085 | - $right_answer_array = explode( '||', $right_answer ); |
|
| 1086 | - if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1087 | - if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1088 | - if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1085 | + $right_answer_array = explode('||', $right_answer); |
|
| 1086 | + if (isset($right_answer_array[0])) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1087 | + if (isset($right_answer_array[1])) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1088 | + if (isset($right_answer_array[2])) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1089 | 1089 | |
| 1090 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 1090 | + $right_answer = $gapfill_pre.' <span class="highlight">'.$gapfill_gap.'</span> '.$gapfill_post; |
|
| 1091 | 1091 | |
| 1092 | - }else{ |
|
| 1092 | + } else { |
|
| 1093 | 1093 | |
| 1094 | 1094 | // for non auto gradable question types no answer should be returned. |
| 1095 | 1095 | $right_answer = ''; |
@@ -1107,4 +1107,4 @@ discard block |
||
| 1107 | 1107 | * for backward compatibility |
| 1108 | 1108 | * @since 1.9.0 |
| 1109 | 1109 | */ |
| 1110 | -class WooThemes_Sensei_Question extends Sensei_Question{} |
|
| 1110 | +class WooThemes_Sensei_Question extends Sensei_Question {} |
|
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @since 1.0.0 |
| 22 | 22 | */ |
| 23 | 23 | public function __construct () { |
| 24 | - $this->token = 'question'; |
|
| 24 | + $this->token = 'question'; |
|
| 25 | 25 | $this->question_types = $this->question_types(); |
| 26 | 26 | $this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' ); |
| 27 | 27 | if ( is_admin() ) { |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | if( isset( $post->ID ) ) { |
| 120 | 120 | |
| 121 | - $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 121 | + $question_type = Sensei()->question->get_question_type( $post->ID ); |
|
| 122 | 122 | |
| 123 | 123 | if( $question_type ) { |
| 124 | 124 | $type = $this->question_types[ $question_type ]; |
@@ -238,15 +238,15 @@ discard block |
||
| 238 | 238 | public function save_question( $post_id = 0 ) { |
| 239 | 239 | |
| 240 | 240 | if( ! isset( $_POST['post_type'] |
| 241 | - ) || 'question' != $_POST['post_type'] ) { |
|
| 242 | - return; |
|
| 243 | - } |
|
| 241 | + ) || 'question' != $_POST['post_type'] ) { |
|
| 242 | + return; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | |
| 247 | - //setup the data for saving |
|
| 247 | + //setup the data for saving |
|
| 248 | 248 | $data = $_POST ; |
| 249 | - $data['quiz_id'] = 0; |
|
| 249 | + $data['quiz_id'] = 0; |
|
| 250 | 250 | $data['question_id'] = $post_id; |
| 251 | 251 | |
| 252 | 252 | if ( ! wp_is_post_revision( $post_id ) ){ |
@@ -340,34 +340,34 @@ discard block |
||
| 340 | 340 | return $request; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - /** |
|
| 344 | - * Get the type of question by id |
|
| 345 | - * |
|
| 346 | - * This function uses the post terms to determine which question type |
|
| 347 | - * the passed question id belongs to. |
|
| 348 | - * |
|
| 349 | - * @since 1.7.4 |
|
| 350 | - * |
|
| 351 | - * @param int $question_id |
|
| 352 | - * |
|
| 353 | - * @return string $question_type | bool |
|
| 354 | - */ |
|
| 355 | - public function get_question_type( $question_id ){ |
|
| 356 | - |
|
| 357 | - if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 358 | - || 'question' != get_post_type( $question_id ) ){ |
|
| 359 | - return false; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - $question_type = 'multiple-choice'; |
|
| 363 | - $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 364 | - foreach( $question_types as $type ) { |
|
| 365 | - $question_type = $type->slug; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - return $question_type; |
|
| 369 | - |
|
| 370 | - }// end get_question_type |
|
| 343 | + /** |
|
| 344 | + * Get the type of question by id |
|
| 345 | + * |
|
| 346 | + * This function uses the post terms to determine which question type |
|
| 347 | + * the passed question id belongs to. |
|
| 348 | + * |
|
| 349 | + * @since 1.7.4 |
|
| 350 | + * |
|
| 351 | + * @param int $question_id |
|
| 352 | + * |
|
| 353 | + * @return string $question_type | bool |
|
| 354 | + */ |
|
| 355 | + public function get_question_type( $question_id ){ |
|
| 356 | + |
|
| 357 | + if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 358 | + || 'question' != get_post_type( $question_id ) ){ |
|
| 359 | + return false; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + $question_type = 'multiple-choice'; |
|
| 363 | + $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 364 | + foreach( $question_types as $type ) { |
|
| 365 | + $question_type = $type->slug; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + return $question_type; |
|
| 369 | + |
|
| 370 | + }// end get_question_type |
|
| 371 | 371 | |
| 372 | 372 | /** |
| 373 | 373 | * Given a question ID, return the grade that can be achieved. |
@@ -399,317 +399,317 @@ discard block |
||
| 399 | 399 | } // end get_question_grade |
| 400 | 400 | |
| 401 | 401 | |
| 402 | - /** |
|
| 403 | - * This function simply loads the question type template |
|
| 404 | - * |
|
| 405 | - * @since 1.9.0 |
|
| 406 | - * @param $question_type |
|
| 407 | - */ |
|
| 408 | - public static function load_question_template( $question_type ){ |
|
| 409 | - |
|
| 410 | - Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Echo the sensei question title. |
|
| 415 | - * |
|
| 416 | - * @uses WooThemes_Sensei_Question::get_the_question_title |
|
| 417 | - * |
|
| 418 | - * @since 1.9.0 |
|
| 419 | - * @param $question_id |
|
| 420 | - */ |
|
| 421 | - public static function the_question_title( $question_id ){ |
|
| 422 | - |
|
| 423 | - echo self::get_the_question_title( $question_id ); |
|
| 424 | - |
|
| 425 | - }// end the_question_title |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * Generate the question title with it's grade. |
|
| 429 | - * |
|
| 430 | - * @since 1.9.0 |
|
| 431 | - * |
|
| 432 | - * @param $question_id |
|
| 433 | - * @return string |
|
| 434 | - */ |
|
| 435 | - public static function get_the_question_title( $question_id ){ |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Filter the sensei question title |
|
| 439 | - * |
|
| 440 | - * @since 1.3.0 |
|
| 441 | - * @param $question_title |
|
| 442 | - */ |
|
| 443 | - $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * hook document in class-woothemes-sensei-message.php the_title() |
|
| 447 | - */ |
|
| 448 | - $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 449 | - |
|
| 450 | - $title_html = '<span class="question question-title">'; |
|
| 451 | - $title_html .= $title; |
|
| 452 | - $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
|
| 453 | - $title_html .='</span>'; |
|
| 454 | - |
|
| 455 | - return $title_html; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Tech the question description |
|
| 460 | - * |
|
| 461 | - * @param $question_id |
|
| 462 | - * @return string |
|
| 463 | - */ |
|
| 464 | - public static function get_the_question_description( $question_id ){ |
|
| 465 | - |
|
| 466 | - $question = get_post( $question_id ); |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * Already documented within WordPress Core |
|
| 470 | - */ |
|
| 471 | - return apply_filters( 'the_content', $question->post_content ); |
|
| 472 | - |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Output the question description |
|
| 477 | - * |
|
| 478 | - * @since 1.9.0 |
|
| 479 | - * @param $question_id |
|
| 480 | - */ |
|
| 481 | - public static function the_question_description( $question_id ){ |
|
| 482 | - |
|
| 483 | - echo self::get_the_question_description( $question_id ); |
|
| 484 | - |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Get the questions media markup |
|
| 489 | - * |
|
| 490 | - * @since 1.9.0 |
|
| 491 | - * @param $question_id |
|
| 492 | - * @return string |
|
| 493 | - */ |
|
| 494 | - public static function get_the_question_media( $question_id ){ |
|
| 495 | - |
|
| 496 | - $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 497 | - $question_media_link = ''; |
|
| 498 | - if( 0 < intval( $question_media ) ) { |
|
| 499 | - $mimetype = get_post_mime_type( $question_media ); |
|
| 500 | - if( $mimetype ) { |
|
| 501 | - $mimetype_array = explode( '/', $mimetype); |
|
| 502 | - if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
| 503 | - $question_media_type = $mimetype_array[0]; |
|
| 504 | - $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 505 | - $attachment = get_post( $question_media ); |
|
| 506 | - $question_media_title = $attachment->post_title; |
|
| 507 | - $question_media_description = $attachment->post_content; |
|
| 508 | - switch( $question_media_type ) { |
|
| 509 | - case 'image': |
|
| 510 | - $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
| 511 | - $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
| 512 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
| 513 | - break; |
|
| 514 | - |
|
| 515 | - case 'audio': |
|
| 516 | - $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 517 | - break; |
|
| 518 | - |
|
| 519 | - case 'video': |
|
| 520 | - $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 521 | - break; |
|
| 522 | - |
|
| 523 | - default: |
|
| 524 | - $question_media_filename = basename( $question_media_url ); |
|
| 525 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
| 526 | - break; |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - $output = ''; |
|
| 533 | - if( $question_media_link ) { |
|
| 534 | - |
|
| 535 | - $output .= '<div class="question_media_display">'; |
|
| 536 | - $output .= $question_media_link; |
|
| 537 | - $output .= '<dl>'; |
|
| 538 | - |
|
| 539 | - if( $question_media_title ) { |
|
| 540 | - |
|
| 541 | - $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 542 | - |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - if( $question_media_description ) { |
|
| 546 | - |
|
| 547 | - $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 548 | - |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - $output .= '</dl>'; |
|
| 552 | - $output .= '</div>'; |
|
| 402 | + /** |
|
| 403 | + * This function simply loads the question type template |
|
| 404 | + * |
|
| 405 | + * @since 1.9.0 |
|
| 406 | + * @param $question_type |
|
| 407 | + */ |
|
| 408 | + public static function load_question_template( $question_type ){ |
|
| 409 | + |
|
| 410 | + Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Echo the sensei question title. |
|
| 415 | + * |
|
| 416 | + * @uses WooThemes_Sensei_Question::get_the_question_title |
|
| 417 | + * |
|
| 418 | + * @since 1.9.0 |
|
| 419 | + * @param $question_id |
|
| 420 | + */ |
|
| 421 | + public static function the_question_title( $question_id ){ |
|
| 422 | + |
|
| 423 | + echo self::get_the_question_title( $question_id ); |
|
| 424 | + |
|
| 425 | + }// end the_question_title |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * Generate the question title with it's grade. |
|
| 429 | + * |
|
| 430 | + * @since 1.9.0 |
|
| 431 | + * |
|
| 432 | + * @param $question_id |
|
| 433 | + * @return string |
|
| 434 | + */ |
|
| 435 | + public static function get_the_question_title( $question_id ){ |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Filter the sensei question title |
|
| 439 | + * |
|
| 440 | + * @since 1.3.0 |
|
| 441 | + * @param $question_title |
|
| 442 | + */ |
|
| 443 | + $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * hook document in class-woothemes-sensei-message.php the_title() |
|
| 447 | + */ |
|
| 448 | + $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 449 | + |
|
| 450 | + $title_html = '<span class="question question-title">'; |
|
| 451 | + $title_html .= $title; |
|
| 452 | + $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
|
| 453 | + $title_html .='</span>'; |
|
| 454 | + |
|
| 455 | + return $title_html; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Tech the question description |
|
| 460 | + * |
|
| 461 | + * @param $question_id |
|
| 462 | + * @return string |
|
| 463 | + */ |
|
| 464 | + public static function get_the_question_description( $question_id ){ |
|
| 465 | + |
|
| 466 | + $question = get_post( $question_id ); |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * Already documented within WordPress Core |
|
| 470 | + */ |
|
| 471 | + return apply_filters( 'the_content', $question->post_content ); |
|
| 472 | + |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Output the question description |
|
| 477 | + * |
|
| 478 | + * @since 1.9.0 |
|
| 479 | + * @param $question_id |
|
| 480 | + */ |
|
| 481 | + public static function the_question_description( $question_id ){ |
|
| 482 | + |
|
| 483 | + echo self::get_the_question_description( $question_id ); |
|
| 484 | + |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Get the questions media markup |
|
| 489 | + * |
|
| 490 | + * @since 1.9.0 |
|
| 491 | + * @param $question_id |
|
| 492 | + * @return string |
|
| 493 | + */ |
|
| 494 | + public static function get_the_question_media( $question_id ){ |
|
| 495 | + |
|
| 496 | + $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 497 | + $question_media_link = ''; |
|
| 498 | + if( 0 < intval( $question_media ) ) { |
|
| 499 | + $mimetype = get_post_mime_type( $question_media ); |
|
| 500 | + if( $mimetype ) { |
|
| 501 | + $mimetype_array = explode( '/', $mimetype); |
|
| 502 | + if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { |
|
| 503 | + $question_media_type = $mimetype_array[0]; |
|
| 504 | + $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 505 | + $attachment = get_post( $question_media ); |
|
| 506 | + $question_media_title = $attachment->post_title; |
|
| 507 | + $question_media_description = $attachment->post_content; |
|
| 508 | + switch( $question_media_type ) { |
|
| 509 | + case 'image': |
|
| 510 | + $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); |
|
| 511 | + $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); |
|
| 512 | + $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; |
|
| 513 | + break; |
|
| 514 | + |
|
| 515 | + case 'audio': |
|
| 516 | + $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 517 | + break; |
|
| 518 | + |
|
| 519 | + case 'video': |
|
| 520 | + $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 521 | + break; |
|
| 522 | + |
|
| 523 | + default: |
|
| 524 | + $question_media_filename = basename( $question_media_url ); |
|
| 525 | + $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; |
|
| 526 | + break; |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + $output = ''; |
|
| 533 | + if( $question_media_link ) { |
|
| 553 | 534 | |
| 535 | + $output .= '<div class="question_media_display">'; |
|
| 536 | + $output .= $question_media_link; |
|
| 537 | + $output .= '<dl>'; |
|
| 554 | 538 | |
| 555 | - } |
|
| 556 | - |
|
| 557 | - return $output; |
|
| 558 | - |
|
| 559 | - } // end get_the_question_media |
|
| 560 | - |
|
| 539 | + if( $question_media_title ) { |
|
| 561 | 540 | |
| 562 | - /** |
|
| 563 | - * Output the question media |
|
| 564 | - * |
|
| 565 | - * @since 1.9.0 |
|
| 566 | - * @param string $question_id |
|
| 567 | - */ |
|
| 568 | - public static function the_question_media( $question_id ){ |
|
| 541 | + $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 569 | 542 | |
| 570 | - echo self::get_the_question_media( $question_id ); |
|
| 543 | + } |
|
| 571 | 544 | |
| 572 | - } |
|
| 545 | + if( $question_media_description ) { |
|
| 573 | 546 | |
| 574 | - /** |
|
| 575 | - * Output a special field for the question needed for question submission. |
|
| 576 | - * |
|
| 577 | - * @since 1.9.0 |
|
| 578 | - * |
|
| 579 | - * @param $question_id |
|
| 580 | - */ |
|
| 581 | - public static function the_question_hidden_fields( $question_id ){ |
|
| 582 | - ?> |
|
| 547 | + $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 548 | + |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + $output .= '</dl>'; |
|
| 552 | + $output .= '</div>'; |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + return $output; |
|
| 558 | + |
|
| 559 | + } // end get_the_question_media |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * Output the question media |
|
| 564 | + * |
|
| 565 | + * @since 1.9.0 |
|
| 566 | + * @param string $question_id |
|
| 567 | + */ |
|
| 568 | + public static function the_question_media( $question_id ){ |
|
| 569 | + |
|
| 570 | + echo self::get_the_question_media( $question_id ); |
|
| 571 | + |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * Output a special field for the question needed for question submission. |
|
| 576 | + * |
|
| 577 | + * @since 1.9.0 |
|
| 578 | + * |
|
| 579 | + * @param $question_id |
|
| 580 | + */ |
|
| 581 | + public static function the_question_hidden_fields( $question_id ){ |
|
| 582 | + ?> |
|
| 583 | 583 | |
| 584 | 584 | <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" /> |
| 585 | 585 | <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" /> |
| 586 | 586 | |
| 587 | 587 | <?php |
| 588 | - } |
|
| 588 | + } |
|
| 589 | 589 | |
| 590 | - /** |
|
| 591 | - * This function can only be run withing the single quiz question loop |
|
| 592 | - * |
|
| 593 | - * @since 1.9.0 |
|
| 594 | - * @param $question_id |
|
| 595 | - */ |
|
| 596 | - public static function answer_feedback_notes( $question_id ){ |
|
| 590 | + /** |
|
| 591 | + * This function can only be run withing the single quiz question loop |
|
| 592 | + * |
|
| 593 | + * @since 1.9.0 |
|
| 594 | + * @param $question_id |
|
| 595 | + */ |
|
| 596 | + public static function answer_feedback_notes( $question_id ){ |
|
| 597 | 597 | |
| 598 | - //IDS |
|
| 599 | - $quiz_id = get_the_ID(); |
|
| 600 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 598 | + //IDS |
|
| 599 | + $quiz_id = get_the_ID(); |
|
| 600 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 601 | 601 | |
| 602 | - // Data to check before showing feedback |
|
| 603 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
| 604 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 605 | - $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
| 606 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 607 | - $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
| 608 | - $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 602 | + // Data to check before showing feedback |
|
| 603 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); |
|
| 604 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 605 | + $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); |
|
| 606 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 607 | + $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); |
|
| 608 | + $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 609 | 609 | |
| 610 | - if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
| 611 | - || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
| 612 | - || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
| 610 | + if( ( $lesson_completed && $not_empty_user_quiz_grade ) |
|
| 611 | + || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) |
|
| 612 | + || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { |
|
| 613 | 613 | |
| 614 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
| 614 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); |
|
| 615 | 615 | |
| 616 | - if( $answer_notes ) { ?> |
|
| 616 | + if( $answer_notes ) { ?> |
|
| 617 | 617 | |
| 618 | 618 | <div class="sensei-message info info-special answer-feedback"> |
| 619 | 619 | |
| 620 | 620 | <?php |
| 621 | 621 | |
| 622 | - /** |
|
| 623 | - * Filter the answer feedback |
|
| 624 | - * Since 1.9.0 |
|
| 625 | - * |
|
| 626 | - * @param string $answer_notes |
|
| 627 | - * @param string $question_id |
|
| 628 | - * @param string $lesson_id |
|
| 629 | - */ |
|
| 630 | - echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 622 | + /** |
|
| 623 | + * Filter the answer feedback |
|
| 624 | + * Since 1.9.0 |
|
| 625 | + * |
|
| 626 | + * @param string $answer_notes |
|
| 627 | + * @param string $question_id |
|
| 628 | + * @param string $lesson_id |
|
| 629 | + */ |
|
| 630 | + echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 631 | 631 | |
| 632 | - ?> |
|
| 632 | + ?> |
|
| 633 | 633 | |
| 634 | 634 | </div> |
| 635 | 635 | |
| 636 | 636 | <?php } |
| 637 | 637 | |
| 638 | - }// end if we can show answer feedback |
|
| 638 | + }// end if we can show answer feedback |
|
| 639 | 639 | |
| 640 | - }// end answer_feedback_notes |
|
| 640 | + }// end answer_feedback_notes |
|
| 641 | 641 | |
| 642 | - /** |
|
| 643 | - * This function has to be run inside the quiz question loop on the single quiz page. |
|
| 644 | - * |
|
| 645 | - * |
|
| 646 | - * @since 1.9.0 |
|
| 647 | - * @param string $question_id |
|
| 648 | - */ |
|
| 649 | - public static function the_answer_result_indication( $question_id ){ |
|
| 642 | + /** |
|
| 643 | + * This function has to be run inside the quiz question loop on the single quiz page. |
|
| 644 | + * |
|
| 645 | + * |
|
| 646 | + * @since 1.9.0 |
|
| 647 | + * @param string $question_id |
|
| 648 | + */ |
|
| 649 | + public static function the_answer_result_indication( $question_id ){ |
|
| 650 | 650 | |
| 651 | - global $post, $current_user, $sensei_question_loop; |
|
| 651 | + global $post, $current_user, $sensei_question_loop; |
|
| 652 | 652 | |
| 653 | - // Post Data |
|
| 654 | - $quiz_id = $sensei_question_loop['quiz_id']; |
|
| 655 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 656 | - $question_item = $sensei_question_loop['current_question']; |
|
| 653 | + // Post Data |
|
| 654 | + $quiz_id = $sensei_question_loop['quiz_id']; |
|
| 655 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 656 | + $question_item = $sensei_question_loop['current_question']; |
|
| 657 | 657 | |
| 658 | - // Setup variable needed to determine if the message should show and what it should show |
|
| 659 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 660 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 661 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 662 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 658 | + // Setup variable needed to determine if the message should show and what it should show |
|
| 659 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 660 | + $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 661 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 662 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 663 | 663 | |
| 664 | - // retrieve the question total grade |
|
| 665 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 664 | + // retrieve the question total grade |
|
| 665 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 666 | 666 | |
| 667 | - // retrieve grade the user achieved |
|
| 668 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 667 | + // retrieve grade the user achieved |
|
| 668 | + $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 669 | 669 | |
| 670 | - // Question ID |
|
| 671 | - $question_id = $question_item->ID; |
|
| 670 | + // Question ID |
|
| 671 | + $question_id = $question_item->ID; |
|
| 672 | 672 | |
| 673 | - // conditions to check |
|
| 674 | - $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
| 675 | - $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
| 676 | - $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
| 673 | + // conditions to check |
|
| 674 | + $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; |
|
| 675 | + $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; |
|
| 676 | + $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; |
|
| 677 | 677 | |
| 678 | - if ( $completed_with_valid_grade |
|
| 679 | - || $completed_with_valid_grade_and_reset_not_allowed |
|
| 680 | - || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 678 | + if ( $completed_with_valid_grade |
|
| 679 | + || $completed_with_valid_grade_and_reset_not_allowed |
|
| 680 | + || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 681 | 681 | |
| 682 | - $user_correct = false; |
|
| 683 | - $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 684 | - $answer_message_class = 'user_wrong'; |
|
| 685 | - // For zero grade mark as 'correct' but add no classes |
|
| 686 | - if ( 0 == $question_grade ) { |
|
| 682 | + $user_correct = false; |
|
| 683 | + $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 684 | + $answer_message_class = 'user_wrong'; |
|
| 685 | + // For zero grade mark as 'correct' but add no classes |
|
| 686 | + if ( 0 == $question_grade ) { |
|
| 687 | 687 | |
| 688 | - $user_correct = true; |
|
| 689 | - $answer_message = ''; |
|
| 690 | - $answer_message_class = ''; |
|
| 688 | + $user_correct = true; |
|
| 689 | + $answer_message = ''; |
|
| 690 | + $answer_message_class = ''; |
|
| 691 | 691 | |
| 692 | - } else if( $user_question_grade > 0 ) { |
|
| 692 | + } else if( $user_question_grade > 0 ) { |
|
| 693 | 693 | |
| 694 | - $user_correct = true; |
|
| 695 | - $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 696 | - $answer_message_class = 'user_right'; |
|
| 694 | + $user_correct = true; |
|
| 695 | + $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 696 | + $answer_message_class = 'user_right'; |
|
| 697 | 697 | |
| 698 | - } |
|
| 698 | + } |
|
| 699 | 699 | |
| 700 | - // attach the correct answer if the question is auto gradable and user got it wrong |
|
| 701 | - if( !$reset_quiz_allowed && !$user_correct ){ |
|
| 700 | + // attach the correct answer if the question is auto gradable and user got it wrong |
|
| 701 | + if( !$reset_quiz_allowed && !$user_correct ){ |
|
| 702 | 702 | |
| 703 | - $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
| 703 | + $answer_message .= ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); |
|
| 704 | 704 | |
| 705 | - } |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | - // answer feedback |
|
| 708 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 709 | - if( $answer_notes ) { |
|
| 710 | - $answer_message_class .= ' has_notes'; |
|
| 711 | - } |
|
| 712 | - ?> |
|
| 707 | + // answer feedback |
|
| 708 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 709 | + if( $answer_notes ) { |
|
| 710 | + $answer_message_class .= ' has_notes'; |
|
| 711 | + } |
|
| 712 | + ?> |
|
| 713 | 713 | |
| 714 | 714 | <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>"> |
| 715 | 715 | |
@@ -719,387 +719,387 @@ discard block |
||
| 719 | 719 | |
| 720 | 720 | <?php |
| 721 | 721 | |
| 722 | - } // end if user can see all the goodies |
|
| 723 | - |
|
| 724 | - }// end the_answer_result_indication |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * Generate the question template data and return it as an array. |
|
| 728 | - * |
|
| 729 | - * @since 1.9.0 |
|
| 730 | - * |
|
| 731 | - * @param string $question_id |
|
| 732 | - * @param $quiz_id |
|
| 733 | - * @return array $question_data |
|
| 734 | - */ |
|
| 735 | - public static function get_template_data( $question_id, $quiz_id ){ |
|
| 736 | - |
|
| 737 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 738 | - |
|
| 739 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 740 | - //backwards compatibility |
|
| 741 | - if( 'on' == $reset_allowed ) { |
|
| 742 | - $reset_allowed = 1; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - // Check again that the lesson is complete |
|
| 746 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
| 747 | - $user_lesson_complete = false; |
|
| 748 | - if ( $user_lesson_end ) { |
|
| 749 | - $user_lesson_complete = true; |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - //setup the question data |
|
| 753 | - $data[ 'ID' ] = $question_id; |
|
| 754 | - $data[ 'title' ] = get_the_title( $question_id ); |
|
| 755 | - $data[ 'content' ] = get_post( $question_id )->post_content; |
|
| 756 | - $data[ 'quiz_id' ] = $quiz_id; |
|
| 757 | - $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 758 | - $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
| 759 | - $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
| 760 | - $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
| 761 | - $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
| 762 | - $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
| 763 | - $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
| 764 | - $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
| 765 | - $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 766 | - $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
| 767 | - $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
| 768 | - |
|
| 769 | - /** |
|
| 770 | - * Filter the question template data. This filter fires in |
|
| 771 | - * the get_template_data function |
|
| 772 | - * |
|
| 773 | - * @hooked self::boolean_load_question_data |
|
| 774 | - * |
|
| 775 | - * @since 1.9.0 |
|
| 776 | - * |
|
| 777 | - * @param array $data |
|
| 778 | - * @param string $question_id |
|
| 779 | - * @param string $quiz_id |
|
| 780 | - */ |
|
| 781 | - return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 722 | + } // end if user can see all the goodies |
|
| 782 | 723 | |
| 783 | - } |
|
| 724 | + }// end the_answer_result_indication |
|
| 784 | 725 | |
| 785 | - /** |
|
| 786 | - * Load multiple choice question data on the sensei_get_question_template_data |
|
| 787 | - * filter. |
|
| 788 | - * |
|
| 789 | - * @since 1.9.0 |
|
| 790 | - * |
|
| 791 | - * @param $question_data |
|
| 792 | - * @param $question_id |
|
| 793 | - * @param $quiz_id |
|
| 794 | - * |
|
| 795 | - * @return array() |
|
| 796 | - */ |
|
| 797 | - public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 726 | + /** |
|
| 727 | + * Generate the question template data and return it as an array. |
|
| 728 | + * |
|
| 729 | + * @since 1.9.0 |
|
| 730 | + * |
|
| 731 | + * @param string $question_id |
|
| 732 | + * @param $quiz_id |
|
| 733 | + * @return array $question_data |
|
| 734 | + */ |
|
| 735 | + public static function get_template_data( $question_id, $quiz_id ){ |
|
| 798 | 736 | |
| 737 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 799 | 738 | |
| 800 | - if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 739 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 740 | + //backwards compatibility |
|
| 741 | + if( 'on' == $reset_allowed ) { |
|
| 742 | + $reset_allowed = 1; |
|
| 743 | + } |
|
| 801 | 744 | |
| 802 | - // Get uploaded file |
|
| 803 | - $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 804 | - $answer_media_url = $answer_media_filename = ''; |
|
| 745 | + // Check again that the lesson is complete |
|
| 746 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); |
|
| 747 | + $user_lesson_complete = false; |
|
| 748 | + if ( $user_lesson_end ) { |
|
| 749 | + $user_lesson_complete = true; |
|
| 750 | + } |
|
| 805 | 751 | |
| 752 | + //setup the question data |
|
| 753 | + $data[ 'ID' ] = $question_id; |
|
| 754 | + $data[ 'title' ] = get_the_title( $question_id ); |
|
| 755 | + $data[ 'content' ] = get_post( $question_id )->post_content; |
|
| 756 | + $data[ 'quiz_id' ] = $quiz_id; |
|
| 757 | + $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 758 | + $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); |
|
| 759 | + $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); |
|
| 760 | + $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); |
|
| 761 | + $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); |
|
| 762 | + $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); |
|
| 763 | + $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); |
|
| 764 | + $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); |
|
| 765 | + $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); |
|
| 766 | + $data[ 'reset_quiz_allowed' ] = $reset_allowed; |
|
| 767 | + $data[ 'lesson_complete' ] = $user_lesson_complete; |
|
| 768 | + |
|
| 769 | + /** |
|
| 770 | + * Filter the question template data. This filter fires in |
|
| 771 | + * the get_template_data function |
|
| 772 | + * |
|
| 773 | + * @hooked self::boolean_load_question_data |
|
| 774 | + * |
|
| 775 | + * @since 1.9.0 |
|
| 776 | + * |
|
| 777 | + * @param array $data |
|
| 778 | + * @param string $question_id |
|
| 779 | + * @param string $quiz_id |
|
| 780 | + */ |
|
| 781 | + return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 806 | 782 | |
| 807 | - $question_helptext = ''; |
|
| 808 | - if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 783 | + } |
|
| 809 | 784 | |
| 810 | - $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 785 | + /** |
|
| 786 | + * Load multiple choice question data on the sensei_get_question_template_data |
|
| 787 | + * filter. |
|
| 788 | + * |
|
| 789 | + * @since 1.9.0 |
|
| 790 | + * |
|
| 791 | + * @param $question_data |
|
| 792 | + * @param $question_id |
|
| 793 | + * @param $quiz_id |
|
| 794 | + * |
|
| 795 | + * @return array() |
|
| 796 | + */ |
|
| 797 | + public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 811 | 798 | |
| 812 | - } |
|
| 813 | 799 | |
| 800 | + if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 814 | 801 | |
| 815 | - if( 0 < intval( $attachment_id ) ) { |
|
| 802 | + // Get uploaded file |
|
| 803 | + $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 804 | + $answer_media_url = $answer_media_filename = ''; |
|
| 816 | 805 | |
| 817 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 818 | - $answer_media_filename = basename( $answer_media_url ); |
|
| 819 | 806 | |
| 820 | - } |
|
| 807 | + $question_helptext = ''; |
|
| 808 | + if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 821 | 809 | |
| 810 | + $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 822 | 811 | |
| 823 | - // Get max upload file size, formatted for display |
|
| 824 | - // Code copied from wp-admin/includes/media.php:1515 |
|
| 825 | - $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
|
| 826 | - $sizes = array( 'KB', 'MB', 'GB' ); |
|
| 827 | - for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
| 828 | - $upload_size_unit /= 1024; |
|
| 829 | - } |
|
| 830 | - if ( $u < 0 ) { |
|
| 812 | + } |
|
| 831 | 813 | |
| 832 | - $upload_size_unit = 0; |
|
| 833 | - $u = 0; |
|
| 834 | 814 | |
| 835 | - } else { |
|
| 815 | + if( 0 < intval( $attachment_id ) ) { |
|
| 836 | 816 | |
| 837 | - $upload_size_unit = (int) $upload_size_unit; |
|
| 817 | + $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 818 | + $answer_media_filename = basename( $answer_media_url ); |
|
| 838 | 819 | |
| 839 | - } |
|
| 840 | - $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 820 | + } |
|
| 841 | 821 | |
| 842 | - // Assemble all the data needed by the file upload template |
|
| 843 | - $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
| 844 | - $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
| 845 | - $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
| 846 | 822 | |
| 847 | - $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 823 | + // Get max upload file size, formatted for display |
|
| 824 | + // Code copied from wp-admin/includes/media.php:1515 |
|
| 825 | + $upload_size_unit = $max_upload_size = wp_max_upload_size(); |
|
| 826 | + $sizes = array( 'KB', 'MB', 'GB' ); |
|
| 827 | + for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { |
|
| 828 | + $upload_size_unit /= 1024; |
|
| 829 | + } |
|
| 830 | + if ( $u < 0 ) { |
|
| 848 | 831 | |
| 849 | - }// end if is file upload type |
|
| 832 | + $upload_size_unit = 0; |
|
| 833 | + $u = 0; |
|
| 850 | 834 | |
| 851 | - return $question_data; |
|
| 835 | + } else { |
|
| 852 | 836 | |
| 853 | - }// end file_upload_load_question_data |
|
| 837 | + $upload_size_unit = (int) $upload_size_unit; |
|
| 854 | 838 | |
| 855 | - /** |
|
| 856 | - * Load multiple choice question data on the sensei_get_question_template_data |
|
| 857 | - * filter. |
|
| 858 | - * |
|
| 859 | - * @since 1.9.0 |
|
| 860 | - * |
|
| 861 | - * @param $question_data |
|
| 862 | - * @param $question_id |
|
| 863 | - * @param $quiz_id |
|
| 864 | - * |
|
| 865 | - * @return array() |
|
| 866 | - */ |
|
| 867 | - public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 839 | + } |
|
| 840 | + $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 868 | 841 | |
| 869 | - if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 842 | + // Assemble all the data needed by the file upload template |
|
| 843 | + $question_data[ 'answer_media_url' ] = $answer_media_url; |
|
| 844 | + $question_data[ 'answer_media_filename' ] = $answer_media_filename; |
|
| 845 | + $question_data[ 'max_upload_size' ] = $max_upload_size; |
|
| 870 | 846 | |
| 847 | + $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 871 | 848 | |
| 872 | - $answer_type = 'radio'; |
|
| 873 | - if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 849 | + }// end if is file upload type |
|
| 874 | 850 | |
| 875 | - $answer_type = 'checkbox'; |
|
| 851 | + return $question_data; |
|
| 876 | 852 | |
| 877 | - } |
|
| 853 | + }// end file_upload_load_question_data |
|
| 878 | 854 | |
| 879 | - // Merge right and wrong answers |
|
| 880 | - if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 855 | + /** |
|
| 856 | + * Load multiple choice question data on the sensei_get_question_template_data |
|
| 857 | + * filter. |
|
| 858 | + * |
|
| 859 | + * @since 1.9.0 |
|
| 860 | + * |
|
| 861 | + * @param $question_data |
|
| 862 | + * @param $question_id |
|
| 863 | + * @param $quiz_id |
|
| 864 | + * |
|
| 865 | + * @return array() |
|
| 866 | + */ |
|
| 867 | + public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 881 | 868 | |
| 882 | - $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 869 | + if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 883 | 870 | |
| 884 | - } else { |
|
| 885 | 871 | |
| 886 | - array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 887 | - $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 872 | + $answer_type = 'radio'; |
|
| 873 | + if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 888 | 874 | |
| 889 | - } |
|
| 875 | + $answer_type = 'checkbox'; |
|
| 890 | 876 | |
| 891 | - // Setup answer options array. |
|
| 892 | - $question_answers_options = array(); |
|
| 893 | - $count = 0; |
|
| 877 | + } |
|
| 894 | 878 | |
| 895 | - foreach( $merged_options as $answer ) { |
|
| 879 | + // Merge right and wrong answers |
|
| 880 | + if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 896 | 881 | |
| 897 | - $count++; |
|
| 898 | - $question_option = array(); |
|
| 882 | + $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 899 | 883 | |
| 900 | - if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 901 | - || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 902 | - || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
| 884 | + } else { |
|
| 903 | 885 | |
| 904 | - $user_correct = false; |
|
| 886 | + array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 887 | + $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 905 | 888 | |
| 889 | + } |
|
| 906 | 890 | |
| 907 | - // For zero grade mark as 'correct' but add no classes |
|
| 908 | - if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 891 | + // Setup answer options array. |
|
| 892 | + $question_answers_options = array(); |
|
| 893 | + $count = 0; |
|
| 909 | 894 | |
| 910 | - $user_correct = true; |
|
| 895 | + foreach( $merged_options as $answer ) { |
|
| 911 | 896 | |
| 912 | - } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 897 | + $count++; |
|
| 898 | + $question_option = array(); |
|
| 913 | 899 | |
| 914 | - $user_correct = true; |
|
| 900 | + if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 901 | + || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) |
|
| 902 | + || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ] && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { |
|
| 915 | 903 | |
| 916 | - } |
|
| 904 | + $user_correct = false; |
|
| 917 | 905 | |
| 918 | - } |
|
| 919 | 906 | |
| 920 | - // setup the option specific classes |
|
| 921 | - $answer_class = ''; |
|
| 922 | - if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
| 923 | - if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
| 907 | + // For zero grade mark as 'correct' but add no classes |
|
| 908 | + if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 924 | 909 | |
| 925 | - $answer_class .= ' right_answer'; |
|
| 910 | + $user_correct = true; |
|
| 926 | 911 | |
| 927 | - } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 912 | + } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 928 | 913 | |
| 929 | - $answer_class .= ' right_answer'; |
|
| 914 | + $user_correct = true; |
|
| 930 | 915 | |
| 931 | - } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
| 932 | - || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
| 916 | + } |
|
| 933 | 917 | |
| 934 | - $answer_class = 'user_wrong'; |
|
| 935 | - if( $user_correct ) { |
|
| 918 | + } |
|
| 936 | 919 | |
| 937 | - $answer_class = 'user_right'; |
|
| 920 | + // setup the option specific classes |
|
| 921 | + $answer_class = ''; |
|
| 922 | + if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { |
|
| 923 | + if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { |
|
| 938 | 924 | |
| 939 | - } |
|
| 925 | + $answer_class .= ' right_answer'; |
|
| 940 | 926 | |
| 941 | - } |
|
| 927 | + } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 942 | 928 | |
| 943 | - } |
|
| 929 | + $answer_class .= ' right_answer'; |
|
| 944 | 930 | |
| 945 | - // determine if the current option must be checked |
|
| 946 | - $checked = ''; |
|
| 947 | - if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
| 948 | - if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
| 931 | + } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) |
|
| 932 | + || ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer ) ) { |
|
| 949 | 933 | |
| 950 | - $checked = 'checked="checked"'; |
|
| 934 | + $answer_class = 'user_wrong'; |
|
| 935 | + if( $user_correct ) { |
|
| 951 | 936 | |
| 952 | - } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 937 | + $answer_class = 'user_right'; |
|
| 953 | 938 | |
| 954 | - $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 939 | + } |
|
| 955 | 940 | |
| 956 | - } |
|
| 941 | + } |
|
| 957 | 942 | |
| 958 | - } // End If Statement |
|
| 943 | + } |
|
| 959 | 944 | |
| 960 | - //Load the answer option data |
|
| 961 | - $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
| 962 | - $question_option[ 'answer' ] = $answer; |
|
| 963 | - $question_option[ 'option_class'] = $answer_class; |
|
| 964 | - $question_option[ 'checked'] = $checked; |
|
| 965 | - $question_option[ 'count' ] = $count; |
|
| 966 | - $question_option[ 'type' ] = $answer_type; |
|
| 945 | + // determine if the current option must be checked |
|
| 946 | + $checked = ''; |
|
| 947 | + if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { |
|
| 948 | + if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { |
|
| 967 | 949 | |
| 968 | - // add the speci fic option to the list of options for this question |
|
| 969 | - $question_answers_options[] = $question_option; |
|
| 950 | + $checked = 'checked="checked"'; |
|
| 970 | 951 | |
| 971 | - } // end for each option |
|
| 952 | + } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 972 | 953 | |
| 954 | + $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 973 | 955 | |
| 974 | - // Shuffle the array depending on the settings |
|
| 975 | - $answer_options_sorted = array(); |
|
| 976 | - $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 977 | - if( $random_order && $random_order == 'yes' ) { |
|
| 956 | + } |
|
| 978 | 957 | |
| 979 | - $answer_options_sorted = $question_answers_options; |
|
| 980 | - shuffle( $answer_options_sorted ); |
|
| 958 | + } // End If Statement |
|
| 981 | 959 | |
| 982 | - } else { |
|
| 960 | + //Load the answer option data |
|
| 961 | + $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); |
|
| 962 | + $question_option[ 'answer' ] = $answer; |
|
| 963 | + $question_option[ 'option_class'] = $answer_class; |
|
| 964 | + $question_option[ 'checked'] = $checked; |
|
| 965 | + $question_option[ 'count' ] = $count; |
|
| 966 | + $question_option[ 'type' ] = $answer_type; |
|
| 983 | 967 | |
| 984 | - $answer_order = array(); |
|
| 985 | - $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 986 | - if( $answer_order_string ) { |
|
| 968 | + // add the speci fic option to the list of options for this question |
|
| 969 | + $question_answers_options[] = $question_option; |
|
| 987 | 970 | |
| 988 | - $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 989 | - if( count( $answer_order ) > 0 ) { |
|
| 971 | + } // end for each option |
|
| 990 | 972 | |
| 991 | - foreach( $answer_order as $answer_id ) { |
|
| 992 | 973 | |
| 993 | - if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 974 | + // Shuffle the array depending on the settings |
|
| 975 | + $answer_options_sorted = array(); |
|
| 976 | + $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 977 | + if( $random_order && $random_order == 'yes' ) { |
|
| 994 | 978 | |
| 995 | - $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 996 | - unset( $question_answers_options[ $answer_id ] ); |
|
| 979 | + $answer_options_sorted = $question_answers_options; |
|
| 980 | + shuffle( $answer_options_sorted ); |
|
| 997 | 981 | |
| 998 | - } |
|
| 982 | + } else { |
|
| 999 | 983 | |
| 1000 | - } |
|
| 984 | + $answer_order = array(); |
|
| 985 | + $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 986 | + if( $answer_order_string ) { |
|
| 1001 | 987 | |
| 1002 | - if( count( $question_answers_options ) > 0 ) { |
|
| 1003 | - foreach( $question_answers_options as $id => $answer ) { |
|
| 988 | + $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 989 | + if( count( $answer_order ) > 0 ) { |
|
| 1004 | 990 | |
| 1005 | - $answer_options_sorted[ $id ] = $answer; |
|
| 991 | + foreach( $answer_order as $answer_id ) { |
|
| 1006 | 992 | |
| 1007 | - } |
|
| 1008 | - } |
|
| 993 | + if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 1009 | 994 | |
| 1010 | - }else{ |
|
| 995 | + $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 996 | + unset( $question_answers_options[ $answer_id ] ); |
|
| 1011 | 997 | |
| 1012 | - $answer_options_sorted = $question_answers_options; |
|
| 998 | + } |
|
| 1013 | 999 | |
| 1014 | - } |
|
| 1000 | + } |
|
| 1015 | 1001 | |
| 1016 | - }else{ |
|
| 1002 | + if( count( $question_answers_options ) > 0 ) { |
|
| 1003 | + foreach( $question_answers_options as $id => $answer ) { |
|
| 1017 | 1004 | |
| 1018 | - $answer_options_sorted = $question_answers_options; |
|
| 1005 | + $answer_options_sorted[ $id ] = $answer; |
|
| 1019 | 1006 | |
| 1020 | - } // end if $answer_order_string |
|
| 1007 | + } |
|
| 1008 | + } |
|
| 1021 | 1009 | |
| 1022 | - } // end if random order |
|
| 1010 | + }else{ |
|
| 1023 | 1011 | |
| 1012 | + $answer_options_sorted = $question_answers_options; |
|
| 1024 | 1013 | |
| 1025 | - // assemble and setup the data for the templates data array |
|
| 1026 | - $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1014 | + } |
|
| 1027 | 1015 | |
| 1028 | - } |
|
| 1016 | + }else{ |
|
| 1029 | 1017 | |
| 1030 | - return $question_data; |
|
| 1018 | + $answer_options_sorted = $question_answers_options; |
|
| 1031 | 1019 | |
| 1032 | - }// end multiple_choice_load_question_data |
|
| 1020 | + } // end if $answer_order_string |
|
| 1033 | 1021 | |
| 1034 | - /** |
|
| 1035 | - * Load the gap fill question data on the sensei_get_question_template_data |
|
| 1036 | - * filter. |
|
| 1037 | - * |
|
| 1038 | - * @since 1.9.0 |
|
| 1039 | - * |
|
| 1040 | - * @param $question_data |
|
| 1041 | - * @param $question_id |
|
| 1042 | - * @param $quiz_id |
|
| 1043 | - * |
|
| 1044 | - * @return array() |
|
| 1045 | - */ |
|
| 1046 | - public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1022 | + } // end if random order |
|
| 1047 | 1023 | |
| 1048 | - if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 1049 | 1024 | |
| 1050 | - $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
| 1051 | - $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
| 1052 | - $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
| 1053 | - $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
| 1025 | + // assemble and setup the data for the templates data array |
|
| 1026 | + $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1054 | 1027 | |
| 1055 | - } |
|
| 1028 | + } |
|
| 1056 | 1029 | |
| 1057 | - return $question_data; |
|
| 1030 | + return $question_data; |
|
| 1058 | 1031 | |
| 1059 | - }// end gap_fill_load_question_data |
|
| 1032 | + }// end multiple_choice_load_question_data |
|
| 1033 | + |
|
| 1034 | + /** |
|
| 1035 | + * Load the gap fill question data on the sensei_get_question_template_data |
|
| 1036 | + * filter. |
|
| 1037 | + * |
|
| 1038 | + * @since 1.9.0 |
|
| 1039 | + * |
|
| 1040 | + * @param $question_data |
|
| 1041 | + * @param $question_id |
|
| 1042 | + * @param $quiz_id |
|
| 1043 | + * |
|
| 1044 | + * @return array() |
|
| 1045 | + */ |
|
| 1046 | + public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1047 | + |
|
| 1048 | + if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 1049 | + |
|
| 1050 | + $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); |
|
| 1051 | + $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; |
|
| 1052 | + $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; |
|
| 1053 | + $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; |
|
| 1054 | + |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + return $question_data; |
|
| 1058 | + |
|
| 1059 | + }// end gap_fill_load_question_data |
|
| 1060 | 1060 | |
| 1061 | 1061 | |
| 1062 | - /** |
|
| 1063 | - * Get the correct answer for a question |
|
| 1064 | - * |
|
| 1065 | - * @param $question_id |
|
| 1066 | - * @return string $correct_answer or empty |
|
| 1067 | - */ |
|
| 1068 | - public static function get_correct_answer( $question_id ){ |
|
| 1062 | + /** |
|
| 1063 | + * Get the correct answer for a question |
|
| 1064 | + * |
|
| 1065 | + * @param $question_id |
|
| 1066 | + * @return string $correct_answer or empty |
|
| 1067 | + */ |
|
| 1068 | + public static function get_correct_answer( $question_id ){ |
|
| 1069 | 1069 | |
| 1070 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 1071 | - $type = Sensei()->question->get_question_type( $question_id ); |
|
| 1072 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 1073 | - $grade_type = 'manual-grade'; |
|
| 1070 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 1071 | + $type = Sensei()->question->get_question_type( $question_id ); |
|
| 1072 | + $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 1073 | + $grade_type = 'manual-grade'; |
|
| 1074 | 1074 | |
| 1075 | - if ('boolean'== $type ) { |
|
| 1075 | + if ('boolean'== $type ) { |
|
| 1076 | 1076 | |
| 1077 | - $right_answer = ucfirst($right_answer); |
|
| 1077 | + $right_answer = ucfirst($right_answer); |
|
| 1078 | 1078 | |
| 1079 | - }elseif( 'multiple-choice' == $type ) { |
|
| 1079 | + }elseif( 'multiple-choice' == $type ) { |
|
| 1080 | 1080 | |
| 1081 | - $right_answer = (array) $right_answer; |
|
| 1082 | - $right_answer = implode( ', ', $right_answer ); |
|
| 1081 | + $right_answer = (array) $right_answer; |
|
| 1082 | + $right_answer = implode( ', ', $right_answer ); |
|
| 1083 | 1083 | |
| 1084 | - }elseif( 'gap-fill' == $type ) { |
|
| 1084 | + }elseif( 'gap-fill' == $type ) { |
|
| 1085 | 1085 | |
| 1086 | - $right_answer_array = explode( '||', $right_answer ); |
|
| 1087 | - if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1088 | - if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1089 | - if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1086 | + $right_answer_array = explode( '||', $right_answer ); |
|
| 1087 | + if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 1088 | + if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 1089 | + if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 1090 | 1090 | |
| 1091 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 1091 | + $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 1092 | 1092 | |
| 1093 | - }else{ |
|
| 1093 | + }else{ |
|
| 1094 | 1094 | |
| 1095 | - // for non auto gradable question types no answer should be returned. |
|
| 1096 | - $right_answer = ''; |
|
| 1095 | + // for non auto gradable question types no answer should be returned. |
|
| 1096 | + $right_answer = ''; |
|
| 1097 | 1097 | |
| 1098 | - } |
|
| 1098 | + } |
|
| 1099 | 1099 | |
| 1100 | - return $right_answer; |
|
| 1100 | + return $right_answer; |
|
| 1101 | 1101 | |
| 1102 | - } // get_correct_answer |
|
| 1102 | + } // get_correct_answer |
|
| 1103 | 1103 | |
| 1104 | 1104 | } // End Class |
| 1105 | 1105 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * This function hooks into the quiz page and accepts the answer form save post. |
| 125 | 125 | * @since 1.7.3 |
| 126 | - * @return bool $saved; |
|
| 126 | + * @return boolean|null $saved; |
|
| 127 | 127 | */ |
| 128 | 128 | public function user_save_quiz_answers_listener(){ |
| 129 | 129 | |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | * @param int $lesson_id |
| 215 | 215 | * @param int $user_id |
| 216 | 216 | * |
| 217 | - * @return array $answers or false |
|
| 217 | + * @return boolean $answers or false |
|
| 218 | 218 | */ |
| 219 | 219 | public function get_user_answers( $lesson_id, $user_id ){ |
| 220 | 220 | |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | * @type int $question_id |
| 708 | 708 | * @type int $question_grade |
| 709 | 709 | * } |
| 710 | - * @param $lesson_id |
|
| 710 | + * @param integer $lesson_id |
|
| 711 | 711 | * @param $user_id (Optional) will use the current user if not supplied |
| 712 | 712 | * |
| 713 | 713 | * @return bool |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | * |
| 755 | 755 | * @since 1.7.4 |
| 756 | 756 | * |
| 757 | - * @param $lesson_id |
|
| 757 | + * @param integer $lesson_id |
|
| 758 | 758 | * @param $user_id (Optional) will use the current user if not supplied |
| 759 | 759 | * |
| 760 | 760 | * @return array $user_quiz_grades or false if none exists for this users |
@@ -1090,7 +1090,6 @@ discard block |
||
| 1090 | 1090 | * Filter the single title and add the Quiz to it. |
| 1091 | 1091 | * |
| 1092 | 1092 | * @param string $title |
| 1093 | - * @param int $id title post id |
|
| 1094 | 1093 | * @return string $quiz_title |
| 1095 | 1094 | */ |
| 1096 | 1095 | public static function single_quiz_title( $title, $post_id ){ |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Quiz Class |
@@ -104,7 +107,7 @@ discard block |
||
| 104 | 107 | global $post; |
| 105 | 108 | if( 'quiz' == get_post_type( $post ) ){ |
| 106 | 109 | $quiz_id = $post->ID; |
| 107 | - }else{ |
|
| 110 | + } else{ |
|
| 108 | 111 | return false; |
| 109 | 112 | } |
| 110 | 113 | |
@@ -234,7 +237,7 @@ discard block |
||
| 234 | 237 | |
| 235 | 238 | $encoded_user_answers = $transient_cached_answers; |
| 236 | 239 | |
| 237 | - }else{ |
|
| 240 | + } else{ |
|
| 238 | 241 | |
| 239 | 242 | $encoded_user_answers = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
| 240 | 243 | |
@@ -424,7 +427,7 @@ discard block |
||
| 424 | 427 | // compress the answer for saving |
| 425 | 428 | if( 'multi-line' == $question_type ) { |
| 426 | 429 | $answer = esc_html( $answer ); |
| 427 | - }elseif( 'file-upload' == $question_type ){ |
|
| 430 | + } elseif( 'file-upload' == $question_type ){ |
|
| 428 | 431 | $file_key = 'file_upload_' . $question_id; |
| 429 | 432 | if( isset( $files[ $file_key ] ) ) { |
| 430 | 433 | $attachment_id = WooThemes_Sensei_Utils::upload_file( $files[ $file_key ] ); |
@@ -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 Quiz Class |
@@ -23,24 +23,24 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @param $file |
| 25 | 25 | */ |
| 26 | - public function __construct ( $file = __FILE__ ) { |
|
| 26 | + public function __construct($file = __FILE__) { |
|
| 27 | 27 | $this->file = $file; |
| 28 | - $this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' ); |
|
| 29 | - add_action( 'save_post', array( $this, 'update_author' )); |
|
| 28 | + $this->meta_fields = array('quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required', 'enable_quiz_reset'); |
|
| 29 | + add_action('save_post', array($this, 'update_author')); |
|
| 30 | 30 | |
| 31 | 31 | // listen to the reset button click |
| 32 | - add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
|
| 32 | + add_action('template_redirect', array($this, 'reset_button_click_listener')); |
|
| 33 | 33 | |
| 34 | 34 | // fire the complete quiz button submit for grading action |
| 35 | - add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); |
|
| 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 | - add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) ); |
|
| 38 | + add_action('sensei_complete_quiz', array($this, 'user_save_quiz_answers_listener')); |
|
| 39 | 39 | |
| 40 | 40 | // fire the load global data function |
| 41 | - add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); |
|
| 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 | 46 | } // End __construct() |
@@ -51,26 +51,26 @@ discard block |
||
| 51 | 51 | * @param int $post_id |
| 52 | 52 | * @return void |
| 53 | 53 | */ |
| 54 | - public function update_author( $post_id ){ |
|
| 54 | + public function update_author($post_id) { |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | // If this isn't a 'lesson' post, don't update it. |
| 58 | 58 | // if this is a revision don't save it |
| 59 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
| 60 | - || wp_is_post_revision( $post_id ) ) { |
|
| 59 | + if (isset($_POST['post_type']) && 'lesson' != $_POST['post_type'] |
|
| 60 | + || wp_is_post_revision($post_id)) { |
|
| 61 | 61 | |
| 62 | 62 | return; |
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | // get the lesson author id to be use late |
| 66 | - $saved_post = get_post( $post_id ); |
|
| 67 | - $new_lesson_author_id = $saved_post->post_author; |
|
| 66 | + $saved_post = get_post($post_id); |
|
| 67 | + $new_lesson_author_id = $saved_post->post_author; |
|
| 68 | 68 | |
| 69 | 69 | //get the lessons quiz |
| 70 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); |
|
| 71 | - foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
| 70 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes($post_id); |
|
| 71 | + foreach ((array) $lesson_quizzes as $quiz_item) { |
|
| 72 | 72 | |
| 73 | - if( ! $quiz_item ) { |
|
| 73 | + if ( ! $quiz_item) { |
|
| 74 | 74 | continue; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | 83 | // remove the action so that it doesn't fire again |
| 84 | - remove_action( 'save_post', array( $this, 'update_author' )); |
|
| 84 | + remove_action('save_post', array($this, 'update_author')); |
|
| 85 | 85 | |
| 86 | 86 | // Update the post into the database |
| 87 | - wp_update_post( $my_post ); |
|
| 87 | + wp_update_post($my_post); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | return; |
@@ -98,19 +98,19 @@ discard block |
||
| 98 | 98 | * @param int $quiz_id |
| 99 | 99 | * @return int @lesson_id |
| 100 | 100 | */ |
| 101 | - public function get_lesson_id( $quiz_id ){ |
|
| 101 | + public function get_lesson_id($quiz_id) { |
|
| 102 | 102 | |
| 103 | - if( empty( $quiz_id ) || ! intval( $quiz_id ) > 0 ){ |
|
| 103 | + if (empty($quiz_id) || ! intval($quiz_id) > 0) { |
|
| 104 | 104 | global $post; |
| 105 | - if( 'quiz' == get_post_type( $post ) ){ |
|
| 105 | + if ('quiz' == get_post_type($post)) { |
|
| 106 | 106 | $quiz_id = $post->ID; |
| 107 | - }else{ |
|
| 107 | + } else { |
|
| 108 | 108 | return false; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - $quiz = get_post( $quiz_id ); |
|
| 113 | + $quiz = get_post($quiz_id); |
|
| 114 | 114 | $lesson_id = $quiz->post_parent; |
| 115 | 115 | |
| 116 | 116 | return $lesson_id; |
@@ -125,23 +125,23 @@ discard block |
||
| 125 | 125 | * @since 1.7.3 |
| 126 | 126 | * @return bool $saved; |
| 127 | 127 | */ |
| 128 | - public function user_save_quiz_answers_listener(){ |
|
| 128 | + public function user_save_quiz_answers_listener() { |
|
| 129 | 129 | |
| 130 | - if( ! isset( $_POST[ 'quiz_save' ]) |
|
| 131 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 132 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 133 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
| 130 | + if ( ! isset($_POST['quiz_save']) |
|
| 131 | + || ! isset($_POST['sensei_question']) |
|
| 132 | + || empty($_POST['sensei_question']) |
|
| 133 | + || ! wp_verify_nonce($_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce') > 1) { |
|
| 134 | 134 | return; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | global $post; |
| 138 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 139 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 138 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
| 139 | + $quiz_answers = $_POST['sensei_question']; |
|
| 140 | 140 | // call the save function |
| 141 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
| 141 | + self::save_user_answers($quiz_answers, $_FILES, $lesson_id, get_current_user_id()); |
|
| 142 | 142 | |
| 143 | 143 | // remove the hook as it should only fire once per click |
| 144 | - remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); |
|
| 144 | + remove_action('sensei_complete_quiz', 'user_save_quiz_answers_listener'); |
|
| 145 | 145 | |
| 146 | 146 | } // end user_save_quiz_answers_listener |
| 147 | 147 | |
@@ -160,17 +160,17 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return false or int $answers_saved |
| 162 | 162 | */ |
| 163 | - public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ |
|
| 163 | + public static function save_user_answers($quiz_answers, $files = array(), $lesson_id, $user_id = 0) { |
|
| 164 | 164 | |
| 165 | - if( ! ( $user_id > 0 ) ){ |
|
| 165 | + if ( ! ($user_id > 0)) { |
|
| 166 | 166 | $user_id = get_current_user_id(); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // make sure the parameters are valid before continuing |
| 170 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 171 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 172 | - ||!get_userdata( $user_id ) |
|
| 173 | - || !is_array( $quiz_answers ) ){ |
|
| 170 | + if (empty($lesson_id) || empty($user_id) |
|
| 171 | + || 'lesson' != get_post_type($lesson_id) |
|
| 172 | + ||! get_userdata($user_id) |
|
| 173 | + || ! is_array($quiz_answers)) { |
|
| 174 | 174 | |
| 175 | 175 | return false; |
| 176 | 176 | |
@@ -178,23 +178,23 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | |
| 180 | 180 | // start the lesson before saving the data in case the user has not started the lesson |
| 181 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 181 | + $activity_logged = Sensei_Utils::sensei_start_lesson($lesson_id, $user_id); |
|
| 182 | 182 | |
| 183 | 183 | //prepare the answers |
| 184 | - $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); |
|
| 184 | + $prepared_answers = self::prepare_form_submitted_answers($quiz_answers, $files); |
|
| 185 | 185 | |
| 186 | 186 | // save the user data |
| 187 | - $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
| 187 | + $answers_saved = Sensei_Utils::add_user_data('quiz_answers', $lesson_id, $prepared_answers, $user_id); |
|
| 188 | 188 | |
| 189 | 189 | // were the answers saved correctly? |
| 190 | - if( intval( $answers_saved ) > 0){ |
|
| 190 | + if (intval($answers_saved) > 0) { |
|
| 191 | 191 | |
| 192 | 192 | // save transient to make retrieval faster |
| 193 | 193 | $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
| 194 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
| 194 | + set_transient($transient_key, $prepared_answers, 10 * DAY_IN_SECONDS); |
|
| 195 | 195 | |
| 196 | 196 | // update the message showed to user |
| 197 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 197 | + Sensei()->frontend->messages = '<div class="sensei-message note">'.__('Quiz Saved Successfully.', 'woothemes-sensei').'</div>'; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | return $answers_saved; |
@@ -216,41 +216,41 @@ discard block |
||
| 216 | 216 | * |
| 217 | 217 | * @return array $answers or false |
| 218 | 218 | */ |
| 219 | - public function get_user_answers( $lesson_id, $user_id ){ |
|
| 219 | + public function get_user_answers($lesson_id, $user_id) { |
|
| 220 | 220 | |
| 221 | 221 | $answers = false; |
| 222 | 222 | |
| 223 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 224 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 223 | + if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) |
|
| 224 | + || ! intval($user_id) > 0 || ! get_userdata($user_id)) { |
|
| 225 | 225 | return false; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // save some time and get the transient cached data |
| 229 | 229 | $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
| 230 | - $transient_cached_answers = get_transient( $transient_key ); |
|
| 230 | + $transient_cached_answers = get_transient($transient_key); |
|
| 231 | 231 | |
| 232 | 232 | // return the transient or get the values get the values from the comment meta |
| 233 | - if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
| 233 | + if ( ! empty($transient_cached_answers) && false != $transient_cached_answers) { |
|
| 234 | 234 | |
| 235 | 235 | $encoded_user_answers = $transient_cached_answers; |
| 236 | 236 | |
| 237 | - }else{ |
|
| 237 | + } else { |
|
| 238 | 238 | |
| 239 | - $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
| 239 | + $encoded_user_answers = Sensei_Utils::get_user_data('quiz_answers', $lesson_id, $user_id); |
|
| 240 | 240 | |
| 241 | 241 | } // end if transient check |
| 242 | 242 | |
| 243 | - if( ! is_array( $encoded_user_answers ) ){ |
|
| 243 | + if ( ! is_array($encoded_user_answers)) { |
|
| 244 | 244 | return false; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | //set the transient with the new valid data for faster retrieval in future |
| 248 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 248 | + set_transient($transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 249 | 249 | |
| 250 | 250 | // decode an unserialize all answers |
| 251 | - foreach( $encoded_user_answers as $question_id => $encoded_answer ) { |
|
| 252 | - $decoded_answer = base64_decode( $encoded_answer ); |
|
| 253 | - $answers[$question_id] = maybe_unserialize( $decoded_answer ); |
|
| 251 | + foreach ($encoded_user_answers as $question_id => $encoded_answer) { |
|
| 252 | + $decoded_answer = base64_decode($encoded_answer); |
|
| 253 | + $answers[$question_id] = maybe_unserialize($decoded_answer); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | return $answers; |
@@ -267,23 +267,23 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @return void; |
| 269 | 269 | */ |
| 270 | - public function reset_button_click_listener( ){ |
|
| 270 | + public function reset_button_click_listener( ) { |
|
| 271 | 271 | |
| 272 | - if( ! isset( $_POST[ 'quiz_reset' ]) |
|
| 273 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_reset_quiz_nonce'], 'woothemes_sensei_reset_quiz_nonce' ) > 1 ) { |
|
| 272 | + if ( ! isset($_POST['quiz_reset']) |
|
| 273 | + || ! wp_verify_nonce($_POST['woothemes_sensei_reset_quiz_nonce'], 'woothemes_sensei_reset_quiz_nonce') > 1) { |
|
| 274 | 274 | |
| 275 | 275 | return; // exit |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | global $post; |
| 279 | 279 | $current_quiz_id = $post->ID; |
| 280 | - $lesson_id = $this->get_lesson_id( $current_quiz_id ); |
|
| 280 | + $lesson_id = $this->get_lesson_id($current_quiz_id); |
|
| 281 | 281 | |
| 282 | 282 | // reset all user data |
| 283 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
| 283 | + $this->reset_user_lesson_data($lesson_id, get_current_user_id()); |
|
| 284 | 284 | |
| 285 | 285 | //this function should only run once |
| 286 | - remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
|
| 286 | + remove_action('template_redirect', array($this, 'reset_button_click_listener')); |
|
| 287 | 287 | |
| 288 | 288 | } // end reset_button_click_listener |
| 289 | 289 | |
@@ -302,18 +302,18 @@ discard block |
||
| 302 | 302 | public function user_quiz_submit_listener() { |
| 303 | 303 | |
| 304 | 304 | // only respond to valid quiz completion submissions |
| 305 | - if( ! isset( $_POST[ 'quiz_complete' ]) |
|
| 306 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 307 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 308 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
| 305 | + if ( ! isset($_POST['quiz_complete']) |
|
| 306 | + || ! isset($_POST['sensei_question']) |
|
| 307 | + || empty($_POST['sensei_question']) |
|
| 308 | + || ! wp_verify_nonce($_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce') > 1) { |
|
| 309 | 309 | return; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | global $post, $current_user; |
| 313 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 314 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 313 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
| 314 | + $quiz_answers = $_POST['sensei_question']; |
|
| 315 | 315 | |
| 316 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
| 316 | + self::submit_answers_for_grading($quiz_answers, $_FILES, $lesson_id, $current_user->ID); |
|
| 317 | 317 | |
| 318 | 318 | } // End sensei_complete_quiz() |
| 319 | 319 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | * @access public |
| 328 | 328 | * |
| 329 | 329 | */ |
| 330 | - public function load_global_quiz_data(){ |
|
| 330 | + public function load_global_quiz_data() { |
|
| 331 | 331 | |
| 332 | 332 | global $post, $current_user; |
| 333 | 333 | $this->data = new stdClass(); |
@@ -336,46 +336,46 @@ discard block |
||
| 336 | 336 | $grade = 0; |
| 337 | 337 | |
| 338 | 338 | // Get Quiz Questions |
| 339 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
| 339 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions($post->ID); |
|
| 340 | 340 | |
| 341 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
| 341 | + $quiz_lesson_id = absint(get_post_meta($post->ID, '_quiz_lesson', true)); |
|
| 342 | 342 | |
| 343 | 343 | // Get quiz grade type |
| 344 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
| 344 | + $quiz_grade_type = get_post_meta($post->ID, '_quiz_grade_type', true); |
|
| 345 | 345 | |
| 346 | 346 | // Get quiz pass setting |
| 347 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
| 347 | + $pass_required = get_post_meta($post->ID, '_pass_required', true); |
|
| 348 | 348 | |
| 349 | 349 | // Get quiz pass mark |
| 350 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
| 350 | + $quiz_passmark = abs(round(doubleval(get_post_meta($post->ID, '_quiz_passmark', true)), 2)); |
|
| 351 | 351 | |
| 352 | 352 | // Get latest quiz answers and grades |
| 353 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 354 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
| 355 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
| 353 | + $lesson_id = Sensei()->quiz->get_lesson_id($post->ID); |
|
| 354 | + $user_quizzes = Sensei()->quiz->get_user_answers($lesson_id, get_current_user_id()); |
|
| 355 | + $user_lesson_status = Sensei_Utils::user_lesson_status($quiz_lesson_id, $current_user->ID); |
|
| 356 | 356 | $user_quiz_grade = 0; |
| 357 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 358 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 357 | + if (isset($user_lesson_status->comment_ID)) { |
|
| 358 | + $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
| 361 | + if ( ! is_array($user_quizzes)) { $user_quizzes = array(); } |
|
| 362 | 362 | |
| 363 | 363 | // Check again that the lesson is complete |
| 364 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 364 | + $user_lesson_end = Sensei_Utils::user_completed_lesson($user_lesson_status); |
|
| 365 | 365 | $user_lesson_complete = false; |
| 366 | - if ( $user_lesson_end ) { |
|
| 366 | + if ($user_lesson_end) { |
|
| 367 | 367 | $user_lesson_complete = true; |
| 368 | 368 | } // End If Statement |
| 369 | 369 | |
| 370 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
| 370 | + $reset_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true); |
|
| 371 | 371 | //backwards compatibility |
| 372 | - if( 'on' == $reset_allowed ) { |
|
| 372 | + if ('on' == $reset_allowed) { |
|
| 373 | 373 | $reset_allowed = 1; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | // Build frontend data object for backwards compatibility |
| 377 | 377 | // using this is no longer recommended |
| 378 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 378 | + $this->data->user_quiz_grade = $user_quiz_grade; // Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 379 | 379 | $this->data->quiz_passmark = $quiz_passmark; |
| 380 | 380 | $this->data->quiz_lesson = $quiz_lesson_id; |
| 381 | 381 | $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
@@ -400,41 +400,41 @@ discard block |
||
| 400 | 400 | * @param $files |
| 401 | 401 | * @return array |
| 402 | 402 | */ |
| 403 | - public static function prepare_form_submitted_answers( $unprepared_answers, $files ){ |
|
| 403 | + public static function prepare_form_submitted_answers($unprepared_answers, $files) { |
|
| 404 | 404 | |
| 405 | 405 | |
| 406 | 406 | $prepared_answers = array(); |
| 407 | 407 | |
| 408 | 408 | // validate incoming answers |
| 409 | - if( empty( $unprepared_answers ) || ! is_array( $unprepared_answers ) ){ |
|
| 409 | + if (empty($unprepared_answers) || ! is_array($unprepared_answers)) { |
|
| 410 | 410 | return false; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | // Loop through submitted quiz answers and save them appropriately |
| 414 | - foreach( $unprepared_answers as $question_id => $answer ) { |
|
| 414 | + foreach ($unprepared_answers as $question_id => $answer) { |
|
| 415 | 415 | |
| 416 | 416 | //get the current questions question type |
| 417 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 417 | + $question_type = Sensei()->question->get_question_type($question_id); |
|
| 418 | 418 | |
| 419 | 419 | // Sanitise answer |
| 420 | - if( 0 == get_magic_quotes_gpc() ) { |
|
| 421 | - $answer = wp_unslash( $answer ); |
|
| 420 | + if (0 == get_magic_quotes_gpc()) { |
|
| 421 | + $answer = wp_unslash($answer); |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | // compress the answer for saving |
| 425 | - if( 'multi-line' == $question_type ) { |
|
| 426 | - $answer = esc_html( $answer ); |
|
| 427 | - }elseif( 'file-upload' == $question_type ){ |
|
| 428 | - $file_key = 'file_upload_' . $question_id; |
|
| 429 | - if( isset( $files[ $file_key ] ) ) { |
|
| 430 | - $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
| 431 | - if( $attachment_id ) { |
|
| 425 | + if ('multi-line' == $question_type) { |
|
| 426 | + $answer = esc_html($answer); |
|
| 427 | + }elseif ('file-upload' == $question_type) { |
|
| 428 | + $file_key = 'file_upload_'.$question_id; |
|
| 429 | + if (isset($files[$file_key])) { |
|
| 430 | + $attachment_id = Sensei_Utils::upload_file($files[$file_key]); |
|
| 431 | + if ($attachment_id) { |
|
| 432 | 432 | $answer = $attachment_id; |
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | } // end if |
| 436 | 436 | |
| 437 | - $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); |
|
| 437 | + $prepared_answers[$question_id] = base64_encode(maybe_serialize($answer)); |
|
| 438 | 438 | |
| 439 | 439 | }// end for each $quiz_answers |
| 440 | 440 | |
@@ -454,54 +454,54 @@ discard block |
||
| 454 | 454 | * @param int $user_id |
| 455 | 455 | * @param int $lesson_id |
| 456 | 456 | */ |
| 457 | - public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
| 457 | + public function reset_user_lesson_data($lesson_id, $user_id = 0) { |
|
| 458 | 458 | |
| 459 | 459 | //make sure the parameters are valid |
| 460 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 461 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 462 | - || ! get_userdata( $user_id ) ){ |
|
| 460 | + if (empty($lesson_id) || empty($user_id) |
|
| 461 | + || 'lesson' != get_post_type($lesson_id) |
|
| 462 | + || ! get_userdata($user_id)) { |
|
| 463 | 463 | return false; |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
| 467 | 467 | |
| 468 | 468 | //get the users lesson status to make |
| 469 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 470 | - if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
| 469 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 470 | + if ( ! isset($user_lesson_status->comment_ID)) { |
|
| 471 | 471 | // this user is not taking this lesson so this process is not needed |
| 472 | 472 | return false; |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | //get the lesson quiz and course |
| 476 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 477 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 476 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 477 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
| 478 | 478 | |
| 479 | 479 | // reset the transients |
| 480 | 480 | $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
| 481 | 481 | $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
| 482 | 482 | $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
| 483 | - delete_transient( $answers_transient_key ); |
|
| 484 | - delete_transient( $grades_transient_key ); |
|
| 485 | - delete_transient( $answers_feedback_transient_key ); |
|
| 483 | + delete_transient($answers_transient_key); |
|
| 484 | + delete_transient($grades_transient_key); |
|
| 485 | + delete_transient($answers_feedback_transient_key); |
|
| 486 | 486 | |
| 487 | 487 | // reset the quiz answers and feedback notes |
| 488 | - $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
| 489 | - $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 490 | - $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 488 | + $deleted_answers = Sensei_Utils::delete_user_data('quiz_answers', $lesson_id, $user_id); |
|
| 489 | + $deleted_grades = Sensei_Utils::delete_user_data('quiz_grades', $lesson_id, $user_id); |
|
| 490 | + $deleted_user_feedback = Sensei_Utils::delete_user_data('quiz_answers_feedback', $lesson_id, $user_id); |
|
| 491 | 491 | |
| 492 | 492 | // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
| 493 | - Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
| 493 | + Sensei_Utils::sensei_delete_quiz_answers($quiz_id, $user_id); |
|
| 494 | 494 | |
| 495 | - Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
| 495 | + Sensei_Utils::update_lesson_status($user_id, $lesson_id, 'in-progress', array('questions_asked' => '', 'grade' => '')); |
|
| 496 | 496 | |
| 497 | 497 | // Update course completion |
| 498 | - Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
| 498 | + Sensei_Utils::update_course_status($user_id, $course_id); |
|
| 499 | 499 | |
| 500 | 500 | // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
| 501 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 502 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 501 | + do_action('sensei_user_lesson_reset', $user_id, $lesson_id); |
|
| 502 | + Sensei()->frontend->messages = '<div class="sensei-message note">'.__('Quiz Reset Successfully.', 'woothemes-sensei').'</div>'; |
|
| 503 | 503 | |
| 504 | - return ( $deleted_answers && $deleted_grades ) ; |
|
| 504 | + return ($deleted_answers && $deleted_grades); |
|
| 505 | 505 | |
| 506 | 506 | } // end reset_user_lesson_data |
| 507 | 507 | |
@@ -521,20 +521,20 @@ discard block |
||
| 521 | 521 | * |
| 522 | 522 | * @return bool $answers_submitted |
| 523 | 523 | */ |
| 524 | - public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
| 524 | + public static function submit_answers_for_grading($quiz_answers, $files = array(), $lesson_id, $user_id = 0) { |
|
| 525 | 525 | |
| 526 | 526 | $answers_submitted = false; |
| 527 | 527 | |
| 528 | 528 | // get the user_id if none was passed in use the current logged in user |
| 529 | - if( ! intval( $user_id ) > 0 ) { |
|
| 529 | + if ( ! intval($user_id) > 0) { |
|
| 530 | 530 | $user_id = get_current_user_id(); |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | // make sure the parameters are valid before continuing |
| 534 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 535 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 536 | - ||!get_userdata( $user_id ) |
|
| 537 | - || !is_array( $quiz_answers ) ){ |
|
| 534 | + if (empty($lesson_id) || empty($user_id) |
|
| 535 | + || 'lesson' != get_post_type($lesson_id) |
|
| 536 | + ||! get_userdata($user_id) |
|
| 537 | + || ! is_array($quiz_answers)) { |
|
| 538 | 538 | |
| 539 | 539 | return false; |
| 540 | 540 | |
@@ -544,38 +544,38 @@ discard block |
||
| 544 | 544 | $grade = 0; |
| 545 | 545 | |
| 546 | 546 | // Get Quiz ID |
| 547 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 547 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 548 | 548 | |
| 549 | 549 | // Get quiz grade type |
| 550 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 550 | + $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); |
|
| 551 | 551 | |
| 552 | 552 | // Get quiz pass setting |
| 553 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 553 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
| 554 | 554 | |
| 555 | 555 | // Get the minimum percentage need to pass this quiz |
| 556 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 556 | + $quiz_pass_percentage = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); |
|
| 557 | 557 | |
| 558 | 558 | // Handle Quiz Questions asked |
| 559 | 559 | // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
| 560 | 560 | // the quiz is reset by admin or user( user: only if the setting is enabled ). |
| 561 | 561 | // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
| 562 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 563 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
| 564 | - if( empty( $questions_asked ) ){ |
|
| 562 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 563 | + $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true); |
|
| 564 | + if (empty($questions_asked)) { |
|
| 565 | 565 | |
| 566 | - $questions_asked = array_keys( $quiz_answers ); |
|
| 567 | - $questions_asked_string = implode( ',', $questions_asked ); |
|
| 566 | + $questions_asked = array_keys($quiz_answers); |
|
| 567 | + $questions_asked_string = implode(',', $questions_asked); |
|
| 568 | 568 | |
| 569 | 569 | // Save questions that were asked in this quiz |
| 570 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
| 570 | + update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string); |
|
| 571 | 571 | |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
| 575 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
| 575 | + self::save_user_answers($quiz_answers, $files, $lesson_id, $user_id); |
|
| 576 | 576 | |
| 577 | 577 | // Grade quiz |
| 578 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
| 578 | + $grade = Sensei_Grading::grade_quiz_auto($quiz_id, $quiz_answers, 0, $quiz_grade_type); |
|
| 579 | 579 | |
| 580 | 580 | // Get Lesson Grading Setting |
| 581 | 581 | $lesson_metadata = array(); |
@@ -585,13 +585,13 @@ discard block |
||
| 585 | 585 | $answers_submitted = true; |
| 586 | 586 | |
| 587 | 587 | // if this condition is false the quiz should manually be graded by admin |
| 588 | - if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
| 588 | + if ('auto' == $quiz_grade_type && ! is_wp_error($grade)) { |
|
| 589 | 589 | |
| 590 | 590 | // Quiz has been automatically Graded |
| 591 | - if ( 'on' == $pass_required ) { |
|
| 591 | + if ('on' == $pass_required) { |
|
| 592 | 592 | |
| 593 | 593 | // Student has reached the pass mark and lesson is complete |
| 594 | - if ( $quiz_pass_percentage <= $grade ) { |
|
| 594 | + if ($quiz_pass_percentage <= $grade) { |
|
| 595 | 595 | |
| 596 | 596 | $lesson_status = 'passed'; |
| 597 | 597 | |
@@ -612,9 +612,9 @@ discard block |
||
| 612 | 612 | |
| 613 | 613 | } // end if ! is_wp_error( $grade ... |
| 614 | 614 | |
| 615 | - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
| 615 | + Sensei_Utils::update_lesson_status($user_id, $lesson_id, $lesson_status, $lesson_metadata); |
|
| 616 | 616 | |
| 617 | - if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
| 617 | + if ('passed' == $lesson_status || 'graded' == $lesson_status) { |
|
| 618 | 618 | |
| 619 | 619 | /** |
| 620 | 620 | * Lesson end action hook |
@@ -624,7 +624,7 @@ discard block |
||
| 624 | 624 | * @param int $user_id |
| 625 | 625 | * @param int $lesson_id |
| 626 | 626 | */ |
| 627 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 627 | + do_action('sensei_user_lesson_end', $user_id, $lesson_id); |
|
| 628 | 628 | |
| 629 | 629 | } |
| 630 | 630 | |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | * @param string $quiz_pass_percentage |
| 641 | 641 | * @param string $quiz_grade_type |
| 642 | 642 | */ |
| 643 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
| 643 | + do_action('sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type); |
|
| 644 | 644 | |
| 645 | 645 | return $answers_submitted; |
| 646 | 646 | |
@@ -660,38 +660,38 @@ discard block |
||
| 660 | 660 | * |
| 661 | 661 | * @return bool $answers_submitted |
| 662 | 662 | */ |
| 663 | - public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 663 | + public function get_user_question_answer($lesson_id, $question_id, $user_id = 0) { |
|
| 664 | 664 | |
| 665 | 665 | // parameter validation |
| 666 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 667 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 668 | - || ! ( intval( $question_id ) > 0 ) |
|
| 669 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 670 | - || 'question' != get_post_type( $question_id )) { |
|
| 666 | + if (empty($lesson_id) || empty($question_id) |
|
| 667 | + || ! (intval($lesson_id) > 0) |
|
| 668 | + || ! (intval($question_id) > 0) |
|
| 669 | + || 'lesson' != get_post_type($lesson_id) |
|
| 670 | + || 'question' != get_post_type($question_id)) { |
|
| 671 | 671 | |
| 672 | 672 | return false; |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - if( ! ( intval( $user_id ) > 0 ) ){ |
|
| 675 | + if ( ! (intval($user_id) > 0)) { |
|
| 676 | 676 | $user_id = get_current_user_id(); |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
| 679 | + $users_answers = $this->get_user_answers($lesson_id, $user_id); |
|
| 680 | 680 | |
| 681 | - if( !$users_answers || empty( $users_answers ) |
|
| 682 | - || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
| 681 | + if ( ! $users_answers || empty($users_answers) |
|
| 682 | + || ! is_array($users_answers) || ! isset($users_answers[$question_id])) { |
|
| 683 | 683 | |
| 684 | 684 | //Fallback for pre 1.7.4 data |
| 685 | - $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
| 685 | + $comment = Sensei_Utils::sensei_check_for_activity(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer'), true); |
|
| 686 | 686 | |
| 687 | - if( ! isset( $comment->comment_content ) ){ |
|
| 687 | + if ( ! isset($comment->comment_content)) { |
|
| 688 | 688 | return false; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 691 | + return maybe_unserialize(base64_decode($comment->comment_content)); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | - return $users_answers[ $question_id ]; |
|
| 694 | + return $users_answers[$question_id]; |
|
| 695 | 695 | |
| 696 | 696 | }// end get_user_question_answer |
| 697 | 697 | |
@@ -712,18 +712,18 @@ discard block |
||
| 712 | 712 | * |
| 713 | 713 | * @return bool |
| 714 | 714 | */ |
| 715 | - public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
| 715 | + public function set_user_grades($quiz_grades, $lesson_id, $user_id = 0) { |
|
| 716 | 716 | |
| 717 | 717 | // get the user_id if none was passed in use the current logged in user |
| 718 | - if( ! intval( $user_id ) > 0 ) { |
|
| 718 | + if ( ! intval($user_id) > 0) { |
|
| 719 | 719 | $user_id = get_current_user_id(); |
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | // make sure the parameters are valid before continuing |
| 723 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 724 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 725 | - ||!get_userdata( $user_id ) |
|
| 726 | - || !is_array( $quiz_grades ) ){ |
|
| 723 | + if (empty($lesson_id) || empty($user_id) |
|
| 724 | + || 'lesson' != get_post_type($lesson_id) |
|
| 725 | + ||! get_userdata($user_id) |
|
| 726 | + || ! is_array($quiz_grades)) { |
|
| 727 | 727 | |
| 728 | 728 | return false; |
| 729 | 729 | |
@@ -732,15 +732,15 @@ discard block |
||
| 732 | 732 | $success = false; |
| 733 | 733 | |
| 734 | 734 | // save that data for the user on the lesson comment meta |
| 735 | - $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
| 735 | + $comment_meta_id = Sensei_Utils::add_user_data('quiz_grades', $lesson_id, $quiz_grades, $user_id); |
|
| 736 | 736 | |
| 737 | 737 | // were the grades save successfully ? |
| 738 | - if( intval( $comment_meta_id ) > 0 ) { |
|
| 738 | + if (intval($comment_meta_id) > 0) { |
|
| 739 | 739 | |
| 740 | 740 | $success = true; |
| 741 | 741 | // save transient |
| 742 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 743 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
| 742 | + $transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 743 | + set_transient($transient_key, $quiz_grades, 10 * DAY_IN_SECONDS); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | return $success; |
@@ -759,36 +759,36 @@ discard block |
||
| 759 | 759 | * |
| 760 | 760 | * @return array $user_quiz_grades or false if none exists for this users |
| 761 | 761 | */ |
| 762 | - public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
| 762 | + public function get_user_grades($lesson_id, $user_id = 0) { |
|
| 763 | 763 | |
| 764 | 764 | $user_grades = array(); |
| 765 | 765 | |
| 766 | 766 | // get the user_id if none was passed in use the current logged in user |
| 767 | - if( ! intval( $user_id ) > 0 ) { |
|
| 767 | + if ( ! intval($user_id) > 0) { |
|
| 768 | 768 | $user_id = get_current_user_id(); |
| 769 | 769 | } |
| 770 | 770 | |
| 771 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 772 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 771 | + if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) |
|
| 772 | + || ! intval($user_id) > 0 || ! get_userdata($user_id)) { |
|
| 773 | 773 | return false; |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | // save some time and get the transient cached data |
| 777 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 778 | - $user_grades = get_transient( $transient_key ); |
|
| 777 | + $transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 778 | + $user_grades = get_transient($transient_key); |
|
| 779 | 779 | |
| 780 | 780 | // get the data if nothing was stored in the transient |
| 781 | - if( empty( $user_grades ) || false != $user_grades ){ |
|
| 781 | + if (empty($user_grades) || false != $user_grades) { |
|
| 782 | 782 | |
| 783 | - $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 783 | + $user_grades = Sensei_Utils::get_user_data('quiz_grades', $lesson_id, $user_id); |
|
| 784 | 784 | |
| 785 | 785 | //set the transient with the new valid data for faster retrieval in future |
| 786 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
| 786 | + set_transient($transient_key, $user_grades, 10 * DAY_IN_SECONDS); |
|
| 787 | 787 | |
| 788 | 788 | } // end if transient check |
| 789 | 789 | |
| 790 | 790 | // if there is no data for this user |
| 791 | - if( ! is_array( $user_grades ) ){ |
|
| 791 | + if ( ! is_array($user_grades)) { |
|
| 792 | 792 | return false; |
| 793 | 793 | } |
| 794 | 794 | |
@@ -811,21 +811,21 @@ discard block |
||
| 811 | 811 | * |
| 812 | 812 | * @return bool $question_grade |
| 813 | 813 | */ |
| 814 | - public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 814 | + public function get_user_question_grade($lesson_id, $question_id, $user_id = 0) { |
|
| 815 | 815 | |
| 816 | 816 | // parameter validation |
| 817 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 818 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 819 | - || ! ( intval( $question_id ) > 0 ) |
|
| 820 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 821 | - || 'question' != get_post_type( $question_id )) { |
|
| 817 | + if (empty($lesson_id) || empty($question_id) |
|
| 818 | + || ! (intval($lesson_id) > 0) |
|
| 819 | + || ! (intval($question_id) > 0) |
|
| 820 | + || 'lesson' != get_post_type($lesson_id) |
|
| 821 | + || 'question' != get_post_type($question_id)) { |
|
| 822 | 822 | |
| 823 | 823 | return false; |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
| 826 | + $all_user_grades = self::get_user_grades($lesson_id, $user_id); |
|
| 827 | 827 | |
| 828 | - if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
| 828 | + if ( ! $all_user_grades || ! isset($all_user_grades[$question_id])) { |
|
| 829 | 829 | |
| 830 | 830 | //fallback to data pre 1.7.4 |
| 831 | 831 | $args = array( |
@@ -834,17 +834,17 @@ discard block |
||
| 834 | 834 | 'type' => 'sensei_user_answer' |
| 835 | 835 | ); |
| 836 | 836 | |
| 837 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 837 | + $question_activity = Sensei_Utils::sensei_check_for_activity($args, true); |
|
| 838 | 838 | $fall_back_grade = false; |
| 839 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 840 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
| 839 | + if (isset($question_activity->comment_ID)) { |
|
| 840 | + $fall_back_grade = get_comment_meta($question_activity->comment_ID, 'user_grade', true); |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | return $fall_back_grade; |
| 844 | 844 | |
| 845 | 845 | } // end if $all_user_grades... |
| 846 | 846 | |
| 847 | - return $all_user_grades[ $question_id ]; |
|
| 847 | + return $all_user_grades[$question_id]; |
|
| 848 | 848 | |
| 849 | 849 | }// end get_user_question_grade |
| 850 | 850 | |
@@ -866,13 +866,13 @@ discard block |
||
| 866 | 866 | * |
| 867 | 867 | * @return false or int $feedback_saved |
| 868 | 868 | */ |
| 869 | - public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
| 869 | + public function save_user_answers_feedback($answers_feedback, $lesson_id, $user_id = 0) { |
|
| 870 | 870 | |
| 871 | 871 | // make sure the parameters are valid before continuing |
| 872 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 873 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 874 | - ||!get_userdata( $user_id ) |
|
| 875 | - || !is_array( $answers_feedback ) ){ |
|
| 872 | + if (empty($lesson_id) || empty($user_id) |
|
| 873 | + || 'lesson' != get_post_type($lesson_id) |
|
| 874 | + ||! get_userdata($user_id) |
|
| 875 | + || ! is_array($answers_feedback)) { |
|
| 876 | 876 | |
| 877 | 877 | return false; |
| 878 | 878 | |
@@ -880,25 +880,25 @@ discard block |
||
| 880 | 880 | |
| 881 | 881 | |
| 882 | 882 | // check if the lesson is started before saving, if not start the lesson for the user |
| 883 | - if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
| 884 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 883 | + if ( ! (0 < intval(Sensei_Utils::user_started_lesson($lesson_id, $user_id)))) { |
|
| 884 | + Sensei_Utils::sensei_start_lesson($lesson_id, $user_id); |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | // encode the feedback |
| 888 | - $encoded_answers_feedback = array(); |
|
| 889 | - foreach( $answers_feedback as $question_id => $feedback ){ |
|
| 890 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
| 888 | + $encoded_answers_feedback = array(); |
|
| 889 | + foreach ($answers_feedback as $question_id => $feedback) { |
|
| 890 | + $encoded_answers_feedback[$question_id] = base64_encode($feedback); |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | // save the user data |
| 894 | - $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
| 894 | + $feedback_saved = Sensei_Utils::add_user_data('quiz_answers_feedback', $lesson_id, $encoded_answers_feedback, $user_id); |
|
| 895 | 895 | |
| 896 | 896 | //Were the the question feedback save correctly? |
| 897 | - if( intval( $feedback_saved ) > 0){ |
|
| 897 | + if (intval($feedback_saved) > 0) { |
|
| 898 | 898 | |
| 899 | 899 | // save transient to make retrieval faster in future |
| 900 | 900 | $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
| 901 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
| 901 | + set_transient($transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS); |
|
| 902 | 902 | |
| 903 | 903 | } |
| 904 | 904 | |
@@ -923,42 +923,42 @@ discard block |
||
| 923 | 923 | * $type string $question_feedback |
| 924 | 924 | * } |
| 925 | 925 | */ |
| 926 | - public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
| 926 | + public function get_user_answers_feedback($lesson_id, $user_id = 0) { |
|
| 927 | 927 | |
| 928 | 928 | $answers_feedback = array(); |
| 929 | 929 | |
| 930 | 930 | // get the user_id if none was passed in use the current logged in user |
| 931 | - if( ! intval( $user_id ) > 0 ) { |
|
| 931 | + if ( ! intval($user_id) > 0) { |
|
| 932 | 932 | $user_id = get_current_user_id(); |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 936 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 935 | + if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) |
|
| 936 | + || ! intval($user_id) > 0 || ! get_userdata($user_id)) { |
|
| 937 | 937 | return false; |
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | // first check the transient to save a few split seconds |
| 941 | 941 | $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
| 942 | - $encoded_feedback = get_transient( $transient_key ); |
|
| 942 | + $encoded_feedback = get_transient($transient_key); |
|
| 943 | 943 | |
| 944 | 944 | // get the data if nothing was stored in the transient |
| 945 | - if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
| 945 | + if (empty($encoded_feedback) || ! $encoded_feedback) { |
|
| 946 | 946 | |
| 947 | - $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 947 | + $encoded_feedback = Sensei_Utils::get_user_data('quiz_answers_feedback', $lesson_id, $user_id); |
|
| 948 | 948 | |
| 949 | 949 | //set the transient with the new valid data for faster retrieval in future |
| 950 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 950 | + set_transient($transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 951 | 951 | |
| 952 | 952 | } // end if transient check |
| 953 | 953 | |
| 954 | 954 | // if there is no data for this user |
| 955 | - if( ! is_array( $encoded_feedback ) ){ |
|
| 955 | + if ( ! is_array($encoded_feedback)) { |
|
| 956 | 956 | return false; |
| 957 | 957 | } |
| 958 | 958 | |
| 959 | - foreach( $encoded_feedback as $question_id => $feedback ){ |
|
| 959 | + foreach ($encoded_feedback as $question_id => $feedback) { |
|
| 960 | 960 | |
| 961 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
| 961 | + $answers_feedback[$question_id] = base64_decode($feedback); |
|
| 962 | 962 | |
| 963 | 963 | } |
| 964 | 964 | |
@@ -981,25 +981,25 @@ discard block |
||
| 981 | 981 | * |
| 982 | 982 | * @return string $feedback or bool if false |
| 983 | 983 | */ |
| 984 | - public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 984 | + public function get_user_question_feedback($lesson_id, $question_id, $user_id = 0) { |
|
| 985 | 985 | |
| 986 | 986 | $feedback = false; |
| 987 | 987 | |
| 988 | 988 | // parameter validation |
| 989 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 990 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 991 | - || ! ( intval( $question_id ) > 0 ) |
|
| 992 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 993 | - || 'question' != get_post_type( $question_id )) { |
|
| 989 | + if (empty($lesson_id) || empty($question_id) |
|
| 990 | + || ! (intval($lesson_id) > 0) |
|
| 991 | + || ! (intval($question_id) > 0) |
|
| 992 | + || 'lesson' != get_post_type($lesson_id) |
|
| 993 | + || 'question' != get_post_type($question_id)) { |
|
| 994 | 994 | |
| 995 | 995 | return false; |
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | // get all the feedback for the user on the given lesson |
| 999 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
| 999 | + $all_feedback = $this->get_user_answers_feedback($lesson_id, $user_id); |
|
| 1000 | 1000 | |
| 1001 | - if( !$all_feedback || empty( $all_feedback ) |
|
| 1002 | - || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
| 1001 | + if ( ! $all_feedback || empty($all_feedback) |
|
| 1002 | + || ! is_array($all_feedback) || ! isset($all_feedback[$question_id])) { |
|
| 1003 | 1003 | |
| 1004 | 1004 | //fallback to data pre 1.7.4 |
| 1005 | 1005 | |
@@ -1009,23 +1009,23 @@ discard block |
||
| 1009 | 1009 | 'user_id' => $user_id, |
| 1010 | 1010 | 'type' => 'sensei_user_answer' |
| 1011 | 1011 | ); |
| 1012 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 1012 | + $question_activity = Sensei_Utils::sensei_check_for_activity($args, true); |
|
| 1013 | 1013 | |
| 1014 | 1014 | // set the default to false and return that if no old data is available. |
| 1015 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 1016 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
| 1015 | + if (isset($question_activity->comment_ID)) { |
|
| 1016 | + $feedback = base64_decode(get_comment_meta($question_activity->comment_ID, 'answer_note', true)); |
|
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | 1019 | // finally use the default question feedback |
| 1020 | - if( empty( $feedback ) ){ |
|
| 1021 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 1020 | + if (empty($feedback)) { |
|
| 1021 | + $feedback = get_post_meta($question_id, '_answer_feedback', true); |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | return $feedback; |
| 1025 | 1025 | |
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | - return $all_feedback[ $question_id ]; |
|
| 1028 | + return $all_feedback[$question_id]; |
|
| 1029 | 1029 | |
| 1030 | 1030 | } // end get_user_question_feedback |
| 1031 | 1031 | |
@@ -1044,7 +1044,7 @@ discard block |
||
| 1044 | 1044 | public function quiz_has_no_questions() { |
| 1045 | 1045 | |
| 1046 | 1046 | |
| 1047 | - if( ! is_singular( 'quiz' ) ) { |
|
| 1047 | + if ( ! is_singular('quiz')) { |
|
| 1048 | 1048 | return; |
| 1049 | 1049 | } |
| 1050 | 1050 | |
@@ -1052,11 +1052,11 @@ discard block |
||
| 1052 | 1052 | |
| 1053 | 1053 | $lesson_id = $this->get_lesson_id($post->ID); |
| 1054 | 1054 | |
| 1055 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1055 | + $has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true); |
|
| 1056 | 1056 | |
| 1057 | 1057 | $lesson = get_post($lesson_id); |
| 1058 | 1058 | |
| 1059 | - if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
| 1059 | + if (is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name") { |
|
| 1060 | 1060 | |
| 1061 | 1061 | wp_redirect(get_permalink($lesson->ID), 301); |
| 1062 | 1062 | exit; |
@@ -1070,7 +1070,7 @@ discard block |
||
| 1070 | 1070 | * |
| 1071 | 1071 | * @deprecated since 1.9.0 |
| 1072 | 1072 | */ |
| 1073 | - public static function deprecate_quiz_sensei_single_main_content_hook(){ |
|
| 1073 | + public static function deprecate_quiz_sensei_single_main_content_hook() { |
|
| 1074 | 1074 | |
| 1075 | 1075 | sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
| 1076 | 1076 | |
@@ -1080,7 +1080,7 @@ discard block |
||
| 1080 | 1080 | * |
| 1081 | 1081 | * @deprecated since 1.9.0 |
| 1082 | 1082 | */ |
| 1083 | - public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
| 1083 | + public static function deprecate_quiz_sensei_quiz_single_title_hook() { |
|
| 1084 | 1084 | |
| 1085 | 1085 | sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
| 1086 | 1086 | |
@@ -1093,29 +1093,29 @@ discard block |
||
| 1093 | 1093 | * @param int $id title post id |
| 1094 | 1094 | * @return string $quiz_title |
| 1095 | 1095 | */ |
| 1096 | - public static function single_quiz_title( $title, $post_id ){ |
|
| 1096 | + public static function single_quiz_title($title, $post_id) { |
|
| 1097 | 1097 | |
| 1098 | - if( 'quiz' == get_post_type( $post_id ) ){ |
|
| 1098 | + if ('quiz' == get_post_type($post_id)) { |
|
| 1099 | 1099 | |
| 1100 | 1100 | $title_with_no_quizzes = $title; |
| 1101 | 1101 | |
| 1102 | 1102 | // if the title has quiz, remove it: legacy titles have the word quiz stored. |
| 1103 | - if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
| 1103 | + if (1 < substr_count(strtoupper($title_with_no_quizzes), 'QUIZ')) { |
|
| 1104 | 1104 | |
| 1105 | 1105 | // remove all possible appearances of quiz |
| 1106 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
| 1107 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
| 1108 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
| 1106 | + $title_with_no_quizzes = str_replace('quiz', '', $title); |
|
| 1107 | + $title_with_no_quizzes = str_replace('Quiz', '', $title_with_no_quizzes); |
|
| 1108 | + $title_with_no_quizzes = str_replace('QUIZ', '', $title_with_no_quizzes); |
|
| 1109 | 1109 | |
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
| 1112 | + $title = $title_with_no_quizzes.' '.__('Quiz', 'woothemes-sensei'); |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | /** |
| 1116 | 1116 | * hook document in class-woothemes-sensei-message.php |
| 1117 | 1117 | */ |
| 1118 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
| 1118 | + return apply_filters('sensei_single_title', $title, get_post_type( )); |
|
| 1119 | 1119 | |
| 1120 | 1120 | } |
| 1121 | 1121 | |
@@ -1127,21 +1127,21 @@ discard block |
||
| 1127 | 1127 | * @since 1.9.0 |
| 1128 | 1128 | * |
| 1129 | 1129 | */ |
| 1130 | - public static function start_quiz_questions_loop(){ |
|
| 1130 | + public static function start_quiz_questions_loop() { |
|
| 1131 | 1131 | |
| 1132 | 1132 | global $sensei_question_loop; |
| 1133 | 1133 | |
| 1134 | 1134 | //intialize the questions loop object |
| 1135 | 1135 | $sensei_question_loop['current'] = -1; |
| 1136 | - $sensei_question_loop['total'] = 0; |
|
| 1136 | + $sensei_question_loop['total'] = 0; |
|
| 1137 | 1137 | $sensei_question_loop['questions'] = array(); |
| 1138 | 1138 | |
| 1139 | 1139 | |
| 1140 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
| 1140 | + $questions = Sensei()->lesson->lesson_quiz_questions(get_the_ID()); |
|
| 1141 | 1141 | |
| 1142 | - if( count( $questions ) > 0 ){ |
|
| 1142 | + if (count($questions) > 0) { |
|
| 1143 | 1143 | |
| 1144 | - $sensei_question_loop['total'] = count( $questions ); |
|
| 1144 | + $sensei_question_loop['total'] = count($questions); |
|
| 1145 | 1145 | $sensei_question_loop['questions'] = $questions; |
| 1146 | 1146 | $sensei_question_loop['quiz_id'] = get_the_ID(); |
| 1147 | 1147 | |
@@ -1157,9 +1157,9 @@ discard block |
||
| 1157 | 1157 | * @since 1.9.0 |
| 1158 | 1158 | * |
| 1159 | 1159 | */ |
| 1160 | - public static function stop_quiz_questions_loop(){ |
|
| 1160 | + public static function stop_quiz_questions_loop() { |
|
| 1161 | 1161 | |
| 1162 | - $sensei_question_loop['total'] = 0; |
|
| 1162 | + $sensei_question_loop['total'] = 0; |
|
| 1163 | 1163 | $sensei_question_loop['questions'] = array(); |
| 1164 | 1164 | $sensei_question_loop['quiz_id'] = ''; |
| 1165 | 1165 | |
@@ -1170,7 +1170,7 @@ discard block |
||
| 1170 | 1170 | * |
| 1171 | 1171 | * @since 1.9.0 |
| 1172 | 1172 | */ |
| 1173 | - public static function the_title(){ |
|
| 1173 | + public static function the_title() { |
|
| 1174 | 1174 | ?> |
| 1175 | 1175 | <header> |
| 1176 | 1176 | |
@@ -1180,7 +1180,7 @@ discard block |
||
| 1180 | 1180 | /** |
| 1181 | 1181 | * Filter documented in class-sensei-messages.php the_title |
| 1182 | 1182 | */ |
| 1183 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
| 1183 | + echo apply_filters('sensei_single_title', get_the_title(get_post()), get_post_type(get_the_ID())); |
|
| 1184 | 1184 | ?> |
| 1185 | 1185 | |
| 1186 | 1186 | </h1> |
@@ -1195,11 +1195,11 @@ discard block |
||
| 1195 | 1195 | * |
| 1196 | 1196 | * @param $quiz_id |
| 1197 | 1197 | */ |
| 1198 | - public static function the_user_status_message( $quiz_id ){ |
|
| 1198 | + public static function the_user_status_message($quiz_id) { |
|
| 1199 | 1199 | |
| 1200 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 1201 | - $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
| 1202 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 1200 | + $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id); |
|
| 1201 | + $status = Sensei_Utils::sensei_user_quiz_status_message($lesson_id, get_current_user_id()); |
|
| 1202 | + echo '<div class="sensei-message '.$status['box_class'].'">'.$status['message'].'</div>'; |
|
| 1203 | 1203 | |
| 1204 | 1204 | } |
| 1205 | 1205 | |
@@ -1210,9 +1210,9 @@ discard block |
||
| 1210 | 1210 | * @since 1.9.0 |
| 1211 | 1211 | * @deprecated |
| 1212 | 1212 | */ |
| 1213 | - public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
| 1213 | + public static function deprecate_sensei_quiz_action_buttons_hook() { |
|
| 1214 | 1214 | |
| 1215 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1215 | + sensei_do_deprecated_action('sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1216 | 1216 | |
| 1217 | 1217 | } |
| 1218 | 1218 | |
@@ -1226,50 +1226,50 @@ discard block |
||
| 1226 | 1226 | |
| 1227 | 1227 | global $post, $current_user; |
| 1228 | 1228 | |
| 1229 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
| 1230 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 1231 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1229 | + $lesson_id = (int) get_post_meta($post->ID, '_quiz_lesson', true); |
|
| 1230 | + $lesson_course_id = (int) get_post_meta($lesson_id, '_lesson_course', true); |
|
| 1231 | + $lesson_prerequisite = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true); |
|
| 1232 | 1232 | $show_actions = true; |
| 1233 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
| 1233 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $current_user->ID); |
|
| 1234 | 1234 | |
| 1235 | 1235 | //setup quiz grade |
| 1236 | 1236 | $user_quiz_grade = ''; |
| 1237 | - if( ! empty( $user_lesson_status ) ){ |
|
| 1238 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1237 | + if ( ! empty($user_lesson_status)) { |
|
| 1238 | + $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | |
| 1242 | - if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 1242 | + if (intval($lesson_prerequisite) > 0) { |
|
| 1243 | 1243 | |
| 1244 | 1244 | // If the user hasn't completed the prereq then hide the current actions |
| 1245 | - $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
| 1245 | + $show_actions = Sensei_Utils::user_completed_lesson($lesson_prerequisite, $current_user->ID); |
|
| 1246 | 1246 | |
| 1247 | 1247 | } |
| 1248 | - if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 1248 | + if ($show_actions && is_user_logged_in() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) { |
|
| 1249 | 1249 | |
| 1250 | 1250 | // Get Reset Settings |
| 1251 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
| 1251 | + $reset_quiz_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true); ?> |
|
| 1252 | 1252 | |
| 1253 | 1253 | <!-- Action Nonce's --> |
| 1254 | 1254 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" |
| 1255 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_complete_quiz_nonce' ) ); ?>" /> |
|
| 1255 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_complete_quiz_nonce')); ?>" /> |
|
| 1256 | 1256 | <input type="hidden" name="woothemes_sensei_reset_quiz_nonce" id="woothemes_sensei_reset_quiz_nonce" |
| 1257 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_reset_quiz_nonce' ) ); ?>" /> |
|
| 1257 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_reset_quiz_nonce')); ?>" /> |
|
| 1258 | 1258 | <input type="hidden" name="woothemes_sensei_save_quiz_nonce" id="woothemes_sensei_save_quiz_nonce" |
| 1259 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_save_quiz_nonce' ) ); ?>" /> |
|
| 1259 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_save_quiz_nonce')); ?>" /> |
|
| 1260 | 1260 | <!--#end Action Nonce's --> |
| 1261 | 1261 | |
| 1262 | - <?php if ( '' == $user_quiz_grade) { ?> |
|
| 1262 | + <?php if ('' == $user_quiz_grade) { ?> |
|
| 1263 | 1263 | |
| 1264 | - <span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php _e( 'Complete Quiz', 'woothemes-sensei' ); ?>"/></span> |
|
| 1264 | + <span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php _e('Complete Quiz', 'woothemes-sensei'); ?>"/></span> |
|
| 1265 | 1265 | |
| 1266 | - <span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php _e( 'Save Quiz', 'woothemes-sensei' ); ?>"/></span> |
|
| 1266 | + <span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php _e('Save Quiz', 'woothemes-sensei'); ?>"/></span> |
|
| 1267 | 1267 | |
| 1268 | 1268 | <?php } // End If Statement ?> |
| 1269 | 1269 | |
| 1270 | - <?php if ( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) { ?> |
|
| 1270 | + <?php if (isset($reset_quiz_allowed) && $reset_quiz_allowed) { ?> |
|
| 1271 | 1271 | |
| 1272 | - <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php _e( 'Reset Quiz', 'woothemes-sensei' ); ?>"/></span> |
|
| 1272 | + <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php _e('Reset Quiz', 'woothemes-sensei'); ?>"/></span> |
|
| 1273 | 1273 | |
| 1274 | 1274 | <?php } ?> |
| 1275 | 1275 | |
@@ -1287,13 +1287,13 @@ discard block |
||
| 1287 | 1287 | * |
| 1288 | 1288 | * @return double $user_quiz_grade |
| 1289 | 1289 | */ |
| 1290 | - public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
| 1290 | + public static function get_user_quiz_grade($lesson_id, $user_id) { |
|
| 1291 | 1291 | |
| 1292 | 1292 | // get the quiz grade |
| 1293 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1293 | + $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); |
|
| 1294 | 1294 | $user_quiz_grade = 0; |
| 1295 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 1296 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1295 | + if (isset($user_lesson_status->comment_ID)) { |
|
| 1296 | + $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true); |
|
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | return (double) $user_quiz_grade; |
@@ -1311,13 +1311,13 @@ discard block |
||
| 1311 | 1311 | * @param int $lesson_id |
| 1312 | 1312 | * @return bool |
| 1313 | 1313 | */ |
| 1314 | - public static function is_reset_allowed( $lesson_id ){ |
|
| 1314 | + public static function is_reset_allowed($lesson_id) { |
|
| 1315 | 1315 | |
| 1316 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1316 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); |
|
| 1317 | 1317 | |
| 1318 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 1318 | + $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true); |
|
| 1319 | 1319 | //backwards compatibility |
| 1320 | - if( 'on' == $reset_allowed ) { |
|
| 1320 | + if ('on' == $reset_allowed) { |
|
| 1321 | 1321 | $reset_allowed = 1; |
| 1322 | 1322 | } |
| 1323 | 1323 | |
@@ -1334,4 +1334,4 @@ discard block |
||
| 1334 | 1334 | * for backward compatibility |
| 1335 | 1335 | * @since 1.9.0 |
| 1336 | 1336 | */ |
| 1337 | -class WooThemes_Sensei_Quiz extends Sensei_Quiz{} |
|
| 1337 | +class WooThemes_Sensei_Quiz extends Sensei_Quiz {} |
|
@@ -25,70 +25,70 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function __construct ( $file = __FILE__ ) { |
| 27 | 27 | $this->file = $file; |
| 28 | - $this->token = 'quiz'; |
|
| 28 | + $this->token = 'quiz'; |
|
| 29 | 29 | $this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' ); |
| 30 | 30 | add_action( 'save_post', array( $this, 'update_author' )); |
| 31 | 31 | |
| 32 | 32 | // listen to the reset button click |
| 33 | 33 | add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
| 34 | 34 | |
| 35 | - // fire the complete quiz button submit for grading action |
|
| 36 | - add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); |
|
| 35 | + // fire the complete quiz button submit for grading action |
|
| 36 | + add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); |
|
| 37 | 37 | |
| 38 | 38 | // fire the save user answers quiz button click responder |
| 39 | 39 | add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) ); |
| 40 | 40 | |
| 41 | - // fire the load global data function |
|
| 42 | - add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); |
|
| 41 | + // fire the load global data function |
|
| 42 | + add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); |
|
| 43 | 43 | |
| 44 | - add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
| 44 | + add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | - } // End __construct() |
|
| 47 | + } // End __construct() |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | - * Update the quiz author when the lesson post type is save |
|
| 51 | - * |
|
| 52 | - * @param int $post_id |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 50 | + * Update the quiz author when the lesson post type is save |
|
| 51 | + * |
|
| 52 | + * @param int $post_id |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | 55 | public function update_author( $post_id ){ |
| 56 | 56 | |
| 57 | 57 | |
| 58 | 58 | // If this isn't a 'lesson' post, don't update it. |
| 59 | - // if this is a revision don't save it |
|
| 60 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
| 61 | - || wp_is_post_revision( $post_id ) ) { |
|
| 59 | + // if this is a revision don't save it |
|
| 60 | + if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
| 61 | + || wp_is_post_revision( $post_id ) ) { |
|
| 62 | 62 | |
| 63 | - return; |
|
| 63 | + return; |
|
| 64 | 64 | |
| 65 | - } |
|
| 66 | - // get the lesson author id to be use late |
|
| 67 | - $saved_post = get_post( $post_id ); |
|
| 68 | - $new_lesson_author_id = $saved_post->post_author; |
|
| 65 | + } |
|
| 66 | + // get the lesson author id to be use late |
|
| 67 | + $saved_post = get_post( $post_id ); |
|
| 68 | + $new_lesson_author_id = $saved_post->post_author; |
|
| 69 | 69 | |
| 70 | - //get the lessons quiz |
|
| 70 | + //get the lessons quiz |
|
| 71 | 71 | $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); |
| 72 | - foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
| 72 | + foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
| 73 | 73 | |
| 74 | - if( ! $quiz_item ) { |
|
| 75 | - continue; |
|
| 76 | - } |
|
| 74 | + if( ! $quiz_item ) { |
|
| 75 | + continue; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - // setup the quiz items new author value |
|
| 78 | + // setup the quiz items new author value |
|
| 79 | 79 | $my_post = array( |
| 80 | - 'ID' => $quiz_item, |
|
| 81 | - 'post_author' => $new_lesson_author_id |
|
| 80 | + 'ID' => $quiz_item, |
|
| 81 | + 'post_author' => $new_lesson_author_id |
|
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | - // remove the action so that it doesn't fire again |
|
| 85 | - remove_action( 'save_post', array( $this, 'update_author' )); |
|
| 84 | + // remove the action so that it doesn't fire again |
|
| 85 | + remove_action( 'save_post', array( $this, 'update_author' )); |
|
| 86 | 86 | |
| 87 | 87 | // Update the post into the database |
| 88 | 88 | wp_update_post( $my_post ); |
| 89 | - } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - return; |
|
| 91 | + return; |
|
| 92 | 92 | }// end update_author |
| 93 | 93 | |
| 94 | 94 | |
@@ -119,32 +119,32 @@ discard block |
||
| 119 | 119 | } // end lesson |
| 120 | 120 | |
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * user_save_quiz_answers_listener |
|
| 124 | - * |
|
| 125 | - * This function hooks into the quiz page and accepts the answer form save post. |
|
| 126 | - * @since 1.7.3 |
|
| 127 | - * @return bool $saved; |
|
| 128 | - */ |
|
| 129 | - public function user_save_quiz_answers_listener(){ |
|
| 122 | + /** |
|
| 123 | + * user_save_quiz_answers_listener |
|
| 124 | + * |
|
| 125 | + * This function hooks into the quiz page and accepts the answer form save post. |
|
| 126 | + * @since 1.7.3 |
|
| 127 | + * @return bool $saved; |
|
| 128 | + */ |
|
| 129 | + public function user_save_quiz_answers_listener(){ |
|
| 130 | 130 | |
| 131 | - if( ! isset( $_POST[ 'quiz_save' ]) |
|
| 132 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 133 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 134 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
| 135 | - return; |
|
| 136 | - } |
|
| 131 | + if( ! isset( $_POST[ 'quiz_save' ]) |
|
| 132 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
| 133 | + || empty( $_POST[ 'sensei_question' ] ) |
|
| 134 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
| 135 | + return; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - global $post; |
|
| 139 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 140 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 141 | - // call the save function |
|
| 142 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
| 138 | + global $post; |
|
| 139 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 140 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 141 | + // call the save function |
|
| 142 | + self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
| 143 | 143 | |
| 144 | - // remove the hook as it should only fire once per click |
|
| 145 | - remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); |
|
| 144 | + // remove the hook as it should only fire once per click |
|
| 145 | + remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); |
|
| 146 | 146 | |
| 147 | - } // end user_save_quiz_answers_listener |
|
| 147 | + } // end user_save_quiz_answers_listener |
|
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | 150 | * Save the user answers for the given lesson's quiz |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @access public |
| 156 | 156 | * |
| 157 | 157 | * @param array $quiz_answers |
| 158 | - * @param array $files from global $_FILES |
|
| 158 | + * @param array $files from global $_FILES |
|
| 159 | 159 | * @param int $lesson_id |
| 160 | 160 | * @param int $user_id |
| 161 | 161 | * |
@@ -163,11 +163,11 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ |
| 165 | 165 | |
| 166 | - if( ! ( $user_id > 0 ) ){ |
|
| 167 | - $user_id = get_current_user_id(); |
|
| 168 | - } |
|
| 166 | + if( ! ( $user_id > 0 ) ){ |
|
| 167 | + $user_id = get_current_user_id(); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - // make sure the parameters are valid before continuing |
|
| 170 | + // make sure the parameters are valid before continuing |
|
| 171 | 171 | if( empty( $lesson_id ) || empty( $user_id ) |
| 172 | 172 | || 'lesson' != get_post_type( $lesson_id ) |
| 173 | 173 | ||!get_userdata( $user_id ) |
@@ -178,25 +178,25 @@ discard block |
||
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
| 181 | - // start the lesson before saving the data in case the user has not started the lesson |
|
| 182 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 181 | + // start the lesson before saving the data in case the user has not started the lesson |
|
| 182 | + $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 183 | 183 | |
| 184 | 184 | //prepare the answers |
| 185 | 185 | $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); |
| 186 | 186 | |
| 187 | 187 | // save the user data |
| 188 | - $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
| 188 | + $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
| 189 | 189 | |
| 190 | 190 | // were the answers saved correctly? |
| 191 | 191 | if( intval( $answers_saved ) > 0){ |
| 192 | 192 | |
| 193 | - // save transient to make retrieval faster |
|
| 194 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 195 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
| 193 | + // save transient to make retrieval faster |
|
| 194 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 195 | + set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
| 196 | 196 | |
| 197 | - // update the message showed to user |
|
| 198 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 199 | - } |
|
| 197 | + // update the message showed to user |
|
| 198 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | 201 | return $answers_saved; |
| 202 | 202 | |
@@ -204,9 +204,9 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | 206 | * Get the user answers for the given lesson's quiz. |
| 207 | - * |
|
| 208 | - * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
| 209 | - * retrieving data for quiz answer before sensei 1.7.4 |
|
| 207 | + * |
|
| 208 | + * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
| 209 | + * retrieving data for quiz answer before sensei 1.7.4 |
|
| 210 | 210 | * |
| 211 | 211 | * |
| 212 | 212 | * @since 1.7.4 |
@@ -226,27 +226,27 @@ discard block |
||
| 226 | 226 | return false; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - // save some time and get the transient cached data |
|
| 230 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 231 | - $transient_cached_answers = get_transient( $transient_key ); |
|
| 229 | + // save some time and get the transient cached data |
|
| 230 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 231 | + $transient_cached_answers = get_transient( $transient_key ); |
|
| 232 | 232 | |
| 233 | - // return the transient or get the values get the values from the comment meta |
|
| 234 | - if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
| 233 | + // return the transient or get the values get the values from the comment meta |
|
| 234 | + if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
| 235 | 235 | |
| 236 | - $encoded_user_answers = $transient_cached_answers; |
|
| 236 | + $encoded_user_answers = $transient_cached_answers; |
|
| 237 | 237 | |
| 238 | - }else{ |
|
| 238 | + }else{ |
|
| 239 | 239 | |
| 240 | - $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
| 240 | + $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
| 241 | 241 | |
| 242 | - } // end if transient check |
|
| 242 | + } // end if transient check |
|
| 243 | 243 | |
| 244 | 244 | if( ! is_array( $encoded_user_answers ) ){ |
| 245 | 245 | return false; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - //set the transient with the new valid data for faster retrieval in future |
|
| 249 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 248 | + //set the transient with the new valid data for faster retrieval in future |
|
| 249 | + set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 250 | 250 | |
| 251 | 251 | // decode an unserialize all answers |
| 252 | 252 | foreach( $encoded_user_answers as $question_id => $encoded_answer ) { |
@@ -280,8 +280,8 @@ discard block |
||
| 280 | 280 | $current_quiz_id = $post->ID; |
| 281 | 281 | $lesson_id = $this->get_lesson_id( $current_quiz_id ); |
| 282 | 282 | |
| 283 | - // reset all user data |
|
| 284 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
| 283 | + // reset all user data |
|
| 284 | + $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
| 285 | 285 | |
| 286 | 286 | //this function should only run once |
| 287 | 287 | remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | * Complete/ submit quiz hooked function |
| 293 | 293 | * |
| 294 | 294 | * This function listens to the complete button submit action and processes the users submitted answers |
| 295 | - * not that this function submits the given users quiz answers for grading. |
|
| 295 | + * not that this function submits the given users quiz answers for grading. |
|
| 296 | 296 | * |
| 297 | 297 | * @since 1.7.4 |
| 298 | 298 | * @access public |
@@ -302,90 +302,90 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | public function user_quiz_submit_listener() { |
| 304 | 304 | |
| 305 | - // only respond to valid quiz completion submissions |
|
| 306 | - if( ! isset( $_POST[ 'quiz_complete' ]) |
|
| 307 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 308 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 309 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
| 310 | - return; |
|
| 311 | - } |
|
| 305 | + // only respond to valid quiz completion submissions |
|
| 306 | + if( ! isset( $_POST[ 'quiz_complete' ]) |
|
| 307 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
| 308 | + || empty( $_POST[ 'sensei_question' ] ) |
|
| 309 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
| 310 | + return; |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - global $post, $current_user; |
|
| 314 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 315 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 313 | + global $post, $current_user; |
|
| 314 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 315 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 316 | 316 | |
| 317 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
| 317 | + self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
| 318 | 318 | |
| 319 | 319 | } // End sensei_complete_quiz() |
| 320 | 320 | |
| 321 | - /** |
|
| 322 | - * This function set's up the data need for the quiz page |
|
| 323 | - * |
|
| 324 | - * This function hooks into sensei_complete_quiz and load the global data for the |
|
| 325 | - * current quiz. |
|
| 326 | - * |
|
| 327 | - * @since 1.7.4 |
|
| 328 | - * @access public |
|
| 329 | - * |
|
| 330 | - */ |
|
| 331 | - public function load_global_quiz_data(){ |
|
| 321 | + /** |
|
| 322 | + * This function set's up the data need for the quiz page |
|
| 323 | + * |
|
| 324 | + * This function hooks into sensei_complete_quiz and load the global data for the |
|
| 325 | + * current quiz. |
|
| 326 | + * |
|
| 327 | + * @since 1.7.4 |
|
| 328 | + * @access public |
|
| 329 | + * |
|
| 330 | + */ |
|
| 331 | + public function load_global_quiz_data(){ |
|
| 332 | 332 | |
| 333 | - global $post, $current_user; |
|
| 334 | - $this->data = new stdClass(); |
|
| 333 | + global $post, $current_user; |
|
| 334 | + $this->data = new stdClass(); |
|
| 335 | 335 | |
| 336 | - // Default grade |
|
| 337 | - $grade = 0; |
|
| 336 | + // Default grade |
|
| 337 | + $grade = 0; |
|
| 338 | 338 | |
| 339 | - // Get Quiz Questions |
|
| 340 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
| 339 | + // Get Quiz Questions |
|
| 340 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
| 341 | 341 | |
| 342 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
| 342 | + $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
| 343 | 343 | |
| 344 | - // Get quiz grade type |
|
| 345 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
| 344 | + // Get quiz grade type |
|
| 345 | + $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
| 346 | 346 | |
| 347 | - // Get quiz pass setting |
|
| 348 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
| 347 | + // Get quiz pass setting |
|
| 348 | + $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
| 349 | 349 | |
| 350 | - // Get quiz pass mark |
|
| 351 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
| 350 | + // Get quiz pass mark |
|
| 351 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
| 352 | 352 | |
| 353 | - // Get latest quiz answers and grades |
|
| 354 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 355 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
| 356 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
| 357 | - $user_quiz_grade = 0; |
|
| 358 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 359 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 360 | - } |
|
| 353 | + // Get latest quiz answers and grades |
|
| 354 | + $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 355 | + $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
| 356 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
| 357 | + $user_quiz_grade = 0; |
|
| 358 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 359 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
| 362 | + if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
| 363 | 363 | |
| 364 | - // Check again that the lesson is complete |
|
| 365 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 366 | - $user_lesson_complete = false; |
|
| 367 | - if ( $user_lesson_end ) { |
|
| 368 | - $user_lesson_complete = true; |
|
| 369 | - } // End If Statement |
|
| 364 | + // Check again that the lesson is complete |
|
| 365 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 366 | + $user_lesson_complete = false; |
|
| 367 | + if ( $user_lesson_end ) { |
|
| 368 | + $user_lesson_complete = true; |
|
| 369 | + } // End If Statement |
|
| 370 | 370 | |
| 371 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
| 372 | - //backwards compatibility |
|
| 373 | - if( 'on' == $reset_allowed ) { |
|
| 374 | - $reset_allowed = 1; |
|
| 375 | - } |
|
| 371 | + $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
| 372 | + //backwards compatibility |
|
| 373 | + if( 'on' == $reset_allowed ) { |
|
| 374 | + $reset_allowed = 1; |
|
| 375 | + } |
|
| 376 | 376 | |
| 377 | - // Build frontend data object for backwards compatibility |
|
| 378 | - // using this is no longer recommended |
|
| 379 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 380 | - $this->data->quiz_passmark = $quiz_passmark; |
|
| 381 | - $this->data->quiz_lesson = $quiz_lesson_id; |
|
| 382 | - $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 383 | - $this->data->user_lesson_end = $user_lesson_end; |
|
| 384 | - $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 385 | - $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
| 386 | - $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 377 | + // Build frontend data object for backwards compatibility |
|
| 378 | + // using this is no longer recommended |
|
| 379 | + $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 380 | + $this->data->quiz_passmark = $quiz_passmark; |
|
| 381 | + $this->data->quiz_lesson = $quiz_lesson_id; |
|
| 382 | + $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 383 | + $this->data->user_lesson_end = $user_lesson_end; |
|
| 384 | + $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 385 | + $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
| 386 | + $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 387 | 387 | |
| 388 | - } // end load_global_quiz_data |
|
| 388 | + } // end load_global_quiz_data |
|
| 389 | 389 | |
| 390 | 390 | |
| 391 | 391 | /** |
@@ -415,25 +415,25 @@ discard block |
||
| 415 | 415 | foreach( $unprepared_answers as $question_id => $answer ) { |
| 416 | 416 | |
| 417 | 417 | //get the current questions 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 | 421 | if( 0 == get_magic_quotes_gpc() ) { |
| 422 | 422 | $answer = wp_unslash( $answer ); |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - // compress the answer for saving |
|
| 425 | + // compress the answer for saving |
|
| 426 | 426 | if( 'multi-line' == $question_type ) { |
| 427 | - $answer = esc_html( $answer ); |
|
| 428 | - }elseif( 'file-upload' == $question_type ){ |
|
| 429 | - $file_key = 'file_upload_' . $question_id; |
|
| 430 | - if( isset( $files[ $file_key ] ) ) { |
|
| 431 | - $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
| 432 | - if( $attachment_id ) { |
|
| 433 | - $answer = $attachment_id; |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - } // end if |
|
| 427 | + $answer = esc_html( $answer ); |
|
| 428 | + }elseif( 'file-upload' == $question_type ){ |
|
| 429 | + $file_key = 'file_upload_' . $question_id; |
|
| 430 | + if( isset( $files[ $file_key ] ) ) { |
|
| 431 | + $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
| 432 | + if( $attachment_id ) { |
|
| 433 | + $answer = $attachment_id; |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + } // end if |
|
| 437 | 437 | |
| 438 | 438 | $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); |
| 439 | 439 | |
@@ -442,814 +442,814 @@ discard block |
||
| 442 | 442 | return $prepared_answers; |
| 443 | 443 | } // prepare_form_submitted_answers |
| 444 | 444 | |
| 445 | - /** |
|
| 446 | - * Reset user submitted questions |
|
| 447 | - * |
|
| 448 | - * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
| 449 | - * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
| 450 | - * |
|
| 451 | - * @since 1.7.4 |
|
| 452 | - * @access public |
|
| 453 | - * |
|
| 454 | - * @return bool $reset_success |
|
| 455 | - * @param int $user_id |
|
| 456 | - * @param int $lesson_id |
|
| 457 | - */ |
|
| 458 | - public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
| 445 | + /** |
|
| 446 | + * Reset user submitted questions |
|
| 447 | + * |
|
| 448 | + * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
| 449 | + * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
| 450 | + * |
|
| 451 | + * @since 1.7.4 |
|
| 452 | + * @access public |
|
| 453 | + * |
|
| 454 | + * @return bool $reset_success |
|
| 455 | + * @param int $user_id |
|
| 456 | + * @param int $lesson_id |
|
| 457 | + */ |
|
| 458 | + public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
| 459 | + |
|
| 460 | + //make sure the parameters are valid |
|
| 461 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 462 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 463 | + || ! get_userdata( $user_id ) ){ |
|
| 464 | + return false; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + //get the users lesson status to make |
|
| 470 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 471 | + if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
| 472 | + // this user is not taking this lesson so this process is not needed |
|
| 473 | + return false; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + //get the lesson quiz and course |
|
| 477 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 478 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 479 | + |
|
| 480 | + // reset the transients |
|
| 481 | + $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 482 | + $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 483 | + $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 484 | + delete_transient( $answers_transient_key ); |
|
| 485 | + delete_transient( $grades_transient_key ); |
|
| 486 | + delete_transient( $answers_feedback_transient_key ); |
|
| 487 | + |
|
| 488 | + // reset the quiz answers and feedback notes |
|
| 489 | + $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
| 490 | + $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 491 | + $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 492 | + |
|
| 493 | + // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
| 494 | + Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
| 495 | + |
|
| 496 | + Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
| 497 | + |
|
| 498 | + // Update course completion |
|
| 499 | + Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
| 459 | 500 | |
| 460 | - //make sure the parameters are valid |
|
| 461 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 462 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 463 | - || ! get_userdata( $user_id ) ){ |
|
| 464 | - return false; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - //get the users lesson status to make |
|
| 470 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 471 | - if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
| 472 | - // this user is not taking this lesson so this process is not needed |
|
| 473 | - return false; |
|
| 474 | - } |
|
| 501 | + // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
| 502 | + do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 503 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 475 | 504 | |
| 476 | - //get the lesson quiz and course |
|
| 477 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 478 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 505 | + return ( $deleted_answers && $deleted_grades ) ; |
|
| 479 | 506 | |
| 480 | - // reset the transients |
|
| 481 | - $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 482 | - $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 483 | - $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 484 | - delete_transient( $answers_transient_key ); |
|
| 485 | - delete_transient( $grades_transient_key ); |
|
| 486 | - delete_transient( $answers_feedback_transient_key ); |
|
| 507 | + } // end reset_user_lesson_data |
|
| 487 | 508 | |
| 488 | - // reset the quiz answers and feedback notes |
|
| 489 | - $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
| 490 | - $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 491 | - $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 509 | + /** |
|
| 510 | + * Submit the users quiz answers for grading |
|
| 511 | + * |
|
| 512 | + * This function accepts users answers and stores it but also initiates the grading |
|
| 513 | + * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
| 514 | + * |
|
| 515 | + * @since 1.7.4 |
|
| 516 | + * @access public |
|
| 517 | + * |
|
| 518 | + * @param array $quiz_answers |
|
| 519 | + * @param array $files from $_FILES |
|
| 520 | + * @param int $user_id |
|
| 521 | + * @param int $lesson_id |
|
| 522 | + * |
|
| 523 | + * @return bool $answers_submitted |
|
| 524 | + */ |
|
| 525 | + public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
| 492 | 526 | |
| 493 | - // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
| 494 | - Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
| 527 | + $answers_submitted = false; |
|
| 495 | 528 | |
| 496 | - Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
| 529 | + // get the user_id if none was passed in use the current logged in user |
|
| 530 | + if( ! intval( $user_id ) > 0 ) { |
|
| 531 | + $user_id = get_current_user_id(); |
|
| 532 | + } |
|
| 497 | 533 | |
| 498 | - // Update course completion |
|
| 499 | - Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
| 534 | + // make sure the parameters are valid before continuing |
|
| 535 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 536 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 537 | + ||!get_userdata( $user_id ) |
|
| 538 | + || !is_array( $quiz_answers ) ){ |
|
| 500 | 539 | |
| 501 | - // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
| 502 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 503 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 540 | + return false; |
|
| 504 | 541 | |
| 505 | - return ( $deleted_answers && $deleted_grades ) ; |
|
| 542 | + } |
|
| 506 | 543 | |
| 507 | - } // end reset_user_lesson_data |
|
| 544 | + // Default grade |
|
| 545 | + $grade = 0; |
|
| 508 | 546 | |
| 509 | - /** |
|
| 510 | - * Submit the users quiz answers for grading |
|
| 511 | - * |
|
| 512 | - * This function accepts users answers and stores it but also initiates the grading |
|
| 513 | - * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
| 514 | - * |
|
| 515 | - * @since 1.7.4 |
|
| 516 | - * @access public |
|
| 517 | - * |
|
| 518 | - * @param array $quiz_answers |
|
| 519 | - * @param array $files from $_FILES |
|
| 520 | - * @param int $user_id |
|
| 521 | - * @param int $lesson_id |
|
| 522 | - * |
|
| 523 | - * @return bool $answers_submitted |
|
| 524 | - */ |
|
| 525 | - public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
| 547 | + // Get Quiz ID |
|
| 548 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 526 | 549 | |
| 527 | - $answers_submitted = false; |
|
| 550 | + // Get quiz grade type |
|
| 551 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 528 | 552 | |
| 529 | - // get the user_id if none was passed in use the current logged in user |
|
| 530 | - if( ! intval( $user_id ) > 0 ) { |
|
| 531 | - $user_id = get_current_user_id(); |
|
| 532 | - } |
|
| 553 | + // Get quiz pass setting |
|
| 554 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 533 | 555 | |
| 534 | - // make sure the parameters are valid before continuing |
|
| 535 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 536 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 537 | - ||!get_userdata( $user_id ) |
|
| 538 | - || !is_array( $quiz_answers ) ){ |
|
| 556 | + // Get the minimum percentage need to pass this quiz |
|
| 557 | + $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 539 | 558 | |
| 540 | - return false; |
|
| 559 | + // Handle Quiz Questions asked |
|
| 560 | + // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
| 561 | + // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
| 562 | + // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
| 563 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 564 | + $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
| 565 | + if( empty( $questions_asked ) ){ |
|
| 541 | 566 | |
| 542 | - } |
|
| 567 | + $questions_asked = array_keys( $quiz_answers ); |
|
| 568 | + $questions_asked_string = implode( ',', $questions_asked ); |
|
| 543 | 569 | |
| 544 | - // Default grade |
|
| 545 | - $grade = 0; |
|
| 570 | + // Save questions that were asked in this quiz |
|
| 571 | + update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
| 546 | 572 | |
| 547 | - // Get Quiz ID |
|
| 548 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 573 | + } |
|
| 549 | 574 | |
| 550 | - // Get quiz grade type |
|
| 551 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 575 | + // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
| 576 | + self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
| 552 | 577 | |
| 553 | - // Get quiz pass setting |
|
| 554 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 578 | + // Grade quiz |
|
| 579 | + $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
| 555 | 580 | |
| 556 | - // Get the minimum percentage need to pass this quiz |
|
| 557 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 581 | + // Get Lesson Grading Setting |
|
| 582 | + $lesson_metadata = array(); |
|
| 583 | + $lesson_status = 'ungraded'; // Default when completing a quiz |
|
| 558 | 584 | |
| 559 | - // Handle Quiz Questions asked |
|
| 560 | - // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
| 561 | - // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
| 562 | - // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
| 563 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 564 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
| 565 | - if( empty( $questions_asked ) ){ |
|
| 585 | + // At this point the answers have been submitted |
|
| 586 | + $answers_submitted = true; |
|
| 566 | 587 | |
| 567 | - $questions_asked = array_keys( $quiz_answers ); |
|
| 568 | - $questions_asked_string = implode( ',', $questions_asked ); |
|
| 569 | - |
|
| 570 | - // Save questions that were asked in this quiz |
|
| 571 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
| 588 | + // if this condition is false the quiz should manually be graded by admin |
|
| 589 | + if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
| 572 | 590 | |
| 573 | - } |
|
| 591 | + // Quiz has been automatically Graded |
|
| 592 | + if ( 'on' == $pass_required ) { |
|
| 574 | 593 | |
| 575 | - // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
| 576 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
| 594 | + // Student has reached the pass mark and lesson is complete |
|
| 595 | + if ( $quiz_pass_percentage <= $grade ) { |
|
| 577 | 596 | |
| 578 | - // Grade quiz |
|
| 579 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
| 597 | + $lesson_status = 'passed'; |
|
| 580 | 598 | |
| 581 | - // Get Lesson Grading Setting |
|
| 582 | - $lesson_metadata = array(); |
|
| 583 | - $lesson_status = 'ungraded'; // Default when completing a quiz |
|
| 599 | + } else { |
|
| 584 | 600 | |
| 585 | - // At this point the answers have been submitted |
|
| 586 | - $answers_submitted = true; |
|
| 601 | + $lesson_status = 'failed'; |
|
| 587 | 602 | |
| 588 | - // if this condition is false the quiz should manually be graded by admin |
|
| 589 | - if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
| 603 | + } // End If Statement |
|
| 590 | 604 | |
| 591 | - // Quiz has been automatically Graded |
|
| 592 | - if ( 'on' == $pass_required ) { |
|
| 605 | + } else { |
|
| 593 | 606 | |
| 594 | - // Student has reached the pass mark and lesson is complete |
|
| 595 | - if ( $quiz_pass_percentage <= $grade ) { |
|
| 607 | + // Student only has to partake the quiz |
|
| 608 | + $lesson_status = 'graded'; |
|
| 609 | + |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
| 613 | + |
|
| 614 | + } // end if ! is_wp_error( $grade ... |
|
| 615 | + |
|
| 616 | + Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
| 596 | 617 | |
| 597 | - $lesson_status = 'passed'; |
|
| 618 | + if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
| 598 | 619 | |
| 599 | - } else { |
|
| 620 | + /** |
|
| 621 | + * Lesson end action hook |
|
| 622 | + * |
|
| 623 | + * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
| 624 | + * |
|
| 625 | + * @param int $user_id |
|
| 626 | + * @param int $lesson_id |
|
| 627 | + */ |
|
| 628 | + do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 600 | 629 | |
| 601 | - $lesson_status = 'failed'; |
|
| 630 | + } |
|
| 602 | 631 | |
| 603 | - } // End If Statement |
|
| 632 | + /** |
|
| 633 | + * User quiz has been submitted |
|
| 634 | + * |
|
| 635 | + * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
| 636 | + * results. |
|
| 637 | + * |
|
| 638 | + * @param int $user_id |
|
| 639 | + * @param int $quiz_id |
|
| 640 | + * @param string $grade |
|
| 641 | + * @param string $quiz_pass_percentage |
|
| 642 | + * @param string $quiz_grade_type |
|
| 643 | + */ |
|
| 644 | + do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
| 604 | 645 | |
| 605 | - } else { |
|
| 646 | + return $answers_submitted; |
|
| 606 | 647 | |
| 607 | - // Student only has to partake the quiz |
|
| 608 | - $lesson_status = 'graded'; |
|
| 609 | - |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
| 613 | - |
|
| 614 | - } // end if ! is_wp_error( $grade ... |
|
| 615 | - |
|
| 616 | - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
| 648 | + }// end submit_answers_for_grading |
|
| 617 | 649 | |
| 618 | - if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
| 650 | + /** |
|
| 651 | + * Get the user question answer |
|
| 652 | + * |
|
| 653 | + * This function gets the the users saved answer on given quiz for the given question parameter |
|
| 654 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 655 | + * |
|
| 656 | + * @since 1.7.4 |
|
| 657 | + * |
|
| 658 | + * @param int $lesson_id |
|
| 659 | + * @param int $question_id |
|
| 660 | + * @param int $user_id ( optional ) |
|
| 661 | + * |
|
| 662 | + * @return bool $answers_submitted |
|
| 663 | + */ |
|
| 664 | + public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 619 | 665 | |
| 620 | - /** |
|
| 621 | - * Lesson end action hook |
|
| 622 | - * |
|
| 623 | - * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
| 624 | - * |
|
| 625 | - * @param int $user_id |
|
| 626 | - * @param int $lesson_id |
|
| 627 | - */ |
|
| 628 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 666 | + // parameter validation |
|
| 667 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 668 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 669 | + || ! ( intval( $question_id ) > 0 ) |
|
| 670 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 671 | + || 'question' != get_post_type( $question_id )) { |
|
| 629 | 672 | |
| 630 | - } |
|
| 673 | + return false; |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + if( ! ( intval( $user_id ) > 0 ) ){ |
|
| 677 | + $user_id = get_current_user_id(); |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
| 681 | + |
|
| 682 | + if( !$users_answers || empty( $users_answers ) |
|
| 683 | + || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
| 684 | + |
|
| 685 | + //Fallback for pre 1.7.4 data |
|
| 686 | + $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
| 687 | + |
|
| 688 | + if( ! isset( $comment->comment_content ) ){ |
|
| 689 | + return false; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + return $users_answers[ $question_id ]; |
|
| 696 | + |
|
| 697 | + }// end get_user_question_answer |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * Saving the users quiz question grades |
|
| 701 | + * |
|
| 702 | + * This function save all the grades for all the question in a given quiz on the lesson |
|
| 703 | + * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
| 704 | + * |
|
| 705 | + * @since 1.7.4 |
|
| 706 | + * |
|
| 707 | + * @param array $quiz_grades{ |
|
| 708 | + * @type int $question_id |
|
| 709 | + * @type int $question_grade |
|
| 710 | + * } |
|
| 711 | + * @param $lesson_id |
|
| 712 | + * @param $user_id (Optional) will use the current user if not supplied |
|
| 713 | + * |
|
| 714 | + * @return bool |
|
| 715 | + */ |
|
| 716 | + public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
| 717 | + |
|
| 718 | + // get the user_id if none was passed in use the current logged in user |
|
| 719 | + if( ! intval( $user_id ) > 0 ) { |
|
| 720 | + $user_id = get_current_user_id(); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + // make sure the parameters are valid before continuing |
|
| 724 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 725 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 726 | + ||!get_userdata( $user_id ) |
|
| 727 | + || !is_array( $quiz_grades ) ){ |
|
| 728 | + |
|
| 729 | + return false; |
|
| 730 | + |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + $success = false; |
|
| 734 | + |
|
| 735 | + // save that data for the user on the lesson comment meta |
|
| 736 | + $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
| 737 | + |
|
| 738 | + // were the grades save successfully ? |
|
| 739 | + if( intval( $comment_meta_id ) > 0 ) { |
|
| 740 | + |
|
| 741 | + $success = true; |
|
| 742 | + // save transient |
|
| 743 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 744 | + set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + return $success; |
|
| 748 | + |
|
| 749 | + }// end set_user_grades |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * Retrieve the users quiz question grades |
|
| 753 | + * |
|
| 754 | + * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
| 755 | + * |
|
| 756 | + * @since 1.7.4 |
|
| 757 | + * |
|
| 758 | + * @param $lesson_id |
|
| 759 | + * @param $user_id (Optional) will use the current user if not supplied |
|
| 760 | + * |
|
| 761 | + * @return array $user_quiz_grades or false if none exists for this users |
|
| 762 | + */ |
|
| 763 | + public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
| 764 | + |
|
| 765 | + $user_grades = array(); |
|
| 766 | + |
|
| 767 | + // get the user_id if none was passed in use the current logged in user |
|
| 768 | + if( ! intval( $user_id ) > 0 ) { |
|
| 769 | + $user_id = get_current_user_id(); |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 773 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 774 | + return false; |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + // save some time and get the transient cached data |
|
| 778 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 779 | + $user_grades = get_transient( $transient_key ); |
|
| 780 | + |
|
| 781 | + // get the data if nothing was stored in the transient |
|
| 782 | + if( empty( $user_grades ) || false != $user_grades ){ |
|
| 783 | + |
|
| 784 | + $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 785 | + |
|
| 786 | + //set the transient with the new valid data for faster retrieval in future |
|
| 787 | + set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
| 788 | + |
|
| 789 | + } // end if transient check |
|
| 790 | + |
|
| 791 | + // if there is no data for this user |
|
| 792 | + if( ! is_array( $user_grades ) ){ |
|
| 793 | + return false; |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + return $user_grades; |
|
| 797 | + |
|
| 798 | + }// end get_user_grades |
|
| 799 | + |
|
| 800 | + /** |
|
| 801 | + * Get the user question grade |
|
| 802 | + * |
|
| 803 | + * This function gets the grade on a quiz for the given question parameter |
|
| 804 | + * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
| 805 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 806 | + * |
|
| 807 | + * @since 1.7.4 |
|
| 808 | + * |
|
| 809 | + * @param int $lesson_id |
|
| 810 | + * @param int $question_id |
|
| 811 | + * @param int $user_id ( optional ) |
|
| 812 | + * |
|
| 813 | + * @return bool $question_grade |
|
| 814 | + */ |
|
| 815 | + public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 816 | + |
|
| 817 | + // parameter validation |
|
| 818 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 819 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 820 | + || ! ( intval( $question_id ) > 0 ) |
|
| 821 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 822 | + || 'question' != get_post_type( $question_id )) { |
|
| 823 | + |
|
| 824 | + return false; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
| 828 | + |
|
| 829 | + if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
| 830 | + |
|
| 831 | + //fallback to data pre 1.7.4 |
|
| 832 | + $args = array( |
|
| 833 | + 'post_id' => $question_id, |
|
| 834 | + 'user_id' => $user_id, |
|
| 835 | + 'type' => 'sensei_user_answer' |
|
| 836 | + ); |
|
| 837 | + |
|
| 838 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 839 | + $fall_back_grade = false; |
|
| 840 | + if( isset( $question_activity->comment_ID ) ){ |
|
| 841 | + $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + return $fall_back_grade; |
|
| 845 | + |
|
| 846 | + } // end if $all_user_grades... |
|
| 847 | + |
|
| 848 | + return $all_user_grades[ $question_id ]; |
|
| 849 | + |
|
| 850 | + }// end get_user_question_grade |
|
| 851 | + |
|
| 852 | + /** |
|
| 853 | + * Save the user's answers feedback |
|
| 854 | + * |
|
| 855 | + * For this function you must supply all three parameters. If will return false one is left out. |
|
| 856 | + * The data will be saved on the lesson ID supplied. |
|
| 857 | + * |
|
| 858 | + * @since 1.7.5 |
|
| 859 | + * @access public |
|
| 860 | + * |
|
| 861 | + * @param array $answers_feedback{ |
|
| 862 | + * $type int $question_id |
|
| 863 | + * $type string $question_feedback |
|
| 864 | + * } |
|
| 865 | + * @param int $lesson_id |
|
| 866 | + * @param int $user_id |
|
| 867 | + * |
|
| 868 | + * @return false or int $feedback_saved |
|
| 869 | + */ |
|
| 870 | + public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
| 871 | + |
|
| 872 | + // make sure the parameters are valid before continuing |
|
| 873 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 874 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 875 | + ||!get_userdata( $user_id ) |
|
| 876 | + || !is_array( $answers_feedback ) ){ |
|
| 877 | + |
|
| 878 | + return false; |
|
| 879 | + |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + // check if the lesson is started before saving, if not start the lesson for the user |
|
| 884 | + if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
| 885 | + Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 886 | + } |
|
| 631 | 887 | |
| 632 | - /** |
|
| 633 | - * User quiz has been submitted |
|
| 634 | - * |
|
| 635 | - * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
| 636 | - * results. |
|
| 637 | - * |
|
| 638 | - * @param int $user_id |
|
| 639 | - * @param int $quiz_id |
|
| 640 | - * @param string $grade |
|
| 641 | - * @param string $quiz_pass_percentage |
|
| 642 | - * @param string $quiz_grade_type |
|
| 643 | - */ |
|
| 644 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
| 888 | + // encode the feedback |
|
| 889 | + $encoded_answers_feedback = array(); |
|
| 890 | + foreach( $answers_feedback as $question_id => $feedback ){ |
|
| 891 | + $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + // save the user data |
|
| 895 | + $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
| 896 | + |
|
| 897 | + //Were the the question feedback save correctly? |
|
| 898 | + if( intval( $feedback_saved ) > 0){ |
|
| 899 | + |
|
| 900 | + // save transient to make retrieval faster in future |
|
| 901 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 902 | + set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
| 645 | 903 | |
| 646 | - return $answers_submitted; |
|
| 904 | + } |
|
| 905 | + |
|
| 906 | + return $feedback_saved; |
|
| 907 | + |
|
| 908 | + } // end save_user_answers_feedback |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * Get the user's answers feedback. |
|
| 912 | + * |
|
| 913 | + * This function returns the feedback submitted by the teacher/admin |
|
| 914 | + * during grading. Grading occurs manually or automatically. |
|
| 915 | + * |
|
| 916 | + * @since 1.7.5 |
|
| 917 | + * @access public |
|
| 918 | + * |
|
| 919 | + * @param int $lesson_id |
|
| 920 | + * @param int $user_id |
|
| 921 | + * |
|
| 922 | + * @return false | array $answers_feedback{ |
|
| 923 | + * $type int $question_id |
|
| 924 | + * $type string $question_feedback |
|
| 925 | + * } |
|
| 926 | + */ |
|
| 927 | + public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
| 928 | + |
|
| 929 | + $answers_feedback = array(); |
|
| 647 | 930 | |
| 648 | - }// end submit_answers_for_grading |
|
| 931 | + // get the user_id if none was passed in use the current logged in user |
|
| 932 | + if( ! intval( $user_id ) > 0 ) { |
|
| 933 | + $user_id = get_current_user_id(); |
|
| 934 | + } |
|
| 649 | 935 | |
| 650 | - /** |
|
| 651 | - * Get the user question answer |
|
| 652 | - * |
|
| 653 | - * This function gets the the users saved answer on given quiz for the given question parameter |
|
| 654 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 655 | - * |
|
| 656 | - * @since 1.7.4 |
|
| 657 | - * |
|
| 658 | - * @param int $lesson_id |
|
| 659 | - * @param int $question_id |
|
| 660 | - * @param int $user_id ( optional ) |
|
| 661 | - * |
|
| 662 | - * @return bool $answers_submitted |
|
| 663 | - */ |
|
| 664 | - public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 936 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 937 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 938 | + return false; |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + // first check the transient to save a few split seconds |
|
| 942 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 943 | + $encoded_feedback = get_transient( $transient_key ); |
|
| 944 | + |
|
| 945 | + // get the data if nothing was stored in the transient |
|
| 946 | + if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
| 665 | 947 | |
| 666 | - // parameter validation |
|
| 667 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 668 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 669 | - || ! ( intval( $question_id ) > 0 ) |
|
| 670 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 671 | - || 'question' != get_post_type( $question_id )) { |
|
| 948 | + $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 949 | + |
|
| 950 | + //set the transient with the new valid data for faster retrieval in future |
|
| 951 | + set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 952 | + |
|
| 953 | + } // end if transient check |
|
| 672 | 954 | |
| 673 | - return false; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - if( ! ( intval( $user_id ) > 0 ) ){ |
|
| 677 | - $user_id = get_current_user_id(); |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
| 681 | - |
|
| 682 | - if( !$users_answers || empty( $users_answers ) |
|
| 683 | - || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
| 684 | - |
|
| 685 | - //Fallback for pre 1.7.4 data |
|
| 686 | - $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
| 687 | - |
|
| 688 | - if( ! isset( $comment->comment_content ) ){ |
|
| 689 | - return false; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - return $users_answers[ $question_id ]; |
|
| 696 | - |
|
| 697 | - }// end get_user_question_answer |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * Saving the users quiz question grades |
|
| 701 | - * |
|
| 702 | - * This function save all the grades for all the question in a given quiz on the lesson |
|
| 703 | - * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
| 704 | - * |
|
| 705 | - * @since 1.7.4 |
|
| 706 | - * |
|
| 707 | - * @param array $quiz_grades{ |
|
| 708 | - * @type int $question_id |
|
| 709 | - * @type int $question_grade |
|
| 710 | - * } |
|
| 711 | - * @param $lesson_id |
|
| 712 | - * @param $user_id (Optional) will use the current user if not supplied |
|
| 713 | - * |
|
| 714 | - * @return bool |
|
| 715 | - */ |
|
| 716 | - public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
| 717 | - |
|
| 718 | - // get the user_id if none was passed in use the current logged in user |
|
| 719 | - if( ! intval( $user_id ) > 0 ) { |
|
| 720 | - $user_id = get_current_user_id(); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - // make sure the parameters are valid before continuing |
|
| 724 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 725 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 726 | - ||!get_userdata( $user_id ) |
|
| 727 | - || !is_array( $quiz_grades ) ){ |
|
| 728 | - |
|
| 729 | - return false; |
|
| 730 | - |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - $success = false; |
|
| 734 | - |
|
| 735 | - // save that data for the user on the lesson comment meta |
|
| 736 | - $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
| 737 | - |
|
| 738 | - // were the grades save successfully ? |
|
| 739 | - if( intval( $comment_meta_id ) > 0 ) { |
|
| 740 | - |
|
| 741 | - $success = true; |
|
| 742 | - // save transient |
|
| 743 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 744 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - return $success; |
|
| 748 | - |
|
| 749 | - }// end set_user_grades |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * Retrieve the users quiz question grades |
|
| 753 | - * |
|
| 754 | - * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
| 755 | - * |
|
| 756 | - * @since 1.7.4 |
|
| 757 | - * |
|
| 758 | - * @param $lesson_id |
|
| 759 | - * @param $user_id (Optional) will use the current user if not supplied |
|
| 760 | - * |
|
| 761 | - * @return array $user_quiz_grades or false if none exists for this users |
|
| 762 | - */ |
|
| 763 | - public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
| 764 | - |
|
| 765 | - $user_grades = array(); |
|
| 766 | - |
|
| 767 | - // get the user_id if none was passed in use the current logged in user |
|
| 768 | - if( ! intval( $user_id ) > 0 ) { |
|
| 769 | - $user_id = get_current_user_id(); |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 773 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 774 | - return false; |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - // save some time and get the transient cached data |
|
| 778 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 779 | - $user_grades = get_transient( $transient_key ); |
|
| 780 | - |
|
| 781 | - // get the data if nothing was stored in the transient |
|
| 782 | - if( empty( $user_grades ) || false != $user_grades ){ |
|
| 783 | - |
|
| 784 | - $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 785 | - |
|
| 786 | - //set the transient with the new valid data for faster retrieval in future |
|
| 787 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
| 788 | - |
|
| 789 | - } // end if transient check |
|
| 790 | - |
|
| 791 | - // if there is no data for this user |
|
| 792 | - if( ! is_array( $user_grades ) ){ |
|
| 793 | - return false; |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - return $user_grades; |
|
| 797 | - |
|
| 798 | - }// end get_user_grades |
|
| 799 | - |
|
| 800 | - /** |
|
| 801 | - * Get the user question grade |
|
| 802 | - * |
|
| 803 | - * This function gets the grade on a quiz for the given question parameter |
|
| 804 | - * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
| 805 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 806 | - * |
|
| 807 | - * @since 1.7.4 |
|
| 808 | - * |
|
| 809 | - * @param int $lesson_id |
|
| 810 | - * @param int $question_id |
|
| 811 | - * @param int $user_id ( optional ) |
|
| 812 | - * |
|
| 813 | - * @return bool $question_grade |
|
| 814 | - */ |
|
| 815 | - public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 816 | - |
|
| 817 | - // parameter validation |
|
| 818 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 819 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 820 | - || ! ( intval( $question_id ) > 0 ) |
|
| 821 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 822 | - || 'question' != get_post_type( $question_id )) { |
|
| 823 | - |
|
| 824 | - return false; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
| 828 | - |
|
| 829 | - if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
| 830 | - |
|
| 831 | - //fallback to data pre 1.7.4 |
|
| 832 | - $args = array( |
|
| 833 | - 'post_id' => $question_id, |
|
| 834 | - 'user_id' => $user_id, |
|
| 835 | - 'type' => 'sensei_user_answer' |
|
| 836 | - ); |
|
| 837 | - |
|
| 838 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 839 | - $fall_back_grade = false; |
|
| 840 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 841 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - return $fall_back_grade; |
|
| 845 | - |
|
| 846 | - } // end if $all_user_grades... |
|
| 847 | - |
|
| 848 | - return $all_user_grades[ $question_id ]; |
|
| 849 | - |
|
| 850 | - }// end get_user_question_grade |
|
| 851 | - |
|
| 852 | - /** |
|
| 853 | - * Save the user's answers feedback |
|
| 854 | - * |
|
| 855 | - * For this function you must supply all three parameters. If will return false one is left out. |
|
| 856 | - * The data will be saved on the lesson ID supplied. |
|
| 857 | - * |
|
| 858 | - * @since 1.7.5 |
|
| 859 | - * @access public |
|
| 860 | - * |
|
| 861 | - * @param array $answers_feedback{ |
|
| 862 | - * $type int $question_id |
|
| 863 | - * $type string $question_feedback |
|
| 864 | - * } |
|
| 865 | - * @param int $lesson_id |
|
| 866 | - * @param int $user_id |
|
| 867 | - * |
|
| 868 | - * @return false or int $feedback_saved |
|
| 869 | - */ |
|
| 870 | - public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
| 871 | - |
|
| 872 | - // make sure the parameters are valid before continuing |
|
| 873 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 874 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 875 | - ||!get_userdata( $user_id ) |
|
| 876 | - || !is_array( $answers_feedback ) ){ |
|
| 877 | - |
|
| 878 | - return false; |
|
| 879 | - |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - // check if the lesson is started before saving, if not start the lesson for the user |
|
| 884 | - if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
| 885 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - // encode the feedback |
|
| 889 | - $encoded_answers_feedback = array(); |
|
| 890 | - foreach( $answers_feedback as $question_id => $feedback ){ |
|
| 891 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - // save the user data |
|
| 895 | - $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
| 896 | - |
|
| 897 | - //Were the the question feedback save correctly? |
|
| 898 | - if( intval( $feedback_saved ) > 0){ |
|
| 899 | - |
|
| 900 | - // save transient to make retrieval faster in future |
|
| 901 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 902 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
| 903 | - |
|
| 904 | - } |
|
| 905 | - |
|
| 906 | - return $feedback_saved; |
|
| 907 | - |
|
| 908 | - } // end save_user_answers_feedback |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * Get the user's answers feedback. |
|
| 912 | - * |
|
| 913 | - * This function returns the feedback submitted by the teacher/admin |
|
| 914 | - * during grading. Grading occurs manually or automatically. |
|
| 915 | - * |
|
| 916 | - * @since 1.7.5 |
|
| 917 | - * @access public |
|
| 918 | - * |
|
| 919 | - * @param int $lesson_id |
|
| 920 | - * @param int $user_id |
|
| 921 | - * |
|
| 922 | - * @return false | array $answers_feedback{ |
|
| 923 | - * $type int $question_id |
|
| 924 | - * $type string $question_feedback |
|
| 925 | - * } |
|
| 926 | - */ |
|
| 927 | - public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
| 928 | - |
|
| 929 | - $answers_feedback = array(); |
|
| 930 | - |
|
| 931 | - // get the user_id if none was passed in use the current logged in user |
|
| 932 | - if( ! intval( $user_id ) > 0 ) { |
|
| 933 | - $user_id = get_current_user_id(); |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 937 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 938 | - return false; |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - // first check the transient to save a few split seconds |
|
| 942 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 943 | - $encoded_feedback = get_transient( $transient_key ); |
|
| 944 | - |
|
| 945 | - // get the data if nothing was stored in the transient |
|
| 946 | - if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
| 947 | - |
|
| 948 | - $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 949 | - |
|
| 950 | - //set the transient with the new valid data for faster retrieval in future |
|
| 951 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 952 | - |
|
| 953 | - } // end if transient check |
|
| 954 | - |
|
| 955 | - // if there is no data for this user |
|
| 956 | - if( ! is_array( $encoded_feedback ) ){ |
|
| 957 | - return false; |
|
| 958 | - } |
|
| 955 | + // if there is no data for this user |
|
| 956 | + if( ! is_array( $encoded_feedback ) ){ |
|
| 957 | + return false; |
|
| 958 | + } |
|
| 959 | 959 | |
| 960 | - foreach( $encoded_feedback as $question_id => $feedback ){ |
|
| 960 | + foreach( $encoded_feedback as $question_id => $feedback ){ |
|
| 961 | 961 | |
| 962 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
| 962 | + $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
| 963 | 963 | |
| 964 | - } |
|
| 964 | + } |
|
| 965 | 965 | |
| 966 | - return $answers_feedback; |
|
| 966 | + return $answers_feedback; |
|
| 967 | 967 | |
| 968 | - } // end get_user_answers_feedback |
|
| 968 | + } // end get_user_answers_feedback |
|
| 969 | 969 | |
| 970 | - /** |
|
| 971 | - * Get the user's answer feedback for a specific question. |
|
| 972 | - * |
|
| 973 | - * This function gives you a single answer note/feedback string |
|
| 974 | - * for the user on the given question. |
|
| 975 | - * |
|
| 976 | - * @since 1.7.5 |
|
| 977 | - * @access public |
|
| 978 | - * |
|
| 979 | - * @param int $lesson_id |
|
| 980 | - * @param int $question_id |
|
| 981 | - * @param int $user_id |
|
| 982 | - * |
|
| 983 | - * @return string $feedback or bool if false |
|
| 984 | - */ |
|
| 985 | - public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 970 | + /** |
|
| 971 | + * Get the user's answer feedback for a specific question. |
|
| 972 | + * |
|
| 973 | + * This function gives you a single answer note/feedback string |
|
| 974 | + * for the user on the given question. |
|
| 975 | + * |
|
| 976 | + * @since 1.7.5 |
|
| 977 | + * @access public |
|
| 978 | + * |
|
| 979 | + * @param int $lesson_id |
|
| 980 | + * @param int $question_id |
|
| 981 | + * @param int $user_id |
|
| 982 | + * |
|
| 983 | + * @return string $feedback or bool if false |
|
| 984 | + */ |
|
| 985 | + public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 986 | 986 | |
| 987 | - $feedback = false; |
|
| 987 | + $feedback = false; |
|
| 988 | 988 | |
| 989 | - // parameter validation |
|
| 990 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 991 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 992 | - || ! ( intval( $question_id ) > 0 ) |
|
| 993 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 994 | - || 'question' != get_post_type( $question_id )) { |
|
| 989 | + // parameter validation |
|
| 990 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 991 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 992 | + || ! ( intval( $question_id ) > 0 ) |
|
| 993 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 994 | + || 'question' != get_post_type( $question_id )) { |
|
| 995 | 995 | |
| 996 | - return false; |
|
| 997 | - } |
|
| 996 | + return false; |
|
| 997 | + } |
|
| 998 | 998 | |
| 999 | - // get all the feedback for the user on the given lesson |
|
| 1000 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
| 999 | + // get all the feedback for the user on the given lesson |
|
| 1000 | + $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
| 1001 | 1001 | |
| 1002 | - if( !$all_feedback || empty( $all_feedback ) |
|
| 1003 | - || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
| 1002 | + if( !$all_feedback || empty( $all_feedback ) |
|
| 1003 | + || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
| 1004 | 1004 | |
| 1005 | - //fallback to data pre 1.7.4 |
|
| 1005 | + //fallback to data pre 1.7.4 |
|
| 1006 | 1006 | |
| 1007 | - // setup the sensei data query |
|
| 1008 | - $args = array( |
|
| 1009 | - 'post_id' => $question_id, |
|
| 1010 | - 'user_id' => $user_id, |
|
| 1011 | - 'type' => 'sensei_user_answer' |
|
| 1012 | - ); |
|
| 1013 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 1007 | + // setup the sensei data query |
|
| 1008 | + $args = array( |
|
| 1009 | + 'post_id' => $question_id, |
|
| 1010 | + 'user_id' => $user_id, |
|
| 1011 | + 'type' => 'sensei_user_answer' |
|
| 1012 | + ); |
|
| 1013 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 1014 | 1014 | |
| 1015 | - // set the default to false and return that if no old data is available. |
|
| 1016 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 1017 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
| 1018 | - } |
|
| 1015 | + // set the default to false and return that if no old data is available. |
|
| 1016 | + if( isset( $question_activity->comment_ID ) ){ |
|
| 1017 | + $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
| 1018 | + } |
|
| 1019 | 1019 | |
| 1020 | - // finally use the default question feedback |
|
| 1021 | - if( empty( $feedback ) ){ |
|
| 1022 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 1023 | - } |
|
| 1020 | + // finally use the default question feedback |
|
| 1021 | + if( empty( $feedback ) ){ |
|
| 1022 | + $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 1023 | + } |
|
| 1024 | 1024 | |
| 1025 | - return $feedback; |
|
| 1025 | + return $feedback; |
|
| 1026 | 1026 | |
| 1027 | - } |
|
| 1027 | + } |
|
| 1028 | 1028 | |
| 1029 | - return $all_feedback[ $question_id ]; |
|
| 1029 | + return $all_feedback[ $question_id ]; |
|
| 1030 | 1030 | |
| 1031 | - } // end get_user_question_feedback |
|
| 1031 | + } // end get_user_question_feedback |
|
| 1032 | 1032 | |
| 1033 | - /** |
|
| 1034 | - * Check if a quiz has no questions, and redirect back to lesson. |
|
| 1035 | - * |
|
| 1036 | - * Though a quiz is created for each lesson, it should not be visible |
|
| 1037 | - * unless it has questions. |
|
| 1038 | - * |
|
| 1039 | - * @since 1.9.0 |
|
| 1040 | - * @access public |
|
| 1041 | - * @param none |
|
| 1042 | - * @return void |
|
| 1043 | - */ |
|
| 1033 | + /** |
|
| 1034 | + * Check if a quiz has no questions, and redirect back to lesson. |
|
| 1035 | + * |
|
| 1036 | + * Though a quiz is created for each lesson, it should not be visible |
|
| 1037 | + * unless it has questions. |
|
| 1038 | + * |
|
| 1039 | + * @since 1.9.0 |
|
| 1040 | + * @access public |
|
| 1041 | + * @param none |
|
| 1042 | + * @return void |
|
| 1043 | + */ |
|
| 1044 | 1044 | |
| 1045 | - public function quiz_has_no_questions() { |
|
| 1045 | + public function quiz_has_no_questions() { |
|
| 1046 | 1046 | |
| 1047 | 1047 | |
| 1048 | - if( ! is_singular( 'quiz' ) ) { |
|
| 1049 | - return; |
|
| 1050 | - } |
|
| 1048 | + if( ! is_singular( 'quiz' ) ) { |
|
| 1049 | + return; |
|
| 1050 | + } |
|
| 1051 | 1051 | |
| 1052 | - global $post; |
|
| 1052 | + global $post; |
|
| 1053 | 1053 | |
| 1054 | - $lesson_id = $this->get_lesson_id($post->ID); |
|
| 1054 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
| 1055 | 1055 | |
| 1056 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1056 | + $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1057 | 1057 | |
| 1058 | - $lesson = get_post($lesson_id); |
|
| 1058 | + $lesson = get_post($lesson_id); |
|
| 1059 | 1059 | |
| 1060 | - if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
| 1060 | + if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
| 1061 | 1061 | |
| 1062 | - wp_redirect(get_permalink($lesson->ID), 301); |
|
| 1063 | - exit; |
|
| 1062 | + wp_redirect(get_permalink($lesson->ID), 301); |
|
| 1063 | + exit; |
|
| 1064 | 1064 | |
| 1065 | - } |
|
| 1065 | + } |
|
| 1066 | 1066 | |
| 1067 | - } // end quiz_has_no_questions |
|
| 1067 | + } // end quiz_has_no_questions |
|
| 1068 | 1068 | |
| 1069 | 1069 | /** |
| 1070 | - * Deprecate the sensei_single_main_content on the single-quiz template. |
|
| 1071 | - * |
|
| 1072 | - * @deprecated since 1.9.0 |
|
| 1073 | - */ |
|
| 1070 | + * Deprecate the sensei_single_main_content on the single-quiz template. |
|
| 1071 | + * |
|
| 1072 | + * @deprecated since 1.9.0 |
|
| 1073 | + */ |
|
| 1074 | 1074 | public static function deprecate_quiz_sensei_single_main_content_hook(){ |
| 1075 | 1075 | |
| 1076 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
| 1076 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
| 1077 | 1077 | |
| 1078 | 1078 | } |
| 1079 | - /* |
|
| 1079 | + /* |
|
| 1080 | 1080 | * Deprecate the sensei_quiz_single_title on the single-quiz template. |
| 1081 | 1081 | * |
| 1082 | 1082 | * @deprecated since 1.9.0 |
| 1083 | 1083 | */ |
| 1084 | - public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
| 1084 | + public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
| 1085 | 1085 | |
| 1086 | - sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
| 1086 | + sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
| 1087 | 1087 | |
| 1088 | - } |
|
| 1088 | + } |
|
| 1089 | 1089 | |
| 1090 | - /** |
|
| 1091 | - * Filter the single title and add the Quiz to it. |
|
| 1092 | - * |
|
| 1093 | - * @param string $title |
|
| 1094 | - * @param int $id title post id |
|
| 1095 | - * @return string $quiz_title |
|
| 1096 | - */ |
|
| 1097 | - public static function single_quiz_title( $title, $post_id ){ |
|
| 1090 | + /** |
|
| 1091 | + * Filter the single title and add the Quiz to it. |
|
| 1092 | + * |
|
| 1093 | + * @param string $title |
|
| 1094 | + * @param int $id title post id |
|
| 1095 | + * @return string $quiz_title |
|
| 1096 | + */ |
|
| 1097 | + public static function single_quiz_title( $title, $post_id ){ |
|
| 1098 | 1098 | |
| 1099 | - if( 'quiz' == get_post_type( $post_id ) ){ |
|
| 1099 | + if( 'quiz' == get_post_type( $post_id ) ){ |
|
| 1100 | 1100 | |
| 1101 | - $title_with_no_quizzes = $title; |
|
| 1101 | + $title_with_no_quizzes = $title; |
|
| 1102 | 1102 | |
| 1103 | - // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
| 1104 | - if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
| 1103 | + // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
| 1104 | + if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
| 1105 | 1105 | |
| 1106 | - // remove all possible appearances of quiz |
|
| 1107 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
| 1108 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
| 1109 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
| 1106 | + // remove all possible appearances of quiz |
|
| 1107 | + $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
| 1108 | + $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
| 1109 | + $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
| 1110 | 1110 | |
| 1111 | - } |
|
| 1111 | + } |
|
| 1112 | 1112 | |
| 1113 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
| 1114 | - } |
|
| 1113 | + $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
| 1114 | + } |
|
| 1115 | 1115 | |
| 1116 | - /** |
|
| 1117 | - * hook document in class-woothemes-sensei-message.php |
|
| 1118 | - */ |
|
| 1119 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
| 1116 | + /** |
|
| 1117 | + * hook document in class-woothemes-sensei-message.php |
|
| 1118 | + */ |
|
| 1119 | + return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
| 1120 | 1120 | |
| 1121 | - } |
|
| 1121 | + } |
|
| 1122 | 1122 | |
| 1123 | - /** |
|
| 1124 | - * Initialize the quiz question loop on the single quiz template |
|
| 1125 | - * |
|
| 1126 | - * The function will create a global quiz loop varialbe. |
|
| 1127 | - * |
|
| 1128 | - * @since 1.9.0 |
|
| 1129 | - * |
|
| 1130 | - */ |
|
| 1131 | - public static function start_quiz_questions_loop(){ |
|
| 1123 | + /** |
|
| 1124 | + * Initialize the quiz question loop on the single quiz template |
|
| 1125 | + * |
|
| 1126 | + * The function will create a global quiz loop varialbe. |
|
| 1127 | + * |
|
| 1128 | + * @since 1.9.0 |
|
| 1129 | + * |
|
| 1130 | + */ |
|
| 1131 | + public static function start_quiz_questions_loop(){ |
|
| 1132 | 1132 | |
| 1133 | - global $sensei_question_loop; |
|
| 1133 | + global $sensei_question_loop; |
|
| 1134 | 1134 | |
| 1135 | - //intialize the questions loop object |
|
| 1136 | - $sensei_question_loop['current'] = -1; |
|
| 1137 | - $sensei_question_loop['total'] = 0; |
|
| 1138 | - $sensei_question_loop['questions'] = array(); |
|
| 1135 | + //intialize the questions loop object |
|
| 1136 | + $sensei_question_loop['current'] = -1; |
|
| 1137 | + $sensei_question_loop['total'] = 0; |
|
| 1138 | + $sensei_question_loop['questions'] = array(); |
|
| 1139 | 1139 | |
| 1140 | 1140 | |
| 1141 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
| 1141 | + $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
| 1142 | 1142 | |
| 1143 | - if( count( $questions ) > 0 ){ |
|
| 1143 | + if( count( $questions ) > 0 ){ |
|
| 1144 | 1144 | |
| 1145 | - $sensei_question_loop['total'] = count( $questions ); |
|
| 1146 | - $sensei_question_loop['questions'] = $questions; |
|
| 1147 | - $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
| 1145 | + $sensei_question_loop['total'] = count( $questions ); |
|
| 1146 | + $sensei_question_loop['questions'] = $questions; |
|
| 1147 | + $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
| 1148 | 1148 | |
| 1149 | - } |
|
| 1149 | + } |
|
| 1150 | 1150 | |
| 1151 | - }// static function |
|
| 1151 | + }// static function |
|
| 1152 | 1152 | |
| 1153 | - /** |
|
| 1154 | - * Initialize the quiz question loop on the single quiz template |
|
| 1155 | - * |
|
| 1156 | - * The function will create a global quiz loop varialbe. |
|
| 1157 | - * |
|
| 1158 | - * @since 1.9.0 |
|
| 1159 | - * |
|
| 1160 | - */ |
|
| 1161 | - public static function stop_quiz_questions_loop(){ |
|
| 1153 | + /** |
|
| 1154 | + * Initialize the quiz question loop on the single quiz template |
|
| 1155 | + * |
|
| 1156 | + * The function will create a global quiz loop varialbe. |
|
| 1157 | + * |
|
| 1158 | + * @since 1.9.0 |
|
| 1159 | + * |
|
| 1160 | + */ |
|
| 1161 | + public static function stop_quiz_questions_loop(){ |
|
| 1162 | 1162 | |
| 1163 | - $sensei_question_loop['total'] = 0; |
|
| 1164 | - $sensei_question_loop['questions'] = array(); |
|
| 1165 | - $sensei_question_loop['quiz_id'] = ''; |
|
| 1163 | + $sensei_question_loop['total'] = 0; |
|
| 1164 | + $sensei_question_loop['questions'] = array(); |
|
| 1165 | + $sensei_question_loop['quiz_id'] = ''; |
|
| 1166 | 1166 | |
| 1167 | - } |
|
| 1167 | + } |
|
| 1168 | 1168 | |
| 1169 | - /** |
|
| 1170 | - * Output the title for the single quiz page |
|
| 1171 | - * |
|
| 1172 | - * @since 1.9.0 |
|
| 1173 | - */ |
|
| 1174 | - public static function the_title(){ |
|
| 1175 | - ?> |
|
| 1169 | + /** |
|
| 1170 | + * Output the title for the single quiz page |
|
| 1171 | + * |
|
| 1172 | + * @since 1.9.0 |
|
| 1173 | + */ |
|
| 1174 | + public static function the_title(){ |
|
| 1175 | + ?> |
|
| 1176 | 1176 | <header> |
| 1177 | 1177 | |
| 1178 | 1178 | <h1> |
| 1179 | 1179 | |
| 1180 | 1180 | <?php |
| 1181 | - /** |
|
| 1182 | - * Filter documented in class-sensei-messages.php the_title |
|
| 1183 | - */ |
|
| 1184 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
| 1185 | - ?> |
|
| 1181 | + /** |
|
| 1182 | + * Filter documented in class-sensei-messages.php the_title |
|
| 1183 | + */ |
|
| 1184 | + echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
| 1185 | + ?> |
|
| 1186 | 1186 | |
| 1187 | 1187 | </h1> |
| 1188 | 1188 | |
| 1189 | 1189 | </header> |
| 1190 | 1190 | |
| 1191 | 1191 | <?php |
| 1192 | - }//the_title |
|
| 1192 | + }//the_title |
|
| 1193 | 1193 | |
| 1194 | - /** |
|
| 1195 | - * Output the sensei quiz status message. |
|
| 1196 | - * |
|
| 1197 | - * @param $quiz_id |
|
| 1198 | - */ |
|
| 1199 | - public static function the_user_status_message( $quiz_id ){ |
|
| 1194 | + /** |
|
| 1195 | + * Output the sensei quiz status message. |
|
| 1196 | + * |
|
| 1197 | + * @param $quiz_id |
|
| 1198 | + */ |
|
| 1199 | + public static function the_user_status_message( $quiz_id ){ |
|
| 1200 | 1200 | |
| 1201 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 1202 | - $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
| 1203 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 1201 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 1202 | + $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
| 1203 | + echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 1204 | 1204 | |
| 1205 | - } |
|
| 1205 | + } |
|
| 1206 | 1206 | |
| 1207 | - /** |
|
| 1208 | - * This functions runs the old sensei_quiz_action_buttons action |
|
| 1209 | - * for backwards compatiblity sake. |
|
| 1210 | - * |
|
| 1211 | - * @since 1.9.0 |
|
| 1212 | - * @deprecated |
|
| 1213 | - */ |
|
| 1214 | - public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
| 1207 | + /** |
|
| 1208 | + * This functions runs the old sensei_quiz_action_buttons action |
|
| 1209 | + * for backwards compatiblity sake. |
|
| 1210 | + * |
|
| 1211 | + * @since 1.9.0 |
|
| 1212 | + * @deprecated |
|
| 1213 | + */ |
|
| 1214 | + public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
| 1215 | 1215 | |
| 1216 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1216 | + sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1217 | 1217 | |
| 1218 | - } |
|
| 1218 | + } |
|
| 1219 | 1219 | |
| 1220 | - /** |
|
| 1221 | - * The quiz action buttons needed to ouput quiz |
|
| 1222 | - * action such as reset complete and save. |
|
| 1223 | - * |
|
| 1224 | - * @since 1.3.0 |
|
| 1225 | - */ |
|
| 1226 | - public static function action_buttons() { |
|
| 1220 | + /** |
|
| 1221 | + * The quiz action buttons needed to ouput quiz |
|
| 1222 | + * action such as reset complete and save. |
|
| 1223 | + * |
|
| 1224 | + * @since 1.3.0 |
|
| 1225 | + */ |
|
| 1226 | + public static function action_buttons() { |
|
| 1227 | 1227 | |
| 1228 | - global $post, $current_user; |
|
| 1228 | + global $post, $current_user; |
|
| 1229 | 1229 | |
| 1230 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
| 1231 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 1232 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1233 | - $show_actions = true; |
|
| 1234 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
| 1230 | + $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
| 1231 | + $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 1232 | + $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1233 | + $show_actions = true; |
|
| 1234 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
| 1235 | 1235 | |
| 1236 | - //setup quiz grade |
|
| 1237 | - $user_quiz_grade = ''; |
|
| 1238 | - if( ! empty( $user_lesson_status ) ){ |
|
| 1239 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1240 | - } |
|
| 1236 | + //setup quiz grade |
|
| 1237 | + $user_quiz_grade = ''; |
|
| 1238 | + if( ! empty( $user_lesson_status ) ){ |
|
| 1239 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1240 | + } |
|
| 1241 | 1241 | |
| 1242 | 1242 | |
| 1243 | - if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 1243 | + if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 1244 | 1244 | |
| 1245 | - // If the user hasn't completed the prereq then hide the current actions |
|
| 1246 | - $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
| 1245 | + // If the user hasn't completed the prereq then hide the current actions |
|
| 1246 | + $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
| 1247 | 1247 | |
| 1248 | - } |
|
| 1249 | - if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 1248 | + } |
|
| 1249 | + if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 1250 | 1250 | |
| 1251 | - // Get Reset Settings |
|
| 1252 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
| 1251 | + // Get Reset Settings |
|
| 1252 | + $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
| 1253 | 1253 | |
| 1254 | 1254 | <!-- Action Nonce's --> |
| 1255 | 1255 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" |
@@ -1276,55 +1276,55 @@ discard block |
||
| 1276 | 1276 | |
| 1277 | 1277 | <?php } |
| 1278 | 1278 | |
| 1279 | - } // End sensei_quiz_action_buttons() |
|
| 1280 | - |
|
| 1281 | - /** |
|
| 1282 | - * Fetch the quiz grade |
|
| 1283 | - * |
|
| 1284 | - * @since 1.9.0 |
|
| 1285 | - * |
|
| 1286 | - * @param int $lesson_id |
|
| 1287 | - * @param int $user_id |
|
| 1288 | - * |
|
| 1289 | - * @return double $user_quiz_grade |
|
| 1290 | - */ |
|
| 1291 | - public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
| 1292 | - |
|
| 1293 | - // get the quiz grade |
|
| 1294 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1295 | - $user_quiz_grade = 0; |
|
| 1296 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 1297 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1298 | - } |
|
| 1299 | - |
|
| 1300 | - return (double) $user_quiz_grade; |
|
| 1301 | - |
|
| 1302 | - } |
|
| 1303 | - |
|
| 1304 | - /** |
|
| 1305 | - * Check the quiz reset property for a given lesson's quiz. |
|
| 1306 | - * |
|
| 1307 | - * The data is stored on the quiz but going forward the quiz post |
|
| 1308 | - * type will be retired, hence the lesson_id is a require parameter. |
|
| 1309 | - * |
|
| 1310 | - * @since 1.9.0 |
|
| 1311 | - * |
|
| 1312 | - * @param int $lesson_id |
|
| 1313 | - * @return bool |
|
| 1314 | - */ |
|
| 1315 | - public static function is_reset_allowed( $lesson_id ){ |
|
| 1316 | - |
|
| 1317 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1318 | - |
|
| 1319 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 1320 | - //backwards compatibility |
|
| 1321 | - if( 'on' == $reset_allowed ) { |
|
| 1322 | - $reset_allowed = 1; |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - return (bool) $reset_allowed; |
|
| 1326 | - |
|
| 1327 | - } |
|
| 1279 | + } // End sensei_quiz_action_buttons() |
|
| 1280 | + |
|
| 1281 | + /** |
|
| 1282 | + * Fetch the quiz grade |
|
| 1283 | + * |
|
| 1284 | + * @since 1.9.0 |
|
| 1285 | + * |
|
| 1286 | + * @param int $lesson_id |
|
| 1287 | + * @param int $user_id |
|
| 1288 | + * |
|
| 1289 | + * @return double $user_quiz_grade |
|
| 1290 | + */ |
|
| 1291 | + public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
| 1292 | + |
|
| 1293 | + // get the quiz grade |
|
| 1294 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1295 | + $user_quiz_grade = 0; |
|
| 1296 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 1297 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1298 | + } |
|
| 1299 | + |
|
| 1300 | + return (double) $user_quiz_grade; |
|
| 1301 | + |
|
| 1302 | + } |
|
| 1303 | + |
|
| 1304 | + /** |
|
| 1305 | + * Check the quiz reset property for a given lesson's quiz. |
|
| 1306 | + * |
|
| 1307 | + * The data is stored on the quiz but going forward the quiz post |
|
| 1308 | + * type will be retired, hence the lesson_id is a require parameter. |
|
| 1309 | + * |
|
| 1310 | + * @since 1.9.0 |
|
| 1311 | + * |
|
| 1312 | + * @param int $lesson_id |
|
| 1313 | + * @return bool |
|
| 1314 | + */ |
|
| 1315 | + public static function is_reset_allowed( $lesson_id ){ |
|
| 1316 | + |
|
| 1317 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1318 | + |
|
| 1319 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 1320 | + //backwards compatibility |
|
| 1321 | + if( 'on' == $reset_allowed ) { |
|
| 1322 | + $reset_allowed = 1; |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + return (bool) $reset_allowed; |
|
| 1326 | + |
|
| 1327 | + } |
|
| 1328 | 1328 | |
| 1329 | 1329 | } // End Class WooThemes_Sensei_Quiz |
| 1330 | 1330 | |
@@ -793,7 +793,7 @@ |
||
| 793 | 793 | * Return an array of field types expecting an array value returned. |
| 794 | 794 | * @access protected |
| 795 | 795 | * @since 1.0.0 |
| 796 | - * @return void |
|
| 796 | + * @return string[] |
|
| 797 | 797 | */ |
| 798 | 798 | protected function get_array_field_types () { |
| 799 | 799 | return array( 'multicheck' ); |
@@ -1,5 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Analysis User Profile List Table Class |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function register_hook_listener() { |
| 61 | 61 | |
| 62 | - add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 ); |
|
| 62 | + add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 ); |
|
| 63 | 63 | add_action( 'admin_init', array( $this, 'settings_fields' ) ); |
| 64 | 64 | add_action( 'init', array( $this, 'general_init' ) ); |
| 65 | 65 | |
@@ -419,9 +419,9 @@ discard block |
||
| 419 | 419 | echo '<input id="' . $args['key'] . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" type="checkbox" value="1"' . checked( esc_attr( $options[$args['key']] ), '1', false ) . ' />' . "\n"; |
| 420 | 420 | if ( $has_description ) { |
| 421 | 421 | echo wp_kses( $args['data']['description'], array( 'a' => array( |
| 422 | - 'href' => array(), |
|
| 423 | - 'title' => array() |
|
| 424 | - ) |
|
| 422 | + 'href' => array(), |
|
| 423 | + 'title' => array() |
|
| 424 | + ) |
|
| 425 | 425 | ) |
| 426 | 426 | ) . '</label>' . "\n"; |
| 427 | 427 | } |
@@ -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 Settings API Class |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @since 1.0.0 |
| 35 | 35 | * @return void |
| 36 | 36 | */ |
| 37 | - public function __construct () { |
|
| 37 | + public function __construct() { |
|
| 38 | 38 | $this->token = 'woothemes-sensei-settings'; |
| 39 | 39 | $this->page_slug = 'woothemes-sensei-settings-api'; |
| 40 | 40 | |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function register_hook_listener() { |
| 61 | 61 | |
| 62 | - add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 ); |
|
| 63 | - add_action( 'admin_init', array( $this, 'settings_fields' ) ); |
|
| 64 | - add_action( 'init', array( $this, 'general_init' ) ); |
|
| 62 | + add_action('admin_menu', array($this, 'register_settings_screen'), 60); |
|
| 63 | + add_action('admin_init', array($this, 'settings_fields')); |
|
| 64 | + add_action('init', array($this, 'general_init')); |
|
| 65 | 65 | |
| 66 | 66 | } // End setup_settings() |
| 67 | 67 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $this->init_sections(); |
| 76 | 76 | $this->init_fields(); |
| 77 | 77 | $this->get_settings(); |
| 78 | - if ( $this->has_tabs == true ) { |
|
| 78 | + if ($this->has_tabs == true) { |
|
| 79 | 79 | $this->create_tabs(); |
| 80 | 80 | } // End If Statement |
| 81 | 81 | } // End general_init() |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | * @since 1.0.0 |
| 87 | 87 | * @return void |
| 88 | 88 | */ |
| 89 | - public function init_sections () { |
|
| 89 | + public function init_sections() { |
|
| 90 | 90 | // Override this function in your class and assign the array of sections to $this->sections. |
| 91 | - _e( 'Override init_sections() in your class.', 'woothemes-sensei' ); |
|
| 91 | + _e('Override init_sections() in your class.', 'woothemes-sensei'); |
|
| 92 | 92 | } // End init_sections() |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -97,9 +97,9 @@ discard block |
||
| 97 | 97 | * @since 1.0.0 |
| 98 | 98 | * @return void |
| 99 | 99 | */ |
| 100 | - public function init_fields () { |
|
| 100 | + public function init_fields() { |
|
| 101 | 101 | // Override this function in your class and assign the array of sections to $this->fields. |
| 102 | - _e( 'Override init_fields() in your class.', 'woothemes-sensei' ); |
|
| 102 | + _e('Override init_fields() in your class.', 'woothemes-sensei'); |
|
| 103 | 103 | } // End init_fields() |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -108,33 +108,33 @@ discard block |
||
| 108 | 108 | * @since 1.1.0 |
| 109 | 109 | * @return void |
| 110 | 110 | */ |
| 111 | - public function settings_tabs () { |
|
| 112 | - if ( ! $this->has_tabs ) { return; } |
|
| 111 | + public function settings_tabs() { |
|
| 112 | + if ( ! $this->has_tabs) { return; } |
|
| 113 | 113 | |
| 114 | - if ( count( $this->tabs ) > 0 ) { |
|
| 114 | + if (count($this->tabs) > 0) { |
|
| 115 | 115 | $html = ''; |
| 116 | 116 | |
| 117 | - $html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">' . "\n"; |
|
| 117 | + $html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">'."\n"; |
|
| 118 | 118 | |
| 119 | 119 | $sections = array( |
| 120 | - 'all' => array( 'href' => '#all', 'name' => __( 'All', 'woothemes-sensei' ), 'class' => 'current all tab' ) |
|
| 120 | + 'all' => array('href' => '#all', 'name' => __('All', 'woothemes-sensei'), 'class' => 'current all tab') |
|
| 121 | 121 | ); |
| 122 | 122 | |
| 123 | - foreach ( $this->tabs as $k => $v ) { |
|
| 124 | - $sections[$k] = array( 'href' => '#' . esc_attr( $k ), 'name' => esc_attr( $v['name'] ), 'class' => 'tab' ); |
|
| 123 | + foreach ($this->tabs as $k => $v) { |
|
| 124 | + $sections[$k] = array('href' => '#'.esc_attr($k), 'name' => esc_attr($v['name']), 'class' => 'tab'); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $count = 1; |
| 128 | - foreach ( $sections as $k => $v ) { |
|
| 128 | + foreach ($sections as $k => $v) { |
|
| 129 | 129 | $count++; |
| 130 | - $html .= '<li><a href="' . $v['href'] . '"'; |
|
| 131 | - if ( isset( $v['class'] ) && ( $v['class'] != '' ) ) { $html .= ' class="' . esc_attr( $v['class'] ) . '"'; } |
|
| 132 | - $html .= '>' . esc_attr( $v['name'] ) . '</a>'; |
|
| 133 | - if ( $count <= count( $sections ) ) { $html .= ' | '; } |
|
| 134 | - $html .= '</li>' . "\n"; |
|
| 130 | + $html .= '<li><a href="'.$v['href'].'"'; |
|
| 131 | + if (isset($v['class']) && ($v['class'] != '')) { $html .= ' class="'.esc_attr($v['class']).'"'; } |
|
| 132 | + $html .= '>'.esc_attr($v['name']).'</a>'; |
|
| 133 | + if ($count <= count($sections)) { $html .= ' | '; } |
|
| 134 | + $html .= '</li>'."\n"; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $html .= '</ul><div class="clear"></div>' . "\n"; |
|
| 137 | + $html .= '</ul><div class="clear"></div>'."\n"; |
|
| 138 | 138 | |
| 139 | 139 | echo $html; |
| 140 | 140 | } |
@@ -146,10 +146,10 @@ discard block |
||
| 146 | 146 | * @since 1.1.0 |
| 147 | 147 | * @return void |
| 148 | 148 | */ |
| 149 | - private function create_tabs () { |
|
| 150 | - if ( count( $this->sections ) > 0 ) { |
|
| 149 | + private function create_tabs() { |
|
| 150 | + if (count($this->sections) > 0) { |
|
| 151 | 151 | $tabs = array(); |
| 152 | - foreach ( $this->sections as $k => $v ) { |
|
| 152 | + foreach ($this->sections as $k => $v) { |
|
| 153 | 153 | $tabs[$k] = $v; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | * @since 1.0.0 |
| 164 | 164 | * @return void |
| 165 | 165 | */ |
| 166 | - public function create_sections () { |
|
| 167 | - if ( count( $this->sections ) > 0 ) { |
|
| 168 | - foreach ( $this->sections as $k => $v ) { |
|
| 169 | - add_settings_section( $k, $v['name'], array( $this, 'section_description' ), $this->token ); |
|
| 166 | + public function create_sections() { |
|
| 167 | + if (count($this->sections) > 0) { |
|
| 168 | + foreach ($this->sections as $k => $v) { |
|
| 169 | + add_settings_section($k, $v['name'], array($this, 'section_description'), $this->token); |
|
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | } // End create_sections() |
@@ -177,18 +177,18 @@ discard block |
||
| 177 | 177 | * @since 1.0.0 |
| 178 | 178 | * @return void |
| 179 | 179 | */ |
| 180 | - public function create_fields () { |
|
| 181 | - if ( count( $this->sections ) > 0 ) { |
|
| 180 | + public function create_fields() { |
|
| 181 | + if (count($this->sections) > 0) { |
|
| 182 | 182 | // $this->parse_fields( $this->fields ); |
| 183 | 183 | |
| 184 | - foreach ( $this->fields as $k => $v ) { |
|
| 185 | - $method = $this->determine_method( $v, 'form' ); |
|
| 184 | + foreach ($this->fields as $k => $v) { |
|
| 185 | + $method = $this->determine_method($v, 'form'); |
|
| 186 | 186 | $name = $v['name']; |
| 187 | - if ( $v['type'] == 'info' ) { $name = ''; } |
|
| 188 | - add_settings_field( $k, $name, $method, $this->token, $v['section'], array( 'key' => $k, 'data' => $v ) ); |
|
| 187 | + if ($v['type'] == 'info') { $name = ''; } |
|
| 188 | + add_settings_field($k, $name, $method, $this->token, $v['section'], array('key' => $k, 'data' => $v)); |
|
| 189 | 189 | |
| 190 | 190 | // Let the API know that we have a colourpicker field. |
| 191 | - if ( $v['type'] == 'range' && $this->has_range == false ) { $this->has_range = true; } |
|
| 191 | + if ($v['type'] == 'range' && $this->has_range == false) { $this->has_range = true; } |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | } // End create_fields() |
@@ -200,43 +200,43 @@ discard block |
||
| 200 | 200 | * @param array $data |
| 201 | 201 | * @return callable, array or string |
| 202 | 202 | */ |
| 203 | - protected function determine_method ( $data, $type = 'form' ) { |
|
| 203 | + protected function determine_method($data, $type = 'form') { |
|
| 204 | 204 | $method = ''; |
| 205 | 205 | |
| 206 | - if ( ! in_array( $type, array( 'form', 'validate', 'check' ) ) ) { return; } |
|
| 206 | + if ( ! in_array($type, array('form', 'validate', 'check'))) { return; } |
|
| 207 | 207 | |
| 208 | 208 | // Check for custom functions. |
| 209 | - if ( isset( $data[$type] ) ) { |
|
| 210 | - if ( function_exists( $data[$type] ) ) { |
|
| 209 | + if (isset($data[$type])) { |
|
| 210 | + if (function_exists($data[$type])) { |
|
| 211 | 211 | $method = $data[$type]; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - if ( $method == '' && method_exists( $this, $data[$type] ) ) { |
|
| 215 | - if ( $type == 'form' ) { |
|
| 216 | - $method = array( $this, $data[$type] ); |
|
| 214 | + if ($method == '' && method_exists($this, $data[$type])) { |
|
| 215 | + if ($type == 'form') { |
|
| 216 | + $method = array($this, $data[$type]); |
|
| 217 | 217 | } else { |
| 218 | 218 | $method = $data[$type]; |
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if ( $method == '' && method_exists ( $this, $type . '_field_' . $data['type'] ) ) { |
|
| 224 | - if ( $type == 'form' ) { |
|
| 225 | - $method = array( $this, $type . '_field_' . $data['type'] ); |
|
| 223 | + if ($method == '' && method_exists($this, $type.'_field_'.$data['type'])) { |
|
| 224 | + if ($type == 'form') { |
|
| 225 | + $method = array($this, $type.'_field_'.$data['type']); |
|
| 226 | 226 | } else { |
| 227 | - $method = $type . '_field_' . $data['type']; |
|
| 227 | + $method = $type.'_field_'.$data['type']; |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if ( $method == '' && function_exists ( $this->token . '_' . $type . '_field_' . $data['type'] ) ) { |
|
| 232 | - $method = $this->token . '_' . $type . '_field_' . $data['type']; |
|
| 231 | + if ($method == '' && function_exists($this->token.'_'.$type.'_field_'.$data['type'])) { |
|
| 232 | + $method = $this->token.'_'.$type.'_field_'.$data['type']; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - if ( $method == '' ) { |
|
| 236 | - if ( $type == 'form' ) { |
|
| 237 | - $method = array( $this, $type . '_field_text' ); |
|
| 235 | + if ($method == '') { |
|
| 236 | + if ($type == 'form') { |
|
| 237 | + $method = array($this, $type.'_field_text'); |
|
| 238 | 238 | } else { |
| 239 | - $method = $type . '_field_text'; |
|
| 239 | + $method = $type.'_field_text'; |
|
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | |
@@ -250,10 +250,10 @@ discard block |
||
| 250 | 250 | * @param array $fields |
| 251 | 251 | * @return void |
| 252 | 252 | */ |
| 253 | - public function parse_fields ( $fields ) { |
|
| 254 | - foreach ( $fields as $k => $v ) { |
|
| 255 | - if ( isset( $v['section'] ) && ( $v['section'] != '' ) && ( isset( $this->sections[$v['section']] ) ) ) { |
|
| 256 | - if ( ! isset( $this->sections[$v['section']]['fields'] ) ) { |
|
| 253 | + public function parse_fields($fields) { |
|
| 254 | + foreach ($fields as $k => $v) { |
|
| 255 | + if (isset($v['section']) && ($v['section'] != '') && (isset($this->sections[$v['section']]))) { |
|
| 256 | + if ( ! isset($this->sections[$v['section']]['fields'])) { |
|
| 257 | 257 | $this->sections[$v['section']]['fields'] = array(); |
| 258 | 258 | } |
| 259 | 259 | |
@@ -270,19 +270,19 @@ discard block |
||
| 270 | 270 | * @since 1.0.0 |
| 271 | 271 | * @return void |
| 272 | 272 | */ |
| 273 | - public function register_settings_screen () { |
|
| 273 | + public function register_settings_screen() { |
|
| 274 | 274 | |
| 275 | 275 | |
| 276 | - if ( current_user_can( 'manage_sensei' ) ) { |
|
| 277 | - $hook = add_submenu_page( 'sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array( $this, 'settings_screen' ) ); |
|
| 276 | + if (current_user_can('manage_sensei')) { |
|
| 277 | + $hook = add_submenu_page('sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array($this, 'settings_screen')); |
|
| 278 | 278 | |
| 279 | 279 | $this->hook = $hook; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) { |
|
| 283 | - add_action( 'admin_notices', array( $this, 'settings_errors' ) ); |
|
| 284 | - add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 285 | - add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) ); |
|
| 282 | + if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) { |
|
| 283 | + add_action('admin_notices', array($this, 'settings_errors')); |
|
| 284 | + add_action('admin_print_scripts', array($this, 'enqueue_scripts')); |
|
| 285 | + add_action('admin_print_styles', array($this, 'enqueue_styles')); |
|
| 286 | 286 | } |
| 287 | 287 | } // End register_settings_screen() |
| 288 | 288 | |
@@ -292,21 +292,21 @@ discard block |
||
| 292 | 292 | * @since 1.0.0 |
| 293 | 293 | * @return void |
| 294 | 294 | */ |
| 295 | - public function settings_screen () { |
|
| 295 | + public function settings_screen() { |
|
| 296 | 296 | |
| 297 | 297 | ?> |
| 298 | -<div id="woothemes-sensei" class="wrap <?php echo esc_attr( $this->token ); ?>"> |
|
| 299 | - <?php screen_icon( 'woothemes-sensei' ); ?> |
|
| 300 | - <h2><?php echo esc_html( $this->name ); ?><?php if ( '' != $this->settings_version ) { echo ' <span class="version">' . $this->settings_version . '</span>'; } ?></h2> |
|
| 301 | - <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> |
|
| 302 | - <?php do_action( 'settings_before_form' ); ?> |
|
| 298 | +<div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>"> |
|
| 299 | + <?php screen_icon('woothemes-sensei'); ?> |
|
| 300 | + <h2><?php echo esc_html($this->name); ?><?php if ('' != $this->settings_version) { echo ' <span class="version">'.$this->settings_version.'</span>'; } ?></h2> |
|
| 301 | + <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> |
|
| 302 | + <?php do_action('settings_before_form'); ?> |
|
| 303 | 303 | <form action="options.php" method="post"> |
| 304 | 304 | <?php $this->settings_tabs(); ?> |
| 305 | - <?php settings_fields( $this->token ); ?> |
|
| 306 | - <?php do_settings_sections( $this->token ); ?> |
|
| 305 | + <?php settings_fields($this->token); ?> |
|
| 306 | + <?php do_settings_sections($this->token); ?> |
|
| 307 | 307 | <?php submit_button(); ?> |
| 308 | 308 | </form> |
| 309 | - <?php do_action( 'settings_after_form' ); ?> |
|
| 309 | + <?php do_action('settings_after_form'); ?> |
|
| 310 | 310 | </div><!--/#woothemes-sensei--> |
| 311 | 311 | <?php |
| 312 | 312 | } // End settings_screen() |
@@ -317,16 +317,16 @@ discard block |
||
| 317 | 317 | * @since 1.0.0 |
| 318 | 318 | * @return array |
| 319 | 319 | */ |
| 320 | - public function get_settings () { |
|
| 321 | - if ( ! is_array( $this->settings ) ) { |
|
| 322 | - $this->settings = get_option( $this->token, array() ); |
|
| 320 | + public function get_settings() { |
|
| 321 | + if ( ! is_array($this->settings)) { |
|
| 322 | + $this->settings = get_option($this->token, array()); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - foreach ( $this->fields as $k => $v ) { |
|
| 326 | - if ( ! isset( $this->settings[$k] ) && isset( $v['default'] ) ) { |
|
| 325 | + foreach ($this->fields as $k => $v) { |
|
| 326 | + if ( ! isset($this->settings[$k]) && isset($v['default'])) { |
|
| 327 | 327 | $this->settings[$k] = $v['default']; |
| 328 | 328 | } |
| 329 | - if ( $v['type'] == 'checkbox' && $this->settings[$k] != true ) { |
|
| 329 | + if ($v['type'] == 'checkbox' && $this->settings[$k] != true) { |
|
| 330 | 330 | $this->settings[$k] = 0; |
| 331 | 331 | } |
| 332 | 332 | } |
@@ -340,8 +340,8 @@ discard block |
||
| 340 | 340 | * @since 1.0.0 |
| 341 | 341 | * @return void |
| 342 | 342 | */ |
| 343 | - public function settings_fields () { |
|
| 344 | - register_setting( $this->token, $this->token, array( $this, 'validate_fields' ) ); |
|
| 343 | + public function settings_fields() { |
|
| 344 | + register_setting($this->token, $this->token, array($this, 'validate_fields')); |
|
| 345 | 345 | $this->create_sections(); |
| 346 | 346 | $this->create_fields(); |
| 347 | 347 | } // End settings_fields() |
@@ -352,8 +352,8 @@ discard block |
||
| 352 | 352 | * @since 1.0.0 |
| 353 | 353 | * @return void |
| 354 | 354 | */ |
| 355 | - public function settings_errors () { |
|
| 356 | - echo settings_errors( $this->token . '-errors' ); |
|
| 355 | + public function settings_errors() { |
|
| 356 | + echo settings_errors($this->token.'-errors'); |
|
| 357 | 357 | } // End settings_errors() |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -362,9 +362,9 @@ discard block |
||
| 362 | 362 | * @since 1.0.0 |
| 363 | 363 | * @return void |
| 364 | 364 | */ |
| 365 | - public function section_description ( $section ) { |
|
| 366 | - if ( isset( $this->sections[$section['id']]['description'] ) ) { |
|
| 367 | - echo wpautop( $this->sections[$section['id']]['description'] ); |
|
| 365 | + public function section_description($section) { |
|
| 366 | + if (isset($this->sections[$section['id']]['description'])) { |
|
| 367 | + echo wpautop($this->sections[$section['id']]['description']); |
|
| 368 | 368 | } |
| 369 | 369 | } // End section_description_main() |
| 370 | 370 | |
@@ -375,12 +375,12 @@ discard block |
||
| 375 | 375 | * @param array $args |
| 376 | 376 | * @return void |
| 377 | 377 | */ |
| 378 | - public function form_field_text ( $args ) { |
|
| 378 | + public function form_field_text($args) { |
|
| 379 | 379 | $options = $this->get_settings(); |
| 380 | 380 | |
| 381 | - echo '<input id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" size="40" type="text" value="' . esc_attr( $options[$args['key']] ) . '" />' . "\n"; |
|
| 382 | - if ( isset( $args['data']['description'] ) ) { |
|
| 383 | - echo '<span class="description">' . $args['data']['description'] . '</span>' . "\n"; |
|
| 381 | + echo '<input id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" size="40" type="text" value="'.esc_attr($options[$args['key']]).'" />'."\n"; |
|
| 382 | + if (isset($args['data']['description'])) { |
|
| 383 | + echo '<span class="description">'.$args['data']['description'].'</span>'."\n"; |
|
| 384 | 384 | } |
| 385 | 385 | } // End form_field_text() |
| 386 | 386 | |
@@ -391,13 +391,13 @@ discard block |
||
| 391 | 391 | * @param array $args |
| 392 | 392 | * @return void |
| 393 | 393 | */ |
| 394 | - public function form_field_color ( $args ) { |
|
| 394 | + public function form_field_color($args) { |
|
| 395 | 395 | $options = $this->get_settings(); |
| 396 | 396 | |
| 397 | - echo '<input id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" size="40" type="text" class="color" value="' . esc_attr( $options[$args['key']] ) . '" />' . "\n"; |
|
| 397 | + echo '<input id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" size="40" type="text" class="color" value="'.esc_attr($options[$args['key']]).'" />'."\n"; |
|
| 398 | 398 | echo '<div style="position:absolute;background:#FFF;z-index:99;border-radius:100%;" class="colorpicker"></div>'; |
| 399 | - if ( isset( $args['data']['description'] ) ) { |
|
| 400 | - echo '<span class="description">' . $args['data']['description'] . '</span>' . "\n"; |
|
| 399 | + if (isset($args['data']['description'])) { |
|
| 400 | + echo '<span class="description">'.$args['data']['description'].'</span>'."\n"; |
|
| 401 | 401 | } |
| 402 | 402 | } // End form_field_text() |
| 403 | 403 | |
@@ -408,22 +408,22 @@ discard block |
||
| 408 | 408 | * @param array $args |
| 409 | 409 | * @return void |
| 410 | 410 | */ |
| 411 | - public function form_field_checkbox ( $args ) { |
|
| 411 | + public function form_field_checkbox($args) { |
|
| 412 | 412 | $options = $this->get_settings(); |
| 413 | 413 | |
| 414 | 414 | $has_description = false; |
| 415 | - if ( isset( $args['data']['description'] ) ) { |
|
| 415 | + if (isset($args['data']['description'])) { |
|
| 416 | 416 | $has_description = true; |
| 417 | - echo '<label for="' . esc_attr( $args['key'] ) . '">' . "\n"; |
|
| 417 | + echo '<label for="'.esc_attr($args['key']).'">'."\n"; |
|
| 418 | 418 | } |
| 419 | - echo '<input id="' . $args['key'] . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" type="checkbox" value="1"' . checked( esc_attr( $options[$args['key']] ), '1', false ) . ' />' . "\n"; |
|
| 420 | - if ( $has_description ) { |
|
| 421 | - echo wp_kses( $args['data']['description'], array( 'a' => array( |
|
| 419 | + echo '<input id="'.$args['key'].'" name="'.$this->token.'['.esc_attr($args['key']).']" type="checkbox" value="1"'.checked(esc_attr($options[$args['key']]), '1', false).' />'."\n"; |
|
| 420 | + if ($has_description) { |
|
| 421 | + echo wp_kses($args['data']['description'], array('a' => array( |
|
| 422 | 422 | 'href' => array(), |
| 423 | 423 | 'title' => array() |
| 424 | 424 | ) |
| 425 | 425 | ) |
| 426 | - ) . '</label>' . "\n"; |
|
| 426 | + ).'</label>'."\n"; |
|
| 427 | 427 | } |
| 428 | 428 | } // End form_field_checkbox() |
| 429 | 429 | |
@@ -434,12 +434,12 @@ discard block |
||
| 434 | 434 | * @param array $args |
| 435 | 435 | * @return void |
| 436 | 436 | */ |
| 437 | - public function form_field_textarea ( $args ) { |
|
| 437 | + public function form_field_textarea($args) { |
|
| 438 | 438 | $options = $this->get_settings(); |
| 439 | 439 | |
| 440 | - echo '<textarea id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" cols="42" rows="5">' . esc_html( $options[$args['key']] ) . '</textarea>' . "\n"; |
|
| 441 | - if ( isset( $args['data']['description'] ) ) { |
|
| 442 | - echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n"; |
|
| 440 | + echo '<textarea id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" cols="42" rows="5">'.esc_html($options[$args['key']]).'</textarea>'."\n"; |
|
| 441 | + if (isset($args['data']['description'])) { |
|
| 442 | + echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n"; |
|
| 443 | 443 | } |
| 444 | 444 | } // End form_field_textarea() |
| 445 | 445 | |
@@ -450,20 +450,20 @@ discard block |
||
| 450 | 450 | * @param array $args |
| 451 | 451 | * @return void |
| 452 | 452 | */ |
| 453 | - public function form_field_select ( $args ) { |
|
| 453 | + public function form_field_select($args) { |
|
| 454 | 454 | $options = $this->get_settings(); |
| 455 | 455 | |
| 456 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 456 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 457 | 457 | $html = ''; |
| 458 | - $html .= '<select class="" id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']">' . "\n"; |
|
| 459 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 460 | - $html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $options[$args['key']] ), $k, false ) . '>' . $v . '</option>' . "\n"; |
|
| 458 | + $html .= '<select class="" id="'.esc_attr($args['key']).'" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']">'."\n"; |
|
| 459 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 460 | + $html .= '<option value="'.esc_attr($k).'"'.selected(esc_attr($options[$args['key']]), $k, false).'>'.$v.'</option>'."\n"; |
|
| 461 | 461 | } |
| 462 | - $html .= '</select>' . "\n"; |
|
| 462 | + $html .= '</select>'."\n"; |
|
| 463 | 463 | echo $html; |
| 464 | 464 | |
| 465 | - if ( isset( $args['data']['description'] ) ) { |
|
| 466 | - echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n"; |
|
| 465 | + if (isset($args['data']['description'])) { |
|
| 466 | + echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n"; |
|
| 467 | 467 | } |
| 468 | 468 | } |
| 469 | 469 | } // End form_field_select() |
@@ -475,18 +475,18 @@ discard block |
||
| 475 | 475 | * @param array $args |
| 476 | 476 | * @return void |
| 477 | 477 | */ |
| 478 | - public function form_field_radio ( $args ) { |
|
| 478 | + public function form_field_radio($args) { |
|
| 479 | 479 | $options = $this->get_settings(); |
| 480 | 480 | |
| 481 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 481 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 482 | 482 | $html = ''; |
| 483 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 484 | - $html .= '<input type="radio" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $options[$args['key']] ), $k, false ) . ' /> ' . $v . '<br />' . "\n"; |
|
| 483 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 484 | + $html .= '<input type="radio" name="'.$this->token.'['.esc_attr($args['key']).']" value="'.esc_attr($k).'"'.checked(esc_attr($options[$args['key']]), $k, false).' /> '.$v.'<br />'."\n"; |
|
| 485 | 485 | } |
| 486 | 486 | echo $html; |
| 487 | 487 | |
| 488 | - if ( isset( $args['data']['description'] ) ) { |
|
| 489 | - echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n"; |
|
| 488 | + if (isset($args['data']['description'])) { |
|
| 489 | + echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n"; |
|
| 490 | 490 | } |
| 491 | 491 | } |
| 492 | 492 | } // End form_field_radio() |
@@ -498,28 +498,28 @@ discard block |
||
| 498 | 498 | * @param array $args |
| 499 | 499 | * @return void |
| 500 | 500 | */ |
| 501 | - public function form_field_multicheck ( $args ) { |
|
| 501 | + public function form_field_multicheck($args) { |
|
| 502 | 502 | $options = $this->get_settings(); |
| 503 | 503 | |
| 504 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 505 | - $html = '<div class="multicheck-container" style="margin-bottom:10px;">' . "\n"; |
|
| 506 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 504 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 505 | + $html = '<div class="multicheck-container" style="margin-bottom:10px;">'."\n"; |
|
| 506 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 507 | 507 | $checked = ''; |
| 508 | 508 | |
| 509 | - if( isset( $options[ $args['key'] ] ) ) { |
|
| 510 | - if ( in_array( $k, (array)$options[ $args['key'] ] ) ) { $checked = ' checked="checked"'; } |
|
| 509 | + if (isset($options[$args['key']])) { |
|
| 510 | + if (in_array($k, (array) $options[$args['key']])) { $checked = ' checked="checked"'; } |
|
| 511 | 511 | } else { |
| 512 | - if ( in_array( $k, $args['data']['defaults'] ) ) { $checked = ' checked="checked"'; } |
|
| 512 | + if (in_array($k, $args['data']['defaults'])) { $checked = ' checked="checked"'; } |
|
| 513 | 513 | } |
| 514 | - $html .= '<label for="checkbox-' . esc_attr( $k ) . '">' . "\n"; |
|
| 515 | - $html .= '<input type="checkbox" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . '][]" class="multicheck multicheck-' . esc_attr( $args['key'] ) . '" value="' . esc_attr( $k ) . '" id="checkbox-' . esc_attr( $k ) . '" ' . $checked . ' /> ' . $v . "\n"; |
|
| 516 | - $html .= '</label><br />' . "\n"; |
|
| 514 | + $html .= '<label for="checkbox-'.esc_attr($k).'">'."\n"; |
|
| 515 | + $html .= '<input type="checkbox" name="'.esc_attr($this->token).'['.esc_attr($args['key']).'][]" class="multicheck multicheck-'.esc_attr($args['key']).'" value="'.esc_attr($k).'" id="checkbox-'.esc_attr($k).'" '.$checked.' /> '.$v."\n"; |
|
| 516 | + $html .= '</label><br />'."\n"; |
|
| 517 | 517 | } |
| 518 | - $html .= '</div>' . "\n"; |
|
| 518 | + $html .= '</div>'."\n"; |
|
| 519 | 519 | echo $html; |
| 520 | 520 | |
| 521 | - if ( isset( $args['data']['description'] ) ) { |
|
| 522 | - echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n"; |
|
| 521 | + if (isset($args['data']['description'])) { |
|
| 522 | + echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n"; |
|
| 523 | 523 | } |
| 524 | 524 | } |
| 525 | 525 | } // End form_field_multicheck() |
@@ -531,20 +531,20 @@ discard block |
||
| 531 | 531 | * @param array $args |
| 532 | 532 | * @return void |
| 533 | 533 | */ |
| 534 | - public function form_field_range ( $args ) { |
|
| 534 | + public function form_field_range($args) { |
|
| 535 | 535 | $options = $this->get_settings(); |
| 536 | 536 | |
| 537 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 537 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 538 | 538 | $html = ''; |
| 539 | - $html .= '<select id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" class="range-input">' . "\n"; |
|
| 540 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 541 | - $html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $options[$args['key']] ), $k, false ) . '>' . $v . '</option>' . "\n"; |
|
| 539 | + $html .= '<select id="'.esc_attr($args['key']).'" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']" class="range-input">'."\n"; |
|
| 540 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 541 | + $html .= '<option value="'.esc_attr($k).'"'.selected(esc_attr($options[$args['key']]), $k, false).'>'.$v.'</option>'."\n"; |
|
| 542 | 542 | } |
| 543 | - $html .= '</select>' . "\n"; |
|
| 543 | + $html .= '</select>'."\n"; |
|
| 544 | 544 | echo $html; |
| 545 | 545 | |
| 546 | - if ( isset( $args['data']['description'] ) ) { |
|
| 547 | - echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n"; |
|
| 546 | + if (isset($args['data']['description'])) { |
|
| 547 | + echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n"; |
|
| 548 | 548 | } |
| 549 | 549 | } |
| 550 | 550 | } // End form_field_range() |
@@ -556,18 +556,18 @@ discard block |
||
| 556 | 556 | * @param array $args |
| 557 | 557 | * @return void |
| 558 | 558 | */ |
| 559 | - public function form_field_images ( $args ) { |
|
| 559 | + public function form_field_images($args) { |
|
| 560 | 560 | $options = $this->get_settings(); |
| 561 | 561 | |
| 562 | - if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) { |
|
| 562 | + if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) { |
|
| 563 | 563 | $html = ''; |
| 564 | - foreach ( $args['data']['options'] as $k => $v ) { |
|
| 565 | - $html .= '<input type="radio" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $options[$args['key']] ), $k, false ) . ' /> ' . $v . '<br />' . "\n"; |
|
| 564 | + foreach ($args['data']['options'] as $k => $v) { |
|
| 565 | + $html .= '<input type="radio" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']" value="'.esc_attr($k).'"'.checked(esc_attr($options[$args['key']]), $k, false).' /> '.$v.'<br />'."\n"; |
|
| 566 | 566 | } |
| 567 | 567 | echo $html; |
| 568 | 568 | |
| 569 | - if ( isset( $args['data']['description'] ) ) { |
|
| 570 | - echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n"; |
|
| 569 | + if (isset($args['data']['description'])) { |
|
| 570 | + echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n"; |
|
| 571 | 571 | } |
| 572 | 572 | } |
| 573 | 573 | } // End form_field_images() |
@@ -579,19 +579,19 @@ discard block |
||
| 579 | 579 | * @param array $args |
| 580 | 580 | * @return void |
| 581 | 581 | */ |
| 582 | - public function form_field_info ( $args ) { |
|
| 582 | + public function form_field_info($args) { |
|
| 583 | 583 | $class = ''; |
| 584 | - if ( isset( $args['data']['class'] ) ) { |
|
| 585 | - $class = ' ' . esc_attr( $args['data']['class'] ); |
|
| 584 | + if (isset($args['data']['class'])) { |
|
| 585 | + $class = ' '.esc_attr($args['data']['class']); |
|
| 586 | 586 | } |
| 587 | - $html = '<div id="' . $args['key'] . '" class="info-box' . $class . '">' . "\n"; |
|
| 588 | - if ( isset( $args['data']['name'] ) && ( $args['data']['name'] != '' ) ) { |
|
| 589 | - $html .= '<h3 class="title">' . esc_html( $args['data']['name'] ) . '</h3>' . "\n"; |
|
| 587 | + $html = '<div id="'.$args['key'].'" class="info-box'.$class.'">'."\n"; |
|
| 588 | + if (isset($args['data']['name']) && ($args['data']['name'] != '')) { |
|
| 589 | + $html .= '<h3 class="title">'.esc_html($args['data']['name']).'</h3>'."\n"; |
|
| 590 | 590 | } |
| 591 | - if ( isset( $args['data']['description'] ) && ( $args['data']['description'] != '' ) ) { |
|
| 592 | - $html .= '<p>' . esc_html( $args['data']['description'] ) . '</p>' . "\n"; |
|
| 591 | + if (isset($args['data']['description']) && ($args['data']['description'] != '')) { |
|
| 592 | + $html .= '<p>'.esc_html($args['data']['description']).'</p>'."\n"; |
|
| 593 | 593 | } |
| 594 | - $html .= '</div>' . "\n"; |
|
| 594 | + $html .= '</div>'."\n"; |
|
| 595 | 595 | |
| 596 | 596 | echo $html; |
| 597 | 597 | } // End form_field_info() |
@@ -603,14 +603,14 @@ discard block |
||
| 603 | 603 | * @since 1.9.0 |
| 604 | 604 | * @param array $args |
| 605 | 605 | */ |
| 606 | - public function form_field_button( $args ) { |
|
| 606 | + public function form_field_button($args) { |
|
| 607 | 607 | $options = $this->get_settings(); |
| 608 | 608 | |
| 609 | - if ( isset( $args['data']['target'] ) && isset( $args['data']['label'] ) ) { |
|
| 610 | - printf( '<a href="%s" class="button button-secondary">%s</a> ', esc_url( $args['data']['target'] ), esc_html( $args['data']['label'] ) ); |
|
| 609 | + if (isset($args['data']['target']) && isset($args['data']['label'])) { |
|
| 610 | + printf('<a href="%s" class="button button-secondary">%s</a> ', esc_url($args['data']['target']), esc_html($args['data']['label'])); |
|
| 611 | 611 | |
| 612 | - if ( isset( $args['data']['description'] ) ) { |
|
| 613 | - echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n"; |
|
| 612 | + if (isset($args['data']['description'])) { |
|
| 613 | + echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n"; |
|
| 614 | 614 | } |
| 615 | 615 | } |
| 616 | 616 | } // End form_field_button() |
@@ -624,23 +624,23 @@ discard block |
||
| 624 | 624 | * @uses $this->parse_errors() |
| 625 | 625 | * @return array $options |
| 626 | 626 | */ |
| 627 | - public function validate_fields ( $input ) { |
|
| 627 | + public function validate_fields($input) { |
|
| 628 | 628 | $options = $this->get_settings(); |
| 629 | 629 | |
| 630 | - foreach ( $this->fields as $k => $v ) { |
|
| 630 | + foreach ($this->fields as $k => $v) { |
|
| 631 | 631 | // Make sure checkboxes are present even when false. |
| 632 | - if ( $v['type'] == 'checkbox' && ! isset( $input[$k] ) ) { $input[$k] = false; } |
|
| 633 | - if ( $v['type'] == 'multicheck' && ! isset( $input[$k] ) ) { $input[$k] = false; } |
|
| 632 | + if ($v['type'] == 'checkbox' && ! isset($input[$k])) { $input[$k] = false; } |
|
| 633 | + if ($v['type'] == 'multicheck' && ! isset($input[$k])) { $input[$k] = false; } |
|
| 634 | 634 | |
| 635 | - if ( isset( $input[$k] ) ) { |
|
| 635 | + if (isset($input[$k])) { |
|
| 636 | 636 | // Perform checks on required fields. |
| 637 | - if ( isset( $v['required'] ) && ( $v['required'] == true ) ) { |
|
| 638 | - if ( in_array( $v['type'], $this->get_array_field_types() ) && ( count( (array) $input[$k] ) <= 0 ) ) { |
|
| 639 | - $this->add_error( $k, $v ); |
|
| 637 | + if (isset($v['required']) && ($v['required'] == true)) { |
|
| 638 | + if (in_array($v['type'], $this->get_array_field_types()) && (count((array) $input[$k]) <= 0)) { |
|
| 639 | + $this->add_error($k, $v); |
|
| 640 | 640 | continue; |
| 641 | 641 | } else { |
| 642 | - if ( $input[$k] == '' ) { |
|
| 643 | - $this->add_error( $k, $v ); |
|
| 642 | + if ($input[$k] == '') { |
|
| 643 | + $this->add_error($k, $v); |
|
| 644 | 644 | continue; |
| 645 | 645 | } |
| 646 | 646 | } |
@@ -649,28 +649,28 @@ discard block |
||
| 649 | 649 | $value = $input[$k]; |
| 650 | 650 | |
| 651 | 651 | // Check if the field is valid. |
| 652 | - $method = $this->determine_method( $v, 'check' ); |
|
| 652 | + $method = $this->determine_method($v, 'check'); |
|
| 653 | 653 | |
| 654 | - if ( function_exists ( $method ) ) { |
|
| 655 | - $is_valid = $method( $value ); |
|
| 654 | + if (function_exists($method)) { |
|
| 655 | + $is_valid = $method($value); |
|
| 656 | 656 | } else { |
| 657 | - if ( method_exists( $this, $method ) ) { |
|
| 658 | - $is_valid = $this->$method( $value ); |
|
| 657 | + if (method_exists($this, $method)) { |
|
| 658 | + $is_valid = $this->$method($value); |
|
| 659 | 659 | } |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - if ( ! $is_valid ) { |
|
| 663 | - $this->add_error( $k, $v ); |
|
| 662 | + if ( ! $is_valid) { |
|
| 663 | + $this->add_error($k, $v); |
|
| 664 | 664 | continue; |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | - $method = $this->determine_method( $v, 'validate' ); |
|
| 667 | + $method = $this->determine_method($v, 'validate'); |
|
| 668 | 668 | |
| 669 | - if ( function_exists ( $method ) ) { |
|
| 670 | - $options[$k] = $method( $value ); |
|
| 669 | + if (function_exists($method)) { |
|
| 670 | + $options[$k] = $method($value); |
|
| 671 | 671 | } else { |
| 672 | - if ( method_exists( $this, $method ) ) { |
|
| 673 | - $options[$k] = $this->$method( $value ); |
|
| 672 | + if (method_exists($this, $method)) { |
|
| 673 | + $options[$k] = $this->$method($value); |
|
| 674 | 674 | } |
| 675 | 675 | } |
| 676 | 676 | } |
@@ -688,8 +688,8 @@ discard block |
||
| 688 | 688 | * @param string $input |
| 689 | 689 | * @return string |
| 690 | 690 | */ |
| 691 | - public function validate_field_text ( $input ) { |
|
| 692 | - return trim( esc_attr( $input ) ); |
|
| 691 | + public function validate_field_text($input) { |
|
| 692 | + return trim(esc_attr($input)); |
|
| 693 | 693 | } // End validate_field_text() |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -699,11 +699,11 @@ discard block |
||
| 699 | 699 | * @param string $input |
| 700 | 700 | * @return string |
| 701 | 701 | */ |
| 702 | - public function validate_field_checkbox ( $input ) { |
|
| 703 | - if ( ! isset( $input ) ) { |
|
| 702 | + public function validate_field_checkbox($input) { |
|
| 703 | + if ( ! isset($input)) { |
|
| 704 | 704 | return 0; |
| 705 | 705 | } else { |
| 706 | - return (bool)$input; |
|
| 706 | + return (bool) $input; |
|
| 707 | 707 | } |
| 708 | 708 | } // End validate_field_checkbox() |
| 709 | 709 | |
@@ -714,10 +714,10 @@ discard block |
||
| 714 | 714 | * @param string $input |
| 715 | 715 | * @return string |
| 716 | 716 | */ |
| 717 | - public function validate_field_multicheck ( $input ) { |
|
| 717 | + public function validate_field_multicheck($input) { |
|
| 718 | 718 | $input = (array) $input; |
| 719 | 719 | |
| 720 | - $input = array_map( 'esc_attr', $input ); |
|
| 720 | + $input = array_map('esc_attr', $input); |
|
| 721 | 721 | |
| 722 | 722 | return $input; |
| 723 | 723 | } // End validate_field_multicheck() |
@@ -729,8 +729,8 @@ discard block |
||
| 729 | 729 | * @param string $input |
| 730 | 730 | * @return string |
| 731 | 731 | */ |
| 732 | - public function validate_field_range ( $input ) { |
|
| 733 | - $input = number_format( floatval( $input ), 0 ); |
|
| 732 | + public function validate_field_range($input) { |
|
| 733 | + $input = number_format(floatval($input), 0); |
|
| 734 | 734 | |
| 735 | 735 | return $input; |
| 736 | 736 | } // End validate_field_range() |
@@ -742,8 +742,8 @@ discard block |
||
| 742 | 742 | * @param string $input |
| 743 | 743 | * @return string |
| 744 | 744 | */ |
| 745 | - public function validate_field_url ( $input ) { |
|
| 746 | - return trim( esc_url( $input ) ); |
|
| 745 | + public function validate_field_url($input) { |
|
| 746 | + return trim(esc_url($input)); |
|
| 747 | 747 | } // End validate_field_url() |
| 748 | 748 | |
| 749 | 749 | /** |
@@ -752,7 +752,7 @@ discard block |
||
| 752 | 752 | * @since 1.1.0 |
| 753 | 753 | * @return boolean Is the value valid? |
| 754 | 754 | */ |
| 755 | - public function check_field_text ( $input ) { |
|
| 755 | + public function check_field_text($input) { |
|
| 756 | 756 | $is_valid = true; |
| 757 | 757 | |
| 758 | 758 | return $is_valid; |
@@ -766,11 +766,11 @@ discard block |
||
| 766 | 766 | * @param array $data |
| 767 | 767 | * @return void |
| 768 | 768 | */ |
| 769 | - protected function add_error ( $key, $data ) { |
|
| 770 | - if ( isset( $data['error_message'] ) ) { |
|
| 769 | + protected function add_error($key, $data) { |
|
| 770 | + if (isset($data['error_message'])) { |
|
| 771 | 771 | $message = $data['error_message']; |
| 772 | 772 | } else { |
| 773 | - $message = sprintf( __( '%s is a required field', 'woothemes-sensei' ), $data['name'] ); |
|
| 773 | + $message = sprintf(__('%s is a required field', 'woothemes-sensei'), $data['name']); |
|
| 774 | 774 | } |
| 775 | 775 | $this->errors[$key] = $message; |
| 776 | 776 | } // End add_error() |
@@ -781,14 +781,14 @@ discard block |
||
| 781 | 781 | * @since 1.0.0 |
| 782 | 782 | * @return void |
| 783 | 783 | */ |
| 784 | - protected function parse_errors () { |
|
| 785 | - if ( count ( $this->errors ) > 0 ) { |
|
| 786 | - foreach ( $this->errors as $k => $v ) { |
|
| 787 | - add_settings_error( $this->token . '-errors', $k, $v, 'error' ); |
|
| 784 | + protected function parse_errors() { |
|
| 785 | + if (count($this->errors) > 0) { |
|
| 786 | + foreach ($this->errors as $k => $v) { |
|
| 787 | + add_settings_error($this->token.'-errors', $k, $v, 'error'); |
|
| 788 | 788 | } |
| 789 | 789 | } else { |
| 790 | - $message = sprintf( __( '%s updated', 'woothemes-sensei' ), $this->name ); |
|
| 791 | - add_settings_error( $this->token . '-errors', $this->token, $message, 'updated' ); |
|
| 790 | + $message = sprintf(__('%s updated', 'woothemes-sensei'), $this->name); |
|
| 791 | + add_settings_error($this->token.'-errors', $this->token, $message, 'updated'); |
|
| 792 | 792 | } |
| 793 | 793 | } // End parse_errors() |
| 794 | 794 | |
@@ -798,8 +798,8 @@ discard block |
||
| 798 | 798 | * @since 1.0.0 |
| 799 | 799 | * @return void |
| 800 | 800 | */ |
| 801 | - protected function get_array_field_types () { |
|
| 802 | - return array( 'multicheck' ); |
|
| 801 | + protected function get_array_field_types() { |
|
| 802 | + return array('multicheck'); |
|
| 803 | 803 | } // End get_array_field_types() |
| 804 | 804 | |
| 805 | 805 | /** |
@@ -808,22 +808,22 @@ discard block |
||
| 808 | 808 | * @since 1.0.0 |
| 809 | 809 | * @return void |
| 810 | 810 | */ |
| 811 | - public function enqueue_scripts () { |
|
| 811 | + public function enqueue_scripts() { |
|
| 812 | 812 | |
| 813 | 813 | |
| 814 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 814 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 815 | 815 | |
| 816 | - wp_enqueue_script( 'farbtastic' ); |
|
| 817 | - wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'farbtastic' ), Sensei()->version ); |
|
| 816 | + wp_enqueue_script('farbtastic'); |
|
| 817 | + wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'farbtastic'), Sensei()->version); |
|
| 818 | 818 | |
| 819 | - if ( $this->has_range ) { |
|
| 820 | - wp_enqueue_script( 'woothemes-sensei-settings-ranges', esc_url( Sensei()->plugin_url . 'assets/js/ranges' . $suffix . '.js' ), array( 'jquery-ui-slider' ), Sensei()->version ); |
|
| 819 | + if ($this->has_range) { |
|
| 820 | + wp_enqueue_script('woothemes-sensei-settings-ranges', esc_url(Sensei()->plugin_url.'assets/js/ranges'.$suffix.'.js'), array('jquery-ui-slider'), Sensei()->version); |
|
| 821 | 821 | } |
| 822 | 822 | |
| 823 | - wp_register_script( 'woothemes-sensei-settings-imageselectors', esc_url( Sensei()->plugin_url . 'assets/js/image-selectors' . $suffix . '.js' ), array( 'jquery' ), Sensei()->version ); |
|
| 823 | + wp_register_script('woothemes-sensei-settings-imageselectors', esc_url(Sensei()->plugin_url.'assets/js/image-selectors'.$suffix.'.js'), array('jquery'), Sensei()->version); |
|
| 824 | 824 | |
| 825 | - if ( $this->has_imageselector ) { |
|
| 826 | - wp_enqueue_script( 'woothemes-sensei-settings-imageselectors' ); |
|
| 825 | + if ($this->has_imageselector) { |
|
| 826 | + wp_enqueue_script('woothemes-sensei-settings-imageselectors'); |
|
| 827 | 827 | } |
| 828 | 828 | |
| 829 | 829 | } // End enqueue_scripts() |
@@ -834,12 +834,12 @@ discard block |
||
| 834 | 834 | * @since 1.0.0 |
| 835 | 835 | * @return void |
| 836 | 836 | */ |
| 837 | - public function enqueue_styles () { |
|
| 837 | + public function enqueue_styles() { |
|
| 838 | 838 | |
| 839 | - wp_enqueue_style( $this->token . '-admin' ); |
|
| 839 | + wp_enqueue_style($this->token.'-admin'); |
|
| 840 | 840 | |
| 841 | - wp_enqueue_style( 'farbtastic' ); |
|
| 842 | - wp_enqueue_style( 'woothemes-sensei-settings-api', esc_url( Sensei()->plugin_url . 'assets/css/settings.css' ), array( 'farbtastic' ), Sensei()->version ); |
|
| 841 | + wp_enqueue_style('farbtastic'); |
|
| 842 | + wp_enqueue_style('woothemes-sensei-settings-api', esc_url(Sensei()->plugin_url.'assets/css/settings.css'), array('farbtastic'), Sensei()->version); |
|
| 843 | 843 | |
| 844 | 844 | $this->enqueue_field_styles(); |
| 845 | 845 | } // End enqueue_styles() |
@@ -850,17 +850,17 @@ discard block |
||
| 850 | 850 | * @since 1.0.0 |
| 851 | 851 | * @return void |
| 852 | 852 | */ |
| 853 | - public function enqueue_field_styles () { |
|
| 853 | + public function enqueue_field_styles() { |
|
| 854 | 854 | |
| 855 | 855 | |
| 856 | - if ( $this->has_range ) { |
|
| 857 | - wp_enqueue_style( 'woothemes-sensei-settings-ranges', esc_url( Sensei()->plugin_url . 'assets/css/ranges.css' ), '', Sensei()->version ); |
|
| 856 | + if ($this->has_range) { |
|
| 857 | + wp_enqueue_style('woothemes-sensei-settings-ranges', esc_url(Sensei()->plugin_url.'assets/css/ranges.css'), '', Sensei()->version); |
|
| 858 | 858 | } |
| 859 | 859 | |
| 860 | - wp_register_style( 'woothemes-sensei-settings-imageselectors', esc_url( Sensei()->plugin_url . 'assets/css/image-selectors.css' ), '', Sensei()->version ); |
|
| 860 | + wp_register_style('woothemes-sensei-settings-imageselectors', esc_url(Sensei()->plugin_url.'assets/css/image-selectors.css'), '', Sensei()->version); |
|
| 861 | 861 | |
| 862 | - if ( $this->has_imageselector ) { |
|
| 863 | - wp_enqueue_style( 'woothemes-sensei-settings-imageselectors' ); |
|
| 862 | + if ($this->has_imageselector) { |
|
| 863 | + wp_enqueue_style('woothemes-sensei-settings-imageselectors'); |
|
| 864 | 864 | } |
| 865 | 865 | } // End enqueue_field_styles() |
| 866 | 866 | } // End Class |
@@ -870,4 +870,4 @@ discard block |
||
| 870 | 870 | * for backward compatibility |
| 871 | 871 | * @since 1.9.0 |
| 872 | 872 | */ |
| 873 | -class WooThemes_Sensei_Settings_API extends Sensei_Settings_API{} |
|
| 873 | +class WooThemes_Sensei_Settings_API extends Sensei_Settings_API {} |
|
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | * |
| 364 | 364 | * @param $course_id |
| 365 | 365 | * @param $new_teacher_id |
| 366 | - * @return void |
|
| 366 | + * @return false|null |
|
| 367 | 367 | */ |
| 368 | 368 | public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
| 369 | 369 | |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | * @since 1.8.0 |
| 455 | 455 | * @access public |
| 456 | 456 | * @parameters |
| 457 | - * @return array $users user id array |
|
| 457 | + * @return boolean $users user id array |
|
| 458 | 458 | */ |
| 459 | 459 | public function update_course_lessons_author ( $course_id, $new_author ){ |
| 460 | 460 | |
@@ -843,8 +843,7 @@ discard block |
||
| 843 | 843 | * This function hooks into wp_insert_post |
| 844 | 844 | * |
| 845 | 845 | * @since 1.8.0 |
| 846 | - * @param int $course_id |
|
| 847 | - * @return bool |
|
| 846 | + * @return false|null |
|
| 848 | 847 | */ |
| 849 | 848 | public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
| 850 | 849 | |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Teacher class |
@@ -414,7 +417,7 @@ discard block |
||
| 414 | 417 | $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
| 415 | 418 | $term_id = $existing_term->term_id; |
| 416 | 419 | |
| 417 | - }else{ |
|
| 420 | + } else{ |
|
| 418 | 421 | |
| 419 | 422 | // for a new term simply get the term from the returned value |
| 420 | 423 | $term_id = $new_term['term_id']; |
@@ -495,7 +498,7 @@ discard block |
||
| 495 | 498 | 'post_author' => $new_author |
| 496 | 499 | ) ); |
| 497 | 500 | } |
| 498 | - }else{ |
|
| 501 | + } else{ |
|
| 499 | 502 | wp_update_post( array( |
| 500 | 503 | 'ID' => $lesson_quizzes, |
| 501 | 504 | 'post_author' => $new_author |
@@ -789,7 +792,7 @@ discard block |
||
| 789 | 792 | // merge the post types instead of overwriting it |
| 790 | 793 | $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
| 791 | 794 | |
| 792 | - }else{ |
|
| 795 | + } else{ |
|
| 793 | 796 | |
| 794 | 797 | // in this instance it is probably just one post type in string format |
| 795 | 798 | $new_post_types = array( $current_post_types , 'course'); |
@@ -979,7 +982,7 @@ discard block |
||
| 979 | 982 | $course_learner_ids[] = $user->ID; |
| 980 | 983 | } |
| 981 | 984 | |
| 982 | - }else{ |
|
| 985 | + } else{ |
|
| 983 | 986 | |
| 984 | 987 | $user = get_userdata( $activity_comments->user_id ); |
| 985 | 988 | $course_learner_ids[] = $user->ID; |
@@ -996,7 +999,7 @@ discard block |
||
| 996 | 999 | |
| 997 | 1000 | $args[ 'include'] = array( 0 ); |
| 998 | 1001 | |
| 999 | - }else{ |
|
| 1002 | + } else{ |
|
| 1000 | 1003 | |
| 1001 | 1004 | $args[ 'include'] = $learner_ids_for_teacher_courses; |
| 1002 | 1005 | |
@@ -1164,7 +1167,7 @@ discard block |
||
| 1164 | 1167 | |
| 1165 | 1168 | $teachers_courses[] = $course->ID; |
| 1166 | 1169 | |
| 1167 | - }else{ |
|
| 1170 | + } else{ |
|
| 1168 | 1171 | |
| 1169 | 1172 | $teachers_courses[] = $course; |
| 1170 | 1173 | |
@@ -1534,7 +1537,7 @@ discard block |
||
| 1534 | 1537 | |
| 1535 | 1538 | return true; |
| 1536 | 1539 | |
| 1537 | - }else{ |
|
| 1540 | + } else{ |
|
| 1538 | 1541 | |
| 1539 | 1542 | return false; |
| 1540 | 1543 | |
@@ -14,251 +14,251 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Teacher { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * $teacher_role |
|
| 19 | - * |
|
| 20 | - * Keeps a reference to the teacher role object |
|
| 21 | - * |
|
| 22 | - * @access protected |
|
| 23 | - * @since 1.8.0 |
|
| 24 | - */ |
|
| 25 | - protected $teacher_role; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * $token |
|
| 29 | - * |
|
| 30 | - * Keeps a reference to the global sensei token |
|
| 31 | - * |
|
| 32 | - * @access protected |
|
| 33 | - * @since 1.8.0 |
|
| 34 | - */ |
|
| 35 | - public $token; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Sensei_Teacher::__constructor |
|
| 39 | - * |
|
| 40 | - * Constructor Function |
|
| 41 | - * |
|
| 42 | - * @since 1.8.0 |
|
| 43 | - * @access public |
|
| 44 | - */ |
|
| 45 | - public function __construct ( ) { |
|
| 46 | - |
|
| 47 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
| 48 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 49 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
| 50 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
| 51 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
| 52 | - |
|
| 53 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 54 | - |
|
| 55 | - //filter the quiz submissions |
|
| 56 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 57 | - |
|
| 58 | - //grading totals count only those belonging to the teacher |
|
| 59 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 60 | - |
|
| 61 | - // show the courses owned by a user on his author archive page |
|
| 62 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
| 63 | - |
|
| 64 | - // notify admin when a teacher creates a course |
|
| 65 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 66 | - |
|
| 67 | - // limit the analysis view to only the users taking courses belong to this teacher |
|
| 68 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
| 69 | - |
|
| 70 | - // give teacher access to question post type |
|
| 71 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 72 | - |
|
| 73 | - // Teacher column on the courses list on the admin edit screen |
|
| 74 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
| 75 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
| 76 | - |
|
| 77 | - //admin edit messages query limit teacher |
|
| 78 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 79 | - |
|
| 80 | - //add filter by teacher on courses list |
|
| 81 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
| 82 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
| 83 | - |
|
| 84 | - // Handle media library restrictions |
|
| 85 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
| 86 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
| 87 | - |
|
| 88 | - // update lesson owner to course teacher when saved |
|
| 89 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 90 | - |
|
| 91 | - // If a Teacher logs in, redirect to /wp-admin/ |
|
| 92 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
| 96 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - } // end __constructor() |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Sensei_Teacher::create_teacher_role |
|
| 103 | - * |
|
| 104 | - * This function checks if the role exist, if not it creates it. |
|
| 105 | - * for the teacher role |
|
| 106 | - * |
|
| 107 | - * @since 1.8.0 |
|
| 108 | - * @access public |
|
| 109 | - * @return void |
|
| 110 | - */ |
|
| 111 | - public function create_role ( ) { |
|
| 112 | - |
|
| 113 | - // check if the role exists |
|
| 114 | - $this->teacher_role = get_role( 'teacher' ); |
|
| 115 | - |
|
| 116 | - // if the the teacher is not a valid WordPress role create it |
|
| 117 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 118 | - // create the role |
|
| 119 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // add the capabilities before returning |
|
| 123 | - $this->add_capabilities(); |
|
| 124 | - |
|
| 125 | - }// end create_teacher_role |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Sensei_Teacher::add_capabilities |
|
| 129 | - * |
|
| 130 | - * @since 1.8.0 |
|
| 131 | - * @access protected |
|
| 132 | - */ |
|
| 133 | - protected function add_capabilities ( ) { |
|
| 134 | - |
|
| 135 | - // if this is not a valid WP_Role object exit without adding anything |
|
| 136 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
| 137 | - return; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Sensei teachers capabilities array filter |
|
| 142 | - * |
|
| 143 | - * These capabilities will be applied to the teacher role |
|
| 144 | - * @param array $capabilities |
|
| 145 | - * keys: (string) $cap_name => (bool) $grant |
|
| 146 | - */ |
|
| 147 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 148 | - // General access rules |
|
| 149 | - 'read' => true, |
|
| 150 | - 'manage_sensei_grades' => true, |
|
| 151 | - 'moderate_comments'=> true, |
|
| 152 | - 'upload_files' => true, |
|
| 153 | - 'edit_files' => true, |
|
| 154 | - |
|
| 155 | - //Lessons |
|
| 156 | - 'publish_lessons' => true, |
|
| 157 | - 'manage_lesson_categories' => true, |
|
| 158 | - 'edit_lessons' => true, |
|
| 159 | - 'edit_published_lessons' => true, |
|
| 160 | - 'edit_private_lessons' => true, |
|
| 161 | - 'read_private_lessons' => true, |
|
| 162 | - 'delete_published_lessons' => true, |
|
| 163 | - |
|
| 164 | - // Courses |
|
| 165 | - 'create_courses' => true, |
|
| 166 | - 'publish_courses' => false, |
|
| 167 | - 'manage_course_categories' => true, |
|
| 168 | - 'edit_courses' => true, |
|
| 169 | - 'edit_published_courses' => true, |
|
| 170 | - 'edit_private_courses' => true, |
|
| 171 | - 'read_private_courses' => true, |
|
| 172 | - 'delete_published_courses' => true, |
|
| 173 | - |
|
| 174 | - // Quiz |
|
| 175 | - 'publish_quizzes' => true, |
|
| 176 | - 'edit_quizzes' => true, |
|
| 177 | - 'edit_published_quizzes' => true, |
|
| 178 | - 'edit_private_quizzes' => true, |
|
| 179 | - 'read_private_quizzes' => true, |
|
| 180 | - |
|
| 181 | - // Questions |
|
| 182 | - 'publish_questions' => true, |
|
| 183 | - 'edit_questions' => true, |
|
| 184 | - 'edit_published_questions' => true, |
|
| 185 | - 'edit_private_questions' => true, |
|
| 186 | - 'read_private_questions' => true, |
|
| 187 | - |
|
| 188 | - //messages |
|
| 189 | - 'publish_sensei_messages' => true, |
|
| 190 | - 'edit_sensei_messages' => true, |
|
| 191 | - 'edit_published_sensei_messages' => true, |
|
| 192 | - 'edit_private_sensei_messages' => true, |
|
| 193 | - 'read_private_sensei_messages' => true, |
|
| 194 | - |
|
| 195 | - // Comments - |
|
| 196 | - // Necessary cap so Teachers can moderate comments |
|
| 197 | - // on their own lessons. We restrict access to other |
|
| 198 | - // post types in $this->restrict_posts_menu_page() |
|
| 199 | - |
|
| 200 | - 'edit_posts' => true, |
|
| 201 | - |
|
| 202 | - )); |
|
| 203 | - |
|
| 204 | - foreach ( $caps as $cap => $grant ) { |
|
| 205 | - |
|
| 206 | - // load the capability on to the teacher role |
|
| 207 | - $this->teacher_role->add_cap($cap, $grant); |
|
| 208 | - |
|
| 209 | - } // end for each |
|
| 210 | - |
|
| 211 | - }// end add_cap |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Sensei_Teacher::teacher_meta_box |
|
| 215 | - * |
|
| 216 | - * Add the teacher metabox to the course post type edit screen |
|
| 217 | - * |
|
| 218 | - * @since 1.8.0 |
|
| 219 | - * @access public |
|
| 220 | - * @parameter string $post_type |
|
| 221 | - * @parameter WP_Post $post |
|
| 222 | - * @return void |
|
| 223 | - */ |
|
| 224 | - public function add_teacher_meta_boxes ( $post ) { |
|
| 225 | - |
|
| 226 | - if( !current_user_can('manage_options') ){ |
|
| 227 | - return; |
|
| 228 | - } |
|
| 229 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
| 230 | - 'course', |
|
| 231 | - 'side', |
|
| 232 | - 'core' |
|
| 233 | - ); |
|
| 234 | - |
|
| 235 | - } // end teacher_meta_box() |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Sensei_Teacher::teacher_meta_box_content |
|
| 239 | - * |
|
| 240 | - * Render the teacher meta box markup |
|
| 241 | - * |
|
| 242 | - * @since 1.8.0 |
|
| 243 | - * @access public |
|
| 244 | - * @parameters |
|
| 245 | - */ |
|
| 246 | - public function teacher_meta_box_content ( $post ) { |
|
| 247 | - |
|
| 248 | - // get the current author |
|
| 249 | - $current_author = $post->post_author; |
|
| 250 | - |
|
| 251 | - //get the users authorised to author courses |
|
| 252 | - $users = $this->get_teachers_and_authors(); |
|
| 253 | - |
|
| 254 | - ?> |
|
| 17 | + /** |
|
| 18 | + * $teacher_role |
|
| 19 | + * |
|
| 20 | + * Keeps a reference to the teacher role object |
|
| 21 | + * |
|
| 22 | + * @access protected |
|
| 23 | + * @since 1.8.0 |
|
| 24 | + */ |
|
| 25 | + protected $teacher_role; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * $token |
|
| 29 | + * |
|
| 30 | + * Keeps a reference to the global sensei token |
|
| 31 | + * |
|
| 32 | + * @access protected |
|
| 33 | + * @since 1.8.0 |
|
| 34 | + */ |
|
| 35 | + public $token; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Sensei_Teacher::__constructor |
|
| 39 | + * |
|
| 40 | + * Constructor Function |
|
| 41 | + * |
|
| 42 | + * @since 1.8.0 |
|
| 43 | + * @access public |
|
| 44 | + */ |
|
| 45 | + public function __construct ( ) { |
|
| 46 | + |
|
| 47 | + add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
| 48 | + add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 49 | + add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
| 50 | + add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
| 51 | + add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
| 52 | + |
|
| 53 | + add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 54 | + |
|
| 55 | + //filter the quiz submissions |
|
| 56 | + add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 57 | + |
|
| 58 | + //grading totals count only those belonging to the teacher |
|
| 59 | + add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 60 | + |
|
| 61 | + // show the courses owned by a user on his author archive page |
|
| 62 | + add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
| 63 | + |
|
| 64 | + // notify admin when a teacher creates a course |
|
| 65 | + add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 66 | + |
|
| 67 | + // limit the analysis view to only the users taking courses belong to this teacher |
|
| 68 | + add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
| 69 | + |
|
| 70 | + // give teacher access to question post type |
|
| 71 | + add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 72 | + |
|
| 73 | + // Teacher column on the courses list on the admin edit screen |
|
| 74 | + add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
| 75 | + add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
| 76 | + |
|
| 77 | + //admin edit messages query limit teacher |
|
| 78 | + add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 79 | + |
|
| 80 | + //add filter by teacher on courses list |
|
| 81 | + add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
| 82 | + add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
| 83 | + |
|
| 84 | + // Handle media library restrictions |
|
| 85 | + add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
| 86 | + add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
| 87 | + |
|
| 88 | + // update lesson owner to course teacher when saved |
|
| 89 | + add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 90 | + |
|
| 91 | + // If a Teacher logs in, redirect to /wp-admin/ |
|
| 92 | + add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
| 96 | + add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + } // end __constructor() |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Sensei_Teacher::create_teacher_role |
|
| 103 | + * |
|
| 104 | + * This function checks if the role exist, if not it creates it. |
|
| 105 | + * for the teacher role |
|
| 106 | + * |
|
| 107 | + * @since 1.8.0 |
|
| 108 | + * @access public |
|
| 109 | + * @return void |
|
| 110 | + */ |
|
| 111 | + public function create_role ( ) { |
|
| 112 | + |
|
| 113 | + // check if the role exists |
|
| 114 | + $this->teacher_role = get_role( 'teacher' ); |
|
| 115 | + |
|
| 116 | + // if the the teacher is not a valid WordPress role create it |
|
| 117 | + if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 118 | + // create the role |
|
| 119 | + $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // add the capabilities before returning |
|
| 123 | + $this->add_capabilities(); |
|
| 124 | + |
|
| 125 | + }// end create_teacher_role |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Sensei_Teacher::add_capabilities |
|
| 129 | + * |
|
| 130 | + * @since 1.8.0 |
|
| 131 | + * @access protected |
|
| 132 | + */ |
|
| 133 | + protected function add_capabilities ( ) { |
|
| 134 | + |
|
| 135 | + // if this is not a valid WP_Role object exit without adding anything |
|
| 136 | + if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
| 137 | + return; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Sensei teachers capabilities array filter |
|
| 142 | + * |
|
| 143 | + * These capabilities will be applied to the teacher role |
|
| 144 | + * @param array $capabilities |
|
| 145 | + * keys: (string) $cap_name => (bool) $grant |
|
| 146 | + */ |
|
| 147 | + $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 148 | + // General access rules |
|
| 149 | + 'read' => true, |
|
| 150 | + 'manage_sensei_grades' => true, |
|
| 151 | + 'moderate_comments'=> true, |
|
| 152 | + 'upload_files' => true, |
|
| 153 | + 'edit_files' => true, |
|
| 154 | + |
|
| 155 | + //Lessons |
|
| 156 | + 'publish_lessons' => true, |
|
| 157 | + 'manage_lesson_categories' => true, |
|
| 158 | + 'edit_lessons' => true, |
|
| 159 | + 'edit_published_lessons' => true, |
|
| 160 | + 'edit_private_lessons' => true, |
|
| 161 | + 'read_private_lessons' => true, |
|
| 162 | + 'delete_published_lessons' => true, |
|
| 163 | + |
|
| 164 | + // Courses |
|
| 165 | + 'create_courses' => true, |
|
| 166 | + 'publish_courses' => false, |
|
| 167 | + 'manage_course_categories' => true, |
|
| 168 | + 'edit_courses' => true, |
|
| 169 | + 'edit_published_courses' => true, |
|
| 170 | + 'edit_private_courses' => true, |
|
| 171 | + 'read_private_courses' => true, |
|
| 172 | + 'delete_published_courses' => true, |
|
| 173 | + |
|
| 174 | + // Quiz |
|
| 175 | + 'publish_quizzes' => true, |
|
| 176 | + 'edit_quizzes' => true, |
|
| 177 | + 'edit_published_quizzes' => true, |
|
| 178 | + 'edit_private_quizzes' => true, |
|
| 179 | + 'read_private_quizzes' => true, |
|
| 180 | + |
|
| 181 | + // Questions |
|
| 182 | + 'publish_questions' => true, |
|
| 183 | + 'edit_questions' => true, |
|
| 184 | + 'edit_published_questions' => true, |
|
| 185 | + 'edit_private_questions' => true, |
|
| 186 | + 'read_private_questions' => true, |
|
| 187 | + |
|
| 188 | + //messages |
|
| 189 | + 'publish_sensei_messages' => true, |
|
| 190 | + 'edit_sensei_messages' => true, |
|
| 191 | + 'edit_published_sensei_messages' => true, |
|
| 192 | + 'edit_private_sensei_messages' => true, |
|
| 193 | + 'read_private_sensei_messages' => true, |
|
| 194 | + |
|
| 195 | + // Comments - |
|
| 196 | + // Necessary cap so Teachers can moderate comments |
|
| 197 | + // on their own lessons. We restrict access to other |
|
| 198 | + // post types in $this->restrict_posts_menu_page() |
|
| 199 | + |
|
| 200 | + 'edit_posts' => true, |
|
| 201 | + |
|
| 202 | + )); |
|
| 203 | + |
|
| 204 | + foreach ( $caps as $cap => $grant ) { |
|
| 205 | + |
|
| 206 | + // load the capability on to the teacher role |
|
| 207 | + $this->teacher_role->add_cap($cap, $grant); |
|
| 208 | + |
|
| 209 | + } // end for each |
|
| 210 | + |
|
| 211 | + }// end add_cap |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Sensei_Teacher::teacher_meta_box |
|
| 215 | + * |
|
| 216 | + * Add the teacher metabox to the course post type edit screen |
|
| 217 | + * |
|
| 218 | + * @since 1.8.0 |
|
| 219 | + * @access public |
|
| 220 | + * @parameter string $post_type |
|
| 221 | + * @parameter WP_Post $post |
|
| 222 | + * @return void |
|
| 223 | + */ |
|
| 224 | + public function add_teacher_meta_boxes ( $post ) { |
|
| 225 | + |
|
| 226 | + if( !current_user_can('manage_options') ){ |
|
| 227 | + return; |
|
| 228 | + } |
|
| 229 | + add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
| 230 | + 'course', |
|
| 231 | + 'side', |
|
| 232 | + 'core' |
|
| 233 | + ); |
|
| 234 | + |
|
| 235 | + } // end teacher_meta_box() |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Sensei_Teacher::teacher_meta_box_content |
|
| 239 | + * |
|
| 240 | + * Render the teacher meta box markup |
|
| 241 | + * |
|
| 242 | + * @since 1.8.0 |
|
| 243 | + * @access public |
|
| 244 | + * @parameters |
|
| 245 | + */ |
|
| 246 | + public function teacher_meta_box_content ( $post ) { |
|
| 247 | + |
|
| 248 | + // get the current author |
|
| 249 | + $current_author = $post->post_author; |
|
| 250 | + |
|
| 251 | + //get the users authorised to author courses |
|
| 252 | + $users = $this->get_teachers_and_authors(); |
|
| 253 | + |
|
| 254 | + ?> |
|
| 255 | 255 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
| 256 | 256 | |
| 257 | 257 | <?php foreach ( $users as $user_id ) { ?> |
| 258 | 258 | |
| 259 | 259 | <?php |
| 260 | - $user = get_user_by('id', $user_id); |
|
| 261 | - ?> |
|
| 260 | + $user = get_user_by('id', $user_id); |
|
| 261 | + ?> |
|
| 262 | 262 | <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
| 263 | 263 | <?php echo $user->display_name; ?> |
| 264 | 264 | </option> |
@@ -269,1289 +269,1289 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | <?php |
| 271 | 271 | |
| 272 | - } // end render_teacher_meta_box() |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Sensei_Teacher::get_teachers_and_authors |
|
| 276 | - * |
|
| 277 | - * Get a list of users who can author courses, lessons and quizes. |
|
| 278 | - * |
|
| 279 | - * @since 1.8.0 |
|
| 280 | - * @access public |
|
| 281 | - * @parameters |
|
| 282 | - * @return array $users user id array |
|
| 283 | - */ |
|
| 284 | - public function get_teachers_and_authors ( ){ |
|
| 285 | - |
|
| 286 | - $author_query_args = array( |
|
| 287 | - 'blog_id' => $GLOBALS['blog_id'], |
|
| 288 | - 'fields' => 'any', |
|
| 289 | - 'who' => 'authors' |
|
| 290 | - ); |
|
| 291 | - |
|
| 292 | - $authors = get_users( $author_query_args ); |
|
| 293 | - |
|
| 294 | - $teacher_query_args = array( |
|
| 295 | - 'blog_id' => $GLOBALS['blog_id'], |
|
| 296 | - 'fields' => 'any', |
|
| 297 | - 'role' => 'teacher', |
|
| 298 | - ); |
|
| 299 | - |
|
| 300 | - $teachers = get_users( $teacher_query_args ); |
|
| 301 | - |
|
| 302 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
| 303 | - |
|
| 304 | - }// end get_teachers_and_authors |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Sensei_Teacher::save_teacher_meta_box |
|
| 308 | - * |
|
| 309 | - * Save the new teacher / author to course and all lessons |
|
| 310 | - * |
|
| 311 | - * Hooked into admin_init |
|
| 312 | - * |
|
| 313 | - * @since 1.8.0 |
|
| 314 | - * @access public |
|
| 315 | - * @parameters |
|
| 316 | - * @return array $users user id array |
|
| 317 | - */ |
|
| 318 | - public function save_teacher_meta_box ( $course_id ){ |
|
| 272 | + } // end render_teacher_meta_box() |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Sensei_Teacher::get_teachers_and_authors |
|
| 276 | + * |
|
| 277 | + * Get a list of users who can author courses, lessons and quizes. |
|
| 278 | + * |
|
| 279 | + * @since 1.8.0 |
|
| 280 | + * @access public |
|
| 281 | + * @parameters |
|
| 282 | + * @return array $users user id array |
|
| 283 | + */ |
|
| 284 | + public function get_teachers_and_authors ( ){ |
|
| 285 | + |
|
| 286 | + $author_query_args = array( |
|
| 287 | + 'blog_id' => $GLOBALS['blog_id'], |
|
| 288 | + 'fields' => 'any', |
|
| 289 | + 'who' => 'authors' |
|
| 290 | + ); |
|
| 291 | + |
|
| 292 | + $authors = get_users( $author_query_args ); |
|
| 293 | + |
|
| 294 | + $teacher_query_args = array( |
|
| 295 | + 'blog_id' => $GLOBALS['blog_id'], |
|
| 296 | + 'fields' => 'any', |
|
| 297 | + 'role' => 'teacher', |
|
| 298 | + ); |
|
| 299 | + |
|
| 300 | + $teachers = get_users( $teacher_query_args ); |
|
| 301 | + |
|
| 302 | + return array_unique( array_merge( $teachers, $authors ) ); |
|
| 303 | + |
|
| 304 | + }// end get_teachers_and_authors |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Sensei_Teacher::save_teacher_meta_box |
|
| 308 | + * |
|
| 309 | + * Save the new teacher / author to course and all lessons |
|
| 310 | + * |
|
| 311 | + * Hooked into admin_init |
|
| 312 | + * |
|
| 313 | + * @since 1.8.0 |
|
| 314 | + * @access public |
|
| 315 | + * @parameters |
|
| 316 | + * @return array $users user id array |
|
| 317 | + */ |
|
| 318 | + public function save_teacher_meta_box ( $course_id ){ |
|
| 319 | 319 | |
| 320 | - // check if this is a post from saving the teacher, if not exit early |
|
| 321 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
| 322 | - return; |
|
| 323 | - } |
|
| 320 | + // check if this is a post from saving the teacher, if not exit early |
|
| 321 | + if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
| 322 | + return; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - //don't fire this hook again |
|
| 326 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 325 | + //don't fire this hook again |
|
| 326 | + remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 327 | 327 | |
| 328 | - // get the current post object |
|
| 329 | - $post = get_post( $course_id ); |
|
| 328 | + // get the current post object |
|
| 329 | + $post = get_post( $course_id ); |
|
| 330 | 330 | |
| 331 | - // get the current teacher/author |
|
| 332 | - $current_author = absint( $post->post_author ); |
|
| 333 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 331 | + // get the current teacher/author |
|
| 332 | + $current_author = absint( $post->post_author ); |
|
| 333 | + $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 334 | 334 | |
| 335 | - // loop through all post lessons to update their authors as well |
|
| 336 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 335 | + // loop through all post lessons to update their authors as well |
|
| 336 | + $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 337 | 337 | |
| 338 | - // do not do any processing if the selected author is the same as the current author |
|
| 339 | - if( $current_author == $new_author ){ |
|
| 340 | - return; |
|
| 341 | - } |
|
| 338 | + // do not do any processing if the selected author is the same as the current author |
|
| 339 | + if( $current_author == $new_author ){ |
|
| 340 | + return; |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - // save the course author |
|
| 344 | - $post_updates = array( |
|
| 345 | - 'ID' => $post->ID , |
|
| 346 | - 'post_author' => $new_author |
|
| 347 | - ); |
|
| 348 | - wp_update_post( $post_updates ); |
|
| 343 | + // save the course author |
|
| 344 | + $post_updates = array( |
|
| 345 | + 'ID' => $post->ID , |
|
| 346 | + 'post_author' => $new_author |
|
| 347 | + ); |
|
| 348 | + wp_update_post( $post_updates ); |
|
| 349 | 349 | |
| 350 | - // ensure the the modules are update so that then new teacher has access to them |
|
| 351 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
| 350 | + // ensure the the modules are update so that then new teacher has access to them |
|
| 351 | + Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
| 352 | 352 | |
| 353 | - // notify the new teacher |
|
| 354 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 353 | + // notify the new teacher |
|
| 354 | + $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 355 | 355 | |
| 356 | - } // end save_teacher_meta_box |
|
| 356 | + } // end save_teacher_meta_box |
|
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
| 360 | - * the new author. Making sure the course terms are maintained. |
|
| 361 | - * |
|
| 362 | - * This function also checks if terms are shared, with other courses |
|
| 363 | - * |
|
| 364 | - * @param $course_id |
|
| 365 | - * @param $new_teacher_id |
|
| 366 | - * @return void |
|
| 367 | - */ |
|
| 368 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 358 | + /** |
|
| 359 | + * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
| 360 | + * the new author. Making sure the course terms are maintained. |
|
| 361 | + * |
|
| 362 | + * This function also checks if terms are shared, with other courses |
|
| 363 | + * |
|
| 364 | + * @param $course_id |
|
| 365 | + * @param $new_teacher_id |
|
| 366 | + * @return void |
|
| 367 | + */ |
|
| 368 | + public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 369 | 369 | |
| 370 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 371 | - return false; |
|
| 372 | - } |
|
| 370 | + if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 371 | + return false; |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
| 374 | + $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
| 375 | 375 | |
| 376 | - if( empty( $terms_selected_on_course ) ){ |
|
| 377 | - return; |
|
| 378 | - } |
|
| 376 | + if( empty( $terms_selected_on_course ) ){ |
|
| 377 | + return; |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - foreach( $terms_selected_on_course as $term ){ |
|
| 380 | + foreach( $terms_selected_on_course as $term ){ |
|
| 381 | 381 | |
| 382 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 383 | - if( $new_teacher_id != $term_author->ID ){ |
|
| 382 | + $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 383 | + if( $new_teacher_id != $term_author->ID ){ |
|
| 384 | 384 | |
| 385 | - $new_term = ''; |
|
| 385 | + $new_term = ''; |
|
| 386 | 386 | |
| 387 | - //if the new teacher is admin first check to see if the term with this name already exists |
|
| 388 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
| 387 | + //if the new teacher is admin first check to see if the term with this name already exists |
|
| 388 | + if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
| 389 | 389 | |
| 390 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 391 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
| 392 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
| 393 | - if( !empty( $existing_admin_terms ) ){ |
|
| 394 | - // insert it even if it exists |
|
| 395 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 396 | - } |
|
| 397 | - } |
|
| 390 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 391 | + $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
| 392 | + $existing_admin_terms = get_terms( 'module', $term_args ); |
|
| 393 | + if( !empty( $existing_admin_terms ) ){ |
|
| 394 | + // insert it even if it exists |
|
| 395 | + $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | - if( empty ( $new_term ) ){ |
|
| 399 | + if( empty ( $new_term ) ){ |
|
| 400 | 400 | |
| 401 | - //setup the new slug |
|
| 402 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 403 | - |
|
| 404 | - // create new term and set it |
|
| 405 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 406 | - |
|
| 407 | - } |
|
| 401 | + //setup the new slug |
|
| 402 | + $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 403 | + |
|
| 404 | + // create new term and set it |
|
| 405 | + $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 406 | + |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | 409 | |
| 410 | 410 | |
| 411 | - // if term exists |
|
| 412 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 411 | + // if term exists |
|
| 412 | + if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 413 | 413 | |
| 414 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 415 | - $term_id = $existing_term->term_id; |
|
| 414 | + $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 415 | + $term_id = $existing_term->term_id; |
|
| 416 | 416 | |
| 417 | - }else{ |
|
| 417 | + }else{ |
|
| 418 | 418 | |
| 419 | - // for a new term simply get the term from the returned value |
|
| 420 | - $term_id = $new_term['term_id']; |
|
| 419 | + // for a new term simply get the term from the returned value |
|
| 420 | + $term_id = $new_term['term_id']; |
|
| 421 | 421 | |
| 422 | - } // end if term exist |
|
| 422 | + } // end if term exist |
|
| 423 | 423 | |
| 424 | - // set the terms selected on the course |
|
| 425 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 424 | + // set the terms selected on the course |
|
| 425 | + wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 426 | 426 | |
| 427 | - // remove old term |
|
| 428 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 427 | + // remove old term |
|
| 428 | + wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 429 | 429 | |
| 430 | - // update the lessons within the current module term |
|
| 431 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 432 | - foreach( $lessons as $lesson ){ |
|
| 430 | + // update the lessons within the current module term |
|
| 431 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 432 | + foreach( $lessons as $lesson ){ |
|
| 433 | 433 | |
| 434 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
| 434 | + if( has_term( $term->slug, 'module', $lesson ) ){ |
|
| 435 | 435 | |
| 436 | - // add the new term, the false at the end says to replace all terms on this module |
|
| 437 | - // with the new term. |
|
| 438 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
| 439 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
| 440 | - } |
|
| 436 | + // add the new term, the false at the end says to replace all terms on this module |
|
| 437 | + // with the new term. |
|
| 438 | + wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
| 439 | + update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | - }// end for each |
|
| 442 | + }// end for each |
|
| 443 | 443 | |
| 444 | - } |
|
| 445 | - } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | - }// end update_course_module_terms_author |
|
| 447 | + }// end update_course_module_terms_author |
|
| 448 | 448 | |
| 449 | - /** |
|
| 450 | - * Sensei_Teacher::update_course_lessons_author |
|
| 451 | - * |
|
| 452 | - * Update all course lessons and their quiz with a new author |
|
| 453 | - * |
|
| 454 | - * @since 1.8.0 |
|
| 455 | - * @access public |
|
| 456 | - * @parameters |
|
| 457 | - * @return array $users user id array |
|
| 458 | - */ |
|
| 459 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 449 | + /** |
|
| 450 | + * Sensei_Teacher::update_course_lessons_author |
|
| 451 | + * |
|
| 452 | + * Update all course lessons and their quiz with a new author |
|
| 453 | + * |
|
| 454 | + * @since 1.8.0 |
|
| 455 | + * @access public |
|
| 456 | + * @parameters |
|
| 457 | + * @return array $users user id array |
|
| 458 | + */ |
|
| 459 | + public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 460 | 460 | |
| 461 | 461 | |
| 462 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 463 | - return false; |
|
| 464 | - } |
|
| 462 | + if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 463 | + return false; |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | - //get a list of course lessons |
|
| 467 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 466 | + //get a list of course lessons |
|
| 467 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 468 | 468 | |
| 469 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 470 | - return false; |
|
| 471 | - } |
|
| 469 | + if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 470 | + return false; |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | - // update each lesson and quiz author |
|
| 474 | - foreach( $lessons as $lesson ){ |
|
| 473 | + // update each lesson and quiz author |
|
| 474 | + foreach( $lessons as $lesson ){ |
|
| 475 | 475 | |
| 476 | - // don't update if the author is tha same as the new author |
|
| 477 | - if( $new_author == $lesson->post_author ){ |
|
| 478 | - continue; |
|
| 479 | - } |
|
| 476 | + // don't update if the author is tha same as the new author |
|
| 477 | + if( $new_author == $lesson->post_author ){ |
|
| 478 | + continue; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - // update lesson author |
|
| 482 | - wp_update_post( array( |
|
| 483 | - 'ID'=> $lesson->ID, |
|
| 484 | - 'post_author' => $new_author |
|
| 485 | - ) ); |
|
| 481 | + // update lesson author |
|
| 482 | + wp_update_post( array( |
|
| 483 | + 'ID'=> $lesson->ID, |
|
| 484 | + 'post_author' => $new_author |
|
| 485 | + ) ); |
|
| 486 | 486 | |
| 487 | - // update quiz author |
|
| 488 | - //get the lessons quiz |
|
| 489 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 490 | - if( is_array( $lesson_quizzes ) ){ |
|
| 491 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
| 492 | - // update quiz with new author |
|
| 493 | - wp_update_post( array( |
|
| 494 | - 'ID' => $quiz_id, |
|
| 495 | - 'post_author' => $new_author |
|
| 496 | - ) ); |
|
| 497 | - } |
|
| 498 | - }else{ |
|
| 499 | - wp_update_post( array( |
|
| 500 | - 'ID' => $lesson_quizzes, |
|
| 501 | - 'post_author' => $new_author |
|
| 502 | - ) ); |
|
| 503 | - } |
|
| 487 | + // update quiz author |
|
| 488 | + //get the lessons quiz |
|
| 489 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 490 | + if( is_array( $lesson_quizzes ) ){ |
|
| 491 | + foreach ( $lesson_quizzes as $quiz_id ) { |
|
| 492 | + // update quiz with new author |
|
| 493 | + wp_update_post( array( |
|
| 494 | + 'ID' => $quiz_id, |
|
| 495 | + 'post_author' => $new_author |
|
| 496 | + ) ); |
|
| 497 | + } |
|
| 498 | + }else{ |
|
| 499 | + wp_update_post( array( |
|
| 500 | + 'ID' => $lesson_quizzes, |
|
| 501 | + 'post_author' => $new_author |
|
| 502 | + ) ); |
|
| 503 | + } |
|
| 504 | 504 | |
| 505 | - } // end for each lessons |
|
| 505 | + } // end for each lessons |
|
| 506 | 506 | |
| 507 | - return true; |
|
| 507 | + return true; |
|
| 508 | 508 | |
| 509 | - }// end update_course_lessons_author |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Sensei_Teacher::course_analysis_teacher_access_limit |
|
| 515 | - * |
|
| 516 | - * Alter the query so that users can only see their courses on the analysis page |
|
| 517 | - * |
|
| 518 | - * @since 1.8.0 |
|
| 519 | - * @access public |
|
| 520 | - * @parameters $query |
|
| 521 | - * @return array $users user id array |
|
| 522 | - */ |
|
| 523 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
| 524 | - |
|
| 525 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 526 | - return $query; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 530 | - return $query; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $screen = get_current_screen(); |
|
| 534 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 535 | - |
|
| 536 | - // exit early for the following conditions |
|
| 537 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 538 | - |
|
| 539 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
| 540 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
| 541 | - return $query; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - global $current_user; |
|
| 545 | - // set the query author to the current user to only show those those posts |
|
| 546 | - $query->set( 'author', $current_user->ID ); |
|
| 547 | - return $query; |
|
| 548 | - |
|
| 549 | - }// end course_analysis_teacher_access_limit |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 554 | - * |
|
| 555 | - * Determine if we're in admin and the current logged in use is a teacher |
|
| 556 | - * |
|
| 557 | - * @since 1.8.0 |
|
| 558 | - * @access public |
|
| 559 | - * @parameters array $wp_query |
|
| 560 | - * @return bool $is_admin_teacher |
|
| 561 | - */ |
|
| 562 | - public function is_admin_teacher ( ){ |
|
| 563 | - |
|
| 564 | - if( ! is_user_logged_in()){ |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - $is_admin_teacher = false; |
|
| 568 | - |
|
| 569 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 570 | - |
|
| 571 | - $is_admin_teacher = true; |
|
| 572 | - |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - return $is_admin_teacher; |
|
| 576 | - |
|
| 577 | - } // end is_admin_teacher |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * Show correct post counts on list table for Sensei post types |
|
| 581 | - * |
|
| 582 | - * @since 1.8.0 |
|
| 583 | - * |
|
| 584 | - * @param object $counts Default status counts |
|
| 585 | - * @param string $type Current post type |
|
| 586 | - * @param string $perm User permission level |
|
| 587 | - * @return object Modified status counts |
|
| 588 | - */ |
|
| 589 | - public function list_table_counts( $counts, $type, $perm ) { |
|
| 590 | - global $current_user; |
|
| 591 | - |
|
| 592 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 593 | - return $counts; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - if( ! $this->is_admin_teacher() ) { |
|
| 597 | - return $counts; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - $args = array( |
|
| 601 | - 'post_type' => $type, |
|
| 602 | - 'author' => $current_user->ID, |
|
| 603 | - 'posts_per_page' => -1 |
|
| 604 | - ); |
|
| 605 | - |
|
| 606 | - // Get all available statuses |
|
| 607 | - $stati = get_post_stati(); |
|
| 608 | - |
|
| 609 | - // Update count object |
|
| 610 | - foreach( $stati as $status ) { |
|
| 611 | - $args['post_status'] = $status; |
|
| 612 | - $posts = get_posts( $args ); |
|
| 613 | - $counts->$status = count( $posts ); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - return $counts; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Filter the post queries to show |
|
| 621 | - * only lesson /course and users that belong |
|
| 622 | - * to the current logged teacher. |
|
| 623 | - * |
|
| 624 | - * @since 1.8.0 |
|
| 625 | - * |
|
| 626 | - */ |
|
| 627 | - public function filter_queries ( $query ) { |
|
| 628 | - global $current_user; |
|
| 629 | - |
|
| 630 | - if( ! $this->is_admin_teacher() ) { |
|
| 631 | - return; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 635 | - return; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - $screen = get_current_screen(); |
|
| 639 | - if( empty( $screen ) ) { |
|
| 640 | - return $query; |
|
| 641 | - } |
|
| 642 | - switch( $screen->id ) { |
|
| 643 | - case 'sensei_page_sensei_grading': |
|
| 644 | - case 'sensei_page_sensei_analysis': |
|
| 645 | - case 'sensei_page_sensei_learners': |
|
| 646 | - case 'lesson': |
|
| 647 | - case 'course': |
|
| 648 | - case 'question': |
|
| 649 | - case 'lesson_page_module-order': |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * sensei_filter_queries_set_author |
|
| 653 | - * Filter the author Sensei set for queries |
|
| 654 | - * |
|
| 655 | - * @since 1.8.0 |
|
| 656 | - * |
|
| 657 | - * @param int $user_id |
|
| 658 | - * @param string $screen_id |
|
| 659 | - * |
|
| 660 | - */ |
|
| 661 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 662 | - break; |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * Limit grading quizzes to only those within courses belonging to the current teacher |
|
| 668 | - * . This excludes the admin user. |
|
| 669 | - * |
|
| 670 | - * @since 1.8.0 |
|
| 671 | - * @hooked into the_comments |
|
| 672 | - * @param array $comments |
|
| 673 | - * |
|
| 674 | - * @return array $comments |
|
| 675 | - */ |
|
| 676 | - public function filter_grading_activity_queries( $comments ){ |
|
| 677 | - |
|
| 678 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 679 | - return $comments ; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - //check if we're on the grading screen |
|
| 683 | - $screen = get_current_screen(); |
|
| 684 | - |
|
| 685 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 686 | - return $comments; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - // get the course and determine if the current teacher is the owner |
|
| 690 | - // if not remove it from the list of comments to be returned |
|
| 691 | - foreach( $comments as $key => $comment){ |
|
| 692 | - $lesson = get_post( $comment->comment_post_ID ); |
|
| 693 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
| 694 | - $course = get_post( $course_id ); |
|
| 695 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
| 696 | - //remove this as the teacher should see this. |
|
| 697 | - unset( $comments[ $key ] ); |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - return $comments ; |
|
| 701 | - |
|
| 702 | - }// end function filter grading |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * Limit the grading screen totals to only show lessons in the course |
|
| 706 | - * belonging to the currently logged in teacher. This only applies to |
|
| 707 | - * the teacher role. |
|
| 708 | - * |
|
| 709 | - * @since 1.8.0 |
|
| 710 | - * |
|
| 711 | - * @hooked into sensei_count_statuses_args |
|
| 712 | - * @param array $args |
|
| 713 | - * |
|
| 714 | - * @return array $args |
|
| 715 | - */ |
|
| 716 | - public function limit_grading_totals( $args ){ |
|
| 717 | - |
|
| 718 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 719 | - return $args ; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - //get the teachers courses |
|
| 723 | - // the query is already filtered to only the teacher |
|
| 724 | - $courses = Sensei()->course->get_all_courses(); |
|
| 725 | - |
|
| 726 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 727 | - return $args; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - //setup the lessons quizzes to limit the grading totals to |
|
| 731 | - $quiz_scope = array(); |
|
| 732 | - foreach( $courses as $course ){ |
|
| 733 | - |
|
| 734 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 735 | - |
|
| 736 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 737 | - |
|
| 738 | - foreach( $course_lessons as $lesson ){ |
|
| 739 | - |
|
| 740 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 741 | - if( !empty( $quiz_id ) ) { |
|
| 742 | - |
|
| 743 | - array_push( $quiz_scope, $quiz_id ); |
|
| 744 | - |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - $args['post__in'] = $quiz_scope; |
|
| 754 | - |
|
| 755 | - return $args; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * It ensures that the author archive shows course by the current user. |
|
| 760 | - * |
|
| 761 | - * This function is hooked into the pre_get_posts filter |
|
| 762 | - * |
|
| 763 | - * @param WP_Query $query |
|
| 764 | - * @return WP_Query $query |
|
| 765 | - */ |
|
| 766 | - public function add_courses_to_author_archive( $query ) { |
|
| 767 | - |
|
| 768 | - if ( is_admin() || ! $query->is_author() ){ |
|
| 769 | - return $query; |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - // this should only apply to users with the teacher role |
|
| 773 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
| 774 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
| 775 | - |
|
| 776 | - return $query; |
|
| 777 | - |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - // Change post types depending on what is set already |
|
| 781 | - $current_post_types = $query->get( 'post_type' ); |
|
| 782 | - if( empty( $current_post_types ) ){ |
|
| 783 | - |
|
| 784 | - // if empty it means post by default, so add post so that it also includes that for now |
|
| 785 | - $new_post_types = array( 'post', 'course' ); |
|
| 786 | - |
|
| 787 | - } elseif( is_array( $current_post_types ) ) { |
|
| 788 | - |
|
| 789 | - // merge the post types instead of overwriting it |
|
| 790 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 791 | - |
|
| 792 | - }else{ |
|
| 793 | - |
|
| 794 | - // in this instance it is probably just one post type in string format |
|
| 795 | - $new_post_types = array( $current_post_types , 'course'); |
|
| 796 | - |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - // change the query before returning it |
|
| 800 | - $query->set('post_type', $new_post_types ); |
|
| 801 | - |
|
| 802 | - /** |
|
| 803 | - * Change the query on the teacher author archive template |
|
| 804 | - * |
|
| 805 | - * @since 1.8.4 |
|
| 806 | - * @param WP_Query $query |
|
| 807 | - */ |
|
| 808 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 809 | - |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - /** |
|
| 813 | - * Notify teacher when someone assigns a course to their account. |
|
| 814 | - * |
|
| 815 | - * @since 1.8.0 |
|
| 816 | - * |
|
| 817 | - * @param $teacher_id |
|
| 818 | - * @param $course_id |
|
| 819 | - * @return bool |
|
| 820 | - */ |
|
| 821 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 822 | - |
|
| 823 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 824 | - return false; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - // if new user is the same as the current logged user, they don't need an email |
|
| 828 | - if( $teacher_id == get_current_user_id() ){ |
|
| 829 | - return true; |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - // load the email class |
|
| 833 | - include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
|
| 834 | - $email = new Teacher_New_Course_Assignment(); |
|
| 835 | - $email->trigger( $teacher_id, $course_id ); |
|
| 836 | - |
|
| 837 | - return true; |
|
| 838 | - } // end teacher_course_assigned_notification |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * Email the admin when a teacher creates a new course |
|
| 842 | - * |
|
| 843 | - * This function hooks into wp_insert_post |
|
| 844 | - * |
|
| 845 | - * @since 1.8.0 |
|
| 846 | - * @param int $course_id |
|
| 847 | - * @return bool |
|
| 848 | - */ |
|
| 849 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 850 | - |
|
| 851 | - $course_id = $post->ID; |
|
| 852 | - |
|
| 853 | - if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
| 854 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
| 855 | - |
|
| 856 | - return false; |
|
| 857 | - |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - /** |
|
| 861 | - * Filter the option to send admin notification emails when teachers creation |
|
| 862 | - * course. |
|
| 863 | - * |
|
| 864 | - * @since 1.8.0 |
|
| 865 | - * |
|
| 866 | - * @param bool $on default true |
|
| 867 | - */ |
|
| 868 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 869 | - return false; |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - // setting up the data needed by the email template |
|
| 873 | - global $sensei_email_data; |
|
| 874 | - $template = 'admin-teacher-new-course-created'; |
|
| 875 | - $course = get_post( $course_id ); |
|
| 876 | - $teacher = new WP_User( $course->post_author ); |
|
| 877 | - $recipient = get_option('admin_email', true); |
|
| 878 | - |
|
| 879 | - // don't send if the course is created by admin |
|
| 880 | - if( $recipient == $teacher->user_email ){ |
|
| 881 | - return; |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - /** |
|
| 885 | - * Filter the email Header for the admin-teacher-new-course-created template |
|
| 886 | - * |
|
| 887 | - * @since 1.8.0 |
|
| 888 | - * @param string $template |
|
| 889 | - */ |
|
| 890 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * Filter the email subject for the the |
|
| 894 | - * admin-teacher-new-course-created template |
|
| 895 | - * |
|
| 896 | - * @since 1.8.0 |
|
| 897 | - * @param string $subject default New course assigned to you |
|
| 898 | - * @param string $template |
|
| 899 | - */ |
|
| 900 | - $subject = apply_filters('sensei_email_subject', |
|
| 901 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 902 | - $template ); |
|
| 903 | - |
|
| 904 | - //course edit link |
|
| 905 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 906 | - |
|
| 907 | - // Construct data array |
|
| 908 | - $email_data = array( |
|
| 909 | - 'template' => $template, |
|
| 910 | - 'heading' => $heading, |
|
| 911 | - 'teacher' => $teacher, |
|
| 912 | - 'course_id' => $course_id, |
|
| 913 | - 'course_name' => $course->post_title, |
|
| 914 | - 'course_edit_link' => $course_edit_link, |
|
| 915 | - ); |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * Filter the sensei email data for the admin-teacher-new-course-created template |
|
| 919 | - * |
|
| 920 | - * @since 1.8.0 |
|
| 921 | - * @param array $email_data |
|
| 922 | - * @param string $template |
|
| 923 | - */ |
|
| 924 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 925 | - |
|
| 926 | - // Send mail |
|
| 927 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 928 | - |
|
| 929 | - }// end notify admin of course creation |
|
| 930 | - |
|
| 931 | - /** |
|
| 932 | - * Limit the analysis view to only the users taking courses belong to this teacher |
|
| 933 | - * |
|
| 934 | - * Hooked into sensei_analysis_get_learners |
|
| 935 | - * @param array $args WP_User_Query arguments |
|
| 936 | - * @return array $learners_query_results |
|
| 937 | - */ |
|
| 938 | - public function limit_analysis_learners( $args ){ |
|
| 939 | - |
|
| 940 | - // show default for none teachers |
|
| 941 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 942 | - return $args; |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - // for teachers all courses only return those which belong to the teacher |
|
| 946 | - // as they don't have access to course belonging to other users |
|
| 947 | - $teacher_courses = Sensei()->course->get_all_courses(); |
|
| 509 | + }// end update_course_lessons_author |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Sensei_Teacher::course_analysis_teacher_access_limit |
|
| 515 | + * |
|
| 516 | + * Alter the query so that users can only see their courses on the analysis page |
|
| 517 | + * |
|
| 518 | + * @since 1.8.0 |
|
| 519 | + * @access public |
|
| 520 | + * @parameters $query |
|
| 521 | + * @return array $users user id array |
|
| 522 | + */ |
|
| 523 | + public function course_analysis_teacher_access_limit ( $query ) { |
|
| 524 | + |
|
| 525 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 526 | + return $query; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 530 | + return $query; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $screen = get_current_screen(); |
|
| 534 | + $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 535 | + |
|
| 536 | + // exit early for the following conditions |
|
| 537 | + $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 538 | + |
|
| 539 | + if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
| 540 | + || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
| 541 | + return $query; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + global $current_user; |
|
| 545 | + // set the query author to the current user to only show those those posts |
|
| 546 | + $query->set( 'author', $current_user->ID ); |
|
| 547 | + return $query; |
|
| 548 | + |
|
| 549 | + }// end course_analysis_teacher_access_limit |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 554 | + * |
|
| 555 | + * Determine if we're in admin and the current logged in use is a teacher |
|
| 556 | + * |
|
| 557 | + * @since 1.8.0 |
|
| 558 | + * @access public |
|
| 559 | + * @parameters array $wp_query |
|
| 560 | + * @return bool $is_admin_teacher |
|
| 561 | + */ |
|
| 562 | + public function is_admin_teacher ( ){ |
|
| 563 | + |
|
| 564 | + if( ! is_user_logged_in()){ |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + $is_admin_teacher = false; |
|
| 568 | + |
|
| 569 | + if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 570 | + |
|
| 571 | + $is_admin_teacher = true; |
|
| 572 | + |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + return $is_admin_teacher; |
|
| 576 | + |
|
| 577 | + } // end is_admin_teacher |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * Show correct post counts on list table for Sensei post types |
|
| 581 | + * |
|
| 582 | + * @since 1.8.0 |
|
| 583 | + * |
|
| 584 | + * @param object $counts Default status counts |
|
| 585 | + * @param string $type Current post type |
|
| 586 | + * @param string $perm User permission level |
|
| 587 | + * @return object Modified status counts |
|
| 588 | + */ |
|
| 589 | + public function list_table_counts( $counts, $type, $perm ) { |
|
| 590 | + global $current_user; |
|
| 591 | + |
|
| 592 | + if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 593 | + return $counts; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + if( ! $this->is_admin_teacher() ) { |
|
| 597 | + return $counts; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + $args = array( |
|
| 601 | + 'post_type' => $type, |
|
| 602 | + 'author' => $current_user->ID, |
|
| 603 | + 'posts_per_page' => -1 |
|
| 604 | + ); |
|
| 605 | + |
|
| 606 | + // Get all available statuses |
|
| 607 | + $stati = get_post_stati(); |
|
| 608 | + |
|
| 609 | + // Update count object |
|
| 610 | + foreach( $stati as $status ) { |
|
| 611 | + $args['post_status'] = $status; |
|
| 612 | + $posts = get_posts( $args ); |
|
| 613 | + $counts->$status = count( $posts ); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + return $counts; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Filter the post queries to show |
|
| 621 | + * only lesson /course and users that belong |
|
| 622 | + * to the current logged teacher. |
|
| 623 | + * |
|
| 624 | + * @since 1.8.0 |
|
| 625 | + * |
|
| 626 | + */ |
|
| 627 | + public function filter_queries ( $query ) { |
|
| 628 | + global $current_user; |
|
| 629 | + |
|
| 630 | + if( ! $this->is_admin_teacher() ) { |
|
| 631 | + return; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 635 | + return; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + $screen = get_current_screen(); |
|
| 639 | + if( empty( $screen ) ) { |
|
| 640 | + return $query; |
|
| 641 | + } |
|
| 642 | + switch( $screen->id ) { |
|
| 643 | + case 'sensei_page_sensei_grading': |
|
| 644 | + case 'sensei_page_sensei_analysis': |
|
| 645 | + case 'sensei_page_sensei_learners': |
|
| 646 | + case 'lesson': |
|
| 647 | + case 'course': |
|
| 648 | + case 'question': |
|
| 649 | + case 'lesson_page_module-order': |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * sensei_filter_queries_set_author |
|
| 653 | + * Filter the author Sensei set for queries |
|
| 654 | + * |
|
| 655 | + * @since 1.8.0 |
|
| 656 | + * |
|
| 657 | + * @param int $user_id |
|
| 658 | + * @param string $screen_id |
|
| 659 | + * |
|
| 660 | + */ |
|
| 661 | + $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 662 | + break; |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * Limit grading quizzes to only those within courses belonging to the current teacher |
|
| 668 | + * . This excludes the admin user. |
|
| 669 | + * |
|
| 670 | + * @since 1.8.0 |
|
| 671 | + * @hooked into the_comments |
|
| 672 | + * @param array $comments |
|
| 673 | + * |
|
| 674 | + * @return array $comments |
|
| 675 | + */ |
|
| 676 | + public function filter_grading_activity_queries( $comments ){ |
|
| 677 | + |
|
| 678 | + if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 679 | + return $comments ; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + //check if we're on the grading screen |
|
| 683 | + $screen = get_current_screen(); |
|
| 684 | + |
|
| 685 | + if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 686 | + return $comments; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + // get the course and determine if the current teacher is the owner |
|
| 690 | + // if not remove it from the list of comments to be returned |
|
| 691 | + foreach( $comments as $key => $comment){ |
|
| 692 | + $lesson = get_post( $comment->comment_post_ID ); |
|
| 693 | + $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
| 694 | + $course = get_post( $course_id ); |
|
| 695 | + if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
| 696 | + //remove this as the teacher should see this. |
|
| 697 | + unset( $comments[ $key ] ); |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + return $comments ; |
|
| 701 | + |
|
| 702 | + }// end function filter grading |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * Limit the grading screen totals to only show lessons in the course |
|
| 706 | + * belonging to the currently logged in teacher. This only applies to |
|
| 707 | + * the teacher role. |
|
| 708 | + * |
|
| 709 | + * @since 1.8.0 |
|
| 710 | + * |
|
| 711 | + * @hooked into sensei_count_statuses_args |
|
| 712 | + * @param array $args |
|
| 713 | + * |
|
| 714 | + * @return array $args |
|
| 715 | + */ |
|
| 716 | + public function limit_grading_totals( $args ){ |
|
| 717 | + |
|
| 718 | + if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 719 | + return $args ; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + //get the teachers courses |
|
| 723 | + // the query is already filtered to only the teacher |
|
| 724 | + $courses = Sensei()->course->get_all_courses(); |
|
| 725 | + |
|
| 726 | + if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 727 | + return $args; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + //setup the lessons quizzes to limit the grading totals to |
|
| 731 | + $quiz_scope = array(); |
|
| 732 | + foreach( $courses as $course ){ |
|
| 733 | + |
|
| 734 | + $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 735 | + |
|
| 736 | + if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 737 | + |
|
| 738 | + foreach( $course_lessons as $lesson ){ |
|
| 739 | + |
|
| 740 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 741 | + if( !empty( $quiz_id ) ) { |
|
| 742 | + |
|
| 743 | + array_push( $quiz_scope, $quiz_id ); |
|
| 744 | + |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + $args['post__in'] = $quiz_scope; |
|
| 754 | + |
|
| 755 | + return $args; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * It ensures that the author archive shows course by the current user. |
|
| 760 | + * |
|
| 761 | + * This function is hooked into the pre_get_posts filter |
|
| 762 | + * |
|
| 763 | + * @param WP_Query $query |
|
| 764 | + * @return WP_Query $query |
|
| 765 | + */ |
|
| 766 | + public function add_courses_to_author_archive( $query ) { |
|
| 767 | + |
|
| 768 | + if ( is_admin() || ! $query->is_author() ){ |
|
| 769 | + return $query; |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + // this should only apply to users with the teacher role |
|
| 773 | + $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
| 774 | + if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
| 775 | + |
|
| 776 | + return $query; |
|
| 777 | + |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + // Change post types depending on what is set already |
|
| 781 | + $current_post_types = $query->get( 'post_type' ); |
|
| 782 | + if( empty( $current_post_types ) ){ |
|
| 783 | + |
|
| 784 | + // if empty it means post by default, so add post so that it also includes that for now |
|
| 785 | + $new_post_types = array( 'post', 'course' ); |
|
| 786 | + |
|
| 787 | + } elseif( is_array( $current_post_types ) ) { |
|
| 788 | + |
|
| 789 | + // merge the post types instead of overwriting it |
|
| 790 | + $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 791 | + |
|
| 792 | + }else{ |
|
| 793 | + |
|
| 794 | + // in this instance it is probably just one post type in string format |
|
| 795 | + $new_post_types = array( $current_post_types , 'course'); |
|
| 796 | + |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + // change the query before returning it |
|
| 800 | + $query->set('post_type', $new_post_types ); |
|
| 801 | + |
|
| 802 | + /** |
|
| 803 | + * Change the query on the teacher author archive template |
|
| 804 | + * |
|
| 805 | + * @since 1.8.4 |
|
| 806 | + * @param WP_Query $query |
|
| 807 | + */ |
|
| 808 | + return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 809 | + |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + /** |
|
| 813 | + * Notify teacher when someone assigns a course to their account. |
|
| 814 | + * |
|
| 815 | + * @since 1.8.0 |
|
| 816 | + * |
|
| 817 | + * @param $teacher_id |
|
| 818 | + * @param $course_id |
|
| 819 | + * @return bool |
|
| 820 | + */ |
|
| 821 | + public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 822 | + |
|
| 823 | + if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 824 | + return false; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + // if new user is the same as the current logged user, they don't need an email |
|
| 828 | + if( $teacher_id == get_current_user_id() ){ |
|
| 829 | + return true; |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + // load the email class |
|
| 833 | + include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
|
| 834 | + $email = new Teacher_New_Course_Assignment(); |
|
| 835 | + $email->trigger( $teacher_id, $course_id ); |
|
| 836 | + |
|
| 837 | + return true; |
|
| 838 | + } // end teacher_course_assigned_notification |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * Email the admin when a teacher creates a new course |
|
| 842 | + * |
|
| 843 | + * This function hooks into wp_insert_post |
|
| 844 | + * |
|
| 845 | + * @since 1.8.0 |
|
| 846 | + * @param int $course_id |
|
| 847 | + * @return bool |
|
| 848 | + */ |
|
| 849 | + public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 850 | + |
|
| 851 | + $course_id = $post->ID; |
|
| 852 | + |
|
| 853 | + if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
| 854 | + || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
| 855 | + |
|
| 856 | + return false; |
|
| 857 | + |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + /** |
|
| 861 | + * Filter the option to send admin notification emails when teachers creation |
|
| 862 | + * course. |
|
| 863 | + * |
|
| 864 | + * @since 1.8.0 |
|
| 865 | + * |
|
| 866 | + * @param bool $on default true |
|
| 867 | + */ |
|
| 868 | + if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 869 | + return false; |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + // setting up the data needed by the email template |
|
| 873 | + global $sensei_email_data; |
|
| 874 | + $template = 'admin-teacher-new-course-created'; |
|
| 875 | + $course = get_post( $course_id ); |
|
| 876 | + $teacher = new WP_User( $course->post_author ); |
|
| 877 | + $recipient = get_option('admin_email', true); |
|
| 878 | + |
|
| 879 | + // don't send if the course is created by admin |
|
| 880 | + if( $recipient == $teacher->user_email ){ |
|
| 881 | + return; |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + /** |
|
| 885 | + * Filter the email Header for the admin-teacher-new-course-created template |
|
| 886 | + * |
|
| 887 | + * @since 1.8.0 |
|
| 888 | + * @param string $template |
|
| 889 | + */ |
|
| 890 | + $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * Filter the email subject for the the |
|
| 894 | + * admin-teacher-new-course-created template |
|
| 895 | + * |
|
| 896 | + * @since 1.8.0 |
|
| 897 | + * @param string $subject default New course assigned to you |
|
| 898 | + * @param string $template |
|
| 899 | + */ |
|
| 900 | + $subject = apply_filters('sensei_email_subject', |
|
| 901 | + '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 902 | + $template ); |
|
| 903 | + |
|
| 904 | + //course edit link |
|
| 905 | + $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 906 | + |
|
| 907 | + // Construct data array |
|
| 908 | + $email_data = array( |
|
| 909 | + 'template' => $template, |
|
| 910 | + 'heading' => $heading, |
|
| 911 | + 'teacher' => $teacher, |
|
| 912 | + 'course_id' => $course_id, |
|
| 913 | + 'course_name' => $course->post_title, |
|
| 914 | + 'course_edit_link' => $course_edit_link, |
|
| 915 | + ); |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * Filter the sensei email data for the admin-teacher-new-course-created template |
|
| 919 | + * |
|
| 920 | + * @since 1.8.0 |
|
| 921 | + * @param array $email_data |
|
| 922 | + * @param string $template |
|
| 923 | + */ |
|
| 924 | + $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 925 | + |
|
| 926 | + // Send mail |
|
| 927 | + Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 928 | + |
|
| 929 | + }// end notify admin of course creation |
|
| 930 | + |
|
| 931 | + /** |
|
| 932 | + * Limit the analysis view to only the users taking courses belong to this teacher |
|
| 933 | + * |
|
| 934 | + * Hooked into sensei_analysis_get_learners |
|
| 935 | + * @param array $args WP_User_Query arguments |
|
| 936 | + * @return array $learners_query_results |
|
| 937 | + */ |
|
| 938 | + public function limit_analysis_learners( $args ){ |
|
| 939 | + |
|
| 940 | + // show default for none teachers |
|
| 941 | + if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 942 | + return $args; |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + // for teachers all courses only return those which belong to the teacher |
|
| 946 | + // as they don't have access to course belonging to other users |
|
| 947 | + $teacher_courses = Sensei()->course->get_all_courses(); |
|
| 948 | 948 | |
| 949 | - // if the user has no courses they should see no users |
|
| 950 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 951 | - // tell the query to return 0 students |
|
| 952 | - $args[ 'include'] = array( 0 ); |
|
| 953 | - return $args; |
|
| 954 | - |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - $learner_ids_for_teacher_courses = array(); |
|
| 958 | - foreach( $teacher_courses as $course ){ |
|
| 959 | - |
|
| 960 | - $course_learner_ids = array(); |
|
| 961 | - $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
| 962 | - |
|
| 963 | - if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 964 | - continue; // skip to the next course as there are no users on this course |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - // it could be an array of comments or a single comment |
|
| 968 | - if( is_array( $activity_comments ) ){ |
|
| 949 | + // if the user has no courses they should see no users |
|
| 950 | + if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 951 | + // tell the query to return 0 students |
|
| 952 | + $args[ 'include'] = array( 0 ); |
|
| 953 | + return $args; |
|
| 954 | + |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + $learner_ids_for_teacher_courses = array(); |
|
| 958 | + foreach( $teacher_courses as $course ){ |
|
| 959 | + |
|
| 960 | + $course_learner_ids = array(); |
|
| 961 | + $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
| 962 | + |
|
| 963 | + if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 964 | + continue; // skip to the next course as there are no users on this course |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + // it could be an array of comments or a single comment |
|
| 968 | + if( is_array( $activity_comments ) ){ |
|
| 969 | 969 | |
| 970 | - foreach( $activity_comments as $comment ){ |
|
| 970 | + foreach( $activity_comments as $comment ){ |
|
| 971 | 971 | |
| 972 | - $user = get_userdata( $comment->user_id ); |
|
| 972 | + $user = get_userdata( $comment->user_id ); |
|
| 973 | 973 | |
| 974 | - if( empty( $user ) ){ |
|
| 975 | - // next comment in this array |
|
| 976 | - continue; |
|
| 977 | - } |
|
| 974 | + if( empty( $user ) ){ |
|
| 975 | + // next comment in this array |
|
| 976 | + continue; |
|
| 977 | + } |
|
| 978 | 978 | |
| 979 | - $course_learner_ids[] = $user->ID; |
|
| 980 | - } |
|
| 979 | + $course_learner_ids[] = $user->ID; |
|
| 980 | + } |
|
| 981 | 981 | |
| 982 | - }else{ |
|
| 982 | + }else{ |
|
| 983 | 983 | |
| 984 | - $user = get_userdata( $activity_comments->user_id ); |
|
| 985 | - $course_learner_ids[] = $user->ID; |
|
| 984 | + $user = get_userdata( $activity_comments->user_id ); |
|
| 985 | + $course_learner_ids[] = $user->ID; |
|
| 986 | 986 | |
| 987 | - } |
|
| 987 | + } |
|
| 988 | 988 | |
| 989 | - // add learners on this course to the all courses learner list |
|
| 990 | - $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
| 989 | + // add learners on this course to the all courses learner list |
|
| 990 | + $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
| 991 | 991 | |
| 992 | - } |
|
| 992 | + } |
|
| 993 | 993 | |
| 994 | - // if there are no students taking the courses by this teacher don't show them any of the other users |
|
| 995 | - if( empty( $learner_ids_for_teacher_courses ) ){ |
|
| 994 | + // if there are no students taking the courses by this teacher don't show them any of the other users |
|
| 995 | + if( empty( $learner_ids_for_teacher_courses ) ){ |
|
| 996 | 996 | |
| 997 | - $args[ 'include'] = array( 0 ); |
|
| 997 | + $args[ 'include'] = array( 0 ); |
|
| 998 | 998 | |
| 999 | - }else{ |
|
| 999 | + }else{ |
|
| 1000 | 1000 | |
| 1001 | - $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
| 1001 | + $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
| 1002 | 1002 | |
| 1003 | - } |
|
| 1003 | + } |
|
| 1004 | 1004 | |
| 1005 | - // return the WP_Use_Query arguments |
|
| 1006 | - return $args; |
|
| 1005 | + // return the WP_Use_Query arguments |
|
| 1006 | + return $args; |
|
| 1007 | 1007 | |
| 1008 | - }// end limit_analysis_learners |
|
| 1008 | + }// end limit_analysis_learners |
|
| 1009 | 1009 | |
| 1010 | - /** |
|
| 1011 | - * Give teacher full admin access to the question post type |
|
| 1012 | - * in certain cases. |
|
| 1013 | - * |
|
| 1014 | - * @since 1.8.0 |
|
| 1015 | - * @param $questions |
|
| 1016 | - * @return mixed |
|
| 1017 | - */ |
|
| 1018 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1010 | + /** |
|
| 1011 | + * Give teacher full admin access to the question post type |
|
| 1012 | + * in certain cases. |
|
| 1013 | + * |
|
| 1014 | + * @since 1.8.0 |
|
| 1015 | + * @param $questions |
|
| 1016 | + * @return mixed |
|
| 1017 | + */ |
|
| 1018 | + public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1019 | 1019 | |
| 1020 | - if( ! $this->is_admin_teacher() ){ |
|
| 1021 | - return $questions; |
|
| 1022 | - } |
|
| 1020 | + if( ! $this->is_admin_teacher() ){ |
|
| 1021 | + return $questions; |
|
| 1022 | + } |
|
| 1023 | 1023 | |
| 1024 | - $screen = get_current_screen(); |
|
| 1024 | + $screen = get_current_screen(); |
|
| 1025 | 1025 | |
| 1026 | - // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
|
| 1027 | - remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
| 1026 | + // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
|
| 1027 | + remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
| 1028 | 1028 | |
| 1029 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1029 | + if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1030 | 1030 | |
| 1031 | - $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1032 | - if( ! empty($admin_user) ){ |
|
| 1031 | + $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1032 | + if( ! empty($admin_user) ){ |
|
| 1033 | 1033 | |
| 1034 | - $current_teacher_id = get_current_user_id(); |
|
| 1034 | + $current_teacher_id = get_current_user_id(); |
|
| 1035 | 1035 | |
| 1036 | - // set current user to admin so teacher can view all questions |
|
| 1037 | - wp_set_current_user( $admin_user->ID ); |
|
| 1038 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 1036 | + // set current user to admin so teacher can view all questions |
|
| 1037 | + wp_set_current_user( $admin_user->ID ); |
|
| 1038 | + $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 1039 | 1039 | |
| 1040 | - // set the teacher as the current use again |
|
| 1041 | - wp_set_current_user( $current_teacher_id ); |
|
| 1042 | - } |
|
| 1040 | + // set the teacher as the current use again |
|
| 1041 | + wp_set_current_user( $current_teacher_id ); |
|
| 1042 | + } |
|
| 1043 | 1043 | |
| 1044 | - } |
|
| 1045 | - // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
|
| 1046 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
| 1044 | + } |
|
| 1045 | + // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
|
| 1046 | + add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
| 1047 | 1047 | |
| 1048 | - return $questions; |
|
| 1049 | - } |
|
| 1048 | + return $questions; |
|
| 1049 | + } |
|
| 1050 | 1050 | |
| 1051 | - /** |
|
| 1052 | - * Give the teacher role access to questions from the question bank |
|
| 1053 | - * |
|
| 1054 | - * @since 1.8.0 |
|
| 1055 | - * @param $wp_query |
|
| 1056 | - * @return mixed |
|
| 1057 | - */ |
|
| 1058 | - public function give_access_to_all_questions( $wp_query ){ |
|
| 1051 | + /** |
|
| 1052 | + * Give the teacher role access to questions from the question bank |
|
| 1053 | + * |
|
| 1054 | + * @since 1.8.0 |
|
| 1055 | + * @param $wp_query |
|
| 1056 | + * @return mixed |
|
| 1057 | + */ |
|
| 1058 | + public function give_access_to_all_questions( $wp_query ){ |
|
| 1059 | 1059 | |
| 1060 | - if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
| 1060 | + if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
| 1061 | 1061 | |
| 1062 | - return $wp_query; |
|
| 1063 | - } |
|
| 1062 | + return $wp_query; |
|
| 1063 | + } |
|
| 1064 | 1064 | |
| 1065 | - $screen = get_current_screen(); |
|
| 1066 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1067 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1065 | + $screen = get_current_screen(); |
|
| 1066 | + if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1067 | + || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1068 | 1068 | |
| 1069 | - $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1070 | - if( ! empty($admin_user) ){ |
|
| 1069 | + $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1070 | + if( ! empty($admin_user) ){ |
|
| 1071 | 1071 | |
| 1072 | - $current_teacher_id = get_current_user_id(); |
|
| 1072 | + $current_teacher_id = get_current_user_id(); |
|
| 1073 | 1073 | |
| 1074 | - // set current user to admin so teacher can view all questions |
|
| 1075 | - wp_set_current_user( $admin_user->ID ); |
|
| 1074 | + // set current user to admin so teacher can view all questions |
|
| 1075 | + wp_set_current_user( $admin_user->ID ); |
|
| 1076 | 1076 | |
| 1077 | - //run new query as admin |
|
| 1078 | - $wp_query = new WP_Query( $wp_query->query ); |
|
| 1077 | + //run new query as admin |
|
| 1078 | + $wp_query = new WP_Query( $wp_query->query ); |
|
| 1079 | 1079 | |
| 1080 | - //set the teache as current use again |
|
| 1081 | - wp_set_current_user( $current_teacher_id ); |
|
| 1080 | + //set the teache as current use again |
|
| 1081 | + wp_set_current_user( $current_teacher_id ); |
|
| 1082 | 1082 | |
| 1083 | - } |
|
| 1084 | - } |
|
| 1083 | + } |
|
| 1084 | + } |
|
| 1085 | 1085 | |
| 1086 | - return $wp_query; |
|
| 1087 | - }// end give_access_to_all_questions |
|
| 1086 | + return $wp_query; |
|
| 1087 | + }// end give_access_to_all_questions |
|
| 1088 | 1088 | |
| 1089 | - /** |
|
| 1090 | - * Add new column heading to the course admin edit list |
|
| 1091 | - * |
|
| 1092 | - * @since 1.8.0 |
|
| 1093 | - * @param $columns |
|
| 1094 | - * @return array |
|
| 1095 | - */ |
|
| 1096 | - public function course_column_heading($columns) { |
|
| 1089 | + /** |
|
| 1090 | + * Add new column heading to the course admin edit list |
|
| 1091 | + * |
|
| 1092 | + * @since 1.8.0 |
|
| 1093 | + * @param $columns |
|
| 1094 | + * @return array |
|
| 1095 | + */ |
|
| 1096 | + public function course_column_heading($columns) { |
|
| 1097 | 1097 | |
| 1098 | - if( $this->is_admin_teacher() ){ |
|
| 1099 | - return $columns; |
|
| 1100 | - } |
|
| 1101 | - $new_columns = array( |
|
| 1102 | - 'teacher' => __('Teacher', 'woothemes-sensei'), |
|
| 1103 | - ); |
|
| 1104 | - return array_merge($columns, $new_columns); |
|
| 1098 | + if( $this->is_admin_teacher() ){ |
|
| 1099 | + return $columns; |
|
| 1100 | + } |
|
| 1101 | + $new_columns = array( |
|
| 1102 | + 'teacher' => __('Teacher', 'woothemes-sensei'), |
|
| 1103 | + ); |
|
| 1104 | + return array_merge($columns, $new_columns); |
|
| 1105 | 1105 | |
| 1106 | - }// end teacher column add |
|
| 1106 | + }// end teacher column add |
|
| 1107 | 1107 | |
| 1108 | - /** |
|
| 1109 | - * Print out teacher column data |
|
| 1110 | - * |
|
| 1111 | - * @since 1.8.0 |
|
| 1112 | - * @param $column |
|
| 1113 | - * @param $course_id |
|
| 1114 | - */ |
|
| 1115 | - public function course_column_data( $column, $course_id ){ |
|
| 1108 | + /** |
|
| 1109 | + * Print out teacher column data |
|
| 1110 | + * |
|
| 1111 | + * @since 1.8.0 |
|
| 1112 | + * @param $column |
|
| 1113 | + * @param $course_id |
|
| 1114 | + */ |
|
| 1115 | + public function course_column_data( $column, $course_id ){ |
|
| 1116 | 1116 | |
| 1117 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1118 | - return; |
|
| 1119 | - } |
|
| 1117 | + if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1118 | + return; |
|
| 1119 | + } |
|
| 1120 | 1120 | |
| 1121 | - $course = get_post( $course_id ); |
|
| 1122 | - $teacher = get_userdata( $course->post_author ); |
|
| 1121 | + $course = get_post( $course_id ); |
|
| 1122 | + $teacher = get_userdata( $course->post_author ); |
|
| 1123 | 1123 | |
| 1124 | - if( !$teacher ){ |
|
| 1125 | - return; |
|
| 1126 | - } |
|
| 1124 | + if( !$teacher ){ |
|
| 1125 | + return; |
|
| 1126 | + } |
|
| 1127 | 1127 | |
| 1128 | - echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
| 1128 | + echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
| 1129 | 1129 | |
| 1130 | - }// end course_column_ data |
|
| 1130 | + }// end course_column_ data |
|
| 1131 | 1131 | |
| 1132 | - /** |
|
| 1133 | - * Return only courses belonging to the given teacher. |
|
| 1134 | - * |
|
| 1135 | - * |
|
| 1136 | - * @since 1.8.0 |
|
| 1137 | - * |
|
| 1138 | - * @param int $teacher_id |
|
| 1139 | - * @param bool $return_ids_only |
|
| 1140 | - * |
|
| 1141 | - * @return array $teachers_courses |
|
| 1142 | - */ |
|
| 1143 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1132 | + /** |
|
| 1133 | + * Return only courses belonging to the given teacher. |
|
| 1134 | + * |
|
| 1135 | + * |
|
| 1136 | + * @since 1.8.0 |
|
| 1137 | + * |
|
| 1138 | + * @param int $teacher_id |
|
| 1139 | + * @param bool $return_ids_only |
|
| 1140 | + * |
|
| 1141 | + * @return array $teachers_courses |
|
| 1142 | + */ |
|
| 1143 | + public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1144 | 1144 | |
| 1145 | - $teachers_courses = array(); |
|
| 1145 | + $teachers_courses = array(); |
|
| 1146 | 1146 | |
| 1147 | - if( empty( $teacher_id ) ){ |
|
| 1148 | - $teacher_id = get_current_user_id(); |
|
| 1149 | - } |
|
| 1147 | + if( empty( $teacher_id ) ){ |
|
| 1148 | + $teacher_id = get_current_user_id(); |
|
| 1149 | + } |
|
| 1150 | 1150 | |
| 1151 | - $all_courses = Sensei()->course->get_all_courses(); |
|
| 1151 | + $all_courses = Sensei()->course->get_all_courses(); |
|
| 1152 | 1152 | |
| 1153 | - if( empty( $all_courses ) ){ |
|
| 1154 | - return $all_courses; |
|
| 1155 | - } |
|
| 1153 | + if( empty( $all_courses ) ){ |
|
| 1154 | + return $all_courses; |
|
| 1155 | + } |
|
| 1156 | 1156 | |
| 1157 | - foreach( $all_courses as $course ){ |
|
| 1157 | + foreach( $all_courses as $course ){ |
|
| 1158 | 1158 | |
| 1159 | - if( $course->post_author != $teacher_id ){ |
|
| 1160 | - continue; |
|
| 1161 | - } |
|
| 1159 | + if( $course->post_author != $teacher_id ){ |
|
| 1160 | + continue; |
|
| 1161 | + } |
|
| 1162 | 1162 | |
| 1163 | - if( $return_ids_only ){ |
|
| 1163 | + if( $return_ids_only ){ |
|
| 1164 | 1164 | |
| 1165 | - $teachers_courses[] = $course->ID; |
|
| 1165 | + $teachers_courses[] = $course->ID; |
|
| 1166 | 1166 | |
| 1167 | - }else{ |
|
| 1167 | + }else{ |
|
| 1168 | 1168 | |
| 1169 | - $teachers_courses[] = $course; |
|
| 1169 | + $teachers_courses[] = $course; |
|
| 1170 | 1170 | |
| 1171 | - } |
|
| 1171 | + } |
|
| 1172 | 1172 | |
| 1173 | - } |
|
| 1173 | + } |
|
| 1174 | 1174 | |
| 1175 | - return $teachers_courses; |
|
| 1175 | + return $teachers_courses; |
|
| 1176 | 1176 | |
| 1177 | - } |
|
| 1177 | + } |
|
| 1178 | 1178 | |
| 1179 | - /** |
|
| 1180 | - * Limit the message display to only those sent to the current teacher |
|
| 1181 | - * |
|
| 1182 | - * @since 1.8.0 |
|
| 1183 | - * |
|
| 1184 | - * @param $query |
|
| 1185 | - * @return mixed |
|
| 1186 | - */ |
|
| 1187 | - public function limit_edit_messages_query( $query ){ |
|
| 1188 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1189 | - return $query; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - $teacher = wp_get_current_user(); |
|
| 1193 | - |
|
| 1194 | - $query->set( 'meta_key', '_receiver' ); |
|
| 1195 | - $meta_query_args = array( |
|
| 1196 | - 'key' => '_receiver', |
|
| 1197 | - 'value' => $teacher->get('user_login') , |
|
| 1198 | - 'compare' => '=' |
|
| 1199 | - ); |
|
| 1179 | + /** |
|
| 1180 | + * Limit the message display to only those sent to the current teacher |
|
| 1181 | + * |
|
| 1182 | + * @since 1.8.0 |
|
| 1183 | + * |
|
| 1184 | + * @param $query |
|
| 1185 | + * @return mixed |
|
| 1186 | + */ |
|
| 1187 | + public function limit_edit_messages_query( $query ){ |
|
| 1188 | + if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1189 | + return $query; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + $teacher = wp_get_current_user(); |
|
| 1193 | + |
|
| 1194 | + $query->set( 'meta_key', '_receiver' ); |
|
| 1195 | + $meta_query_args = array( |
|
| 1196 | + 'key' => '_receiver', |
|
| 1197 | + 'value' => $teacher->get('user_login') , |
|
| 1198 | + 'compare' => '=' |
|
| 1199 | + ); |
|
| 1200 | 1200 | |
| 1201 | - $query->set('meta_query', $meta_query_args ); |
|
| 1201 | + $query->set('meta_query', $meta_query_args ); |
|
| 1202 | 1202 | |
| 1203 | - return $query; |
|
| 1204 | - } |
|
| 1203 | + return $query; |
|
| 1204 | + } |
|
| 1205 | 1205 | |
| 1206 | 1206 | |
| 1207 | - /** |
|
| 1208 | - * Add options to filter courses by teacher |
|
| 1209 | - * |
|
| 1210 | - * @since 1.8.0 |
|
| 1211 | - * |
|
| 1212 | - * @return void |
|
| 1213 | - */ |
|
| 1214 | - public function course_teacher_filter_options() { |
|
| 1215 | - global $typenow; |
|
| 1207 | + /** |
|
| 1208 | + * Add options to filter courses by teacher |
|
| 1209 | + * |
|
| 1210 | + * @since 1.8.0 |
|
| 1211 | + * |
|
| 1212 | + * @return void |
|
| 1213 | + */ |
|
| 1214 | + public function course_teacher_filter_options() { |
|
| 1215 | + global $typenow; |
|
| 1216 | 1216 | |
| 1217 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1218 | - return; |
|
| 1219 | - } |
|
| 1217 | + if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1218 | + return; |
|
| 1219 | + } |
|
| 1220 | 1220 | |
| 1221 | - // get all roles |
|
| 1222 | - $roles = get_editable_roles(); |
|
| 1221 | + // get all roles |
|
| 1222 | + $roles = get_editable_roles(); |
|
| 1223 | 1223 | |
| 1224 | - // get roles with the course edit capability |
|
| 1225 | - // and then get the users with those roles |
|
| 1226 | - $users_who_can_edit_courses = array(); |
|
| 1227 | - foreach( $roles as $role_item ){ |
|
| 1224 | + // get roles with the course edit capability |
|
| 1225 | + // and then get the users with those roles |
|
| 1226 | + $users_who_can_edit_courses = array(); |
|
| 1227 | + foreach( $roles as $role_item ){ |
|
| 1228 | 1228 | |
| 1229 | - $role = get_role( strtolower( $role_item['name'] ) ); |
|
| 1229 | + $role = get_role( strtolower( $role_item['name'] ) ); |
|
| 1230 | 1230 | |
| 1231 | - if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
| 1231 | + if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
| 1232 | 1232 | |
| 1233 | - $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
| 1234 | - $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
| 1233 | + $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
| 1234 | + $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
| 1235 | 1235 | |
| 1236 | - // add user from the current $user_role to all users |
|
| 1237 | - $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
| 1236 | + // add user from the current $user_role to all users |
|
| 1237 | + $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
| 1238 | 1238 | |
| 1239 | - } |
|
| 1239 | + } |
|
| 1240 | 1240 | |
| 1241 | - } |
|
| 1241 | + } |
|
| 1242 | 1242 | |
| 1243 | - // Create the select element with the given users who can edit course |
|
| 1244 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1245 | - $course_options = ''; |
|
| 1246 | - foreach( $users_who_can_edit_courses as $user ) { |
|
| 1247 | - $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
| 1248 | - } |
|
| 1243 | + // Create the select element with the given users who can edit course |
|
| 1244 | + $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1245 | + $course_options = ''; |
|
| 1246 | + foreach( $users_who_can_edit_courses as $user ) { |
|
| 1247 | + $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
| 1248 | + } |
|
| 1249 | 1249 | |
| 1250 | - $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
|
| 1251 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1252 | - $output .= $course_options; |
|
| 1253 | - $output .= '</select>'; |
|
| 1250 | + $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
|
| 1251 | + $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1252 | + $output .= $course_options; |
|
| 1253 | + $output .= '</select>'; |
|
| 1254 | 1254 | |
| 1255 | - echo $output; |
|
| 1256 | - } |
|
| 1255 | + echo $output; |
|
| 1256 | + } |
|
| 1257 | 1257 | |
| 1258 | - /** |
|
| 1259 | - * Modify the main query on the admin course list screen |
|
| 1260 | - * |
|
| 1261 | - * @since 1.8.0 |
|
| 1262 | - * |
|
| 1263 | - * @param $query |
|
| 1264 | - * @return $query |
|
| 1265 | - */ |
|
| 1266 | - public function teacher_filter_query_modify( $query ){ |
|
| 1267 | - global $typenow; |
|
| 1258 | + /** |
|
| 1259 | + * Modify the main query on the admin course list screen |
|
| 1260 | + * |
|
| 1261 | + * @since 1.8.0 |
|
| 1262 | + * |
|
| 1263 | + * @param $query |
|
| 1264 | + * @return $query |
|
| 1265 | + */ |
|
| 1266 | + public function teacher_filter_query_modify( $query ){ |
|
| 1267 | + global $typenow; |
|
| 1268 | 1268 | |
| 1269 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1270 | - return $query; |
|
| 1271 | - } |
|
| 1272 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1273 | - |
|
| 1274 | - if( empty( $course_teacher ) ) { |
|
| 1275 | - return $query; |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - $query['author'] = $course_teacher; |
|
| 1279 | - return $query; |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * Only show current teacher's media in the media library |
|
| 1284 | - * @param array $request Default request arguments |
|
| 1285 | - * @return array Modified request arguments |
|
| 1286 | - */ |
|
| 1287 | - public function restrict_media_library( $request = array() ) { |
|
| 1288 | - |
|
| 1289 | - if( ! is_admin() ) { |
|
| 1290 | - return $request; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - if( ! $this->is_admin_teacher() ) { |
|
| 1294 | - return $request; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - $screen = get_current_screen(); |
|
| 1298 | - |
|
| 1299 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1300 | - $teacher = intval( get_current_user_id() ); |
|
| 1301 | - |
|
| 1302 | - if( $teacher ) { |
|
| 1303 | - $request['author__in'] = array( $teacher ); |
|
| 1304 | - } |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - return $request; |
|
| 1308 | - } // End restrict_media_library() |
|
| 1309 | - |
|
| 1310 | - /** |
|
| 1311 | - * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen |
|
| 1312 | - * @param array $query Default query arguments |
|
| 1313 | - * @return array Modified query arguments |
|
| 1314 | - */ |
|
| 1315 | - public function restrict_media_library_modal( $query = array() ) { |
|
| 1316 | - |
|
| 1317 | - if( ! is_admin() ) { |
|
| 1318 | - return $query; |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - if( ! $this->is_admin_teacher() ) { |
|
| 1322 | - return $query; |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - $teacher = intval( get_current_user_id() ); |
|
| 1326 | - |
|
| 1327 | - if( $teacher ) { |
|
| 1328 | - $query['author__in'] = array( $teacher ); |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - return $query; |
|
| 1332 | - } // End restrict_media_library_modal() |
|
| 1333 | - |
|
| 1334 | - /** |
|
| 1335 | - * When saving the lesson, update the teacher if the lesson belongs to a course |
|
| 1336 | - * |
|
| 1337 | - * @since 1.8.0 |
|
| 1338 | - * |
|
| 1339 | - * @param int $lesson_id |
|
| 1340 | - */ |
|
| 1341 | - public function update_lesson_teacher( $lesson_id ){ |
|
| 1342 | - |
|
| 1343 | - if( 'lesson'!= get_post_type() ){ |
|
| 1344 | - return; |
|
| 1345 | - } |
|
| 1269 | + if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1270 | + return $query; |
|
| 1271 | + } |
|
| 1272 | + $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1273 | + |
|
| 1274 | + if( empty( $course_teacher ) ) { |
|
| 1275 | + return $query; |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + $query['author'] = $course_teacher; |
|
| 1279 | + return $query; |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * Only show current teacher's media in the media library |
|
| 1284 | + * @param array $request Default request arguments |
|
| 1285 | + * @return array Modified request arguments |
|
| 1286 | + */ |
|
| 1287 | + public function restrict_media_library( $request = array() ) { |
|
| 1288 | + |
|
| 1289 | + if( ! is_admin() ) { |
|
| 1290 | + return $request; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + if( ! $this->is_admin_teacher() ) { |
|
| 1294 | + return $request; |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + $screen = get_current_screen(); |
|
| 1298 | + |
|
| 1299 | + if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1300 | + $teacher = intval( get_current_user_id() ); |
|
| 1301 | + |
|
| 1302 | + if( $teacher ) { |
|
| 1303 | + $request['author__in'] = array( $teacher ); |
|
| 1304 | + } |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + return $request; |
|
| 1308 | + } // End restrict_media_library() |
|
| 1309 | + |
|
| 1310 | + /** |
|
| 1311 | + * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen |
|
| 1312 | + * @param array $query Default query arguments |
|
| 1313 | + * @return array Modified query arguments |
|
| 1314 | + */ |
|
| 1315 | + public function restrict_media_library_modal( $query = array() ) { |
|
| 1316 | + |
|
| 1317 | + if( ! is_admin() ) { |
|
| 1318 | + return $query; |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + if( ! $this->is_admin_teacher() ) { |
|
| 1322 | + return $query; |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + $teacher = intval( get_current_user_id() ); |
|
| 1326 | + |
|
| 1327 | + if( $teacher ) { |
|
| 1328 | + $query['author__in'] = array( $teacher ); |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + return $query; |
|
| 1332 | + } // End restrict_media_library_modal() |
|
| 1333 | + |
|
| 1334 | + /** |
|
| 1335 | + * When saving the lesson, update the teacher if the lesson belongs to a course |
|
| 1336 | + * |
|
| 1337 | + * @since 1.8.0 |
|
| 1338 | + * |
|
| 1339 | + * @param int $lesson_id |
|
| 1340 | + */ |
|
| 1341 | + public function update_lesson_teacher( $lesson_id ){ |
|
| 1342 | + |
|
| 1343 | + if( 'lesson'!= get_post_type() ){ |
|
| 1344 | + return; |
|
| 1345 | + } |
|
| 1346 | 1346 | |
| 1347 | - // this should only run once per request cycle |
|
| 1348 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1347 | + // this should only run once per request cycle |
|
| 1348 | + remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1349 | 1349 | |
| 1350 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1350 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1351 | 1351 | |
| 1352 | - if( empty( $course_id ) || ! $course_id ){ |
|
| 1353 | - return; |
|
| 1354 | - } |
|
| 1352 | + if( empty( $course_id ) || ! $course_id ){ |
|
| 1353 | + return; |
|
| 1354 | + } |
|
| 1355 | 1355 | |
| 1356 | - $course = get_post( $course_id ); |
|
| 1356 | + $course = get_post( $course_id ); |
|
| 1357 | 1357 | |
| 1358 | - $lesson_update_args= array( |
|
| 1359 | - 'ID' => $lesson_id , |
|
| 1360 | - 'post_author' => $course->post_author |
|
| 1361 | - ); |
|
| 1362 | - wp_update_post( $lesson_update_args ); |
|
| 1358 | + $lesson_update_args= array( |
|
| 1359 | + 'ID' => $lesson_id , |
|
| 1360 | + 'post_author' => $course->post_author |
|
| 1361 | + ); |
|
| 1362 | + wp_update_post( $lesson_update_args ); |
|
| 1363 | 1363 | |
| 1364 | - } // end update_lesson_teacher |
|
| 1364 | + } // end update_lesson_teacher |
|
| 1365 | 1365 | |
| 1366 | - /** |
|
| 1367 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 1368 | - * |
|
| 1369 | - * Limit teachers to only see their courses, lessons and questions |
|
| 1370 | - * |
|
| 1371 | - * @since 1.8.0 |
|
| 1372 | - * @access public |
|
| 1373 | - * @parameters array $wp_query |
|
| 1374 | - * @return WP_Query $wp_query |
|
| 1375 | - */ |
|
| 1376 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1377 | - global $current_user; |
|
| 1366 | + /** |
|
| 1367 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 1368 | + * |
|
| 1369 | + * Limit teachers to only see their courses, lessons and questions |
|
| 1370 | + * |
|
| 1371 | + * @since 1.8.0 |
|
| 1372 | + * @access public |
|
| 1373 | + * @parameters array $wp_query |
|
| 1374 | + * @return WP_Query $wp_query |
|
| 1375 | + */ |
|
| 1376 | + public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1377 | + global $current_user; |
|
| 1378 | 1378 | |
| 1379 | - //exit early |
|
| 1380 | - if( ! $this->is_admin_teacher() ){ |
|
| 1381 | - return $wp_query; |
|
| 1382 | - } |
|
| 1379 | + //exit early |
|
| 1380 | + if( ! $this->is_admin_teacher() ){ |
|
| 1381 | + return $wp_query; |
|
| 1382 | + } |
|
| 1383 | 1383 | |
| 1384 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1385 | - return $wp_query; |
|
| 1386 | - } |
|
| 1384 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1385 | + return $wp_query; |
|
| 1386 | + } |
|
| 1387 | 1387 | |
| 1388 | - $screen = get_current_screen(); |
|
| 1388 | + $screen = get_current_screen(); |
|
| 1389 | 1389 | |
| 1390 | - if( empty( $screen ) ){ |
|
| 1391 | - return $wp_query; |
|
| 1392 | - } |
|
| 1390 | + if( empty( $screen ) ){ |
|
| 1391 | + return $wp_query; |
|
| 1392 | + } |
|
| 1393 | 1393 | |
| 1394 | - // for any of these conditions limit what the teacher will see |
|
| 1395 | - $limit_screens = array( |
|
| 1396 | - 'edit-lesson', |
|
| 1397 | - 'edit-course', |
|
| 1398 | - 'edit-question', |
|
| 1399 | - 'course_page_course-order', |
|
| 1400 | - 'lesson_page_lesson-order', |
|
| 1401 | - ); |
|
| 1394 | + // for any of these conditions limit what the teacher will see |
|
| 1395 | + $limit_screens = array( |
|
| 1396 | + 'edit-lesson', |
|
| 1397 | + 'edit-course', |
|
| 1398 | + 'edit-question', |
|
| 1399 | + 'course_page_course-order', |
|
| 1400 | + 'lesson_page_lesson-order', |
|
| 1401 | + ); |
|
| 1402 | 1402 | |
| 1403 | - if( in_array($screen->id , $limit_screens ) ) { |
|
| 1403 | + if( in_array($screen->id , $limit_screens ) ) { |
|
| 1404 | 1404 | |
| 1405 | - // set the query author to the current user to only show those those posts |
|
| 1406 | - $wp_query->set( 'author', $current_user->ID ); |
|
| 1407 | - } |
|
| 1405 | + // set the query author to the current user to only show those those posts |
|
| 1406 | + $wp_query->set( 'author', $current_user->ID ); |
|
| 1407 | + } |
|
| 1408 | 1408 | |
| 1409 | - return $wp_query; |
|
| 1409 | + return $wp_query; |
|
| 1410 | 1410 | |
| 1411 | - } // end limit_teacher_edit_screen_post_types() |
|
| 1411 | + } // end limit_teacher_edit_screen_post_types() |
|
| 1412 | 1412 | |
| 1413 | 1413 | |
| 1414 | - /** |
|
| 1415 | - * Sensei_Teacher::teacher_login_redirect |
|
| 1416 | - * |
|
| 1417 | - * Redirect teachers to /wp-admin/ after login |
|
| 1418 | - * |
|
| 1419 | - * @since 1.8.7 |
|
| 1420 | - * @access public |
|
| 1421 | - * @param string $user_login |
|
| 1422 | - * @param object $user |
|
| 1423 | - * @return void |
|
| 1424 | - */ |
|
| 1414 | + /** |
|
| 1415 | + * Sensei_Teacher::teacher_login_redirect |
|
| 1416 | + * |
|
| 1417 | + * Redirect teachers to /wp-admin/ after login |
|
| 1418 | + * |
|
| 1419 | + * @since 1.8.7 |
|
| 1420 | + * @access public |
|
| 1421 | + * @param string $user_login |
|
| 1422 | + * @param object $user |
|
| 1423 | + * @return void |
|
| 1424 | + */ |
|
| 1425 | 1425 | |
| 1426 | - public function teacher_login_redirect( $user_login, $user ) { |
|
| 1426 | + public function teacher_login_redirect( $user_login, $user ) { |
|
| 1427 | 1427 | |
| 1428 | - if (user_can($user, 'edit_courses')) { |
|
| 1428 | + if (user_can($user, 'edit_courses')) { |
|
| 1429 | 1429 | |
| 1430 | - if (isset($_POST['redirect_to'])) { |
|
| 1430 | + if (isset($_POST['redirect_to'])) { |
|
| 1431 | 1431 | |
| 1432 | - wp_redirect($_POST['redirect_to'], 303); |
|
| 1432 | + wp_redirect($_POST['redirect_to'], 303); |
|
| 1433 | 1433 | |
| 1434 | - exit; |
|
| 1434 | + exit; |
|
| 1435 | 1435 | |
| 1436 | - } else { |
|
| 1436 | + } else { |
|
| 1437 | 1437 | |
| 1438 | - wp_redirect(admin_url(), 303); |
|
| 1438 | + wp_redirect(admin_url(), 303); |
|
| 1439 | 1439 | |
| 1440 | - exit; |
|
| 1440 | + exit; |
|
| 1441 | 1441 | |
| 1442 | - } |
|
| 1443 | - } |
|
| 1442 | + } |
|
| 1443 | + } |
|
| 1444 | 1444 | |
| 1445 | - } // end teacher_login_redirect() |
|
| 1445 | + } // end teacher_login_redirect() |
|
| 1446 | 1446 | |
| 1447 | 1447 | |
| 1448 | 1448 | |
| 1449 | - /** |
|
| 1450 | - * Sensei_Teacher::restrict_posts_menu_page() |
|
| 1451 | - * |
|
| 1452 | - * Remove the Posts menu page for teachers and restrict access to it. |
|
| 1453 | - * We have to do this because we give teachers the 'edit_posts' cap |
|
| 1454 | - * so they can 'moderate_comments' as well. |
|
| 1455 | - * |
|
| 1456 | - * @since 1.8.7 |
|
| 1457 | - * @access public |
|
| 1458 | - * @parameters void |
|
| 1459 | - * @return void |
|
| 1460 | - */ |
|
| 1449 | + /** |
|
| 1450 | + * Sensei_Teacher::restrict_posts_menu_page() |
|
| 1451 | + * |
|
| 1452 | + * Remove the Posts menu page for teachers and restrict access to it. |
|
| 1453 | + * We have to do this because we give teachers the 'edit_posts' cap |
|
| 1454 | + * so they can 'moderate_comments' as well. |
|
| 1455 | + * |
|
| 1456 | + * @since 1.8.7 |
|
| 1457 | + * @access public |
|
| 1458 | + * @parameters void |
|
| 1459 | + * @return void |
|
| 1460 | + */ |
|
| 1461 | 1461 | |
| 1462 | - public function restrict_posts_menu_page() { |
|
| 1462 | + public function restrict_posts_menu_page() { |
|
| 1463 | 1463 | |
| 1464 | - global $pagenow, $typenow; |
|
| 1464 | + global $pagenow, $typenow; |
|
| 1465 | 1465 | |
| 1466 | - $user = wp_get_current_user(); |
|
| 1466 | + $user = wp_get_current_user(); |
|
| 1467 | 1467 | |
| 1468 | - /** |
|
| 1469 | - * Filter the option to hide the Posts menu page. |
|
| 1470 | - * |
|
| 1471 | - * @since 1.8.7 |
|
| 1472 | - * |
|
| 1473 | - * @param bool $restrict default true |
|
| 1474 | - */ |
|
| 1468 | + /** |
|
| 1469 | + * Filter the option to hide the Posts menu page. |
|
| 1470 | + * |
|
| 1471 | + * @since 1.8.7 |
|
| 1472 | + * |
|
| 1473 | + * @param bool $restrict default true |
|
| 1474 | + */ |
|
| 1475 | 1475 | |
| 1476 | - $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
| 1476 | + $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
| 1477 | 1477 | |
| 1478 | - if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
| 1478 | + if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
| 1479 | 1479 | |
| 1480 | - remove_menu_page('edit.php'); |
|
| 1480 | + remove_menu_page('edit.php'); |
|
| 1481 | 1481 | |
| 1482 | - if ($pagenow == "edit.php" || $pagenow == "post-new.php") { |
|
| 1482 | + if ($pagenow == "edit.php" || $pagenow == "post-new.php") { |
|
| 1483 | 1483 | |
| 1484 | - if ($typenow == '' || $typenow == 'post' || $typenow == 'page') { |
|
| 1484 | + if ($typenow == '' || $typenow == 'post' || $typenow == 'page') { |
|
| 1485 | 1485 | |
| 1486 | - wp_die('You do not have sufficient permissions to access this page.'); |
|
| 1486 | + wp_die('You do not have sufficient permissions to access this page.'); |
|
| 1487 | 1487 | |
| 1488 | - } |
|
| 1488 | + } |
|
| 1489 | 1489 | |
| 1490 | - } |
|
| 1490 | + } |
|
| 1491 | 1491 | |
| 1492 | - } |
|
| 1492 | + } |
|
| 1493 | 1493 | |
| 1494 | - } // end restrict_posts_menu_page() |
|
| 1494 | + } // end restrict_posts_menu_page() |
|
| 1495 | 1495 | |
| 1496 | - /** |
|
| 1497 | - * Sensei_Teacher::restrict_comment_moderation() |
|
| 1498 | - * |
|
| 1499 | - * Restrict commendation moderation for teachers |
|
| 1500 | - * so they can only moderate comments made to posts they own. |
|
| 1501 | - * |
|
| 1502 | - * @since 1.8.7 |
|
| 1503 | - * @access public |
|
| 1504 | - * @parameters obj $clauses |
|
| 1505 | - * @return obj $clauses |
|
| 1506 | - */ |
|
| 1496 | + /** |
|
| 1497 | + * Sensei_Teacher::restrict_comment_moderation() |
|
| 1498 | + * |
|
| 1499 | + * Restrict commendation moderation for teachers |
|
| 1500 | + * so they can only moderate comments made to posts they own. |
|
| 1501 | + * |
|
| 1502 | + * @since 1.8.7 |
|
| 1503 | + * @access public |
|
| 1504 | + * @parameters obj $clauses |
|
| 1505 | + * @return obj $clauses |
|
| 1506 | + */ |
|
| 1507 | 1507 | |
| 1508 | - public function restrict_comment_moderation($clauses) { |
|
| 1508 | + public function restrict_comment_moderation($clauses) { |
|
| 1509 | 1509 | |
| 1510 | - global $pagenow; |
|
| 1510 | + global $pagenow; |
|
| 1511 | 1511 | |
| 1512 | - if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
| 1512 | + if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
| 1513 | 1513 | |
| 1514 | - $clauses->query_vars['post_author'] = get_current_user_id(); |
|
| 1514 | + $clauses->query_vars['post_author'] = get_current_user_id(); |
|
| 1515 | 1515 | |
| 1516 | - } |
|
| 1516 | + } |
|
| 1517 | 1517 | |
| 1518 | - return $clauses; |
|
| 1518 | + return $clauses; |
|
| 1519 | 1519 | |
| 1520 | - } // end restrict_comment_moderation() |
|
| 1520 | + } // end restrict_comment_moderation() |
|
| 1521 | 1521 | |
| 1522 | - /** |
|
| 1523 | - * Determine if a user is a teacher by ID |
|
| 1524 | - * |
|
| 1525 | - * @param int $user_id |
|
| 1526 | - * |
|
| 1527 | - * @return bool |
|
| 1528 | - */ |
|
| 1529 | - public static function is_a_teacher( $user_id ){ |
|
| 1522 | + /** |
|
| 1523 | + * Determine if a user is a teacher by ID |
|
| 1524 | + * |
|
| 1525 | + * @param int $user_id |
|
| 1526 | + * |
|
| 1527 | + * @return bool |
|
| 1528 | + */ |
|
| 1529 | + public static function is_a_teacher( $user_id ){ |
|
| 1530 | 1530 | |
| 1531 | - $user = get_user_by('id', $user_id); |
|
| 1531 | + $user = get_user_by('id', $user_id); |
|
| 1532 | 1532 | |
| 1533 | - if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
| 1533 | + if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
| 1534 | 1534 | |
| 1535 | - return true; |
|
| 1535 | + return true; |
|
| 1536 | 1536 | |
| 1537 | - }else{ |
|
| 1537 | + }else{ |
|
| 1538 | 1538 | |
| 1539 | - return false; |
|
| 1539 | + return false; |
|
| 1540 | 1540 | |
| 1541 | - } |
|
| 1541 | + } |
|
| 1542 | 1542 | |
| 1543 | - }// end is_a_teacher |
|
| 1543 | + }// end is_a_teacher |
|
| 1544 | 1544 | |
| 1545 | - /** |
|
| 1546 | - * The archive title on the teacher archive filter |
|
| 1547 | - * |
|
| 1548 | - * @since 1.9.0 |
|
| 1549 | - */ |
|
| 1550 | - public static function archive_title(){ |
|
| 1545 | + /** |
|
| 1546 | + * The archive title on the teacher archive filter |
|
| 1547 | + * |
|
| 1548 | + * @since 1.9.0 |
|
| 1549 | + */ |
|
| 1550 | + public static function archive_title(){ |
|
| 1551 | 1551 | |
| 1552 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1553 | - $author_name = $author->display_name; |
|
| 1554 | - ?> |
|
| 1552 | + $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1553 | + $author_name = $author->display_name; |
|
| 1554 | + ?> |
|
| 1555 | 1555 | <h2 class="teacher-archive-title"> |
| 1556 | 1556 | |
| 1557 | 1557 | <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
@@ -1559,17 +1559,17 @@ discard block |
||
| 1559 | 1559 | </h2> |
| 1560 | 1560 | <?php |
| 1561 | 1561 | |
| 1562 | - }// archive title |
|
| 1562 | + }// archive title |
|
| 1563 | 1563 | |
| 1564 | - /** |
|
| 1565 | - * Removing course meta on the teacher archive page |
|
| 1566 | - * |
|
| 1567 | - * @since 1.9.0 |
|
| 1568 | - */ |
|
| 1569 | - public static function remove_course_meta_on_teacher_archive(){ |
|
| 1564 | + /** |
|
| 1565 | + * Removing course meta on the teacher archive page |
|
| 1566 | + * |
|
| 1567 | + * @since 1.9.0 |
|
| 1568 | + */ |
|
| 1569 | + public static function remove_course_meta_on_teacher_archive(){ |
|
| 1570 | 1570 | |
| 1571 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
| 1571 | + remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
| 1572 | 1572 | |
| 1573 | - } |
|
| 1573 | + } |
|
| 1574 | 1574 | |
| 1575 | 1575 | } // End Class |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Teacher class |
@@ -42,58 +42,58 @@ discard block |
||
| 42 | 42 | * @since 1.8.0 |
| 43 | 43 | * @access public |
| 44 | 44 | */ |
| 45 | - public function __construct ( ) { |
|
| 45 | + public function __construct( ) { |
|
| 46 | 46 | |
| 47 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
| 48 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 49 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
| 50 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
| 51 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
| 47 | + add_action('add_meta_boxes', array($this, 'add_teacher_meta_boxes'), 10, 2); |
|
| 48 | + add_action('save_post', array($this, 'save_teacher_meta_box')); |
|
| 49 | + add_filter('parse_query', array($this, 'limit_teacher_edit_screen_post_types')); |
|
| 50 | + add_filter('pre_get_posts', array($this, 'course_analysis_teacher_access_limit')); |
|
| 51 | + add_filter('wp_count_posts', array($this, 'list_table_counts'), 10, 3); |
|
| 52 | 52 | |
| 53 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 53 | + add_action('pre_get_posts', array($this, 'filter_queries')); |
|
| 54 | 54 | |
| 55 | 55 | //filter the quiz submissions |
| 56 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 56 | + add_filter('sensei_check_for_activity', array($this, 'filter_grading_activity_queries')); |
|
| 57 | 57 | |
| 58 | 58 | //grading totals count only those belonging to the teacher |
| 59 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 59 | + add_filter('sensei_count_statuses_args', array($this, 'limit_grading_totals')); |
|
| 60 | 60 | |
| 61 | 61 | // show the courses owned by a user on his author archive page |
| 62 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
| 62 | + add_filter('pre_get_posts', array($this, 'add_courses_to_author_archive')); |
|
| 63 | 63 | |
| 64 | 64 | // notify admin when a teacher creates a course |
| 65 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 65 | + add_action('transition_post_status', array($this, 'notify_admin_teacher_course_creation'), 10, 3); |
|
| 66 | 66 | |
| 67 | 67 | // limit the analysis view to only the users taking courses belong to this teacher |
| 68 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
| 68 | + add_filter('sensei_analysis_overview_filter_users', array($this, 'limit_analysis_learners'), 5, 1); |
|
| 69 | 69 | |
| 70 | 70 | // give teacher access to question post type |
| 71 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 71 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
| 72 | 72 | |
| 73 | 73 | // Teacher column on the courses list on the admin edit screen |
| 74 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
| 75 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
| 74 | + add_filter('manage_edit-course_columns', array($this, 'course_column_heading'), 10, 1); |
|
| 75 | + add_filter('manage_course_posts_custom_column', array($this, 'course_column_data'), 10, 2); |
|
| 76 | 76 | |
| 77 | 77 | //admin edit messages query limit teacher |
| 78 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 78 | + add_filter('pre_get_posts', array($this, 'limit_edit_messages_query')); |
|
| 79 | 79 | |
| 80 | 80 | //add filter by teacher on courses list |
| 81 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
| 82 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
| 81 | + add_action('restrict_manage_posts', array($this, 'course_teacher_filter_options')); |
|
| 82 | + add_filter('request', array($this, 'teacher_filter_query_modify')); |
|
| 83 | 83 | |
| 84 | 84 | // Handle media library restrictions |
| 85 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
| 86 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
| 85 | + add_filter('request', array($this, 'restrict_media_library'), 10, 1); |
|
| 86 | + add_filter('ajax_query_attachments_args', array($this, 'restrict_media_library_modal'), 10, 1); |
|
| 87 | 87 | |
| 88 | 88 | // update lesson owner to course teacher when saved |
| 89 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 89 | + add_action('save_post', array($this, 'update_lesson_teacher')); |
|
| 90 | 90 | |
| 91 | 91 | // If a Teacher logs in, redirect to /wp-admin/ |
| 92 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 92 | + add_filter('wp_login', array($this, 'teacher_login_redirect'), 10, 2); |
|
| 93 | 93 | |
| 94 | 94 | |
| 95 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
| 96 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
| 95 | + add_action('admin_menu', array($this, 'restrict_posts_menu_page'), 10); |
|
| 96 | + add_filter('pre_get_comments', array($this, 'restrict_comment_moderation'), 10, 1); |
|
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | } // end __constructor() |
@@ -108,15 +108,15 @@ discard block |
||
| 108 | 108 | * @access public |
| 109 | 109 | * @return void |
| 110 | 110 | */ |
| 111 | - public function create_role ( ) { |
|
| 111 | + public function create_role( ) { |
|
| 112 | 112 | |
| 113 | 113 | // check if the role exists |
| 114 | - $this->teacher_role = get_role( 'teacher' ); |
|
| 114 | + $this->teacher_role = get_role('teacher'); |
|
| 115 | 115 | |
| 116 | 116 | // if the the teacher is not a valid WordPress role create it |
| 117 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 117 | + if ( ! is_a($this->teacher_role, 'WP_Role')) { |
|
| 118 | 118 | // create the role |
| 119 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 119 | + $this->teacher_role = add_role('teacher', __('Teacher', 'woothemes-sensei')); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // add the capabilities before returning |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | * @since 1.8.0 |
| 131 | 131 | * @access protected |
| 132 | 132 | */ |
| 133 | - protected function add_capabilities ( ) { |
|
| 133 | + protected function add_capabilities( ) { |
|
| 134 | 134 | |
| 135 | 135 | // if this is not a valid WP_Role object exit without adding anything |
| 136 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
| 136 | + if ( ! is_a($this->teacher_role, 'WP_Role') || empty($this->teacher_role)) { |
|
| 137 | 137 | return; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param array $capabilities |
| 145 | 145 | * keys: (string) $cap_name => (bool) $grant |
| 146 | 146 | */ |
| 147 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 147 | + $caps = apply_filters('sensei_teacher_role_capabilities', array( |
|
| 148 | 148 | // General access rules |
| 149 | 149 | 'read' => true, |
| 150 | 150 | 'manage_sensei_grades' => true, |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | )); |
| 203 | 203 | |
| 204 | - foreach ( $caps as $cap => $grant ) { |
|
| 204 | + foreach ($caps as $cap => $grant) { |
|
| 205 | 205 | |
| 206 | 206 | // load the capability on to the teacher role |
| 207 | 207 | $this->teacher_role->add_cap($cap, $grant); |
@@ -221,12 +221,12 @@ discard block |
||
| 221 | 221 | * @parameter WP_Post $post |
| 222 | 222 | * @return void |
| 223 | 223 | */ |
| 224 | - public function add_teacher_meta_boxes ( $post ) { |
|
| 224 | + public function add_teacher_meta_boxes($post) { |
|
| 225 | 225 | |
| 226 | - if( !current_user_can('manage_options') ){ |
|
| 226 | + if ( ! current_user_can('manage_options')) { |
|
| 227 | 227 | return; |
| 228 | 228 | } |
| 229 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
| 229 | + add_meta_box('sensei-teacher', __('Teacher', 'woothemes-sensei'), array($this, 'teacher_meta_box_content'), |
|
| 230 | 230 | 'course', |
| 231 | 231 | 'side', |
| 232 | 232 | 'core' |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | * @access public |
| 244 | 244 | * @parameters |
| 245 | 245 | */ |
| 246 | - public function teacher_meta_box_content ( $post ) { |
|
| 246 | + public function teacher_meta_box_content($post) { |
|
| 247 | 247 | |
| 248 | 248 | // get the current author |
| 249 | 249 | $current_author = $post->post_author; |
@@ -254,12 +254,12 @@ discard block |
||
| 254 | 254 | ?> |
| 255 | 255 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
| 256 | 256 | |
| 257 | - <?php foreach ( $users as $user_id ) { ?> |
|
| 257 | + <?php foreach ($users as $user_id) { ?> |
|
| 258 | 258 | |
| 259 | 259 | <?php |
| 260 | 260 | $user = get_user_by('id', $user_id); |
| 261 | 261 | ?> |
| 262 | - <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
|
| 262 | + <option <?php selected($current_author, $user_id, true); ?> value="<?php echo $user_id; ?>" > |
|
| 263 | 263 | <?php echo $user->display_name; ?> |
| 264 | 264 | </option> |
| 265 | 265 | |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * @parameters |
| 282 | 282 | * @return array $users user id array |
| 283 | 283 | */ |
| 284 | - public function get_teachers_and_authors ( ){ |
|
| 284 | + public function get_teachers_and_authors( ) { |
|
| 285 | 285 | |
| 286 | 286 | $author_query_args = array( |
| 287 | 287 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | 'who' => 'authors' |
| 290 | 290 | ); |
| 291 | 291 | |
| 292 | - $authors = get_users( $author_query_args ); |
|
| 292 | + $authors = get_users($author_query_args); |
|
| 293 | 293 | |
| 294 | 294 | $teacher_query_args = array( |
| 295 | 295 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -297,9 +297,9 @@ discard block |
||
| 297 | 297 | 'role' => 'teacher', |
| 298 | 298 | ); |
| 299 | 299 | |
| 300 | - $teachers = get_users( $teacher_query_args ); |
|
| 300 | + $teachers = get_users($teacher_query_args); |
|
| 301 | 301 | |
| 302 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
| 302 | + return array_unique(array_merge($teachers, $authors)); |
|
| 303 | 303 | |
| 304 | 304 | }// end get_teachers_and_authors |
| 305 | 305 | |
@@ -315,43 +315,43 @@ discard block |
||
| 315 | 315 | * @parameters |
| 316 | 316 | * @return array $users user id array |
| 317 | 317 | */ |
| 318 | - public function save_teacher_meta_box ( $course_id ){ |
|
| 318 | + public function save_teacher_meta_box($course_id) { |
|
| 319 | 319 | |
| 320 | 320 | // check if this is a post from saving the teacher, if not exit early |
| 321 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
| 321 | + if ( ! isset($_POST['sensei-course-teacher-author']) || ! isset($_POST['post_ID'])) { |
|
| 322 | 322 | return; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | //don't fire this hook again |
| 326 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 326 | + remove_action('save_post', array($this, 'save_teacher_meta_box')); |
|
| 327 | 327 | |
| 328 | 328 | // get the current post object |
| 329 | - $post = get_post( $course_id ); |
|
| 329 | + $post = get_post($course_id); |
|
| 330 | 330 | |
| 331 | 331 | // get the current teacher/author |
| 332 | - $current_author = absint( $post->post_author ); |
|
| 333 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 332 | + $current_author = absint($post->post_author); |
|
| 333 | + $new_author = absint($_POST['sensei-course-teacher-author']); |
|
| 334 | 334 | |
| 335 | 335 | // loop through all post lessons to update their authors as well |
| 336 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 336 | + $this->update_course_lessons_author($course_id, $new_author); |
|
| 337 | 337 | |
| 338 | 338 | // do not do any processing if the selected author is the same as the current author |
| 339 | - if( $current_author == $new_author ){ |
|
| 339 | + if ($current_author == $new_author) { |
|
| 340 | 340 | return; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | // save the course author |
| 344 | 344 | $post_updates = array( |
| 345 | - 'ID' => $post->ID , |
|
| 345 | + 'ID' => $post->ID, |
|
| 346 | 346 | 'post_author' => $new_author |
| 347 | 347 | ); |
| 348 | - wp_update_post( $post_updates ); |
|
| 348 | + wp_update_post($post_updates); |
|
| 349 | 349 | |
| 350 | 350 | // ensure the the modules are update so that then new teacher has access to them |
| 351 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
| 351 | + Sensei_Teacher::update_course_modules_author($course_id, $new_author); |
|
| 352 | 352 | |
| 353 | 353 | // notify the new teacher |
| 354 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 354 | + $this->teacher_course_assigned_notification($new_author, $course_id); |
|
| 355 | 355 | |
| 356 | 356 | } // end save_teacher_meta_box |
| 357 | 357 | |
@@ -365,56 +365,56 @@ discard block |
||
| 365 | 365 | * @param $new_teacher_id |
| 366 | 366 | * @return void |
| 367 | 367 | */ |
| 368 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 368 | + public static function update_course_modules_author($course_id, $new_teacher_id) { |
|
| 369 | 369 | |
| 370 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 370 | + if (empty($course_id) || empty($new_teacher_id)) { |
|
| 371 | 371 | return false; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
| 374 | + $terms_selected_on_course = wp_get_object_terms($course_id, 'module'); |
|
| 375 | 375 | |
| 376 | - if( empty( $terms_selected_on_course ) ){ |
|
| 376 | + if (empty($terms_selected_on_course)) { |
|
| 377 | 377 | return; |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - foreach( $terms_selected_on_course as $term ){ |
|
| 380 | + foreach ($terms_selected_on_course as $term) { |
|
| 381 | 381 | |
| 382 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 383 | - if( $new_teacher_id != $term_author->ID ){ |
|
| 382 | + $term_author = Sensei_Core_Modules::get_term_author($term->slug); |
|
| 383 | + if ($new_teacher_id != $term_author->ID) { |
|
| 384 | 384 | |
| 385 | 385 | $new_term = ''; |
| 386 | 386 | |
| 387 | 387 | //if the new teacher is admin first check to see if the term with this name already exists |
| 388 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
| 388 | + if (user_can($new_teacher_id, 'manage_options')) { |
|
| 389 | 389 | |
| 390 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 391 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
| 392 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
| 393 | - if( !empty( $existing_admin_terms ) ){ |
|
| 390 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim($term->name)); |
|
| 391 | + $term_args = array('slug'=> $slug_without_teacher_id, 'hide_empty' => false,); |
|
| 392 | + $existing_admin_terms = get_terms('module', $term_args); |
|
| 393 | + if ( ! empty($existing_admin_terms)) { |
|
| 394 | 394 | // insert it even if it exists |
| 395 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 395 | + $new_term = get_term($existing_admin_terms[0]->term_id, 'module', ARRAY_A); |
|
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - if( empty ( $new_term ) ){ |
|
| 399 | + if (empty ($new_term)) { |
|
| 400 | 400 | |
| 401 | 401 | //setup the new slug |
| 402 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 402 | + $new_author_term_slug = $new_teacher_id.'-'.str_ireplace(' ', '-', trim($term->name)); |
|
| 403 | 403 | |
| 404 | 404 | // create new term and set it |
| 405 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 405 | + $new_term = wp_insert_term($term->name, 'module', array('slug'=> $new_author_term_slug)); |
|
| 406 | 406 | |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | |
| 410 | 410 | |
| 411 | 411 | // if term exists |
| 412 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 412 | + if (is_wp_error($new_term) && isset($new_term->errors['term_exists'])) { |
|
| 413 | 413 | |
| 414 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 414 | + $existing_term = get_term_by('slug', $new_author_term_slug, 'module'); |
|
| 415 | 415 | $term_id = $existing_term->term_id; |
| 416 | 416 | |
| 417 | - }else{ |
|
| 417 | + } else { |
|
| 418 | 418 | |
| 419 | 419 | // for a new term simply get the term from the returned value |
| 420 | 420 | $term_id = $new_term['term_id']; |
@@ -422,21 +422,21 @@ discard block |
||
| 422 | 422 | } // end if term exist |
| 423 | 423 | |
| 424 | 424 | // set the terms selected on the course |
| 425 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 425 | + wp_set_object_terms($course_id, $term_id, 'module', true); |
|
| 426 | 426 | |
| 427 | 427 | // remove old term |
| 428 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 428 | + wp_remove_object_terms($course_id, $term->term_id, 'module'); |
|
| 429 | 429 | |
| 430 | 430 | // update the lessons within the current module term |
| 431 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 432 | - foreach( $lessons as $lesson ){ |
|
| 431 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 432 | + foreach ($lessons as $lesson) { |
|
| 433 | 433 | |
| 434 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
| 434 | + if (has_term($term->slug, 'module', $lesson)) { |
|
| 435 | 435 | |
| 436 | 436 | // add the new term, the false at the end says to replace all terms on this module |
| 437 | 437 | // with the new term. |
| 438 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
| 439 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
| 438 | + wp_set_object_terms($lesson->ID, $term_id, 'module', false); |
|
| 439 | + update_post_meta($lesson->ID, '_order_module_'.intval($term_id), 0); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | }// end for each |
@@ -456,50 +456,50 @@ discard block |
||
| 456 | 456 | * @parameters |
| 457 | 457 | * @return array $users user id array |
| 458 | 458 | */ |
| 459 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 459 | + public function update_course_lessons_author($course_id, $new_author) { |
|
| 460 | 460 | |
| 461 | 461 | |
| 462 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 462 | + if (empty($course_id) || empty($new_author)) { |
|
| 463 | 463 | return false; |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | //get a list of course lessons |
| 467 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 467 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 468 | 468 | |
| 469 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 469 | + if (empty($lessons) || ! is_array($lessons)) { |
|
| 470 | 470 | return false; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | // update each lesson and quiz author |
| 474 | - foreach( $lessons as $lesson ){ |
|
| 474 | + foreach ($lessons as $lesson) { |
|
| 475 | 475 | |
| 476 | 476 | // don't update if the author is tha same as the new author |
| 477 | - if( $new_author == $lesson->post_author ){ |
|
| 477 | + if ($new_author == $lesson->post_author) { |
|
| 478 | 478 | continue; |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | // update lesson author |
| 482 | - wp_update_post( array( |
|
| 482 | + wp_update_post(array( |
|
| 483 | 483 | 'ID'=> $lesson->ID, |
| 484 | 484 | 'post_author' => $new_author |
| 485 | - ) ); |
|
| 485 | + )); |
|
| 486 | 486 | |
| 487 | 487 | // update quiz author |
| 488 | 488 | //get the lessons quiz |
| 489 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 490 | - if( is_array( $lesson_quizzes ) ){ |
|
| 491 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
| 489 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
| 490 | + if (is_array($lesson_quizzes)) { |
|
| 491 | + foreach ($lesson_quizzes as $quiz_id) { |
|
| 492 | 492 | // update quiz with new author |
| 493 | - wp_update_post( array( |
|
| 493 | + wp_update_post(array( |
|
| 494 | 494 | 'ID' => $quiz_id, |
| 495 | 495 | 'post_author' => $new_author |
| 496 | - ) ); |
|
| 496 | + )); |
|
| 497 | 497 | } |
| 498 | - }else{ |
|
| 499 | - wp_update_post( array( |
|
| 498 | + } else { |
|
| 499 | + wp_update_post(array( |
|
| 500 | 500 | 'ID' => $lesson_quizzes, |
| 501 | 501 | 'post_author' => $new_author |
| 502 | - ) ); |
|
| 502 | + )); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | } // end for each lessons |
@@ -520,30 +520,30 @@ discard block |
||
| 520 | 520 | * @parameters $query |
| 521 | 521 | * @return array $users user id array |
| 522 | 522 | */ |
| 523 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
| 523 | + public function course_analysis_teacher_access_limit($query) { |
|
| 524 | 524 | |
| 525 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 525 | + if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 526 | 526 | return $query; |
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 529 | + if ( ! function_exists('get_current_screen')) { |
|
| 530 | 530 | return $query; |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | $screen = get_current_screen(); |
| 534 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 534 | + $sensei_post_types = array('course', 'lesson', 'question'); |
|
| 535 | 535 | |
| 536 | 536 | // exit early for the following conditions |
| 537 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 537 | + $limit_screen_ids = array('sensei_page_sensei_analysis', 'course_page_module-order'); |
|
| 538 | 538 | |
| 539 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
| 540 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
| 539 | + if ( ! $this->is_admin_teacher() || empty($screen) || ! in_array($screen->id, $limit_screen_ids) |
|
| 540 | + || ! in_array($query->query['post_type'], $sensei_post_types)) { |
|
| 541 | 541 | return $query; |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | global $current_user; |
| 545 | 545 | // set the query author to the current user to only show those those posts |
| 546 | - $query->set( 'author', $current_user->ID ); |
|
| 546 | + $query->set('author', $current_user->ID); |
|
| 547 | 547 | return $query; |
| 548 | 548 | |
| 549 | 549 | }// end course_analysis_teacher_access_limit |
@@ -559,14 +559,14 @@ discard block |
||
| 559 | 559 | * @parameters array $wp_query |
| 560 | 560 | * @return bool $is_admin_teacher |
| 561 | 561 | */ |
| 562 | - public function is_admin_teacher ( ){ |
|
| 562 | + public function is_admin_teacher( ) { |
|
| 563 | 563 | |
| 564 | - if( ! is_user_logged_in()){ |
|
| 564 | + if ( ! is_user_logged_in()) { |
|
| 565 | 565 | return false; |
| 566 | 566 | } |
| 567 | 567 | $is_admin_teacher = false; |
| 568 | 568 | |
| 569 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 569 | + if (is_admin() && Sensei_Teacher::is_a_teacher(get_current_user_id())) { |
|
| 570 | 570 | |
| 571 | 571 | $is_admin_teacher = true; |
| 572 | 572 | |
@@ -586,14 +586,14 @@ discard block |
||
| 586 | 586 | * @param string $perm User permission level |
| 587 | 587 | * @return object Modified status counts |
| 588 | 588 | */ |
| 589 | - public function list_table_counts( $counts, $type, $perm ) { |
|
| 589 | + public function list_table_counts($counts, $type, $perm) { |
|
| 590 | 590 | global $current_user; |
| 591 | 591 | |
| 592 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 592 | + if ( ! in_array($type, array('course', 'lesson', 'question'))) { |
|
| 593 | 593 | return $counts; |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - if( ! $this->is_admin_teacher() ) { |
|
| 596 | + if ( ! $this->is_admin_teacher()) { |
|
| 597 | 597 | return $counts; |
| 598 | 598 | } |
| 599 | 599 | |
@@ -607,10 +607,10 @@ discard block |
||
| 607 | 607 | $stati = get_post_stati(); |
| 608 | 608 | |
| 609 | 609 | // Update count object |
| 610 | - foreach( $stati as $status ) { |
|
| 610 | + foreach ($stati as $status) { |
|
| 611 | 611 | $args['post_status'] = $status; |
| 612 | - $posts = get_posts( $args ); |
|
| 613 | - $counts->$status = count( $posts ); |
|
| 612 | + $posts = get_posts($args); |
|
| 613 | + $counts->$status = count($posts); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | return $counts; |
@@ -624,22 +624,22 @@ discard block |
||
| 624 | 624 | * @since 1.8.0 |
| 625 | 625 | * |
| 626 | 626 | */ |
| 627 | - public function filter_queries ( $query ) { |
|
| 627 | + public function filter_queries($query) { |
|
| 628 | 628 | global $current_user; |
| 629 | 629 | |
| 630 | - if( ! $this->is_admin_teacher() ) { |
|
| 630 | + if ( ! $this->is_admin_teacher()) { |
|
| 631 | 631 | return; |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 634 | + if ( ! function_exists('get_current_screen')) { |
|
| 635 | 635 | return; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | $screen = get_current_screen(); |
| 639 | - if( empty( $screen ) ) { |
|
| 639 | + if (empty($screen)) { |
|
| 640 | 640 | return $query; |
| 641 | 641 | } |
| 642 | - switch( $screen->id ) { |
|
| 642 | + switch ($screen->id) { |
|
| 643 | 643 | case 'sensei_page_sensei_grading': |
| 644 | 644 | case 'sensei_page_sensei_analysis': |
| 645 | 645 | case 'sensei_page_sensei_learners': |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | * @param string $screen_id |
| 659 | 659 | * |
| 660 | 660 | */ |
| 661 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 661 | + $query->set('author', apply_filters('sensei_filter_queries_set_author', $current_user->ID, $screen->id)); |
|
| 662 | 662 | break; |
| 663 | 663 | } |
| 664 | 664 | } |
@@ -673,31 +673,31 @@ discard block |
||
| 673 | 673 | * |
| 674 | 674 | * @return array $comments |
| 675 | 675 | */ |
| 676 | - public function filter_grading_activity_queries( $comments ){ |
|
| 676 | + public function filter_grading_activity_queries($comments) { |
|
| 677 | 677 | |
| 678 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 679 | - return $comments ; |
|
| 678 | + if ( ! is_admin() || ! $this->is_admin_teacher() || is_numeric($comments) || ! is_array($comments)) { |
|
| 679 | + return $comments; |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | //check if we're on the grading screen |
| 683 | 683 | $screen = get_current_screen(); |
| 684 | 684 | |
| 685 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 685 | + if (empty($screen) || 'sensei_page_sensei_grading' != $screen->id) { |
|
| 686 | 686 | return $comments; |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | // get the course and determine if the current teacher is the owner |
| 690 | 690 | // if not remove it from the list of comments to be returned |
| 691 | - foreach( $comments as $key => $comment){ |
|
| 692 | - $lesson = get_post( $comment->comment_post_ID ); |
|
| 693 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
| 694 | - $course = get_post( $course_id ); |
|
| 695 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
| 691 | + foreach ($comments as $key => $comment) { |
|
| 692 | + $lesson = get_post($comment->comment_post_ID); |
|
| 693 | + $course_id = Sensei()->lesson->get_course_id($lesson->ID); |
|
| 694 | + $course = get_post($course_id); |
|
| 695 | + if ( ! isset($course->post_author) || intval($course->post_author) != intval(get_current_user_id())) { |
|
| 696 | 696 | //remove this as the teacher should see this. |
| 697 | - unset( $comments[ $key ] ); |
|
| 697 | + unset($comments[$key]); |
|
| 698 | 698 | } |
| 699 | 699 | } |
| 700 | - return $comments ; |
|
| 700 | + return $comments; |
|
| 701 | 701 | |
| 702 | 702 | }// end function filter grading |
| 703 | 703 | |
@@ -713,34 +713,34 @@ discard block |
||
| 713 | 713 | * |
| 714 | 714 | * @return array $args |
| 715 | 715 | */ |
| 716 | - public function limit_grading_totals( $args ){ |
|
| 716 | + public function limit_grading_totals($args) { |
|
| 717 | 717 | |
| 718 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 719 | - return $args ; |
|
| 718 | + if ( ! is_admin() || ! $this->is_admin_teacher() || ! is_array($args)) { |
|
| 719 | + return $args; |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | //get the teachers courses |
| 723 | 723 | // the query is already filtered to only the teacher |
| 724 | - $courses = Sensei()->course->get_all_courses(); |
|
| 724 | + $courses = Sensei()->course->get_all_courses(); |
|
| 725 | 725 | |
| 726 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 726 | + if (empty($courses) || ! is_array($courses)) { |
|
| 727 | 727 | return $args; |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | //setup the lessons quizzes to limit the grading totals to |
| 731 | 731 | $quiz_scope = array(); |
| 732 | - foreach( $courses as $course ){ |
|
| 732 | + foreach ($courses as $course) { |
|
| 733 | 733 | |
| 734 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 734 | + $course_lessons = Sensei()->course->course_lessons($course->ID); |
|
| 735 | 735 | |
| 736 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 736 | + if ( ! empty($course_lessons) && is_array($course_lessons)) { |
|
| 737 | 737 | |
| 738 | - foreach( $course_lessons as $lesson ){ |
|
| 738 | + foreach ($course_lessons as $lesson) { |
|
| 739 | 739 | |
| 740 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 741 | - if( !empty( $quiz_id ) ) { |
|
| 740 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
| 741 | + if ( ! empty($quiz_id)) { |
|
| 742 | 742 | |
| 743 | - array_push( $quiz_scope, $quiz_id ); |
|
| 743 | + array_push($quiz_scope, $quiz_id); |
|
| 744 | 744 | |
| 745 | 745 | } |
| 746 | 746 | |
@@ -763,41 +763,41 @@ discard block |
||
| 763 | 763 | * @param WP_Query $query |
| 764 | 764 | * @return WP_Query $query |
| 765 | 765 | */ |
| 766 | - public function add_courses_to_author_archive( $query ) { |
|
| 766 | + public function add_courses_to_author_archive($query) { |
|
| 767 | 767 | |
| 768 | - if ( is_admin() || ! $query->is_author() ){ |
|
| 768 | + if (is_admin() || ! $query->is_author()) { |
|
| 769 | 769 | return $query; |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | // this should only apply to users with the teacher role |
| 773 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
| 774 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
| 773 | + $current_page_user = get_user_by('login', $query->get('author_name')); |
|
| 774 | + if ( ! $current_page_user || ! in_array('teacher', $current_page_user->roles)) { |
|
| 775 | 775 | |
| 776 | 776 | return $query; |
| 777 | 777 | |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | // Change post types depending on what is set already |
| 781 | - $current_post_types = $query->get( 'post_type' ); |
|
| 782 | - if( empty( $current_post_types ) ){ |
|
| 781 | + $current_post_types = $query->get('post_type'); |
|
| 782 | + if (empty($current_post_types)) { |
|
| 783 | 783 | |
| 784 | 784 | // if empty it means post by default, so add post so that it also includes that for now |
| 785 | - $new_post_types = array( 'post', 'course' ); |
|
| 785 | + $new_post_types = array('post', 'course'); |
|
| 786 | 786 | |
| 787 | - } elseif( is_array( $current_post_types ) ) { |
|
| 787 | + } elseif (is_array($current_post_types)) { |
|
| 788 | 788 | |
| 789 | 789 | // merge the post types instead of overwriting it |
| 790 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 790 | + $new_post_types = array_merge($current_post_types, array('course')); |
|
| 791 | 791 | |
| 792 | - }else{ |
|
| 792 | + } else { |
|
| 793 | 793 | |
| 794 | 794 | // in this instance it is probably just one post type in string format |
| 795 | - $new_post_types = array( $current_post_types , 'course'); |
|
| 795 | + $new_post_types = array($current_post_types, 'course'); |
|
| 796 | 796 | |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | // change the query before returning it |
| 800 | - $query->set('post_type', $new_post_types ); |
|
| 800 | + $query->set('post_type', $new_post_types); |
|
| 801 | 801 | |
| 802 | 802 | /** |
| 803 | 803 | * Change the query on the teacher author archive template |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | * @since 1.8.4 |
| 806 | 806 | * @param WP_Query $query |
| 807 | 807 | */ |
| 808 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 808 | + return apply_filters('sensei_teacher_archive_query', $query); |
|
| 809 | 809 | |
| 810 | 810 | } |
| 811 | 811 | |
@@ -818,21 +818,21 @@ discard block |
||
| 818 | 818 | * @param $course_id |
| 819 | 819 | * @return bool |
| 820 | 820 | */ |
| 821 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 821 | + public function teacher_course_assigned_notification($teacher_id, $course_id) { |
|
| 822 | 822 | |
| 823 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 823 | + if ('course' != get_post_type($course_id) || ! get_userdata($teacher_id)) { |
|
| 824 | 824 | return false; |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | // if new user is the same as the current logged user, they don't need an email |
| 828 | - if( $teacher_id == get_current_user_id() ){ |
|
| 828 | + if ($teacher_id == get_current_user_id()) { |
|
| 829 | 829 | return true; |
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | // load the email class |
| 833 | 833 | include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
| 834 | 834 | $email = new Teacher_New_Course_Assignment(); |
| 835 | - $email->trigger( $teacher_id, $course_id ); |
|
| 835 | + $email->trigger($teacher_id, $course_id); |
|
| 836 | 836 | |
| 837 | 837 | return true; |
| 838 | 838 | } // end teacher_course_assigned_notification |
@@ -846,12 +846,12 @@ discard block |
||
| 846 | 846 | * @param int $course_id |
| 847 | 847 | * @return bool |
| 848 | 848 | */ |
| 849 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 849 | + public function notify_admin_teacher_course_creation($new_status, $old_status, $post) { |
|
| 850 | 850 | |
| 851 | 851 | $course_id = $post->ID; |
| 852 | 852 | |
| 853 | - if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
| 854 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
| 853 | + if ('course' != get_post_type($course_id) || 'auto-draft' == get_post_status($course_id) |
|
| 854 | + || 'trash' == get_post_status($course_id) || 'draft' == get_post_status($course_id)) { |
|
| 855 | 855 | |
| 856 | 856 | return false; |
| 857 | 857 | |
@@ -865,19 +865,19 @@ discard block |
||
| 865 | 865 | * |
| 866 | 866 | * @param bool $on default true |
| 867 | 867 | */ |
| 868 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 868 | + if ( ! apply_filters('sensei_notify_admin_new_course_creation', true)) { |
|
| 869 | 869 | return false; |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | // setting up the data needed by the email template |
| 873 | 873 | global $sensei_email_data; |
| 874 | 874 | $template = 'admin-teacher-new-course-created'; |
| 875 | - $course = get_post( $course_id ); |
|
| 876 | - $teacher = new WP_User( $course->post_author ); |
|
| 875 | + $course = get_post($course_id); |
|
| 876 | + $teacher = new WP_User($course->post_author); |
|
| 877 | 877 | $recipient = get_option('admin_email', true); |
| 878 | 878 | |
| 879 | 879 | // don't send if the course is created by admin |
| 880 | - if( $recipient == $teacher->user_email ){ |
|
| 880 | + if ($recipient == $teacher->user_email) { |
|
| 881 | 881 | return; |
| 882 | 882 | } |
| 883 | 883 | |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | * @since 1.8.0 |
| 888 | 888 | * @param string $template |
| 889 | 889 | */ |
| 890 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 890 | + $heading = apply_filters('sensei_email_heading', __('New course created.', 'woothemes-sensei'), $template); |
|
| 891 | 891 | |
| 892 | 892 | /** |
| 893 | 893 | * Filter the email subject for the the |
@@ -898,11 +898,11 @@ discard block |
||
| 898 | 898 | * @param string $template |
| 899 | 899 | */ |
| 900 | 900 | $subject = apply_filters('sensei_email_subject', |
| 901 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 902 | - $template ); |
|
| 901 | + '['.get_bloginfo('name', 'display').'] '.__('New course created by', 'woothemes-sensei').' '.$teacher->display_name, |
|
| 902 | + $template); |
|
| 903 | 903 | |
| 904 | 904 | //course edit link |
| 905 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 905 | + $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit'); |
|
| 906 | 906 | |
| 907 | 907 | // Construct data array |
| 908 | 908 | $email_data = array( |
@@ -921,10 +921,10 @@ discard block |
||
| 921 | 921 | * @param array $email_data |
| 922 | 922 | * @param string $template |
| 923 | 923 | */ |
| 924 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 924 | + $sensei_email_data = apply_filters('sensei_email_data', $email_data, $template); |
|
| 925 | 925 | |
| 926 | 926 | // Send mail |
| 927 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 927 | + Sensei()->emails->send($recipient, $subject, Sensei()->emails->get_content($template)); |
|
| 928 | 928 | |
| 929 | 929 | }// end notify admin of course creation |
| 930 | 930 | |
@@ -935,10 +935,10 @@ discard block |
||
| 935 | 935 | * @param array $args WP_User_Query arguments |
| 936 | 936 | * @return array $learners_query_results |
| 937 | 937 | */ |
| 938 | - public function limit_analysis_learners( $args ){ |
|
| 938 | + public function limit_analysis_learners($args) { |
|
| 939 | 939 | |
| 940 | 940 | // show default for none teachers |
| 941 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 941 | + if ( ! Sensei()->teacher->is_admin_teacher()) { |
|
| 942 | 942 | return $args; |
| 943 | 943 | } |
| 944 | 944 | |
@@ -947,31 +947,31 @@ discard block |
||
| 947 | 947 | $teacher_courses = Sensei()->course->get_all_courses(); |
| 948 | 948 | |
| 949 | 949 | // if the user has no courses they should see no users |
| 950 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 950 | + if (empty($teacher_courses) || ! is_array($teacher_courses)) { |
|
| 951 | 951 | // tell the query to return 0 students |
| 952 | - $args[ 'include'] = array( 0 ); |
|
| 952 | + $args['include'] = array(0); |
|
| 953 | 953 | return $args; |
| 954 | 954 | |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | 957 | $learner_ids_for_teacher_courses = array(); |
| 958 | - foreach( $teacher_courses as $course ){ |
|
| 958 | + foreach ($teacher_courses as $course) { |
|
| 959 | 959 | |
| 960 | 960 | $course_learner_ids = array(); |
| 961 | - $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
| 961 | + $activity_comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id'), true); |
|
| 962 | 962 | |
| 963 | - if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 963 | + if (empty($activity_comments) || (is_array($activity_comments) && ! (count($activity_comments) > 0))) { |
|
| 964 | 964 | continue; // skip to the next course as there are no users on this course |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | // it could be an array of comments or a single comment |
| 968 | - if( is_array( $activity_comments ) ){ |
|
| 968 | + if (is_array($activity_comments)) { |
|
| 969 | 969 | |
| 970 | - foreach( $activity_comments as $comment ){ |
|
| 970 | + foreach ($activity_comments as $comment) { |
|
| 971 | 971 | |
| 972 | - $user = get_userdata( $comment->user_id ); |
|
| 972 | + $user = get_userdata($comment->user_id); |
|
| 973 | 973 | |
| 974 | - if( empty( $user ) ){ |
|
| 974 | + if (empty($user)) { |
|
| 975 | 975 | // next comment in this array |
| 976 | 976 | continue; |
| 977 | 977 | } |
@@ -979,26 +979,26 @@ discard block |
||
| 979 | 979 | $course_learner_ids[] = $user->ID; |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | - }else{ |
|
| 982 | + } else { |
|
| 983 | 983 | |
| 984 | - $user = get_userdata( $activity_comments->user_id ); |
|
| 984 | + $user = get_userdata($activity_comments->user_id); |
|
| 985 | 985 | $course_learner_ids[] = $user->ID; |
| 986 | 986 | |
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | // add learners on this course to the all courses learner list |
| 990 | - $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
| 990 | + $learner_ids_for_teacher_courses = array_merge($learner_ids_for_teacher_courses, $course_learner_ids); |
|
| 991 | 991 | |
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | // if there are no students taking the courses by this teacher don't show them any of the other users |
| 995 | - if( empty( $learner_ids_for_teacher_courses ) ){ |
|
| 995 | + if (empty($learner_ids_for_teacher_courses)) { |
|
| 996 | 996 | |
| 997 | - $args[ 'include'] = array( 0 ); |
|
| 997 | + $args['include'] = array(0); |
|
| 998 | 998 | |
| 999 | - }else{ |
|
| 999 | + } else { |
|
| 1000 | 1000 | |
| 1001 | - $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
| 1001 | + $args['include'] = $learner_ids_for_teacher_courses; |
|
| 1002 | 1002 | |
| 1003 | 1003 | } |
| 1004 | 1004 | |
@@ -1015,35 +1015,35 @@ discard block |
||
| 1015 | 1015 | * @param $questions |
| 1016 | 1016 | * @return mixed |
| 1017 | 1017 | */ |
| 1018 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1018 | + public function allow_teacher_access_to_questions($questions, $quiz_id) { |
|
| 1019 | 1019 | |
| 1020 | - if( ! $this->is_admin_teacher() ){ |
|
| 1020 | + if ( ! $this->is_admin_teacher()) { |
|
| 1021 | 1021 | return $questions; |
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | $screen = get_current_screen(); |
| 1025 | 1025 | |
| 1026 | 1026 | // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
| 1027 | - remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
| 1027 | + remove_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20); |
|
| 1028 | 1028 | |
| 1029 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1029 | + if ( ! empty($screen) && 'lesson' == $screen->post_type) { |
|
| 1030 | 1030 | |
| 1031 | 1031 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
| 1032 | - if( ! empty($admin_user) ){ |
|
| 1032 | + if ( ! empty($admin_user)) { |
|
| 1033 | 1033 | |
| 1034 | 1034 | $current_teacher_id = get_current_user_id(); |
| 1035 | 1035 | |
| 1036 | 1036 | // set current user to admin so teacher can view all questions |
| 1037 | - wp_set_current_user( $admin_user->ID ); |
|
| 1038 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 1037 | + wp_set_current_user($admin_user->ID); |
|
| 1038 | + $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id); |
|
| 1039 | 1039 | |
| 1040 | 1040 | // set the teacher as the current use again |
| 1041 | - wp_set_current_user( $current_teacher_id ); |
|
| 1041 | + wp_set_current_user($current_teacher_id); |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | } |
| 1045 | 1045 | // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
| 1046 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
| 1046 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
| 1047 | 1047 | |
| 1048 | 1048 | return $questions; |
| 1049 | 1049 | } |
@@ -1055,30 +1055,30 @@ discard block |
||
| 1055 | 1055 | * @param $wp_query |
| 1056 | 1056 | * @return mixed |
| 1057 | 1057 | */ |
| 1058 | - public function give_access_to_all_questions( $wp_query ){ |
|
| 1058 | + public function give_access_to_all_questions($wp_query) { |
|
| 1059 | 1059 | |
| 1060 | - if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
| 1060 | + if ( ! $this->is_admin_teacher() || ! function_exists('get_current_screen') || 'question' != $wp_query->get('post_type')) { |
|
| 1061 | 1061 | |
| 1062 | 1062 | return $wp_query; |
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | $screen = get_current_screen(); |
| 1066 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1067 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1066 | + if ((isset($screen->id) && 'lesson' == $screen->id) |
|
| 1067 | + || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 1068 | 1068 | |
| 1069 | 1069 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
| 1070 | - if( ! empty($admin_user) ){ |
|
| 1070 | + if ( ! empty($admin_user)) { |
|
| 1071 | 1071 | |
| 1072 | 1072 | $current_teacher_id = get_current_user_id(); |
| 1073 | 1073 | |
| 1074 | 1074 | // set current user to admin so teacher can view all questions |
| 1075 | - wp_set_current_user( $admin_user->ID ); |
|
| 1075 | + wp_set_current_user($admin_user->ID); |
|
| 1076 | 1076 | |
| 1077 | 1077 | //run new query as admin |
| 1078 | - $wp_query = new WP_Query( $wp_query->query ); |
|
| 1078 | + $wp_query = new WP_Query($wp_query->query); |
|
| 1079 | 1079 | |
| 1080 | 1080 | //set the teache as current use again |
| 1081 | - wp_set_current_user( $current_teacher_id ); |
|
| 1081 | + wp_set_current_user($current_teacher_id); |
|
| 1082 | 1082 | |
| 1083 | 1083 | } |
| 1084 | 1084 | } |
@@ -1095,7 +1095,7 @@ discard block |
||
| 1095 | 1095 | */ |
| 1096 | 1096 | public function course_column_heading($columns) { |
| 1097 | 1097 | |
| 1098 | - if( $this->is_admin_teacher() ){ |
|
| 1098 | + if ($this->is_admin_teacher()) { |
|
| 1099 | 1099 | return $columns; |
| 1100 | 1100 | } |
| 1101 | 1101 | $new_columns = array( |
@@ -1112,20 +1112,20 @@ discard block |
||
| 1112 | 1112 | * @param $column |
| 1113 | 1113 | * @param $course_id |
| 1114 | 1114 | */ |
| 1115 | - public function course_column_data( $column, $course_id ){ |
|
| 1115 | + public function course_column_data($column, $course_id) { |
|
| 1116 | 1116 | |
| 1117 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1117 | + if ($this->is_admin_teacher() || 'teacher' != $column) { |
|
| 1118 | 1118 | return; |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | - $course = get_post( $course_id ); |
|
| 1122 | - $teacher = get_userdata( $course->post_author ); |
|
| 1121 | + $course = get_post($course_id); |
|
| 1122 | + $teacher = get_userdata($course->post_author); |
|
| 1123 | 1123 | |
| 1124 | - if( !$teacher ){ |
|
| 1124 | + if ( ! $teacher) { |
|
| 1125 | 1125 | return; |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | - echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
| 1128 | + echo '<a href="'.get_edit_user_link($teacher->ID).'" >'.$teacher->display_name.'</a>'; |
|
| 1129 | 1129 | |
| 1130 | 1130 | }// end course_column_ data |
| 1131 | 1131 | |
@@ -1140,31 +1140,31 @@ discard block |
||
| 1140 | 1140 | * |
| 1141 | 1141 | * @return array $teachers_courses |
| 1142 | 1142 | */ |
| 1143 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1143 | + public function get_teacher_courses($teacher_id, $return_ids_only = false) { |
|
| 1144 | 1144 | |
| 1145 | 1145 | $teachers_courses = array(); |
| 1146 | 1146 | |
| 1147 | - if( empty( $teacher_id ) ){ |
|
| 1147 | + if (empty($teacher_id)) { |
|
| 1148 | 1148 | $teacher_id = get_current_user_id(); |
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | $all_courses = Sensei()->course->get_all_courses(); |
| 1152 | 1152 | |
| 1153 | - if( empty( $all_courses ) ){ |
|
| 1153 | + if (empty($all_courses)) { |
|
| 1154 | 1154 | return $all_courses; |
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | - foreach( $all_courses as $course ){ |
|
| 1157 | + foreach ($all_courses as $course) { |
|
| 1158 | 1158 | |
| 1159 | - if( $course->post_author != $teacher_id ){ |
|
| 1159 | + if ($course->post_author != $teacher_id) { |
|
| 1160 | 1160 | continue; |
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | - if( $return_ids_only ){ |
|
| 1163 | + if ($return_ids_only) { |
|
| 1164 | 1164 | |
| 1165 | 1165 | $teachers_courses[] = $course->ID; |
| 1166 | 1166 | |
| 1167 | - }else{ |
|
| 1167 | + } else { |
|
| 1168 | 1168 | |
| 1169 | 1169 | $teachers_courses[] = $course; |
| 1170 | 1170 | |
@@ -1184,21 +1184,21 @@ discard block |
||
| 1184 | 1184 | * @param $query |
| 1185 | 1185 | * @return mixed |
| 1186 | 1186 | */ |
| 1187 | - public function limit_edit_messages_query( $query ){ |
|
| 1188 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1187 | + public function limit_edit_messages_query($query) { |
|
| 1188 | + if ( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type')) { |
|
| 1189 | 1189 | return $query; |
| 1190 | 1190 | } |
| 1191 | 1191 | |
| 1192 | 1192 | $teacher = wp_get_current_user(); |
| 1193 | 1193 | |
| 1194 | - $query->set( 'meta_key', '_receiver' ); |
|
| 1194 | + $query->set('meta_key', '_receiver'); |
|
| 1195 | 1195 | $meta_query_args = array( |
| 1196 | 1196 | 'key' => '_receiver', |
| 1197 | - 'value' => $teacher->get('user_login') , |
|
| 1197 | + 'value' => $teacher->get('user_login'), |
|
| 1198 | 1198 | 'compare' => '=' |
| 1199 | 1199 | ); |
| 1200 | 1200 | |
| 1201 | - $query->set('meta_query', $meta_query_args ); |
|
| 1201 | + $query->set('meta_query', $meta_query_args); |
|
| 1202 | 1202 | |
| 1203 | 1203 | return $query; |
| 1204 | 1204 | } |
@@ -1214,7 +1214,7 @@ discard block |
||
| 1214 | 1214 | public function course_teacher_filter_options() { |
| 1215 | 1215 | global $typenow; |
| 1216 | 1216 | |
| 1217 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1217 | + if ( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
| 1218 | 1218 | return; |
| 1219 | 1219 | } |
| 1220 | 1220 | |
@@ -1224,31 +1224,31 @@ discard block |
||
| 1224 | 1224 | // get roles with the course edit capability |
| 1225 | 1225 | // and then get the users with those roles |
| 1226 | 1226 | $users_who_can_edit_courses = array(); |
| 1227 | - foreach( $roles as $role_item ){ |
|
| 1227 | + foreach ($roles as $role_item) { |
|
| 1228 | 1228 | |
| 1229 | - $role = get_role( strtolower( $role_item['name'] ) ); |
|
| 1229 | + $role = get_role(strtolower($role_item['name'])); |
|
| 1230 | 1230 | |
| 1231 | - if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
| 1231 | + if (is_a($role, 'WP_Role') && $role->has_cap('edit_courses')) { |
|
| 1232 | 1232 | |
| 1233 | - $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
| 1234 | - $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
| 1233 | + $user_query_args = array('role' => $role->name, 'fields' => array('ID', 'display_name')); |
|
| 1234 | + $role_users_who_can_edit_courses = get_users($user_query_args); |
|
| 1235 | 1235 | |
| 1236 | 1236 | // add user from the current $user_role to all users |
| 1237 | - $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
| 1237 | + $users_who_can_edit_courses = array_merge($users_who_can_edit_courses, $role_users_who_can_edit_courses); |
|
| 1238 | 1238 | |
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | 1243 | // Create the select element with the given users who can edit course |
| 1244 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1244 | + $selected = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
| 1245 | 1245 | $course_options = ''; |
| 1246 | - foreach( $users_who_can_edit_courses as $user ) { |
|
| 1247 | - $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
| 1246 | + foreach ($users_who_can_edit_courses as $user) { |
|
| 1247 | + $course_options .= '<option value="'.esc_attr($user->ID).'" '.selected($selected, $user->ID, false).'>'.$user->display_name.'</option>'; |
|
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | 1250 | $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
| 1251 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1251 | + $output .= '<option value="">'.__('Show all teachers', 'woothemes-sensei').'</option>'; |
|
| 1252 | 1252 | $output .= $course_options; |
| 1253 | 1253 | $output .= '</select>'; |
| 1254 | 1254 | |
@@ -1263,15 +1263,15 @@ discard block |
||
| 1263 | 1263 | * @param $query |
| 1264 | 1264 | * @return $query |
| 1265 | 1265 | */ |
| 1266 | - public function teacher_filter_query_modify( $query ){ |
|
| 1266 | + public function teacher_filter_query_modify($query) { |
|
| 1267 | 1267 | global $typenow; |
| 1268 | 1268 | |
| 1269 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1269 | + if ( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
| 1270 | 1270 | return $query; |
| 1271 | 1271 | } |
| 1272 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1272 | + $course_teacher = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
| 1273 | 1273 | |
| 1274 | - if( empty( $course_teacher ) ) { |
|
| 1274 | + if (empty($course_teacher)) { |
|
| 1275 | 1275 | return $query; |
| 1276 | 1276 | } |
| 1277 | 1277 | |
@@ -1284,23 +1284,23 @@ discard block |
||
| 1284 | 1284 | * @param array $request Default request arguments |
| 1285 | 1285 | * @return array Modified request arguments |
| 1286 | 1286 | */ |
| 1287 | - public function restrict_media_library( $request = array() ) { |
|
| 1287 | + public function restrict_media_library($request = array()) { |
|
| 1288 | 1288 | |
| 1289 | - if( ! is_admin() ) { |
|
| 1289 | + if ( ! is_admin()) { |
|
| 1290 | 1290 | return $request; |
| 1291 | 1291 | } |
| 1292 | 1292 | |
| 1293 | - if( ! $this->is_admin_teacher() ) { |
|
| 1293 | + if ( ! $this->is_admin_teacher()) { |
|
| 1294 | 1294 | return $request; |
| 1295 | 1295 | } |
| 1296 | 1296 | |
| 1297 | 1297 | $screen = get_current_screen(); |
| 1298 | 1298 | |
| 1299 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1300 | - $teacher = intval( get_current_user_id() ); |
|
| 1299 | + if (in_array($screen->id, array('upload', 'course', 'lesson', 'question'))) { |
|
| 1300 | + $teacher = intval(get_current_user_id()); |
|
| 1301 | 1301 | |
| 1302 | - if( $teacher ) { |
|
| 1303 | - $request['author__in'] = array( $teacher ); |
|
| 1302 | + if ($teacher) { |
|
| 1303 | + $request['author__in'] = array($teacher); |
|
| 1304 | 1304 | } |
| 1305 | 1305 | } |
| 1306 | 1306 | |
@@ -1312,20 +1312,20 @@ discard block |
||
| 1312 | 1312 | * @param array $query Default query arguments |
| 1313 | 1313 | * @return array Modified query arguments |
| 1314 | 1314 | */ |
| 1315 | - public function restrict_media_library_modal( $query = array() ) { |
|
| 1315 | + public function restrict_media_library_modal($query = array()) { |
|
| 1316 | 1316 | |
| 1317 | - if( ! is_admin() ) { |
|
| 1317 | + if ( ! is_admin()) { |
|
| 1318 | 1318 | return $query; |
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | - if( ! $this->is_admin_teacher() ) { |
|
| 1321 | + if ( ! $this->is_admin_teacher()) { |
|
| 1322 | 1322 | return $query; |
| 1323 | 1323 | } |
| 1324 | 1324 | |
| 1325 | - $teacher = intval( get_current_user_id() ); |
|
| 1325 | + $teacher = intval(get_current_user_id()); |
|
| 1326 | 1326 | |
| 1327 | - if( $teacher ) { |
|
| 1328 | - $query['author__in'] = array( $teacher ); |
|
| 1327 | + if ($teacher) { |
|
| 1328 | + $query['author__in'] = array($teacher); |
|
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | 1331 | return $query; |
@@ -1338,28 +1338,28 @@ discard block |
||
| 1338 | 1338 | * |
| 1339 | 1339 | * @param int $lesson_id |
| 1340 | 1340 | */ |
| 1341 | - public function update_lesson_teacher( $lesson_id ){ |
|
| 1341 | + public function update_lesson_teacher($lesson_id) { |
|
| 1342 | 1342 | |
| 1343 | - if( 'lesson'!= get_post_type() ){ |
|
| 1343 | + if ('lesson' != get_post_type()) { |
|
| 1344 | 1344 | return; |
| 1345 | 1345 | } |
| 1346 | 1346 | |
| 1347 | 1347 | // this should only run once per request cycle |
| 1348 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1348 | + remove_action('save_post', array($this, 'update_lesson_teacher')); |
|
| 1349 | 1349 | |
| 1350 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1350 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
| 1351 | 1351 | |
| 1352 | - if( empty( $course_id ) || ! $course_id ){ |
|
| 1352 | + if (empty($course_id) || ! $course_id) { |
|
| 1353 | 1353 | return; |
| 1354 | 1354 | } |
| 1355 | 1355 | |
| 1356 | - $course = get_post( $course_id ); |
|
| 1356 | + $course = get_post($course_id); |
|
| 1357 | 1357 | |
| 1358 | - $lesson_update_args= array( |
|
| 1359 | - 'ID' => $lesson_id , |
|
| 1358 | + $lesson_update_args = array( |
|
| 1359 | + 'ID' => $lesson_id, |
|
| 1360 | 1360 | 'post_author' => $course->post_author |
| 1361 | 1361 | ); |
| 1362 | - wp_update_post( $lesson_update_args ); |
|
| 1362 | + wp_update_post($lesson_update_args); |
|
| 1363 | 1363 | |
| 1364 | 1364 | } // end update_lesson_teacher |
| 1365 | 1365 | |
@@ -1373,21 +1373,21 @@ discard block |
||
| 1373 | 1373 | * @parameters array $wp_query |
| 1374 | 1374 | * @return WP_Query $wp_query |
| 1375 | 1375 | */ |
| 1376 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1376 | + public function limit_teacher_edit_screen_post_types($wp_query) { |
|
| 1377 | 1377 | global $current_user; |
| 1378 | 1378 | |
| 1379 | 1379 | //exit early |
| 1380 | - if( ! $this->is_admin_teacher() ){ |
|
| 1380 | + if ( ! $this->is_admin_teacher()) { |
|
| 1381 | 1381 | return $wp_query; |
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1384 | + if ( ! function_exists('get_current_screen')) { |
|
| 1385 | 1385 | return $wp_query; |
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | 1388 | $screen = get_current_screen(); |
| 1389 | 1389 | |
| 1390 | - if( empty( $screen ) ){ |
|
| 1390 | + if (empty($screen)) { |
|
| 1391 | 1391 | return $wp_query; |
| 1392 | 1392 | } |
| 1393 | 1393 | |
@@ -1400,10 +1400,10 @@ discard block |
||
| 1400 | 1400 | 'lesson_page_lesson-order', |
| 1401 | 1401 | ); |
| 1402 | 1402 | |
| 1403 | - if( in_array($screen->id , $limit_screens ) ) { |
|
| 1403 | + if (in_array($screen->id, $limit_screens)) { |
|
| 1404 | 1404 | |
| 1405 | 1405 | // set the query author to the current user to only show those those posts |
| 1406 | - $wp_query->set( 'author', $current_user->ID ); |
|
| 1406 | + $wp_query->set('author', $current_user->ID); |
|
| 1407 | 1407 | } |
| 1408 | 1408 | |
| 1409 | 1409 | return $wp_query; |
@@ -1423,7 +1423,7 @@ discard block |
||
| 1423 | 1423 | * @return void |
| 1424 | 1424 | */ |
| 1425 | 1425 | |
| 1426 | - public function teacher_login_redirect( $user_login, $user ) { |
|
| 1426 | + public function teacher_login_redirect($user_login, $user) { |
|
| 1427 | 1427 | |
| 1428 | 1428 | if (user_can($user, 'edit_courses')) { |
| 1429 | 1429 | |
@@ -1473,9 +1473,9 @@ discard block |
||
| 1473 | 1473 | * @param bool $restrict default true |
| 1474 | 1474 | */ |
| 1475 | 1475 | |
| 1476 | - $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
| 1476 | + $restrict = apply_filters('sensei_restrict_posts_menu_page', true); |
|
| 1477 | 1477 | |
| 1478 | - if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
| 1478 | + if (in_array('teacher', (array) $user->roles) && ! current_user_can('delete_posts') && $restrict) { |
|
| 1479 | 1479 | |
| 1480 | 1480 | remove_menu_page('edit.php'); |
| 1481 | 1481 | |
@@ -1509,7 +1509,7 @@ discard block |
||
| 1509 | 1509 | |
| 1510 | 1510 | global $pagenow; |
| 1511 | 1511 | |
| 1512 | - if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
| 1512 | + if (self::is_a_teacher(get_current_user_id()) && $pagenow == "edit-comments.php") { |
|
| 1513 | 1513 | |
| 1514 | 1514 | $clauses->query_vars['post_author'] = get_current_user_id(); |
| 1515 | 1515 | |
@@ -1526,15 +1526,15 @@ discard block |
||
| 1526 | 1526 | * |
| 1527 | 1527 | * @return bool |
| 1528 | 1528 | */ |
| 1529 | - public static function is_a_teacher( $user_id ){ |
|
| 1529 | + public static function is_a_teacher($user_id) { |
|
| 1530 | 1530 | |
| 1531 | 1531 | $user = get_user_by('id', $user_id); |
| 1532 | 1532 | |
| 1533 | - if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
| 1533 | + if (isset($user->roles) && in_array('teacher', $user->roles)) { |
|
| 1534 | 1534 | |
| 1535 | 1535 | return true; |
| 1536 | 1536 | |
| 1537 | - }else{ |
|
| 1537 | + } else { |
|
| 1538 | 1538 | |
| 1539 | 1539 | return false; |
| 1540 | 1540 | |
@@ -1547,14 +1547,14 @@ discard block |
||
| 1547 | 1547 | * |
| 1548 | 1548 | * @since 1.9.0 |
| 1549 | 1549 | */ |
| 1550 | - public static function archive_title(){ |
|
| 1550 | + public static function archive_title() { |
|
| 1551 | 1551 | |
| 1552 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1552 | + $author = get_user_by('id', get_query_var('author')); |
|
| 1553 | 1553 | $author_name = $author->display_name; |
| 1554 | 1554 | ?> |
| 1555 | 1555 | <h2 class="teacher-archive-title"> |
| 1556 | 1556 | |
| 1557 | - <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
|
| 1557 | + <?php echo sprintf(__('All courses by %s', 'woothemes-sensei'), $author_name); ?> |
|
| 1558 | 1558 | |
| 1559 | 1559 | </h2> |
| 1560 | 1560 | <?php |
@@ -1566,9 +1566,9 @@ discard block |
||
| 1566 | 1566 | * |
| 1567 | 1567 | * @since 1.9.0 |
| 1568 | 1568 | */ |
| 1569 | - public static function remove_course_meta_on_teacher_archive(){ |
|
| 1569 | + public static function remove_course_meta_on_teacher_archive() { |
|
| 1570 | 1570 | |
| 1571 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
| 1571 | + remove_action('sensei_course_content_inside_before', array(Sensei()->course, 'the_course_meta')); |
|
| 1572 | 1572 | |
| 1573 | 1573 | } |
| 1574 | 1574 | |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | * |
| 456 | 456 | * @since 1.1.0 |
| 457 | 457 | * @access public |
| 458 | - * @return void |
|
| 458 | + * @return boolean |
|
| 459 | 459 | */ |
| 460 | 460 | public function assign_role_caps() { |
| 461 | 461 | foreach ( $this->parent->post_types->role_caps as $role_cap_set ) { |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | * |
| 481 | 481 | * @since 1.3.0 |
| 482 | 482 | * @access public |
| 483 | - * @return void |
|
| 483 | + * @return boolean |
|
| 484 | 484 | */ |
| 485 | 485 | public function set_default_quiz_grade_type() { |
| 486 | 486 | $args = array( 'post_type' => 'quiz', |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | * |
| 503 | 503 | * @since 1.3.0 |
| 504 | 504 | * @access public |
| 505 | - * @return void |
|
| 505 | + * @return boolean |
|
| 506 | 506 | */ |
| 507 | 507 | public function set_default_question_type() { |
| 508 | 508 | $args = array( 'post_type' => 'question', |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | * |
| 533 | 533 | * @since 1.3.0 |
| 534 | 534 | * @access public |
| 535 | - * @return void |
|
| 535 | + * @return boolean |
|
| 536 | 536 | */ |
| 537 | 537 | public function update_question_answer_data( $n = 50, $offset = 0 ) { |
| 538 | 538 | |
@@ -1429,8 +1429,8 @@ discard block |
||
| 1429 | 1429 | * |
| 1430 | 1430 | * @global type $woothemes_sensei |
| 1431 | 1431 | * @global type $wpdb |
| 1432 | - * @param type $n |
|
| 1433 | - * @param type $offset |
|
| 1432 | + * @param integer $n |
|
| 1433 | + * @param integer $offset |
|
| 1434 | 1434 | * @return boolean |
| 1435 | 1435 | */ |
| 1436 | 1436 | function status_changes_repair_course_statuses( $n = 50, $offset = 0 ) { |
@@ -1674,8 +1674,8 @@ discard block |
||
| 1674 | 1674 | * Update the comment counts for all Courses and Lessons now that sensei comments will no longer be counted. |
| 1675 | 1675 | * |
| 1676 | 1676 | * @global type $wpdb |
| 1677 | - * @param type $n |
|
| 1678 | - * @param type $offset |
|
| 1677 | + * @param integer $n |
|
| 1678 | + * @param integer $offset |
|
| 1679 | 1679 | * @return boolean |
| 1680 | 1680 | */ |
| 1681 | 1681 | public function update_comment_course_lesson_comment_counts( $n = 50, $offset = 0 ) { |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | '1.7.2' => array( 'auto' => array( 'index_comment_status_field' => array( 'title' => __( 'Add database index to comment statuses', 'woothemes-sensei' ), 'desc' => __( 'This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei' ) ), ), |
| 71 | 71 | /*'manual' => array( 'remove_legacy_comments' => array( 'title' => __( 'Remove legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'This removes all legacy (pre-1.7) Sensei activity types - only run this update once the update to v1.7 is complete and everything is stable.', 'woothemes-sensei' ) ) )*/ |
| 72 | 72 | ), |
| 73 | - '1.8.0' => array( 'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ), |
|
| 74 | - 'manual' => array() |
|
| 75 | - ), |
|
| 73 | + '1.8.0' => array( 'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ), |
|
| 74 | + 'manual' => array() |
|
| 75 | + ), |
|
| 76 | 76 | ); |
| 77 | 77 | |
| 78 | 78 | $this->updates = apply_filters( 'sensei_upgrade_functions', $this->updates, $this->updates ); |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | } // End For Loop |
| 330 | 330 | } // End For Loop |
| 331 | 331 | |
| 332 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 332 | + $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 333 | 333 | update_option( $this->token . '-upgrades', $this->updates_run ); |
| 334 | 334 | return true; |
| 335 | 335 | |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | */ |
| 447 | 447 | private function set_update_run( $update ) { |
| 448 | 448 | array_push( $this->updates_run, $update ); |
| 449 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 449 | + $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 450 | 450 | update_option( $this->token . '-upgrades', $this->updates_run ); |
| 451 | 451 | } |
| 452 | 452 | |
@@ -918,11 +918,11 @@ discard block |
||
| 918 | 918 | update_post_meta( $lesson->ID, '_order_' . $course_id, 0 ); |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | - $module = Sensei()->modules->get_lesson_module( $lesson->ID ); |
|
| 921 | + $module = Sensei()->modules->get_lesson_module( $lesson->ID ); |
|
| 922 | 922 | |
| 923 | - if( $module ) { |
|
| 924 | - update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 ); |
|
| 925 | - } |
|
| 923 | + if( $module ) { |
|
| 924 | + update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 ); |
|
| 925 | + } |
|
| 926 | 926 | |
| 927 | 927 | } |
| 928 | 928 | |
@@ -1732,22 +1732,22 @@ discard block |
||
| 1732 | 1732 | |
| 1733 | 1733 | } |
| 1734 | 1734 | |
| 1735 | - /** |
|
| 1736 | - * WooThemes_Sensei_Updates::enhance_teacher_role |
|
| 1737 | - * |
|
| 1738 | - * This runs the update to create the teacher role |
|
| 1739 | - * @access public |
|
| 1740 | - * @since 1.8.0 |
|
| 1741 | - * @return bool; |
|
| 1742 | - */ |
|
| 1743 | - public function enhance_teacher_role ( ) { |
|
| 1744 | - |
|
| 1745 | - require_once('class-sensei-teacher.php'); |
|
| 1746 | - $teacher = new Sensei_Teacher(); |
|
| 1747 | - $teacher->create_role(); |
|
| 1748 | - return true; |
|
| 1749 | - |
|
| 1750 | - }// end enhance_teacher_role |
|
| 1735 | + /** |
|
| 1736 | + * WooThemes_Sensei_Updates::enhance_teacher_role |
|
| 1737 | + * |
|
| 1738 | + * This runs the update to create the teacher role |
|
| 1739 | + * @access public |
|
| 1740 | + * @since 1.8.0 |
|
| 1741 | + * @return bool; |
|
| 1742 | + */ |
|
| 1743 | + public function enhance_teacher_role ( ) { |
|
| 1744 | + |
|
| 1745 | + require_once('class-sensei-teacher.php'); |
|
| 1746 | + $teacher = new Sensei_Teacher(); |
|
| 1747 | + $teacher->create_role(); |
|
| 1748 | + return true; |
|
| 1749 | + |
|
| 1750 | + }// end enhance_teacher_role |
|
| 1751 | 1751 | |
| 1752 | 1752 | } // End Class |
| 1753 | 1753 | |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Updates Class |
@@ -769,9 +772,15 @@ discard block |
||
| 769 | 772 | $all_activity = get_comments( array( 'status' => 'approve' ) ); |
| 770 | 773 | $activity_count = array(); |
| 771 | 774 | foreach( $all_activity as $activity ) { |
| 772 | - if( '' == $activity->comment_type ) continue; |
|
| 773 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 774 | - if( 0 == $activity->user_id ) continue; |
|
| 775 | + if( '' == $activity->comment_type ) { |
|
| 776 | + continue; |
|
| 777 | + } |
|
| 778 | + if( strpos( 'sensei_', $activity->comment_type ) != 0 ) { |
|
| 779 | + continue; |
|
| 780 | + } |
|
| 781 | + if( 0 == $activity->user_id ) { |
|
| 782 | + continue; |
|
| 783 | + } |
|
| 775 | 784 | $activity_count[] = $activity->comment_ID; |
| 776 | 785 | } |
| 777 | 786 | |
@@ -784,9 +793,15 @@ discard block |
||
| 784 | 793 | $activities = get_comments( $args ); |
| 785 | 794 | |
| 786 | 795 | foreach( $activities as $activity ) { |
| 787 | - if( '' == $activity->comment_type ) continue; |
|
| 788 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 789 | - if( 0 == $activity->user_id ) continue; |
|
| 796 | + if( '' == $activity->comment_type ) { |
|
| 797 | + continue; |
|
| 798 | + } |
|
| 799 | + if( strpos( 'sensei_', $activity->comment_type ) != 0 ) { |
|
| 800 | + continue; |
|
| 801 | + } |
|
| 802 | + if( 0 == $activity->user_id ) { |
|
| 803 | + continue; |
|
| 804 | + } |
|
| 790 | 805 | |
| 791 | 806 | $user_exists = get_userdata( $activity->user_id ); |
| 792 | 807 | |
@@ -845,7 +860,9 @@ discard block |
||
| 845 | 860 | |
| 846 | 861 | foreach( $questions as $question ) { |
| 847 | 862 | |
| 848 | - if( ! isset( $question->ID ) ) continue; |
|
| 863 | + if( ! isset( $question->ID ) ) { |
|
| 864 | + continue; |
|
| 865 | + } |
|
| 849 | 866 | |
| 850 | 867 | $quiz_id = get_post_meta( $question->ID, '_quiz_id', true ); |
| 851 | 868 | |
@@ -882,7 +899,9 @@ discard block |
||
| 882 | 899 | |
| 883 | 900 | foreach( $quizzes as $quiz ) { |
| 884 | 901 | |
| 885 | - if( ! isset( $quiz->ID ) ) continue; |
|
| 902 | + if( ! isset( $quiz->ID ) ) { |
|
| 903 | + continue; |
|
| 904 | + } |
|
| 886 | 905 | |
| 887 | 906 | if( isset( $lesson_completion ) && 'passed' == $lesson_completion ) { |
| 888 | 907 | update_post_meta( $quiz->ID, '_pass_required', 'on' ); |
@@ -910,7 +929,9 @@ discard block |
||
| 910 | 929 | |
| 911 | 930 | foreach( $lessons as $lesson ) { |
| 912 | 931 | |
| 913 | - if( ! isset( $lesson->ID ) ) continue; |
|
| 932 | + if( ! isset( $lesson->ID ) ) { |
|
| 933 | + continue; |
|
| 934 | + } |
|
| 914 | 935 | |
| 915 | 936 | $course_id = get_post_meta( $lesson->ID, '_lesson_course', true); |
| 916 | 937 | |
@@ -984,11 +1005,15 @@ discard block |
||
| 984 | 1005 | |
| 985 | 1006 | foreach( $quizzes as $quiz ) { |
| 986 | 1007 | |
| 987 | - if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) continue; |
|
| 1008 | + if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) { |
|
| 1009 | + continue; |
|
| 1010 | + } |
|
| 988 | 1011 | |
| 989 | 1012 | $lesson_id = get_post_meta( $quiz->ID, '_quiz_lesson', true ); |
| 990 | 1013 | |
| 991 | - if( empty( $lesson_id ) ) continue; |
|
| 1014 | + if( empty( $lesson_id ) ) { |
|
| 1015 | + continue; |
|
| 1016 | + } |
|
| 992 | 1017 | |
| 993 | 1018 | $data = array( |
| 994 | 1019 | 'ID' => $quiz->ID, |
@@ -1071,8 +1096,7 @@ discard block |
||
| 1071 | 1096 | delete_post_meta( $quiz_id, '_quiz_passmark' ); |
| 1072 | 1097 | delete_post_meta( $lesson_id, '_quiz_has_questions' ); |
| 1073 | 1098 | $d_count++; |
| 1074 | - } |
|
| 1075 | - else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) { |
|
| 1099 | + } else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) { |
|
| 1076 | 1100 | |
| 1077 | 1101 | // Quiz has no questions, drop the corresponding data |
| 1078 | 1102 | update_post_meta( $lesson_id, '_quiz_has_questions', true ); |
@@ -1222,20 +1246,16 @@ discard block |
||
| 1222 | 1246 | // Check if the user has to get the passmark and has or not |
| 1223 | 1247 | if ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] <= $quiz_grade ) { |
| 1224 | 1248 | $status = 'passed'; |
| 1225 | - } |
|
| 1226 | - elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) { |
|
| 1249 | + } elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) { |
|
| 1227 | 1250 | $status = 'failed'; |
| 1228 | - } |
|
| 1229 | - else { |
|
| 1251 | + } else { |
|
| 1230 | 1252 | $status = 'graded'; |
| 1231 | 1253 | } |
| 1232 | - } |
|
| 1233 | - else { |
|
| 1254 | + } else { |
|
| 1234 | 1255 | // If the lesson has a quiz, but the user doesn't have a grade, it's not yet been graded |
| 1235 | 1256 | $status = 'ungraded'; |
| 1236 | 1257 | } |
| 1237 | - } |
|
| 1238 | - else { |
|
| 1258 | + } else { |
|
| 1239 | 1259 | // Lesson has no quiz, so it can only ever be this status |
| 1240 | 1260 | $status = 'complete'; |
| 1241 | 1261 | } |
@@ -1374,8 +1394,7 @@ discard block |
||
| 1374 | 1394 | } |
| 1375 | 1395 | $meta_data['complete'] = $lessons_completed; |
| 1376 | 1396 | $meta_data['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ); |
| 1377 | - } |
|
| 1378 | - else { |
|
| 1397 | + } else { |
|
| 1379 | 1398 | // Course has no lessons, therefore cannot be 'complete' |
| 1380 | 1399 | $status = 'in-progress'; |
| 1381 | 1400 | } |
@@ -1506,8 +1525,7 @@ discard block |
||
| 1506 | 1525 | $lessons_completed++; |
| 1507 | 1526 | break; |
| 1508 | 1527 | } |
| 1509 | - } |
|
| 1510 | - else { |
|
| 1528 | + } else { |
|
| 1511 | 1529 | switch ( $lesson_status ) { |
| 1512 | 1530 | case 'complete': // Lesson has no quiz/questions |
| 1513 | 1531 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
@@ -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 Updates Class |
@@ -27,59 +27,59 @@ discard block |
||
| 27 | 27 | * @param string $parent The main Sensei object by Ref. |
| 28 | 28 | * @return void |
| 29 | 29 | */ |
| 30 | - public function __construct ( $parent ) { |
|
| 30 | + public function __construct($parent) { |
|
| 31 | 31 | |
| 32 | 32 | // Setup object data |
| 33 | 33 | $this->parent = $parent; |
| 34 | - $this->updates_run = get_option( 'woothemes-sensei-upgrades', array() ); |
|
| 34 | + $this->updates_run = get_option('woothemes-sensei-upgrades', array()); |
|
| 35 | 35 | |
| 36 | 36 | // The list of upgrades to run |
| 37 | - $this->updates = array( '1.1.0' => array( 'auto' => array( 'assign_role_caps' => array( 'title' => __( 'Assign role capabilities', 'woothemes-sensei' ), 'desc' => __( 'Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei' ), 'product' => 'Sensei' ) ), |
|
| 37 | + $this->updates = array('1.1.0' => array('auto' => array('assign_role_caps' => array('title' => __('Assign role capabilities', 'woothemes-sensei'), 'desc' => __('Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei'), 'product' => 'Sensei')), |
|
| 38 | 38 | 'manual' => array() |
| 39 | 39 | ), |
| 40 | - '1.3.0' => array( 'auto' => array( 'set_default_quiz_grade_type' => array( 'title' => __( 'Set default quiz grade type', 'woothemes-sensei' ), 'desc' => __( 'Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei' ) ), |
|
| 41 | - 'set_default_question_type' => array( 'title' => __( 'Set default question type', 'woothemes-sensei' ), 'desc' => __( 'Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei' ) ) |
|
| 40 | + '1.3.0' => array('auto' => array('set_default_quiz_grade_type' => array('title' => __('Set default quiz grade type', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei')), |
|
| 41 | + 'set_default_question_type' => array('title' => __('Set default question type', 'woothemes-sensei'), 'desc' => __('Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei')) |
|
| 42 | 42 | ), |
| 43 | - 'manual' => array( 'update_question_answer_data' => array( 'title' => __( 'Update question answer data', 'woothemes-sensei' ), 'desc' => __( 'Updates questions to use the new question types structure.', 'woothemes-sensei' ) ) ) |
|
| 43 | + 'manual' => array('update_question_answer_data' => array('title' => __('Update question answer data', 'woothemes-sensei'), 'desc' => __('Updates questions to use the new question types structure.', 'woothemes-sensei'))) |
|
| 44 | 44 | ), |
| 45 | - '1.4.0' => array( 'auto' => array( 'update_question_grade_points' => array( 'title' => __( 'Update question grade points', 'woothemes-sensei' ), 'desc' => __( 'Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei' ) ) ), |
|
| 45 | + '1.4.0' => array('auto' => array('update_question_grade_points' => array('title' => __('Update question grade points', 'woothemes-sensei'), 'desc' => __('Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei'))), |
|
| 46 | 46 | 'manual' => array() |
| 47 | 47 | ), |
| 48 | - '1.5.0' => array( 'auto' => array( 'convert_essay_paste_questions' => array( 'title' => __( 'Convert essay paste questions into multi-line questions', 'woothemes-sensei' ), 'desc' => __( 'Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei' ) ) ), |
|
| 49 | - 'manual' => array( 'set_random_question_order' => array( 'title' => __( 'Set all quizzes to have a random question order', 'woothemes-sensei' ), 'desc' => __( 'Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei' ) ), |
|
| 50 | - 'set_default_show_question_count' => array( 'title' => __( 'Set all quizzes to show all questions', 'woothemes-sensei' ), 'desc' => __( 'Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei' ) ), |
|
| 51 | - 'remove_deleted_user_activity' => array( 'title' => __( 'Remove Sensei activity for deleted users', 'woothemes-sensei' ), 'desc' => __( 'Removes all course, lesson & quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei' ) ) ) |
|
| 48 | + '1.5.0' => array('auto' => array('convert_essay_paste_questions' => array('title' => __('Convert essay paste questions into multi-line questions', 'woothemes-sensei'), 'desc' => __('Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei'))), |
|
| 49 | + 'manual' => array('set_random_question_order' => array('title' => __('Set all quizzes to have a random question order', 'woothemes-sensei'), 'desc' => __('Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei')), |
|
| 50 | + 'set_default_show_question_count' => array('title' => __('Set all quizzes to show all questions', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei')), |
|
| 51 | + 'remove_deleted_user_activity' => array('title' => __('Remove Sensei activity for deleted users', 'woothemes-sensei'), 'desc' => __('Removes all course, lesson & quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei'))) |
|
| 52 | 52 | ), |
| 53 | - '1.6.0' => array( 'auto' => array( 'add_teacher_role' => array( 'title' => __( 'Add \'Teacher\' role', 'woothemes-sensei' ), 'desc' => __( 'Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei' ) ), |
|
| 54 | - 'add_sensei_caps' => array( 'title' => __( 'Add administrator capabilities', 'woothemes-sensei' ), 'desc' => __( 'Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei' ) ), |
|
| 55 | - 'restructure_question_meta' => array( 'title' => __( 'Restructure question meta data', 'woothemes-sensei' ), 'desc' => __( 'Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei' ) ), |
|
| 56 | - 'update_quiz_settings' => array( 'title' => __( 'Add new quiz settings', 'woothemes-sensei' ), 'desc' => __( 'Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei' ) ), |
|
| 57 | - 'reset_lesson_order_meta' => array( 'title' => __( 'Set default order of lessons', 'woothemes-sensei' ), 'desc' => __( 'Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei' ) ), ), |
|
| 53 | + '1.6.0' => array('auto' => array('add_teacher_role' => array('title' => __('Add \'Teacher\' role', 'woothemes-sensei'), 'desc' => __('Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei')), |
|
| 54 | + 'add_sensei_caps' => array('title' => __('Add administrator capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei')), |
|
| 55 | + 'restructure_question_meta' => array('title' => __('Restructure question meta data', 'woothemes-sensei'), 'desc' => __('Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei')), |
|
| 56 | + 'update_quiz_settings' => array('title' => __('Add new quiz settings', 'woothemes-sensei'), 'desc' => __('Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei')), |
|
| 57 | + 'reset_lesson_order_meta' => array('title' => __('Set default order of lessons', 'woothemes-sensei'), 'desc' => __('Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei')),), |
|
| 58 | 58 | 'manual' => array() |
| 59 | 59 | ), |
| 60 | - '1.7.0' => array( 'auto' => array( 'add_editor_caps' => array( 'title' => __( 'Add Editor capabilities', 'woothemes-sensei' ), 'desc' => __( 'Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei' ) ), ), |
|
| 61 | - 'forced' => array( 'update_question_gap_fill_separators' => array( 'title' => __( 'Update Gap Fill questions', 'woothemes-sensei' ), 'desc' => __( 'Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei' ) ), |
|
| 62 | - 'update_quiz_lesson_relationship' => array( 'title' => __( 'Restructure quiz lesson relationship', 'woothemes-sensei' ), 'desc' => __( 'Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei' ) ), |
|
| 63 | - 'status_changes_fix_lessons' => array( 'title' => __( 'Update lesson statuses', 'woothemes-sensei' ), 'desc' => __( 'Update existing lesson statuses.', 'woothemes-sensei' ) ), |
|
| 64 | - 'status_changes_convert_lessons' => array( 'title' => __( 'Convert lesson statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new lesson statuses.', 'woothemes-sensei' ) ), |
|
| 65 | - 'status_changes_convert_courses' => array( 'title' => __( 'Convert course statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new course statuses.', 'woothemes-sensei' ) ), |
|
| 66 | - 'status_changes_convert_questions' => array( 'title' => __( 'Convert question statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new question statuses.', 'woothemes-sensei' ) ), |
|
| 67 | - 'update_legacy_sensei_comments_status' => array( 'title' => __( 'Convert legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei' ) ), |
|
| 68 | - 'update_comment_course_lesson_comment_counts' => array( 'title' => __( 'Update comment counts', 'woothemes-sensei' ), 'desc' => __( 'Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei' ) ), ), |
|
| 60 | + '1.7.0' => array('auto' => array('add_editor_caps' => array('title' => __('Add Editor capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei')),), |
|
| 61 | + 'forced' => array('update_question_gap_fill_separators' => array('title' => __('Update Gap Fill questions', 'woothemes-sensei'), 'desc' => __('Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei')), |
|
| 62 | + 'update_quiz_lesson_relationship' => array('title' => __('Restructure quiz lesson relationship', 'woothemes-sensei'), 'desc' => __('Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei')), |
|
| 63 | + 'status_changes_fix_lessons' => array('title' => __('Update lesson statuses', 'woothemes-sensei'), 'desc' => __('Update existing lesson statuses.', 'woothemes-sensei')), |
|
| 64 | + 'status_changes_convert_lessons' => array('title' => __('Convert lesson statuses', 'woothemes-sensei'), 'desc' => __('Convert to new lesson statuses.', 'woothemes-sensei')), |
|
| 65 | + 'status_changes_convert_courses' => array('title' => __('Convert course statuses', 'woothemes-sensei'), 'desc' => __('Convert to new course statuses.', 'woothemes-sensei')), |
|
| 66 | + 'status_changes_convert_questions' => array('title' => __('Convert question statuses', 'woothemes-sensei'), 'desc' => __('Convert to new question statuses.', 'woothemes-sensei')), |
|
| 67 | + 'update_legacy_sensei_comments_status' => array('title' => __('Convert legacy Sensei activity types', 'woothemes-sensei'), 'desc' => __('Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei')), |
|
| 68 | + 'update_comment_course_lesson_comment_counts' => array('title' => __('Update comment counts', 'woothemes-sensei'), 'desc' => __('Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei')),), |
|
| 69 | 69 | ), |
| 70 | - '1.7.2' => array( 'auto' => array( 'index_comment_status_field' => array( 'title' => __( 'Add database index to comment statuses', 'woothemes-sensei' ), 'desc' => __( 'This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei' ) ), ), |
|
| 70 | + '1.7.2' => array('auto' => array('index_comment_status_field' => array('title' => __('Add database index to comment statuses', 'woothemes-sensei'), 'desc' => __('This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei')),), |
|
| 71 | 71 | /*'manual' => array( 'remove_legacy_comments' => array( 'title' => __( 'Remove legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'This removes all legacy (pre-1.7) Sensei activity types - only run this update once the update to v1.7 is complete and everything is stable.', 'woothemes-sensei' ) ) )*/ |
| 72 | 72 | ), |
| 73 | - '1.8.0' => array( 'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ), |
|
| 73 | + '1.8.0' => array('auto' => array('enhance_teacher_role' => array('title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.'),), |
|
| 74 | 74 | 'manual' => array() |
| 75 | 75 | ), |
| 76 | 76 | ); |
| 77 | 77 | |
| 78 | - $this->updates = apply_filters( 'sensei_upgrade_functions', $this->updates, $this->updates ); |
|
| 79 | - $this->version = get_option( 'woothemes-sensei-version' ); |
|
| 78 | + $this->updates = apply_filters('sensei_upgrade_functions', $this->updates, $this->updates); |
|
| 79 | + $this->version = get_option('woothemes-sensei-version'); |
|
| 80 | 80 | |
| 81 | 81 | // Manual Update Screen |
| 82 | - add_action('admin_menu', array( $this, 'add_update_admin_screen' ), 50 ); |
|
| 82 | + add_action('admin_menu', array($this, 'add_update_admin_screen'), 50); |
|
| 83 | 83 | |
| 84 | 84 | } // End __construct() |
| 85 | 85 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * @return void |
| 92 | 92 | */ |
| 93 | 93 | public function add_update_admin_screen() { |
| 94 | - if ( current_user_can( 'manage_options' ) ) { |
|
| 95 | - add_submenu_page( 'sensei', __( 'Sensei Updates', 'woothemes-sensei' ), __( 'Data Updates', 'woothemes-sensei' ), 'manage_options', 'sensei_updates', array( $this, 'sensei_updates_page' ) ); |
|
| 94 | + if (current_user_can('manage_options')) { |
|
| 95 | + add_submenu_page('sensei', __('Sensei Updates', 'woothemes-sensei'), __('Data Updates', 'woothemes-sensei'), 'manage_options', 'sensei_updates', array($this, 'sensei_updates_page')); |
|
| 96 | 96 | } |
| 97 | 97 | } // End add_update_admin_screen() |
| 98 | 98 | |
@@ -106,80 +106,80 @@ discard block |
||
| 106 | 106 | public function sensei_updates_page() { |
| 107 | 107 | |
| 108 | 108 | // Only allow admins to load this page and run the update functions |
| 109 | - if( current_user_can( 'manage_options' ) ) { |
|
| 109 | + if (current_user_can('manage_options')) { |
|
| 110 | 110 | ?> |
| 111 | 111 | <div class="wrap"> |
| 112 | 112 | |
| 113 | 113 | <div id="icon-woothemes-sensei" class="icon32"><br></div> |
| 114 | - <h2><?php _e( 'Sensei Updates', 'woothemes-sensei' ); ?></h2> |
|
| 114 | + <h2><?php _e('Sensei Updates', 'woothemes-sensei'); ?></h2> |
|
| 115 | 115 | |
| 116 | 116 | <?php |
| 117 | - if ( isset( $_GET['action'] ) && $_GET['action'] == 'update' && isset( $_GET['n'] ) && intval( $_GET['n'] ) >= 0 && ( ( isset( $_POST['checked'][0] ) && '' != $_POST['checked'][0] ) || ( isset( $_GET['functions'] ) && '' != $_GET['functions'] ) ) ) { |
|
| 117 | + if (isset($_GET['action']) && $_GET['action'] == 'update' && isset($_GET['n']) && intval($_GET['n']) >= 0 && ((isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) || (isset($_GET['functions']) && '' != $_GET['functions']))) { |
|
| 118 | 118 | |
| 119 | 119 | // Setup the data variables |
| 120 | - $n = intval( $_GET['n'] ); |
|
| 120 | + $n = intval($_GET['n']); |
|
| 121 | 121 | $functions_list = ''; |
| 122 | 122 | $done_processing = false; |
| 123 | 123 | |
| 124 | 124 | // Check for updates to run |
| 125 | - if ( isset( $_POST['checked'][0] ) && '' != $_POST['checked'][0] ) { |
|
| 125 | + if (isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) { |
|
| 126 | 126 | |
| 127 | - foreach ( $_POST['checked'] as $key => $value ) { |
|
| 127 | + foreach ($_POST['checked'] as $key => $value) { |
|
| 128 | 128 | |
| 129 | 129 | // Dynamic function call |
| 130 | - if ( method_exists( $this, $value) ) { |
|
| 131 | - $done_processing = call_user_func_array( array( $this, $value ), array( 50, $n ) ); |
|
| 130 | + if (method_exists($this, $value)) { |
|
| 131 | + $done_processing = call_user_func_array(array($this, $value), array(50, $n)); |
|
| 132 | 132 | } else { |
| 133 | - $done_processing = call_user_func_array( $value, array( 50, $n ) ); |
|
| 133 | + $done_processing = call_user_func_array($value, array(50, $n)); |
|
| 134 | 134 | } // End If Statement |
| 135 | 135 | |
| 136 | 136 | // Add to functions list get args |
| 137 | - if ( '' == $functions_list ) { |
|
| 137 | + if ('' == $functions_list) { |
|
| 138 | 138 | $functions_list .= $value; |
| 139 | 139 | } else { |
| 140 | - $functions_list .= '+' . $value; |
|
| 140 | + $functions_list .= '+'.$value; |
|
| 141 | 141 | } // End If Statement |
| 142 | 142 | |
| 143 | 143 | // Mark update has having been run |
| 144 | - $this->set_update_run( $value ); |
|
| 144 | + $this->set_update_run($value); |
|
| 145 | 145 | |
| 146 | 146 | } // End For Loop |
| 147 | 147 | |
| 148 | 148 | } // End If Statement |
| 149 | 149 | |
| 150 | 150 | // Check for updates to run |
| 151 | - if ( isset( $_GET['functions'] ) && '' != $_GET['functions'] ) { |
|
| 151 | + if (isset($_GET['functions']) && '' != $_GET['functions']) { |
|
| 152 | 152 | |
| 153 | 153 | // Existing functions from GET variables instead of POST |
| 154 | 154 | $functions_array = $_GET['functions']; |
| 155 | 155 | |
| 156 | - foreach ( $functions_array as $key => $value ) { |
|
| 156 | + foreach ($functions_array as $key => $value) { |
|
| 157 | 157 | |
| 158 | 158 | // Dynamic function call |
| 159 | - if ( method_exists( $this, $value) ) { |
|
| 160 | - $done_processing = call_user_func_array( array( $this, $value ), array( 50, $n ) ); |
|
| 159 | + if (method_exists($this, $value)) { |
|
| 160 | + $done_processing = call_user_func_array(array($this, $value), array(50, $n)); |
|
| 161 | 161 | } else { |
| 162 | - $done_processing = call_user_func_array( $value, array( 50, $n ) ); |
|
| 162 | + $done_processing = call_user_func_array($value, array(50, $n)); |
|
| 163 | 163 | } // End If Statement |
| 164 | 164 | |
| 165 | 165 | // Add to functions list get args |
| 166 | - if ( '' == $functions_list ) { |
|
| 166 | + if ('' == $functions_list) { |
|
| 167 | 167 | $functions_list .= $value; |
| 168 | 168 | } else { |
| 169 | - $functions_list .= '+' . $value; |
|
| 169 | + $functions_list .= '+'.$value; |
|
| 170 | 170 | } // End If Statement |
| 171 | 171 | |
| 172 | - $this->set_update_run( $value ); |
|
| 172 | + $this->set_update_run($value); |
|
| 173 | 173 | |
| 174 | 174 | } // End For Loop |
| 175 | 175 | |
| 176 | 176 | } // End If Statement |
| 177 | 177 | |
| 178 | - if ( ! $done_processing ) { ?> |
|
| 178 | + if ( ! $done_processing) { ?> |
|
| 179 | 179 | |
| 180 | - <h3><?php _e( 'Processing Updates...', 'woothemes-sensei' ); ?></h3> |
|
| 180 | + <h3><?php _e('Processing Updates...', 'woothemes-sensei'); ?></h3> |
|
| 181 | 181 | |
| 182 | - <p><?php _e( 'If your browser doesn’t start loading the next page automatically, click this button:', 'woothemes-sensei' ); ?> <a class="button" href="admin.php?page=sensei_updates&action=update&n=<?php echo ($n + 50) ?>&functions[]=<?php echo $functions_list; ?>"><?php _e( 'Next', 'woothemes-sensei' ); ?></a></p> |
|
| 182 | + <p><?php _e('If your browser doesn’t start loading the next page automatically, click this button:', 'woothemes-sensei'); ?> <a class="button" href="admin.php?page=sensei_updates&action=update&n=<?php echo ($n + 50) ?>&functions[]=<?php echo $functions_list; ?>"><?php _e('Next', 'woothemes-sensei'); ?></a></p> |
|
| 183 | 183 | <script type='text/javascript'> |
| 184 | 184 | <!-- |
| 185 | 185 | function sensei_nextpage() { |
@@ -191,48 +191,48 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | } else { ?> |
| 193 | 193 | |
| 194 | - <p><strong><?php _e( 'Update completed successfully!', 'woothemes-sensei' ); ?></strong></p> |
|
| 195 | - <p><a href="<?php echo admin_url('edit.php?post_type=lesson'); ?>"><?php _e( 'Create a new lesson', 'woothemes-sensei' ); ?></a> or <a href="<?php echo admin_url('admin.php?page=sensei_updates'); ?>"><?php _e( 'run some more updates', 'woothemes-sensei' ); ?></a>.</p> |
|
| 194 | + <p><strong><?php _e('Update completed successfully!', 'woothemes-sensei'); ?></strong></p> |
|
| 195 | + <p><a href="<?php echo admin_url('edit.php?post_type=lesson'); ?>"><?php _e('Create a new lesson', 'woothemes-sensei'); ?></a> or <a href="<?php echo admin_url('admin.php?page=sensei_updates'); ?>"><?php _e('run some more updates', 'woothemes-sensei'); ?></a>.</p> |
|
| 196 | 196 | |
| 197 | 197 | <?php } // End If Statement |
| 198 | 198 | |
| 199 | 199 | } else { ?> |
| 200 | 200 | |
| 201 | - <h3><?php _e( 'Updates', 'woothemes-sensei' ); ?></h3> |
|
| 202 | - <p><?php printf( __( 'These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei' ), '<code>', '</code>' ); ?></p> |
|
| 201 | + <h3><?php _e('Updates', 'woothemes-sensei'); ?></h3> |
|
| 202 | + <p><?php printf(__('These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei'), '<code>', '</code>'); ?></p> |
|
| 203 | 203 | |
| 204 | - <div class="updated"><p><strong><?php _e( 'Only run these updates if you have been instructed to do so by WooThemes support staff.', 'woothemes-sensei' ); ?></strong></p></div> |
|
| 204 | + <div class="updated"><p><strong><?php _e('Only run these updates if you have been instructed to do so by WooThemes support staff.', 'woothemes-sensei'); ?></strong></p></div> |
|
| 205 | 205 | |
| 206 | 206 | <table class="widefat" cellspacing="0" id="update-plugins-table"> |
| 207 | 207 | |
| 208 | 208 | <thead> |
| 209 | 209 | <tr> |
| 210 | - <th scope="col" class="manage-column"><?php _e( 'Update', 'woothemes-sensei' ); ?></th> |
|
| 211 | - <th scope="col" class="manage-column"><?php _e( 'Type', 'woothemes-sensei' ); ?></th> |
|
| 212 | - <th scope="col" class="manage-column"><?php _e( 'Action', 'woothemes-sensei' ); ?></th> |
|
| 210 | + <th scope="col" class="manage-column"><?php _e('Update', 'woothemes-sensei'); ?></th> |
|
| 211 | + <th scope="col" class="manage-column"><?php _e('Type', 'woothemes-sensei'); ?></th> |
|
| 212 | + <th scope="col" class="manage-column"><?php _e('Action', 'woothemes-sensei'); ?></th> |
|
| 213 | 213 | </tr> |
| 214 | 214 | </thead> |
| 215 | 215 | |
| 216 | 216 | <tfoot> |
| 217 | 217 | <tr> |
| 218 | - <th scope="col" class="manage-column"><?php _e( 'Update', 'woothemes-sensei' ); ?></th> |
|
| 219 | - <th scope="col" class="manage-column"><?php _e( 'Type', 'woothemes-sensei' ); ?></th> |
|
| 220 | - <th scope="col" class="manage-column"><?php _e( 'Action', 'woothemes-sensei' ); ?></th> |
|
| 218 | + <th scope="col" class="manage-column"><?php _e('Update', 'woothemes-sensei'); ?></th> |
|
| 219 | + <th scope="col" class="manage-column"><?php _e('Type', 'woothemes-sensei'); ?></th> |
|
| 220 | + <th scope="col" class="manage-column"><?php _e('Action', 'woothemes-sensei'); ?></th> |
|
| 221 | 221 | </tr> |
| 222 | 222 | </tfoot> |
| 223 | 223 | |
| 224 | 224 | <tbody class="updates"> |
| 225 | 225 | <?php |
| 226 | 226 | // Sort updates with the latest at the top |
| 227 | - uksort( $this->updates, array( $this, 'sort_updates' ) ); |
|
| 228 | - $this->updates = array_reverse( $this->updates, true ); |
|
| 227 | + uksort($this->updates, array($this, 'sort_updates')); |
|
| 228 | + $this->updates = array_reverse($this->updates, true); |
|
| 229 | 229 | $class = 'alternate'; |
| 230 | - foreach( $this->updates as $version => $version_updates ) { |
|
| 231 | - foreach( $version_updates as $type => $updates ) { |
|
| 232 | - foreach( $updates as $update => $data ) { |
|
| 233 | - $update_run = $this->has_update_run( $update ); |
|
| 230 | + foreach ($this->updates as $version => $version_updates) { |
|
| 231 | + foreach ($version_updates as $type => $updates) { |
|
| 232 | + foreach ($updates as $update => $data) { |
|
| 233 | + $update_run = $this->has_update_run($update); |
|
| 234 | 234 | $product = 'Sensei'; |
| 235 | - if ( isset( $data['product'] ) && '' != $data['product'] ) { |
|
| 235 | + if (isset($data['product']) && '' != $data['product']) { |
|
| 236 | 236 | $product = $data['product']; |
| 237 | 237 | } // End If Statement |
| 238 | 238 | ?> |
@@ -242,21 +242,21 @@ discard block |
||
| 242 | 242 | <p> |
| 243 | 243 | <input type="hidden" name="checked[]" value="<?php echo $update; ?>"> |
| 244 | 244 | <strong><?php echo $data['title']; ?></strong><br><?php echo $data['desc']; ?><br> |
| 245 | - <em><?php printf( __( 'Originally included in %s v%s', 'woothemes-sensei' ), $product, $version ); ?></em> |
|
| 245 | + <em><?php printf(__('Originally included in %s v%s', 'woothemes-sensei'), $product, $version); ?></em> |
|
| 246 | 246 | </p> |
| 247 | 247 | </td> |
| 248 | 248 | <?php |
| 249 | - $type_label = __( 'Auto', 'woothemes-sensei' ); |
|
| 250 | - if( $type != 'auto' ) { |
|
| 251 | - $type_label = __( 'Manual', 'woothemes-sensei' ); |
|
| 249 | + $type_label = __('Auto', 'woothemes-sensei'); |
|
| 250 | + if ($type != 'auto') { |
|
| 251 | + $type_label = __('Manual', 'woothemes-sensei'); |
|
| 252 | 252 | } |
| 253 | 253 | ?> |
| 254 | 254 | <td><p><?php echo $type_label; ?></p></td> |
| 255 | - <td><p><input onclick="javascript:return confirm('<?php echo addslashes( sprintf( __( 'Are you sure you want to run the \'%s\' update?', 'woothemes-sensei' ), $data['title'] ) ); ?>');" id="update-sensei" class="button<?php if( ! $update_run ) { echo ' button-primary'; } ?>" type="submit" value="<?php if( $update_run ) { _e( 'Re-run Update', 'woothemes-sensei' ); } else { _e( 'Run Update', 'woothemes-sensei' ); } ?>" name="update"></p></td> |
|
| 255 | + <td><p><input onclick="javascript:return confirm('<?php echo addslashes(sprintf(__('Are you sure you want to run the \'%s\' update?', 'woothemes-sensei'), $data['title'])); ?>');" id="update-sensei" class="button<?php if ( ! $update_run) { echo ' button-primary'; } ?>" type="submit" value="<?php if ($update_run) { _e('Re-run Update', 'woothemes-sensei'); } else { _e('Run Update', 'woothemes-sensei'); } ?>" name="update"></p></td> |
|
| 256 | 256 | </tr> |
| 257 | 257 | </form> |
| 258 | 258 | <?php |
| 259 | - if( 'alternate' == $class ) { |
|
| 259 | + if ('alternate' == $class) { |
|
| 260 | 260 | $class = ''; |
| 261 | 261 | } else { |
| 262 | 262 | $class = 'alternate'; |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | * @param string $b Second key |
| 284 | 284 | * @return integer |
| 285 | 285 | */ |
| 286 | - private function sort_updates( $a, $b ) { |
|
| 287 | - return strcmp( $a, $b ); |
|
| 286 | + private function sort_updates($a, $b) { |
|
| 287 | + return strcmp($a, $b); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -295,32 +295,32 @@ discard block |
||
| 295 | 295 | * @access public |
| 296 | 296 | * @return boolean |
| 297 | 297 | */ |
| 298 | - public function update ( $type = 'auto' ) { |
|
| 298 | + public function update($type = 'auto') { |
|
| 299 | 299 | |
| 300 | 300 | // Only allow admins to run update functions |
| 301 | - if( current_user_can( 'manage_options' ) ) { |
|
| 301 | + if (current_user_can('manage_options')) { |
|
| 302 | 302 | |
| 303 | 303 | $this->force_updates(); |
| 304 | 304 | |
| 305 | 305 | // Run through all functions |
| 306 | - foreach ( $this->updates as $version => $value ) { |
|
| 307 | - foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) { |
|
| 308 | - if ( $upgrade_type == $type ) { |
|
| 306 | + foreach ($this->updates as $version => $value) { |
|
| 307 | + foreach ($this->updates[$version] as $upgrade_type => $function_to_run) { |
|
| 308 | + if ($upgrade_type == $type) { |
|
| 309 | 309 | $updated = false; |
| 310 | 310 | // Run the update function |
| 311 | - foreach ( $function_to_run as $function_name => $update_data ) { |
|
| 312 | - if ( isset( $function_name ) && '' != $function_name ) { |
|
| 313 | - if ( ! in_array( $function_name, $this->updates_run ) ) { |
|
| 311 | + foreach ($function_to_run as $function_name => $update_data) { |
|
| 312 | + if (isset($function_name) && '' != $function_name) { |
|
| 313 | + if ( ! in_array($function_name, $this->updates_run)) { |
|
| 314 | 314 | $updated = false; |
| 315 | - if ( method_exists( $this, $function_name ) ) { |
|
| 316 | - $updated = call_user_func( array( $this, $function_name ) ); |
|
| 317 | - } elseif( function_exists( $function_name ) ) { |
|
| 318 | - $updated = call_user_func( $function_name ); |
|
| 315 | + if (method_exists($this, $function_name)) { |
|
| 316 | + $updated = call_user_func(array($this, $function_name)); |
|
| 317 | + } elseif (function_exists($function_name)) { |
|
| 318 | + $updated = call_user_func($function_name); |
|
| 319 | 319 | } else { |
| 320 | 320 | // Nothing to see here... |
| 321 | 321 | } // End If Statement |
| 322 | - if ( $updated ) { |
|
| 323 | - array_push( $this->updates_run, $function_name ); |
|
| 322 | + if ($updated) { |
|
| 323 | + array_push($this->updates_run, $function_name); |
|
| 324 | 324 | } // End If Statement |
| 325 | 325 | } |
| 326 | 326 | } // End If Statement |
@@ -329,8 +329,8 @@ discard block |
||
| 329 | 329 | } // End For Loop |
| 330 | 330 | } // End For Loop |
| 331 | 331 | |
| 332 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 333 | - update_option( Sensei()->token . '-upgrades', $this->updates_run ); |
|
| 332 | + $this->updates_run = array_unique($this->updates_run); // we only need one reference per update |
|
| 333 | + update_option(Sensei()->token.'-upgrades', $this->updates_run); |
|
| 334 | 334 | return true; |
| 335 | 335 | |
| 336 | 336 | } |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | |
| 340 | 340 | private function force_updates() { |
| 341 | 341 | |
| 342 | - if( ! isset( $_GET['page'] ) || 'sensei_updates' != $_GET['page'] ) { |
|
| 342 | + if ( ! isset($_GET['page']) || 'sensei_updates' != $_GET['page']) { |
|
| 343 | 343 | |
| 344 | 344 | // $skip_forced_updates = false; |
| 345 | 345 | // if( ! get_option( 'woothemes-sensei-force-updates', false ) ) { |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | // Force critical updates if only if lessons already exist |
| 350 | 350 | $skip_forced_updates = false; |
| 351 | - $lesson_posts = wp_count_posts( 'lesson' ); |
|
| 352 | - if( ! isset( $lesson_posts->publish ) || ! $lesson_posts->publish ) { |
|
| 351 | + $lesson_posts = wp_count_posts('lesson'); |
|
| 352 | + if ( ! isset($lesson_posts->publish) || ! $lesson_posts->publish) { |
|
| 353 | 353 | $skip_forced_updates = true; |
| 354 | 354 | } |
| 355 | 355 | |
@@ -357,69 +357,69 @@ discard block |
||
| 357 | 357 | |
| 358 | 358 | $updates_to_run = array(); |
| 359 | 359 | |
| 360 | - foreach ( $this->updates as $version => $value ) { |
|
| 361 | - foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) { |
|
| 362 | - if ( $upgrade_type == 'forced' ) { |
|
| 363 | - foreach ( $function_to_run as $function_name => $update_data ) { |
|
| 360 | + foreach ($this->updates as $version => $value) { |
|
| 361 | + foreach ($this->updates[$version] as $upgrade_type => $function_to_run) { |
|
| 362 | + if ($upgrade_type == 'forced') { |
|
| 363 | + foreach ($function_to_run as $function_name => $update_data) { |
|
| 364 | 364 | |
| 365 | - if( $skip_forced_updates ) { |
|
| 366 | - $this->set_update_run( $function_name ); |
|
| 365 | + if ($skip_forced_updates) { |
|
| 366 | + $this->set_update_run($function_name); |
|
| 367 | 367 | continue; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - $update_run = $this->has_update_run( $function_name ); |
|
| 370 | + $update_run = $this->has_update_run($function_name); |
|
| 371 | 371 | |
| 372 | - if( ! $update_run ) { |
|
| 372 | + if ( ! $update_run) { |
|
| 373 | 373 | $use_the_force = true; |
| 374 | - $updates_to_run[ $function_name ] = $update_data; |
|
| 374 | + $updates_to_run[$function_name] = $update_data; |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - if( $skip_forced_updates ) { |
|
| 381 | + if ($skip_forced_updates) { |
|
| 382 | 382 | return; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - if( $use_the_force && 0 < count( $updates_to_run ) ) { |
|
| 385 | + if ($use_the_force && 0 < count($updates_to_run)) { |
|
| 386 | 386 | |
| 387 | - $update_title = __( 'Important Sensei updates required', 'woothemes-sensei' ); |
|
| 387 | + $update_title = __('Important Sensei updates required', 'woothemes-sensei'); |
|
| 388 | 388 | |
| 389 | - $update_message = '<h1>' . __( 'Important Sensei upgrades required!', 'woothemes-sensei' ) . '</h1>' . "\n"; |
|
| 389 | + $update_message = '<h1>'.__('Important Sensei upgrades required!', 'woothemes-sensei').'</h1>'."\n"; |
|
| 390 | 390 | |
| 391 | 391 | // $update_message .= '<h4>' . sprintf( __( 'These updates are only required if you are updating from a previous version of Sensei. If you are installing Sensei for the first time, %1$syou can dismiss this page by clicking here%2$s.', 'woothemes-sensei' ), '<a href="' . add_query_arg( array( 'sensei_skip_forced_updates' => 'true' ) ) . '">', '</a>' ) . '</h4>' ."\n"; |
| 392 | 392 | |
| 393 | - $update_message .= '<p>' . __( 'The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei' ) . '</p>' . "\n"; |
|
| 393 | + $update_message .= '<p>'.__('The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei').'</p>'."\n"; |
|
| 394 | 394 | |
| 395 | - $update_message .= '<p><b>' . __( 'To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei' ) . '</b></p>' . "\n"; |
|
| 395 | + $update_message .= '<p><b>'.__('To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei').'</b></p>'."\n"; |
|
| 396 | 396 | |
| 397 | - $update_message .= '<p>' . __( 'Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei' ) . '</p>' . "\n"; |
|
| 397 | + $update_message .= '<p>'.__('Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei').'</p>'."\n"; |
|
| 398 | 398 | |
| 399 | - $update_message .= '<p><b>' . __( 'Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei' ) . '</b></p>' . "\n"; |
|
| 399 | + $update_message .= '<p><b>'.__('Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei').'</b></p>'."\n"; |
|
| 400 | 400 | |
| 401 | - $update_message .= '<ol>' . "\n"; |
|
| 401 | + $update_message .= '<ol>'."\n"; |
|
| 402 | 402 | |
| 403 | - foreach( $updates_to_run as $function => $data ) { |
|
| 403 | + foreach ($updates_to_run as $function => $data) { |
|
| 404 | 404 | |
| 405 | - if( ! isset( $data['title'] ) ) { |
|
| 405 | + if ( ! isset($data['title'])) { |
|
| 406 | 406 | break; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - $update_message .= '<li style="margin:5px 0;"><a href="' . admin_url( 'admin.php?page=sensei_updates&action=update&n=0&functions[]=' . $function ) . '" target="_blank">' . $data['title'] . '</a></li>'; |
|
| 409 | + $update_message .= '<li style="margin:5px 0;"><a href="'.admin_url('admin.php?page=sensei_updates&action=update&n=0&functions[]='.$function).'" target="_blank">'.$data['title'].'</a></li>'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - $update_message .= '</ol>' . "\n"; |
|
| 412 | + $update_message .= '</ol>'."\n"; |
|
| 413 | 413 | |
| 414 | - switch( $version ) { |
|
| 414 | + switch ($version) { |
|
| 415 | 415 | |
| 416 | 416 | case '1.7.0': |
| 417 | - $update_message .= '<p><em>' . sprintf( __( 'Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei' ), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>' ) . '</em></p>' . "\n"; |
|
| 417 | + $update_message .= '<p><em>'.sprintf(__('Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei'), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>').'</em></p>'."\n"; |
|
| 418 | 418 | break; |
| 419 | 419 | |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - wp_die( $update_message, $update_title ); |
|
| 422 | + wp_die($update_message, $update_title); |
|
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | } |
@@ -431,8 +431,8 @@ discard block |
||
| 431 | 431 | * @since 1.4.0 |
| 432 | 432 | * @return boolean |
| 433 | 433 | */ |
| 434 | - private function has_update_run( $update ) { |
|
| 435 | - if ( in_array( $update, $this->updates_run ) ) { |
|
| 434 | + private function has_update_run($update) { |
|
| 435 | + if (in_array($update, $this->updates_run)) { |
|
| 436 | 436 | return true; |
| 437 | 437 | } |
| 438 | 438 | return false; |
@@ -444,10 +444,10 @@ discard block |
||
| 444 | 444 | * @param string $update Update to process |
| 445 | 445 | * @since 1.4.0 |
| 446 | 446 | */ |
| 447 | - private function set_update_run( $update ) { |
|
| 448 | - array_push( $this->updates_run, $update ); |
|
| 449 | - $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update |
|
| 450 | - update_option( Sensei()->token . '-upgrades', $this->updates_run ); |
|
| 447 | + private function set_update_run($update) { |
|
| 448 | + array_push($this->updates_run, $update); |
|
| 449 | + $this->updates_run = array_unique($this->updates_run); // we only need one reference per update |
|
| 450 | + update_option(Sensei()->token.'-upgrades', $this->updates_run); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -458,15 +458,15 @@ discard block |
||
| 458 | 458 | * @return void |
| 459 | 459 | */ |
| 460 | 460 | public function assign_role_caps() { |
| 461 | - foreach ( $this->parent->post_types->role_caps as $role_cap_set ) { |
|
| 462 | - foreach ( $role_cap_set as $role_key => $capabilities_array ) { |
|
| 461 | + foreach ($this->parent->post_types->role_caps as $role_cap_set) { |
|
| 462 | + foreach ($role_cap_set as $role_key => $capabilities_array) { |
|
| 463 | 463 | /* Get the role. */ |
| 464 | - $role = get_role( $role_key ); |
|
| 465 | - foreach ( $capabilities_array as $cap_name ) { |
|
| 464 | + $role = get_role($role_key); |
|
| 465 | + foreach ($capabilities_array as $cap_name) { |
|
| 466 | 466 | /* If the role exists, add required capabilities for the plugin. */ |
| 467 | - if ( !empty( $role ) ) { |
|
| 468 | - if ( !$role->has_cap( $cap_name ) ) { |
|
| 469 | - $role->add_cap( $cap_name ); |
|
| 467 | + if ( ! empty($role)) { |
|
| 468 | + if ( ! $role->has_cap($cap_name)) { |
|
| 469 | + $role->add_cap($cap_name); |
|
| 470 | 470 | } // End If Statement |
| 471 | 471 | } // End If Statement |
| 472 | 472 | } // End For Loop |
@@ -483,16 +483,16 @@ discard block |
||
| 483 | 483 | * @return void |
| 484 | 484 | */ |
| 485 | 485 | public function set_default_quiz_grade_type() { |
| 486 | - $args = array( 'post_type' => 'quiz', |
|
| 486 | + $args = array('post_type' => 'quiz', |
|
| 487 | 487 | 'posts_per_page' => -1, |
| 488 | 488 | 'post_status' => 'publish', |
| 489 | 489 | 'suppress_filters' => 0 |
| 490 | 490 | ); |
| 491 | - $quizzes = get_posts( $args ); |
|
| 491 | + $quizzes = get_posts($args); |
|
| 492 | 492 | |
| 493 | - foreach( $quizzes as $quiz ) { |
|
| 494 | - update_post_meta( $quiz->ID, '_quiz_grade_type', 'auto' ); |
|
| 495 | - update_post_meta( $quiz->ID, '_quiz_grade_type_disabled', '' ); |
|
| 493 | + foreach ($quizzes as $quiz) { |
|
| 494 | + update_post_meta($quiz->ID, '_quiz_grade_type', 'auto'); |
|
| 495 | + update_post_meta($quiz->ID, '_quiz_grade_type_disabled', ''); |
|
| 496 | 496 | } |
| 497 | 497 | return true; |
| 498 | 498 | } // End set_default_quiz_grade_type |
@@ -505,23 +505,23 @@ discard block |
||
| 505 | 505 | * @return void |
| 506 | 506 | */ |
| 507 | 507 | public function set_default_question_type() { |
| 508 | - $args = array( 'post_type' => 'question', |
|
| 508 | + $args = array('post_type' => 'question', |
|
| 509 | 509 | 'posts_per_page' => -1, |
| 510 | 510 | 'post_status' => 'publish', |
| 511 | 511 | 'suppress_filters' => 0 |
| 512 | 512 | ); |
| 513 | - $questions = get_posts( $args ); |
|
| 513 | + $questions = get_posts($args); |
|
| 514 | 514 | |
| 515 | 515 | $already_run = true; |
| 516 | - foreach( $questions as $question ) { |
|
| 517 | - if( $already_run ) { |
|
| 518 | - $terms = wp_get_post_terms( $question->ID, 'question-type' ); |
|
| 519 | - if( is_array( $terms ) && count( $terms ) > 0 ) { |
|
| 516 | + foreach ($questions as $question) { |
|
| 517 | + if ($already_run) { |
|
| 518 | + $terms = wp_get_post_terms($question->ID, 'question-type'); |
|
| 519 | + if (is_array($terms) && count($terms) > 0) { |
|
| 520 | 520 | break; |
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | 523 | $already_run = false; |
| 524 | - wp_set_post_terms( $question->ID, array( 'multiple-choice' ), 'question-type' ); |
|
| 524 | + wp_set_post_terms($question->ID, array('multiple-choice'), 'question-type'); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | return true; |
@@ -534,90 +534,90 @@ discard block |
||
| 534 | 534 | * @access public |
| 535 | 535 | * @return void |
| 536 | 536 | */ |
| 537 | - public function update_question_answer_data( $n = 50, $offset = 0 ) { |
|
| 537 | + public function update_question_answer_data($n = 50, $offset = 0) { |
|
| 538 | 538 | |
| 539 | 539 | // Get Total Number of Updates to run |
| 540 | - $quiz_count_object = wp_count_posts( 'quiz' ); |
|
| 540 | + $quiz_count_object = wp_count_posts('quiz'); |
|
| 541 | 541 | $quiz_count_published = $quiz_count_object->publish; |
| 542 | 542 | |
| 543 | 543 | // Calculate if this is the last page |
| 544 | - if ( 0 == $offset ) { |
|
| 544 | + if (0 == $offset) { |
|
| 545 | 545 | $current_page = 1; |
| 546 | 546 | } else { |
| 547 | - $current_page = intval( $offset / $n ); |
|
| 547 | + $current_page = intval($offset / $n); |
|
| 548 | 548 | } // End If Statement |
| 549 | - $total_pages = intval( $quiz_count_published / $n ); |
|
| 549 | + $total_pages = intval($quiz_count_published / $n); |
|
| 550 | 550 | |
| 551 | 551 | |
| 552 | - $args = array( 'post_type' => 'quiz', |
|
| 552 | + $args = array('post_type' => 'quiz', |
|
| 553 | 553 | 'posts_per_page' => $n, |
| 554 | 554 | 'offset' => $offset, |
| 555 | 555 | 'post_status' => 'publish', |
| 556 | 556 | 'suppress_filters' => 0 |
| 557 | 557 | ); |
| 558 | - $quizzes = get_posts( $args ); |
|
| 558 | + $quizzes = get_posts($args); |
|
| 559 | 559 | |
| 560 | 560 | $old_answers = array(); |
| 561 | 561 | $right_answers = array(); |
| 562 | 562 | $old_user_answers = array(); |
| 563 | 563 | |
| 564 | - if( is_array( $quizzes ) ) { |
|
| 565 | - foreach( $quizzes as $quiz ) { |
|
| 564 | + if (is_array($quizzes)) { |
|
| 565 | + foreach ($quizzes as $quiz) { |
|
| 566 | 566 | $quiz_id = $quiz->ID; |
| 567 | 567 | |
| 568 | 568 | // Get current user answers |
| 569 | - $comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $quiz_id, 'type' => 'sensei_quiz_answers' ), true ); |
|
| 569 | + $comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => $quiz_id, 'type' => 'sensei_quiz_answers'), true); |
|
| 570 | 570 | // Need to always return an array, even with only 1 item |
| 571 | - if ( !is_array($comments) ) { |
|
| 572 | - $comments = array( $comments ); |
|
| 571 | + if ( ! is_array($comments)) { |
|
| 572 | + $comments = array($comments); |
|
| 573 | 573 | } |
| 574 | - foreach ( $comments as $comment ) { |
|
| 574 | + foreach ($comments as $comment) { |
|
| 575 | 575 | $user_id = $comment->user_id; |
| 576 | - $content = maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 577 | - $old_user_answers[ $quiz_id ][ $user_id ] = $content; |
|
| 576 | + $content = maybe_unserialize(base64_decode($comment->comment_content)); |
|
| 577 | + $old_user_answers[$quiz_id][$user_id] = $content; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | // Get correct answers |
| 581 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); |
|
| 582 | - if( is_array( $questions ) ) { |
|
| 583 | - foreach( $questions as $question ) { |
|
| 584 | - $right_answer = get_post_meta( $question->ID, '_question_right_answer', true ); |
|
| 585 | - $right_answers[ $quiz_id ][ $question->ID ] = $right_answer; |
|
| 581 | + $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id); |
|
| 582 | + if (is_array($questions)) { |
|
| 583 | + foreach ($questions as $question) { |
|
| 584 | + $right_answer = get_post_meta($question->ID, '_question_right_answer', true); |
|
| 585 | + $right_answers[$quiz_id][$question->ID] = $right_answer; |
|
| 586 | 586 | } |
| 587 | 587 | } |
| 588 | 588 | } |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - if( is_array( $right_answers ) ) { |
|
| 592 | - foreach( $right_answers as $quiz_id => $question ) { |
|
| 591 | + if (is_array($right_answers)) { |
|
| 592 | + foreach ($right_answers as $quiz_id => $question) { |
|
| 593 | 593 | $count = 0; |
| 594 | - if( is_array( $question ) ) { |
|
| 595 | - foreach( $question as $question_id => $answer ) { |
|
| 594 | + if (is_array($question)) { |
|
| 595 | + foreach ($question as $question_id => $answer) { |
|
| 596 | 596 | ++$count; |
| 597 | - if( isset( $old_user_answers[ $quiz_id ] ) ) { |
|
| 598 | - $answers_linkup[ $quiz_id ][ $count ] = $question_id; |
|
| 597 | + if (isset($old_user_answers[$quiz_id])) { |
|
| 598 | + $answers_linkup[$quiz_id][$count] = $question_id; |
|
| 599 | 599 | } |
| 600 | 600 | } |
| 601 | 601 | } |
| 602 | 602 | } |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | - if( is_array( $old_user_answers ) ) { |
|
| 606 | - foreach( $old_user_answers as $quiz_id => $user_answers ) { |
|
| 607 | - foreach( $user_answers as $user_id => $answers ) { |
|
| 608 | - foreach( $answers as $answer_id => $user_answer ) { |
|
| 609 | - $question_id = $answers_linkup[ $quiz_id ][ $answer_id ]; |
|
| 610 | - $new_user_answers[ $question_id ] = $user_answer; |
|
| 611 | - Sensei_Utils::sensei_grade_question_auto( $question_id, '', $user_answer, $user_id ); |
|
| 605 | + if (is_array($old_user_answers)) { |
|
| 606 | + foreach ($old_user_answers as $quiz_id => $user_answers) { |
|
| 607 | + foreach ($user_answers as $user_id => $answers) { |
|
| 608 | + foreach ($answers as $answer_id => $user_answer) { |
|
| 609 | + $question_id = $answers_linkup[$quiz_id][$answer_id]; |
|
| 610 | + $new_user_answers[$question_id] = $user_answer; |
|
| 611 | + Sensei_Utils::sensei_grade_question_auto($question_id, '', $user_answer, $user_id); |
|
| 612 | 612 | } |
| 613 | - $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
|
| 614 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 615 | - Sensei_Utils::sensei_save_quiz_answers( $new_user_answers, $user_id ); |
|
| 613 | + $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); |
|
| 614 | + Sensei_Utils::sensei_start_lesson($lesson_id, $user_id); |
|
| 615 | + Sensei_Utils::sensei_save_quiz_answers($new_user_answers, $user_id); |
|
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | - if ( $current_page == $total_pages ) { |
|
| 620 | + if ($current_page == $total_pages) { |
|
| 621 | 621 | return true; |
| 622 | 622 | } else { |
| 623 | 623 | return false; |
@@ -632,15 +632,15 @@ discard block |
||
| 632 | 632 | * @return boolean |
| 633 | 633 | */ |
| 634 | 634 | public function update_question_grade_points() { |
| 635 | - $args = array( 'post_type' => 'question', |
|
| 635 | + $args = array('post_type' => 'question', |
|
| 636 | 636 | 'posts_per_page' => -1, |
| 637 | 637 | 'post_status' => 'publish', |
| 638 | 638 | 'suppress_filters' => 0 |
| 639 | 639 | ); |
| 640 | - $questions = get_posts( $args ); |
|
| 640 | + $questions = get_posts($args); |
|
| 641 | 641 | |
| 642 | - foreach( $questions as $question ) { |
|
| 643 | - update_post_meta( $question->ID, '_question_grade', '1' ); |
|
| 642 | + foreach ($questions as $question) { |
|
| 643 | + update_post_meta($question->ID, '_question_grade', '1'); |
|
| 644 | 644 | } |
| 645 | 645 | return true; |
| 646 | 646 | } // End update_question_grade_points |
@@ -652,7 +652,7 @@ discard block |
||
| 652 | 652 | * @return boolean |
| 653 | 653 | */ |
| 654 | 654 | public function convert_essay_paste_questions() { |
| 655 | - $args = array( 'post_type' => 'question', |
|
| 655 | + $args = array('post_type' => 'question', |
|
| 656 | 656 | 'posts_per_page' => -1, |
| 657 | 657 | 'post_status' => 'publish', |
| 658 | 658 | 'tax_query' => array( |
@@ -664,14 +664,14 @@ discard block |
||
| 664 | 664 | ), |
| 665 | 665 | 'suppress_filters' => 0 |
| 666 | 666 | ); |
| 667 | - $questions = get_posts( $args ); |
|
| 667 | + $questions = get_posts($args); |
|
| 668 | 668 | |
| 669 | - foreach( $questions as $question ) { |
|
| 670 | - wp_set_object_terms( $question->ID, 'multi-line', 'question-type', false ); |
|
| 669 | + foreach ($questions as $question) { |
|
| 670 | + wp_set_object_terms($question->ID, 'multi-line', 'question-type', false); |
|
| 671 | 671 | |
| 672 | - $quiz_id = get_post_meta( $question->ID, '_quiz_id', true ); |
|
| 673 | - if( 0 < intval( $quiz_id ) ) { |
|
| 674 | - add_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $quiz_id . '0000', true ); |
|
| 672 | + $quiz_id = get_post_meta($question->ID, '_quiz_id', true); |
|
| 673 | + if (0 < intval($quiz_id)) { |
|
| 674 | + add_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $quiz_id.'0000', true); |
|
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | 677 | return true; |
@@ -683,33 +683,33 @@ discard block |
||
| 683 | 683 | * @since 1.5.0 |
| 684 | 684 | * @return boolean |
| 685 | 685 | */ |
| 686 | - public function set_random_question_order( $n = 50, $offset = 0 ) { |
|
| 686 | + public function set_random_question_order($n = 50, $offset = 0) { |
|
| 687 | 687 | |
| 688 | 688 | // Get Total Number of Updates to run |
| 689 | - $quiz_count_object = wp_count_posts( 'quiz' ); |
|
| 689 | + $quiz_count_object = wp_count_posts('quiz'); |
|
| 690 | 690 | $quiz_count_published = $quiz_count_object->publish; |
| 691 | 691 | |
| 692 | 692 | // Calculate if this is the last page |
| 693 | - if ( 0 == $offset ) { |
|
| 693 | + if (0 == $offset) { |
|
| 694 | 694 | $current_page = 1; |
| 695 | 695 | } else { |
| 696 | - $current_page = intval( $offset / $n ); |
|
| 696 | + $current_page = intval($offset / $n); |
|
| 697 | 697 | } // End If Statement |
| 698 | - $total_pages = intval( $quiz_count_published / $n ); |
|
| 698 | + $total_pages = intval($quiz_count_published / $n); |
|
| 699 | 699 | |
| 700 | - $args = array( 'post_type' => 'quiz', |
|
| 700 | + $args = array('post_type' => 'quiz', |
|
| 701 | 701 | 'post_status' => 'any', |
| 702 | 702 | 'posts_per_page' => $n, |
| 703 | 703 | 'offset' => $offset, |
| 704 | 704 | 'suppress_filters' => 0 |
| 705 | 705 | ); |
| 706 | - $quizzes = get_posts( $args ); |
|
| 706 | + $quizzes = get_posts($args); |
|
| 707 | 707 | |
| 708 | - foreach( $quizzes as $quiz ) { |
|
| 709 | - update_post_meta( $quiz->ID, '_random_question_order', 'yes' ); |
|
| 708 | + foreach ($quizzes as $quiz) { |
|
| 709 | + update_post_meta($quiz->ID, '_random_question_order', 'yes'); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | - if ( $current_page == $total_pages ) { |
|
| 712 | + if ($current_page == $total_pages) { |
|
| 713 | 713 | return true; |
| 714 | 714 | } else { |
| 715 | 715 | return false; |
@@ -723,37 +723,37 @@ discard block |
||
| 723 | 723 | * @since 1.5.0 |
| 724 | 724 | * @return boolean |
| 725 | 725 | */ |
| 726 | - public function set_default_show_question_count( $n = 50, $offset = 0 ) { |
|
| 726 | + public function set_default_show_question_count($n = 50, $offset = 0) { |
|
| 727 | 727 | |
| 728 | - $args = array( 'post_type' => 'quiz', |
|
| 728 | + $args = array('post_type' => 'quiz', |
|
| 729 | 729 | 'post_status' => 'any', |
| 730 | 730 | 'posts_per_page' => $n, |
| 731 | 731 | 'offset' => $offset, |
| 732 | 732 | 'meta_key' => '_show_questions', |
| 733 | 733 | 'suppress_filters' => 0 |
| 734 | 734 | ); |
| 735 | - $quizzes = get_posts( $args ); |
|
| 735 | + $quizzes = get_posts($args); |
|
| 736 | 736 | |
| 737 | - $total_quizzes = count( $quizzes ); |
|
| 737 | + $total_quizzes = count($quizzes); |
|
| 738 | 738 | |
| 739 | - if( 0 == intval( $total_quizzes ) ) { |
|
| 739 | + if (0 == intval($total_quizzes)) { |
|
| 740 | 740 | return true; |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | - foreach( $quizzes as $quiz ) { |
|
| 744 | - delete_post_meta( $quiz->ID, '_show_questions' ); |
|
| 743 | + foreach ($quizzes as $quiz) { |
|
| 744 | + delete_post_meta($quiz->ID, '_show_questions'); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - $total_pages = intval( $total_quizzes / $n ); |
|
| 747 | + $total_pages = intval($total_quizzes / $n); |
|
| 748 | 748 | |
| 749 | 749 | // Calculate if this is the last page |
| 750 | - if ( 0 == $offset ) { |
|
| 750 | + if (0 == $offset) { |
|
| 751 | 751 | $current_page = 1; |
| 752 | 752 | } else { |
| 753 | - $current_page = intval( $offset / $n ); |
|
| 753 | + $current_page = intval($offset / $n); |
|
| 754 | 754 | } // End If Statement |
| 755 | 755 | |
| 756 | - if ( $current_page == $total_pages ) { |
|
| 756 | + if ($current_page == $total_pages) { |
|
| 757 | 757 | return true; |
| 758 | 758 | } else { |
| 759 | 759 | return false; |
@@ -761,17 +761,17 @@ discard block |
||
| 761 | 761 | |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - public function remove_deleted_user_activity( $n = 50, $offset = 0 ) { |
|
| 764 | + public function remove_deleted_user_activity($n = 50, $offset = 0) { |
|
| 765 | 765 | |
| 766 | 766 | |
| 767 | 767 | // remove_filter( 'comments_clauses', array( Sensei()->admin, 'comments_admin_filter' ) ); |
| 768 | 768 | |
| 769 | - $all_activity = get_comments( array( 'status' => 'approve' ) ); |
|
| 769 | + $all_activity = get_comments(array('status' => 'approve')); |
|
| 770 | 770 | $activity_count = array(); |
| 771 | - foreach( $all_activity as $activity ) { |
|
| 772 | - if( '' == $activity->comment_type ) continue; |
|
| 773 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 774 | - if( 0 == $activity->user_id ) continue; |
|
| 771 | + foreach ($all_activity as $activity) { |
|
| 772 | + if ('' == $activity->comment_type) continue; |
|
| 773 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
| 774 | + if (0 == $activity->user_id) continue; |
|
| 775 | 775 | $activity_count[] = $activity->comment_ID; |
| 776 | 776 | } |
| 777 | 777 | |
@@ -781,35 +781,35 @@ discard block |
||
| 781 | 781 | 'status' => 'approve' |
| 782 | 782 | ); |
| 783 | 783 | |
| 784 | - $activities = get_comments( $args ); |
|
| 784 | + $activities = get_comments($args); |
|
| 785 | 785 | |
| 786 | - foreach( $activities as $activity ) { |
|
| 787 | - if( '' == $activity->comment_type ) continue; |
|
| 788 | - if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue; |
|
| 789 | - if( 0 == $activity->user_id ) continue; |
|
| 786 | + foreach ($activities as $activity) { |
|
| 787 | + if ('' == $activity->comment_type) continue; |
|
| 788 | + if (strpos('sensei_', $activity->comment_type) != 0) continue; |
|
| 789 | + if (0 == $activity->user_id) continue; |
|
| 790 | 790 | |
| 791 | - $user_exists = get_userdata( $activity->user_id ); |
|
| 791 | + $user_exists = get_userdata($activity->user_id); |
|
| 792 | 792 | |
| 793 | - if( ! $user_exists ) { |
|
| 794 | - wp_delete_comment( intval( $activity->comment_ID ), true ); |
|
| 793 | + if ( ! $user_exists) { |
|
| 794 | + wp_delete_comment(intval($activity->comment_ID), true); |
|
| 795 | 795 | wp_cache_flush(); |
| 796 | 796 | } |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | - $total_activities = count( $activity_count ); |
|
| 799 | + $total_activities = count($activity_count); |
|
| 800 | 800 | |
| 801 | - $total_pages = intval( $total_activities / $n ); |
|
| 801 | + $total_pages = intval($total_activities / $n); |
|
| 802 | 802 | |
| 803 | 803 | // Calculate if this is the last page |
| 804 | - if ( 0 == $offset ) { |
|
| 804 | + if (0 == $offset) { |
|
| 805 | 805 | $current_page = 1; |
| 806 | 806 | } else { |
| 807 | - $current_page = intval( $offset / $n ); |
|
| 807 | + $current_page = intval($offset / $n); |
|
| 808 | 808 | } // End If Statement |
| 809 | 809 | |
| 810 | 810 | // add_filter( 'comments_clauses', array( Sensei()->admin, 'comments_admin_filter' ) ); |
| 811 | 811 | |
| 812 | - if ( $current_page >= $total_pages ) { |
|
| 812 | + if ($current_page >= $total_pages) { |
|
| 813 | 813 | return true; |
| 814 | 814 | } else { |
| 815 | 815 | return false; |
@@ -818,16 +818,16 @@ discard block |
||
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | public function add_teacher_role() { |
| 821 | - add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ), array( 'read' => true, 'manage_sensei_grades' => true ) ); |
|
| 821 | + add_role('teacher', __('Teacher', 'woothemes-sensei'), array('read' => true, 'manage_sensei_grades' => true)); |
|
| 822 | 822 | return true; |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | public function add_sensei_caps() { |
| 826 | - $role = get_role( 'administrator' ); |
|
| 826 | + $role = get_role('administrator'); |
|
| 827 | 827 | |
| 828 | - if( ! is_null( $role ) ) { |
|
| 829 | - $role->add_cap( 'manage_sensei' ); |
|
| 830 | - $role->add_cap( 'manage_sensei_grades' ); |
|
| 828 | + if ( ! is_null($role)) { |
|
| 829 | + $role->add_cap('manage_sensei'); |
|
| 830 | + $role->add_cap('manage_sensei_grades'); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | return true; |
@@ -841,16 +841,16 @@ discard block |
||
| 841 | 841 | 'suppress_filters' => 0 |
| 842 | 842 | ); |
| 843 | 843 | |
| 844 | - $questions = get_posts( $args ); |
|
| 844 | + $questions = get_posts($args); |
|
| 845 | 845 | |
| 846 | - foreach( $questions as $question ) { |
|
| 846 | + foreach ($questions as $question) { |
|
| 847 | 847 | |
| 848 | - if( ! isset( $question->ID ) ) continue; |
|
| 848 | + if ( ! isset($question->ID)) continue; |
|
| 849 | 849 | |
| 850 | - $quiz_id = get_post_meta( $question->ID, '_quiz_id', true ); |
|
| 850 | + $quiz_id = get_post_meta($question->ID, '_quiz_id', true); |
|
| 851 | 851 | |
| 852 | - $question_order = get_post_meta( $question->ID, '_quiz_question_order', true ); |
|
| 853 | - update_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $question_order ); |
|
| 852 | + $question_order = get_post_meta($question->ID, '_quiz_question_order', true); |
|
| 853 | + update_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $question_order); |
|
| 854 | 854 | |
| 855 | 855 | } |
| 856 | 856 | |
@@ -859,15 +859,15 @@ discard block |
||
| 859 | 859 | |
| 860 | 860 | public function update_quiz_settings() { |
| 861 | 861 | |
| 862 | - $settings = get_option( 'woothemes-sensei-settings', array() ); |
|
| 862 | + $settings = get_option('woothemes-sensei-settings', array()); |
|
| 863 | 863 | |
| 864 | 864 | $lesson_completion = false; |
| 865 | - if( isset( $settings['lesson_completion'] ) ) { |
|
| 865 | + if (isset($settings['lesson_completion'])) { |
|
| 866 | 866 | $lesson_completion = $settings['lesson_completion']; |
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | $reset_quiz_allowed = false; |
| 870 | - if( isset( $settings['quiz_reset_allowed'] ) ) { |
|
| 870 | + if (isset($settings['quiz_reset_allowed'])) { |
|
| 871 | 871 | $reset_quiz_allowed = $settings['quiz_reset_allowed']; |
| 872 | 872 | } |
| 873 | 873 | |
@@ -878,20 +878,20 @@ discard block |
||
| 878 | 878 | 'suppress_filters' => 0 |
| 879 | 879 | ); |
| 880 | 880 | |
| 881 | - $quizzes = get_posts( $args ); |
|
| 881 | + $quizzes = get_posts($args); |
|
| 882 | 882 | |
| 883 | - foreach( $quizzes as $quiz ) { |
|
| 883 | + foreach ($quizzes as $quiz) { |
|
| 884 | 884 | |
| 885 | - if( ! isset( $quiz->ID ) ) continue; |
|
| 885 | + if ( ! isset($quiz->ID)) continue; |
|
| 886 | 886 | |
| 887 | - if( isset( $lesson_completion ) && 'passed' == $lesson_completion ) { |
|
| 888 | - update_post_meta( $quiz->ID, '_pass_required', 'on' ); |
|
| 887 | + if (isset($lesson_completion) && 'passed' == $lesson_completion) { |
|
| 888 | + update_post_meta($quiz->ID, '_pass_required', 'on'); |
|
| 889 | 889 | } else { |
| 890 | - update_post_meta( $quiz->ID, '_quiz_passmark', 0 ); |
|
| 890 | + update_post_meta($quiz->ID, '_quiz_passmark', 0); |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | - if( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) { |
|
| 894 | - update_post_meta( $quiz->ID, '_enable_quiz_reset', 'on' ); |
|
| 893 | + if (isset($reset_quiz_allowed) && $reset_quiz_allowed) { |
|
| 894 | + update_post_meta($quiz->ID, '_enable_quiz_reset', 'on'); |
|
| 895 | 895 | } |
| 896 | 896 | } |
| 897 | 897 | |
@@ -906,22 +906,22 @@ discard block |
||
| 906 | 906 | 'suppress_filters' => 0 |
| 907 | 907 | ); |
| 908 | 908 | |
| 909 | - $lessons = get_posts( $args ); |
|
| 909 | + $lessons = get_posts($args); |
|
| 910 | 910 | |
| 911 | - foreach( $lessons as $lesson ) { |
|
| 911 | + foreach ($lessons as $lesson) { |
|
| 912 | 912 | |
| 913 | - if( ! isset( $lesson->ID ) ) continue; |
|
| 913 | + if ( ! isset($lesson->ID)) continue; |
|
| 914 | 914 | |
| 915 | - $course_id = get_post_meta( $lesson->ID, '_lesson_course', true); |
|
| 915 | + $course_id = get_post_meta($lesson->ID, '_lesson_course', true); |
|
| 916 | 916 | |
| 917 | - if( $course_id ) { |
|
| 918 | - update_post_meta( $lesson->ID, '_order_' . $course_id, 0 ); |
|
| 917 | + if ($course_id) { |
|
| 918 | + update_post_meta($lesson->ID, '_order_'.$course_id, 0); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | - $module = Sensei()->modules->get_lesson_module( $lesson->ID ); |
|
| 921 | + $module = Sensei()->modules->get_lesson_module($lesson->ID); |
|
| 922 | 922 | |
| 923 | - if( $module ) { |
|
| 924 | - update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 ); |
|
| 923 | + if ($module) { |
|
| 924 | + update_post_meta($lesson->ID, '_order_module_'.$module->term_id, 0); |
|
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | } |
@@ -930,10 +930,10 @@ discard block |
||
| 930 | 930 | } |
| 931 | 931 | |
| 932 | 932 | public function add_editor_caps() { |
| 933 | - $role = get_role( 'editor' ); |
|
| 933 | + $role = get_role('editor'); |
|
| 934 | 934 | |
| 935 | - if( ! is_null( $role ) ) { |
|
| 936 | - $role->add_cap( 'manage_sensei_grades' ); |
|
| 935 | + if ( ! is_null($role)) { |
|
| 936 | + $role->add_cap('manage_sensei_grades'); |
|
| 937 | 937 | } |
| 938 | 938 | |
| 939 | 939 | return true; |
@@ -952,26 +952,26 @@ discard block |
||
| 952 | 952 | WHERE m.meta_key = '_question_right_answer' AND m.meta_value LIKE '%|%' AND m.meta_value NOT LIKE '%||%' |
| 953 | 953 | AND m.post_id = tr.object_id AND tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.term_id = t.term_id |
| 954 | 954 | AND tt.taxonomy = 'question-type' AND t.slug = 'gap-fill'"; |
| 955 | - $wpdb->query( $sql ); |
|
| 955 | + $wpdb->query($sql); |
|
| 956 | 956 | |
| 957 | 957 | return true; |
| 958 | 958 | } |
| 959 | 959 | |
| 960 | - public function update_quiz_lesson_relationship( $n = 50, $offset = 0 ) { |
|
| 961 | - $count_object = wp_count_posts( 'quiz' ); |
|
| 960 | + public function update_quiz_lesson_relationship($n = 50, $offset = 0) { |
|
| 961 | + $count_object = wp_count_posts('quiz'); |
|
| 962 | 962 | |
| 963 | 963 | $count_published = 0; |
| 964 | - foreach ( $count_object AS $status => $count ) { |
|
| 964 | + foreach ($count_object AS $status => $count) { |
|
| 965 | 965 | $count_published += $count; |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | // Calculate if this is the last page |
| 969 | - if ( 0 == $offset ) { |
|
| 969 | + if (0 == $offset) { |
|
| 970 | 970 | $current_page = 1; |
| 971 | 971 | } else { |
| 972 | - $current_page = intval( $offset / $n ); |
|
| 972 | + $current_page = intval($offset / $n); |
|
| 973 | 973 | } |
| 974 | - $total_pages = ceil( $count_published / $n ); |
|
| 974 | + $total_pages = ceil($count_published / $n); |
|
| 975 | 975 | |
| 976 | 976 | $args = array( |
| 977 | 977 | 'post_type' => 'quiz', |
@@ -980,52 +980,52 @@ discard block |
||
| 980 | 980 | 'post_status' => 'any' |
| 981 | 981 | ); |
| 982 | 982 | |
| 983 | - $quizzes = get_posts( $args ); |
|
| 983 | + $quizzes = get_posts($args); |
|
| 984 | 984 | |
| 985 | - foreach( $quizzes as $quiz ) { |
|
| 985 | + foreach ($quizzes as $quiz) { |
|
| 986 | 986 | |
| 987 | - if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) continue; |
|
| 987 | + if ( ! isset($quiz->ID) || 0 != $quiz->post_parent) continue; |
|
| 988 | 988 | |
| 989 | - $lesson_id = get_post_meta( $quiz->ID, '_quiz_lesson', true ); |
|
| 989 | + $lesson_id = get_post_meta($quiz->ID, '_quiz_lesson', true); |
|
| 990 | 990 | |
| 991 | - if( empty( $lesson_id ) ) continue; |
|
| 991 | + if (empty($lesson_id)) continue; |
|
| 992 | 992 | |
| 993 | 993 | $data = array( |
| 994 | 994 | 'ID' => $quiz->ID, |
| 995 | 995 | 'post_parent' => $lesson_id, |
| 996 | 996 | ); |
| 997 | - wp_update_post( $data ); |
|
| 997 | + wp_update_post($data); |
|
| 998 | 998 | |
| 999 | - update_post_meta( $lesson_id, '_lesson_quiz', $quiz->ID ); |
|
| 999 | + update_post_meta($lesson_id, '_lesson_quiz', $quiz->ID); |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | - if ( $current_page == $total_pages || 0 == $total_pages ) { |
|
| 1002 | + if ($current_page == $total_pages || 0 == $total_pages) { |
|
| 1003 | 1003 | return true; |
| 1004 | 1004 | } else { |
| 1005 | 1005 | return false; |
| 1006 | 1006 | } |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - function status_changes_fix_lessons( $n = 50, $offset = 0 ) { |
|
| 1009 | + function status_changes_fix_lessons($n = 50, $offset = 0) { |
|
| 1010 | 1010 | global $wpdb; |
| 1011 | 1011 | |
| 1012 | - $count_object = wp_count_posts( 'lesson' ); |
|
| 1012 | + $count_object = wp_count_posts('lesson'); |
|
| 1013 | 1013 | $count_published = 0; |
| 1014 | - foreach ( $count_object AS $status => $count ) { |
|
| 1014 | + foreach ($count_object AS $status => $count) { |
|
| 1015 | 1015 | $count_published += $count; |
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | - if ( 0 == $count_published ) { |
|
| 1018 | + if (0 == $count_published) { |
|
| 1019 | 1019 | return true; |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | // Calculate if this is the last page |
| 1023 | - if ( 0 == $offset ) { |
|
| 1023 | + if (0 == $offset) { |
|
| 1024 | 1024 | $current_page = 1; |
| 1025 | 1025 | } else { |
| 1026 | - $current_page = intval( $offset / $n ); |
|
| 1026 | + $current_page = intval($offset / $n); |
|
| 1027 | 1027 | } |
| 1028 | - $total_pages = ceil( $count_published / $n ); |
|
| 1028 | + $total_pages = ceil($count_published / $n); |
|
| 1029 | 1029 | |
| 1030 | 1030 | // Get all Lessons with (and without) Quizzes... |
| 1031 | 1031 | $args = array( |
@@ -1035,26 +1035,26 @@ discard block |
||
| 1035 | 1035 | 'offset' => $offset, |
| 1036 | 1036 | 'fields' => 'ids' |
| 1037 | 1037 | ); |
| 1038 | - $lesson_ids = get_posts( $args ); |
|
| 1038 | + $lesson_ids = get_posts($args); |
|
| 1039 | 1039 | |
| 1040 | 1040 | // ...get all Quiz IDs for the above Lessons |
| 1041 | - $id_list = join( ',', $lesson_ids ); |
|
| 1042 | - $meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A ); |
|
| 1041 | + $id_list = join(',', $lesson_ids); |
|
| 1042 | + $meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A); |
|
| 1043 | 1043 | $lesson_quiz_ids = array(); |
| 1044 | - if ( !empty($meta_list) ) { |
|
| 1045 | - foreach ( $meta_list as $metarow ) { |
|
| 1044 | + if ( ! empty($meta_list)) { |
|
| 1045 | + foreach ($meta_list as $metarow) { |
|
| 1046 | 1046 | $lesson_id = $metarow['meta_value']; |
| 1047 | 1047 | $quiz_id = $metarow['post_id']; |
| 1048 | - $lesson_quiz_ids[ $lesson_id ] = $quiz_id; |
|
| 1048 | + $lesson_quiz_ids[$lesson_id] = $quiz_id; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | 1052 | // ...check all Quiz IDs for questions |
| 1053 | - $id_list = join( ',', array_values($lesson_quiz_ids) ); |
|
| 1054 | - $meta_list = $wpdb->get_results( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A ); |
|
| 1053 | + $id_list = join(',', array_values($lesson_quiz_ids)); |
|
| 1054 | + $meta_list = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A); |
|
| 1055 | 1055 | $lesson_quiz_ids_with_questions = array(); |
| 1056 | - if ( !empty($meta_list) ) { |
|
| 1057 | - foreach ( $meta_list as $metarow ) { |
|
| 1056 | + if ( ! empty($meta_list)) { |
|
| 1057 | + foreach ($meta_list as $metarow) { |
|
| 1058 | 1058 | $quiz_id = $metarow['meta_value']; |
| 1059 | 1059 | $lesson_quiz_ids_with_questions[] = $quiz_id; |
| 1060 | 1060 | } |
@@ -1062,49 +1062,49 @@ discard block |
||
| 1062 | 1062 | |
| 1063 | 1063 | // For each quiz check there are questions, if not remove the corresponding meta keys from Quizzes and Lessons |
| 1064 | 1064 | // if there are questions on the quiz add the corresponding meta keys to Quizzes and Lessons |
| 1065 | - $d_count = $a_count =0; |
|
| 1066 | - foreach ( $lesson_quiz_ids AS $lesson_id => $quiz_id ) { |
|
| 1067 | - if ( !in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) { |
|
| 1065 | + $d_count = $a_count = 0; |
|
| 1066 | + foreach ($lesson_quiz_ids AS $lesson_id => $quiz_id) { |
|
| 1067 | + if ( ! in_array($quiz_id, $lesson_quiz_ids_with_questions)) { |
|
| 1068 | 1068 | |
| 1069 | 1069 | // Quiz has no questions, drop the corresponding data |
| 1070 | - delete_post_meta( $quiz_id, '_pass_required' ); |
|
| 1071 | - delete_post_meta( $quiz_id, '_quiz_passmark' ); |
|
| 1072 | - delete_post_meta( $lesson_id, '_quiz_has_questions' ); |
|
| 1070 | + delete_post_meta($quiz_id, '_pass_required'); |
|
| 1071 | + delete_post_meta($quiz_id, '_quiz_passmark'); |
|
| 1072 | + delete_post_meta($lesson_id, '_quiz_has_questions'); |
|
| 1073 | 1073 | $d_count++; |
| 1074 | 1074 | } |
| 1075 | - else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) { |
|
| 1075 | + else if (in_array($quiz_id, $lesson_quiz_ids_with_questions)) { |
|
| 1076 | 1076 | |
| 1077 | 1077 | // Quiz has no questions, drop the corresponding data |
| 1078 | - update_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1078 | + update_post_meta($lesson_id, '_quiz_has_questions', true); |
|
| 1079 | 1079 | $a_count++; |
| 1080 | 1080 | } |
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | - if ( $current_page == $total_pages ) { |
|
| 1083 | + if ($current_page == $total_pages) { |
|
| 1084 | 1084 | return true; |
| 1085 | 1085 | } else { |
| 1086 | 1086 | return false; |
| 1087 | 1087 | } |
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | - function status_changes_convert_lessons( $n = 50, $offset = 0 ) { |
|
| 1090 | + function status_changes_convert_lessons($n = 50, $offset = 0) { |
|
| 1091 | 1091 | global $wpdb; |
| 1092 | 1092 | |
| 1093 | - wp_defer_comment_counting( true ); |
|
| 1093 | + wp_defer_comment_counting(true); |
|
| 1094 | 1094 | |
| 1095 | - $user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " ); |
|
| 1095 | + $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users "); |
|
| 1096 | 1096 | |
| 1097 | - if ( 0 == $user_count_result ) { |
|
| 1097 | + if (0 == $user_count_result) { |
|
| 1098 | 1098 | return true; |
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | - if ( 0 == $offset ) { |
|
| 1101 | + if (0 == $offset) { |
|
| 1102 | 1102 | $current_page = 1; |
| 1103 | 1103 | } else { |
| 1104 | - $current_page = intval( $offset / $n ); |
|
| 1104 | + $current_page = intval($offset / $n); |
|
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | - $total_pages = ceil( $user_count_result / $n ); |
|
| 1107 | + $total_pages = ceil($user_count_result / $n); |
|
| 1108 | 1108 | |
| 1109 | 1109 | // Get all Lessons with Quizzes... |
| 1110 | 1110 | $args = array( |
@@ -1119,34 +1119,34 @@ discard block |
||
| 1119 | 1119 | ), |
| 1120 | 1120 | 'fields' => 'ids' |
| 1121 | 1121 | ); |
| 1122 | - $lesson_ids_with_quizzes = get_posts( $args ); |
|
| 1122 | + $lesson_ids_with_quizzes = get_posts($args); |
|
| 1123 | 1123 | // ...get all Quiz IDs for the above Lessons |
| 1124 | - $id_list = join( ',', $lesson_ids_with_quizzes ); |
|
| 1125 | - $meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A ); |
|
| 1124 | + $id_list = join(',', $lesson_ids_with_quizzes); |
|
| 1125 | + $meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A); |
|
| 1126 | 1126 | $lesson_quiz_ids = array(); |
| 1127 | - if ( !empty($meta_list) ) { |
|
| 1128 | - foreach ( $meta_list as $metarow ) { |
|
| 1127 | + if ( ! empty($meta_list)) { |
|
| 1128 | + foreach ($meta_list as $metarow) { |
|
| 1129 | 1129 | $lesson_id = $metarow['meta_value']; |
| 1130 | 1130 | $quiz_id = $metarow['post_id']; |
| 1131 | - $lesson_quiz_ids[ $lesson_id ] = $quiz_id; |
|
| 1131 | + $lesson_quiz_ids[$lesson_id] = $quiz_id; |
|
| 1132 | 1132 | } |
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | // ...get all Pass Required & Passmarks for the above Lesson/Quizzes |
| 1136 | - $id_list = join( ',', array_values($lesson_quiz_ids) ); |
|
| 1137 | - $meta_list = $wpdb->get_results( "SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A ); |
|
| 1136 | + $id_list = join(',', array_values($lesson_quiz_ids)); |
|
| 1137 | + $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A); |
|
| 1138 | 1138 | $quizzes_pass_required = $quizzes_passmarks = array(); |
| 1139 | - if ( !empty($meta_list) ) { |
|
| 1140 | - foreach ( $meta_list as $metarow ) { |
|
| 1141 | - if ( !empty($metarow['meta_value']) ) { |
|
| 1139 | + if ( ! empty($meta_list)) { |
|
| 1140 | + foreach ($meta_list as $metarow) { |
|
| 1141 | + if ( ! empty($metarow['meta_value'])) { |
|
| 1142 | 1142 | $quiz_id = $metarow['post_id']; |
| 1143 | 1143 | $key = $metarow['meta_key']; |
| 1144 | 1144 | $value = $metarow['meta_value']; |
| 1145 | - if ( '_pass_required' == $key ) { |
|
| 1146 | - $quizzes_pass_required[ $quiz_id ] = $value; |
|
| 1145 | + if ('_pass_required' == $key) { |
|
| 1146 | + $quizzes_pass_required[$quiz_id] = $value; |
|
| 1147 | 1147 | } |
| 1148 | - if ( '_quiz_passmark' == $key ) { |
|
| 1149 | - $quizzes_passmarks[ $quiz_id ] = $value; |
|
| 1148 | + if ('_quiz_passmark' == $key) { |
|
| 1149 | + $quizzes_passmarks[$quiz_id] = $value; |
|
| 1150 | 1150 | } |
| 1151 | 1151 | } |
| 1152 | 1152 | } |
@@ -1160,41 +1160,41 @@ discard block |
||
| 1160 | 1160 | $check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_lesson_status' "; |
| 1161 | 1161 | |
| 1162 | 1162 | // $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time? |
| 1163 | - $user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) ); |
|
| 1163 | + $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset)); |
|
| 1164 | 1164 | |
| 1165 | - foreach ( $user_ids AS $user_id ) { |
|
| 1165 | + foreach ($user_ids AS $user_id) { |
|
| 1166 | 1166 | |
| 1167 | 1167 | $lesson_ends = $lesson_grades = $lesson_answers = array(); |
| 1168 | 1168 | |
| 1169 | 1169 | // Pre-process the lesson ends |
| 1170 | - $_lesson_ends = $wpdb->get_results( $wpdb->prepare($end_sql, $user_id), ARRAY_A ); |
|
| 1171 | - foreach ( $_lesson_ends as $lesson_end ) { |
|
| 1170 | + $_lesson_ends = $wpdb->get_results($wpdb->prepare($end_sql, $user_id), ARRAY_A); |
|
| 1171 | + foreach ($_lesson_ends as $lesson_end) { |
|
| 1172 | 1172 | // This will overwrite existing entries with the newer ones |
| 1173 | - $lesson_ends[ $lesson_end['comment_post_ID'] ] = $lesson_end['comment_date']; |
|
| 1173 | + $lesson_ends[$lesson_end['comment_post_ID']] = $lesson_end['comment_date']; |
|
| 1174 | 1174 | } |
| 1175 | - unset( $_lesson_ends ); |
|
| 1175 | + unset($_lesson_ends); |
|
| 1176 | 1176 | |
| 1177 | 1177 | // Pre-process the lesson grades |
| 1178 | - $_lesson_grades = $wpdb->get_results( $wpdb->prepare($grade_sql, $user_id), ARRAY_A ); |
|
| 1179 | - foreach ( $_lesson_grades as $lesson_grade ) { |
|
| 1178 | + $_lesson_grades = $wpdb->get_results($wpdb->prepare($grade_sql, $user_id), ARRAY_A); |
|
| 1179 | + foreach ($_lesson_grades as $lesson_grade) { |
|
| 1180 | 1180 | // This will overwrite existing entries with the newer ones (assuming the grade is higher) |
| 1181 | - if ( empty($lesson_grades[ $lesson_grade['comment_post_ID'] ]) || $lesson_grades[ $lesson_grade['comment_post_ID'] ] < $lesson_grade['comment_content'] ) { |
|
| 1182 | - $lesson_grades[ $lesson_grade['comment_post_ID'] ] = $lesson_grade['comment_content']; |
|
| 1181 | + if (empty($lesson_grades[$lesson_grade['comment_post_ID']]) || $lesson_grades[$lesson_grade['comment_post_ID']] < $lesson_grade['comment_content']) { |
|
| 1182 | + $lesson_grades[$lesson_grade['comment_post_ID']] = $lesson_grade['comment_content']; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | } |
| 1185 | - unset( $_lesson_grades ); |
|
| 1185 | + unset($_lesson_grades); |
|
| 1186 | 1186 | |
| 1187 | 1187 | // Pre-process the lesson answers |
| 1188 | - $_lesson_answers = $wpdb->get_results( $wpdb->prepare($answers_sql, $user_id), ARRAY_A ); |
|
| 1189 | - foreach ( $_lesson_answers as $lesson_answer ) { |
|
| 1188 | + $_lesson_answers = $wpdb->get_results($wpdb->prepare($answers_sql, $user_id), ARRAY_A); |
|
| 1189 | + foreach ($_lesson_answers as $lesson_answer) { |
|
| 1190 | 1190 | // This will overwrite existing entries with the newer ones |
| 1191 | - $lesson_answers[ $lesson_answer['comment_post_ID'] ] = $lesson_answer['comment_content']; |
|
| 1191 | + $lesson_answers[$lesson_answer['comment_post_ID']] = $lesson_answer['comment_content']; |
|
| 1192 | 1192 | } |
| 1193 | - unset( $_lesson_answers ); |
|
| 1193 | + unset($_lesson_answers); |
|
| 1194 | 1194 | |
| 1195 | 1195 | // Grab all the lesson starts for the user |
| 1196 | - $lesson_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A ); |
|
| 1197 | - foreach ( $lesson_starts as $lesson_log ) { |
|
| 1196 | + $lesson_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A); |
|
| 1197 | + foreach ($lesson_starts as $lesson_log) { |
|
| 1198 | 1198 | |
| 1199 | 1199 | $lesson_id = $lesson_log['comment_post_ID']; |
| 1200 | 1200 | |
@@ -1207,23 +1207,23 @@ discard block |
||
| 1207 | 1207 | 'start' => $status_date, |
| 1208 | 1208 | ); |
| 1209 | 1209 | // Check if there is a lesson end |
| 1210 | - if ( !empty($lesson_ends[$lesson_id]) ) { |
|
| 1210 | + if ( ! empty($lesson_ends[$lesson_id])) { |
|
| 1211 | 1211 | $status_date = $lesson_ends[$lesson_id]; |
| 1212 | 1212 | // Check lesson has quiz |
| 1213 | - if ( !empty( $lesson_quiz_ids[$lesson_id] ) ) { |
|
| 1213 | + if ( ! empty($lesson_quiz_ids[$lesson_id])) { |
|
| 1214 | 1214 | // Check for the quiz answers |
| 1215 | - if ( !empty($lesson_answers[$quiz_id]) ) { |
|
| 1215 | + if ( ! empty($lesson_answers[$quiz_id])) { |
|
| 1216 | 1216 | $meta_data['questions_asked'] = $lesson_answers[$quiz_id]; |
| 1217 | 1217 | } |
| 1218 | 1218 | // Check if there is a quiz grade |
| 1219 | 1219 | $quiz_id = $lesson_quiz_ids[$lesson_id]; |
| 1220 | - if ( !empty($lesson_grades[$quiz_id]) ) { |
|
| 1220 | + if ( ! empty($lesson_grades[$quiz_id])) { |
|
| 1221 | 1221 | $meta_data['grade'] = $quiz_grade = $lesson_grades[$quiz_id]; |
| 1222 | 1222 | // Check if the user has to get the passmark and has or not |
| 1223 | - if ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] <= $quiz_grade ) { |
|
| 1223 | + if ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] <= $quiz_grade) { |
|
| 1224 | 1224 | $status = 'passed'; |
| 1225 | 1225 | } |
| 1226 | - elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) { |
|
| 1226 | + elseif ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] > $quiz_grade) { |
|
| 1227 | 1227 | $status = 'failed'; |
| 1228 | 1228 | } |
| 1229 | 1229 | else { |
@@ -1251,26 +1251,26 @@ discard block |
||
| 1251 | 1251 | 'comment_author' => '', |
| 1252 | 1252 | ); |
| 1253 | 1253 | // Check it doesn't already exist |
| 1254 | - $sql = $wpdb->prepare( $check_existing_sql, $lesson_id, $user_id ); |
|
| 1255 | - $comment_ID = $wpdb->get_var( $sql ); |
|
| 1256 | - if ( !$comment_ID ) { |
|
| 1254 | + $sql = $wpdb->prepare($check_existing_sql, $lesson_id, $user_id); |
|
| 1255 | + $comment_ID = $wpdb->get_var($sql); |
|
| 1256 | + if ( ! $comment_ID) { |
|
| 1257 | 1257 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
| 1258 | 1258 | $wpdb->insert($wpdb->comments, $data); |
| 1259 | 1259 | $comment_ID = (int) $wpdb->insert_id; |
| 1260 | 1260 | |
| 1261 | - if ( $comment_ID && !empty($meta_data) ) { |
|
| 1262 | - foreach ( $meta_data as $key => $value ) { |
|
| 1261 | + if ($comment_ID && ! empty($meta_data)) { |
|
| 1262 | + foreach ($meta_data as $key => $value) { |
|
| 1263 | 1263 | // Bypassing WP add_comment_meta(() so no actions/filters are run |
| 1264 | - if ( $wpdb->get_var( $wpdb->prepare( |
|
| 1264 | + if ($wpdb->get_var($wpdb->prepare( |
|
| 1265 | 1265 | "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ", |
| 1266 | - $comment_ID, $key ) ) ) { |
|
| 1266 | + $comment_ID, $key ))) { |
|
| 1267 | 1267 | continue; // Found the meta data already |
| 1268 | 1268 | } |
| 1269 | - $result = $wpdb->insert( $wpdb->commentmeta, array( |
|
| 1269 | + $result = $wpdb->insert($wpdb->commentmeta, array( |
|
| 1270 | 1270 | 'comment_id' => $comment_ID, |
| 1271 | 1271 | 'meta_key' => $key, |
| 1272 | 1272 | 'meta_value' => $value |
| 1273 | - ) ); |
|
| 1273 | + )); |
|
| 1274 | 1274 | } |
| 1275 | 1275 | } |
| 1276 | 1276 | } |
@@ -1278,40 +1278,40 @@ discard block |
||
| 1278 | 1278 | } |
| 1279 | 1279 | $wpdb->flush(); |
| 1280 | 1280 | |
| 1281 | - if ( $current_page == $total_pages ) { |
|
| 1281 | + if ($current_page == $total_pages) { |
|
| 1282 | 1282 | return true; |
| 1283 | 1283 | } else { |
| 1284 | 1284 | return false; |
| 1285 | 1285 | } |
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | - function status_changes_convert_courses( $n = 50, $offset = 0 ) { |
|
| 1288 | + function status_changes_convert_courses($n = 50, $offset = 0) { |
|
| 1289 | 1289 | global $wpdb; |
| 1290 | 1290 | |
| 1291 | - wp_defer_comment_counting( true ); |
|
| 1291 | + wp_defer_comment_counting(true); |
|
| 1292 | 1292 | |
| 1293 | - $user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " ); |
|
| 1293 | + $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users "); |
|
| 1294 | 1294 | |
| 1295 | - if ( 0 == $user_count_result ) { |
|
| 1295 | + if (0 == $user_count_result) { |
|
| 1296 | 1296 | return true; |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | - if ( 0 == $offset ) { |
|
| 1299 | + if (0 == $offset) { |
|
| 1300 | 1300 | $current_page = 1; |
| 1301 | 1301 | } else { |
| 1302 | - $current_page = intval( $offset / $n ); |
|
| 1302 | + $current_page = intval($offset / $n); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | - $total_pages = ceil( $user_count_result / $n ); |
|
| 1305 | + $total_pages = ceil($user_count_result / $n); |
|
| 1306 | 1306 | |
| 1307 | 1307 | // Get all Lesson => Course relationships |
| 1308 | - $meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A ); |
|
| 1308 | + $meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A); |
|
| 1309 | 1309 | $course_lesson_ids = array(); |
| 1310 | - if ( !empty($meta_list) ) { |
|
| 1311 | - foreach ( $meta_list as $metarow ) { |
|
| 1310 | + if ( ! empty($meta_list)) { |
|
| 1311 | + foreach ($meta_list as $metarow) { |
|
| 1312 | 1312 | $lesson_id = $metarow['post_id']; |
| 1313 | 1313 | $course_id = $metarow['meta_value']; |
| 1314 | - $course_lesson_ids[ $course_id ][] = $lesson_id; |
|
| 1314 | + $course_lesson_ids[$course_id][] = $lesson_id; |
|
| 1315 | 1315 | } |
| 1316 | 1316 | } |
| 1317 | 1317 | |
@@ -1321,13 +1321,13 @@ discard block |
||
| 1321 | 1321 | $check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_course_status' "; |
| 1322 | 1322 | |
| 1323 | 1323 | // $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time? |
| 1324 | - $user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) ); |
|
| 1324 | + $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset)); |
|
| 1325 | 1325 | |
| 1326 | - foreach ( $user_ids AS $user_id ) { |
|
| 1326 | + foreach ($user_ids AS $user_id) { |
|
| 1327 | 1327 | |
| 1328 | 1328 | // Grab all the course starts for the user |
| 1329 | - $course_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A ); |
|
| 1330 | - foreach ( $course_starts as $course_log ) { |
|
| 1329 | + $course_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A); |
|
| 1330 | + foreach ($course_starts as $course_log) { |
|
| 1331 | 1331 | |
| 1332 | 1332 | $course_id = $course_log['comment_post_ID']; |
| 1333 | 1333 | |
@@ -1342,23 +1342,23 @@ discard block |
||
| 1342 | 1342 | 'percent' => 0, |
| 1343 | 1343 | ); |
| 1344 | 1344 | // Check if the course has lessons |
| 1345 | - if ( !empty( $course_lesson_ids[$course_id] ) ) { |
|
| 1345 | + if ( ! empty($course_lesson_ids[$course_id])) { |
|
| 1346 | 1346 | |
| 1347 | 1347 | $lessons_completed = 0; |
| 1348 | - $total_lessons = count( $course_lesson_ids[ $course_id ] ); |
|
| 1348 | + $total_lessons = count($course_lesson_ids[$course_id]); |
|
| 1349 | 1349 | |
| 1350 | 1350 | // Don't use prepare as we need to provide the id join |
| 1351 | - $sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[ $course_id ]) ); |
|
| 1351 | + $sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[$course_id])); |
|
| 1352 | 1352 | // Get all lesson statuses for this Courses' lessons |
| 1353 | - $lesson_statuses = $wpdb->get_results( $sql, ARRAY_A ); |
|
| 1353 | + $lesson_statuses = $wpdb->get_results($sql, ARRAY_A); |
|
| 1354 | 1354 | // Not enough lesson statuses, thus cannot be complete |
| 1355 | - if ( $total_lessons > count($lesson_statuses) ) { |
|
| 1355 | + if ($total_lessons > count($lesson_statuses)) { |
|
| 1356 | 1356 | $status = 'in-progress'; |
| 1357 | 1357 | } |
| 1358 | 1358 | // Count each lesson to work out the overall percentage |
| 1359 | - foreach ( $lesson_statuses as $lesson_status ) { |
|
| 1359 | + foreach ($lesson_statuses as $lesson_status) { |
|
| 1360 | 1360 | $status_date = $lesson_status['comment_date']; |
| 1361 | - switch ( $lesson_status['status'] ) { |
|
| 1361 | + switch ($lesson_status['status']) { |
|
| 1362 | 1362 | case 'complete': // Lesson has no quiz/questions |
| 1363 | 1363 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
| 1364 | 1364 | case 'passed': |
@@ -1373,7 +1373,7 @@ discard block |
||
| 1373 | 1373 | } |
| 1374 | 1374 | } |
| 1375 | 1375 | $meta_data['complete'] = $lessons_completed; |
| 1376 | - $meta_data['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ); |
|
| 1376 | + $meta_data['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)); |
|
| 1377 | 1377 | } |
| 1378 | 1378 | else { |
| 1379 | 1379 | // Course has no lessons, therefore cannot be 'complete' |
@@ -1390,26 +1390,26 @@ discard block |
||
| 1390 | 1390 | 'comment_author' => '', |
| 1391 | 1391 | ); |
| 1392 | 1392 | // Check it doesn't already exist |
| 1393 | - $sql = $wpdb->prepare( $check_existing_sql, $course_id, $user_id ); |
|
| 1394 | - $comment_ID = $wpdb->get_var( $sql ); |
|
| 1395 | - if ( !$comment_ID ) { |
|
| 1393 | + $sql = $wpdb->prepare($check_existing_sql, $course_id, $user_id); |
|
| 1394 | + $comment_ID = $wpdb->get_var($sql); |
|
| 1395 | + if ( ! $comment_ID) { |
|
| 1396 | 1396 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
| 1397 | 1397 | $wpdb->insert($wpdb->comments, $data); |
| 1398 | 1398 | $comment_ID = (int) $wpdb->insert_id; |
| 1399 | 1399 | |
| 1400 | - if ( $comment_ID && !empty($meta_data) ) { |
|
| 1401 | - foreach ( $meta_data as $key => $value ) { |
|
| 1400 | + if ($comment_ID && ! empty($meta_data)) { |
|
| 1401 | + foreach ($meta_data as $key => $value) { |
|
| 1402 | 1402 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
| 1403 | - if ( $wpdb->get_var( $wpdb->prepare( |
|
| 1403 | + if ($wpdb->get_var($wpdb->prepare( |
|
| 1404 | 1404 | "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ", |
| 1405 | - $comment_ID, $key ) ) ) { |
|
| 1405 | + $comment_ID, $key ))) { |
|
| 1406 | 1406 | continue; // Found the meta data already |
| 1407 | 1407 | } |
| 1408 | - $result = $wpdb->insert( $wpdb->commentmeta, array( |
|
| 1408 | + $result = $wpdb->insert($wpdb->commentmeta, array( |
|
| 1409 | 1409 | 'comment_id' => $comment_ID, |
| 1410 | 1410 | 'meta_key' => $key, |
| 1411 | 1411 | 'meta_value' => $value |
| 1412 | - ) ); |
|
| 1412 | + )); |
|
| 1413 | 1413 | } |
| 1414 | 1414 | } |
| 1415 | 1415 | } |
@@ -1417,7 +1417,7 @@ discard block |
||
| 1417 | 1417 | } |
| 1418 | 1418 | $wpdb->flush(); |
| 1419 | 1419 | |
| 1420 | - if ( $current_page == $total_pages ) { |
|
| 1420 | + if ($current_page == $total_pages) { |
|
| 1421 | 1421 | return true; |
| 1422 | 1422 | } else { |
| 1423 | 1423 | return false; |
@@ -1433,70 +1433,70 @@ discard block |
||
| 1433 | 1433 | * @param type $offset |
| 1434 | 1434 | * @return boolean |
| 1435 | 1435 | */ |
| 1436 | - function status_changes_repair_course_statuses( $n = 50, $offset = 0 ) { |
|
| 1436 | + function status_changes_repair_course_statuses($n = 50, $offset = 0) { |
|
| 1437 | 1437 | global $wpdb; |
| 1438 | 1438 | |
| 1439 | - $count_object = wp_count_posts( 'lesson' ); |
|
| 1439 | + $count_object = wp_count_posts('lesson'); |
|
| 1440 | 1440 | $count_published = $count_object->publish; |
| 1441 | 1441 | |
| 1442 | - if ( 0 == $count_published ) { |
|
| 1442 | + if (0 == $count_published) { |
|
| 1443 | 1443 | return true; |
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | 1446 | // Calculate if this is the last page |
| 1447 | - if ( 0 == $offset ) { |
|
| 1447 | + if (0 == $offset) { |
|
| 1448 | 1448 | $current_page = 1; |
| 1449 | 1449 | } else { |
| 1450 | - $current_page = intval( $offset / $n ); |
|
| 1450 | + $current_page = intval($offset / $n); |
|
| 1451 | 1451 | } |
| 1452 | - $total_pages = ceil( $count_published / $n ); |
|
| 1452 | + $total_pages = ceil($count_published / $n); |
|
| 1453 | 1453 | |
| 1454 | 1454 | $course_lesson_ids = $lesson_user_statuses = array(); |
| 1455 | 1455 | |
| 1456 | 1456 | // Get all Lesson => Course relationships |
| 1457 | - $meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A ); |
|
| 1458 | - if ( !empty($meta_list) ) { |
|
| 1459 | - foreach ( $meta_list as $metarow ) { |
|
| 1457 | + $meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A); |
|
| 1458 | + if ( ! empty($meta_list)) { |
|
| 1459 | + foreach ($meta_list as $metarow) { |
|
| 1460 | 1460 | $lesson_id = $metarow['post_id']; |
| 1461 | 1461 | $course_id = $metarow['meta_value']; |
| 1462 | - $course_lesson_ids[ $course_id ][] = $lesson_id; |
|
| 1462 | + $course_lesson_ids[$course_id][] = $lesson_id; |
|
| 1463 | 1463 | } |
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | // Get all Lesson => Course relationships |
| 1467 | - $status_list = $wpdb->get_results( "SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A ); |
|
| 1468 | - if ( !empty($status_list) ) { |
|
| 1469 | - foreach ( $status_list as $status ) { |
|
| 1470 | - $lesson_user_statuses[ $status['comment_post_ID'] ][ $status['user_id'] ] = $status['comment_approved']; |
|
| 1467 | + $status_list = $wpdb->get_results("SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A); |
|
| 1468 | + if ( ! empty($status_list)) { |
|
| 1469 | + foreach ($status_list as $status) { |
|
| 1470 | + $lesson_user_statuses[$status['comment_post_ID']][$status['user_id']] = $status['comment_approved']; |
|
| 1471 | 1471 | } |
| 1472 | 1472 | } |
| 1473 | 1473 | |
| 1474 | - $course_completion = Sensei()->settings->settings[ 'course_completion' ]; |
|
| 1474 | + $course_completion = Sensei()->settings->settings['course_completion']; |
|
| 1475 | 1475 | |
| 1476 | 1476 | $per_page = 40; |
| 1477 | 1477 | $comment_id_offset = $count = 0; |
| 1478 | 1478 | |
| 1479 | 1479 | $course_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_course_status' AND comment_ID > %d LIMIT $per_page"; |
| 1480 | 1480 | // $per_page users at a time |
| 1481 | - while ( $course_statuses = $wpdb->get_results( $wpdb->prepare($course_sql, $comment_id_offset) ) ) { |
|
| 1481 | + while ($course_statuses = $wpdb->get_results($wpdb->prepare($course_sql, $comment_id_offset))) { |
|
| 1482 | 1482 | |
| 1483 | - foreach ( $course_statuses AS $course_status ) { |
|
| 1483 | + foreach ($course_statuses AS $course_status) { |
|
| 1484 | 1484 | $user_id = $course_status->user_id; |
| 1485 | 1485 | $course_id = $course_status->comment_post_ID; |
| 1486 | - $total_lessons = count( $course_lesson_ids[ $course_id ] ); |
|
| 1487 | - if ( $total_lessons <= 0 ) { |
|
| 1486 | + $total_lessons = count($course_lesson_ids[$course_id]); |
|
| 1487 | + if ($total_lessons <= 0) { |
|
| 1488 | 1488 | $total_lessons = 1; // Fix division of zero error, some courses have no lessons |
| 1489 | 1489 | } |
| 1490 | 1490 | $lessons_completed = 0; |
| 1491 | 1491 | $status = 'in-progress'; |
| 1492 | 1492 | |
| 1493 | 1493 | // Some Courses have no lessons... (can they ever be complete?) |
| 1494 | - if ( !empty($course_lesson_ids[ $course_id ]) ) { |
|
| 1495 | - foreach( $course_lesson_ids[ $course_id ] AS $lesson_id ) { |
|
| 1496 | - $lesson_status = $lesson_user_statuses[ $lesson_id ][ $user_id ]; |
|
| 1494 | + if ( ! empty($course_lesson_ids[$course_id])) { |
|
| 1495 | + foreach ($course_lesson_ids[$course_id] AS $lesson_id) { |
|
| 1496 | + $lesson_status = $lesson_user_statuses[$lesson_id][$user_id]; |
|
| 1497 | 1497 | // If lessons are complete without needing quizzes to be passed |
| 1498 | - if ( 'passed' != $course_completion ) { |
|
| 1499 | - switch ( $lesson_status ) { |
|
| 1498 | + if ('passed' != $course_completion) { |
|
| 1499 | + switch ($lesson_status) { |
|
| 1500 | 1500 | // A user cannot 'complete' a course if a lesson... |
| 1501 | 1501 | case 'in-progress': // ...is still in progress |
| 1502 | 1502 | case 'ungraded': // ...hasn't yet been graded |
@@ -1508,7 +1508,7 @@ discard block |
||
| 1508 | 1508 | } |
| 1509 | 1509 | } |
| 1510 | 1510 | else { |
| 1511 | - switch ( $lesson_status ) { |
|
| 1511 | + switch ($lesson_status) { |
|
| 1512 | 1512 | case 'complete': // Lesson has no quiz/questions |
| 1513 | 1513 | case 'graded': // Lesson has quiz, but it's not important what the grade was |
| 1514 | 1514 | case 'passed': // Lesson has quiz and the user passed |
@@ -1523,79 +1523,79 @@ discard block |
||
| 1523 | 1523 | } |
| 1524 | 1524 | } // Each lesson |
| 1525 | 1525 | } // Check for lessons |
| 1526 | - if ( $lessons_completed == $total_lessons ) { |
|
| 1526 | + if ($lessons_completed == $total_lessons) { |
|
| 1527 | 1527 | $status = 'complete'; |
| 1528 | 1528 | } |
| 1529 | 1529 | // update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above |
| 1530 | 1530 | $metadata = array( |
| 1531 | 1531 | 'complete' => $lessons_completed, |
| 1532 | - 'percent' => abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ), |
|
| 1532 | + 'percent' => abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)), |
|
| 1533 | 1533 | ); |
| 1534 | - Sensei_Utils::update_course_status( $user_id, $course_id, $status, $metadata ); |
|
| 1534 | + Sensei_Utils::update_course_status($user_id, $course_id, $status, $metadata); |
|
| 1535 | 1535 | $count++; |
| 1536 | 1536 | |
| 1537 | 1537 | } // per course status |
| 1538 | 1538 | $comment_id_offset = $course_status->comment_ID; |
| 1539 | 1539 | } // all course statuses |
| 1540 | 1540 | |
| 1541 | - if ( $current_page == $total_pages ) { |
|
| 1541 | + if ($current_page == $total_pages) { |
|
| 1542 | 1542 | return true; |
| 1543 | 1543 | } else { |
| 1544 | 1544 | return false; |
| 1545 | 1545 | } |
| 1546 | 1546 | } |
| 1547 | 1547 | |
| 1548 | - function status_changes_convert_questions( $n = 50, $offset = 0 ) { |
|
| 1548 | + function status_changes_convert_questions($n = 50, $offset = 0) { |
|
| 1549 | 1549 | global $wpdb; |
| 1550 | 1550 | |
| 1551 | - wp_defer_comment_counting( true ); |
|
| 1551 | + wp_defer_comment_counting(true); |
|
| 1552 | 1552 | |
| 1553 | - $user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " ); |
|
| 1553 | + $user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users "); |
|
| 1554 | 1554 | |
| 1555 | - if ( 0 == $user_count_result ) { |
|
| 1555 | + if (0 == $user_count_result) { |
|
| 1556 | 1556 | return true; |
| 1557 | 1557 | } |
| 1558 | 1558 | |
| 1559 | 1559 | // Calculate if this is the last page |
| 1560 | - if ( 0 == $offset ) { |
|
| 1560 | + if (0 == $offset) { |
|
| 1561 | 1561 | $current_page = 1; |
| 1562 | 1562 | } else { |
| 1563 | - $current_page = intval( $offset / $n ); |
|
| 1563 | + $current_page = intval($offset / $n); |
|
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | - $total_pages = ceil( $user_count_result / $n ); |
|
| 1566 | + $total_pages = ceil($user_count_result / $n); |
|
| 1567 | 1567 | |
| 1568 | 1568 | $users_sql = "SELECT ID FROM $wpdb->users ORDER BY ID ASC LIMIT %d OFFSET %d"; |
| 1569 | 1569 | $answers_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_user_answer' AND user_id = %d GROUP BY comment_post_ID "; |
| 1570 | 1570 | $grades_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_user_grade' AND user_id = %d GROUP BY comment_post_ID "; |
| 1571 | 1571 | $notes_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_answer_notes' AND user_id = %d GROUP BY comment_post_ID "; |
| 1572 | 1572 | |
| 1573 | - $user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) ); |
|
| 1573 | + $user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset)); |
|
| 1574 | 1574 | |
| 1575 | - foreach ( $user_ids AS $user_id ) { |
|
| 1575 | + foreach ($user_ids AS $user_id) { |
|
| 1576 | 1576 | |
| 1577 | 1577 | $answer_grades = $answer_notes = array(); |
| 1578 | 1578 | |
| 1579 | 1579 | // Pre-process the answer grades |
| 1580 | - $_answer_grades = $wpdb->get_results( $wpdb->prepare($grades_sql, $user_id), ARRAY_A ); |
|
| 1581 | - foreach ( $_answer_grades as $answer_grade ) { |
|
| 1580 | + $_answer_grades = $wpdb->get_results($wpdb->prepare($grades_sql, $user_id), ARRAY_A); |
|
| 1581 | + foreach ($_answer_grades as $answer_grade) { |
|
| 1582 | 1582 | // This will overwrite existing entries with the newer ones |
| 1583 | - $answer_grades[ $answer_grade['comment_post_ID'] ] = $answer_grade['comment_content']; |
|
| 1583 | + $answer_grades[$answer_grade['comment_post_ID']] = $answer_grade['comment_content']; |
|
| 1584 | 1584 | } |
| 1585 | - unset( $_answer_grades ); |
|
| 1585 | + unset($_answer_grades); |
|
| 1586 | 1586 | |
| 1587 | 1587 | // Pre-process the answer notes |
| 1588 | - $_answer_notes = $wpdb->get_results( $wpdb->prepare($notes_sql, $user_id), ARRAY_A ); |
|
| 1589 | - foreach ( $_answer_notes as $answer_note ) { |
|
| 1588 | + $_answer_notes = $wpdb->get_results($wpdb->prepare($notes_sql, $user_id), ARRAY_A); |
|
| 1589 | + foreach ($_answer_notes as $answer_note) { |
|
| 1590 | 1590 | // This will overwrite existing entries with the newer ones |
| 1591 | - $answer_notes[ $answer_note['comment_post_ID'] ] = $answer_note['comment_content']; |
|
| 1591 | + $answer_notes[$answer_note['comment_post_ID']] = $answer_note['comment_content']; |
|
| 1592 | 1592 | } |
| 1593 | - unset( $_answer_notes ); |
|
| 1593 | + unset($_answer_notes); |
|
| 1594 | 1594 | |
| 1595 | 1595 | // Grab all the questions for the user |
| 1596 | 1596 | $sql = $wpdb->prepare($answers_sql, $user_id); |
| 1597 | - $answers = $wpdb->get_results( $sql, ARRAY_A ); |
|
| 1598 | - foreach ( $answers as $answer ) { |
|
| 1597 | + $answers = $wpdb->get_results($sql, ARRAY_A); |
|
| 1598 | + foreach ($answers as $answer) { |
|
| 1599 | 1599 | |
| 1600 | 1600 | // Excape data |
| 1601 | 1601 | $answer = wp_slash($answer); |
@@ -1605,12 +1605,12 @@ discard block |
||
| 1605 | 1605 | $meta_data = array(); |
| 1606 | 1606 | |
| 1607 | 1607 | // Check if the question has been graded, add as meta |
| 1608 | - if ( !empty($answer_grades[ $answer['comment_post_ID'] ]) ) { |
|
| 1609 | - $meta_data['user_grade'] = $answer_grades[ $answer['comment_post_ID'] ]; |
|
| 1608 | + if ( ! empty($answer_grades[$answer['comment_post_ID']])) { |
|
| 1609 | + $meta_data['user_grade'] = $answer_grades[$answer['comment_post_ID']]; |
|
| 1610 | 1610 | } |
| 1611 | 1611 | // Check if there is an answer note, add as meta |
| 1612 | - if ( !empty($answer_notes[ $answer['comment_post_ID'] ]) ) { |
|
| 1613 | - $meta_data['answer_note'] = $answer_notes[ $answer['comment_post_ID'] ]; |
|
| 1612 | + if ( ! empty($answer_notes[$answer['comment_post_ID']])) { |
|
| 1613 | + $meta_data['answer_note'] = $answer_notes[$answer['comment_post_ID']]; |
|
| 1614 | 1614 | } |
| 1615 | 1615 | |
| 1616 | 1616 | // Wipe the unnessary data from the main comment |
@@ -1623,21 +1623,21 @@ discard block |
||
| 1623 | 1623 | ); |
| 1624 | 1624 | $data = array_merge($answer, $data); |
| 1625 | 1625 | |
| 1626 | - $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) ); |
|
| 1627 | - if ( $rval ) { |
|
| 1628 | - if ( !empty($meta_data) ) { |
|
| 1629 | - foreach ( $meta_data as $key => $value ) { |
|
| 1626 | + $rval = $wpdb->update($wpdb->comments, $data, compact('comment_ID')); |
|
| 1627 | + if ($rval) { |
|
| 1628 | + if ( ! empty($meta_data)) { |
|
| 1629 | + foreach ($meta_data as $key => $value) { |
|
| 1630 | 1630 | // Bypassing WP wp_insert_comment( $data ), so no actions/filters are run |
| 1631 | - if ( $wpdb->get_var( $wpdb->prepare( |
|
| 1631 | + if ($wpdb->get_var($wpdb->prepare( |
|
| 1632 | 1632 | "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ", |
| 1633 | - $comment_ID, $key ) ) ) { |
|
| 1633 | + $comment_ID, $key ))) { |
|
| 1634 | 1634 | continue; // Found the meta data already |
| 1635 | 1635 | } |
| 1636 | - $result = $wpdb->insert( $wpdb->commentmeta, array( |
|
| 1636 | + $result = $wpdb->insert($wpdb->commentmeta, array( |
|
| 1637 | 1637 | 'comment_id' => $comment_ID, |
| 1638 | 1638 | 'meta_key' => $key, |
| 1639 | 1639 | 'meta_value' => $value |
| 1640 | - ) ); |
|
| 1640 | + )); |
|
| 1641 | 1641 | } |
| 1642 | 1642 | } |
| 1643 | 1643 | } |
@@ -1645,7 +1645,7 @@ discard block |
||
| 1645 | 1645 | } |
| 1646 | 1646 | $wpdb->flush(); |
| 1647 | 1647 | |
| 1648 | - if ( $current_page == $total_pages ) { |
|
| 1648 | + if ($current_page == $total_pages) { |
|
| 1649 | 1649 | return true; |
| 1650 | 1650 | } else { |
| 1651 | 1651 | return false; |
@@ -1662,10 +1662,10 @@ discard block |
||
| 1662 | 1662 | global $wpdb; |
| 1663 | 1663 | |
| 1664 | 1664 | // Update 'sensei_user_answer' entries to use comment_approved = 'log' so they don't appear in counts |
| 1665 | - $wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' " ); |
|
| 1665 | + $wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' "); |
|
| 1666 | 1666 | |
| 1667 | 1667 | // Mark all old Sensei comment types with comment_approved = 'legacy' so they no longer appear in counts, but can be restored if required |
| 1668 | - $wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') " ); |
|
| 1668 | + $wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') "); |
|
| 1669 | 1669 | |
| 1670 | 1670 | return true; |
| 1671 | 1671 | } |
@@ -1678,50 +1678,50 @@ discard block |
||
| 1678 | 1678 | * @param type $offset |
| 1679 | 1679 | * @return boolean |
| 1680 | 1680 | */ |
| 1681 | - public function update_comment_course_lesson_comment_counts( $n = 50, $offset = 0 ) { |
|
| 1681 | + public function update_comment_course_lesson_comment_counts($n = 50, $offset = 0) { |
|
| 1682 | 1682 | global $wpdb; |
| 1683 | 1683 | |
| 1684 | - $item_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') " ); |
|
| 1684 | + $item_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') "); |
|
| 1685 | 1685 | |
| 1686 | - if ( 0 == $item_count_result ) { |
|
| 1686 | + if (0 == $item_count_result) { |
|
| 1687 | 1687 | return true; |
| 1688 | 1688 | } |
| 1689 | 1689 | |
| 1690 | 1690 | // Calculate if this is the last page |
| 1691 | - if ( 0 == $offset ) { |
|
| 1691 | + if (0 == $offset) { |
|
| 1692 | 1692 | $current_page = 1; |
| 1693 | 1693 | } else { |
| 1694 | - $current_page = intval( $offset / $n ); |
|
| 1694 | + $current_page = intval($offset / $n); |
|
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | - $total_pages = ceil( $item_count_result / $n ); |
|
| 1697 | + $total_pages = ceil($item_count_result / $n); |
|
| 1698 | 1698 | |
| 1699 | 1699 | // Recalculate all counts |
| 1700 | - $items = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset ) ); |
|
| 1701 | - foreach ( (array) $items as $post ) { |
|
| 1700 | + $items = $wpdb->get_results($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset)); |
|
| 1701 | + foreach ((array) $items as $post) { |
|
| 1702 | 1702 | // Code copied from wp_update_comment_count_now() |
| 1703 | - $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID) ); |
|
| 1704 | - $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID) ); |
|
| 1703 | + $new = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID)); |
|
| 1704 | + $wpdb->update($wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID)); |
|
| 1705 | 1705 | |
| 1706 | - clean_post_cache( $post->ID ); |
|
| 1706 | + clean_post_cache($post->ID); |
|
| 1707 | 1707 | } |
| 1708 | 1708 | |
| 1709 | - if ( $current_page == $total_pages ) { |
|
| 1709 | + if ($current_page == $total_pages) { |
|
| 1710 | 1710 | return true; |
| 1711 | 1711 | } else { |
| 1712 | 1712 | return false; |
| 1713 | 1713 | } |
| 1714 | 1714 | } |
| 1715 | 1715 | |
| 1716 | - public function remove_legacy_comments () { |
|
| 1716 | + public function remove_legacy_comments() { |
|
| 1717 | 1717 | global $wpdb; |
| 1718 | 1718 | |
| 1719 | - $result = $wpdb->delete( $wpdb->comments, array( 'comment_approved' => 'legacy' ) ); |
|
| 1719 | + $result = $wpdb->delete($wpdb->comments, array('comment_approved' => 'legacy')); |
|
| 1720 | 1720 | |
| 1721 | 1721 | return true; |
| 1722 | 1722 | } |
| 1723 | 1723 | |
| 1724 | - public function index_comment_status_field () { |
|
| 1724 | + public function index_comment_status_field() { |
|
| 1725 | 1725 | global $wpdb; |
| 1726 | 1726 | |
| 1727 | 1727 | $wpdb->query("ALTER TABLE `$wpdb->comments` ADD INDEX `comment_type` ( `comment_type` )"); |
@@ -1740,7 +1740,7 @@ discard block |
||
| 1740 | 1740 | * @since 1.8.0 |
| 1741 | 1741 | * @return bool; |
| 1742 | 1742 | */ |
| 1743 | - public function enhance_teacher_role ( ) { |
|
| 1743 | + public function enhance_teacher_role( ) { |
|
| 1744 | 1744 | |
| 1745 | 1745 | require_once('class-sensei-teacher.php'); |
| 1746 | 1746 | $teacher = new Sensei_Teacher(); |