@@ -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 ); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | add_action( 'sensei_course_status_updated', array( $this, 'learner_completed_course' ), 10, 4 ); |
| 46 | 46 | add_action( 'sensei_course_status_updated', array( $this, 'teacher_completed_course' ), 10, 4 ); |
| 47 | 47 | add_action( 'sensei_user_course_start', array( $this, 'teacher_started_course' ), 10, 2 ); |
| 48 | - add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 ); |
|
| 48 | + add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 ); |
|
| 49 | 49 | add_action( 'sensei_user_quiz_submitted', array( $this, 'teacher_quiz_submitted' ), 10, 5 ); |
| 50 | 50 | add_action( 'sensei_new_private_message', array( $this, 'teacher_new_message' ), 10, 1 ); |
| 51 | 51 | add_action( 'sensei_private_message_reply', array( $this, 'new_message_reply' ), 10, 2 ); |
@@ -62,9 +62,9 @@ discard block |
||
| 62 | 62 | $this->emails['learner-graded-quiz'] = include( 'emails/class-woothemes-sensei-email-learner-graded-quiz.php' ); |
| 63 | 63 | $this->emails['learner-completed-course'] = include( 'emails/class-woothemes-sensei-email-learner-completed-course.php' ); |
| 64 | 64 | $this->emails['teacher-completed-course'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-course.php' ); |
| 65 | - $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' ); |
|
| 66 | - $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' ); |
|
| 67 | - $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' ); |
|
| 65 | + $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' ); |
|
| 66 | + $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' ); |
|
| 67 | + $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' ); |
|
| 68 | 68 | $this->emails['teacher-new-message'] = include( 'emails/class-woothemes-sensei-email-teacher-new-message.php' ); |
| 69 | 69 | $this->emails['new-message-reply'] = include( 'emails/class-woothemes-sensei-email-new-message-reply.php' ); |
| 70 | 70 | $this->emails = apply_filters( 'sensei_email_classes', $this->emails ); |
@@ -171,20 +171,20 @@ discard block |
||
| 171 | 171 | add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); |
| 172 | 172 | add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); |
| 173 | 173 | |
| 174 | - // Send |
|
| 175 | - $send_email = true; |
|
| 174 | + // Send |
|
| 175 | + $send_email = true; |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Filter Sensei's ability to send out emails. |
|
| 179 | - * |
|
| 180 | - * @since 1.8.0 |
|
| 181 | - * @param bool $send_email default true |
|
| 182 | - */ |
|
| 183 | - if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message ) ){ |
|
| 177 | + /** |
|
| 178 | + * Filter Sensei's ability to send out emails. |
|
| 179 | + * |
|
| 180 | + * @since 1.8.0 |
|
| 181 | + * @param bool $send_email default true |
|
| 182 | + */ |
|
| 183 | + if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message ) ){ |
|
| 184 | 184 | |
| 185 | - wp_mail( $to, $subject, $message, $headers, $attachments ); |
|
| 185 | + wp_mail( $to, $subject, $message, $headers, $attachments ); |
|
| 186 | 186 | |
| 187 | - } |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | 189 | // Unhook filters |
| 190 | 190 | remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); |
@@ -326,44 +326,44 @@ discard block |
||
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - /** |
|
| 330 | - * teacher_completed_lesson() |
|
| 331 | - * |
|
| 332 | - * Send email to teacher on student completing lesson |
|
| 333 | - * |
|
| 334 | - * @access public |
|
| 335 | - * @return void |
|
| 336 | - * @since 1.9.0 |
|
| 337 | - */ |
|
| 338 | - function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) { |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - $send = false; |
|
| 342 | - |
|
| 343 | - if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) { |
|
| 344 | - if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) { |
|
| 345 | - $send = true; |
|
| 346 | - } |
|
| 347 | - } else { |
|
| 348 | - $send = true; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - if( $send ) { |
|
| 352 | - $email = $this->emails['teacher-completed-lesson']; |
|
| 353 | - $email->trigger( $learner_id, $lesson_id ); |
|
| 354 | - } |
|
| 355 | - } |
|
| 329 | + /** |
|
| 330 | + * teacher_completed_lesson() |
|
| 331 | + * |
|
| 332 | + * Send email to teacher on student completing lesson |
|
| 333 | + * |
|
| 334 | + * @access public |
|
| 335 | + * @return void |
|
| 336 | + * @since 1.9.0 |
|
| 337 | + */ |
|
| 338 | + function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) { |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + $send = false; |
|
| 342 | + |
|
| 343 | + if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) { |
|
| 344 | + if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) { |
|
| 345 | + $send = true; |
|
| 346 | + } |
|
| 347 | + } else { |
|
| 348 | + $send = true; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + if( $send ) { |
|
| 352 | + $email = $this->emails['teacher-completed-lesson']; |
|
| 353 | + $email->trigger( $learner_id, $lesson_id ); |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | 357 | /** |
| 358 | 358 | * Send email to teacher on quiz submission |
| 359 | 359 | * |
| 360 | 360 | * |
| 361 | - * @param int $learner_id |
|
| 362 | - * @param int $quiz_id |
|
| 363 | - * @param int $grade |
|
| 364 | - * @param int $passmark |
|
| 365 | - * @param string $quiz_grade_type |
|
| 366 | - */ |
|
| 361 | + * @param int $learner_id |
|
| 362 | + * @param int $quiz_id |
|
| 363 | + * @param int $grade |
|
| 364 | + * @param int $passmark |
|
| 365 | + * @param string $quiz_grade_type |
|
| 366 | + */ |
|
| 367 | 367 | function teacher_quiz_submitted( $learner_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0, $quiz_grade_type = 'manual' ) { |
| 368 | 368 | |
| 369 | 369 | $send = false; |
@@ -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 ) { |
@@ -40,16 +40,16 @@ discard block |
||
| 40 | 40 | public $total_items = 0; |
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var array $sortable_columns |
|
| 45 | - * |
|
| 46 | - */ |
|
| 47 | - public $sortable_columns = array(); |
|
| 43 | + /** |
|
| 44 | + * @var array $sortable_columns |
|
| 45 | + * |
|
| 46 | + */ |
|
| 47 | + public $sortable_columns = array(); |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var array columns |
|
| 51 | - */ |
|
| 52 | - public $columns = array(); |
|
| 49 | + /** |
|
| 50 | + * @var array columns |
|
| 51 | + */ |
|
| 52 | + public $columns = array(); |
|
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * Constructor |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | $sortable[$id] = $data; |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - $primary = $this->get_primary_column_name(); |
|
| 179 | - $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); |
|
| 178 | + $primary = $this->get_primary_column_name(); |
|
| 179 | + $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); |
|
| 180 | 180 | |
| 181 | 181 | return $this->_column_headers; |
| 182 | 182 | } |
@@ -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 ) { |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @since 1.6.0 |
| 22 | 22 | */ |
| 23 | 23 | public function __construct () { |
| 24 | - $this->token = 'messages'; |
|
| 24 | + $this->token = 'messages'; |
|
| 25 | 25 | $this->post_type = 'sensei_message'; |
| 26 | 26 | $this->meta_fields = array( 'sender', 'receiver' ); |
| 27 | 27 | |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | // Monitor when new reply is posted |
| 37 | 37 | add_action( 'comment_post', array( $this, 'message_reply_received' ), 10, 1 ); |
| 38 | 38 | |
| 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 ); |
|
| 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 ); |
|
| 41 | 41 | |
| 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 ); |
|
| 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 ); |
|
| 44 | 44 | |
| 45 | 45 | // Process saving of message posts |
| 46 | 46 | add_action( 'save_post', array( $this, 'save_message' ) ); |
@@ -48,20 +48,20 @@ discard block |
||
| 48 | 48 | // Add message links to courses & lessons |
| 49 | 49 | add_action( 'sensei_single_course_content_inside_before', array( $this, 'send_message_link' ), 35 ); |
| 50 | 50 | |
| 51 | - // add message link to lesson |
|
| 52 | - add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); |
|
| 51 | + // add message link to lesson |
|
| 52 | + add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); |
|
| 53 | 53 | |
| 54 | - // add message link to lesson |
|
| 55 | - add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); |
|
| 54 | + // add message link to lesson |
|
| 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() { |
@@ -162,8 +162,8 @@ discard block |
||
| 162 | 162 | public function send_message_link( $post_id = 0, $user_id = 0 ) { |
| 163 | 163 | global $post; |
| 164 | 164 | |
| 165 | - // only show the link for the allowed post types: |
|
| 166 | - $allowed_post_types = array('lesson', 'course', 'quiz'); |
|
| 165 | + // only show the link for the allowed post types: |
|
| 166 | + $allowed_post_types = array('lesson', 'course', 'quiz'); |
|
| 167 | 167 | if ( ! in_array( get_post_type() , $allowed_post_types ) ) { |
| 168 | 168 | |
| 169 | 169 | return; |
@@ -186,8 +186,8 @@ discard block |
||
| 186 | 186 | } elseif( 'course' == $post->post_type ) { |
| 187 | 187 | $contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' ); |
| 188 | 188 | }else{ |
| 189 | - $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); |
|
| 190 | - } |
|
| 189 | + $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | 192 | $html .= '<p><a class="button send-message-button" href="' . esc_url($href) . '#private_message">' . $contact_button_text . '</a></p>'; |
| 193 | 193 | } |
@@ -212,19 +212,19 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | if( ! isset( $post->ID ) ) return $html; |
| 214 | 214 | |
| 215 | - //confirm private message |
|
| 216 | - $confirmation = ''; |
|
| 217 | - if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { |
|
| 215 | + //confirm private message |
|
| 216 | + $confirmation = ''; |
|
| 217 | + if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { |
|
| 218 | 218 | |
| 219 | - $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); |
|
| 220 | - $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; |
|
| 219 | + $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); |
|
| 220 | + $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; |
|
| 221 | 221 | |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | $html .= '<h3 id="private_message">' . __( 'Send Private Message', 'woothemes-sensei' ) . '</h3>'; |
| 225 | - $html .= '<p>'; |
|
| 226 | - $html .= $confirmation; |
|
| 227 | - $html .= '</p>'; |
|
| 225 | + $html .= '<p>'; |
|
| 226 | + $html .= $confirmation; |
|
| 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 | 230 | $html .= '<textarea name="contact_message" placeholder="' . __( 'Enter your private message.', 'woothemes-sensei' ) . '"></textarea>'; |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 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 | 260 | if( is_null( $comment ) ) return; |
| 261 | 261 | |
@@ -270,87 +270,87 @@ discard block |
||
| 270 | 270 | do_action( 'sensei_private_message_reply', $comment, $message ); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * This function stops WordPress from sending the default comment update emails. |
|
| 275 | - * |
|
| 276 | - * This function is hooked into comment_notification_recipients. It will simply return |
|
| 277 | - * an empty array if the current passed in comment is on a message post type. |
|
| 278 | - * |
|
| 279 | - * @param array $emails |
|
| 280 | - * @param int $comment_id |
|
| 281 | - * @return array; |
|
| 282 | - */ |
|
| 283 | - public function stop_wp_comment_emails( $emails , $comment_id ){ |
|
| 273 | + /** |
|
| 274 | + * This function stops WordPress from sending the default comment update emails. |
|
| 275 | + * |
|
| 276 | + * This function is hooked into comment_notification_recipients. It will simply return |
|
| 277 | + * an empty array if the current passed in comment is on a message post type. |
|
| 278 | + * |
|
| 279 | + * @param array $emails |
|
| 280 | + * @param int $comment_id |
|
| 281 | + * @return array; |
|
| 282 | + */ |
|
| 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 | - // empty the emails array to ensure no emails are sent for this comment |
|
| 290 | - $emails = array(); |
|
| 289 | + // empty the emails array to ensure no emails are sent for this comment |
|
| 290 | + $emails = array(); |
|
| 291 | 291 | |
| 292 | - } |
|
| 293 | - return $emails; |
|
| 292 | + } |
|
| 293 | + return $emails; |
|
| 294 | 294 | |
| 295 | - }// end stop_wp_comment_emails |
|
| 295 | + }// end stop_wp_comment_emails |
|
| 296 | 296 | |
| 297 | 297 | /** |
| 298 | - * Save new message post |
|
| 299 | - * @param integer $sender_id ID of sender |
|
| 300 | - * @param integer $receiver_id ID of receiver |
|
| 301 | - * @param string $message Message content |
|
| 302 | - * @param string $post_id ID of post related to message |
|
| 303 | - * @return mixed Message ID on success, boolean false on failure |
|
| 304 | - */ |
|
| 305 | - private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { |
|
| 298 | + * Save new message post |
|
| 299 | + * @param integer $sender_id ID of sender |
|
| 300 | + * @param integer $receiver_id ID of receiver |
|
| 301 | + * @param string $message Message content |
|
| 302 | + * @param string $post_id ID of post related to message |
|
| 303 | + * @return mixed Message ID on success, boolean false on failure |
|
| 304 | + */ |
|
| 305 | + private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { |
|
| 306 | 306 | |
| 307 | - $message_id = false; |
|
| 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 | - // Set up post data for message |
|
| 314 | - $message_data = array( |
|
| 315 | - 'post_type' => $this->post_type, |
|
| 316 | - 'post_title' => esc_html( $title ), |
|
| 317 | - 'post_content' => esc_html( $message ), |
|
| 318 | - 'post_status' => 'publish', |
|
| 319 | - 'ping_status' => 'closed', |
|
| 320 | - 'comment_status' => 'open', |
|
| 321 | - 'post_excerpt' => '', |
|
| 322 | - 'post_author' => intval( $sender_id ) |
|
| 323 | - ); |
|
| 313 | + // Set up post data for message |
|
| 314 | + $message_data = array( |
|
| 315 | + 'post_type' => $this->post_type, |
|
| 316 | + 'post_title' => esc_html( $title ), |
|
| 317 | + 'post_content' => esc_html( $message ), |
|
| 318 | + 'post_status' => 'publish', |
|
| 319 | + 'ping_status' => 'closed', |
|
| 320 | + 'comment_status' => 'open', |
|
| 321 | + 'post_excerpt' => '', |
|
| 322 | + 'post_author' => intval( $sender_id ) |
|
| 323 | + ); |
|
| 324 | 324 | |
| 325 | - // Insert post |
|
| 326 | - $message_id = wp_insert_post( $message_data ); |
|
| 325 | + // Insert post |
|
| 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 | - // Add sender to message meta |
|
| 331 | - $sender = get_userdata( $sender_id ); |
|
| 332 | - add_post_meta( $message_id, '_sender', $sender->user_login ); |
|
| 330 | + // Add sender to message meta |
|
| 331 | + $sender = get_userdata( $sender_id ); |
|
| 332 | + add_post_meta( $message_id, '_sender', $sender->user_login ); |
|
| 333 | 333 | |
| 334 | - // Add receiver to message meta |
|
| 335 | - $receiver = get_userdata( $receiver_id ); |
|
| 336 | - add_post_meta( $message_id, '_receiver', $receiver->user_login ); |
|
| 334 | + // Add receiver to message meta |
|
| 335 | + $receiver = get_userdata( $receiver_id ); |
|
| 336 | + add_post_meta( $message_id, '_receiver', $receiver->user_login ); |
|
| 337 | 337 | |
| 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 ); |
|
| 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 ); |
|
| 342 | 342 | |
| 343 | - do_action( 'sensei_new_private_message', $message_id ); |
|
| 343 | + do_action( 'sensei_new_private_message', $message_id ); |
|
| 344 | 344 | |
| 345 | - } else { |
|
| 345 | + } else { |
|
| 346 | 346 | |
| 347 | - $message_id = false; |
|
| 347 | + $message_id = false; |
|
| 348 | 348 | |
| 349 | - } |
|
| 350 | - } |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - return $message_id; |
|
| 353 | - } |
|
| 352 | + return $message_id; |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | 355 | /** |
| 356 | 356 | * Check if user has access to view this message |
@@ -389,56 +389,56 @@ discard block |
||
| 389 | 389 | remove_meta_box('commentstatusdiv', $this->post_type, 'normal'); |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - /** |
|
| 393 | - * Function message_login() |
|
| 394 | - * |
|
| 395 | - * Only show /messages/* to logged in users, and |
|
| 396 | - * redirect logged out users to wp-login.php |
|
| 397 | - * |
|
| 398 | - * @since 1.9.0 |
|
| 399 | - * @param none |
|
| 400 | - * @return void |
|
| 401 | - */ |
|
| 392 | + /** |
|
| 393 | + * Function message_login() |
|
| 394 | + * |
|
| 395 | + * Only show /messages/* to logged in users, and |
|
| 396 | + * redirect logged out users to wp-login.php |
|
| 397 | + * |
|
| 398 | + * @since 1.9.0 |
|
| 399 | + * @param none |
|
| 400 | + * @return void |
|
| 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 | - return; |
|
| 408 | - } |
|
| 407 | + return; |
|
| 408 | + } |
|
| 409 | 409 | |
| 410 | - $settings = Sensei()->settings->get_settings(); |
|
| 411 | - if( isset( $settings[ 'my_course_page' ] ) |
|
| 412 | - && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 410 | + $settings = Sensei()->settings->get_settings(); |
|
| 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 | - $my_courses_url = get_permalink($my_courses_page_id); |
|
| 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 | - wp_redirect($my_courses_url, 303); |
|
| 426 | - exit; |
|
| 427 | - } |
|
| 425 | + wp_redirect($my_courses_url, 303); |
|
| 426 | + exit; |
|
| 427 | + } |
|
| 428 | 428 | |
| 429 | - else { |
|
| 429 | + else { |
|
| 430 | 430 | |
| 431 | - wp_redirect(home_url('/wp-login.php'), 303); |
|
| 432 | - exit; |
|
| 433 | - } |
|
| 431 | + wp_redirect(home_url('/wp-login.php'), 303); |
|
| 432 | + exit; |
|
| 433 | + } |
|
| 434 | 434 | |
| 435 | - } |
|
| 436 | - } |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | 437 | /** |
| 438 | - * Only show allowed messages in messages archive |
|
| 439 | - * @param WP_Query $query Original query |
|
| 440 | - * @return void |
|
| 441 | - */ |
|
| 438 | + * Only show allowed messages in messages archive |
|
| 439 | + * @param WP_Query $query Original query |
|
| 440 | + * @return void |
|
| 441 | + */ |
|
| 442 | 442 | public function message_list( $query ) { |
| 443 | 443 | global $current_user; |
| 444 | 444 | |
@@ -555,17 +555,17 @@ discard block |
||
| 555 | 555 | return $open; |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - /** |
|
| 559 | - * Print outthe message was sent by $sender_username on the |
|
| 560 | - * |
|
| 561 | - * @since 1.9.0 |
|
| 562 | - */ |
|
| 563 | - public static function the_message_sent_by_title(){ |
|
| 558 | + /** |
|
| 559 | + * Print outthe message was sent by $sender_username on the |
|
| 560 | + * |
|
| 561 | + * @since 1.9.0 |
|
| 562 | + */ |
|
| 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> |
@@ -577,41 +577,41 @@ discard block |
||
| 577 | 577 | |
| 578 | 578 | <?php } |
| 579 | 579 | |
| 580 | - } |
|
| 580 | + } |
|
| 581 | 581 | |
| 582 | - /** |
|
| 583 | - * sensei_single_title output for single page title |
|
| 584 | - * @since 1.1.0 |
|
| 585 | - * @return void |
|
| 586 | - * @deprecate |
|
| 587 | - */ |
|
| 588 | - public static function the_title() { |
|
| 582 | + /** |
|
| 583 | + * sensei_single_title output for single page title |
|
| 584 | + * @since 1.1.0 |
|
| 585 | + * @return void |
|
| 586 | + * @deprecate |
|
| 587 | + */ |
|
| 588 | + public static function the_title() { |
|
| 589 | 589 | |
| 590 | - global $post; |
|
| 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>' ); |
|
| 595 | - } else { |
|
| 596 | - $title = get_the_title( $post->ID ); |
|
| 597 | - } |
|
| 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 | + } else { |
|
| 596 | + $title = get_the_title( $post->ID ); |
|
| 597 | + } |
|
| 598 | 598 | |
| 599 | - ?> |
|
| 599 | + ?> |
|
| 600 | 600 | <header> |
| 601 | 601 | |
| 602 | 602 | <h1> |
| 603 | 603 | |
| 604 | 604 | <?php |
| 605 | - /** |
|
| 606 | - * Filter Sensei single title |
|
| 607 | - * |
|
| 608 | - * @since 1.8.0 |
|
| 609 | - * @param string $title |
|
| 610 | - * @param string $template |
|
| 611 | - * @param string $post_type |
|
| 612 | - */ |
|
| 613 | - echo apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 614 | - ?> |
|
| 605 | + /** |
|
| 606 | + * Filter Sensei single title |
|
| 607 | + * |
|
| 608 | + * @since 1.8.0 |
|
| 609 | + * @param string $title |
|
| 610 | + * @param string $template |
|
| 611 | + * @param string $post_type |
|
| 612 | + */ |
|
| 613 | + echo apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 614 | + ?> |
|
| 615 | 615 | |
| 616 | 616 | </h1> |
| 617 | 617 | |
@@ -619,52 +619,52 @@ discard block |
||
| 619 | 619 | |
| 620 | 620 | <?php |
| 621 | 621 | |
| 622 | - } // End sensei_single_title() |
|
| 622 | + } // End sensei_single_title() |
|
| 623 | 623 | |
| 624 | - /** |
|
| 625 | - * Generates the my messages |
|
| 626 | - * archive header. |
|
| 627 | - * |
|
| 628 | - * @since 1.9.0 |
|
| 629 | - * |
|
| 630 | - * @return string |
|
| 631 | - */ |
|
| 632 | - public static function the_archive_header( ){ |
|
| 624 | + /** |
|
| 625 | + * Generates the my messages |
|
| 626 | + * archive header. |
|
| 627 | + * |
|
| 628 | + * @since 1.9.0 |
|
| 629 | + * |
|
| 630 | + * @return string |
|
| 631 | + */ |
|
| 632 | + public static function the_archive_header( ){ |
|
| 633 | 633 | |
| 634 | - $html = ''; |
|
| 635 | - $html .= '<header class="archive-header"><h1>'; |
|
| 636 | - $html .= __( 'My Messages', 'woothemes-sensei' ); |
|
| 637 | - $html .= '</h1></header>'; |
|
| 634 | + $html = ''; |
|
| 635 | + $html .= '<header class="archive-header"><h1>'; |
|
| 636 | + $html .= __( 'My Messages', 'woothemes-sensei' ); |
|
| 637 | + $html .= '</h1></header>'; |
|
| 638 | 638 | |
| 639 | - /** |
|
| 640 | - * Filter the sensei messages archive title. |
|
| 641 | - * @since 1.0.0 |
|
| 642 | - */ |
|
| 643 | - echo apply_filters( 'sensei_message_archive_title', $html ); |
|
| 639 | + /** |
|
| 640 | + * Filter the sensei messages archive title. |
|
| 641 | + * @since 1.0.0 |
|
| 642 | + */ |
|
| 643 | + echo apply_filters( 'sensei_message_archive_title', $html ); |
|
| 644 | 644 | |
| 645 | - } // get_archive_header() |
|
| 645 | + } // get_archive_header() |
|
| 646 | 646 | |
| 647 | - /** |
|
| 648 | - * Output the title for a message given the post_id. |
|
| 649 | - * |
|
| 650 | - * @since 1.9.0 |
|
| 651 | - * @param $post_id |
|
| 652 | - */ |
|
| 653 | - public static function the_message_title( $message_post_id ){ |
|
| 647 | + /** |
|
| 648 | + * Output the title for a message given the post_id. |
|
| 649 | + * |
|
| 650 | + * @since 1.9.0 |
|
| 651 | + * @param $post_id |
|
| 652 | + */ |
|
| 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 | - } else { |
|
| 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 | 669 | <a href="<?php esc_url( get_permalink( $message_post_id ) );?>"> |
| 670 | 670 | <?php echo $title; ?> |
@@ -673,21 +673,21 @@ discard block |
||
| 673 | 673 | </h2> |
| 674 | 674 | |
| 675 | 675 | <?php |
| 676 | - } //end the_message_header |
|
| 676 | + } //end the_message_header |
|
| 677 | 677 | |
| 678 | - /** |
|
| 679 | - * Output the message sender given the post id. |
|
| 680 | - * |
|
| 681 | - * @param $message_post_id |
|
| 682 | - */ |
|
| 683 | - public static function the_message_sender( $message_post_id ){ |
|
| 678 | + /** |
|
| 679 | + * Output the message sender given the post id. |
|
| 680 | + * |
|
| 681 | + * @param $message_post_id |
|
| 682 | + */ |
|
| 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() ); |
|
| 690 | - ?> |
|
| 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 | + ?> |
|
| 691 | 691 | <p class="message-meta"> |
| 692 | 692 | <small> |
| 693 | 693 | <em> <?php echo $sender_display_name; ?> </em> |
@@ -695,18 +695,18 @@ discard block |
||
| 695 | 695 | </p> |
| 696 | 696 | |
| 697 | 697 | <?php |
| 698 | - } // end if |
|
| 699 | - |
|
| 700 | - } // end the_message_archive_sender |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * Link to the users my messages page |
|
| 704 | - * |
|
| 705 | - * @since 1.9.0 |
|
| 706 | - */ |
|
| 707 | - public static function the_my_messages_link(){ |
|
| 708 | - if( ! Sensei()->settings->get('messages_disable') ) { |
|
| 709 | - ?> |
|
| 698 | + } // end if |
|
| 699 | + |
|
| 700 | + } // end the_message_archive_sender |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * Link to the users my messages page |
|
| 704 | + * |
|
| 705 | + * @since 1.9.0 |
|
| 706 | + */ |
|
| 707 | + public static function the_my_messages_link(){ |
|
| 708 | + if( ! Sensei()->settings->get('messages_disable') ) { |
|
| 709 | + ?> |
|
| 710 | 710 | <p class="my-messages-link-container"> |
| 711 | 711 | <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>" |
| 712 | 712 | title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>"> |
@@ -714,8 +714,8 @@ discard block |
||
| 714 | 714 | </a> |
| 715 | 715 | </p> |
| 716 | 716 | <?php |
| 717 | - } |
|
| 718 | - } |
|
| 717 | + } |
|
| 718 | + } |
|
| 719 | 719 | |
| 720 | 720 | } // End Class |
| 721 | 721 | |
@@ -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 ){ |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @since 1.0.0 |
| 21 | 21 | */ |
| 22 | 22 | public function __construct () { |
| 23 | - $this->token = 'question'; |
|
| 23 | + $this->token = 'question'; |
|
| 24 | 24 | $this->question_types = $this->question_types(); |
| 25 | 25 | $this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' ); |
| 26 | 26 | if ( is_admin() ) { |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 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 | 122 | if( $question_type ) { |
| 123 | 123 | $type = $this->question_types[ $question_type ]; |
@@ -237,15 +237,15 @@ discard block |
||
| 237 | 237 | public function save_question( $post_id = 0 ) { |
| 238 | 238 | |
| 239 | 239 | if( ! isset( $_POST['post_type'] |
| 240 | - ) || 'question' != $_POST['post_type'] ) { |
|
| 241 | - return; |
|
| 242 | - } |
|
| 240 | + ) || 'question' != $_POST['post_type'] ) { |
|
| 241 | + return; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | 244 | |
| 245 | 245 | |
| 246 | - //setup the data for saving |
|
| 246 | + //setup the data for saving |
|
| 247 | 247 | $data = $_POST ; |
| 248 | - $data['quiz_id'] = 0; |
|
| 248 | + $data['quiz_id'] = 0; |
|
| 249 | 249 | $data['question_id'] = $post_id; |
| 250 | 250 | |
| 251 | 251 | if ( ! wp_is_post_revision( $post_id ) ){ |
@@ -339,34 +339,34 @@ discard block |
||
| 339 | 339 | return $request; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - /** |
|
| 343 | - * Get the type of question by id |
|
| 344 | - * |
|
| 345 | - * This function uses the post terms to determine which question type |
|
| 346 | - * the passed question id belongs to. |
|
| 347 | - * |
|
| 348 | - * @since 1.7.4 |
|
| 349 | - * |
|
| 350 | - * @param int $question_id |
|
| 351 | - * |
|
| 352 | - * @return string $question_type | bool |
|
| 353 | - */ |
|
| 354 | - public function get_question_type( $question_id ){ |
|
| 355 | - |
|
| 356 | - if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 357 | - || 'question' != get_post_type( $question_id ) ){ |
|
| 358 | - return false; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - $question_type = 'multiple-choice'; |
|
| 362 | - $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 363 | - foreach( $question_types as $type ) { |
|
| 364 | - $question_type = $type->slug; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - return $question_type; |
|
| 368 | - |
|
| 369 | - }// end get_question_type |
|
| 342 | + /** |
|
| 343 | + * Get the type of question by id |
|
| 344 | + * |
|
| 345 | + * This function uses the post terms to determine which question type |
|
| 346 | + * the passed question id belongs to. |
|
| 347 | + * |
|
| 348 | + * @since 1.7.4 |
|
| 349 | + * |
|
| 350 | + * @param int $question_id |
|
| 351 | + * |
|
| 352 | + * @return string $question_type | bool |
|
| 353 | + */ |
|
| 354 | + public function get_question_type( $question_id ){ |
|
| 355 | + |
|
| 356 | + if( empty( $question_id ) || ! intval( $question_id ) > 0 |
|
| 357 | + || 'question' != get_post_type( $question_id ) ){ |
|
| 358 | + return false; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + $question_type = 'multiple-choice'; |
|
| 362 | + $question_types = wp_get_post_terms( $question_id, 'question-type' ); |
|
| 363 | + foreach( $question_types as $type ) { |
|
| 364 | + $question_type = $type->slug; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + return $question_type; |
|
| 368 | + |
|
| 369 | + }// end get_question_type |
|
| 370 | 370 | |
| 371 | 371 | /** |
| 372 | 372 | * Given a question ID, return the grade that can be achieved. |
@@ -398,317 +398,317 @@ discard block |
||
| 398 | 398 | } // end get_question_grade |
| 399 | 399 | |
| 400 | 400 | |
| 401 | - /** |
|
| 402 | - * This function simply loads the question type template |
|
| 403 | - * |
|
| 404 | - * @since 1.9.0 |
|
| 405 | - * @param $question_type |
|
| 406 | - */ |
|
| 407 | - public static function load_question_template( $question_type ){ |
|
| 408 | - |
|
| 409 | - Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Echo the sensei question title. |
|
| 414 | - * |
|
| 415 | - * @uses WooThemes_Sensei_Question::get_the_question_title |
|
| 416 | - * |
|
| 417 | - * @since 1.9.0 |
|
| 418 | - * @param $question_id |
|
| 419 | - */ |
|
| 420 | - public static function the_question_title( $question_id ){ |
|
| 421 | - |
|
| 422 | - echo self::get_the_question_title( $question_id ); |
|
| 423 | - |
|
| 424 | - }// end the_question_title |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Generate the question title with it's grade. |
|
| 428 | - * |
|
| 429 | - * @since 1.9.0 |
|
| 430 | - * |
|
| 431 | - * @param $question_id |
|
| 432 | - * @return string |
|
| 433 | - */ |
|
| 434 | - public static function get_the_question_title( $question_id ){ |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Filter the sensei question title |
|
| 438 | - * |
|
| 439 | - * @since 1.3.0 |
|
| 440 | - * @param $question_title |
|
| 441 | - */ |
|
| 442 | - $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * hook document in class-woothemes-sensei-message.php the_title() |
|
| 446 | - */ |
|
| 447 | - $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 448 | - |
|
| 449 | - $title_html = '<span class="question question-title">'; |
|
| 450 | - $title_html .= $title; |
|
| 451 | - $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
|
| 452 | - $title_html .='</span>'; |
|
| 453 | - |
|
| 454 | - return $title_html; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Tech the question description |
|
| 459 | - * |
|
| 460 | - * @param $question_id |
|
| 461 | - * @return string |
|
| 462 | - */ |
|
| 463 | - public static function get_the_question_description( $question_id ){ |
|
| 464 | - |
|
| 465 | - $question = get_post( $question_id ); |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Already documented within WordPress Core |
|
| 469 | - */ |
|
| 470 | - return apply_filters( 'the_content', $question->post_content ); |
|
| 471 | - |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Output the question description |
|
| 476 | - * |
|
| 477 | - * @since 1.9.0 |
|
| 478 | - * @param $question_id |
|
| 479 | - */ |
|
| 480 | - public static function the_question_description( $question_id ){ |
|
| 481 | - |
|
| 482 | - echo self::get_the_question_description( $question_id ); |
|
| 483 | - |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Get the questions media markup |
|
| 488 | - * |
|
| 489 | - * @since 1.9.0 |
|
| 490 | - * @param $question_id |
|
| 491 | - * @return string |
|
| 492 | - */ |
|
| 493 | - public static function get_the_question_media( $question_id ){ |
|
| 494 | - |
|
| 495 | - $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 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] ) { |
|
| 502 | - $question_media_type = $mimetype_array[0]; |
|
| 503 | - $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 504 | - $attachment = get_post( $question_media ); |
|
| 505 | - $question_media_title = $attachment->post_title; |
|
| 506 | - $question_media_description = $attachment->post_content; |
|
| 507 | - switch( $question_media_type ) { |
|
| 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>'; |
|
| 512 | - break; |
|
| 513 | - |
|
| 514 | - case 'audio': |
|
| 515 | - $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 516 | - break; |
|
| 517 | - |
|
| 518 | - case 'video': |
|
| 519 | - $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 520 | - break; |
|
| 521 | - |
|
| 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>'; |
|
| 525 | - break; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - $output = ''; |
|
| 532 | - if( $question_media_link ) { |
|
| 533 | - |
|
| 534 | - $output .= '<div class="question_media_display">'; |
|
| 535 | - $output .= $question_media_link; |
|
| 536 | - $output .= '<dl>'; |
|
| 537 | - |
|
| 538 | - if( $question_media_title ) { |
|
| 539 | - |
|
| 540 | - $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 541 | - |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - if( $question_media_description ) { |
|
| 545 | - |
|
| 546 | - $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 547 | - |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - $output .= '</dl>'; |
|
| 551 | - $output .= '</div>'; |
|
| 401 | + /** |
|
| 402 | + * This function simply loads the question type template |
|
| 403 | + * |
|
| 404 | + * @since 1.9.0 |
|
| 405 | + * @param $question_type |
|
| 406 | + */ |
|
| 407 | + public static function load_question_template( $question_type ){ |
|
| 408 | + |
|
| 409 | + Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Echo the sensei question title. |
|
| 414 | + * |
|
| 415 | + * @uses WooThemes_Sensei_Question::get_the_question_title |
|
| 416 | + * |
|
| 417 | + * @since 1.9.0 |
|
| 418 | + * @param $question_id |
|
| 419 | + */ |
|
| 420 | + public static function the_question_title( $question_id ){ |
|
| 421 | + |
|
| 422 | + echo self::get_the_question_title( $question_id ); |
|
| 423 | + |
|
| 424 | + }// end the_question_title |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Generate the question title with it's grade. |
|
| 428 | + * |
|
| 429 | + * @since 1.9.0 |
|
| 430 | + * |
|
| 431 | + * @param $question_id |
|
| 432 | + * @return string |
|
| 433 | + */ |
|
| 434 | + public static function get_the_question_title( $question_id ){ |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Filter the sensei question title |
|
| 438 | + * |
|
| 439 | + * @since 1.3.0 |
|
| 440 | + * @param $question_title |
|
| 441 | + */ |
|
| 442 | + $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * hook document in class-woothemes-sensei-message.php the_title() |
|
| 446 | + */ |
|
| 447 | + $title = apply_filters( 'sensei_single_title', $title, 'question'); |
|
| 448 | + |
|
| 449 | + $title_html = '<span class="question question-title">'; |
|
| 450 | + $title_html .= $title; |
|
| 451 | + $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; |
|
| 452 | + $title_html .='</span>'; |
|
| 453 | + |
|
| 454 | + return $title_html; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Tech the question description |
|
| 459 | + * |
|
| 460 | + * @param $question_id |
|
| 461 | + * @return string |
|
| 462 | + */ |
|
| 463 | + public static function get_the_question_description( $question_id ){ |
|
| 464 | + |
|
| 465 | + $question = get_post( $question_id ); |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Already documented within WordPress Core |
|
| 469 | + */ |
|
| 470 | + return apply_filters( 'the_content', $question->post_content ); |
|
| 471 | + |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Output the question description |
|
| 476 | + * |
|
| 477 | + * @since 1.9.0 |
|
| 478 | + * @param $question_id |
|
| 479 | + */ |
|
| 480 | + public static function the_question_description( $question_id ){ |
|
| 481 | + |
|
| 482 | + echo self::get_the_question_description( $question_id ); |
|
| 483 | + |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Get the questions media markup |
|
| 488 | + * |
|
| 489 | + * @since 1.9.0 |
|
| 490 | + * @param $question_id |
|
| 491 | + * @return string |
|
| 492 | + */ |
|
| 493 | + public static function get_the_question_media( $question_id ){ |
|
| 494 | + |
|
| 495 | + $question_media = get_post_meta( $question_id, '_question_media', true ); |
|
| 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] ) { |
|
| 502 | + $question_media_type = $mimetype_array[0]; |
|
| 503 | + $question_media_url = wp_get_attachment_url( $question_media ); |
|
| 504 | + $attachment = get_post( $question_media ); |
|
| 505 | + $question_media_title = $attachment->post_title; |
|
| 506 | + $question_media_description = $attachment->post_content; |
|
| 507 | + switch( $question_media_type ) { |
|
| 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>'; |
|
| 512 | + break; |
|
| 513 | + |
|
| 514 | + case 'audio': |
|
| 515 | + $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); |
|
| 516 | + break; |
|
| 517 | + |
|
| 518 | + case 'video': |
|
| 519 | + $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); |
|
| 520 | + break; |
|
| 521 | + |
|
| 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>'; |
|
| 525 | + break; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + $output = ''; |
|
| 532 | + if( $question_media_link ) { |
|
| 552 | 533 | |
| 534 | + $output .= '<div class="question_media_display">'; |
|
| 535 | + $output .= $question_media_link; |
|
| 536 | + $output .= '<dl>'; |
|
| 553 | 537 | |
| 554 | - } |
|
| 555 | - |
|
| 556 | - return $output; |
|
| 557 | - |
|
| 558 | - } // end get_the_question_media |
|
| 559 | - |
|
| 538 | + if( $question_media_title ) { |
|
| 560 | 539 | |
| 561 | - /** |
|
| 562 | - * Output the question media |
|
| 563 | - * |
|
| 564 | - * @since 1.9.0 |
|
| 565 | - * @param string $question_id |
|
| 566 | - */ |
|
| 567 | - public static function the_question_media( $question_id ){ |
|
| 540 | + $output .= '<dt>'. $question_media_title. '</dt>'; |
|
| 568 | 541 | |
| 569 | - echo self::get_the_question_media( $question_id ); |
|
| 542 | + } |
|
| 570 | 543 | |
| 571 | - } |
|
| 544 | + if( $question_media_description ) { |
|
| 572 | 545 | |
| 573 | - /** |
|
| 574 | - * Output a special field for the question needed for question submission. |
|
| 575 | - * |
|
| 576 | - * @since 1.9.0 |
|
| 577 | - * |
|
| 578 | - * @param $question_id |
|
| 579 | - */ |
|
| 580 | - public static function the_question_hidden_fields( $question_id ){ |
|
| 581 | - ?> |
|
| 546 | + $output .= '<dd>' . $question_media_description . '</dd>'; |
|
| 547 | + |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + $output .= '</dl>'; |
|
| 551 | + $output .= '</div>'; |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + return $output; |
|
| 557 | + |
|
| 558 | + } // end get_the_question_media |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Output the question media |
|
| 563 | + * |
|
| 564 | + * @since 1.9.0 |
|
| 565 | + * @param string $question_id |
|
| 566 | + */ |
|
| 567 | + public static function the_question_media( $question_id ){ |
|
| 568 | + |
|
| 569 | + echo self::get_the_question_media( $question_id ); |
|
| 570 | + |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Output a special field for the question needed for question submission. |
|
| 575 | + * |
|
| 576 | + * @since 1.9.0 |
|
| 577 | + * |
|
| 578 | + * @param $question_id |
|
| 579 | + */ |
|
| 580 | + public static function the_question_hidden_fields( $question_id ){ |
|
| 581 | + ?> |
|
| 582 | 582 | |
| 583 | 583 | <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" /> |
| 584 | 584 | <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" /> |
| 585 | 585 | |
| 586 | 586 | <?php |
| 587 | - } |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | - /** |
|
| 590 | - * This function can only be run withing the single quiz question loop |
|
| 591 | - * |
|
| 592 | - * @since 1.9.0 |
|
| 593 | - * @param $question_id |
|
| 594 | - */ |
|
| 595 | - public static function answer_feedback_notes( $question_id ){ |
|
| 589 | + /** |
|
| 590 | + * This function can only be run withing the single quiz question loop |
|
| 591 | + * |
|
| 592 | + * @since 1.9.0 |
|
| 593 | + * @param $question_id |
|
| 594 | + */ |
|
| 595 | + public static function answer_feedback_notes( $question_id ){ |
|
| 596 | 596 | |
| 597 | - //IDS |
|
| 598 | - $quiz_id = get_the_ID(); |
|
| 599 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 597 | + //IDS |
|
| 598 | + $quiz_id = get_the_ID(); |
|
| 599 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 600 | 600 | |
| 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 ); |
|
| 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 ); |
|
| 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 | |
| 619 | 619 | <?php |
| 620 | 620 | |
| 621 | - /** |
|
| 622 | - * Filter the answer feedback |
|
| 623 | - * Since 1.9.0 |
|
| 624 | - * |
|
| 625 | - * @param string $answer_notes |
|
| 626 | - * @param string $question_id |
|
| 627 | - * @param string $lesson_id |
|
| 628 | - */ |
|
| 629 | - echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 621 | + /** |
|
| 622 | + * Filter the answer feedback |
|
| 623 | + * Since 1.9.0 |
|
| 624 | + * |
|
| 625 | + * @param string $answer_notes |
|
| 626 | + * @param string $question_id |
|
| 627 | + * @param string $lesson_id |
|
| 628 | + */ |
|
| 629 | + echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); |
|
| 630 | 630 | |
| 631 | - ?> |
|
| 631 | + ?> |
|
| 632 | 632 | |
| 633 | 633 | </div> |
| 634 | 634 | |
| 635 | 635 | <?php } |
| 636 | 636 | |
| 637 | - }// end if we can show answer feedback |
|
| 637 | + }// end if we can show answer feedback |
|
| 638 | 638 | |
| 639 | - }// end answer_feedback_notes |
|
| 639 | + }// end answer_feedback_notes |
|
| 640 | 640 | |
| 641 | - /** |
|
| 642 | - * This function has to be run inside the quiz question loop on the single quiz page. |
|
| 643 | - * |
|
| 644 | - * |
|
| 645 | - * @since 1.9.0 |
|
| 646 | - * @param string $question_id |
|
| 647 | - */ |
|
| 648 | - public static function the_answer_result_indication( $question_id ){ |
|
| 641 | + /** |
|
| 642 | + * This function has to be run inside the quiz question loop on the single quiz page. |
|
| 643 | + * |
|
| 644 | + * |
|
| 645 | + * @since 1.9.0 |
|
| 646 | + * @param string $question_id |
|
| 647 | + */ |
|
| 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 | - // Post Data |
|
| 653 | - $quiz_id = $sensei_question_loop['quiz_id']; |
|
| 654 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 655 | - $question_item = $sensei_question_loop['current_question']; |
|
| 652 | + // Post Data |
|
| 653 | + $quiz_id = $sensei_question_loop['quiz_id']; |
|
| 654 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 655 | + $question_item = $sensei_question_loop['current_question']; |
|
| 656 | 656 | |
| 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 ); |
|
| 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 ); |
|
| 662 | 662 | |
| 663 | - // retrieve the question total grade |
|
| 664 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 663 | + // retrieve the question total grade |
|
| 664 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); |
|
| 665 | 665 | |
| 666 | - // retrieve grade the user achieved |
|
| 667 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 666 | + // retrieve grade the user achieved |
|
| 667 | + $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); |
|
| 668 | 668 | |
| 669 | - // Question ID |
|
| 670 | - $question_id = $question_item->ID; |
|
| 669 | + // Question ID |
|
| 670 | + $question_id = $question_item->ID; |
|
| 671 | 671 | |
| 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 != '' ; |
|
| 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 != '' ; |
|
| 676 | 676 | |
| 677 | - if ( $completed_with_valid_grade |
|
| 678 | - || $completed_with_valid_grade_and_reset_not_allowed |
|
| 679 | - || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 677 | + if ( $completed_with_valid_grade |
|
| 678 | + || $completed_with_valid_grade_and_reset_not_allowed |
|
| 679 | + || $grade_type_auto_a_valid_grade_and_reset_not_allowed ) { |
|
| 680 | 680 | |
| 681 | - $user_correct = false; |
|
| 682 | - $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 683 | - $answer_message_class = 'user_wrong'; |
|
| 684 | - // For zero grade mark as 'correct' but add no classes |
|
| 685 | - if ( 0 == $question_grade ) { |
|
| 681 | + $user_correct = false; |
|
| 682 | + $answer_message = __( 'Incorrect', 'woothemes-sensei' ); |
|
| 683 | + $answer_message_class = 'user_wrong'; |
|
| 684 | + // For zero grade mark as 'correct' but add no classes |
|
| 685 | + if ( 0 == $question_grade ) { |
|
| 686 | 686 | |
| 687 | - $user_correct = true; |
|
| 688 | - $answer_message = ''; |
|
| 689 | - $answer_message_class = ''; |
|
| 687 | + $user_correct = true; |
|
| 688 | + $answer_message = ''; |
|
| 689 | + $answer_message_class = ''; |
|
| 690 | 690 | |
| 691 | - } else if( $user_question_grade > 0 ) { |
|
| 691 | + } else if( $user_question_grade > 0 ) { |
|
| 692 | 692 | |
| 693 | - $user_correct = true; |
|
| 694 | - $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 695 | - $answer_message_class = 'user_right'; |
|
| 693 | + $user_correct = true; |
|
| 694 | + $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); |
|
| 695 | + $answer_message_class = 'user_right'; |
|
| 696 | 696 | |
| 697 | - } |
|
| 697 | + } |
|
| 698 | 698 | |
| 699 | - // attach the correct answer if the question is auto gradable and user got it wrong |
|
| 700 | - if( !$reset_quiz_allowed && !$user_correct ){ |
|
| 699 | + // attach the correct answer if the question is auto gradable and user got it wrong |
|
| 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 | - // answer feedback |
|
| 707 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 708 | - if( $answer_notes ) { |
|
| 709 | - $answer_message_class .= ' has_notes'; |
|
| 710 | - } |
|
| 711 | - ?> |
|
| 706 | + // answer feedback |
|
| 707 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); |
|
| 708 | + if( $answer_notes ) { |
|
| 709 | + $answer_message_class .= ' has_notes'; |
|
| 710 | + } |
|
| 711 | + ?> |
|
| 712 | 712 | |
| 713 | 713 | <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>"> |
| 714 | 714 | |
@@ -718,387 +718,387 @@ discard block |
||
| 718 | 718 | |
| 719 | 719 | <?php |
| 720 | 720 | |
| 721 | - } // end if user can see all the goodies |
|
| 722 | - |
|
| 723 | - }// end the_answer_result_indication |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * Generate the question template data and return it as an array. |
|
| 727 | - * |
|
| 728 | - * @since 1.9.0 |
|
| 729 | - * |
|
| 730 | - * @param string $question_id |
|
| 731 | - * @param $quiz_id |
|
| 732 | - * @return array $question_data |
|
| 733 | - */ |
|
| 734 | - public static function get_template_data( $question_id, $quiz_id ){ |
|
| 735 | - |
|
| 736 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 737 | - |
|
| 738 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 739 | - //backwards compatibility |
|
| 740 | - if( 'on' == $reset_allowed ) { |
|
| 741 | - $reset_allowed = 1; |
|
| 742 | - } |
|
| 743 | - |
|
| 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() ); |
|
| 746 | - $user_lesson_complete = false; |
|
| 747 | - if ( $user_lesson_end ) { |
|
| 748 | - $user_lesson_complete = true; |
|
| 749 | - } |
|
| 750 | - |
|
| 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; |
|
| 767 | - |
|
| 768 | - /** |
|
| 769 | - * Filter the question template data. This filter fires in |
|
| 770 | - * the get_template_data function |
|
| 771 | - * |
|
| 772 | - * @hooked self::boolean_load_question_data |
|
| 773 | - * |
|
| 774 | - * @since 1.9.0 |
|
| 775 | - * |
|
| 776 | - * @param array $data |
|
| 777 | - * @param string $question_id |
|
| 778 | - * @param string $quiz_id |
|
| 779 | - */ |
|
| 780 | - return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 721 | + } // end if user can see all the goodies |
|
| 781 | 722 | |
| 782 | - } |
|
| 723 | + }// end the_answer_result_indication |
|
| 783 | 724 | |
| 784 | - /** |
|
| 785 | - * Load multiple choice question data on the sensei_get_question_template_data |
|
| 786 | - * filter. |
|
| 787 | - * |
|
| 788 | - * @since 1.9.0 |
|
| 789 | - * |
|
| 790 | - * @param $question_data |
|
| 791 | - * @param $question_id |
|
| 792 | - * @param $quiz_id |
|
| 793 | - * |
|
| 794 | - * @return array() |
|
| 795 | - */ |
|
| 796 | - public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 725 | + /** |
|
| 726 | + * Generate the question template data and return it as an array. |
|
| 727 | + * |
|
| 728 | + * @since 1.9.0 |
|
| 729 | + * |
|
| 730 | + * @param string $question_id |
|
| 731 | + * @param $quiz_id |
|
| 732 | + * @return array $question_data |
|
| 733 | + */ |
|
| 734 | + public static function get_template_data( $question_id, $quiz_id ){ |
|
| 797 | 735 | |
| 736 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 798 | 737 | |
| 799 | - if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 738 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 739 | + //backwards compatibility |
|
| 740 | + if( 'on' == $reset_allowed ) { |
|
| 741 | + $reset_allowed = 1; |
|
| 742 | + } |
|
| 800 | 743 | |
| 801 | - // Get uploaded file |
|
| 802 | - $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 803 | - $answer_media_url = $answer_media_filename = ''; |
|
| 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() ); |
|
| 746 | + $user_lesson_complete = false; |
|
| 747 | + if ( $user_lesson_end ) { |
|
| 748 | + $user_lesson_complete = true; |
|
| 749 | + } |
|
| 804 | 750 | |
| 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; |
|
| 767 | + |
|
| 768 | + /** |
|
| 769 | + * Filter the question template data. This filter fires in |
|
| 770 | + * the get_template_data function |
|
| 771 | + * |
|
| 772 | + * @hooked self::boolean_load_question_data |
|
| 773 | + * |
|
| 774 | + * @since 1.9.0 |
|
| 775 | + * |
|
| 776 | + * @param array $data |
|
| 777 | + * @param string $question_id |
|
| 778 | + * @param string $quiz_id |
|
| 779 | + */ |
|
| 780 | + return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); |
|
| 805 | 781 | |
| 806 | - $question_helptext = ''; |
|
| 807 | - if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 782 | + } |
|
| 808 | 783 | |
| 809 | - $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 784 | + /** |
|
| 785 | + * Load multiple choice question data on the sensei_get_question_template_data |
|
| 786 | + * filter. |
|
| 787 | + * |
|
| 788 | + * @since 1.9.0 |
|
| 789 | + * |
|
| 790 | + * @param $question_data |
|
| 791 | + * @param $question_id |
|
| 792 | + * @param $quiz_id |
|
| 793 | + * |
|
| 794 | + * @return array() |
|
| 795 | + */ |
|
| 796 | + public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ |
|
| 810 | 797 | |
| 811 | - } |
|
| 812 | 798 | |
| 799 | + if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 813 | 800 | |
| 814 | - if( 0 < intval( $attachment_id ) ) { |
|
| 801 | + // Get uploaded file |
|
| 802 | + $attachment_id = $question_data[ 'user_answer_entry' ]; |
|
| 803 | + $answer_media_url = $answer_media_filename = ''; |
|
| 815 | 804 | |
| 816 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 817 | - $answer_media_filename = basename( $answer_media_url ); |
|
| 818 | 805 | |
| 819 | - } |
|
| 806 | + $question_helptext = ''; |
|
| 807 | + if( isset( $question_data['question_wrong_answers'][0] ) ) { |
|
| 820 | 808 | |
| 809 | + $question_helptext = $question_data['question_wrong_answers'][0]; |
|
| 821 | 810 | |
| 822 | - // Get max upload file size, formatted for display |
|
| 823 | - // Code copied from wp-admin/includes/media.php:1515 |
|
| 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++ ) { |
|
| 827 | - $upload_size_unit /= 1024; |
|
| 828 | - } |
|
| 829 | - if ( $u < 0 ) { |
|
| 811 | + } |
|
| 830 | 812 | |
| 831 | - $upload_size_unit = 0; |
|
| 832 | - $u = 0; |
|
| 833 | 813 | |
| 834 | - } else { |
|
| 814 | + if( 0 < intval( $attachment_id ) ) { |
|
| 835 | 815 | |
| 836 | - $upload_size_unit = (int) $upload_size_unit; |
|
| 816 | + $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 817 | + $answer_media_filename = basename( $answer_media_url ); |
|
| 837 | 818 | |
| 838 | - } |
|
| 839 | - $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 819 | + } |
|
| 840 | 820 | |
| 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; |
|
| 845 | 821 | |
| 846 | - $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 822 | + // Get max upload file size, formatted for display |
|
| 823 | + // Code copied from wp-admin/includes/media.php:1515 |
|
| 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++ ) { |
|
| 827 | + $upload_size_unit /= 1024; |
|
| 828 | + } |
|
| 829 | + if ( $u < 0 ) { |
|
| 847 | 830 | |
| 848 | - }// end if is file upload type |
|
| 831 | + $upload_size_unit = 0; |
|
| 832 | + $u = 0; |
|
| 849 | 833 | |
| 850 | - return $question_data; |
|
| 834 | + } else { |
|
| 851 | 835 | |
| 852 | - }// end file_upload_load_question_data |
|
| 836 | + $upload_size_unit = (int) $upload_size_unit; |
|
| 853 | 837 | |
| 854 | - /** |
|
| 855 | - * Load multiple choice question data on the sensei_get_question_template_data |
|
| 856 | - * filter. |
|
| 857 | - * |
|
| 858 | - * @since 1.9.0 |
|
| 859 | - * |
|
| 860 | - * @param $question_data |
|
| 861 | - * @param $question_id |
|
| 862 | - * @param $quiz_id |
|
| 863 | - * |
|
| 864 | - * @return array() |
|
| 865 | - */ |
|
| 866 | - public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 838 | + } |
|
| 839 | + $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); |
|
| 867 | 840 | |
| 868 | - if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 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; |
|
| 869 | 845 | |
| 846 | + $question_data[ 'question_helptext' ] = $question_helptext; |
|
| 870 | 847 | |
| 871 | - $answer_type = 'radio'; |
|
| 872 | - if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 848 | + }// end if is file upload type |
|
| 873 | 849 | |
| 874 | - $answer_type = 'checkbox'; |
|
| 850 | + return $question_data; |
|
| 875 | 851 | |
| 876 | - } |
|
| 852 | + }// end file_upload_load_question_data |
|
| 877 | 853 | |
| 878 | - // Merge right and wrong answers |
|
| 879 | - if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 854 | + /** |
|
| 855 | + * Load multiple choice question data on the sensei_get_question_template_data |
|
| 856 | + * filter. |
|
| 857 | + * |
|
| 858 | + * @since 1.9.0 |
|
| 859 | + * |
|
| 860 | + * @param $question_data |
|
| 861 | + * @param $question_id |
|
| 862 | + * @param $quiz_id |
|
| 863 | + * |
|
| 864 | + * @return array() |
|
| 865 | + */ |
|
| 866 | + public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 880 | 867 | |
| 881 | - $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 868 | + if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 882 | 869 | |
| 883 | - } else { |
|
| 884 | 870 | |
| 885 | - array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 886 | - $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 871 | + $answer_type = 'radio'; |
|
| 872 | + if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { |
|
| 887 | 873 | |
| 888 | - } |
|
| 874 | + $answer_type = 'checkbox'; |
|
| 889 | 875 | |
| 890 | - // Setup answer options array. |
|
| 891 | - $question_answers_options = array(); |
|
| 892 | - $count = 0; |
|
| 876 | + } |
|
| 893 | 877 | |
| 894 | - foreach( $merged_options as $answer ) { |
|
| 878 | + // Merge right and wrong answers |
|
| 879 | + if ( is_array( $question_data[ 'question_right_answer' ] ) ) { |
|
| 895 | 880 | |
| 896 | - $count++; |
|
| 897 | - $question_option = array(); |
|
| 881 | + $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 898 | 882 | |
| 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' ] ) ) ) { |
|
| 883 | + } else { |
|
| 902 | 884 | |
| 903 | - $user_correct = false; |
|
| 885 | + array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); |
|
| 886 | + $merged_options = $question_data[ 'question_wrong_answers' ]; |
|
| 904 | 887 | |
| 888 | + } |
|
| 905 | 889 | |
| 906 | - // For zero grade mark as 'correct' but add no classes |
|
| 907 | - if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 890 | + // Setup answer options array. |
|
| 891 | + $question_answers_options = array(); |
|
| 892 | + $count = 0; |
|
| 908 | 893 | |
| 909 | - $user_correct = true; |
|
| 894 | + foreach( $merged_options as $answer ) { |
|
| 910 | 895 | |
| 911 | - } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 896 | + $count++; |
|
| 897 | + $question_option = array(); |
|
| 912 | 898 | |
| 913 | - $user_correct = true; |
|
| 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' ] ) ) ) { |
|
| 914 | 902 | |
| 915 | - } |
|
| 903 | + $user_correct = false; |
|
| 916 | 904 | |
| 917 | - } |
|
| 918 | 905 | |
| 919 | - // setup the option specific classes |
|
| 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']) ) { |
|
| 906 | + // For zero grade mark as 'correct' but add no classes |
|
| 907 | + if ( 0 == $question_data[ 'question_grade' ] ) { |
|
| 923 | 908 | |
| 924 | - $answer_class .= ' right_answer'; |
|
| 909 | + $user_correct = true; |
|
| 925 | 910 | |
| 926 | - } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 911 | + } else if( $question_data[ 'user_question_grade' ] > 0 ) { |
|
| 927 | 912 | |
| 928 | - $answer_class .= ' right_answer'; |
|
| 913 | + $user_correct = true; |
|
| 929 | 914 | |
| 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 ) ) { |
|
| 915 | + } |
|
| 932 | 916 | |
| 933 | - $answer_class = 'user_wrong'; |
|
| 934 | - if( $user_correct ) { |
|
| 917 | + } |
|
| 935 | 918 | |
| 936 | - $answer_class = 'user_right'; |
|
| 919 | + // setup the option specific classes |
|
| 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']) ) { |
|
| 937 | 923 | |
| 938 | - } |
|
| 924 | + $answer_class .= ' right_answer'; |
|
| 939 | 925 | |
| 940 | - } |
|
| 926 | + } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { |
|
| 941 | 927 | |
| 942 | - } |
|
| 928 | + $answer_class .= ' right_answer'; |
|
| 943 | 929 | |
| 944 | - // determine if the current option must be checked |
|
| 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'] ) ) { |
|
| 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 ) ) { |
|
| 948 | 932 | |
| 949 | - $checked = 'checked="checked"'; |
|
| 933 | + $answer_class = 'user_wrong'; |
|
| 934 | + if( $user_correct ) { |
|
| 950 | 935 | |
| 951 | - } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 936 | + $answer_class = 'user_right'; |
|
| 952 | 937 | |
| 953 | - $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 938 | + } |
|
| 954 | 939 | |
| 955 | - } |
|
| 940 | + } |
|
| 956 | 941 | |
| 957 | - } // End If Statement |
|
| 942 | + } |
|
| 958 | 943 | |
| 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; |
|
| 944 | + // determine if the current option must be checked |
|
| 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'] ) ) { |
|
| 966 | 948 | |
| 967 | - // add the speci fic option to the list of options for this question |
|
| 968 | - $question_answers_options[$question_option[ 'ID' ]] = $question_option; |
|
| 949 | + $checked = 'checked="checked"'; |
|
| 969 | 950 | |
| 970 | - } // end for each option |
|
| 951 | + } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { |
|
| 971 | 952 | |
| 953 | + $checked = checked( $answer, $question_data['user_answer_entry'] , false ); |
|
| 972 | 954 | |
| 973 | - // Shuffle the array depending on the settings |
|
| 974 | - $answer_options_sorted = array(); |
|
| 975 | - $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 976 | - if( $random_order && $random_order == 'yes' ) { |
|
| 955 | + } |
|
| 977 | 956 | |
| 978 | - $answer_options_sorted = $question_answers_options; |
|
| 979 | - shuffle( $answer_options_sorted ); |
|
| 957 | + } // End If Statement |
|
| 980 | 958 | |
| 981 | - } else { |
|
| 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; |
|
| 982 | 966 | |
| 983 | - $answer_order = array(); |
|
| 984 | - $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 985 | - if( $answer_order_string ) { |
|
| 967 | + // add the speci fic option to the list of options for this question |
|
| 968 | + $question_answers_options[$question_option[ 'ID' ]] = $question_option; |
|
| 986 | 969 | |
| 987 | - $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 988 | - if( count( $answer_order ) > 0 ) { |
|
| 970 | + } // end for each option |
|
| 989 | 971 | |
| 990 | - foreach( $answer_order as $answer_id ) { |
|
| 991 | 972 | |
| 992 | - if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 973 | + // Shuffle the array depending on the settings |
|
| 974 | + $answer_options_sorted = array(); |
|
| 975 | + $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); |
|
| 976 | + if( $random_order && $random_order == 'yes' ) { |
|
| 993 | 977 | |
| 994 | - $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 995 | - unset( $question_answers_options[ $answer_id ] ); |
|
| 978 | + $answer_options_sorted = $question_answers_options; |
|
| 979 | + shuffle( $answer_options_sorted ); |
|
| 996 | 980 | |
| 997 | - } |
|
| 981 | + } else { |
|
| 998 | 982 | |
| 999 | - } |
|
| 983 | + $answer_order = array(); |
|
| 984 | + $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); |
|
| 985 | + if( $answer_order_string ) { |
|
| 1000 | 986 | |
| 1001 | - if( count( $question_answers_options ) > 0 ) { |
|
| 1002 | - foreach( $question_answers_options as $id => $answer ) { |
|
| 987 | + $answer_order = array_filter( explode( ',', $answer_order_string ) ); |
|
| 988 | + if( count( $answer_order ) > 0 ) { |
|
| 1003 | 989 | |
| 1004 | - $answer_options_sorted[ $id ] = $answer; |
|
| 990 | + foreach( $answer_order as $answer_id ) { |
|
| 1005 | 991 | |
| 1006 | - } |
|
| 1007 | - } |
|
| 992 | + if( isset( $question_answers_options[ $answer_id ] ) ) { |
|
| 1008 | 993 | |
| 1009 | - }else{ |
|
| 994 | + $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; |
|
| 995 | + unset( $question_answers_options[ $answer_id ] ); |
|
| 1010 | 996 | |
| 1011 | - $answer_options_sorted = $question_answers_options; |
|
| 997 | + } |
|
| 1012 | 998 | |
| 1013 | - } |
|
| 999 | + } |
|
| 1014 | 1000 | |
| 1015 | - }else{ |
|
| 1001 | + if( count( $question_answers_options ) > 0 ) { |
|
| 1002 | + foreach( $question_answers_options as $id => $answer ) { |
|
| 1016 | 1003 | |
| 1017 | - $answer_options_sorted = $question_answers_options; |
|
| 1004 | + $answer_options_sorted[ $id ] = $answer; |
|
| 1018 | 1005 | |
| 1019 | - } // end if $answer_order_string |
|
| 1006 | + } |
|
| 1007 | + } |
|
| 1020 | 1008 | |
| 1021 | - } // end if random order |
|
| 1009 | + }else{ |
|
| 1022 | 1010 | |
| 1011 | + $answer_options_sorted = $question_answers_options; |
|
| 1023 | 1012 | |
| 1024 | - // assemble and setup the data for the templates data array |
|
| 1025 | - $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1013 | + } |
|
| 1026 | 1014 | |
| 1027 | - } |
|
| 1015 | + }else{ |
|
| 1028 | 1016 | |
| 1029 | - return $question_data; |
|
| 1017 | + $answer_options_sorted = $question_answers_options; |
|
| 1030 | 1018 | |
| 1031 | - }// end multiple_choice_load_question_data |
|
| 1019 | + } // end if $answer_order_string |
|
| 1032 | 1020 | |
| 1033 | - /** |
|
| 1034 | - * Load the gap fill question data on the sensei_get_question_template_data |
|
| 1035 | - * filter. |
|
| 1036 | - * |
|
| 1037 | - * @since 1.9.0 |
|
| 1038 | - * |
|
| 1039 | - * @param $question_data |
|
| 1040 | - * @param $question_id |
|
| 1041 | - * @param $quiz_id |
|
| 1042 | - * |
|
| 1043 | - * @return array() |
|
| 1044 | - */ |
|
| 1045 | - public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1021 | + } // end if random order |
|
| 1046 | 1022 | |
| 1047 | - if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 1048 | 1023 | |
| 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] : ''; |
|
| 1024 | + // assemble and setup the data for the templates data array |
|
| 1025 | + $question_data[ 'answer_options' ] = $answer_options_sorted; |
|
| 1053 | 1026 | |
| 1054 | - } |
|
| 1027 | + } |
|
| 1055 | 1028 | |
| 1056 | - return $question_data; |
|
| 1029 | + return $question_data; |
|
| 1057 | 1030 | |
| 1058 | - }// end gap_fill_load_question_data |
|
| 1031 | + }// end multiple_choice_load_question_data |
|
| 1032 | + |
|
| 1033 | + /** |
|
| 1034 | + * Load the gap fill question data on the sensei_get_question_template_data |
|
| 1035 | + * filter. |
|
| 1036 | + * |
|
| 1037 | + * @since 1.9.0 |
|
| 1038 | + * |
|
| 1039 | + * @param $question_data |
|
| 1040 | + * @param $question_id |
|
| 1041 | + * @param $quiz_id |
|
| 1042 | + * |
|
| 1043 | + * @return array() |
|
| 1044 | + */ |
|
| 1045 | + public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ |
|
| 1046 | + |
|
| 1047 | + if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { |
|
| 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] : ''; |
|
| 1053 | + |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + return $question_data; |
|
| 1057 | + |
|
| 1058 | + }// end gap_fill_load_question_data |
|
| 1059 | 1059 | |
| 1060 | 1060 | |
| 1061 | - /** |
|
| 1062 | - * Get the correct answer for a question |
|
| 1063 | - * |
|
| 1064 | - * @param $question_id |
|
| 1065 | - * @return string $correct_answer or empty |
|
| 1066 | - */ |
|
| 1067 | - public static function get_correct_answer( $question_id ){ |
|
| 1061 | + /** |
|
| 1062 | + * Get the correct answer for a question |
|
| 1063 | + * |
|
| 1064 | + * @param $question_id |
|
| 1065 | + * @return string $correct_answer or empty |
|
| 1066 | + */ |
|
| 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' ); |
|
| 1072 | - $grade_type = 'manual-grade'; |
|
| 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 | + $grade_type = 'manual-grade'; |
|
| 1073 | 1073 | |
| 1074 | - if ('boolean'== $type ) { |
|
| 1074 | + if ('boolean'== $type ) { |
|
| 1075 | 1075 | |
| 1076 | - $right_answer = ucfirst($right_answer); |
|
| 1076 | + $right_answer = ucfirst($right_answer); |
|
| 1077 | 1077 | |
| 1078 | - }elseif( 'multiple-choice' == $type ) { |
|
| 1078 | + }elseif( 'multiple-choice' == $type ) { |
|
| 1079 | 1079 | |
| 1080 | - $right_answer = (array) $right_answer; |
|
| 1081 | - $right_answer = implode( ', ', $right_answer ); |
|
| 1080 | + $right_answer = (array) $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 | - // for non auto gradable question types no answer should be returned. |
|
| 1095 | - $right_answer = ''; |
|
| 1094 | + // for non auto gradable question types no answer should be returned. |
|
| 1095 | + $right_answer = ''; |
|
| 1096 | 1096 | |
| 1097 | - } |
|
| 1097 | + } |
|
| 1098 | 1098 | |
| 1099 | - return $right_answer; |
|
| 1099 | + return $right_answer; |
|
| 1100 | 1100 | |
| 1101 | - } // get_correct_answer |
|
| 1101 | + } // get_correct_answer |
|
| 1102 | 1102 | |
| 1103 | 1103 | } // End Class |
| 1104 | 1104 | |
@@ -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 ){ |
@@ -24,69 +24,69 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public function __construct ( $file = __FILE__ ) { |
| 26 | 26 | $this->file = $file; |
| 27 | - $this->token = 'quiz'; |
|
| 27 | + $this->token = 'quiz'; |
|
| 28 | 28 | $this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' ); |
| 29 | 29 | add_action( 'save_post', array( $this, 'update_author' )); |
| 30 | 30 | |
| 31 | 31 | // listen to the reset button click |
| 32 | 32 | add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
| 33 | 33 | |
| 34 | - // fire the complete quiz button submit for grading action |
|
| 35 | - add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'user_quiz_submit_listener' ) ); |
|
| 34 | + // fire the complete quiz button submit for grading action |
|
| 35 | + add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'user_quiz_submit_listener' ) ); |
|
| 36 | 36 | |
| 37 | 37 | // fire the save user answers quiz button click responder |
| 38 | 38 | add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'user_save_quiz_answers_listener' ) ); |
| 39 | 39 | |
| 40 | - // fire the load global data function |
|
| 41 | - add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'load_global_quiz_data' ), 80 ); |
|
| 40 | + // fire the load global data function |
|
| 41 | + add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'load_global_quiz_data' ), 80 ); |
|
| 42 | 42 | |
| 43 | - add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
| 43 | + add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - } // End __construct() |
|
| 46 | + } // End __construct() |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * Update the quiz author when the lesson post type is save |
|
| 50 | - * |
|
| 51 | - * @param int $post_id |
|
| 52 | - * @return void |
|
| 53 | - */ |
|
| 49 | + * Update the quiz author when the lesson post type is save |
|
| 50 | + * |
|
| 51 | + * @param int $post_id |
|
| 52 | + * @return void |
|
| 53 | + */ |
|
| 54 | 54 | public function update_author( $post_id ){ |
| 55 | 55 | |
| 56 | 56 | // If this isn't a 'lesson' post, don't update it. |
| 57 | - // if this is a revision don't save it |
|
| 58 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
| 59 | - || wp_is_post_revision( $post_id ) ) { |
|
| 57 | + // if this is a revision don't save it |
|
| 58 | + if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
| 59 | + || wp_is_post_revision( $post_id ) ) { |
|
| 60 | 60 | |
| 61 | - return; |
|
| 61 | + return; |
|
| 62 | 62 | |
| 63 | - } |
|
| 64 | - // get the lesson author id to be use late |
|
| 65 | - $saved_post = get_post( $post_id ); |
|
| 66 | - $new_lesson_author_id = $saved_post->post_author; |
|
| 63 | + } |
|
| 64 | + // get the lesson author id to be use late |
|
| 65 | + $saved_post = get_post( $post_id ); |
|
| 66 | + $new_lesson_author_id = $saved_post->post_author; |
|
| 67 | 67 | |
| 68 | - //get the lessons quiz |
|
| 68 | + //get the lessons quiz |
|
| 69 | 69 | $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); |
| 70 | - foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
| 70 | + foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
| 71 | 71 | |
| 72 | - if( ! $quiz_item ) { |
|
| 73 | - continue; |
|
| 74 | - } |
|
| 72 | + if( ! $quiz_item ) { |
|
| 73 | + continue; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // setup the quiz items new author value |
|
| 76 | + // setup the quiz items new author value |
|
| 77 | 77 | $my_post = array( |
| 78 | - 'ID' => $quiz_item, |
|
| 79 | - 'post_author' => $new_lesson_author_id |
|
| 78 | + 'ID' => $quiz_item, |
|
| 79 | + 'post_author' => $new_lesson_author_id |
|
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | - // remove the action so that it doesn't fire again |
|
| 83 | - remove_action( 'save_post', array( $this, 'update_author' )); |
|
| 82 | + // remove the action so that it doesn't fire again |
|
| 83 | + remove_action( 'save_post', array( $this, 'update_author' )); |
|
| 84 | 84 | |
| 85 | 85 | // Update the post into the database |
| 86 | 86 | wp_update_post( $my_post ); |
| 87 | - } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - return; |
|
| 89 | + return; |
|
| 90 | 90 | }// end update_author |
| 91 | 91 | |
| 92 | 92 | |
@@ -117,32 +117,32 @@ discard block |
||
| 117 | 117 | } // end lesson |
| 118 | 118 | |
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * user_save_quiz_answers_listener |
|
| 122 | - * |
|
| 123 | - * This function hooks into the quiz page and accepts the answer form save post. |
|
| 124 | - * @since 1.7.3 |
|
| 125 | - * @return bool $saved; |
|
| 126 | - */ |
|
| 127 | - public function user_save_quiz_answers_listener(){ |
|
| 120 | + /** |
|
| 121 | + * user_save_quiz_answers_listener |
|
| 122 | + * |
|
| 123 | + * This function hooks into the quiz page and accepts the answer form save post. |
|
| 124 | + * @since 1.7.3 |
|
| 125 | + * @return bool $saved; |
|
| 126 | + */ |
|
| 127 | + public function user_save_quiz_answers_listener(){ |
|
| 128 | 128 | |
| 129 | - if( ! isset( $_POST[ 'quiz_save' ]) |
|
| 130 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 131 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 132 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
| 133 | - return; |
|
| 134 | - } |
|
| 129 | + if( ! isset( $_POST[ 'quiz_save' ]) |
|
| 130 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
| 131 | + || empty( $_POST[ 'sensei_question' ] ) |
|
| 132 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
| 133 | + return; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - global $post; |
|
| 137 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 138 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 139 | - // call the save function |
|
| 140 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
| 136 | + global $post; |
|
| 137 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 138 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 139 | + // call the save function |
|
| 140 | + self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
| 141 | 141 | |
| 142 | - // remove the hook as it should only fire once per click |
|
| 143 | - remove_action( 'sensei_single_quiz_content_inside_before', 'user_save_quiz_answers_listener' ); |
|
| 142 | + // remove the hook as it should only fire once per click |
|
| 143 | + remove_action( 'sensei_single_quiz_content_inside_before', 'user_save_quiz_answers_listener' ); |
|
| 144 | 144 | |
| 145 | - } // end user_save_quiz_answers_listener |
|
| 145 | + } // end user_save_quiz_answers_listener |
|
| 146 | 146 | |
| 147 | 147 | /** |
| 148 | 148 | * Save the user answers for the given lesson's quiz |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @access public |
| 154 | 154 | * |
| 155 | 155 | * @param array $quiz_answers |
| 156 | - * @param array $files from global $_FILES |
|
| 156 | + * @param array $files from global $_FILES |
|
| 157 | 157 | * @param int $lesson_id |
| 158 | 158 | * @param int $user_id |
| 159 | 159 | * |
@@ -161,11 +161,11 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ |
| 163 | 163 | |
| 164 | - if( ! ( $user_id > 0 ) ){ |
|
| 165 | - $user_id = get_current_user_id(); |
|
| 166 | - } |
|
| 164 | + if( ! ( $user_id > 0 ) ){ |
|
| 165 | + $user_id = get_current_user_id(); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - // make sure the parameters are valid before continuing |
|
| 168 | + // make sure the parameters are valid before continuing |
|
| 169 | 169 | if( empty( $lesson_id ) || empty( $user_id ) |
| 170 | 170 | || 'lesson' != get_post_type( $lesson_id ) |
| 171 | 171 | ||!get_userdata( $user_id ) |
@@ -176,25 +176,25 @@ discard block |
||
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
| 179 | - // start the lesson before saving the data in case the user has not started the lesson |
|
| 180 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 179 | + // start the lesson before saving the data in case the user has not started the lesson |
|
| 180 | + $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 181 | 181 | |
| 182 | 182 | //prepare the answers |
| 183 | 183 | $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); |
| 184 | 184 | |
| 185 | 185 | // save the user data |
| 186 | - $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
| 186 | + $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
| 187 | 187 | |
| 188 | 188 | // were the answers saved correctly? |
| 189 | 189 | if( intval( $answers_saved ) > 0){ |
| 190 | 190 | |
| 191 | - // save transient to make retrieval faster |
|
| 192 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 193 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
| 191 | + // save transient to make retrieval faster |
|
| 192 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 193 | + set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
| 194 | 194 | |
| 195 | - // update the message showed to user |
|
| 196 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 197 | - } |
|
| 195 | + // update the message showed to user |
|
| 196 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | return $answers_saved; |
| 200 | 200 | |
@@ -202,9 +202,9 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | /** |
| 204 | 204 | * Get the user answers for the given lesson's quiz. |
| 205 | - * |
|
| 206 | - * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
| 207 | - * retrieving data for quiz answer before sensei 1.7.4 |
|
| 205 | + * |
|
| 206 | + * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
| 207 | + * retrieving data for quiz answer before sensei 1.7.4 |
|
| 208 | 208 | * |
| 209 | 209 | * |
| 210 | 210 | * @since 1.7.4 |
@@ -224,27 +224,27 @@ discard block |
||
| 224 | 224 | return false; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - // save some time and get the transient cached data |
|
| 228 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 229 | - $transient_cached_answers = get_transient( $transient_key ); |
|
| 227 | + // save some time and get the transient cached data |
|
| 228 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 229 | + $transient_cached_answers = get_transient( $transient_key ); |
|
| 230 | 230 | |
| 231 | - // return the transient or get the values get the values from the comment meta |
|
| 232 | - if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
| 231 | + // return the transient or get the values get the values from the comment meta |
|
| 232 | + if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
| 233 | 233 | |
| 234 | - $encoded_user_answers = $transient_cached_answers; |
|
| 234 | + $encoded_user_answers = $transient_cached_answers; |
|
| 235 | 235 | |
| 236 | - }else{ |
|
| 236 | + }else{ |
|
| 237 | 237 | |
| 238 | - $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
| 238 | + $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
| 239 | 239 | |
| 240 | - } // end if transient check |
|
| 240 | + } // end if transient check |
|
| 241 | 241 | |
| 242 | 242 | if( ! is_array( $encoded_user_answers ) ){ |
| 243 | 243 | return false; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - //set the transient with the new valid data for faster retrieval in future |
|
| 247 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 246 | + //set the transient with the new valid data for faster retrieval in future |
|
| 247 | + set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 248 | 248 | |
| 249 | 249 | // decode an unserialize all answers |
| 250 | 250 | foreach( $encoded_user_answers as $question_id => $encoded_answer ) { |
@@ -278,8 +278,8 @@ discard block |
||
| 278 | 278 | $current_quiz_id = $post->ID; |
| 279 | 279 | $lesson_id = $this->get_lesson_id( $current_quiz_id ); |
| 280 | 280 | |
| 281 | - // reset all user data |
|
| 282 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
| 281 | + // reset all user data |
|
| 282 | + $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
| 283 | 283 | |
| 284 | 284 | //this function should only run once |
| 285 | 285 | remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * Complete/ submit quiz hooked function |
| 291 | 291 | * |
| 292 | 292 | * This function listens to the complete button submit action and processes the users submitted answers |
| 293 | - * not that this function submits the given users quiz answers for grading. |
|
| 293 | + * not that this function submits the given users quiz answers for grading. |
|
| 294 | 294 | * |
| 295 | 295 | * @since 1.7.4 |
| 296 | 296 | * @access public |
@@ -300,90 +300,90 @@ discard block |
||
| 300 | 300 | */ |
| 301 | 301 | public function user_quiz_submit_listener() { |
| 302 | 302 | |
| 303 | - // only respond to valid quiz completion submissions |
|
| 304 | - if( ! isset( $_POST[ 'quiz_complete' ]) |
|
| 305 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 306 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 307 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
| 308 | - return; |
|
| 309 | - } |
|
| 303 | + // only respond to valid quiz completion submissions |
|
| 304 | + if( ! isset( $_POST[ 'quiz_complete' ]) |
|
| 305 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
| 306 | + || empty( $_POST[ 'sensei_question' ] ) |
|
| 307 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
| 308 | + return; |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - global $post, $current_user; |
|
| 312 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 313 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 311 | + global $post, $current_user; |
|
| 312 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 313 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 314 | 314 | |
| 315 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
| 315 | + self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
| 316 | 316 | |
| 317 | 317 | } // End sensei_complete_quiz() |
| 318 | 318 | |
| 319 | - /** |
|
| 320 | - * This function set's up the data need for the quiz page |
|
| 321 | - * |
|
| 322 | - * This function hooks into sensei_complete_quiz and load the global data for the |
|
| 323 | - * current quiz. |
|
| 324 | - * |
|
| 325 | - * @since 1.7.4 |
|
| 326 | - * @access public |
|
| 327 | - * |
|
| 328 | - */ |
|
| 329 | - public function load_global_quiz_data(){ |
|
| 319 | + /** |
|
| 320 | + * This function set's up the data need for the quiz page |
|
| 321 | + * |
|
| 322 | + * This function hooks into sensei_complete_quiz and load the global data for the |
|
| 323 | + * current quiz. |
|
| 324 | + * |
|
| 325 | + * @since 1.7.4 |
|
| 326 | + * @access public |
|
| 327 | + * |
|
| 328 | + */ |
|
| 329 | + public function load_global_quiz_data(){ |
|
| 330 | 330 | |
| 331 | - global $post, $current_user; |
|
| 332 | - $this->data = new stdClass(); |
|
| 331 | + global $post, $current_user; |
|
| 332 | + $this->data = new stdClass(); |
|
| 333 | 333 | |
| 334 | - // Default grade |
|
| 335 | - $grade = 0; |
|
| 334 | + // Default grade |
|
| 335 | + $grade = 0; |
|
| 336 | 336 | |
| 337 | - // Get Quiz Questions |
|
| 338 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
| 337 | + // Get Quiz Questions |
|
| 338 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
| 339 | 339 | |
| 340 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
| 340 | + $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
| 341 | 341 | |
| 342 | - // Get quiz grade type |
|
| 343 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
| 342 | + // Get quiz grade type |
|
| 343 | + $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
| 344 | 344 | |
| 345 | - // Get quiz pass setting |
|
| 346 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
| 345 | + // Get quiz pass setting |
|
| 346 | + $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
| 347 | 347 | |
| 348 | - // Get quiz pass mark |
|
| 349 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
| 348 | + // Get quiz pass mark |
|
| 349 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
| 350 | 350 | |
| 351 | - // Get latest quiz answers and grades |
|
| 352 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 353 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
| 354 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
| 355 | - $user_quiz_grade = 0; |
|
| 356 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 357 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 358 | - } |
|
| 351 | + // Get latest quiz answers and grades |
|
| 352 | + $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 353 | + $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
| 354 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
| 355 | + $user_quiz_grade = 0; |
|
| 356 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 357 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
| 360 | + if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
| 361 | 361 | |
| 362 | - // Check again that the lesson is complete |
|
| 363 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 364 | - $user_lesson_complete = false; |
|
| 365 | - if ( $user_lesson_end ) { |
|
| 366 | - $user_lesson_complete = true; |
|
| 367 | - } // End If Statement |
|
| 362 | + // Check again that the lesson is complete |
|
| 363 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 364 | + $user_lesson_complete = false; |
|
| 365 | + if ( $user_lesson_end ) { |
|
| 366 | + $user_lesson_complete = true; |
|
| 367 | + } // End If Statement |
|
| 368 | 368 | |
| 369 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
| 370 | - //backwards compatibility |
|
| 371 | - if( 'on' == $reset_allowed ) { |
|
| 372 | - $reset_allowed = 1; |
|
| 373 | - } |
|
| 369 | + $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
| 370 | + //backwards compatibility |
|
| 371 | + if( 'on' == $reset_allowed ) { |
|
| 372 | + $reset_allowed = 1; |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - // Build frontend data object for backwards compatibility |
|
| 376 | - // using this is no longer recommended |
|
| 377 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 378 | - $this->data->quiz_passmark = $quiz_passmark; |
|
| 379 | - $this->data->quiz_lesson = $quiz_lesson_id; |
|
| 380 | - $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 381 | - $this->data->user_lesson_end = $user_lesson_end; |
|
| 382 | - $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 383 | - $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
| 384 | - $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 375 | + // Build frontend data object for backwards compatibility |
|
| 376 | + // using this is no longer recommended |
|
| 377 | + $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 378 | + $this->data->quiz_passmark = $quiz_passmark; |
|
| 379 | + $this->data->quiz_lesson = $quiz_lesson_id; |
|
| 380 | + $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 381 | + $this->data->user_lesson_end = $user_lesson_end; |
|
| 382 | + $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 383 | + $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
| 384 | + $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 385 | 385 | |
| 386 | - } // end load_global_quiz_data |
|
| 386 | + } // end load_global_quiz_data |
|
| 387 | 387 | |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -413,25 +413,25 @@ discard block |
||
| 413 | 413 | foreach( $unprepared_answers as $question_id => $answer ) { |
| 414 | 414 | |
| 415 | 415 | //get the current questions question type |
| 416 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 416 | + $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 417 | 417 | |
| 418 | 418 | // Sanitise answer |
| 419 | 419 | if( 0 == get_magic_quotes_gpc() ) { |
| 420 | 420 | $answer = wp_unslash( $answer ); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - // compress the answer for saving |
|
| 423 | + // compress the answer for saving |
|
| 424 | 424 | if( 'multi-line' == $question_type ) { |
| 425 | - $answer = esc_html( $answer ); |
|
| 426 | - }elseif( 'file-upload' == $question_type ){ |
|
| 427 | - $file_key = 'file_upload_' . $question_id; |
|
| 428 | - if( isset( $files[ $file_key ] ) ) { |
|
| 429 | - $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
| 430 | - if( $attachment_id ) { |
|
| 431 | - $answer = $attachment_id; |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - } // end if |
|
| 425 | + $answer = esc_html( $answer ); |
|
| 426 | + }elseif( 'file-upload' == $question_type ){ |
|
| 427 | + $file_key = 'file_upload_' . $question_id; |
|
| 428 | + if( isset( $files[ $file_key ] ) ) { |
|
| 429 | + $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
| 430 | + if( $attachment_id ) { |
|
| 431 | + $answer = $attachment_id; |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + } // end if |
|
| 435 | 435 | |
| 436 | 436 | $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); |
| 437 | 437 | |
@@ -440,813 +440,813 @@ discard block |
||
| 440 | 440 | return $prepared_answers; |
| 441 | 441 | } // prepare_form_submitted_answers |
| 442 | 442 | |
| 443 | - /** |
|
| 444 | - * Reset user submitted questions |
|
| 445 | - * |
|
| 446 | - * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
| 447 | - * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
| 448 | - * |
|
| 449 | - * @since 1.7.4 |
|
| 450 | - * @access public |
|
| 451 | - * |
|
| 452 | - * @return bool $reset_success |
|
| 453 | - * @param int $user_id |
|
| 454 | - * @param int $lesson_id |
|
| 455 | - */ |
|
| 456 | - public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
| 443 | + /** |
|
| 444 | + * Reset user submitted questions |
|
| 445 | + * |
|
| 446 | + * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
| 447 | + * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
| 448 | + * |
|
| 449 | + * @since 1.7.4 |
|
| 450 | + * @access public |
|
| 451 | + * |
|
| 452 | + * @return bool $reset_success |
|
| 453 | + * @param int $user_id |
|
| 454 | + * @param int $lesson_id |
|
| 455 | + */ |
|
| 456 | + public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
| 457 | + |
|
| 458 | + //make sure the parameters are valid |
|
| 459 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 460 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 461 | + || ! get_userdata( $user_id ) ){ |
|
| 462 | + return false; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + //get the users lesson status to make |
|
| 468 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 469 | + if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
| 470 | + // this user is not taking this lesson so this process is not needed |
|
| 471 | + return false; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + //get the lesson quiz and course |
|
| 475 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 476 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 477 | + |
|
| 478 | + // reset the transients |
|
| 479 | + $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 480 | + $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 481 | + $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 482 | + delete_transient( $answers_transient_key ); |
|
| 483 | + delete_transient( $grades_transient_key ); |
|
| 484 | + delete_transient( $answers_feedback_transient_key ); |
|
| 485 | + |
|
| 486 | + // reset the quiz answers and feedback notes |
|
| 487 | + $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
| 488 | + $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 489 | + $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 490 | + |
|
| 491 | + // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
| 492 | + Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
| 493 | + |
|
| 494 | + Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
| 495 | + |
|
| 496 | + // Update course completion |
|
| 497 | + Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
| 457 | 498 | |
| 458 | - //make sure the parameters are valid |
|
| 459 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 460 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 461 | - || ! get_userdata( $user_id ) ){ |
|
| 462 | - return false; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - //get the users lesson status to make |
|
| 468 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 469 | - if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
| 470 | - // this user is not taking this lesson so this process is not needed |
|
| 471 | - return false; |
|
| 472 | - } |
|
| 499 | + // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
| 500 | + do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 501 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 473 | 502 | |
| 474 | - //get the lesson quiz and course |
|
| 475 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 476 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 503 | + return ( $deleted_answers && $deleted_grades ) ; |
|
| 477 | 504 | |
| 478 | - // reset the transients |
|
| 479 | - $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 480 | - $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 481 | - $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 482 | - delete_transient( $answers_transient_key ); |
|
| 483 | - delete_transient( $grades_transient_key ); |
|
| 484 | - delete_transient( $answers_feedback_transient_key ); |
|
| 505 | + } // end reset_user_lesson_data |
|
| 485 | 506 | |
| 486 | - // reset the quiz answers and feedback notes |
|
| 487 | - $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
| 488 | - $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 489 | - $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 507 | + /** |
|
| 508 | + * Submit the users quiz answers for grading |
|
| 509 | + * |
|
| 510 | + * This function accepts users answers and stores it but also initiates the grading |
|
| 511 | + * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
| 512 | + * |
|
| 513 | + * @since 1.7.4 |
|
| 514 | + * @access public |
|
| 515 | + * |
|
| 516 | + * @param array $quiz_answers |
|
| 517 | + * @param array $files from $_FILES |
|
| 518 | + * @param int $user_id |
|
| 519 | + * @param int $lesson_id |
|
| 520 | + * |
|
| 521 | + * @return bool $answers_submitted |
|
| 522 | + */ |
|
| 523 | + public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
| 490 | 524 | |
| 491 | - // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
| 492 | - Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
| 525 | + $answers_submitted = false; |
|
| 493 | 526 | |
| 494 | - Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
| 527 | + // get the user_id if none was passed in use the current logged in user |
|
| 528 | + if( ! intval( $user_id ) > 0 ) { |
|
| 529 | + $user_id = get_current_user_id(); |
|
| 530 | + } |
|
| 495 | 531 | |
| 496 | - // Update course completion |
|
| 497 | - Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
| 532 | + // make sure the parameters are valid before continuing |
|
| 533 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 534 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 535 | + ||!get_userdata( $user_id ) |
|
| 536 | + || !is_array( $quiz_answers ) ){ |
|
| 498 | 537 | |
| 499 | - // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
| 500 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 501 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 538 | + return false; |
|
| 502 | 539 | |
| 503 | - return ( $deleted_answers && $deleted_grades ) ; |
|
| 540 | + } |
|
| 504 | 541 | |
| 505 | - } // end reset_user_lesson_data |
|
| 542 | + // Default grade |
|
| 543 | + $grade = 0; |
|
| 506 | 544 | |
| 507 | - /** |
|
| 508 | - * Submit the users quiz answers for grading |
|
| 509 | - * |
|
| 510 | - * This function accepts users answers and stores it but also initiates the grading |
|
| 511 | - * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
| 512 | - * |
|
| 513 | - * @since 1.7.4 |
|
| 514 | - * @access public |
|
| 515 | - * |
|
| 516 | - * @param array $quiz_answers |
|
| 517 | - * @param array $files from $_FILES |
|
| 518 | - * @param int $user_id |
|
| 519 | - * @param int $lesson_id |
|
| 520 | - * |
|
| 521 | - * @return bool $answers_submitted |
|
| 522 | - */ |
|
| 523 | - public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
| 545 | + // Get Quiz ID |
|
| 546 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 524 | 547 | |
| 525 | - $answers_submitted = false; |
|
| 548 | + // Get quiz grade type |
|
| 549 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 526 | 550 | |
| 527 | - // get the user_id if none was passed in use the current logged in user |
|
| 528 | - if( ! intval( $user_id ) > 0 ) { |
|
| 529 | - $user_id = get_current_user_id(); |
|
| 530 | - } |
|
| 551 | + // Get quiz pass setting |
|
| 552 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 531 | 553 | |
| 532 | - // make sure the parameters are valid before continuing |
|
| 533 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 534 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 535 | - ||!get_userdata( $user_id ) |
|
| 536 | - || !is_array( $quiz_answers ) ){ |
|
| 554 | + // Get the minimum percentage need to pass this quiz |
|
| 555 | + $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 537 | 556 | |
| 538 | - return false; |
|
| 557 | + // Handle Quiz Questions asked |
|
| 558 | + // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
| 559 | + // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
| 560 | + // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
| 561 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 562 | + $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
| 563 | + if( empty( $questions_asked ) ){ |
|
| 539 | 564 | |
| 540 | - } |
|
| 565 | + $questions_asked = array_keys( $quiz_answers ); |
|
| 566 | + $questions_asked_string = implode( ',', $questions_asked ); |
|
| 541 | 567 | |
| 542 | - // Default grade |
|
| 543 | - $grade = 0; |
|
| 568 | + // Save questions that were asked in this quiz |
|
| 569 | + update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
| 544 | 570 | |
| 545 | - // Get Quiz ID |
|
| 546 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 571 | + } |
|
| 547 | 572 | |
| 548 | - // Get quiz grade type |
|
| 549 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 573 | + // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
| 574 | + self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
| 550 | 575 | |
| 551 | - // Get quiz pass setting |
|
| 552 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 576 | + // Grade quiz |
|
| 577 | + $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
| 553 | 578 | |
| 554 | - // Get the minimum percentage need to pass this quiz |
|
| 555 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 579 | + // Get Lesson Grading Setting |
|
| 580 | + $lesson_metadata = array(); |
|
| 581 | + $lesson_status = 'ungraded'; // Default when completing a quiz |
|
| 556 | 582 | |
| 557 | - // Handle Quiz Questions asked |
|
| 558 | - // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
| 559 | - // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
| 560 | - // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
| 561 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 562 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
| 563 | - if( empty( $questions_asked ) ){ |
|
| 583 | + // At this point the answers have been submitted |
|
| 584 | + $answers_submitted = true; |
|
| 564 | 585 | |
| 565 | - $questions_asked = array_keys( $quiz_answers ); |
|
| 566 | - $questions_asked_string = implode( ',', $questions_asked ); |
|
| 567 | - |
|
| 568 | - // Save questions that were asked in this quiz |
|
| 569 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
| 586 | + // if this condition is false the quiz should manually be graded by admin |
|
| 587 | + if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
| 570 | 588 | |
| 571 | - } |
|
| 589 | + // Quiz has been automatically Graded |
|
| 590 | + if ( 'on' == $pass_required ) { |
|
| 572 | 591 | |
| 573 | - // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
| 574 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
| 592 | + // Student has reached the pass mark and lesson is complete |
|
| 593 | + if ( $quiz_pass_percentage <= $grade ) { |
|
| 575 | 594 | |
| 576 | - // Grade quiz |
|
| 577 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
| 595 | + $lesson_status = 'passed'; |
|
| 578 | 596 | |
| 579 | - // Get Lesson Grading Setting |
|
| 580 | - $lesson_metadata = array(); |
|
| 581 | - $lesson_status = 'ungraded'; // Default when completing a quiz |
|
| 597 | + } else { |
|
| 582 | 598 | |
| 583 | - // At this point the answers have been submitted |
|
| 584 | - $answers_submitted = true; |
|
| 599 | + $lesson_status = 'failed'; |
|
| 585 | 600 | |
| 586 | - // if this condition is false the quiz should manually be graded by admin |
|
| 587 | - if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
| 601 | + } // End If Statement |
|
| 588 | 602 | |
| 589 | - // Quiz has been automatically Graded |
|
| 590 | - if ( 'on' == $pass_required ) { |
|
| 603 | + } else { |
|
| 591 | 604 | |
| 592 | - // Student has reached the pass mark and lesson is complete |
|
| 593 | - if ( $quiz_pass_percentage <= $grade ) { |
|
| 605 | + // Student only has to partake the quiz |
|
| 606 | + $lesson_status = 'graded'; |
|
| 607 | + |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
| 611 | + |
|
| 612 | + } // end if ! is_wp_error( $grade ... |
|
| 613 | + |
|
| 614 | + Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
| 594 | 615 | |
| 595 | - $lesson_status = 'passed'; |
|
| 616 | + if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
| 596 | 617 | |
| 597 | - } else { |
|
| 618 | + /** |
|
| 619 | + * Lesson end action hook |
|
| 620 | + * |
|
| 621 | + * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
| 622 | + * |
|
| 623 | + * @param int $user_id |
|
| 624 | + * @param int $lesson_id |
|
| 625 | + */ |
|
| 626 | + do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 598 | 627 | |
| 599 | - $lesson_status = 'failed'; |
|
| 628 | + } |
|
| 600 | 629 | |
| 601 | - } // End If Statement |
|
| 630 | + /** |
|
| 631 | + * User quiz has been submitted |
|
| 632 | + * |
|
| 633 | + * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
| 634 | + * results. |
|
| 635 | + * |
|
| 636 | + * @param int $user_id |
|
| 637 | + * @param int $quiz_id |
|
| 638 | + * @param string $grade |
|
| 639 | + * @param string $quiz_pass_percentage |
|
| 640 | + * @param string $quiz_grade_type |
|
| 641 | + */ |
|
| 642 | + do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
| 602 | 643 | |
| 603 | - } else { |
|
| 644 | + return $answers_submitted; |
|
| 604 | 645 | |
| 605 | - // Student only has to partake the quiz |
|
| 606 | - $lesson_status = 'graded'; |
|
| 607 | - |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
| 611 | - |
|
| 612 | - } // end if ! is_wp_error( $grade ... |
|
| 613 | - |
|
| 614 | - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
| 646 | + }// end submit_answers_for_grading |
|
| 615 | 647 | |
| 616 | - if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
| 648 | + /** |
|
| 649 | + * Get the user question answer |
|
| 650 | + * |
|
| 651 | + * This function gets the the users saved answer on given quiz for the given question parameter |
|
| 652 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 653 | + * |
|
| 654 | + * @since 1.7.4 |
|
| 655 | + * |
|
| 656 | + * @param int $lesson_id |
|
| 657 | + * @param int $question_id |
|
| 658 | + * @param int $user_id ( optional ) |
|
| 659 | + * |
|
| 660 | + * @return bool $answers_submitted |
|
| 661 | + */ |
|
| 662 | + public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 617 | 663 | |
| 618 | - /** |
|
| 619 | - * Lesson end action hook |
|
| 620 | - * |
|
| 621 | - * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
| 622 | - * |
|
| 623 | - * @param int $user_id |
|
| 624 | - * @param int $lesson_id |
|
| 625 | - */ |
|
| 626 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 664 | + // parameter validation |
|
| 665 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 666 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 667 | + || ! ( intval( $question_id ) > 0 ) |
|
| 668 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 669 | + || 'question' != get_post_type( $question_id )) { |
|
| 627 | 670 | |
| 628 | - } |
|
| 671 | + return false; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + if( ! ( intval( $user_id ) > 0 ) ){ |
|
| 675 | + $user_id = get_current_user_id(); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
| 679 | + |
|
| 680 | + if( !$users_answers || empty( $users_answers ) |
|
| 681 | + || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
| 682 | + |
|
| 683 | + //Fallback for pre 1.7.4 data |
|
| 684 | + $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
| 685 | + |
|
| 686 | + if( ! isset( $comment->comment_content ) ){ |
|
| 687 | + return false; |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + return $users_answers[ $question_id ]; |
|
| 694 | + |
|
| 695 | + }// end get_user_question_answer |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * Saving the users quiz question grades |
|
| 699 | + * |
|
| 700 | + * This function save all the grades for all the question in a given quiz on the lesson |
|
| 701 | + * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
| 702 | + * |
|
| 703 | + * @since 1.7.4 |
|
| 704 | + * |
|
| 705 | + * @param array $quiz_grades{ |
|
| 706 | + * @type int $question_id |
|
| 707 | + * @type int $question_grade |
|
| 708 | + * } |
|
| 709 | + * @param $lesson_id |
|
| 710 | + * @param $user_id (Optional) will use the current user if not supplied |
|
| 711 | + * |
|
| 712 | + * @return bool |
|
| 713 | + */ |
|
| 714 | + public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
| 715 | + |
|
| 716 | + // get the user_id if none was passed in use the current logged in user |
|
| 717 | + if( ! intval( $user_id ) > 0 ) { |
|
| 718 | + $user_id = get_current_user_id(); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + // make sure the parameters are valid before continuing |
|
| 722 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 723 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 724 | + ||!get_userdata( $user_id ) |
|
| 725 | + || !is_array( $quiz_grades ) ){ |
|
| 726 | + |
|
| 727 | + return false; |
|
| 728 | + |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + $success = false; |
|
| 732 | + |
|
| 733 | + // save that data for the user on the lesson comment meta |
|
| 734 | + $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
| 735 | + |
|
| 736 | + // were the grades save successfully ? |
|
| 737 | + if( intval( $comment_meta_id ) > 0 ) { |
|
| 738 | + |
|
| 739 | + $success = true; |
|
| 740 | + // save transient |
|
| 741 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 742 | + set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + return $success; |
|
| 746 | + |
|
| 747 | + }// end set_user_grades |
|
| 748 | + |
|
| 749 | + /** |
|
| 750 | + * Retrieve the users quiz question grades |
|
| 751 | + * |
|
| 752 | + * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
| 753 | + * |
|
| 754 | + * @since 1.7.4 |
|
| 755 | + * |
|
| 756 | + * @param $lesson_id |
|
| 757 | + * @param $user_id (Optional) will use the current user if not supplied |
|
| 758 | + * |
|
| 759 | + * @return array $user_quiz_grades or false if none exists for this users |
|
| 760 | + */ |
|
| 761 | + public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
| 762 | + |
|
| 763 | + $user_grades = array(); |
|
| 764 | + |
|
| 765 | + // get the user_id if none was passed in use the current logged in user |
|
| 766 | + if( ! intval( $user_id ) > 0 ) { |
|
| 767 | + $user_id = get_current_user_id(); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 771 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 772 | + return false; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + // save some time and get the transient cached data |
|
| 776 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 777 | + $user_grades = get_transient( $transient_key ); |
|
| 778 | + |
|
| 779 | + // get the data if nothing was stored in the transient |
|
| 780 | + if( empty( $user_grades ) || false != $user_grades ){ |
|
| 781 | + |
|
| 782 | + $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 783 | + |
|
| 784 | + //set the transient with the new valid data for faster retrieval in future |
|
| 785 | + set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
| 786 | + |
|
| 787 | + } // end if transient check |
|
| 788 | + |
|
| 789 | + // if there is no data for this user |
|
| 790 | + if( ! is_array( $user_grades ) ){ |
|
| 791 | + return false; |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + return $user_grades; |
|
| 795 | + |
|
| 796 | + }// end get_user_grades |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * Get the user question grade |
|
| 800 | + * |
|
| 801 | + * This function gets the grade on a quiz for the given question parameter |
|
| 802 | + * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
| 803 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 804 | + * |
|
| 805 | + * @since 1.7.4 |
|
| 806 | + * |
|
| 807 | + * @param int $lesson_id |
|
| 808 | + * @param int $question_id |
|
| 809 | + * @param int $user_id ( optional ) |
|
| 810 | + * |
|
| 811 | + * @return bool $question_grade |
|
| 812 | + */ |
|
| 813 | + public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 814 | + |
|
| 815 | + // parameter validation |
|
| 816 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 817 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 818 | + || ! ( intval( $question_id ) > 0 ) |
|
| 819 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 820 | + || 'question' != get_post_type( $question_id )) { |
|
| 821 | + |
|
| 822 | + return false; |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
| 826 | + |
|
| 827 | + if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
| 828 | + |
|
| 829 | + //fallback to data pre 1.7.4 |
|
| 830 | + $args = array( |
|
| 831 | + 'post_id' => $question_id, |
|
| 832 | + 'user_id' => $user_id, |
|
| 833 | + 'type' => 'sensei_user_answer' |
|
| 834 | + ); |
|
| 835 | + |
|
| 836 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 837 | + $fall_back_grade = false; |
|
| 838 | + if( isset( $question_activity->comment_ID ) ){ |
|
| 839 | + $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + return $fall_back_grade; |
|
| 843 | + |
|
| 844 | + } // end if $all_user_grades... |
|
| 845 | + |
|
| 846 | + return $all_user_grades[ $question_id ]; |
|
| 847 | + |
|
| 848 | + }// end get_user_question_grade |
|
| 849 | + |
|
| 850 | + /** |
|
| 851 | + * Save the user's answers feedback |
|
| 852 | + * |
|
| 853 | + * For this function you must supply all three parameters. If will return false one is left out. |
|
| 854 | + * The data will be saved on the lesson ID supplied. |
|
| 855 | + * |
|
| 856 | + * @since 1.7.5 |
|
| 857 | + * @access public |
|
| 858 | + * |
|
| 859 | + * @param array $answers_feedback{ |
|
| 860 | + * $type int $question_id |
|
| 861 | + * $type string $question_feedback |
|
| 862 | + * } |
|
| 863 | + * @param int $lesson_id |
|
| 864 | + * @param int $user_id |
|
| 865 | + * |
|
| 866 | + * @return false or int $feedback_saved |
|
| 867 | + */ |
|
| 868 | + public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
| 869 | + |
|
| 870 | + // make sure the parameters are valid before continuing |
|
| 871 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 872 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 873 | + ||!get_userdata( $user_id ) |
|
| 874 | + || !is_array( $answers_feedback ) ){ |
|
| 875 | + |
|
| 876 | + return false; |
|
| 877 | + |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + |
|
| 881 | + // check if the lesson is started before saving, if not start the lesson for the user |
|
| 882 | + if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
| 883 | + Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 884 | + } |
|
| 629 | 885 | |
| 630 | - /** |
|
| 631 | - * User quiz has been submitted |
|
| 632 | - * |
|
| 633 | - * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
| 634 | - * results. |
|
| 635 | - * |
|
| 636 | - * @param int $user_id |
|
| 637 | - * @param int $quiz_id |
|
| 638 | - * @param string $grade |
|
| 639 | - * @param string $quiz_pass_percentage |
|
| 640 | - * @param string $quiz_grade_type |
|
| 641 | - */ |
|
| 642 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
| 886 | + // encode the feedback |
|
| 887 | + $encoded_answers_feedback = array(); |
|
| 888 | + foreach( $answers_feedback as $question_id => $feedback ){ |
|
| 889 | + $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + // save the user data |
|
| 893 | + $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
| 894 | + |
|
| 895 | + //Were the the question feedback save correctly? |
|
| 896 | + if( intval( $feedback_saved ) > 0){ |
|
| 897 | + |
|
| 898 | + // save transient to make retrieval faster in future |
|
| 899 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 900 | + set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
| 643 | 901 | |
| 644 | - return $answers_submitted; |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + return $feedback_saved; |
|
| 905 | + |
|
| 906 | + } // end save_user_answers_feedback |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * Get the user's answers feedback. |
|
| 910 | + * |
|
| 911 | + * This function returns the feedback submitted by the teacher/admin |
|
| 912 | + * during grading. Grading occurs manually or automatically. |
|
| 913 | + * |
|
| 914 | + * @since 1.7.5 |
|
| 915 | + * @access public |
|
| 916 | + * |
|
| 917 | + * @param int $lesson_id |
|
| 918 | + * @param int $user_id |
|
| 919 | + * |
|
| 920 | + * @return false | array $answers_feedback{ |
|
| 921 | + * $type int $question_id |
|
| 922 | + * $type string $question_feedback |
|
| 923 | + * } |
|
| 924 | + */ |
|
| 925 | + public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
| 926 | + |
|
| 927 | + $answers_feedback = array(); |
|
| 645 | 928 | |
| 646 | - }// end submit_answers_for_grading |
|
| 929 | + // get the user_id if none was passed in use the current logged in user |
|
| 930 | + if( ! intval( $user_id ) > 0 ) { |
|
| 931 | + $user_id = get_current_user_id(); |
|
| 932 | + } |
|
| 647 | 933 | |
| 648 | - /** |
|
| 649 | - * Get the user question answer |
|
| 650 | - * |
|
| 651 | - * This function gets the the users saved answer on given quiz for the given question parameter |
|
| 652 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 653 | - * |
|
| 654 | - * @since 1.7.4 |
|
| 655 | - * |
|
| 656 | - * @param int $lesson_id |
|
| 657 | - * @param int $question_id |
|
| 658 | - * @param int $user_id ( optional ) |
|
| 659 | - * |
|
| 660 | - * @return bool $answers_submitted |
|
| 661 | - */ |
|
| 662 | - public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 934 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 935 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 936 | + return false; |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + // first check the transient to save a few split seconds |
|
| 940 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 941 | + $encoded_feedback = get_transient( $transient_key ); |
|
| 942 | + |
|
| 943 | + // get the data if nothing was stored in the transient |
|
| 944 | + if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
| 945 | + |
|
| 946 | + $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 947 | + |
|
| 948 | + //set the transient with the new valid data for faster retrieval in future |
|
| 949 | + set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 950 | + |
|
| 951 | + } // end if transient check |
|
| 663 | 952 | |
| 664 | - // parameter validation |
|
| 665 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 666 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 667 | - || ! ( intval( $question_id ) > 0 ) |
|
| 668 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 669 | - || 'question' != get_post_type( $question_id )) { |
|
| 953 | + // if there is no data for this user |
|
| 954 | + if( ! is_array( $encoded_feedback ) ){ |
|
| 955 | + return false; |
|
| 956 | + } |
|
| 670 | 957 | |
| 671 | - return false; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - if( ! ( intval( $user_id ) > 0 ) ){ |
|
| 675 | - $user_id = get_current_user_id(); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
| 679 | - |
|
| 680 | - if( !$users_answers || empty( $users_answers ) |
|
| 681 | - || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
| 682 | - |
|
| 683 | - //Fallback for pre 1.7.4 data |
|
| 684 | - $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
| 685 | - |
|
| 686 | - if( ! isset( $comment->comment_content ) ){ |
|
| 687 | - return false; |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - return $users_answers[ $question_id ]; |
|
| 694 | - |
|
| 695 | - }// end get_user_question_answer |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * Saving the users quiz question grades |
|
| 699 | - * |
|
| 700 | - * This function save all the grades for all the question in a given quiz on the lesson |
|
| 701 | - * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
| 702 | - * |
|
| 703 | - * @since 1.7.4 |
|
| 704 | - * |
|
| 705 | - * @param array $quiz_grades{ |
|
| 706 | - * @type int $question_id |
|
| 707 | - * @type int $question_grade |
|
| 708 | - * } |
|
| 709 | - * @param $lesson_id |
|
| 710 | - * @param $user_id (Optional) will use the current user if not supplied |
|
| 711 | - * |
|
| 712 | - * @return bool |
|
| 713 | - */ |
|
| 714 | - public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
| 715 | - |
|
| 716 | - // get the user_id if none was passed in use the current logged in user |
|
| 717 | - if( ! intval( $user_id ) > 0 ) { |
|
| 718 | - $user_id = get_current_user_id(); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - // make sure the parameters are valid before continuing |
|
| 722 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 723 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 724 | - ||!get_userdata( $user_id ) |
|
| 725 | - || !is_array( $quiz_grades ) ){ |
|
| 726 | - |
|
| 727 | - return false; |
|
| 728 | - |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - $success = false; |
|
| 732 | - |
|
| 733 | - // save that data for the user on the lesson comment meta |
|
| 734 | - $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
| 735 | - |
|
| 736 | - // were the grades save successfully ? |
|
| 737 | - if( intval( $comment_meta_id ) > 0 ) { |
|
| 738 | - |
|
| 739 | - $success = true; |
|
| 740 | - // save transient |
|
| 741 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 742 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - return $success; |
|
| 746 | - |
|
| 747 | - }// end set_user_grades |
|
| 748 | - |
|
| 749 | - /** |
|
| 750 | - * Retrieve the users quiz question grades |
|
| 751 | - * |
|
| 752 | - * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
| 753 | - * |
|
| 754 | - * @since 1.7.4 |
|
| 755 | - * |
|
| 756 | - * @param $lesson_id |
|
| 757 | - * @param $user_id (Optional) will use the current user if not supplied |
|
| 758 | - * |
|
| 759 | - * @return array $user_quiz_grades or false if none exists for this users |
|
| 760 | - */ |
|
| 761 | - public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
| 762 | - |
|
| 763 | - $user_grades = array(); |
|
| 764 | - |
|
| 765 | - // get the user_id if none was passed in use the current logged in user |
|
| 766 | - if( ! intval( $user_id ) > 0 ) { |
|
| 767 | - $user_id = get_current_user_id(); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 771 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 772 | - return false; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - // save some time and get the transient cached data |
|
| 776 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 777 | - $user_grades = get_transient( $transient_key ); |
|
| 778 | - |
|
| 779 | - // get the data if nothing was stored in the transient |
|
| 780 | - if( empty( $user_grades ) || false != $user_grades ){ |
|
| 781 | - |
|
| 782 | - $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 783 | - |
|
| 784 | - //set the transient with the new valid data for faster retrieval in future |
|
| 785 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
| 786 | - |
|
| 787 | - } // end if transient check |
|
| 788 | - |
|
| 789 | - // if there is no data for this user |
|
| 790 | - if( ! is_array( $user_grades ) ){ |
|
| 791 | - return false; |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - return $user_grades; |
|
| 795 | - |
|
| 796 | - }// end get_user_grades |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * Get the user question grade |
|
| 800 | - * |
|
| 801 | - * This function gets the grade on a quiz for the given question parameter |
|
| 802 | - * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
| 803 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 804 | - * |
|
| 805 | - * @since 1.7.4 |
|
| 806 | - * |
|
| 807 | - * @param int $lesson_id |
|
| 808 | - * @param int $question_id |
|
| 809 | - * @param int $user_id ( optional ) |
|
| 810 | - * |
|
| 811 | - * @return bool $question_grade |
|
| 812 | - */ |
|
| 813 | - public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 814 | - |
|
| 815 | - // parameter validation |
|
| 816 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 817 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 818 | - || ! ( intval( $question_id ) > 0 ) |
|
| 819 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 820 | - || 'question' != get_post_type( $question_id )) { |
|
| 821 | - |
|
| 822 | - return false; |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
| 826 | - |
|
| 827 | - if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
| 828 | - |
|
| 829 | - //fallback to data pre 1.7.4 |
|
| 830 | - $args = array( |
|
| 831 | - 'post_id' => $question_id, |
|
| 832 | - 'user_id' => $user_id, |
|
| 833 | - 'type' => 'sensei_user_answer' |
|
| 834 | - ); |
|
| 835 | - |
|
| 836 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 837 | - $fall_back_grade = false; |
|
| 838 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 839 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - return $fall_back_grade; |
|
| 843 | - |
|
| 844 | - } // end if $all_user_grades... |
|
| 845 | - |
|
| 846 | - return $all_user_grades[ $question_id ]; |
|
| 847 | - |
|
| 848 | - }// end get_user_question_grade |
|
| 849 | - |
|
| 850 | - /** |
|
| 851 | - * Save the user's answers feedback |
|
| 852 | - * |
|
| 853 | - * For this function you must supply all three parameters. If will return false one is left out. |
|
| 854 | - * The data will be saved on the lesson ID supplied. |
|
| 855 | - * |
|
| 856 | - * @since 1.7.5 |
|
| 857 | - * @access public |
|
| 858 | - * |
|
| 859 | - * @param array $answers_feedback{ |
|
| 860 | - * $type int $question_id |
|
| 861 | - * $type string $question_feedback |
|
| 862 | - * } |
|
| 863 | - * @param int $lesson_id |
|
| 864 | - * @param int $user_id |
|
| 865 | - * |
|
| 866 | - * @return false or int $feedback_saved |
|
| 867 | - */ |
|
| 868 | - public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
| 869 | - |
|
| 870 | - // make sure the parameters are valid before continuing |
|
| 871 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 872 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 873 | - ||!get_userdata( $user_id ) |
|
| 874 | - || !is_array( $answers_feedback ) ){ |
|
| 875 | - |
|
| 876 | - return false; |
|
| 877 | - |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - |
|
| 881 | - // check if the lesson is started before saving, if not start the lesson for the user |
|
| 882 | - if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
| 883 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - // encode the feedback |
|
| 887 | - $encoded_answers_feedback = array(); |
|
| 888 | - foreach( $answers_feedback as $question_id => $feedback ){ |
|
| 889 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - // save the user data |
|
| 893 | - $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
| 894 | - |
|
| 895 | - //Were the the question feedback save correctly? |
|
| 896 | - if( intval( $feedback_saved ) > 0){ |
|
| 897 | - |
|
| 898 | - // save transient to make retrieval faster in future |
|
| 899 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 900 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
| 901 | - |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - return $feedback_saved; |
|
| 905 | - |
|
| 906 | - } // end save_user_answers_feedback |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * Get the user's answers feedback. |
|
| 910 | - * |
|
| 911 | - * This function returns the feedback submitted by the teacher/admin |
|
| 912 | - * during grading. Grading occurs manually or automatically. |
|
| 913 | - * |
|
| 914 | - * @since 1.7.5 |
|
| 915 | - * @access public |
|
| 916 | - * |
|
| 917 | - * @param int $lesson_id |
|
| 918 | - * @param int $user_id |
|
| 919 | - * |
|
| 920 | - * @return false | array $answers_feedback{ |
|
| 921 | - * $type int $question_id |
|
| 922 | - * $type string $question_feedback |
|
| 923 | - * } |
|
| 924 | - */ |
|
| 925 | - public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
| 926 | - |
|
| 927 | - $answers_feedback = array(); |
|
| 928 | - |
|
| 929 | - // get the user_id if none was passed in use the current logged in user |
|
| 930 | - if( ! intval( $user_id ) > 0 ) { |
|
| 931 | - $user_id = get_current_user_id(); |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 935 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 936 | - return false; |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - // first check the transient to save a few split seconds |
|
| 940 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 941 | - $encoded_feedback = get_transient( $transient_key ); |
|
| 942 | - |
|
| 943 | - // get the data if nothing was stored in the transient |
|
| 944 | - if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
| 945 | - |
|
| 946 | - $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 947 | - |
|
| 948 | - //set the transient with the new valid data for faster retrieval in future |
|
| 949 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 950 | - |
|
| 951 | - } // end if transient check |
|
| 952 | - |
|
| 953 | - // if there is no data for this user |
|
| 954 | - if( ! is_array( $encoded_feedback ) ){ |
|
| 955 | - return false; |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - foreach( $encoded_feedback as $question_id => $feedback ){ |
|
| 958 | + foreach( $encoded_feedback as $question_id => $feedback ){ |
|
| 959 | 959 | |
| 960 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
| 960 | + $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
| 961 | 961 | |
| 962 | - } |
|
| 962 | + } |
|
| 963 | 963 | |
| 964 | - return $answers_feedback; |
|
| 964 | + return $answers_feedback; |
|
| 965 | 965 | |
| 966 | - } // end get_user_answers_feedback |
|
| 966 | + } // end get_user_answers_feedback |
|
| 967 | 967 | |
| 968 | - /** |
|
| 969 | - * Get the user's answer feedback for a specific question. |
|
| 970 | - * |
|
| 971 | - * This function gives you a single answer note/feedback string |
|
| 972 | - * for the user on the given question. |
|
| 973 | - * |
|
| 974 | - * @since 1.7.5 |
|
| 975 | - * @access public |
|
| 976 | - * |
|
| 977 | - * @param int $lesson_id |
|
| 978 | - * @param int $question_id |
|
| 979 | - * @param int $user_id |
|
| 980 | - * |
|
| 981 | - * @return string $feedback or bool if false |
|
| 982 | - */ |
|
| 983 | - public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 968 | + /** |
|
| 969 | + * Get the user's answer feedback for a specific question. |
|
| 970 | + * |
|
| 971 | + * This function gives you a single answer note/feedback string |
|
| 972 | + * for the user on the given question. |
|
| 973 | + * |
|
| 974 | + * @since 1.7.5 |
|
| 975 | + * @access public |
|
| 976 | + * |
|
| 977 | + * @param int $lesson_id |
|
| 978 | + * @param int $question_id |
|
| 979 | + * @param int $user_id |
|
| 980 | + * |
|
| 981 | + * @return string $feedback or bool if false |
|
| 982 | + */ |
|
| 983 | + public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 984 | 984 | |
| 985 | - $feedback = false; |
|
| 985 | + $feedback = false; |
|
| 986 | 986 | |
| 987 | - // parameter validation |
|
| 988 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 989 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 990 | - || ! ( intval( $question_id ) > 0 ) |
|
| 991 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 992 | - || 'question' != get_post_type( $question_id )) { |
|
| 987 | + // parameter validation |
|
| 988 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 989 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 990 | + || ! ( intval( $question_id ) > 0 ) |
|
| 991 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 992 | + || 'question' != get_post_type( $question_id )) { |
|
| 993 | 993 | |
| 994 | - return false; |
|
| 995 | - } |
|
| 994 | + return false; |
|
| 995 | + } |
|
| 996 | 996 | |
| 997 | - // get all the feedback for the user on the given lesson |
|
| 998 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
| 997 | + // get all the feedback for the user on the given lesson |
|
| 998 | + $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
| 999 | 999 | |
| 1000 | - if( !$all_feedback || empty( $all_feedback ) |
|
| 1001 | - || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
| 1000 | + if( !$all_feedback || empty( $all_feedback ) |
|
| 1001 | + || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
| 1002 | 1002 | |
| 1003 | - //fallback to data pre 1.7.4 |
|
| 1003 | + //fallback to data pre 1.7.4 |
|
| 1004 | 1004 | |
| 1005 | - // setup the sensei data query |
|
| 1006 | - $args = array( |
|
| 1007 | - 'post_id' => $question_id, |
|
| 1008 | - 'user_id' => $user_id, |
|
| 1009 | - 'type' => 'sensei_user_answer' |
|
| 1010 | - ); |
|
| 1011 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 1005 | + // setup the sensei data query |
|
| 1006 | + $args = array( |
|
| 1007 | + 'post_id' => $question_id, |
|
| 1008 | + 'user_id' => $user_id, |
|
| 1009 | + 'type' => 'sensei_user_answer' |
|
| 1010 | + ); |
|
| 1011 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 1012 | 1012 | |
| 1013 | - // set the default to false and return that if no old data is available. |
|
| 1014 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 1015 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
| 1016 | - } |
|
| 1013 | + // set the default to false and return that if no old data is available. |
|
| 1014 | + if( isset( $question_activity->comment_ID ) ){ |
|
| 1015 | + $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
| 1016 | + } |
|
| 1017 | 1017 | |
| 1018 | - // finally use the default question feedback |
|
| 1019 | - if( empty( $feedback ) ){ |
|
| 1020 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 1021 | - } |
|
| 1018 | + // finally use the default question feedback |
|
| 1019 | + if( empty( $feedback ) ){ |
|
| 1020 | + $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 1021 | + } |
|
| 1022 | 1022 | |
| 1023 | - return $feedback; |
|
| 1023 | + return $feedback; |
|
| 1024 | 1024 | |
| 1025 | - } |
|
| 1025 | + } |
|
| 1026 | 1026 | |
| 1027 | - return $all_feedback[ $question_id ]; |
|
| 1027 | + return $all_feedback[ $question_id ]; |
|
| 1028 | 1028 | |
| 1029 | - } // end get_user_question_feedback |
|
| 1029 | + } // end get_user_question_feedback |
|
| 1030 | 1030 | |
| 1031 | - /** |
|
| 1032 | - * Check if a quiz has no questions, and redirect back to lesson. |
|
| 1033 | - * |
|
| 1034 | - * Though a quiz is created for each lesson, it should not be visible |
|
| 1035 | - * unless it has questions. |
|
| 1036 | - * |
|
| 1037 | - * @since 1.9.0 |
|
| 1038 | - * @access public |
|
| 1039 | - * @param none |
|
| 1040 | - * @return void |
|
| 1041 | - */ |
|
| 1031 | + /** |
|
| 1032 | + * Check if a quiz has no questions, and redirect back to lesson. |
|
| 1033 | + * |
|
| 1034 | + * Though a quiz is created for each lesson, it should not be visible |
|
| 1035 | + * unless it has questions. |
|
| 1036 | + * |
|
| 1037 | + * @since 1.9.0 |
|
| 1038 | + * @access public |
|
| 1039 | + * @param none |
|
| 1040 | + * @return void |
|
| 1041 | + */ |
|
| 1042 | 1042 | |
| 1043 | - public function quiz_has_no_questions() { |
|
| 1043 | + public function quiz_has_no_questions() { |
|
| 1044 | 1044 | |
| 1045 | - if( ! is_singular( 'quiz' ) ) { |
|
| 1046 | - return; |
|
| 1047 | - } |
|
| 1045 | + if( ! is_singular( 'quiz' ) ) { |
|
| 1046 | + return; |
|
| 1047 | + } |
|
| 1048 | 1048 | |
| 1049 | - global $post; |
|
| 1049 | + global $post; |
|
| 1050 | 1050 | |
| 1051 | - $lesson_id = $this->get_lesson_id($post->ID); |
|
| 1051 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
| 1052 | 1052 | |
| 1053 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1053 | + $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1054 | 1054 | |
| 1055 | - $lesson = get_post($lesson_id); |
|
| 1055 | + $lesson = get_post($lesson_id); |
|
| 1056 | 1056 | |
| 1057 | - if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
| 1057 | + if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
| 1058 | 1058 | |
| 1059 | - wp_redirect(get_permalink($lesson->ID), 301); |
|
| 1060 | - exit; |
|
| 1059 | + wp_redirect(get_permalink($lesson->ID), 301); |
|
| 1060 | + exit; |
|
| 1061 | 1061 | |
| 1062 | - } |
|
| 1062 | + } |
|
| 1063 | 1063 | |
| 1064 | - } // end quiz_has_no_questions |
|
| 1064 | + } // end quiz_has_no_questions |
|
| 1065 | 1065 | |
| 1066 | 1066 | /** |
| 1067 | - * Deprecate the sensei_single_main_content on the single-quiz template. |
|
| 1068 | - * |
|
| 1069 | - * @deprecated since 1.9.0 |
|
| 1070 | - */ |
|
| 1067 | + * Deprecate the sensei_single_main_content on the single-quiz template. |
|
| 1068 | + * |
|
| 1069 | + * @deprecated since 1.9.0 |
|
| 1070 | + */ |
|
| 1071 | 1071 | public static function deprecate_quiz_sensei_single_main_content_hook(){ |
| 1072 | 1072 | |
| 1073 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
| 1073 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
| 1074 | 1074 | |
| 1075 | 1075 | } |
| 1076 | - /* |
|
| 1076 | + /* |
|
| 1077 | 1077 | * Deprecate the sensei_quiz_single_title on the single-quiz template. |
| 1078 | 1078 | * |
| 1079 | 1079 | * @deprecated since 1.9.0 |
| 1080 | 1080 | */ |
| 1081 | - public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
| 1081 | + public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
| 1082 | 1082 | |
| 1083 | - sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
| 1083 | + sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
| 1084 | 1084 | |
| 1085 | - } |
|
| 1085 | + } |
|
| 1086 | 1086 | |
| 1087 | - /** |
|
| 1088 | - * Filter the single title and add the Quiz to it. |
|
| 1089 | - * |
|
| 1090 | - * @param string $title |
|
| 1091 | - * @param int $id title post id |
|
| 1092 | - * @return string $quiz_title |
|
| 1093 | - */ |
|
| 1094 | - public static function single_quiz_title( $title, $post_id ){ |
|
| 1087 | + /** |
|
| 1088 | + * Filter the single title and add the Quiz to it. |
|
| 1089 | + * |
|
| 1090 | + * @param string $title |
|
| 1091 | + * @param int $id title post id |
|
| 1092 | + * @return string $quiz_title |
|
| 1093 | + */ |
|
| 1094 | + public static function single_quiz_title( $title, $post_id ){ |
|
| 1095 | 1095 | |
| 1096 | - if( 'quiz' == get_post_type( $post_id ) ){ |
|
| 1096 | + if( 'quiz' == get_post_type( $post_id ) ){ |
|
| 1097 | 1097 | |
| 1098 | - $title_with_no_quizzes = $title; |
|
| 1098 | + $title_with_no_quizzes = $title; |
|
| 1099 | 1099 | |
| 1100 | - // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
| 1101 | - if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
| 1100 | + // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
| 1101 | + if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
| 1102 | 1102 | |
| 1103 | - // remove all possible appearances of quiz |
|
| 1104 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
| 1105 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
| 1106 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
| 1103 | + // remove all possible appearances of quiz |
|
| 1104 | + $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
| 1105 | + $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
| 1106 | + $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
| 1107 | 1107 | |
| 1108 | - } |
|
| 1108 | + } |
|
| 1109 | 1109 | |
| 1110 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
| 1111 | - } |
|
| 1110 | + $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
| 1111 | + } |
|
| 1112 | 1112 | |
| 1113 | - /** |
|
| 1114 | - * hook document in class-woothemes-sensei-message.php |
|
| 1115 | - */ |
|
| 1116 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
| 1113 | + /** |
|
| 1114 | + * hook document in class-woothemes-sensei-message.php |
|
| 1115 | + */ |
|
| 1116 | + return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
| 1117 | 1117 | |
| 1118 | - } |
|
| 1118 | + } |
|
| 1119 | 1119 | |
| 1120 | - /** |
|
| 1121 | - * Initialize the quiz question loop on the single quiz template |
|
| 1122 | - * |
|
| 1123 | - * The function will create a global quiz loop varialbe. |
|
| 1124 | - * |
|
| 1125 | - * @since 1.9.0 |
|
| 1126 | - * |
|
| 1127 | - */ |
|
| 1128 | - public static function start_quiz_questions_loop(){ |
|
| 1120 | + /** |
|
| 1121 | + * Initialize the quiz question loop on the single quiz template |
|
| 1122 | + * |
|
| 1123 | + * The function will create a global quiz loop varialbe. |
|
| 1124 | + * |
|
| 1125 | + * @since 1.9.0 |
|
| 1126 | + * |
|
| 1127 | + */ |
|
| 1128 | + public static function start_quiz_questions_loop(){ |
|
| 1129 | 1129 | |
| 1130 | - global $sensei_question_loop; |
|
| 1130 | + global $sensei_question_loop; |
|
| 1131 | 1131 | |
| 1132 | - //intialize the questions loop object |
|
| 1133 | - $sensei_question_loop['current'] = -1; |
|
| 1134 | - $sensei_question_loop['total'] = 0; |
|
| 1135 | - $sensei_question_loop['questions'] = array(); |
|
| 1132 | + //intialize the questions loop object |
|
| 1133 | + $sensei_question_loop['current'] = -1; |
|
| 1134 | + $sensei_question_loop['total'] = 0; |
|
| 1135 | + $sensei_question_loop['questions'] = array(); |
|
| 1136 | 1136 | |
| 1137 | 1137 | |
| 1138 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
| 1138 | + $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
| 1139 | 1139 | |
| 1140 | - if( count( $questions ) > 0 ){ |
|
| 1140 | + if( count( $questions ) > 0 ){ |
|
| 1141 | 1141 | |
| 1142 | - $sensei_question_loop['total'] = count( $questions ); |
|
| 1143 | - $sensei_question_loop['questions'] = $questions; |
|
| 1144 | - $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
| 1142 | + $sensei_question_loop['total'] = count( $questions ); |
|
| 1143 | + $sensei_question_loop['questions'] = $questions; |
|
| 1144 | + $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
| 1145 | 1145 | |
| 1146 | - } |
|
| 1146 | + } |
|
| 1147 | 1147 | |
| 1148 | - }// static function |
|
| 1148 | + }// static function |
|
| 1149 | 1149 | |
| 1150 | - /** |
|
| 1151 | - * Initialize the quiz question loop on the single quiz template |
|
| 1152 | - * |
|
| 1153 | - * The function will create a global quiz loop varialbe. |
|
| 1154 | - * |
|
| 1155 | - * @since 1.9.0 |
|
| 1156 | - * |
|
| 1157 | - */ |
|
| 1158 | - public static function stop_quiz_questions_loop(){ |
|
| 1150 | + /** |
|
| 1151 | + * Initialize the quiz question loop on the single quiz template |
|
| 1152 | + * |
|
| 1153 | + * The function will create a global quiz loop varialbe. |
|
| 1154 | + * |
|
| 1155 | + * @since 1.9.0 |
|
| 1156 | + * |
|
| 1157 | + */ |
|
| 1158 | + public static function stop_quiz_questions_loop(){ |
|
| 1159 | 1159 | |
| 1160 | - $sensei_question_loop['total'] = 0; |
|
| 1161 | - $sensei_question_loop['questions'] = array(); |
|
| 1162 | - $sensei_question_loop['quiz_id'] = ''; |
|
| 1160 | + $sensei_question_loop['total'] = 0; |
|
| 1161 | + $sensei_question_loop['questions'] = array(); |
|
| 1162 | + $sensei_question_loop['quiz_id'] = ''; |
|
| 1163 | 1163 | |
| 1164 | - } |
|
| 1164 | + } |
|
| 1165 | 1165 | |
| 1166 | - /** |
|
| 1167 | - * Output the title for the single quiz page |
|
| 1168 | - * |
|
| 1169 | - * @since 1.9.0 |
|
| 1170 | - */ |
|
| 1171 | - public static function the_title(){ |
|
| 1172 | - ?> |
|
| 1166 | + /** |
|
| 1167 | + * Output the title for the single quiz page |
|
| 1168 | + * |
|
| 1169 | + * @since 1.9.0 |
|
| 1170 | + */ |
|
| 1171 | + public static function the_title(){ |
|
| 1172 | + ?> |
|
| 1173 | 1173 | <header> |
| 1174 | 1174 | |
| 1175 | 1175 | <h1> |
| 1176 | 1176 | |
| 1177 | 1177 | <?php |
| 1178 | - /** |
|
| 1179 | - * Filter documented in class-sensei-messages.php the_title |
|
| 1180 | - */ |
|
| 1181 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
| 1182 | - ?> |
|
| 1178 | + /** |
|
| 1179 | + * Filter documented in class-sensei-messages.php the_title |
|
| 1180 | + */ |
|
| 1181 | + echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
| 1182 | + ?> |
|
| 1183 | 1183 | |
| 1184 | 1184 | </h1> |
| 1185 | 1185 | |
| 1186 | 1186 | </header> |
| 1187 | 1187 | |
| 1188 | 1188 | <?php |
| 1189 | - }//the_title |
|
| 1189 | + }//the_title |
|
| 1190 | 1190 | |
| 1191 | - /** |
|
| 1192 | - * Output the sensei quiz status message. |
|
| 1193 | - * |
|
| 1194 | - * @param $quiz_id |
|
| 1195 | - */ |
|
| 1196 | - public static function the_user_status_message( $quiz_id ){ |
|
| 1191 | + /** |
|
| 1192 | + * Output the sensei quiz status message. |
|
| 1193 | + * |
|
| 1194 | + * @param $quiz_id |
|
| 1195 | + */ |
|
| 1196 | + public static function the_user_status_message( $quiz_id ){ |
|
| 1197 | 1197 | |
| 1198 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 1199 | - $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
| 1200 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 1198 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 1199 | + $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
| 1200 | + echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 1201 | 1201 | |
| 1202 | - } |
|
| 1202 | + } |
|
| 1203 | 1203 | |
| 1204 | - /** |
|
| 1205 | - * This functions runs the old sensei_quiz_action_buttons action |
|
| 1206 | - * for backwards compatiblity sake. |
|
| 1207 | - * |
|
| 1208 | - * @since 1.9.0 |
|
| 1209 | - * @deprecated |
|
| 1210 | - */ |
|
| 1211 | - public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
| 1204 | + /** |
|
| 1205 | + * This functions runs the old sensei_quiz_action_buttons action |
|
| 1206 | + * for backwards compatiblity sake. |
|
| 1207 | + * |
|
| 1208 | + * @since 1.9.0 |
|
| 1209 | + * @deprecated |
|
| 1210 | + */ |
|
| 1211 | + public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
| 1212 | 1212 | |
| 1213 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1213 | + sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1214 | 1214 | |
| 1215 | - } |
|
| 1215 | + } |
|
| 1216 | 1216 | |
| 1217 | - /** |
|
| 1218 | - * The quiz action buttons needed to ouput quiz |
|
| 1219 | - * action such as reset complete and save. |
|
| 1220 | - * |
|
| 1221 | - * @since 1.3.0 |
|
| 1222 | - */ |
|
| 1223 | - public static function action_buttons() { |
|
| 1217 | + /** |
|
| 1218 | + * The quiz action buttons needed to ouput quiz |
|
| 1219 | + * action such as reset complete and save. |
|
| 1220 | + * |
|
| 1221 | + * @since 1.3.0 |
|
| 1222 | + */ |
|
| 1223 | + public static function action_buttons() { |
|
| 1224 | 1224 | |
| 1225 | - global $post, $current_user; |
|
| 1225 | + global $post, $current_user; |
|
| 1226 | 1226 | |
| 1227 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
| 1228 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 1229 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1230 | - $show_actions = true; |
|
| 1231 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
| 1227 | + $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
| 1228 | + $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 1229 | + $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1230 | + $show_actions = true; |
|
| 1231 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
| 1232 | 1232 | |
| 1233 | - //setup quiz grade |
|
| 1234 | - $user_quiz_grade = ''; |
|
| 1235 | - if( ! empty( $user_lesson_status ) ){ |
|
| 1236 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1237 | - } |
|
| 1233 | + //setup quiz grade |
|
| 1234 | + $user_quiz_grade = ''; |
|
| 1235 | + if( ! empty( $user_lesson_status ) ){ |
|
| 1236 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1237 | + } |
|
| 1238 | 1238 | |
| 1239 | 1239 | |
| 1240 | - if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 1240 | + if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 1241 | 1241 | |
| 1242 | - // If the user hasn't completed the prereq then hide the current actions |
|
| 1243 | - $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
| 1242 | + // If the user hasn't completed the prereq then hide the current actions |
|
| 1243 | + $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
| 1244 | 1244 | |
| 1245 | - } |
|
| 1246 | - if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 1245 | + } |
|
| 1246 | + if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 1247 | 1247 | |
| 1248 | - // Get Reset Settings |
|
| 1249 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
| 1248 | + // Get Reset Settings |
|
| 1249 | + $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
| 1250 | 1250 | |
| 1251 | 1251 | <!-- Action Nonce's --> |
| 1252 | 1252 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" |
@@ -1273,55 +1273,55 @@ discard block |
||
| 1273 | 1273 | |
| 1274 | 1274 | <?php } |
| 1275 | 1275 | |
| 1276 | - } // End sensei_quiz_action_buttons() |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * Fetch the quiz grade |
|
| 1280 | - * |
|
| 1281 | - * @since 1.9.0 |
|
| 1282 | - * |
|
| 1283 | - * @param int $lesson_id |
|
| 1284 | - * @param int $user_id |
|
| 1285 | - * |
|
| 1286 | - * @return double $user_quiz_grade |
|
| 1287 | - */ |
|
| 1288 | - public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
| 1289 | - |
|
| 1290 | - // get the quiz grade |
|
| 1291 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1292 | - $user_quiz_grade = 0; |
|
| 1293 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 1294 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - return (double) $user_quiz_grade; |
|
| 1298 | - |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - /** |
|
| 1302 | - * Check the quiz reset property for a given lesson's quiz. |
|
| 1303 | - * |
|
| 1304 | - * The data is stored on the quiz but going forward the quiz post |
|
| 1305 | - * type will be retired, hence the lesson_id is a require parameter. |
|
| 1306 | - * |
|
| 1307 | - * @since 1.9.0 |
|
| 1308 | - * |
|
| 1309 | - * @param int $lesson_id |
|
| 1310 | - * @return bool |
|
| 1311 | - */ |
|
| 1312 | - public static function is_reset_allowed( $lesson_id ){ |
|
| 1313 | - |
|
| 1314 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1315 | - |
|
| 1316 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 1317 | - //backwards compatibility |
|
| 1318 | - if( 'on' == $reset_allowed ) { |
|
| 1319 | - $reset_allowed = 1; |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - return (bool) $reset_allowed; |
|
| 1323 | - |
|
| 1324 | - } |
|
| 1276 | + } // End sensei_quiz_action_buttons() |
|
| 1277 | + |
|
| 1278 | + /** |
|
| 1279 | + * Fetch the quiz grade |
|
| 1280 | + * |
|
| 1281 | + * @since 1.9.0 |
|
| 1282 | + * |
|
| 1283 | + * @param int $lesson_id |
|
| 1284 | + * @param int $user_id |
|
| 1285 | + * |
|
| 1286 | + * @return double $user_quiz_grade |
|
| 1287 | + */ |
|
| 1288 | + public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
| 1289 | + |
|
| 1290 | + // get the quiz grade |
|
| 1291 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1292 | + $user_quiz_grade = 0; |
|
| 1293 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 1294 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + return (double) $user_quiz_grade; |
|
| 1298 | + |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + /** |
|
| 1302 | + * Check the quiz reset property for a given lesson's quiz. |
|
| 1303 | + * |
|
| 1304 | + * The data is stored on the quiz but going forward the quiz post |
|
| 1305 | + * type will be retired, hence the lesson_id is a require parameter. |
|
| 1306 | + * |
|
| 1307 | + * @since 1.9.0 |
|
| 1308 | + * |
|
| 1309 | + * @param int $lesson_id |
|
| 1310 | + * @return bool |
|
| 1311 | + */ |
|
| 1312 | + public static function is_reset_allowed( $lesson_id ){ |
|
| 1313 | + |
|
| 1314 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1315 | + |
|
| 1316 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 1317 | + //backwards compatibility |
|
| 1318 | + if( 'on' == $reset_allowed ) { |
|
| 1319 | + $reset_allowed = 1; |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + return (bool) $reset_allowed; |
|
| 1323 | + |
|
| 1324 | + } |
|
| 1325 | 1325 | |
| 1326 | 1326 | } // End Class WooThemes_Sensei_Quiz |
| 1327 | 1327 | |
@@ -178,8 +178,8 @@ |
||
| 178 | 178 | * |
| 179 | 179 | * @since 1.9.0 |
| 180 | 180 | * |
| 181 | - * @param $hook_tag |
|
| 182 | - * @param $version |
|
| 181 | + * @param string $hook_tag |
|
| 182 | + * @param string $version |
|
| 183 | 183 | * @param $alternative |
| 184 | 184 | * @param array $args |
| 185 | 185 | */ |
@@ -45,16 +45,16 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | function sensei_all_access() { |
| 47 | 47 | |
| 48 | - $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' ); |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Filter sensei_all_access function result |
|
| 52 | - * which determinse if the current user |
|
| 53 | - * can access all of Sensei without restrictions |
|
| 54 | - * |
|
| 55 | - * @since 1.4.0 |
|
| 56 | - * @param bool $access |
|
| 57 | - */ |
|
| 48 | + $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' ); |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Filter sensei_all_access function result |
|
| 52 | + * which determinse if the current user |
|
| 53 | + * can access all of Sensei without restrictions |
|
| 54 | + * |
|
| 55 | + * @since 1.4.0 |
|
| 56 | + * @param bool $access |
|
| 57 | + */ |
|
| 58 | 58 | return apply_filters( 'sensei_all_access', $access ); |
| 59 | 59 | |
| 60 | 60 | } // End sensei_all_access() |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | function sensei_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
| 74 | 74 | |
| 75 | - $hex = str_replace( '#', '', $color ); |
|
| 75 | + $hex = str_replace( '#', '', $color ); |
|
| 76 | 76 | |
| 77 | 77 | $c_r = hexdec( substr( $hex, 0, 2 ) ); |
| 78 | 78 | $c_g = hexdec( substr( $hex, 2, 2 ) ); |
@@ -119,15 +119,15 @@ discard block |
||
| 119 | 119 | $color = '#'; |
| 120 | 120 | |
| 121 | 121 | foreach ($base as $k => $v) : |
| 122 | - $amount = $v / 100; |
|
| 123 | - $amount = round($amount * $factor); |
|
| 124 | - $new_decimal = $v - $amount; |
|
| 125 | - |
|
| 126 | - $new_hex_component = dechex($new_decimal); |
|
| 127 | - if(strlen($new_hex_component) < 2) : |
|
| 128 | - $new_hex_component = "0".$new_hex_component; |
|
| 129 | - endif; |
|
| 130 | - $color .= $new_hex_component; |
|
| 122 | + $amount = $v / 100; |
|
| 123 | + $amount = round($amount * $factor); |
|
| 124 | + $new_decimal = $v - $amount; |
|
| 125 | + |
|
| 126 | + $new_hex_component = dechex($new_decimal); |
|
| 127 | + if(strlen($new_hex_component) < 2) : |
|
| 128 | + $new_hex_component = "0".$new_hex_component; |
|
| 129 | + endif; |
|
| 130 | + $color .= $new_hex_component; |
|
| 131 | 131 | endforeach; |
| 132 | 132 | |
| 133 | 133 | return $color; |
@@ -148,17 +148,17 @@ discard block |
||
| 148 | 148 | $base = sensei_rgb_from_hex( $color ); |
| 149 | 149 | $color = '#'; |
| 150 | 150 | |
| 151 | - foreach ($base as $k => $v) : |
|
| 152 | - $amount = 255 - $v; |
|
| 153 | - $amount = $amount / 100; |
|
| 154 | - $amount = round($amount * $factor); |
|
| 155 | - $new_decimal = $v + $amount; |
|
| 156 | - |
|
| 157 | - $new_hex_component = dechex($new_decimal); |
|
| 158 | - if(strlen($new_hex_component) < 2) : |
|
| 159 | - $new_hex_component = "0".$new_hex_component; |
|
| 160 | - endif; |
|
| 161 | - $color .= $new_hex_component; |
|
| 151 | + foreach ($base as $k => $v) : |
|
| 152 | + $amount = 255 - $v; |
|
| 153 | + $amount = $amount / 100; |
|
| 154 | + $amount = round($amount * $factor); |
|
| 155 | + $new_decimal = $v + $amount; |
|
| 156 | + |
|
| 157 | + $new_hex_component = dechex($new_decimal); |
|
| 158 | + if(strlen($new_hex_component) < 2) : |
|
| 159 | + $new_hex_component = "0".$new_hex_component; |
|
| 160 | + endif; |
|
| 161 | + $color .= $new_hex_component; |
|
| 162 | 162 | endforeach; |
| 163 | 163 | |
| 164 | 164 | return $color; |
@@ -172,14 +172,14 @@ discard block |
||
| 172 | 172 | * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active() |
| 173 | 173 | */ |
| 174 | 174 | if ( ! function_exists( 'is_woocommerce_active' ) ) { |
| 175 | - function is_woocommerce_active() { |
|
| 176 | - // calling is present instead of is active here |
|
| 177 | - // as this function can override other is_woocommerce_active |
|
| 178 | - // function in other woo plugins and Sensei_WC::is_woocommerce_active |
|
| 179 | - // also check the sensei settings for enable WooCommerce support, which |
|
| 180 | - // other plugins should not check against. |
|
| 181 | - return Sensei_WC::is_woocommerce_present(); |
|
| 182 | - } |
|
| 175 | + function is_woocommerce_active() { |
|
| 176 | + // calling is present instead of is active here |
|
| 177 | + // as this function can override other is_woocommerce_active |
|
| 178 | + // function in other woo plugins and Sensei_WC::is_woocommerce_active |
|
| 179 | + // also check the sensei settings for enable WooCommerce support, which |
|
| 180 | + // other plugins should not check against. |
|
| 181 | + return Sensei_WC::is_woocommerce_present(); |
|
| 182 | + } |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -195,20 +195,20 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | function sensei_do_deprecated_action( $hook_tag, $version, $alternative="" , $args = array() ){ |
| 197 | 197 | |
| 198 | - if( has_action( $hook_tag ) ){ |
|
| 198 | + if( has_action( $hook_tag ) ){ |
|
| 199 | 199 | |
| 200 | - $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version ); |
|
| 200 | + $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version ); |
|
| 201 | 201 | |
| 202 | - if( !empty( $alternative ) ){ |
|
| 202 | + if( !empty( $alternative ) ){ |
|
| 203 | 203 | |
| 204 | - $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ; |
|
| 204 | + $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ; |
|
| 205 | 205 | |
| 206 | - } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - trigger_error( $error_message ); |
|
| 209 | - do_action( $hook_tag , $args ); |
|
| 208 | + trigger_error( $error_message ); |
|
| 209 | + do_action( $hook_tag , $args ); |
|
| 210 | 210 | |
| 211 | - } |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | 213 | }// end sensei_do_deprecated_action |
| 214 | 214 | |
@@ -238,18 +238,18 @@ discard block |
||
| 238 | 238 | */ |
| 239 | 239 | function sensei_user_login_url(){ |
| 240 | 240 | |
| 241 | - $my_courses_page_id = intval( Sensei()->settings->get( 'my_course_page' ) ); |
|
| 242 | - $page = get_post( $my_courses_page_id ); |
|
| 241 | + $my_courses_page_id = intval( Sensei()->settings->get( 'my_course_page' ) ); |
|
| 242 | + $page = get_post( $my_courses_page_id ); |
|
| 243 | 243 | |
| 244 | - if ( $my_courses_page_id && isset( $page->ID ) && 'page' == get_post_type( $page->ID ) ){ |
|
| 244 | + if ( $my_courses_page_id && isset( $page->ID ) && 'page' == get_post_type( $page->ID ) ){ |
|
| 245 | 245 | |
| 246 | - return get_permalink( $page->ID ); |
|
| 246 | + return get_permalink( $page->ID ); |
|
| 247 | 247 | |
| 248 | - } else { |
|
| 248 | + } else { |
|
| 249 | 249 | |
| 250 | - return wp_login_url(); |
|
| 250 | + return wp_login_url(); |
|
| 251 | 251 | |
| 252 | - } |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | 254 | }// end sensei_user_login_link |
| 255 | 255 | |
@@ -262,8 +262,8 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | function sensei_is_login_required(){ |
| 264 | 264 | |
| 265 | - $login_required = isset( Sensei()->settings->settings['access_permission'] ) && ( true == Sensei()->settings->settings['access_permission'] ); |
|
| 265 | + $login_required = isset( Sensei()->settings->settings['access_permission'] ) && ( true == Sensei()->settings->settings['access_permission'] ); |
|
| 266 | 266 | |
| 267 | - return $login_required; |
|
| 267 | + return $login_required; |
|
| 268 | 268 | |
| 269 | 269 | } |
| 270 | 270 | \ No newline at end of file |
@@ -103,8 +103,8 @@ |
||
| 103 | 103 | * |
| 104 | 104 | * @since 1.9.0 |
| 105 | 105 | * |
| 106 | - * @param $title |
|
| 107 | - * @param $shortcode_specific_override |
|
| 106 | + * @param string $title |
|
| 107 | + * @param string $shortcode_specific_override |
|
| 108 | 108 | * @return string |
| 109 | 109 | */ |
| 110 | 110 | public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
@@ -17,323 +17,323 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class Sensei_Legacy_Shortcodes { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Add the legacy shortcodes to WordPress |
|
| 22 | - * |
|
| 23 | - * @since 1.9.0 |
|
| 24 | - */ |
|
| 25 | - public static function init(){ |
|
| 26 | - |
|
| 27 | - add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); |
|
| 28 | - add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); |
|
| 29 | - add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); |
|
| 30 | - add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); |
|
| 31 | - add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); |
|
| 32 | - add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); |
|
| 33 | - |
|
| 34 | - } |
|
| 35 | - /** |
|
| 36 | - * all_courses shortcode output function. |
|
| 37 | - * |
|
| 38 | - * The function should only be called indirectly through do_shortcode() |
|
| 39 | - * |
|
| 40 | - * @access public |
|
| 41 | - * @param mixed $atts |
|
| 42 | - * @param mixed $content (default: null) |
|
| 43 | - * @return string |
|
| 44 | - */ |
|
| 45 | - public static function all_courses( $atts, $content = null ) { |
|
| 46 | - |
|
| 47 | - return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title |
|
| 48 | - |
|
| 49 | - } // all_courses() |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * paid_courses function. |
|
| 53 | - * |
|
| 54 | - * @access public |
|
| 55 | - * @param mixed $atts |
|
| 56 | - * @param mixed $content (default: null) |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - public static function paid_courses( $atts, $content = null ) { |
|
| 60 | - |
|
| 61 | - return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' ); |
|
| 62 | - |
|
| 63 | - } // End paid_courses() |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * featured_courses function. |
|
| 68 | - * |
|
| 69 | - * @access public |
|
| 70 | - * @param mixed $atts |
|
| 71 | - * @param mixed $content (default: null) |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public static function featured_courses( $atts, $content = null ) { |
|
| 75 | - |
|
| 76 | - return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' ); |
|
| 20 | + /** |
|
| 21 | + * Add the legacy shortcodes to WordPress |
|
| 22 | + * |
|
| 23 | + * @since 1.9.0 |
|
| 24 | + */ |
|
| 25 | + public static function init(){ |
|
| 26 | + |
|
| 27 | + add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); |
|
| 28 | + add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); |
|
| 29 | + add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); |
|
| 30 | + add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); |
|
| 31 | + add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); |
|
| 32 | + add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); |
|
| 33 | + |
|
| 34 | + } |
|
| 35 | + /** |
|
| 36 | + * all_courses shortcode output function. |
|
| 37 | + * |
|
| 38 | + * The function should only be called indirectly through do_shortcode() |
|
| 39 | + * |
|
| 40 | + * @access public |
|
| 41 | + * @param mixed $atts |
|
| 42 | + * @param mixed $content (default: null) |
|
| 43 | + * @return string |
|
| 44 | + */ |
|
| 45 | + public static function all_courses( $atts, $content = null ) { |
|
| 46 | + |
|
| 47 | + return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title |
|
| 48 | + |
|
| 49 | + } // all_courses() |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * paid_courses function. |
|
| 53 | + * |
|
| 54 | + * @access public |
|
| 55 | + * @param mixed $atts |
|
| 56 | + * @param mixed $content (default: null) |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + public static function paid_courses( $atts, $content = null ) { |
|
| 60 | + |
|
| 61 | + return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' ); |
|
| 62 | + |
|
| 63 | + } // End paid_courses() |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * featured_courses function. |
|
| 68 | + * |
|
| 69 | + * @access public |
|
| 70 | + * @param mixed $atts |
|
| 71 | + * @param mixed $content (default: null) |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public static function featured_courses( $atts, $content = null ) { |
|
| 75 | + |
|
| 76 | + return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' ); |
|
| 77 | 77 | |
| 78 | - } // End featured_courses() |
|
| 78 | + } // End featured_courses() |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * shortcode_free_courses function. |
|
| 82 | - * |
|
| 83 | - * @access public |
|
| 84 | - * @param mixed $atts |
|
| 85 | - * @param mixed $content (default: null) |
|
| 86 | - * @return string |
|
| 87 | - */ |
|
| 88 | - public static function free_courses( $atts, $content = null ) { |
|
| 80 | + /** |
|
| 81 | + * shortcode_free_courses function. |
|
| 82 | + * |
|
| 83 | + * @access public |
|
| 84 | + * @param mixed $atts |
|
| 85 | + * @param mixed $content (default: null) |
|
| 86 | + * @return string |
|
| 87 | + */ |
|
| 88 | + public static function free_courses( $atts, $content = null ) { |
|
| 89 | 89 | |
| 90 | - return self::generate_shortcode_courses( 'Free Courses', 'freecourses' ); |
|
| 90 | + return self::generate_shortcode_courses( 'Free Courses', 'freecourses' ); |
|
| 91 | 91 | |
| 92 | - } // End free_courses() |
|
| 92 | + } // End free_courses() |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * shortcode_new_courses function. |
|
| 96 | - * |
|
| 97 | - * @access public |
|
| 98 | - * @param mixed $atts |
|
| 99 | - * @param mixed $content (default: null) |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - public static function new_courses( $atts, $content = null ) { |
|
| 94 | + /** |
|
| 95 | + * shortcode_new_courses function. |
|
| 96 | + * |
|
| 97 | + * @access public |
|
| 98 | + * @param mixed $atts |
|
| 99 | + * @param mixed $content (default: null) |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + public static function new_courses( $atts, $content = null ) { |
|
| 103 | 103 | |
| 104 | - return self::generate_shortcode_courses( 'New Courses', 'newcourses' ); |
|
| 104 | + return self::generate_shortcode_courses( 'New Courses', 'newcourses' ); |
|
| 105 | 105 | |
| 106 | - } // End new_courses() |
|
| 106 | + } // End new_courses() |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Generate courses adding a title. |
|
| 110 | - * |
|
| 111 | - * @since 1.9.0 |
|
| 112 | - * |
|
| 113 | - * @param $title |
|
| 114 | - * @param $shortcode_specific_override |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 117 | - public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
|
| 108 | + /** |
|
| 109 | + * Generate courses adding a title. |
|
| 110 | + * |
|
| 111 | + * @since 1.9.0 |
|
| 112 | + * |
|
| 113 | + * @param $title |
|
| 114 | + * @param $shortcode_specific_override |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | + public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
|
| 118 | 118 | |
| 119 | - global $shortcode_override, $posts_array; |
|
| 119 | + global $shortcode_override, $posts_array; |
|
| 120 | 120 | |
| 121 | - $shortcode_override = $shortcode_specific_override; |
|
| 121 | + $shortcode_override = $shortcode_specific_override; |
|
| 122 | 122 | |
| 123 | - // do not show this short code if there is a shortcode int he url and |
|
| 124 | - // this specific shortcode is not the one requested in the ur. |
|
| 125 | - $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
| 126 | - if( ! empty( $specific_shortcode_requested) && |
|
| 127 | - $specific_shortcode_requested != $shortcode_override ){ |
|
| 123 | + // do not show this short code if there is a shortcode int he url and |
|
| 124 | + // this specific shortcode is not the one requested in the ur. |
|
| 125 | + $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
| 126 | + if( ! empty( $specific_shortcode_requested) && |
|
| 127 | + $specific_shortcode_requested != $shortcode_override ){ |
|
| 128 | 128 | |
| 129 | - return ''; |
|
| 129 | + return ''; |
|
| 130 | 130 | |
| 131 | - } |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - // loop and get all courses html |
|
| 134 | - ob_start(); |
|
| 135 | - self::initialise_legacy_course_loop(); |
|
| 136 | - $courses = ob_get_clean(); |
|
| 133 | + // loop and get all courses html |
|
| 134 | + ob_start(); |
|
| 135 | + self::initialise_legacy_course_loop(); |
|
| 136 | + $courses = ob_get_clean(); |
|
| 137 | 137 | |
| 138 | - $content = ''; |
|
| 139 | - if( count( $posts_array ) > 0 ){ |
|
| 138 | + $content = ''; |
|
| 139 | + if( count( $posts_array ) > 0 ){ |
|
| 140 | 140 | |
| 141 | - $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; |
|
| 142 | - $before .= '<section id="main-course" class="course-container">'; |
|
| 141 | + $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; |
|
| 142 | + $before .= '<section id="main-course" class="course-container">'; |
|
| 143 | 143 | |
| 144 | - $after = '</section>'; |
|
| 144 | + $after = '</section>'; |
|
| 145 | 145 | |
| 146 | - //assemble |
|
| 147 | - $content = $before . $courses . $after; |
|
| 146 | + //assemble |
|
| 147 | + $content = $before . $courses . $after; |
|
| 148 | 148 | |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - return $content; |
|
| 151 | + return $content; |
|
| 152 | 152 | |
| 153 | - }// end generate_shortcode_courses |
|
| 153 | + }// end generate_shortcode_courses |
|
| 154 | 154 | |
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * user_courses function. |
|
| 158 | - * |
|
| 159 | - * @access public |
|
| 160 | - * @param mixed $atts |
|
| 161 | - * @param mixed $content (default: null) |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public static function user_courses( $atts, $content = null ) { |
|
| 165 | - global $shortcode_override; |
|
| 166 | - extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); |
|
| 156 | + /** |
|
| 157 | + * user_courses function. |
|
| 158 | + * |
|
| 159 | + * @access public |
|
| 160 | + * @param mixed $atts |
|
| 161 | + * @param mixed $content (default: null) |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | + public static function user_courses( $atts, $content = null ) { |
|
| 165 | + global $shortcode_override; |
|
| 166 | + extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); |
|
| 167 | 167 | |
| 168 | - $shortcode_override = 'usercourses'; |
|
| 168 | + $shortcode_override = 'usercourses'; |
|
| 169 | 169 | |
| 170 | - ob_start(); |
|
| 170 | + ob_start(); |
|
| 171 | 171 | |
| 172 | - if( is_user_logged_in() ){ |
|
| 172 | + if( is_user_logged_in() ){ |
|
| 173 | 173 | |
| 174 | - Sensei_Templates::get_template( 'user/my-courses.php' ); |
|
| 174 | + Sensei_Templates::get_template( 'user/my-courses.php' ); |
|
| 175 | 175 | |
| 176 | - }else{ |
|
| 176 | + }else{ |
|
| 177 | 177 | |
| 178 | - Sensei()->frontend->sensei_login_form(); |
|
| 178 | + Sensei()->frontend->sensei_login_form(); |
|
| 179 | 179 | |
| 180 | - } |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - $content = ob_get_clean(); |
|
| 183 | - return $content; |
|
| 182 | + $content = ob_get_clean(); |
|
| 183 | + return $content; |
|
| 184 | 184 | |
| 185 | - } // End user_courses() |
|
| 185 | + } // End user_courses() |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * This function is simply to honor the legacy |
|
| 189 | - * loop-course.php for the old shortcodes. |
|
| 190 | - * @since 1.9.0 |
|
| 191 | - */ |
|
| 192 | - public static function initialise_legacy_course_loop(){ |
|
| 187 | + /** |
|
| 188 | + * This function is simply to honor the legacy |
|
| 189 | + * loop-course.php for the old shortcodes. |
|
| 190 | + * @since 1.9.0 |
|
| 191 | + */ |
|
| 192 | + public static function initialise_legacy_course_loop(){ |
|
| 193 | 193 | |
| 194 | - global $post, $wp_query, $shortcode_override, $course_excludes; |
|
| 194 | + global $post, $wp_query, $shortcode_override, $course_excludes; |
|
| 195 | 195 | |
| 196 | - // Handle Query Type |
|
| 197 | - $query_type = ''; |
|
| 196 | + // Handle Query Type |
|
| 197 | + $query_type = ''; |
|
| 198 | 198 | |
| 199 | - if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { |
|
| 200 | - $query_type = esc_html( $_GET[ 'action' ] ); |
|
| 201 | - } // End If Statement |
|
| 199 | + if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { |
|
| 200 | + $query_type = esc_html( $_GET[ 'action' ] ); |
|
| 201 | + } // End If Statement |
|
| 202 | 202 | |
| 203 | - if ( '' != $shortcode_override ) { |
|
| 204 | - $query_type = $shortcode_override; |
|
| 205 | - } // End If Statement |
|
| 203 | + if ( '' != $shortcode_override ) { |
|
| 204 | + $query_type = $shortcode_override; |
|
| 205 | + } // End If Statement |
|
| 206 | 206 | |
| 207 | - if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } |
|
| 207 | + if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } |
|
| 208 | 208 | |
| 209 | - // Check that query returns results |
|
| 210 | - // Handle Pagination |
|
| 211 | - $paged = $wp_query->get( 'paged' ); |
|
| 212 | - $paged = empty( $paged ) ? 1 : $paged; |
|
| 209 | + // Check that query returns results |
|
| 210 | + // Handle Pagination |
|
| 211 | + $paged = $wp_query->get( 'paged' ); |
|
| 212 | + $paged = empty( $paged ) ? 1 : $paged; |
|
| 213 | 213 | |
| 214 | 214 | |
| 215 | - // Check for pagination settings |
|
| 216 | - if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
| 215 | + // Check for pagination settings |
|
| 216 | + if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
| 217 | 217 | |
| 218 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 218 | + $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 219 | 219 | |
| 220 | - } else { |
|
| 220 | + } else { |
|
| 221 | 221 | |
| 222 | - $amount = $wp_query->get( 'posts_per_page' ); |
|
| 222 | + $amount = $wp_query->get( 'posts_per_page' ); |
|
| 223 | 223 | |
| 224 | - } // End If Statement |
|
| 224 | + } // End If Statement |
|
| 225 | 225 | |
| 226 | - // This is not a paginated page (or it's simply the first page of a paginated page/post) |
|
| 226 | + // This is not a paginated page (or it's simply the first page of a paginated page/post) |
|
| 227 | 227 | |
| 228 | - global $posts_array; |
|
| 229 | - $course_includes = array(); |
|
| 228 | + global $posts_array; |
|
| 229 | + $course_includes = array(); |
|
| 230 | 230 | |
| 231 | - $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); |
|
| 232 | - $course_query = new WP_Query( $query_args ); |
|
| 233 | - $posts_array = $course_query->get_posts(); |
|
| 231 | + $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); |
|
| 232 | + $course_query = new WP_Query( $query_args ); |
|
| 233 | + $posts_array = $course_query->get_posts(); |
|
| 234 | 234 | |
| 235 | - // output the courses |
|
| 236 | - if( ! empty( $posts_array ) ) { |
|
| 235 | + // output the courses |
|
| 236 | + if( ! empty( $posts_array ) ) { |
|
| 237 | 237 | |
| 238 | - //output all courses for current query |
|
| 239 | - self::loop_courses( $course_query, $amount ); |
|
| 238 | + //output all courses for current query |
|
| 239 | + self::loop_courses( $course_query, $amount ); |
|
| 240 | 240 | |
| 241 | - } |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - } |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Loop through courses in the query and output the infomration needed |
|
| 247 | - * |
|
| 248 | - * @since 1.9.0 |
|
| 249 | - * |
|
| 250 | - * @param WP_Query $course_query |
|
| 251 | - */ |
|
| 252 | - public static function loop_courses( $course_query, $amount ){ |
|
| 245 | + /** |
|
| 246 | + * Loop through courses in the query and output the infomration needed |
|
| 247 | + * |
|
| 248 | + * @since 1.9.0 |
|
| 249 | + * |
|
| 250 | + * @param WP_Query $course_query |
|
| 251 | + */ |
|
| 252 | + public static function loop_courses( $course_query, $amount ){ |
|
| 253 | 253 | |
| 254 | - global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; |
|
| 254 | + global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; |
|
| 255 | 255 | |
| 256 | - if ( count( $course_query->get_posts() ) > 0 ) { |
|
| 256 | + if ( count( $course_query->get_posts() ) > 0 ) { |
|
| 257 | 257 | |
| 258 | - do_action( 'sensei_course_archive_header', $shortcode_override ); |
|
| 258 | + do_action( 'sensei_course_archive_header', $shortcode_override ); |
|
| 259 | 259 | |
| 260 | - foreach ( $course_query->get_posts() as $course){ |
|
| 260 | + foreach ( $course_query->get_posts() as $course){ |
|
| 261 | 261 | |
| 262 | - // Make sure the other loops dont include the same post twice! |
|
| 263 | - array_push( $course_excludes, $course->ID ); |
|
| 262 | + // Make sure the other loops dont include the same post twice! |
|
| 263 | + array_push( $course_excludes, $course->ID ); |
|
| 264 | 264 | |
| 265 | - // output the course markup |
|
| 266 | - self::the_course( $course->ID ); |
|
| 265 | + // output the course markup |
|
| 266 | + self::the_course( $course->ID ); |
|
| 267 | 267 | |
| 268 | - } // End For Loop |
|
| 268 | + } // End For Loop |
|
| 269 | 269 | |
| 270 | - // More and Prev links |
|
| 271 | - $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); |
|
| 272 | - $posts_array = $posts_array_query->get_posts(); |
|
| 273 | - $max_pages = $course_query->found_posts / $amount; |
|
| 274 | - if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { |
|
| 270 | + // More and Prev links |
|
| 271 | + $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); |
|
| 272 | + $posts_array = $posts_array_query->get_posts(); |
|
| 273 | + $max_pages = $course_query->found_posts / $amount; |
|
| 274 | + if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { |
|
| 275 | 275 | |
| 276 | - switch( $shortcode_override ){ |
|
| 277 | - case 'paidcourses': |
|
| 278 | - $filter = 'paid'; |
|
| 279 | - break; |
|
| 280 | - case 'featuredcourses': |
|
| 281 | - $filter = 'featured'; |
|
| 282 | - break; |
|
| 283 | - case 'freecourses': |
|
| 284 | - $filter = 'free'; |
|
| 285 | - break; |
|
| 286 | - default: |
|
| 287 | - $filter = ''; |
|
| 288 | - break; |
|
| 289 | - } |
|
| 276 | + switch( $shortcode_override ){ |
|
| 277 | + case 'paidcourses': |
|
| 278 | + $filter = 'paid'; |
|
| 279 | + break; |
|
| 280 | + case 'featuredcourses': |
|
| 281 | + $filter = 'featured'; |
|
| 282 | + break; |
|
| 283 | + case 'freecourses': |
|
| 284 | + $filter = 'free'; |
|
| 285 | + break; |
|
| 286 | + default: |
|
| 287 | + $filter = ''; |
|
| 288 | + break; |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - $quer_args = array(); |
|
| 292 | - $quer_args[ 'paged' ] = '2'; |
|
| 293 | - if( !empty( $filter ) ){ |
|
| 294 | - $quer_args[ 'course_filter' ] = $filter; |
|
| 295 | - } |
|
| 291 | + $quer_args = array(); |
|
| 292 | + $quer_args[ 'paged' ] = '2'; |
|
| 293 | + if( !empty( $filter ) ){ |
|
| 294 | + $quer_args[ 'course_filter' ] = $filter; |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - $course_pagination_link = get_post_type_archive_link( 'course' ); |
|
| 298 | - $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); |
|
| 299 | - $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); |
|
| 297 | + $course_pagination_link = get_post_type_archive_link( 'course' ); |
|
| 298 | + $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); |
|
| 299 | + $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); |
|
| 300 | 300 | |
| 301 | - // next/more |
|
| 302 | - $html = '<div class="navigation"><div class="nav-next">'; |
|
| 303 | - $html .= '<a href="' . $more_link_url . '">'; |
|
| 304 | - $html .= $more_link_text; |
|
| 305 | - $html .= '<span class="meta-nav"></span></a></div>'; |
|
| 301 | + // next/more |
|
| 302 | + $html = '<div class="navigation"><div class="nav-next">'; |
|
| 303 | + $html .= '<a href="' . $more_link_url . '">'; |
|
| 304 | + $html .= $more_link_text; |
|
| 305 | + $html .= '<span class="meta-nav"></span></a></div>'; |
|
| 306 | 306 | |
| 307 | - echo apply_filters( 'course_archive_next_link', $html ); |
|
| 307 | + echo apply_filters( 'course_archive_next_link', $html ); |
|
| 308 | 308 | |
| 309 | - } // End If Statement |
|
| 309 | + } // End If Statement |
|
| 310 | 310 | |
| 311 | - } // End If Statement |
|
| 312 | - } |
|
| 311 | + } // End If Statement |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * Print a single course markup |
|
| 316 | - * |
|
| 317 | - * @param $course_id |
|
| 318 | - */ |
|
| 319 | - public static function the_course( $course_id ){ |
|
| 314 | + /** |
|
| 315 | + * Print a single course markup |
|
| 316 | + * |
|
| 317 | + * @param $course_id |
|
| 318 | + */ |
|
| 319 | + public static function the_course( $course_id ){ |
|
| 320 | 320 | |
| 321 | - // Get meta data |
|
| 322 | - $course = get_post( $course_id ); |
|
| 323 | - $user_info = get_userdata( absint( $course->post_author ) ); |
|
| 324 | - $author_link = get_author_posts_url( absint( $course->post_author ) ); |
|
| 325 | - $author_display_name = $user_info->display_name; |
|
| 326 | - $author_id = $course->post_author; |
|
| 327 | - $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); |
|
| 328 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); |
|
| 329 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 330 | - ?> |
|
| 321 | + // Get meta data |
|
| 322 | + $course = get_post( $course_id ); |
|
| 323 | + $user_info = get_userdata( absint( $course->post_author ) ); |
|
| 324 | + $author_link = get_author_posts_url( absint( $course->post_author ) ); |
|
| 325 | + $author_display_name = $user_info->display_name; |
|
| 326 | + $author_id = $course->post_author; |
|
| 327 | + $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); |
|
| 328 | + $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); |
|
| 329 | + $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 330 | + ?> |
|
| 331 | 331 | |
| 332 | 332 | <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>"> |
| 333 | 333 | <?php |
| 334 | - // so that legacy shortcodes work with the party plugins that wants to hook in |
|
| 335 | - do_action('sensei_course_content_before',$course->ID ); |
|
| 336 | - ?> |
|
| 334 | + // so that legacy shortcodes work with the party plugins that wants to hook in |
|
| 335 | + do_action('sensei_course_content_before',$course->ID ); |
|
| 336 | + ?> |
|
| 337 | 337 | <div class="course-content"> |
| 338 | 338 | |
| 339 | 339 | <?php Sensei()->course->course_image($course_id); ?> |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | </p> |
| 370 | 370 | |
| 371 | 371 | <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
| 372 | - $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> |
|
| 372 | + $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> |
|
| 373 | 373 | <p class="sensei-free-lessons"> |
| 374 | 374 | <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
| 375 | 375 | </a> - <?php echo $preview_lessons; ?> |
@@ -380,15 +380,15 @@ discard block |
||
| 380 | 380 | |
| 381 | 381 | </div> |
| 382 | 382 | <?php |
| 383 | - // so that legacy shortcodes work with thir party plugins that wants to hook in |
|
| 384 | - do_action('sensei_course_content_after', $course->ID); |
|
| 385 | - ?> |
|
| 383 | + // so that legacy shortcodes work with thir party plugins that wants to hook in |
|
| 384 | + do_action('sensei_course_content_after', $course->ID); |
|
| 385 | + ?> |
|
| 386 | 386 | |
| 387 | 387 | </article> |
| 388 | 388 | |
| 389 | 389 | <?php |
| 390 | 390 | |
| 391 | 391 | |
| 392 | - } // end the_course |
|
| 392 | + } // end the_course |
|
| 393 | 393 | |
| 394 | 394 | }// end class legacy shortcodes |
| 395 | 395 | \ No newline at end of file |
@@ -114,7 +114,7 @@ |
||
| 114 | 114 | * |
| 115 | 115 | * @since 1.9.0 |
| 116 | 116 | * |
| 117 | - * @param array $category_ids |
|
| 117 | + * @param array $categories |
|
| 118 | 118 | * @return array |
| 119 | 119 | */ |
| 120 | 120 | public function generate_term_ids( $categories = array() ){ |
@@ -24,135 +24,135 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class Sensei_Shortcode_Course_Categories implements Sensei_Shortcode_Interface { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var array list of taxonomy terms. |
|
| 29 | - */ |
|
| 30 | - protected $sensei_course_taxonomy_terms; |
|
| 27 | + /** |
|
| 28 | + * @var array list of taxonomy terms. |
|
| 29 | + */ |
|
| 30 | + protected $sensei_course_taxonomy_terms; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Setup the shortcode object |
|
| 34 | - * |
|
| 35 | - * @since 1.9.0 |
|
| 36 | - * @param array $attributes |
|
| 37 | - * @param string $content |
|
| 38 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 39 | - */ |
|
| 40 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 32 | + /** |
|
| 33 | + * Setup the shortcode object |
|
| 34 | + * |
|
| 35 | + * @since 1.9.0 |
|
| 36 | + * @param array $attributes |
|
| 37 | + * @param string $content |
|
| 38 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 39 | + */ |
|
| 40 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 41 | 41 | |
| 42 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'name'; |
|
| 43 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; |
|
| 44 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '100'; |
|
| 45 | - $this->parent = isset( $attributes['parent'] ) ? $attributes['parent'] : ''; |
|
| 42 | + $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'name'; |
|
| 43 | + $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; |
|
| 44 | + $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '100'; |
|
| 45 | + $this->parent = isset( $attributes['parent'] ) ? $attributes['parent'] : ''; |
|
| 46 | 46 | |
| 47 | - $include = isset( $attributes['include'] ) ? explode( ',' , $attributes['include'] ) : ''; |
|
| 48 | - $this->include = $this->generate_term_ids( $include ); |
|
| 47 | + $include = isset( $attributes['include'] ) ? explode( ',' , $attributes['include'] ) : ''; |
|
| 48 | + $this->include = $this->generate_term_ids( $include ); |
|
| 49 | 49 | |
| 50 | - $exclude = isset( $attributes['exclude'] ) ? explode( ',' , $attributes['exclude'] ) : ''; |
|
| 51 | - $this->exclude = $this->generate_term_ids( $exclude ); |
|
| 50 | + $exclude = isset( $attributes['exclude'] ) ? explode( ',' , $attributes['exclude'] ) : ''; |
|
| 51 | + $this->exclude = $this->generate_term_ids( $exclude ); |
|
| 52 | 52 | |
| 53 | - // make sure we handle string true/false values correctly with respective defaults |
|
| 54 | - $hide_empty = isset( $attributes['hide_empty'] ) ? $attributes['hide_empty'] : 'false'; |
|
| 55 | - $this->hide_empty = 'true' == $hide_empty ? true: false; |
|
| 53 | + // make sure we handle string true/false values correctly with respective defaults |
|
| 54 | + $hide_empty = isset( $attributes['hide_empty'] ) ? $attributes['hide_empty'] : 'false'; |
|
| 55 | + $this->hide_empty = 'true' == $hide_empty ? true: false; |
|
| 56 | 56 | |
| 57 | - $this->setup_course_categories(); |
|
| 57 | + $this->setup_course_categories(); |
|
| 58 | 58 | |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * create the messages query . |
|
| 63 | - * |
|
| 64 | - * @return mixed |
|
| 65 | - */ |
|
| 66 | - public function setup_course_categories(){ |
|
| 61 | + /** |
|
| 62 | + * create the messages query . |
|
| 63 | + * |
|
| 64 | + * @return mixed |
|
| 65 | + */ |
|
| 66 | + public function setup_course_categories(){ |
|
| 67 | 67 | |
| 68 | - $args = array( |
|
| 69 | - 'orderby' => $this->orderby, |
|
| 70 | - 'order' => $this->order, |
|
| 71 | - 'exclude' => $this->exclude, |
|
| 72 | - 'include' => $this->include, |
|
| 73 | - 'number' => $this->number, |
|
| 74 | - 'parent' => $this->parent, |
|
| 75 | - 'hide_empty' => $this->hide_empty, |
|
| 76 | - 'fields' => 'all', |
|
| 77 | - ); |
|
| 68 | + $args = array( |
|
| 69 | + 'orderby' => $this->orderby, |
|
| 70 | + 'order' => $this->order, |
|
| 71 | + 'exclude' => $this->exclude, |
|
| 72 | + 'include' => $this->include, |
|
| 73 | + 'number' => $this->number, |
|
| 74 | + 'parent' => $this->parent, |
|
| 75 | + 'hide_empty' => $this->hide_empty, |
|
| 76 | + 'fields' => 'all', |
|
| 77 | + ); |
|
| 78 | 78 | |
| 79 | - $this->sensei_course_taxonomy_terms = get_terms('course-category', $args); |
|
| 79 | + $this->sensei_course_taxonomy_terms = get_terms('course-category', $args); |
|
| 80 | 80 | |
| 81 | - } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Rendering the shortcode this class is responsible for. |
|
| 85 | - * |
|
| 86 | - * @return string $content |
|
| 87 | - */ |
|
| 88 | - public function render(){ |
|
| 83 | + /** |
|
| 84 | + * Rendering the shortcode this class is responsible for. |
|
| 85 | + * |
|
| 86 | + * @return string $content |
|
| 87 | + */ |
|
| 88 | + public function render(){ |
|
| 89 | 89 | |
| 90 | - if( empty( $this->sensei_course_taxonomy_terms ) ){ |
|
| 90 | + if( empty( $this->sensei_course_taxonomy_terms ) ){ |
|
| 91 | 91 | |
| 92 | - return __( 'No course categories found.', 'woothemes-sensei' ); |
|
| 92 | + return __( 'No course categories found.', 'woothemes-sensei' ); |
|
| 93 | 93 | |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - $terms_html = ''; |
|
| 96 | + $terms_html = ''; |
|
| 97 | 97 | |
| 98 | - //set the wp_query to the current messages query |
|
| 99 | - $terms_html .= '<ul class="sensei course-categories">'; |
|
| 100 | - foreach( $this->sensei_course_taxonomy_terms as $category ){ |
|
| 98 | + //set the wp_query to the current messages query |
|
| 99 | + $terms_html .= '<ul class="sensei course-categories">'; |
|
| 100 | + foreach( $this->sensei_course_taxonomy_terms as $category ){ |
|
| 101 | 101 | |
| 102 | - $category_link = '<a href="'. get_term_link( $category ) . '">' . $category->name . '</a>'; |
|
| 103 | - $terms_html .= '<li class="sensei course-category" >' . $category_link . '</li>'; |
|
| 102 | + $category_link = '<a href="'. get_term_link( $category ) . '">' . $category->name . '</a>'; |
|
| 103 | + $terms_html .= '<li class="sensei course-category" >' . $category_link . '</li>'; |
|
| 104 | 104 | |
| 105 | - } |
|
| 106 | - $terms_html .= '<ul>'; |
|
| 105 | + } |
|
| 106 | + $terms_html .= '<ul>'; |
|
| 107 | 107 | |
| 108 | - return $terms_html; |
|
| 108 | + return $terms_html; |
|
| 109 | 109 | |
| 110 | - }// end render |
|
| 110 | + }// end render |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Convert an array of mixed ids, slugs or names to only the id's of those terms |
|
| 114 | - * |
|
| 115 | - * @since 1.9.0 |
|
| 116 | - * |
|
| 117 | - * @param array $category_ids |
|
| 118 | - * @return array |
|
| 119 | - */ |
|
| 120 | - public function generate_term_ids( $categories = array() ){ |
|
| 112 | + /** |
|
| 113 | + * Convert an array of mixed ids, slugs or names to only the id's of those terms |
|
| 114 | + * |
|
| 115 | + * @since 1.9.0 |
|
| 116 | + * |
|
| 117 | + * @param array $category_ids |
|
| 118 | + * @return array |
|
| 119 | + */ |
|
| 120 | + public function generate_term_ids( $categories = array() ){ |
|
| 121 | 121 | |
| 122 | - $cat_ids = array(); |
|
| 122 | + $cat_ids = array(); |
|
| 123 | 123 | |
| 124 | - if ( is_array($categories) ) { |
|
| 125 | - foreach ($categories as $cat) { |
|
| 124 | + if ( is_array($categories) ) { |
|
| 125 | + foreach ($categories as $cat) { |
|
| 126 | 126 | |
| 127 | - if (!is_numeric($cat)) { |
|
| 127 | + if (!is_numeric($cat)) { |
|
| 128 | 128 | |
| 129 | - // try the slug |
|
| 130 | - $term = get_term_by('slug', $cat, 'course-category'); |
|
| 129 | + // try the slug |
|
| 130 | + $term = get_term_by('slug', $cat, 'course-category'); |
|
| 131 | 131 | |
| 132 | - // if the slug didn't work try the name |
|
| 133 | - if (!$term) { |
|
| 132 | + // if the slug didn't work try the name |
|
| 133 | + if (!$term) { |
|
| 134 | 134 | |
| 135 | - $term = get_term_by('name', $cat, 'course-category'); |
|
| 135 | + $term = get_term_by('name', $cat, 'course-category'); |
|
| 136 | 136 | |
| 137 | - } |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if ($term) { |
|
| 140 | - $cat_ids[] = $term->term_id; |
|
| 141 | - } |
|
| 139 | + if ($term) { |
|
| 140 | + $cat_ids[] = $term->term_id; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - } else { |
|
| 143 | + } else { |
|
| 144 | 144 | |
| 145 | - $cat_ids[] = $cat; |
|
| 145 | + $cat_ids[] = $cat; |
|
| 146 | 146 | |
| 147 | - } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return $cat_ids; |
|
| 153 | + return $cat_ids; |
|
| 154 | 154 | |
| 155 | - }// end generate_term_ids |
|
| 155 | + }// end generate_term_ids |
|
| 156 | 156 | |
| 157 | 157 | }// end class |
| 158 | 158 | |
@@ -325,7 +325,7 @@ |
||
| 325 | 325 | * |
| 326 | 326 | * @param array $classes |
| 327 | 327 | * @param WP_Post $course |
| 328 | - * @return array $classes |
|
| 328 | + * @return string[] $classes |
|
| 329 | 329 | */ |
| 330 | 330 | public function course_status_class_tagging($classes, $course){ |
| 331 | 331 | |
@@ -25,167 +25,167 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | class Sensei_Shortcode_User_Courses implements Sensei_Shortcode_Interface { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var WP_Query to help setup the query needed by the render method. |
|
| 30 | - */ |
|
| 31 | - protected $query; |
|
| 28 | + /** |
|
| 29 | + * @var WP_Query to help setup the query needed by the render method. |
|
| 30 | + */ |
|
| 31 | + protected $query; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var string number of items to show on the current page |
|
| 35 | - * Default: -1. |
|
| 36 | - */ |
|
| 37 | - protected $number; |
|
| 33 | + /** |
|
| 34 | + * @var string number of items to show on the current page |
|
| 35 | + * Default: -1. |
|
| 36 | + */ |
|
| 37 | + protected $number; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var string ordery by course field |
|
| 41 | - * Default: date |
|
| 42 | - */ |
|
| 43 | - protected $orderby; |
|
| 39 | + /** |
|
| 40 | + * @var string ordery by course field |
|
| 41 | + * Default: date |
|
| 42 | + */ |
|
| 43 | + protected $orderby; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string ASC or DESC |
|
| 47 | - * Default: 'DESC' |
|
| 48 | - */ |
|
| 49 | - protected $order; |
|
| 45 | + /** |
|
| 46 | + * @var string ASC or DESC |
|
| 47 | + * Default: 'DESC' |
|
| 48 | + */ |
|
| 49 | + protected $order; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var status can be completed or active. If none is specified all will be shown |
|
| 53 | - */ |
|
| 54 | - protected $status; |
|
| 51 | + /** |
|
| 52 | + * @var status can be completed or active. If none is specified all will be shown |
|
| 53 | + */ |
|
| 54 | + protected $status; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Setup the shortcode object |
|
| 58 | - * |
|
| 59 | - * @since 1.9.0 |
|
| 60 | - * @param array $attributes |
|
| 61 | - * @param string $content |
|
| 62 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 63 | - */ |
|
| 64 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 56 | + /** |
|
| 57 | + * Setup the shortcode object |
|
| 58 | + * |
|
| 59 | + * @since 1.9.0 |
|
| 60 | + * @param array $attributes |
|
| 61 | + * @param string $content |
|
| 62 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 63 | + */ |
|
| 64 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 65 | 65 | |
| 66 | - if(! is_user_logged_in() ) { |
|
| 67 | - // show the login form |
|
| 68 | - Sensei()->frontend->sensei_login_form(); |
|
| 69 | - return; |
|
| 70 | - } |
|
| 66 | + if(! is_user_logged_in() ) { |
|
| 67 | + // show the login form |
|
| 68 | + Sensei()->frontend->sensei_login_form(); |
|
| 69 | + return; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - // set up all argument need for constructing the course query |
|
| 73 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 74 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 75 | - $this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all'; |
|
| 72 | + // set up all argument need for constructing the course query |
|
| 73 | + $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 74 | + $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 75 | + $this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all'; |
|
| 76 | 76 | |
| 77 | - // set the default for menu_order to be ASC |
|
| 78 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 77 | + // set the default for menu_order to be ASC |
|
| 78 | + if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 79 | 79 | |
| 80 | - $this->order = 'ASC'; |
|
| 80 | + $this->order = 'ASC'; |
|
| 81 | 81 | |
| 82 | - }else{ |
|
| 82 | + }else{ |
|
| 83 | 83 | |
| 84 | - // for everything else use the value passed or the default DESC |
|
| 85 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; |
|
| 84 | + // for everything else use the value passed or the default DESC |
|
| 85 | + $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; |
|
| 86 | 86 | |
| 87 | - } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - // setup the course query that will be used when rendering |
|
| 90 | - $this->setup_course_query(); |
|
| 91 | - } |
|
| 89 | + // setup the course query that will be used when rendering |
|
| 90 | + $this->setup_course_query(); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Sets up the object course query |
|
| 95 | - * that will be used in the render method. |
|
| 96 | - * |
|
| 97 | - * @since 1.9.0 |
|
| 98 | - */ |
|
| 99 | - protected function setup_course_query(){ |
|
| 93 | + /** |
|
| 94 | + * Sets up the object course query |
|
| 95 | + * that will be used in the render method. |
|
| 96 | + * |
|
| 97 | + * @since 1.9.0 |
|
| 98 | + */ |
|
| 99 | + protected function setup_course_query(){ |
|
| 100 | 100 | |
| 101 | - $status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' ); |
|
| 102 | - $user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true ); |
|
| 103 | - if ( !is_array($user_courses_logs) ) { |
|
| 101 | + $status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' ); |
|
| 102 | + $user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true ); |
|
| 103 | + if ( !is_array($user_courses_logs) ) { |
|
| 104 | 104 | |
| 105 | - $user_courses_logs = array( $user_courses_logs ); |
|
| 105 | + $user_courses_logs = array( $user_courses_logs ); |
|
| 106 | 106 | |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - $completed_ids = $active_ids = array(); |
|
| 110 | - foreach( $user_courses_logs as $course_status ) { |
|
| 109 | + $completed_ids = $active_ids = array(); |
|
| 110 | + foreach( $user_courses_logs as $course_status ) { |
|
| 111 | 111 | |
| 112 | - if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) { |
|
| 112 | + if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) { |
|
| 113 | 113 | |
| 114 | - $completed_ids[] = $course_status->comment_post_ID; |
|
| 114 | + $completed_ids[] = $course_status->comment_post_ID; |
|
| 115 | 115 | |
| 116 | - } else { |
|
| 116 | + } else { |
|
| 117 | 117 | |
| 118 | - $active_ids[] = $course_status->comment_post_ID; |
|
| 118 | + $active_ids[] = $course_status->comment_post_ID; |
|
| 119 | 119 | |
| 120 | - } |
|
| 121 | - } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - if( 'completed' == $this->status ){ |
|
| 123 | + if( 'completed' == $this->status ){ |
|
| 124 | 124 | |
| 125 | - $included_courses = $completed_ids; |
|
| 125 | + $included_courses = $completed_ids; |
|
| 126 | 126 | |
| 127 | 127 | |
| 128 | - }elseif( 'active'==$this->status ){ |
|
| 128 | + }elseif( 'active'==$this->status ){ |
|
| 129 | 129 | |
| 130 | - $included_courses = $active_ids; |
|
| 130 | + $included_courses = $active_ids; |
|
| 131 | 131 | |
| 132 | - }else{ // all courses |
|
| 132 | + }else{ // all courses |
|
| 133 | 133 | |
| 134 | - if( empty( $completed_ids ) ){ |
|
| 134 | + if( empty( $completed_ids ) ){ |
|
| 135 | 135 | |
| 136 | - add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) ); |
|
| 137 | - } |
|
| 136 | + add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) ); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if( empty( $active_ids ) ){ |
|
| 139 | + if( empty( $active_ids ) ){ |
|
| 140 | 140 | |
| 141 | - add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) ); |
|
| 141 | + add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) ); |
|
| 142 | 142 | |
| 143 | - } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - if( empty( $completed_ids ) && empty( $active_ids ) ){ |
|
| 145 | + if( empty( $completed_ids ) && empty( $active_ids ) ){ |
|
| 146 | 146 | |
| 147 | - $included_courses = array('-1000'); // don't show any courses |
|
| 147 | + $included_courses = array('-1000'); // don't show any courses |
|
| 148 | 148 | |
| 149 | - }else{ |
|
| 150 | - $included_courses = Sensei_Utils::array_zip_merge( (array)$active_ids, (array)$completed_ids ); |
|
| 151 | - } |
|
| 149 | + }else{ |
|
| 150 | + $included_courses = Sensei_Utils::array_zip_merge( (array)$active_ids, (array)$completed_ids ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + // temporary work around to hide pagination on the courses page |
|
| 157 | + // this is in place until we can load the course for each tab via ajax |
|
| 158 | + // if the shortcode is not active or in active and the active and completed |
|
| 159 | + // tabs show up. |
|
| 160 | + $number_of_posts = $this->number; |
|
| 161 | + if( 'active' != $this->status && 'complete' != $this->status ){ |
|
| 162 | + $number_of_posts = 1000; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // course query parameters |
|
| 166 | + $query_var_paged = get_query_var('paged'); |
|
| 167 | + $query_args = array( |
|
| 168 | + 'post_type' => 'course', |
|
| 169 | + 'post_status' => 'publish', |
|
| 170 | + 'orderby' => $this->orderby, |
|
| 171 | + 'order' => $this->order, |
|
| 172 | + 'paged' => empty( $query_var_paged )? 1 : $query_var_paged, |
|
| 173 | + 'posts_per_page' => $number_of_posts, |
|
| 174 | + 'post__in' => $included_courses, |
|
| 175 | + ); |
|
| 176 | + |
|
| 177 | + $this->query = new WP_Query( $query_args ); |
|
| 152 | 178 | |
| 179 | + }// end setup _course_query |
|
| 153 | 180 | |
| 154 | - } |
|
| 155 | - |
|
| 156 | - // temporary work around to hide pagination on the courses page |
|
| 157 | - // this is in place until we can load the course for each tab via ajax |
|
| 158 | - // if the shortcode is not active or in active and the active and completed |
|
| 159 | - // tabs show up. |
|
| 160 | - $number_of_posts = $this->number; |
|
| 161 | - if( 'active' != $this->status && 'complete' != $this->status ){ |
|
| 162 | - $number_of_posts = 1000; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // course query parameters |
|
| 166 | - $query_var_paged = get_query_var('paged'); |
|
| 167 | - $query_args = array( |
|
| 168 | - 'post_type' => 'course', |
|
| 169 | - 'post_status' => 'publish', |
|
| 170 | - 'orderby' => $this->orderby, |
|
| 171 | - 'order' => $this->order, |
|
| 172 | - 'paged' => empty( $query_var_paged )? 1 : $query_var_paged, |
|
| 173 | - 'posts_per_page' => $number_of_posts, |
|
| 174 | - 'post__in' => $included_courses, |
|
| 175 | - ); |
|
| 176 | - |
|
| 177 | - $this->query = new WP_Query( $query_args ); |
|
| 178 | - |
|
| 179 | - }// end setup _course_query |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Output the message that tells the user they have |
|
| 183 | - * no completed courses. |
|
| 184 | - * |
|
| 185 | - * @since 1.9.0 |
|
| 186 | - */ |
|
| 187 | - public function completed_no_course_message_output(){ |
|
| 188 | - ?> |
|
| 181 | + /** |
|
| 182 | + * Output the message that tells the user they have |
|
| 183 | + * no completed courses. |
|
| 184 | + * |
|
| 185 | + * @since 1.9.0 |
|
| 186 | + */ |
|
| 187 | + public function completed_no_course_message_output(){ |
|
| 188 | + ?> |
|
| 189 | 189 | <li class="user-completed"> |
| 190 | 190 | <div class="sensei-message info"> |
| 191 | 191 | |
@@ -194,16 +194,16 @@ discard block |
||
| 194 | 194 | </div> |
| 195 | 195 | </li> |
| 196 | 196 | <?php |
| 197 | - } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * Output the message that tells the user they have |
|
| 201 | - * no active courses. |
|
| 202 | - * |
|
| 203 | - * @since 1.9.0 |
|
| 204 | - */ |
|
| 205 | - public function active_no_course_message_output(){ |
|
| 206 | - ?> |
|
| 199 | + /** |
|
| 200 | + * Output the message that tells the user they have |
|
| 201 | + * no active courses. |
|
| 202 | + * |
|
| 203 | + * @since 1.9.0 |
|
| 204 | + */ |
|
| 205 | + public function active_no_course_message_output(){ |
|
| 206 | + ?> |
|
| 207 | 207 | |
| 208 | 208 | <li class="user-active"> |
| 209 | 209 | <div class="sensei-message info"> |
@@ -219,141 +219,141 @@ discard block |
||
| 219 | 219 | </div> |
| 220 | 220 | </li> |
| 221 | 221 | <?php |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * Rendering the shortcode this class is responsible for. |
|
| 226 | - * |
|
| 227 | - * @return string $content |
|
| 228 | - */ |
|
| 229 | - public function render(){ |
|
| 224 | + /** |
|
| 225 | + * Rendering the shortcode this class is responsible for. |
|
| 226 | + * |
|
| 227 | + * @return string $content |
|
| 228 | + */ |
|
| 229 | + public function render(){ |
|
| 230 | 230 | |
| 231 | - global $wp_query; |
|
| 231 | + global $wp_query; |
|
| 232 | 232 | |
| 233 | - if(! is_user_logged_in() ) { |
|
| 234 | - return ''; |
|
| 235 | - } |
|
| 233 | + if(! is_user_logged_in() ) { |
|
| 234 | + return ''; |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - // keep a reference to old query |
|
| 238 | - $current_global_query = $wp_query; |
|
| 237 | + // keep a reference to old query |
|
| 238 | + $current_global_query = $wp_query; |
|
| 239 | 239 | |
| 240 | - // assign the query setup in $this-> setup_course_query |
|
| 241 | - $wp_query = $this->query; |
|
| 240 | + // assign the query setup in $this-> setup_course_query |
|
| 241 | + $wp_query = $this->query; |
|
| 242 | 242 | |
| 243 | - $this->attach_shortcode_hooks(); |
|
| 243 | + $this->attach_shortcode_hooks(); |
|
| 244 | 244 | |
| 245 | - ob_start(); |
|
| 246 | - echo '<section id="sensei-user-courses">'; |
|
| 247 | - Sensei_Messages::the_my_messages_link(); |
|
| 248 | - Sensei_Templates::get_template('loop-course.php'); |
|
| 249 | - Sensei_Templates::get_template('globals/pagination.php'); |
|
| 250 | - echo '</section>'; |
|
| 245 | + ob_start(); |
|
| 246 | + echo '<section id="sensei-user-courses">'; |
|
| 247 | + Sensei_Messages::the_my_messages_link(); |
|
| 248 | + Sensei_Templates::get_template('loop-course.php'); |
|
| 249 | + Sensei_Templates::get_template('globals/pagination.php'); |
|
| 250 | + echo '</section>'; |
|
| 251 | 251 | |
| 252 | - $shortcode_output = ob_get_clean(); |
|
| 252 | + $shortcode_output = ob_get_clean(); |
|
| 253 | 253 | |
| 254 | - $this->detach_shortcode_hooks(); |
|
| 254 | + $this->detach_shortcode_hooks(); |
|
| 255 | 255 | |
| 256 | - //restore old query |
|
| 257 | - $wp_query = $current_global_query; |
|
| 256 | + //restore old query |
|
| 257 | + $wp_query = $current_global_query; |
|
| 258 | 258 | |
| 259 | - return $shortcode_output; |
|
| 259 | + return $shortcode_output; |
|
| 260 | 260 | |
| 261 | - }// end render |
|
| 261 | + }// end render |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Add hooks for the shortcode |
|
| 265 | - * |
|
| 266 | - * @since 1.9.0 |
|
| 267 | - */ |
|
| 268 | - public function attach_shortcode_hooks(){ |
|
| 263 | + /** |
|
| 264 | + * Add hooks for the shortcode |
|
| 265 | + * |
|
| 266 | + * @since 1.9.0 |
|
| 267 | + */ |
|
| 268 | + public function attach_shortcode_hooks(){ |
|
| 269 | 269 | |
| 270 | - // attach the toggle functionality |
|
| 271 | - // don't show the toggle action if the user specified complete or active for this shortcode |
|
| 272 | - if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){ |
|
| 270 | + // attach the toggle functionality |
|
| 271 | + // don't show the toggle action if the user specified complete or active for this shortcode |
|
| 272 | + if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){ |
|
| 273 | 273 | |
| 274 | - add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 275 | - add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 ); |
|
| 274 | + add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 275 | + add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 ); |
|
| 276 | 276 | |
| 277 | - } |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - // add extra classes to distinguish the course based on user completed or active |
|
| 280 | - add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 279 | + // add extra classes to distinguish the course based on user completed or active |
|
| 280 | + add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 281 | 281 | |
| 282 | - // attach progress meter below course |
|
| 283 | - add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 284 | - add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 282 | + // attach progress meter below course |
|
| 283 | + add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 284 | + add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 285 | 285 | |
| 286 | - } |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - /** |
|
| 289 | - * Remove hooks for the shortcode |
|
| 290 | - * |
|
| 291 | - * @since 1.9.0 |
|
| 292 | - */ |
|
| 293 | - public function detach_shortcode_hooks(){ |
|
| 288 | + /** |
|
| 289 | + * Remove hooks for the shortcode |
|
| 290 | + * |
|
| 291 | + * @since 1.9.0 |
|
| 292 | + */ |
|
| 293 | + public function detach_shortcode_hooks(){ |
|
| 294 | 294 | |
| 295 | - //remove all hooks after the output is generated |
|
| 296 | - remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 297 | - remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 298 | - remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 299 | - remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 300 | - } |
|
| 295 | + //remove all hooks after the output is generated |
|
| 296 | + remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 297 | + remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 298 | + remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 299 | + remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Hooks into sensei_course_content_inside_after |
|
| 304 | - * |
|
| 305 | - * @param $course |
|
| 306 | - */ |
|
| 307 | - public function attach_course_progress( $course_id ){ |
|
| 302 | + /** |
|
| 303 | + * Hooks into sensei_course_content_inside_after |
|
| 304 | + * |
|
| 305 | + * @param $course |
|
| 306 | + */ |
|
| 307 | + public function attach_course_progress( $course_id ){ |
|
| 308 | 308 | |
| 309 | - $percentage = Sensei()->course->get_completion_percentage( $course_id, get_current_user_id() ); |
|
| 310 | - echo Sensei()->course->get_progress_meter( $percentage ); |
|
| 309 | + $percentage = Sensei()->course->get_completion_percentage( $course_id, get_current_user_id() ); |
|
| 310 | + echo Sensei()->course->get_progress_meter( $percentage ); |
|
| 311 | 311 | |
| 312 | - }// attach_course_progress |
|
| 312 | + }// attach_course_progress |
|
| 313 | 313 | |
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * Hooked into sensei_course_content_inside_after |
|
| 317 | - * |
|
| 318 | - * Prints out the course action buttons |
|
| 319 | - * |
|
| 320 | - * @param integer $course_id |
|
| 321 | - */ |
|
| 322 | - public function attach_course_buttons( $course_id ){ |
|
| 315 | + /** |
|
| 316 | + * Hooked into sensei_course_content_inside_after |
|
| 317 | + * |
|
| 318 | + * Prints out the course action buttons |
|
| 319 | + * |
|
| 320 | + * @param integer $course_id |
|
| 321 | + */ |
|
| 322 | + public function attach_course_buttons( $course_id ){ |
|
| 323 | 323 | |
| 324 | - Sensei()->course->the_course_action_buttons( get_post( $course_id ) ); |
|
| 324 | + Sensei()->course->the_course_action_buttons( get_post( $course_id ) ); |
|
| 325 | 325 | |
| 326 | - }// attach_course_buttons |
|
| 326 | + }// attach_course_buttons |
|
| 327 | 327 | |
| 328 | - /** |
|
| 329 | - * Add a the user status class for the given course. |
|
| 330 | - * |
|
| 331 | - * @since 1.9 |
|
| 332 | - * |
|
| 333 | - * @param array $classes |
|
| 334 | - * @param WP_Post $course |
|
| 335 | - * @return array $classes |
|
| 336 | - */ |
|
| 337 | - public function course_status_class_tagging($classes, $course){ |
|
| 328 | + /** |
|
| 329 | + * Add a the user status class for the given course. |
|
| 330 | + * |
|
| 331 | + * @since 1.9 |
|
| 332 | + * |
|
| 333 | + * @param array $classes |
|
| 334 | + * @param WP_Post $course |
|
| 335 | + * @return array $classes |
|
| 336 | + */ |
|
| 337 | + public function course_status_class_tagging($classes, $course){ |
|
| 338 | 338 | |
| 339 | - if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) { |
|
| 339 | + if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) { |
|
| 340 | 340 | |
| 341 | - $classes[] = 'user-completed'; |
|
| 341 | + $classes[] = 'user-completed'; |
|
| 342 | 342 | |
| 343 | - } else { |
|
| 343 | + } else { |
|
| 344 | 344 | |
| 345 | - $classes[] = 'user-active'; |
|
| 345 | + $classes[] = 'user-active'; |
|
| 346 | 346 | |
| 347 | - } |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | - return $classes; |
|
| 349 | + return $classes; |
|
| 350 | 350 | |
| 351 | - }// end course_status_class_tagging |
|
| 351 | + }// end course_status_class_tagging |
|
| 352 | 352 | |
| 353 | - /** |
|
| 354 | - * Output the course toggle functionality |
|
| 355 | - */ |
|
| 356 | - public function course_toggle_actions(){ ?> |
|
| 353 | + /** |
|
| 354 | + * Output the course toggle functionality |
|
| 355 | + */ |
|
| 356 | + public function course_toggle_actions(){ ?> |
|
| 357 | 357 | |
| 358 | 358 | <section id="user-course-status-toggle"> |
| 359 | 359 | <a id="sensei-user-courses-active-action" href=""><?php _e('Active Courses'); ?></a> |
@@ -363,12 +363,12 @@ discard block |
||
| 363 | 363 | |
| 364 | 364 | <?php } |
| 365 | 365 | |
| 366 | - /** |
|
| 367 | - * Load the javascript for the toggle functionality |
|
| 368 | - * |
|
| 369 | - * @since 1.9.0 |
|
| 370 | - */ |
|
| 371 | - function print_course_toggle_actions_inline_script() { ?> |
|
| 366 | + /** |
|
| 367 | + * Load the javascript for the toggle functionality |
|
| 368 | + * |
|
| 369 | + * @since 1.9.0 |
|
| 370 | + */ |
|
| 371 | + function print_course_toggle_actions_inline_script() { ?> |
|
| 372 | 372 | |
| 373 | 373 | <script type="text/javascript"> |
| 374 | 374 | var buttonContainer = jQuery('#user-course-status-toggle'); |