| @@ -10,6 +10,9 @@ | ||
| 10 | 10 | private static $found_files = array(); | 
| 11 | 11 | private static $custom_hooks_found = ''; | 
| 12 | 12 | |
| 13 | + /** | |
| 14 | + * @param string $pattern | |
| 15 | + */ | |
| 13 | 16 |  	private static function get_files( $pattern, $flags = 0, $path = '' ) { | 
| 14 | 17 | |
| 15 | 18 |  	    if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) { | 
| @@ -1,7 +1,7 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | 2 | /** | 
| 3 | - * Generate documentation for hooks in WC | |
| 4 | - */ | |
| 3 | + * Generate documentation for hooks in WC | |
| 4 | + */ | |
| 5 | 5 |  class WC_HookFinder { | 
| 6 | 6 | private static $current_file = ''; | 
| 7 | 7 | private static $files_to_scan = array(); | 
| @@ -12,20 +12,20 @@ discard block | ||
| 12 | 12 | |
| 13 | 13 |  	private static function get_files( $pattern, $flags = 0, $path = '' ) { | 
| 14 | 14 | |
| 15 | -	    if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) { | |
| 15 | +		if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) { | |
| 16 | 16 | |
| 17 | -	        if ($dir == '\\' || $dir == '/') { $dir = ''; } // End IF Statement | |
| 17 | +			if ($dir == '\\' || $dir == '/') { $dir = ''; } // End IF Statement | |
| 18 | 18 | |
| 19 | - return self::get_files(basename( $pattern ), $flags, $dir . '/' ); | |
| 19 | + return self::get_files(basename( $pattern ), $flags, $dir . '/' ); | |
| 20 | 20 | |
| 21 | - } // End IF Statement | |
| 21 | + } // End IF Statement | |
| 22 | 22 | |
| 23 | - $paths = glob( $path . '*', GLOB_ONLYDIR | GLOB_NOSORT ); | |
| 24 | - $files = glob( $path . $pattern, $flags ); | |
| 23 | + $paths = glob( $path . '*', GLOB_ONLYDIR | GLOB_NOSORT ); | |
| 24 | + $files = glob( $path . $pattern, $flags ); | |
| 25 | 25 | |
| 26 | -	    if ( is_array( $paths ) ) { | |
| 27 | -		    foreach ( $paths as $p ) { | |
| 28 | - $found_files = array(); | |
| 26 | +		if ( is_array( $paths ) ) { | |
| 27 | +			foreach ( $paths as $p ) { | |
| 28 | + $found_files = array(); | |
| 29 | 29 | $retrieved_files = (array) self::get_files( $pattern, $flags, $p . '/' ); | 
| 30 | 30 |  		   		foreach ( $retrieved_files as $file ) { | 
| 31 | 31 | if ( ! in_array( $file, self::$found_files ) ) | 
| @@ -38,10 +38,10 @@ discard block | ||
| 38 | 38 | $files = array_merge( $files, $found_files ); | 
| 39 | 39 | } | 
| 40 | 40 | |
| 41 | - } // End FOREACH Loop | |
| 42 | - } | |
| 43 | - return $files; | |
| 44 | - } | |
| 41 | + } // End FOREACH Loop | |
| 42 | + } | |
| 43 | + return $files; | |
| 44 | + } | |
| 45 | 45 | |
| 46 | 46 |  	private static function get_hook_link( $hook, $details = array() ) { | 
| 47 | 47 |  		if ( ! empty( $details['class'] ) ) { | 
| @@ -126,7 +126,7 @@ discard block | ||
| 126 | 126 |  									if ( isset( self::$custom_hooks_found[ $hook ] ) ) { | 
| 127 | 127 | self::$custom_hooks_found[ $hook ]['file'][] = self::$current_file; | 
| 128 | 128 |  									} else { | 
| 129 | - self::$custom_hooks_found[ $hook ] = array( | |
| 129 | + self::$custom_hooks_found[ $hook ] = array( | |
| 130 | 130 | 'line' => $token[2], | 
| 131 | 131 | 'class' => $current_class, | 
| 132 | 132 | 'function' => $current_function, | 
| @@ -21,6 +21,7 @@ discard block | ||
| 21 | 21 | /** | 
| 22 | 22 | * Constructor | 
| 23 | 23 | * @since 1.0.0 | 
| 24 | + * @param string $file | |
| 24 | 25 | * @return void | 
| 25 | 26 | */ | 
| 26 | 27 |  	public function __construct ( $file ) { | 
| @@ -215,6 +216,7 @@ discard block | ||
| 215 | 216 | /** | 
| 216 | 217 | * An individual users' profile view for analysis, showing their Courses | 
| 217 | 218 | * @since 1.2.0 | 
| 219 | + * @param integer $user_id | |
| 218 | 220 | * @return void | 
| 219 | 221 | */ | 
| 220 | 222 |  	public function analysis_user_profile_view( $user_id ) { | 
| @@ -242,6 +244,7 @@ discard block | ||
| 242 | 244 | /** | 
| 243 | 245 | * An individual Course view for analysis, showing the Courses Lessons | 
| 244 | 246 | * @since 1.2.0 | 
| 247 | + * @param integer $course_id | |
| 245 | 248 | * @return void | 
| 246 | 249 | */ | 
| 247 | 250 |  	public function analysis_course_view( $course_id ) { | 
| @@ -269,6 +272,8 @@ discard block | ||
| 269 | 272 | /** | 
| 270 | 273 | * An individual Course view for analysis, showing a specific Learners Lessons | 
| 271 | 274 | * @since 1.2.0 | 
| 275 | + * @param integer $course_id | |
| 276 | + * @param integer $user_id | |
| 272 | 277 | * @return void | 
| 273 | 278 | */ | 
| 274 | 279 |  	public function analysis_user_course_view( $course_id, $user_id ) { | 
| @@ -296,6 +301,7 @@ discard block | ||
| 296 | 301 | /** | 
| 297 | 302 | * An individual Course view for analysis, showing all the Learners | 
| 298 | 303 | * @since 1.2.0 | 
| 304 | + * @param integer $course_id | |
| 299 | 305 | * @return void | 
| 300 | 306 | */ | 
| 301 | 307 |  	public function analysis_course_users_view( $course_id ) { | 
| @@ -323,6 +329,7 @@ discard block | ||
| 323 | 329 | /** | 
| 324 | 330 | * An individual Lesson view for analysis, showing all the Learners | 
| 325 | 331 | * @since 1.2.0 | 
| 332 | + * @param integer $lesson_id | |
| 326 | 333 | * @return void | 
| 327 | 334 | */ | 
| 328 | 335 |  	public function analysis_lesson_users_view( $lesson_id ) { | 
| @@ -633,7 +640,7 @@ discard block | ||
| 633 | 640 | /** | 
| 634 | 641 | * Write array data to CSV | 
| 635 | 642 | * @since 1.2.0 | 
| 636 | - * @param array $report_array data array | |
| 643 | + * @param array $report_data data array | |
| 637 | 644 | * @return void | 
| 638 | 645 | */ | 
| 639 | 646 |  	public function report_write_download( $report_data = array() ) { | 
| @@ -55,7 +55,7 @@ discard block | ||
| 55 | 55 | |
| 56 | 56 |  		if ( current_user_can( 'manage_sensei_grades' ) ) { | 
| 57 | 57 | |
| 58 | -            add_submenu_page( 'sensei', __('Analysis', 'woothemes-sensei'),  __('Analysis', 'woothemes-sensei') , 'manage_sensei_grades', 'sensei_analysis', array( $this, 'analysis_page' ) ); | |
| 58 | +			add_submenu_page( 'sensei', __('Analysis', 'woothemes-sensei'),  __('Analysis', 'woothemes-sensei') , 'manage_sensei_grades', 'sensei_analysis', array( $this, 'analysis_page' ) ); | |
| 59 | 59 | |
| 60 | 60 | } | 
| 61 | 61 | |
| @@ -105,7 +105,7 @@ discard block | ||
| 105 | 105 | 'analysis-lesson' | 
| 106 | 106 | ); | 
| 107 | 107 |  		foreach ( $classes_to_load as $class_file ) { | 
| 108 | - Sensei()->load_class( $class_file ); | |
| 108 | + Sensei()->load_class( $class_file ); | |
| 109 | 109 | } // End For Loop | 
| 110 | 110 | } // End load_data_table_files() | 
| 111 | 111 | |
| @@ -443,7 +443,7 @@ discard block | ||
| 443 | 443 | |
| 444 | 444 | $user_id = intval( $_GET['user_id'] ); | 
| 445 | 445 | $url = esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user' => $user_id ), admin_url( 'admin.php' ) ) ); | 
| 446 | - $user_name = Sensei_Student::get_full_name( $user_id ); | |
| 446 | + $user_name = Sensei_Student::get_full_name( $user_id ); | |
| 447 | 447 | $title .= sprintf( '  <span class="user-title">>  <a href="%s">%s</a></span>', $url, $user_name ); | 
| 448 | 448 | |
| 449 | 449 | } // End If Statement | 
| @@ -464,8 +464,8 @@ discard block | ||
| 464 | 464 | $user_id = intval( $_GET['user_id'] ); | 
| 465 | 465 | $user_data = get_userdata( $user_id ); | 
| 466 | 466 | $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $user_id ), admin_url( 'admin.php' ) ); | 
| 467 | - $user_name = Sensei_Student::get_full_name( $user_id ); | |
| 468 | - $title .= sprintf( '  <span class="user-title">>  <a href="%s">%s</a></span>', $url, $user_name ); | |
| 467 | + $user_name = Sensei_Student::get_full_name( $user_id ); | |
| 468 | + $title .= sprintf( '  <span class="user-title">>  <a href="%s">%s</a></span>', $url, $user_name ); | |
| 469 | 469 | $title .= sprintf( '  <span class="user-title">>  <a href="%s">%s</a></span>', esc_url( $url ), $user_data->display_name ); | 
| 470 | 470 | } // End If Statement | 
| 471 | 471 |  		if ( isset( $_GET['course_id'] ) ) {  | 
| @@ -40,6 +40,7 @@ discard block | ||
| 40 | 40 | * Constructor for the email class hooks in all emails that can be sent. | 
| 41 | 41 | * | 
| 42 | 42 | * @access public | 
| 43 | + * @param string $file | |
| 43 | 44 | * @return void | 
| 44 | 45 | */ | 
| 45 | 46 |  	function __construct( $file ) { | 
| @@ -140,7 +141,7 @@ discard block | ||
| 140 | 141 | * Wraps a message in the sensei mail template. | 
| 141 | 142 | * | 
| 142 | 143 | * @access public | 
| 143 | - * @param mixed $content | |
| 144 | + * @param null|string $content | |
| 144 | 145 | * @return string | 
| 145 | 146 | */ | 
| 146 | 147 |  	function wrap_message( $content ) { | 
| @@ -198,6 +199,9 @@ discard block | ||
| 198 | 199 | remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); | 
| 199 | 200 | } | 
| 200 | 201 | |
| 202 | + /** | |
| 203 | + * @param string $email_template | |
| 204 | + */ | |
| 201 | 205 |  	function get_content( $email_template ) { | 
| 202 | 206 | |
| 203 | 207 | $message = $this->load_template( $email_template ); | 
| @@ -51,7 +51,7 @@ discard block | ||
| 51 | 51 | add_action( 'sensei_course_status_updated', array( $this, 'learner_completed_course' ), 10, 4 ); | 
| 52 | 52 | add_action( 'sensei_course_status_updated', array( $this, 'teacher_completed_course' ), 10, 4 ); | 
| 53 | 53 | add_action( 'sensei_user_course_start', array( $this, 'teacher_started_course' ), 10, 2 ); | 
| 54 | - add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 ); | |
| 54 | + add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 ); | |
| 55 | 55 | add_action( 'sensei_user_quiz_submitted', array( $this, 'teacher_quiz_submitted' ), 10, 5 ); | 
| 56 | 56 | add_action( 'sensei_new_private_message', array( $this, 'teacher_new_message' ), 10, 1 ); | 
| 57 | 57 | add_action( 'sensei_private_message_reply', array( $this, 'new_message_reply' ), 10, 2 ); | 
| @@ -68,9 +68,9 @@ discard block | ||
| 68 | 68 | $this->emails['learner-graded-quiz'] = include( 'emails/class-woothemes-sensei-email-learner-graded-quiz.php' ); | 
| 69 | 69 | $this->emails['learner-completed-course'] = include( 'emails/class-woothemes-sensei-email-learner-completed-course.php' ); | 
| 70 | 70 | $this->emails['teacher-completed-course'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-course.php' ); | 
| 71 | - $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' ); | |
| 72 | - $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' ); | |
| 73 | - $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' ); | |
| 71 | + $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' ); | |
| 72 | + $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' ); | |
| 73 | + $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' ); | |
| 74 | 74 | $this->emails['teacher-new-message'] = include( 'emails/class-woothemes-sensei-email-teacher-new-message.php' ); | 
| 75 | 75 | $this->emails['new-message-reply'] = include( 'emails/class-woothemes-sensei-email-new-message-reply.php' ); | 
| 76 | 76 | $this->emails = apply_filters( 'sensei_email_classes', $this->emails ); | 
| @@ -177,20 +177,20 @@ discard block | ||
| 177 | 177 | add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); | 
| 178 | 178 | add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); | 
| 179 | 179 | |
| 180 | - // Send | |
| 181 | - $send_email = true; | |
| 180 | + // Send | |
| 181 | + $send_email = true; | |
| 182 | 182 | |
| 183 | - /** | |
| 184 | - * Filter Sensei's ability to send out emails. | |
| 185 | - * | |
| 186 | - * @since 1.8.0 | |
| 187 | - * @param bool $send_email default true | |
| 188 | - */ | |
| 189 | -        if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message )  ){ | |
| 183 | + /** | |
| 184 | + * Filter Sensei's ability to send out emails. | |
| 185 | + * | |
| 186 | + * @since 1.8.0 | |
| 187 | + * @param bool $send_email default true | |
| 188 | + */ | |
| 189 | +		if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message )  ){ | |
| 190 | 190 | |
| 191 | - wp_mail( $to, $subject, $message, $headers, $attachments ); | |
| 191 | + wp_mail( $to, $subject, $message, $headers, $attachments ); | |
| 192 | 192 | |
| 193 | - } | |
| 193 | + } | |
| 194 | 194 | |
| 195 | 195 | // Unhook filters | 
| 196 | 196 | remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); | 
| @@ -332,33 +332,33 @@ discard block | ||
| 332 | 332 | } | 
| 333 | 333 | } | 
| 334 | 334 | |
| 335 | - /** | |
| 336 | - * teacher_completed_lesson() | |
| 337 | - * | |
| 338 | - * Send email to teacher on student completing lesson | |
| 339 | - * | |
| 340 | - * @access public | |
| 341 | - * @return void | |
| 342 | - * @since 1.9.0 | |
| 343 | - */ | |
| 344 | -    function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) { | |
| 345 | - | |
| 346 | - | |
| 347 | - $send = false; | |
| 348 | - | |
| 349 | -        if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) { | |
| 350 | -            if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) { | |
| 351 | - $send = true; | |
| 352 | - } | |
| 353 | -        } else { | |
| 354 | - $send = true; | |
| 355 | - } | |
| 356 | - | |
| 357 | -        if( $send ) { | |
| 358 | - $email = $this->emails['teacher-completed-lesson']; | |
| 359 | - $email->trigger( $learner_id, $lesson_id ); | |
| 360 | - } | |
| 361 | - } | |
| 335 | + /** | |
| 336 | + * teacher_completed_lesson() | |
| 337 | + * | |
| 338 | + * Send email to teacher on student completing lesson | |
| 339 | + * | |
| 340 | + * @access public | |
| 341 | + * @return void | |
| 342 | + * @since 1.9.0 | |
| 343 | + */ | |
| 344 | +	function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) { | |
| 345 | + | |
| 346 | + | |
| 347 | + $send = false; | |
| 348 | + | |
| 349 | +		if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) { | |
| 350 | +			if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) { | |
| 351 | + $send = true; | |
| 352 | + } | |
| 353 | +		} else { | |
| 354 | + $send = true; | |
| 355 | + } | |
| 356 | + | |
| 357 | +		if( $send ) { | |
| 358 | + $email = $this->emails['teacher-completed-lesson']; | |
| 359 | + $email->trigger( $learner_id, $lesson_id ); | |
| 360 | + } | |
| 361 | + } | |
| 362 | 362 | |
| 363 | 363 | /** | 
| 364 | 364 | * Send email to teacher on quiz submission | 
| @@ -22,7 +22,7 @@ discard block | ||
| 22 | 22 | * Constructor | 
| 23 | 23 | * @since 1.3.0 | 
| 24 | 24 | * | 
| 25 | - * @param $file | |
| 25 | + * @param string $file | |
| 26 | 26 | */ | 
| 27 | 27 |  	public function __construct ( $file ) { | 
| 28 | 28 | $this->name = __( 'Grading', 'woothemes-sensei' ); | 
| @@ -330,6 +330,7 @@ discard block | ||
| 330 | 330 | /** | 
| 331 | 331 | * Return array of valid statuses for either Course or Lesson | 
| 332 | 332 | * @since 1.7.0 | 
| 333 | + * @param string $type | |
| 333 | 334 | * @return array | 
| 334 | 335 | */ | 
| 335 | 336 |  	public function get_stati( $type ) { | 
| @@ -529,7 +530,7 @@ discard block | ||
| 529 | 530 | * the grades as the Grader selected theme and saves the total grade and | 
| 530 | 531 | * individual question grades. | 
| 531 | 532 | * | 
| 532 | - * @return bool | |
| 533 | + * @return false|null | |
| 533 | 534 | */ | 
| 534 | 535 |      public function admin_process_grading_submission() { | 
| 535 | 536 | |
| @@ -906,8 +907,8 @@ discard block | ||
| 906 | 907 | * Grading logic specifically for the gap fill questions | 
| 907 | 908 | * | 
| 908 | 909 | * @since 1.9.0 | 
| 909 | - * @param $question_id | |
| 910 | - * @param $user_answer | |
| 910 | + * @param integer $question_id | |
| 911 | + * @param string $user_answer | |
| 911 | 912 | * | 
| 912 | 913 | * @return bool | int false or the grade given to the user answer | 
| 913 | 914 | */ | 
| @@ -21,8 +21,8 @@ discard block | ||
| 21 | 21 | /** | 
| 22 | 22 | * Constructor | 
| 23 | 23 | * @since 1.3.0 | 
| 24 | - * | |
| 25 | - * @param $file | |
| 24 | + * | |
| 25 | + * @param $file | |
| 26 | 26 | */ | 
| 27 | 27 |  	public function __construct ( $file ) { | 
| 28 | 28 | $this->name = __( 'Grading', 'woothemes-sensei' ); | 
| @@ -284,7 +284,7 @@ discard block | ||
| 284 | 284 | } | 
| 285 | 285 |  		if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) { | 
| 286 | 286 | |
| 287 | - $user_name = Sensei_Student::get_full_name( $_GET['user_id'] ); | |
| 287 | + $user_name = Sensei_Student::get_full_name( $_GET['user_id'] ); | |
| 288 | 288 | $title .= '  <span class="user-title">>  ' . $user_name . '</span>'; | 
| 289 | 289 | |
| 290 | 290 | } // End If Statement | 
| @@ -318,7 +318,7 @@ discard block | ||
| 318 | 318 | } | 
| 319 | 319 |  		if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) { | 
| 320 | 320 | |
| 321 | - $user_name = Sensei_Student::get_full_name( $_GET['user'] ); | |
| 321 | + $user_name = Sensei_Student::get_full_name( $_GET['user'] ); | |
| 322 | 322 | $title .= '  <span class="user-title">>  ' . $user_name . '</span>'; | 
| 323 | 323 | |
| 324 | 324 | } // End If Statement | 
| @@ -367,15 +367,15 @@ discard block | ||
| 367 | 367 |  	public function count_statuses( $args = array() ) { | 
| 368 | 368 | global $wpdb; | 
| 369 | 369 | |
| 370 | - /** | |
| 371 | - * Filter fires inside Sensei_Grading::count_statuses | |
| 372 | - * | |
| 373 | - * Alter the the post_in array to determine which posts the | |
| 374 | - * comment query should be limited to. | |
| 375 | - * @since 1.8.0 | |
| 376 | - * @param array $args | |
| 377 | - */ | |
| 378 | - $args = apply_filters( 'sensei_count_statuses_args', $args ); | |
| 370 | + /** | |
| 371 | + * Filter fires inside Sensei_Grading::count_statuses | |
| 372 | + * | |
| 373 | + * Alter the the post_in array to determine which posts the | |
| 374 | + * comment query should be limited to. | |
| 375 | + * @since 1.8.0 | |
| 376 | + * @param array $args | |
| 377 | + */ | |
| 378 | + $args = apply_filters( 'sensei_count_statuses_args', $args ); | |
| 379 | 379 | |
| 380 | 380 |  		if ( 'course' == $args['type'] ) { | 
| 381 | 381 | $type = 'sensei_course_status'; | 
| @@ -387,7 +387,7 @@ discard block | ||
| 387 | 387 | |
| 388 | 388 |  		$query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s "; | 
| 389 | 389 | |
| 390 | - // Restrict to specific posts | |
| 390 | + // Restrict to specific posts | |
| 391 | 391 |  		if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) { | 
| 392 | 392 |  			$query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')'; | 
| 393 | 393 | } | 
| @@ -522,148 +522,148 @@ discard block | ||
| 522 | 522 | return $html; | 
| 523 | 523 | } // End lessons_drop_down_html() | 
| 524 | 524 | |
| 525 | - /** | |
| 526 | - * The process grading function handles admin grading submissions. | |
| 527 | - * | |
| 528 | - * This function is hooked on to admin_init. It simply accepts | |
| 529 | - * the grades as the Grader selected theme and saves the total grade and | |
| 530 | - * individual question grades. | |
| 531 | - * | |
| 532 | - * @return bool | |
| 533 | - */ | |
| 534 | -    public function admin_process_grading_submission() { | |
| 525 | + /** | |
| 526 | + * The process grading function handles admin grading submissions. | |
| 527 | + * | |
| 528 | + * This function is hooked on to admin_init. It simply accepts | |
| 529 | + * the grades as the Grader selected theme and saves the total grade and | |
| 530 | + * individual question grades. | |
| 531 | + * | |
| 532 | + * @return bool | |
| 533 | + */ | |
| 534 | +	public function admin_process_grading_submission() { | |
| 535 | 535 | |
| 536 | - // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry | |
| 537 | - if( ! isset( $_POST['sensei_manual_grade'] ) | |
| 538 | - || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) | |
| 539 | - || ! isset( $_GET['quiz_id'] ) | |
| 540 | -            || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { | |
| 536 | + // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry | |
| 537 | + if( ! isset( $_POST['sensei_manual_grade'] ) | |
| 538 | + || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' ) | |
| 539 | + || ! isset( $_GET['quiz_id'] ) | |
| 540 | +			|| $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) { | |
| 541 | 541 | |
| 542 | - return false; //exit and do not grade | |
| 542 | + return false; //exit and do not grade | |
| 543 | 543 | |
| 544 | - } | |
| 544 | + } | |
| 545 | 545 | |
| 546 | - $quiz_id = $_GET['quiz_id']; | |
| 547 | - $user_id = $_GET['user']; | |
| 546 | + $quiz_id = $_GET['quiz_id']; | |
| 547 | + $user_id = $_GET['user']; | |
| 548 | 548 | |
| 549 | 549 | |
| 550 | - $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); | |
| 551 | - $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 552 | - $quiz_grade = 0; | |
| 553 | - $count = 0; | |
| 554 | - $quiz_grade_total = $_POST['quiz_grade_total']; | |
| 555 | - $all_question_grades = array(); | |
| 556 | - $all_answers_feedback = array(); | |
| 550 | + $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id ); | |
| 551 | + $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 552 | + $quiz_grade = 0; | |
| 553 | + $count = 0; | |
| 554 | + $quiz_grade_total = $_POST['quiz_grade_total']; | |
| 555 | + $all_question_grades = array(); | |
| 556 | + $all_answers_feedback = array(); | |
| 557 | 557 | |
| 558 | -        foreach( $questions as $question ) { | |
| 558 | +		foreach( $questions as $question ) { | |
| 559 | 559 | |
| 560 | - ++$count; | |
| 561 | - $question_id = $question->ID; | |
| 560 | + ++$count; | |
| 561 | + $question_id = $question->ID; | |
| 562 | 562 | |
| 563 | -            if( isset( $_POST[ 'question_' . $question_id ] ) ) { | |
| 563 | +			if( isset( $_POST[ 'question_' . $question_id ] ) ) { | |
| 564 | 564 | |
| 565 | - $question_grade = 0; | |
| 566 | -                if( $_POST[ 'question_' . $question_id ] == 'right' ) { | |
| 565 | + $question_grade = 0; | |
| 566 | +				if( $_POST[ 'question_' . $question_id ] == 'right' ) { | |
| 567 | 567 | |
| 568 | - $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; | |
| 568 | + $question_grade = $_POST[ 'question_' . $question_id . '_grade' ]; | |
| 569 | 569 | |
| 570 | - } | |
| 570 | + } | |
| 571 | 571 | |
| 572 | - // add data to the array that will, after the loop, be stored on the lesson status | |
| 573 | - $all_question_grades[ $question_id ] = $question_grade; | |
| 572 | + // add data to the array that will, after the loop, be stored on the lesson status | |
| 573 | + $all_question_grades[ $question_id ] = $question_grade; | |
| 574 | 574 | |
| 575 | - // tally up the total quiz grade | |
| 576 | - $quiz_grade += $question_grade; | |
| 575 | + // tally up the total quiz grade | |
| 576 | + $quiz_grade += $question_grade; | |
| 577 | 577 | |
| 578 | - } // endif | |
| 578 | + } // endif | |
| 579 | 579 | |
| 580 | - // Question answer feedback / notes | |
| 581 | - $question_feedback = ''; | |
| 582 | -            if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ | |
| 580 | + // Question answer feedback / notes | |
| 581 | + $question_feedback = ''; | |
| 582 | +			if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){ | |
| 583 | 583 | |
| 584 | - $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); | |
| 584 | + $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] ); | |
| 585 | 585 | |
| 586 | - } | |
| 587 | - $all_answers_feedback[ $question_id ] = $question_feedback; | |
| 586 | + } | |
| 587 | + $all_answers_feedback[ $question_id ] = $question_feedback; | |
| 588 | 588 | |
| 589 | - } // end for each $questions | |
| 589 | + } // end for each $questions | |
| 590 | 590 | |
| 591 | - //store all question grades on the lesson status | |
| 592 | - Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); | |
| 591 | + //store all question grades on the lesson status | |
| 592 | + Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id ); | |
| 593 | 593 | |
| 594 | - //store the feedback from grading | |
| 595 | - Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); | |
| 594 | + //store the feedback from grading | |
| 595 | + Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id ); | |
| 596 | 596 | |
| 597 | - // $_POST['all_questions_graded'] is set when all questions have been graded | |
| 598 | - // in the class sensei grading user quiz -> display() | |
| 599 | -        if( $_POST['all_questions_graded'] == 'yes' ) { | |
| 597 | + // $_POST['all_questions_graded'] is set when all questions have been graded | |
| 598 | + // in the class sensei grading user quiz -> display() | |
| 599 | +		if( $_POST['all_questions_graded'] == 'yes' ) { | |
| 600 | 600 | |
| 601 | - // set the users total quiz grade | |
| 601 | + // set the users total quiz grade | |
| 602 | 602 |  			if ( 0 < intval( $quiz_grade_total ) ) { | 
| 603 | - $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); | |
| 603 | + $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) ); | |
| 604 | 604 | } | 
| 605 | 605 |  			else { | 
| 606 | 606 | $grade = 0; | 
| 607 | 607 | } | 
| 608 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); | |
| 609 | - | |
| 610 | - // Duplicating what Frontend->sensei_complete_quiz() does | |
| 611 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); | |
| 612 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); | |
| 613 | - $lesson_metadata = array(); | |
| 614 | -            if ( $pass_required ) { | |
| 615 | - // Student has reached the pass mark and lesson is complete | |
| 616 | -                if ( $quiz_passmark <= $grade ) { | |
| 617 | - $lesson_status = 'passed'; | |
| 618 | - } | |
| 619 | -                else { | |
| 620 | - $lesson_status = 'failed'; | |
| 621 | - } // End If Statement | |
| 622 | - } | |
| 623 | - // Student only has to partake the quiz | |
| 624 | -            else { | |
| 625 | - $lesson_status = 'graded'; | |
| 626 | - } | |
| 627 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above | |
| 608 | + Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id ); | |
| 609 | + | |
| 610 | + // Duplicating what Frontend->sensei_complete_quiz() does | |
| 611 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); | |
| 612 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); | |
| 613 | + $lesson_metadata = array(); | |
| 614 | +			if ( $pass_required ) { | |
| 615 | + // Student has reached the pass mark and lesson is complete | |
| 616 | +				if ( $quiz_passmark <= $grade ) { | |
| 617 | + $lesson_status = 'passed'; | |
| 618 | + } | |
| 619 | +				else { | |
| 620 | + $lesson_status = 'failed'; | |
| 621 | + } // End If Statement | |
| 622 | + } | |
| 623 | + // Student only has to partake the quiz | |
| 624 | +			else { | |
| 625 | + $lesson_status = 'graded'; | |
| 626 | + } | |
| 627 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above | |
| 628 | 628 | |
| 629 | - Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); | |
| 629 | + Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata ); | |
| 630 | 630 | |
| 631 | -            if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) { | |
| 631 | +			if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) { | |
| 632 | 632 | |
| 633 | - /** | |
| 634 | - * Summary. | |
| 635 | - * | |
| 636 | - * Description. | |
| 637 | - * | |
| 638 | - * @since 1.7.0 | |
| 639 | - * | |
| 640 | - * @param int $user_id | |
| 641 | - * @param int $quiz_lesson_id | |
| 642 | - */ | |
| 643 | - do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); | |
| 633 | + /** | |
| 634 | + * Summary. | |
| 635 | + * | |
| 636 | + * Description. | |
| 637 | + * | |
| 638 | + * @since 1.7.0 | |
| 639 | + * | |
| 640 | + * @param int $user_id | |
| 641 | + * @param int $quiz_lesson_id | |
| 642 | + */ | |
| 643 | + do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id ); | |
| 644 | 644 | |
| 645 | - } // end if in_array | |
| 645 | + } // end if in_array | |
| 646 | 646 | |
| 647 | - }// end if $_POST['all_que... | |
| 647 | + }// end if $_POST['all_que... | |
| 648 | 648 | |
| 649 | -        if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { | |
| 649 | +		if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) { | |
| 650 | 650 | |
| 651 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); | |
| 651 | + $load_url = add_query_arg( array( 'message' => 'graded' ) ); | |
| 652 | 652 | |
| 653 | -        } elseif ( isset( $_POST['_wp_http_referer'] ) ) { | |
| 653 | +		} elseif ( isset( $_POST['_wp_http_referer'] ) ) { | |
| 654 | 654 | |
| 655 | - $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); | |
| 655 | + $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] ); | |
| 656 | 656 | |
| 657 | -        } else { | |
| 657 | +		} else { | |
| 658 | 658 | |
| 659 | - $load_url = add_query_arg( array( 'message' => 'graded' ) ); | |
| 659 | + $load_url = add_query_arg( array( 'message' => 'graded' ) ); | |
| 660 | 660 | |
| 661 | - } | |
| 661 | + } | |
| 662 | 662 | |
| 663 | - wp_safe_redirect( esc_url_raw( $load_url ) ); | |
| 664 | - exit; | |
| 663 | + wp_safe_redirect( esc_url_raw( $load_url ) ); | |
| 664 | + exit; | |
| 665 | 665 | |
| 666 | - } // end admin_process_grading_submission | |
| 666 | + } // end admin_process_grading_submission | |
| 667 | 667 | |
| 668 | 668 |  	public function get_redirect_url() { | 
| 669 | 669 | // Parse POST data | 
| @@ -708,283 +708,283 @@ discard block | ||
| 708 | 708 | } // End If Statement | 
| 709 | 709 | } // End sensei_grading_notices() | 
| 710 | 710 | |
| 711 | - /** | |
| 712 | - * Grade quiz automatically | |
| 713 | - * | |
| 714 | - * This function grades each question automatically if there all questions are auto gradable. If not | |
| 715 | - * the quiz will not be auto gradable. | |
| 716 | - * | |
| 717 | - * @since 1.7.4 | |
| 718 | - * | |
| 719 | - * @param integer $quiz_id ID of quiz | |
| 720 | -     * @param  array $submitted questions id ans answers { | |
| 721 | - * @type int $question_id | |
| 722 | - * @type mixed $answer | |
| 723 | - * } | |
| 724 | - * @param integer $total_questions Total questions in quiz (not used) | |
| 725 | - * @param string $quiz_grade_type Optional defaults to auto | |
| 726 | - * | |
| 727 | - * @return int $quiz_grade total sum of all question grades | |
| 728 | - */ | |
| 729 | -    public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { | |
| 730 | - | |
| 731 | - if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted | |
| 732 | -            || $quiz_grade_type != 'auto' ) { | |
| 733 | - return false; // exit early | |
| 734 | - } | |
| 735 | - | |
| 736 | - | |
| 737 | - $user_id = get_current_user_id(); | |
| 738 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; | |
| 739 | - $quiz_autogradable = true; | |
| 740 | - | |
| 741 | - /** | |
| 742 | - * Filter the types of question types that can be automatically graded. | |
| 743 | - * | |
| 744 | - * This filter fires inside the auto grade quiz function and provides you with the default list. | |
| 745 | - * | |
| 746 | -         * @param array { | |
| 747 | - * 'multiple-choice', | |
| 748 | - * 'boolean', | |
| 749 | - * 'gap-fill'. | |
| 750 | - * } | |
| 751 | - */ | |
| 752 | - $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); | |
| 753 | - | |
| 754 | - $grade_total = 0; | |
| 755 | - $all_question_grades = array(); | |
| 756 | -        foreach( $submitted as $question_id => $answer ) { | |
| 757 | - | |
| 758 | - // check if the question is autogradable, either by type, or because the grade is 0 | |
| 759 | - $question_type = Sensei()->question->get_question_type( $question_id ); | |
| 711 | + /** | |
| 712 | + * Grade quiz automatically | |
| 713 | + * | |
| 714 | + * This function grades each question automatically if there all questions are auto gradable. If not | |
| 715 | + * the quiz will not be auto gradable. | |
| 716 | + * | |
| 717 | + * @since 1.7.4 | |
| 718 | + * | |
| 719 | + * @param integer $quiz_id ID of quiz | |
| 720 | +	 * @param  array $submitted questions id ans answers { | |
| 721 | + * @type int $question_id | |
| 722 | + * @type mixed $answer | |
| 723 | + * } | |
| 724 | + * @param integer $total_questions Total questions in quiz (not used) | |
| 725 | + * @param string $quiz_grade_type Optional defaults to auto | |
| 726 | + * | |
| 727 | + * @return int $quiz_grade total sum of all question grades | |
| 728 | + */ | |
| 729 | +	public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { | |
| 730 | + | |
| 731 | + if( ! ( intval( $quiz_id ) > 0 ) || ! $submitted | |
| 732 | +			|| $quiz_grade_type != 'auto' ) { | |
| 733 | + return false; // exit early | |
| 734 | + } | |
| 735 | + | |
| 736 | + | |
| 737 | + $user_id = get_current_user_id(); | |
| 738 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ) ; | |
| 739 | + $quiz_autogradable = true; | |
| 740 | + | |
| 741 | + /** | |
| 742 | + * Filter the types of question types that can be automatically graded. | |
| 743 | + * | |
| 744 | + * This filter fires inside the auto grade quiz function and provides you with the default list. | |
| 745 | + * | |
| 746 | +		 * @param array { | |
| 747 | + * 'multiple-choice', | |
| 748 | + * 'boolean', | |
| 749 | + * 'gap-fill'. | |
| 750 | + * } | |
| 751 | + */ | |
| 752 | + $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) ); | |
| 753 | + | |
| 754 | + $grade_total = 0; | |
| 755 | + $all_question_grades = array(); | |
| 756 | +		foreach( $submitted as $question_id => $answer ) { | |
| 757 | + | |
| 758 | + // check if the question is autogradable, either by type, or because the grade is 0 | |
| 759 | + $question_type = Sensei()->question->get_question_type( $question_id ); | |
| 760 | 760 | $achievable_grade = Sensei()->question->get_question_grade( $question_id ); | 
| 761 | 761 | // Question has a zero grade, so skip grading | 
| 762 | 762 |  			if ( 0 == $achievable_grade ) { | 
| 763 | 763 | $all_question_grades[ $question_id ] = $achievable_grade; | 
| 764 | 764 | } | 
| 765 | -            elseif ( in_array( $question_type, $autogradable_question_types ) ) { | |
| 766 | - // Get user question grade | |
| 767 | - $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); | |
| 768 | - $all_question_grades[ $question_id ] = $question_grade; | |
| 769 | - $grade_total += $question_grade; | |
| 765 | +			elseif ( in_array( $question_type, $autogradable_question_types ) ) { | |
| 766 | + // Get user question grade | |
| 767 | + $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id ); | |
| 768 | + $all_question_grades[ $question_id ] = $question_grade; | |
| 769 | + $grade_total += $question_grade; | |
| 770 | 770 | |
| 771 | -            } else { | |
| 771 | +			} else { | |
| 772 | 772 | |
| 773 | - // There is a question that cannot be autograded | |
| 774 | - $quiz_autogradable = false; | |
| 773 | + // There is a question that cannot be autograded | |
| 774 | + $quiz_autogradable = false; | |
| 775 | 775 | |
| 776 | - } // end if in_array( $question_type... | |
| 776 | + } // end if in_array( $question_type... | |
| 777 | 777 | |
| 778 | - }// end for each question | |
| 778 | + }// end for each question | |
| 779 | 779 | |
| 780 | - // Only if the whole quiz was autogradable do we set a grade | |
| 781 | -        if ( $quiz_autogradable ) { | |
| 780 | + // Only if the whole quiz was autogradable do we set a grade | |
| 781 | +		if ( $quiz_autogradable ) { | |
| 782 | 782 | |
| 783 | - $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); | |
| 783 | + $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id ); | |
| 784 | 784 | // Check for zero total from grades | 
| 785 | 785 |  			if ( 0 < $quiz_total ) { | 
| 786 | - $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); | |
| 786 | + $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) ); | |
| 787 | 787 | } | 
| 788 | 788 |  			else { | 
| 789 | 789 | $grade = 0; | 
| 790 | 790 | } | 
| 791 | - Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); | |
| 791 | + Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type ); | |
| 792 | 792 | |
| 793 | -        } else { | |
| 793 | +		} else { | |
| 794 | 794 | |
| 795 | - $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); | |
| 795 | + $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) ); | |
| 796 | 796 | |
| 797 | - } | |
| 798 | - | |
| 799 | - // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default | |
| 800 | - // when doing manual grading. | |
| 801 | - Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); | |
| 797 | + } | |
| 802 | 798 | |
| 803 | - return $grade; | |
| 799 | + // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default | |
| 800 | + // when doing manual grading. | |
| 801 | + Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id ); | |
| 804 | 802 | |
| 805 | - } // End grade_quiz_auto() | |
| 803 | + return $grade; | |
| 806 | 804 | |
| 807 | - /** | |
| 808 | - * Grade question automatically | |
| 809 | - * | |
| 810 | - * This function checks the question typ and then grades it accordingly. | |
| 811 | - * | |
| 812 | - * @since 1.7.4 | |
| 813 | - * | |
| 814 | - * @param integer $question_id | |
| 815 | - * @param string $question_type of the standard Sensei question types | |
| 816 | - * @param string $answer | |
| 817 | - * @param int $user_id | |
| 818 | - * | |
| 819 | - * @return int $question_grade | |
| 820 | - */ | |
| 821 | -    public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { | |
| 822 | - | |
| 823 | -        if( intval( $user_id ) == 0 ) { | |
| 824 | - | |
| 825 | - $user_id = get_current_user_id(); | |
| 826 | - | |
| 827 | - } | |
| 828 | - | |
| 829 | -        if( ! ( intval( $question_id ) > 0 ) ) { | |
| 830 | - | |
| 831 | - return false; | |
| 832 | - | |
| 833 | - } | |
| 834 | - | |
| 835 | - | |
| 836 | - Sensei()->question->get_question_type( $question_id ); | |
| 837 | - | |
| 838 | - /** | |
| 839 | - * Applying a grade before the auto grading takes place. | |
| 840 | - * | |
| 841 | - * This filter is applied just before the question is auto graded. It fires in the context of a single question | |
| 842 | - * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value | |
| 843 | - * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question. | |
| 844 | - * | |
| 845 | - * @param int $question_grade default false | |
| 846 | - * @param int $question_id | |
| 847 | - * @param string $question_type one of the Sensei question type. | |
| 848 | - * @param string $answer user supplied question answer | |
| 849 | - */ | |
| 850 | - $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); | |
| 805 | + } // End grade_quiz_auto() | |
| 851 | 806 | |
| 852 | -        if ( false !== $question_grade ) { | |
| 807 | + /** | |
| 808 | + * Grade question automatically | |
| 809 | + * | |
| 810 | + * This function checks the question typ and then grades it accordingly. | |
| 811 | + * | |
| 812 | + * @since 1.7.4 | |
| 813 | + * | |
| 814 | + * @param integer $question_id | |
| 815 | + * @param string $question_type of the standard Sensei question types | |
| 816 | + * @param string $answer | |
| 817 | + * @param int $user_id | |
| 818 | + * | |
| 819 | + * @return int $question_grade | |
| 820 | + */ | |
| 821 | +	public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { | |
| 822 | + | |
| 823 | +		if( intval( $user_id ) == 0 ) { | |
| 824 | + | |
| 825 | + $user_id = get_current_user_id(); | |
| 826 | + | |
| 827 | + } | |
| 828 | + | |
| 829 | +		if( ! ( intval( $question_id ) > 0 ) ) { | |
| 830 | + | |
| 831 | + return false; | |
| 832 | + | |
| 833 | + } | |
| 834 | + | |
| 835 | + | |
| 836 | + Sensei()->question->get_question_type( $question_id ); | |
| 837 | + | |
| 838 | + /** | |
| 839 | + * Applying a grade before the auto grading takes place. | |
| 840 | + * | |
| 841 | + * This filter is applied just before the question is auto graded. It fires in the context of a single question | |
| 842 | + * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value | |
| 843 | + * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question. | |
| 844 | + * | |
| 845 | + * @param int $question_grade default false | |
| 846 | + * @param int $question_id | |
| 847 | + * @param string $question_type one of the Sensei question type. | |
| 848 | + * @param string $answer user supplied question answer | |
| 849 | + */ | |
| 850 | + $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer ); | |
| 853 | 851 | |
| 854 | - return $question_grade; | |
| 852 | +		if ( false !== $question_grade ) { | |
| 855 | 853 | |
| 856 | - } | |
| 854 | + return $question_grade; | |
| 857 | 855 | |
| 858 | - // auto grading core | |
| 859 | -        if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){ | |
| 856 | + } | |
| 860 | 857 | |
| 861 | - $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); | |
| 858 | + // auto grading core | |
| 859 | +		if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){ | |
| 862 | 860 | |
| 863 | -            if( 0 == get_magic_quotes_gpc() ) { | |
| 864 | - $answer = wp_unslash( $answer ); | |
| 865 | - } | |
| 866 | - $answer = (array) $answer; | |
| 867 | -            if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { | |
| 868 | - // Loop through all answers ensure none are 'missing' | |
| 869 | - $all_correct = true; | |
| 870 | -                foreach ( $answer as $check_answer ) { | |
| 871 | -                    if ( !in_array( $check_answer, $right_answer ) ) { | |
| 872 | - $all_correct = false; | |
| 873 | - } | |
| 874 | - } | |
| 875 | - // If all correct then grade | |
| 876 | -                if ( $all_correct ) { | |
| 877 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); | |
| 878 | - } | |
| 879 | - } | |
| 861 | + $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true ); | |
| 880 | 862 | |
| 881 | -        } elseif( 'gap-fill' == $question_type ){ | |
| 863 | +			if( 0 == get_magic_quotes_gpc() ) { | |
| 864 | + $answer = wp_unslash( $answer ); | |
| 865 | + } | |
| 866 | + $answer = (array) $answer; | |
| 867 | +			if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) { | |
| 868 | + // Loop through all answers ensure none are 'missing' | |
| 869 | + $all_correct = true; | |
| 870 | +				foreach ( $answer as $check_answer ) { | |
| 871 | +					if ( !in_array( $check_answer, $right_answer ) ) { | |
| 872 | + $all_correct = false; | |
| 873 | + } | |
| 874 | + } | |
| 875 | + // If all correct then grade | |
| 876 | +				if ( $all_correct ) { | |
| 877 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); | |
| 878 | + } | |
| 879 | + } | |
| 882 | 880 | |
| 883 | - $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); | |
| 881 | +		} elseif( 'gap-fill' == $question_type ){ | |
| 884 | 882 | |
| 885 | -        } else{ | |
| 883 | + $question_grade = self::grade_gap_fill_question( $question_id ,$answer ); | |
| 886 | 884 | |
| 887 | - /** | |
| 888 | - * Grading questions that are not auto gradable. | |
| 889 | - * | |
| 890 | - * This filter is applied the context of ta single question within the sensei_grade_question_auto function. | |
| 891 | - * It fires for all other questions types. It does not apply to 'multiple-choice' , 'boolean' and gap-fill. | |
| 892 | - * | |
| 893 | - * @param int $question_grade default zero | |
| 894 | - * @param int $question_id | |
| 895 | - * @param string $question_type one of the Sensei question type. | |
| 896 | - * @param string $answer user supplied question answer | |
| 897 | - */ | |
| 898 | - $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); | |
| 885 | +		} else{ | |
| 899 | 886 | |
| 900 | - } // end if $question_type | |
| 887 | + /** | |
| 888 | + * Grading questions that are not auto gradable. | |
| 889 | + * | |
| 890 | + * This filter is applied the context of ta single question within the sensei_grade_question_auto function. | |
| 891 | + * It fires for all other questions types. It does not apply to 'multiple-choice' , 'boolean' and gap-fill. | |
| 892 | + * | |
| 893 | + * @param int $question_grade default zero | |
| 894 | + * @param int $question_id | |
| 895 | + * @param string $question_type one of the Sensei question type. | |
| 896 | + * @param string $answer user supplied question answer | |
| 897 | + */ | |
| 898 | + $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer ); | |
| 901 | 899 | |
| 902 | - return $question_grade; | |
| 903 | - } // end grade_question_auto | |
| 900 | + } // end if $question_type | |
| 904 | 901 | |
| 905 | - /** | |
| 906 | - * Grading logic specifically for the gap fill questions | |
| 907 | - * | |
| 908 | - * @since 1.9.0 | |
| 909 | - * @param $question_id | |
| 910 | - * @param $user_answer | |
| 911 | - * | |
| 912 | - * @return bool | int false or the grade given to the user answer | |
| 913 | - */ | |
| 914 | -    public static function grade_gap_fill_question( $question_id, $user_answer ){ | |
| 902 | + return $question_grade; | |
| 903 | + } // end grade_question_auto | |
| 915 | 904 | |
| 916 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); | |
| 917 | - $gapfill_array = explode( '||', $right_answer ); | |
| 905 | + /** | |
| 906 | + * Grading logic specifically for the gap fill questions | |
| 907 | + * | |
| 908 | + * @since 1.9.0 | |
| 909 | + * @param $question_id | |
| 910 | + * @param $user_answer | |
| 911 | + * | |
| 912 | + * @return bool | int false or the grade given to the user answer | |
| 913 | + */ | |
| 914 | +	public static function grade_gap_fill_question( $question_id, $user_answer ){ | |
| 918 | 915 | |
| 919 | -        if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 | |
| 920 | - $user_answer = wp_unslash( $user_answer ); | |
| 921 | - } | |
| 916 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); | |
| 917 | + $gapfill_array = explode( '||', $right_answer ); | |
| 922 | 918 | |
| 923 | - /** | |
| 924 | - * case sensitive grading filter | |
| 925 | - * | |
| 926 | - * alter the value simply use this code in your plugin or the themes functions.php | |
| 927 | - * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); | |
| 928 | - * | |
| 929 | - * @param bool $do_case_sensitive_comparison default false. | |
| 930 | - * | |
| 931 | - * @since 1.9.0 | |
| 932 | - */ | |
| 933 | -        $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); | |
| 919 | +		if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2 | |
| 920 | + $user_answer = wp_unslash( $user_answer ); | |
| 921 | + } | |
| 922 | + | |
| 923 | + /** | |
| 924 | + * case sensitive grading filter | |
| 925 | + * | |
| 926 | + * alter the value simply use this code in your plugin or the themes functions.php | |
| 927 | + * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); | |
| 928 | + * | |
| 929 | + * @param bool $do_case_sensitive_comparison default false. | |
| 930 | + * | |
| 931 | + * @since 1.9.0 | |
| 932 | + */ | |
| 933 | +		$do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false ); | |
| 934 | 934 | |
| 935 | -        if( $do_case_sensitive_comparison ){ | |
| 935 | +		if( $do_case_sensitive_comparison ){ | |
| 936 | 936 | |
| 937 | - // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer | |
| 938 | -            if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { | |
| 937 | + // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer | |
| 938 | +			if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) { | |
| 939 | 939 | |
| 940 | - return Sensei()->question->get_question_grade( $question_id ); | |
| 940 | + return Sensei()->question->get_question_grade( $question_id ); | |
| 941 | 941 | |
| 942 | -            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { | |
| 942 | +			} else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { | |
| 943 | 943 | |
| 944 | -                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { | |
| 944 | +				if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { | |
| 945 | 945 | |
| 946 | - return Sensei()->question->get_question_grade($question_id); | |
| 946 | + return Sensei()->question->get_question_grade($question_id); | |
| 947 | 947 | |
| 948 | -                }else{ | |
| 948 | +				}else{ | |
| 949 | 949 | |
| 950 | - return false; | |
| 950 | + return false; | |
| 951 | 951 | |
| 952 | - } | |
| 952 | + } | |
| 953 | 953 | |
| 954 | -            }else{ | |
| 954 | +			}else{ | |
| 955 | 955 | |
| 956 | - return false; | |
| 956 | + return false; | |
| 957 | 957 | |
| 958 | - } | |
| 958 | + } | |
| 959 | 959 | |
| 960 | -        }else{ | |
| 960 | +		}else{ | |
| 961 | 961 | |
| 962 | - // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer | |
| 963 | -            if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { | |
| 962 | + // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer | |
| 963 | +			if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) { | |
| 964 | 964 | |
| 965 | - return Sensei()->question->get_question_grade( $question_id ); | |
| 965 | + return Sensei()->question->get_question_grade( $question_id ); | |
| 966 | 966 | |
| 967 | -            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { | |
| 967 | +			} else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { | |
| 968 | 968 | |
| 969 | -                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { | |
| 969 | +				if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { | |
| 970 | 970 | |
| 971 | - return Sensei()->question->get_question_grade( $question_id ); | |
| 971 | + return Sensei()->question->get_question_grade( $question_id ); | |
| 972 | 972 | |
| 973 | -                }else{ | |
| 973 | +				}else{ | |
| 974 | 974 | |
| 975 | - return false; | |
| 975 | + return false; | |
| 976 | 976 | |
| 977 | - } | |
| 977 | + } | |
| 978 | 978 | |
| 979 | -            }else{ | |
| 979 | +			}else{ | |
| 980 | 980 | |
| 981 | - return false; | |
| 981 | + return false; | |
| 982 | 982 | |
| 983 | - } | |
| 983 | + } | |
| 984 | 984 | |
| 985 | - } | |
| 985 | + } | |
| 986 | 986 | |
| 987 | - } | |
| 987 | + } | |
| 988 | 988 | |
| 989 | 989 | } // End Class | 
| 990 | 990 | |
| @@ -44,6 +44,7 @@ | ||
| 44 | 44 | /** | 
| 45 | 45 | * Constructor | 
| 46 | 46 | * @since 1.2.0 | 
| 47 | + * @param string $token | |
| 47 | 48 | * @return void | 
| 48 | 49 | */ | 
| 49 | 50 |  	public function __construct ( $token ) { | 
| @@ -162,8 +162,8 @@ | ||
| 162 | 162 | $sortable[$id] = $data; | 
| 163 | 163 | } | 
| 164 | 164 | |
| 165 | - $primary = $this->get_primary_column_name(); | |
| 166 | - $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); | |
| 165 | + $primary = $this->get_primary_column_name(); | |
| 166 | + $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); | |
| 167 | 167 | |
| 168 | 168 | return $this->_column_headers; | 
| 169 | 169 | } | 
| @@ -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 ) { | 
| @@ -22,7 +22,7 @@ discard block | ||
| 22 | 22 | * @since 1.6.0 | 
| 23 | 23 | */ | 
| 24 | 24 |  	public function __construct () { | 
| 25 | - $this->token = 'messages'; | |
| 25 | + $this->token = 'messages'; | |
| 26 | 26 | $this->post_type = 'sensei_message'; | 
| 27 | 27 | $this->meta_fields = array( 'sender', 'receiver' ); | 
| 28 | 28 | |
| @@ -37,11 +37,11 @@ discard block | ||
| 37 | 37 | // Monitor when new reply is posted | 
| 38 | 38 | add_action( 'comment_post', array( $this, 'message_reply_received' ), 10, 1 ); | 
| 39 | 39 | |
| 40 | - // Block WordPress from sending comment update emails for the messages post type | |
| 41 | -        add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  ); | |
| 40 | + // Block WordPress from sending comment update emails for the messages post type | |
| 41 | +		add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  ); | |
| 42 | 42 | |
| 43 | - // Block WordPress from sending comment moderator emails on the sensei messages post types | |
| 44 | -        add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  ); | |
| 43 | + // Block WordPress from sending comment moderator emails on the sensei messages post types | |
| 44 | +		add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  ); | |
| 45 | 45 | |
| 46 | 46 | // Process saving of message posts | 
| 47 | 47 | add_action( 'save_post', array( $this, 'save_message' ) ); | 
| @@ -49,20 +49,20 @@ discard block | ||
| 49 | 49 | // Add message links to courses & lessons | 
| 50 | 50 | add_action( 'sensei_single_course_content_inside_before', array( $this, 'send_message_link' ), 35 ); | 
| 51 | 51 | |
| 52 | - // add message link to lesson | |
| 53 | - add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); | |
| 52 | + // add message link to lesson | |
| 53 | + add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 ); | |
| 54 | 54 | |
| 55 | - // add message link to lesson | |
| 56 | - add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); | |
| 55 | + // add message link to lesson | |
| 56 | + add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 ); | |
| 57 | 57 | |
| 58 | 58 | // Hide messages and replies from users who do not have access | 
| 59 | - add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); | |
| 60 | - add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); | |
| 61 | - add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); | |
| 62 | - add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); | |
| 63 | - add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); | |
| 64 | - add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); | |
| 65 | - add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); | |
| 59 | + add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 ); | |
| 60 | + add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 ); | |
| 61 | + add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 ); | |
| 62 | + add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 ); | |
| 63 | + add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 ); | |
| 64 | + add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 ); | |
| 65 | + add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 ); | |
| 66 | 66 | } // End __construct() | 
| 67 | 67 | |
| 68 | 68 |  	public function add_menu_item() { | 
| @@ -163,8 +163,8 @@ discard block | ||
| 163 | 163 |  	public function send_message_link( $post_id = 0, $user_id = 0 ) { | 
| 164 | 164 | global $post; | 
| 165 | 165 | |
| 166 | - // only show the link for the allowed post types: | |
| 167 | -        $allowed_post_types = array('lesson', 'course', 'quiz'); | |
| 166 | + // only show the link for the allowed post types: | |
| 167 | +		$allowed_post_types = array('lesson', 'course', 'quiz'); | |
| 168 | 168 |  		if ( ! in_array( get_post_type() , $allowed_post_types ) ) { | 
| 169 | 169 | |
| 170 | 170 | return; | 
| @@ -187,8 +187,8 @@ discard block | ||
| 187 | 187 |  				} elseif( 'course' == $post->post_type ) { | 
| 188 | 188 | $contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' ); | 
| 189 | 189 |  				}else{ | 
| 190 | - $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); | |
| 191 | - } | |
| 190 | + $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' ); | |
| 191 | + } | |
| 192 | 192 | |
| 193 | 193 | $html .= '<p><a class="button send-message-button" href="' . esc_url($href) . '#private_message">' . $contact_button_text . '</a></p>'; | 
| 194 | 194 | } | 
| @@ -213,19 +213,19 @@ discard block | ||
| 213 | 213 | |
| 214 | 214 | if( ! isset( $post->ID ) ) return $html; | 
| 215 | 215 | |
| 216 | - //confirm private message | |
| 217 | - $confirmation = ''; | |
| 218 | -        if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { | |
| 216 | + //confirm private message | |
| 217 | + $confirmation = ''; | |
| 218 | +		if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) { | |
| 219 | 219 | |
| 220 | -            $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); | |
| 221 | - $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; | |
| 220 | +			$confirmation_message = __('Your private message has been sent.', 'woothemes-sensei'); | |
| 221 | + $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>'; | |
| 222 | 222 | |
| 223 | - } | |
| 223 | + } | |
| 224 | 224 | |
| 225 | 225 | $html .= '<h3 id="private_message">' . __( 'Send Private Message', 'woothemes-sensei' ) . '</h3>'; | 
| 226 | - $html .= '<p>'; | |
| 227 | - $html .= $confirmation; | |
| 228 | - $html .= '</p>'; | |
| 226 | + $html .= '<p>'; | |
| 227 | + $html .= $confirmation; | |
| 228 | + $html .= '</p>'; | |
| 229 | 229 | $html .= '<form name="contact-teacher" action="" method="post" class="contact-teacher">'; | 
| 230 | 230 | $html .= '<p class="form-row form-row-wide">'; | 
| 231 | 231 | $html .= '<textarea name="contact_message" placeholder="' . __( 'Enter your private message.', 'woothemes-sensei' ) . '"></textarea>'; | 
| @@ -256,7 +256,7 @@ discard block | ||
| 256 | 256 |  	public function message_reply_received( $comment_id = 0 ) { | 
| 257 | 257 | |
| 258 | 258 | // Get comment object | 
| 259 | - $comment = get_comment( $comment_id ); | |
| 259 | + $comment = get_comment( $comment_id ); | |
| 260 | 260 | |
| 261 | 261 | if( is_null( $comment ) ) return; | 
| 262 | 262 | |
| @@ -271,87 +271,87 @@ discard block | ||
| 271 | 271 | do_action( 'sensei_private_message_reply', $comment, $message ); | 
| 272 | 272 | } | 
| 273 | 273 | |
| 274 | - /** | |
| 275 | - * This function stops WordPress from sending the default comment update emails. | |
| 276 | - * | |
| 277 | - * This function is hooked into comment_notification_recipients. It will simply return | |
| 278 | - * an empty array if the current passed in comment is on a message post type. | |
| 279 | - * | |
| 280 | - * @param array $emails | |
| 281 | - * @param int $comment_id | |
| 282 | - * @return array; | |
| 283 | - */ | |
| 284 | -    public function stop_wp_comment_emails( $emails , $comment_id ){ | |
| 274 | + /** | |
| 275 | + * This function stops WordPress from sending the default comment update emails. | |
| 276 | + * | |
| 277 | + * This function is hooked into comment_notification_recipients. It will simply return | |
| 278 | + * an empty array if the current passed in comment is on a message post type. | |
| 279 | + * | |
| 280 | + * @param array $emails | |
| 281 | + * @param int $comment_id | |
| 282 | + * @return array; | |
| 283 | + */ | |
| 284 | +	public function stop_wp_comment_emails( $emails , $comment_id ){ | |
| 285 | 285 | |
| 286 | - $comment = get_comment( $comment_id ); | |
| 287 | - if( isset( $comment->comment_post_ID ) && | |
| 288 | -            'sensei_message' == get_post_type( $comment->comment_post_ID )  ){ | |
| 286 | + $comment = get_comment( $comment_id ); | |
| 287 | + if( isset( $comment->comment_post_ID ) && | |
| 288 | +			'sensei_message' == get_post_type( $comment->comment_post_ID )  ){ | |
| 289 | 289 | |
| 290 | - // empty the emails array to ensure no emails are sent for this comment | |
| 291 | - $emails = array(); | |
| 290 | + // empty the emails array to ensure no emails are sent for this comment | |
| 291 | + $emails = array(); | |
| 292 | 292 | |
| 293 | - } | |
| 294 | - return $emails; | |
| 293 | + } | |
| 294 | + return $emails; | |
| 295 | 295 | |
| 296 | - }// end stop_wp_comment_emails | |
| 296 | + }// end stop_wp_comment_emails | |
| 297 | 297 | |
| 298 | 298 | /** | 
| 299 | - * Save new message post | |
| 300 | - * @param integer $sender_id ID of sender | |
| 301 | - * @param integer $receiver_id ID of receiver | |
| 302 | - * @param string $message Message content | |
| 303 | - * @param string $post_id ID of post related to message | |
| 304 | - * @return mixed Message ID on success, boolean false on failure | |
| 305 | - */ | |
| 306 | -    private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { | |
| 299 | + * Save new message post | |
| 300 | + * @param integer $sender_id ID of sender | |
| 301 | + * @param integer $receiver_id ID of receiver | |
| 302 | + * @param string $message Message content | |
| 303 | + * @param string $post_id ID of post related to message | |
| 304 | + * @return mixed Message ID on success, boolean false on failure | |
| 305 | + */ | |
| 306 | +	private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) { | |
| 307 | 307 | |
| 308 | - $message_id = false; | |
| 308 | + $message_id = false; | |
| 309 | 309 | |
| 310 | -    	if( $sender_id && $receiver_id && $message && $post_id ) { | |
| 310 | +		if( $sender_id && $receiver_id && $message && $post_id ) { | |
| 311 | 311 | |
| 312 | - $title = wp_trim_words( $message, 8, '...' ); | |
| 312 | + $title = wp_trim_words( $message, 8, '...' ); | |
| 313 | 313 | |
| 314 | - // Set up post data for message | |
| 315 | - $message_data = array( | |
| 316 | - 'post_type' => $this->post_type, | |
| 317 | - 'post_title' => esc_html( $title ), | |
| 318 | - 'post_content' => esc_html( $message ), | |
| 319 | - 'post_status' => 'publish', | |
| 320 | - 'ping_status' => 'closed', | |
| 321 | - 'comment_status' => 'open', | |
| 322 | - 'post_excerpt' => '', | |
| 323 | - 'post_author' => intval( $sender_id ) | |
| 324 | - ); | |
| 314 | + // Set up post data for message | |
| 315 | + $message_data = array( | |
| 316 | + 'post_type' => $this->post_type, | |
| 317 | + 'post_title' => esc_html( $title ), | |
| 318 | + 'post_content' => esc_html( $message ), | |
| 319 | + 'post_status' => 'publish', | |
| 320 | + 'ping_status' => 'closed', | |
| 321 | + 'comment_status' => 'open', | |
| 322 | + 'post_excerpt' => '', | |
| 323 | + 'post_author' => intval( $sender_id ) | |
| 324 | + ); | |
| 325 | 325 | |
| 326 | - // Insert post | |
| 327 | - $message_id = wp_insert_post( $message_data ); | |
| 326 | + // Insert post | |
| 327 | + $message_id = wp_insert_post( $message_data ); | |
| 328 | 328 | |
| 329 | -	        if( ! is_wp_error( $message_id ) ) { | |
| 329 | +			if( ! is_wp_error( $message_id ) ) { | |
| 330 | 330 | |
| 331 | - // Add sender to message meta | |
| 332 | - $sender = get_userdata( $sender_id ); | |
| 333 | - add_post_meta( $message_id, '_sender', $sender->user_login ); | |
| 331 | + // Add sender to message meta | |
| 332 | + $sender = get_userdata( $sender_id ); | |
| 333 | + add_post_meta( $message_id, '_sender', $sender->user_login ); | |
| 334 | 334 | |
| 335 | - // Add receiver to message meta | |
| 336 | - $receiver = get_userdata( $receiver_id ); | |
| 337 | - add_post_meta( $message_id, '_receiver', $receiver->user_login ); | |
| 335 | + // Add receiver to message meta | |
| 336 | + $receiver = get_userdata( $receiver_id ); | |
| 337 | + add_post_meta( $message_id, '_receiver', $receiver->user_login ); | |
| 338 | 338 | |
| 339 | - // Add lesson/course ID to message meta | |
| 340 | - $post = get_post( $post_id ); | |
| 341 | - add_post_meta( $message_id, '_posttype', $post->post_type ); | |
| 342 | - add_post_meta( $message_id, '_post', $post->ID ); | |
| 339 | + // Add lesson/course ID to message meta | |
| 340 | + $post = get_post( $post_id ); | |
| 341 | + add_post_meta( $message_id, '_posttype', $post->post_type ); | |
| 342 | + add_post_meta( $message_id, '_post', $post->ID ); | |
| 343 | 343 | |
| 344 | - do_action( 'sensei_new_private_message', $message_id ); | |
| 344 | + do_action( 'sensei_new_private_message', $message_id ); | |
| 345 | 345 | |
| 346 | -		    } else { | |
| 346 | +			} else { | |
| 347 | 347 | |
| 348 | - $message_id = false; | |
| 348 | + $message_id = false; | |
| 349 | 349 | |
| 350 | - } | |
| 351 | - } | |
| 350 | + } | |
| 351 | + } | |
| 352 | 352 | |
| 353 | - return $message_id; | |
| 354 | - } | |
| 353 | + return $message_id; | |
| 354 | + } | |
| 355 | 355 | |
| 356 | 356 | /** | 
| 357 | 357 | * Check if user has access to view this message | 
| @@ -390,56 +390,56 @@ discard block | ||
| 390 | 390 |  		remove_meta_box('commentstatusdiv', $this->post_type, 'normal'); | 
| 391 | 391 | } | 
| 392 | 392 | |
| 393 | - /** | |
| 394 | - * Function message_login() | |
| 395 | - * | |
| 396 | - * Only show /messages/* to logged in users, and | |
| 397 | - * redirect logged out users to wp-login.php | |
| 398 | - * | |
| 399 | - * @since 1.9.0 | |
| 400 | - * @param none | |
| 401 | - * @return void | |
| 402 | - */ | |
| 393 | + /** | |
| 394 | + * Function message_login() | |
| 395 | + * | |
| 396 | + * Only show /messages/* to logged in users, and | |
| 397 | + * redirect logged out users to wp-login.php | |
| 398 | + * | |
| 399 | + * @since 1.9.0 | |
| 400 | + * @param none | |
| 401 | + * @return void | |
| 402 | + */ | |
| 403 | 403 | |
| 404 | -    public function message_login () { | |
| 404 | +	public function message_login () { | |
| 405 | 405 | |
| 406 | -        if ( is_user_logged_in() ) { | |
| 406 | +		if ( is_user_logged_in() ) { | |
| 407 | 407 | |
| 408 | - return; | |
| 409 | - } | |
| 408 | + return; | |
| 409 | + } | |
| 410 | 410 | |
| 411 | - $settings = Sensei()->settings->get_settings(); | |
| 412 | - if( isset( $settings[ 'my_course_page' ] ) | |
| 413 | -            && 0 < intval( $settings[ 'my_course_page' ] ) ){ | |
| 411 | + $settings = Sensei()->settings->get_settings(); | |
| 412 | + if( isset( $settings[ 'my_course_page' ] ) | |
| 413 | +			&& 0 < intval( $settings[ 'my_course_page' ] ) ){ | |
| 414 | 414 | |
| 415 | - $my_courses_page_id = $settings[ 'my_course_page' ]; | |
| 415 | + $my_courses_page_id = $settings[ 'my_course_page' ]; | |
| 416 | 416 | |
| 417 | - $my_courses_url = get_permalink($my_courses_page_id); | |
| 417 | + $my_courses_url = get_permalink($my_courses_page_id); | |
| 418 | 418 | |
| 419 | - } | |
| 419 | + } | |
| 420 | 420 | |
| 421 | - if ( is_single() && is_singular( $this->post_type ) | |
| 422 | -            || is_post_type_archive( $this->post_type ) ) { | |
| 421 | + if ( is_single() && is_singular( $this->post_type ) | |
| 422 | +			|| is_post_type_archive( $this->post_type ) ) { | |
| 423 | 423 | |
| 424 | -            if ( isset($my_courses_url) ) { | |
| 424 | +			if ( isset($my_courses_url) ) { | |
| 425 | 425 | |
| 426 | - wp_redirect($my_courses_url, 303); | |
| 427 | - exit; | |
| 428 | - } | |
| 426 | + wp_redirect($my_courses_url, 303); | |
| 427 | + exit; | |
| 428 | + } | |
| 429 | 429 | |
| 430 | -            else { | |
| 430 | +			else { | |
| 431 | 431 | |
| 432 | -                wp_redirect(home_url('/wp-login.php'), 303); | |
| 433 | - exit; | |
| 434 | - } | |
| 432 | +				wp_redirect(home_url('/wp-login.php'), 303); | |
| 433 | + exit; | |
| 434 | + } | |
| 435 | 435 | |
| 436 | - } | |
| 437 | - } | |
| 436 | + } | |
| 437 | + } | |
| 438 | 438 | /** | 
| 439 | - * Only show allowed messages in messages archive | |
| 440 | - * @param array $query Original query | |
| 441 | - * @return void | |
| 442 | - */ | |
| 439 | + * Only show allowed messages in messages archive | |
| 440 | + * @param array $query Original query | |
| 441 | + * @return void | |
| 442 | + */ | |
| 443 | 443 |  	public function message_list( $query ) { | 
| 444 | 444 | global $current_user; | 
| 445 | 445 | |
| @@ -556,17 +556,17 @@ discard block | ||
| 556 | 556 | return $open; | 
| 557 | 557 | } | 
| 558 | 558 | |
| 559 | - /** | |
| 560 | - * Print outthe message was sent by $sender_username on the | |
| 561 | - * | |
| 562 | - * @since 1.9.0 | |
| 563 | - */ | |
| 564 | -    public static function the_message_sent_by_title(){ | |
| 559 | + /** | |
| 560 | + * Print outthe message was sent by $sender_username on the | |
| 561 | + * | |
| 562 | + * @since 1.9.0 | |
| 563 | + */ | |
| 564 | +	public static function the_message_sent_by_title(){ | |
| 565 | 565 | |
| 566 | - $sender_username = get_post_meta( get_the_ID() , '_sender', true ); | |
| 567 | -        if( $sender_username ) { | |
| 566 | + $sender_username = get_post_meta( get_the_ID() , '_sender', true ); | |
| 567 | +		if( $sender_username ) { | |
| 568 | 568 | |
| 569 | - $sender = get_user_by( 'login', $sender_username ); ?> | |
| 569 | + $sender = get_user_by( 'login', $sender_username ); ?> | |
| 570 | 570 | |
| 571 | 571 | <p class="message-meta"> | 
| 572 | 572 | <small> | 
| @@ -578,41 +578,41 @@ discard block | ||
| 578 | 578 | |
| 579 | 579 | <?php } | 
| 580 | 580 | |
| 581 | - } | |
| 581 | + } | |
| 582 | 582 | |
| 583 | - /** | |
| 584 | - * sensei_single_title output for single page title | |
| 585 | - * @since 1.1.0 | |
| 586 | - * @return void | |
| 587 | - * @deprecate | |
| 588 | - */ | |
| 589 | -    public static function the_title() { | |
| 583 | + /** | |
| 584 | + * sensei_single_title output for single page title | |
| 585 | + * @since 1.1.0 | |
| 586 | + * @return void | |
| 587 | + * @deprecate | |
| 588 | + */ | |
| 589 | +	public static function the_title() { | |
| 590 | 590 | |
| 591 | - global $post; | |
| 591 | + global $post; | |
| 592 | 592 | |
| 593 | - $content_post_id = get_post_meta( $post->ID, '_post', true ); | |
| 594 | -        if( $content_post_id ) { | |
| 595 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); | |
| 596 | -        } else { | |
| 597 | - $title = get_the_title( $post->ID ); | |
| 598 | - } | |
| 593 | + $content_post_id = get_post_meta( $post->ID, '_post', true ); | |
| 594 | +		if( $content_post_id ) { | |
| 595 | + $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' ); | |
| 596 | +		} else { | |
| 597 | + $title = get_the_title( $post->ID ); | |
| 598 | + } | |
| 599 | 599 | |
| 600 | - ?> | |
| 600 | + ?> | |
| 601 | 601 | <header> | 
| 602 | 602 | |
| 603 | 603 | <h1> | 
| 604 | 604 | |
| 605 | 605 | <?php | 
| 606 | - /** | |
| 607 | - * Filter Sensei single title | |
| 608 | - * | |
| 609 | - * @since 1.8.0 | |
| 610 | - * @param string $title | |
| 611 | - * @param string $template | |
| 612 | - * @param string $post_type | |
| 613 | - */ | |
| 614 | - echo apply_filters( 'sensei_single_title', $title, $post->post_type ); | |
| 615 | - ?> | |
| 606 | + /** | |
| 607 | + * Filter Sensei single title | |
| 608 | + * | |
| 609 | + * @since 1.8.0 | |
| 610 | + * @param string $title | |
| 611 | + * @param string $template | |
| 612 | + * @param string $post_type | |
| 613 | + */ | |
| 614 | + echo apply_filters( 'sensei_single_title', $title, $post->post_type ); | |
| 615 | + ?> | |
| 616 | 616 | |
| 617 | 617 | </h1> | 
| 618 | 618 | |
| @@ -620,52 +620,52 @@ discard block | ||
| 620 | 620 | |
| 621 | 621 | <?php | 
| 622 | 622 | |
| 623 | - } // End sensei_single_title() | |
| 623 | + } // End sensei_single_title() | |
| 624 | 624 | |
| 625 | - /** | |
| 626 | - * Generates the my messages | |
| 627 | - * archive header. | |
| 628 | - * | |
| 629 | - * @since 1.9.0 | |
| 630 | - * | |
| 631 | - * @return string | |
| 632 | - */ | |
| 633 | -    public static function the_archive_header( ){ | |
| 625 | + /** | |
| 626 | + * Generates the my messages | |
| 627 | + * archive header. | |
| 628 | + * | |
| 629 | + * @since 1.9.0 | |
| 630 | + * | |
| 631 | + * @return string | |
| 632 | + */ | |
| 633 | +	public static function the_archive_header( ){ | |
| 634 | 634 | |
| 635 | - $html = ''; | |
| 636 | - $html .= '<header class="archive-header"><h1>'; | |
| 637 | - $html .= __( 'My Messages', 'woothemes-sensei' ); | |
| 638 | - $html .= '</h1></header>'; | |
| 635 | + $html = ''; | |
| 636 | + $html .= '<header class="archive-header"><h1>'; | |
| 637 | + $html .= __( 'My Messages', 'woothemes-sensei' ); | |
| 638 | + $html .= '</h1></header>'; | |
| 639 | 639 | |
| 640 | - /** | |
| 641 | - * Filter the sensei messages archive title. | |
| 642 | - * @since 1.0.0 | |
| 643 | - */ | |
| 644 | - echo apply_filters( 'sensei_message_archive_title', $html ); | |
| 640 | + /** | |
| 641 | + * Filter the sensei messages archive title. | |
| 642 | + * @since 1.0.0 | |
| 643 | + */ | |
| 644 | + echo apply_filters( 'sensei_message_archive_title', $html ); | |
| 645 | 645 | |
| 646 | - } // get_archive_header() | |
| 646 | + } // get_archive_header() | |
| 647 | 647 | |
| 648 | - /** | |
| 649 | - * Output the title for a message given the post_id. | |
| 650 | - * | |
| 651 | - * @since 1.9.0 | |
| 652 | - * @param $post_id | |
| 653 | - */ | |
| 654 | -    public static function the_message_title( $message_post_id ){ | |
| 648 | + /** | |
| 649 | + * Output the title for a message given the post_id. | |
| 650 | + * | |
| 651 | + * @since 1.9.0 | |
| 652 | + * @param $post_id | |
| 653 | + */ | |
| 654 | +	public static function the_message_title( $message_post_id ){ | |
| 655 | 655 | |
| 656 | - $content_post_id = get_post_meta( $message_post_id, '_post', true ); | |
| 656 | + $content_post_id = get_post_meta( $message_post_id, '_post', true ); | |
| 657 | 657 | |
| 658 | -        if( $content_post_id ) { | |
| 658 | +		if( $content_post_id ) { | |
| 659 | 659 | |
| 660 | - $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); | |
| 660 | + $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) ); | |
| 661 | 661 | |
| 662 | -        } else { | |
| 662 | +		} else { | |
| 663 | 663 | |
| 664 | - $title = get_the_title( $message_post_id ); | |
| 664 | + $title = get_the_title( $message_post_id ); | |
| 665 | 665 | |
| 666 | - } | |
| 666 | + } | |
| 667 | 667 | |
| 668 | - ?> | |
| 668 | + ?> | |
| 669 | 669 | <h2> | 
| 670 | 670 | <a href="<?php esc_url( get_permalink( $message_post_id ) );?>"> | 
| 671 | 671 | <?php echo $title; ?> | 
| @@ -674,21 +674,21 @@ discard block | ||
| 674 | 674 | </h2> | 
| 675 | 675 | |
| 676 | 676 | <?php | 
| 677 | - } //end the_message_header | |
| 677 | + } //end the_message_header | |
| 678 | 678 | |
| 679 | - /** | |
| 680 | - * Output the message sender given the post id. | |
| 681 | - * | |
| 682 | - * @param $message_post_id | |
| 683 | - */ | |
| 684 | -    public  static function the_message_sender( $message_post_id ){ | |
| 679 | + /** | |
| 680 | + * Output the message sender given the post id. | |
| 681 | + * | |
| 682 | + * @param $message_post_id | |
| 683 | + */ | |
| 684 | +	public  static function the_message_sender( $message_post_id ){ | |
| 685 | 685 | |
| 686 | - $sender_username = get_post_meta( $message_post_id, '_sender', true ); | |
| 687 | - $sender = get_user_by( 'login', $sender_username ); | |
| 686 | + $sender_username = get_post_meta( $message_post_id, '_sender', true ); | |
| 687 | + $sender = get_user_by( 'login', $sender_username ); | |
| 688 | 688 | |
| 689 | -        if( $sender_username && $sender instanceof WP_User ) { | |
| 690 | - $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); | |
| 691 | - ?> | |
| 689 | +		if( $sender_username && $sender instanceof WP_User ) { | |
| 690 | + $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); | |
| 691 | + ?> | |
| 692 | 692 | <p class="message-meta"> | 
| 693 | 693 | <small> | 
| 694 | 694 | <em> <?php echo $sender_display_name; ?> </em> | 
| @@ -696,18 +696,18 @@ discard block | ||
| 696 | 696 | </p> | 
| 697 | 697 | |
| 698 | 698 | <?php | 
| 699 | - } // end if | |
| 700 | - | |
| 701 | - } // end the_message_archive_sender | |
| 702 | - | |
| 703 | - /** | |
| 704 | - * Link to the users my messages page | |
| 705 | - * | |
| 706 | - * @since 1.9.0 | |
| 707 | - */ | |
| 708 | -    public static function the_my_messages_link(){ | |
| 709 | -        if( ! Sensei()->settings->get('messages_disable')  ) { | |
| 710 | - ?> | |
| 699 | + } // end if | |
| 700 | + | |
| 701 | + } // end the_message_archive_sender | |
| 702 | + | |
| 703 | + /** | |
| 704 | + * Link to the users my messages page | |
| 705 | + * | |
| 706 | + * @since 1.9.0 | |
| 707 | + */ | |
| 708 | +	public static function the_my_messages_link(){ | |
| 709 | +		if( ! Sensei()->settings->get('messages_disable')  ) { | |
| 710 | + ?> | |
| 711 | 711 | <p class="my-messages-link-container"> | 
| 712 | 712 | <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>" | 
| 713 | 713 | title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>"> | 
| @@ -715,8 +715,8 @@ discard block | ||
| 715 | 715 | </a> | 
| 716 | 716 | </p> | 
| 717 | 717 | <?php | 
| 718 | - } | |
| 719 | - } | |
| 718 | + } | |
| 719 | + } | |
| 720 | 720 | |
| 721 | 721 | } // End Class | 
| 722 | 722 | |
| @@ -33,10 +33,6 @@ discard block | ||
| 33 | 33 | * | 
| 34 | 34 | * | 
| 35 | 35 | * | 
| 36 | - * @param string $message | |
| 37 | - * @param string $type defaults to alert options( alert, tick , download , note ) | |
| 38 | - * | |
| 39 | - * @return void | |
| 40 | 36 | */ | 
| 41 | 37 | |
| 42 | 38 |  	public function add_notice( $content ,  $type = 'alert'   ){ | 
| @@ -47,10 +43,6 @@ discard block | ||
| 47 | 43 | /** | 
| 48 | 44 | * Output all notices added | 
| 49 | 45 | * | 
| 50 | - * @param string $message | |
| 51 | - * @param string $type | |
| 52 | - * | |
| 53 | - * @return void | |
| 54 | 46 | */ | 
| 55 | 47 | |
| 56 | 48 |  	public function print_notices(){ | 
| @@ -16,28 +16,28 @@ discard block | ||
| 16 | 16 |  class Sensei_Notices{ | 
| 17 | 17 | |
| 18 | 18 | /** | 
| 19 | - * @var $notices | |
| 20 | - */ | |
| 19 | + * @var $notices | |
| 20 | + */ | |
| 21 | 21 | protected $notices; | 
| 22 | 22 | |
| 23 | 23 | /** | 
| 24 | - * constructor | |
| 25 | - */ | |
| 24 | + * constructor | |
| 25 | + */ | |
| 26 | 26 |  	public function __construct(){ | 
| 27 | 27 | //initialize the notices variable | 
| 28 | 28 | $this->notices = array(); | 
| 29 | 29 | } | 
| 30 | 30 | |
| 31 | 31 | /** | 
| 32 | - * Add a notice to the array of notices for display at a later stage. | |
| 33 | - * | |
| 34 | - * | |
| 35 | - * | |
| 36 | - * @param string $message | |
| 37 | - * @param string $type defaults to alert options( alert, tick , download , note ) | |
| 38 | - * | |
| 39 | - * @return void | |
| 40 | - */ | |
| 32 | + * Add a notice to the array of notices for display at a later stage. | |
| 33 | + * | |
| 34 | + * | |
| 35 | + * | |
| 36 | + * @param string $message | |
| 37 | + * @param string $type defaults to alert options( alert, tick , download , note ) | |
| 38 | + * | |
| 39 | + * @return void | |
| 40 | + */ | |
| 41 | 41 | |
| 42 | 42 |  	public function add_notice( $content ,  $type = 'alert'   ){ | 
| 43 | 43 | // append the new notice | 
| @@ -45,13 +45,13 @@ discard block | ||
| 45 | 45 | } // end add_notice() | 
| 46 | 46 | |
| 47 | 47 | /** | 
| 48 | - * Output all notices added | |
| 49 | - * | |
| 50 | - * @param string $message | |
| 51 | - * @param string $type | |
| 52 | - * | |
| 53 | - * @return void | |
| 54 | - */ | |
| 48 | + * Output all notices added | |
| 49 | + * | |
| 50 | + * @param string $message | |
| 51 | + * @param string $type | |
| 52 | + * | |
| 53 | + * @return void | |
| 54 | + */ | |
| 55 | 55 | |
| 56 | 56 |  	public function print_notices(){ | 
| 57 | 57 |  		if(  count( $this->notices ) > 0  ){ | 
| @@ -68,10 +68,10 @@ discard block | ||
| 68 | 68 | } // end print_notice() | 
| 69 | 69 | |
| 70 | 70 | /** | 
| 71 | - * Clear all notices | |
| 72 | - * | |
| 73 | - * @return void | |
| 74 | - */ | |
| 71 | + * Clear all notices | |
| 72 | + * | |
| 73 | + * @return void | |
| 74 | + */ | |
| 75 | 75 | |
| 76 | 76 |  	public function clear_notices(){ | 
| 77 | 77 | // assign an empty array to clear all existing notices | 
| @@ -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 ){ | 
| @@ -21,7 +21,7 @@ discard block | ||
| 21 | 21 | * @since 1.0.0 | 
| 22 | 22 | */ | 
| 23 | 23 |  	public function __construct () { | 
| 24 | - $this->token = 'question'; | |
| 24 | + $this->token = 'question'; | |
| 25 | 25 | $this->question_types = $this->question_types(); | 
| 26 | 26 | $this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' ); | 
| 27 | 27 |  		if ( is_admin() ) { | 
| @@ -118,7 +118,7 @@ discard block | ||
| 118 | 118 | |
| 119 | 119 |  			if( isset( $post->ID ) ) { | 
| 120 | 120 | |
| 121 | - $question_type = Sensei()->question->get_question_type( $post->ID ); | |
| 121 | + $question_type = Sensei()->question->get_question_type( $post->ID ); | |
| 122 | 122 | |
| 123 | 123 |  				if( $question_type ) { | 
| 124 | 124 | $type = $this->question_types[ $question_type ]; | 
| @@ -238,15 +238,15 @@ discard block | ||
| 238 | 238 |  	public function save_question( $post_id = 0 ) { | 
| 239 | 239 | |
| 240 | 240 | if( ! isset( $_POST['post_type'] | 
| 241 | -            ) || 'question' != $_POST['post_type'] ) { | |
| 242 | - return; | |
| 243 | - } | |
| 241 | +			) || 'question' != $_POST['post_type'] ) { | |
| 242 | + return; | |
| 243 | + } | |
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | |
| 247 | - //setup the data for saving | |
| 247 | + //setup the data for saving | |
| 248 | 248 | $data = $_POST ; | 
| 249 | - $data['quiz_id'] = 0; | |
| 249 | + $data['quiz_id'] = 0; | |
| 250 | 250 | $data['question_id'] = $post_id; | 
| 251 | 251 | |
| 252 | 252 |  		if ( ! wp_is_post_revision( $post_id ) ){ | 
| @@ -340,34 +340,34 @@ discard block | ||
| 340 | 340 | return $request; | 
| 341 | 341 | } | 
| 342 | 342 | |
| 343 | - /** | |
| 344 | - * Get the type of question by id | |
| 345 | - * | |
| 346 | - * This function uses the post terms to determine which question type | |
| 347 | - * the passed question id belongs to. | |
| 348 | - * | |
| 349 | - * @since 1.7.4 | |
| 350 | - * | |
| 351 | - * @param int $question_id | |
| 352 | - * | |
| 353 | - * @return string $question_type | bool | |
| 354 | - */ | |
| 355 | -    public function get_question_type( $question_id ){ | |
| 356 | - | |
| 357 | - if( empty( $question_id ) || ! intval( $question_id ) > 0 | |
| 358 | -            || 'question' != get_post_type( $question_id )   ){ | |
| 359 | - return false; | |
| 360 | - } | |
| 361 | - | |
| 362 | - $question_type = 'multiple-choice'; | |
| 363 | - $question_types = wp_get_post_terms( $question_id, 'question-type' ); | |
| 364 | -        foreach( $question_types as $type ) { | |
| 365 | - $question_type = $type->slug; | |
| 366 | - } | |
| 367 | - | |
| 368 | - return $question_type; | |
| 369 | - | |
| 370 | - }// end get_question_type | |
| 343 | + /** | |
| 344 | + * Get the type of question by id | |
| 345 | + * | |
| 346 | + * This function uses the post terms to determine which question type | |
| 347 | + * the passed question id belongs to. | |
| 348 | + * | |
| 349 | + * @since 1.7.4 | |
| 350 | + * | |
| 351 | + * @param int $question_id | |
| 352 | + * | |
| 353 | + * @return string $question_type | bool | |
| 354 | + */ | |
| 355 | +	public function get_question_type( $question_id ){ | |
| 356 | + | |
| 357 | + if( empty( $question_id ) || ! intval( $question_id ) > 0 | |
| 358 | +			|| 'question' != get_post_type( $question_id )   ){ | |
| 359 | + return false; | |
| 360 | + } | |
| 361 | + | |
| 362 | + $question_type = 'multiple-choice'; | |
| 363 | + $question_types = wp_get_post_terms( $question_id, 'question-type' ); | |
| 364 | +		foreach( $question_types as $type ) { | |
| 365 | + $question_type = $type->slug; | |
| 366 | + } | |
| 367 | + | |
| 368 | + return $question_type; | |
| 369 | + | |
| 370 | + }// end get_question_type | |
| 371 | 371 | |
| 372 | 372 | /** | 
| 373 | 373 | * Given a question ID, return the grade that can be achieved. | 
| @@ -399,317 +399,317 @@ discard block | ||
| 399 | 399 | } // end get_question_grade | 
| 400 | 400 | |
| 401 | 401 | |
| 402 | - /** | |
| 403 | - * This function simply loads the question type template | |
| 404 | - * | |
| 405 | - * @since 1.9.0 | |
| 406 | - * @param $question_type | |
| 407 | - */ | |
| 408 | -    public static function load_question_template( $question_type ){ | |
| 409 | - | |
| 410 | - Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); | |
| 411 | - } | |
| 412 | - | |
| 413 | - /** | |
| 414 | - * Echo the sensei question title. | |
| 415 | - * | |
| 416 | - * @uses WooThemes_Sensei_Question::get_the_question_title | |
| 417 | - * | |
| 418 | - * @since 1.9.0 | |
| 419 | - * @param $question_id | |
| 420 | - */ | |
| 421 | -    public static function the_question_title( $question_id ){ | |
| 422 | - | |
| 423 | - echo self::get_the_question_title( $question_id ); | |
| 424 | - | |
| 425 | - }// end the_question_title | |
| 426 | - | |
| 427 | - /** | |
| 428 | - * Generate the question title with it's grade. | |
| 429 | - * | |
| 430 | - * @since 1.9.0 | |
| 431 | - * | |
| 432 | - * @param $question_id | |
| 433 | - * @return string | |
| 434 | - */ | |
| 435 | -    public static function get_the_question_title( $question_id ){ | |
| 436 | - | |
| 437 | - /** | |
| 438 | - * Filter the sensei question title | |
| 439 | - * | |
| 440 | - * @since 1.3.0 | |
| 441 | - * @param $question_title | |
| 442 | - */ | |
| 443 | - $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); | |
| 444 | - | |
| 445 | - /** | |
| 446 | - * hook document in class-woothemes-sensei-message.php the_title() | |
| 447 | - */ | |
| 448 | - $title = apply_filters( 'sensei_single_title', $title, 'question'); | |
| 449 | - | |
| 450 | - $title_html = '<span class="question question-title">'; | |
| 451 | - $title_html .= $title; | |
| 452 | - $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; | |
| 453 | - $title_html .='</span>'; | |
| 454 | - | |
| 455 | - return $title_html; | |
| 456 | - } | |
| 457 | - | |
| 458 | - /** | |
| 459 | - * Tech the question description | |
| 460 | - * | |
| 461 | - * @param $question_id | |
| 462 | - * @return string | |
| 463 | - */ | |
| 464 | -    public static function get_the_question_description( $question_id ){ | |
| 465 | - | |
| 466 | - $question = get_post( $question_id ); | |
| 467 | - | |
| 468 | - /** | |
| 469 | - * Already documented within WordPress Core | |
| 470 | - */ | |
| 471 | - return apply_filters( 'the_content', $question->post_content ); | |
| 472 | - | |
| 473 | - } | |
| 474 | - | |
| 475 | - /** | |
| 476 | - * Output the question description | |
| 477 | - * | |
| 478 | - * @since 1.9.0 | |
| 479 | - * @param $question_id | |
| 480 | - */ | |
| 481 | -    public static function the_question_description( $question_id  ){ | |
| 482 | - | |
| 483 | - echo self::get_the_question_description( $question_id ); | |
| 484 | - | |
| 485 | - } | |
| 486 | - | |
| 487 | - /** | |
| 488 | - * Get the questions media markup | |
| 489 | - * | |
| 490 | - * @since 1.9.0 | |
| 491 | - * @param $question_id | |
| 492 | - * @return string | |
| 493 | - */ | |
| 494 | -    public static function get_the_question_media( $question_id ){ | |
| 495 | - | |
| 496 | - $question_media = get_post_meta( $question_id, '_question_media', true ); | |
| 497 | - $question_media_link = ''; | |
| 498 | -        if( 0 < intval( $question_media ) ) { | |
| 499 | - $mimetype = get_post_mime_type( $question_media ); | |
| 500 | -            if( $mimetype ) { | |
| 501 | - $mimetype_array = explode( '/', $mimetype); | |
| 502 | -                if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { | |
| 503 | - $question_media_type = $mimetype_array[0]; | |
| 504 | - $question_media_url = wp_get_attachment_url( $question_media ); | |
| 505 | - $attachment = get_post( $question_media ); | |
| 506 | - $question_media_title = $attachment->post_title; | |
| 507 | - $question_media_description = $attachment->post_content; | |
| 508 | -                    switch( $question_media_type ) { | |
| 509 | - case 'image': | |
| 510 | - $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); | |
| 511 | - $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); | |
| 512 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; | |
| 513 | - break; | |
| 514 | - | |
| 515 | - case 'audio': | |
| 516 | - $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); | |
| 517 | - break; | |
| 518 | - | |
| 519 | - case 'video': | |
| 520 | - $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); | |
| 521 | - break; | |
| 522 | - | |
| 523 | - default: | |
| 524 | - $question_media_filename = basename( $question_media_url ); | |
| 525 | - $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; | |
| 526 | - break; | |
| 527 | - } | |
| 528 | - } | |
| 529 | - } | |
| 530 | - } | |
| 531 | - | |
| 532 | - $output = ''; | |
| 533 | -        if( $question_media_link ) { | |
| 534 | - | |
| 535 | - $output .= '<div class="question_media_display">'; | |
| 536 | - $output .= $question_media_link; | |
| 537 | - $output .= '<dl>'; | |
| 538 | - | |
| 539 | -                if( $question_media_title ) { | |
| 540 | - | |
| 541 | - $output .= '<dt>'. $question_media_title. '</dt>'; | |
| 542 | - | |
| 543 | - } | |
| 544 | - | |
| 545 | -                if( $question_media_description ) { | |
| 546 | - | |
| 547 | - $output .= '<dd>' . $question_media_description . '</dd>'; | |
| 548 | - | |
| 549 | - } | |
| 550 | - | |
| 551 | - $output .= '</dl>'; | |
| 552 | - $output .= '</div>'; | |
| 402 | + /** | |
| 403 | + * This function simply loads the question type template | |
| 404 | + * | |
| 405 | + * @since 1.9.0 | |
| 406 | + * @param $question_type | |
| 407 | + */ | |
| 408 | +	public static function load_question_template( $question_type ){ | |
| 409 | + | |
| 410 | + Sensei_Templates::get_template ( 'single-quiz/question_type-' . $question_type . '.php' ); | |
| 411 | + } | |
| 412 | + | |
| 413 | + /** | |
| 414 | + * Echo the sensei question title. | |
| 415 | + * | |
| 416 | + * @uses WooThemes_Sensei_Question::get_the_question_title | |
| 417 | + * | |
| 418 | + * @since 1.9.0 | |
| 419 | + * @param $question_id | |
| 420 | + */ | |
| 421 | +	public static function the_question_title( $question_id ){ | |
| 422 | + | |
| 423 | + echo self::get_the_question_title( $question_id ); | |
| 424 | + | |
| 425 | + }// end the_question_title | |
| 426 | + | |
| 427 | + /** | |
| 428 | + * Generate the question title with it's grade. | |
| 429 | + * | |
| 430 | + * @since 1.9.0 | |
| 431 | + * | |
| 432 | + * @param $question_id | |
| 433 | + * @return string | |
| 434 | + */ | |
| 435 | +	public static function get_the_question_title( $question_id ){ | |
| 436 | + | |
| 437 | + /** | |
| 438 | + * Filter the sensei question title | |
| 439 | + * | |
| 440 | + * @since 1.3.0 | |
| 441 | + * @param $question_title | |
| 442 | + */ | |
| 443 | + $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) ); | |
| 444 | + | |
| 445 | + /** | |
| 446 | + * hook document in class-woothemes-sensei-message.php the_title() | |
| 447 | + */ | |
| 448 | + $title = apply_filters( 'sensei_single_title', $title, 'question'); | |
| 449 | + | |
| 450 | + $title_html = '<span class="question question-title">'; | |
| 451 | + $title_html .= $title; | |
| 452 | + $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>'; | |
| 453 | + $title_html .='</span>'; | |
| 454 | + | |
| 455 | + return $title_html; | |
| 456 | + } | |
| 457 | + | |
| 458 | + /** | |
| 459 | + * Tech the question description | |
| 460 | + * | |
| 461 | + * @param $question_id | |
| 462 | + * @return string | |
| 463 | + */ | |
| 464 | +	public static function get_the_question_description( $question_id ){ | |
| 465 | + | |
| 466 | + $question = get_post( $question_id ); | |
| 467 | + | |
| 468 | + /** | |
| 469 | + * Already documented within WordPress Core | |
| 470 | + */ | |
| 471 | + return apply_filters( 'the_content', $question->post_content ); | |
| 472 | + | |
| 473 | + } | |
| 474 | + | |
| 475 | + /** | |
| 476 | + * Output the question description | |
| 477 | + * | |
| 478 | + * @since 1.9.0 | |
| 479 | + * @param $question_id | |
| 480 | + */ | |
| 481 | +	public static function the_question_description( $question_id  ){ | |
| 482 | + | |
| 483 | + echo self::get_the_question_description( $question_id ); | |
| 484 | + | |
| 485 | + } | |
| 486 | + | |
| 487 | + /** | |
| 488 | + * Get the questions media markup | |
| 489 | + * | |
| 490 | + * @since 1.9.0 | |
| 491 | + * @param $question_id | |
| 492 | + * @return string | |
| 493 | + */ | |
| 494 | +	public static function get_the_question_media( $question_id ){ | |
| 495 | + | |
| 496 | + $question_media = get_post_meta( $question_id, '_question_media', true ); | |
| 497 | + $question_media_link = ''; | |
| 498 | +		if( 0 < intval( $question_media ) ) { | |
| 499 | + $mimetype = get_post_mime_type( $question_media ); | |
| 500 | +			if( $mimetype ) { | |
| 501 | + $mimetype_array = explode( '/', $mimetype); | |
| 502 | +				if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) { | |
| 503 | + $question_media_type = $mimetype_array[0]; | |
| 504 | + $question_media_url = wp_get_attachment_url( $question_media ); | |
| 505 | + $attachment = get_post( $question_media ); | |
| 506 | + $question_media_title = $attachment->post_title; | |
| 507 | + $question_media_description = $attachment->post_content; | |
| 508 | +					switch( $question_media_type ) { | |
| 509 | + case 'image': | |
| 510 | + $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id ); | |
| 511 | + $attachment_src = wp_get_attachment_image_src( $question_media, $image_size ); | |
| 512 | + $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>'; | |
| 513 | + break; | |
| 514 | + | |
| 515 | + case 'audio': | |
| 516 | + $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) ); | |
| 517 | + break; | |
| 518 | + | |
| 519 | + case 'video': | |
| 520 | + $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) ); | |
| 521 | + break; | |
| 522 | + | |
| 523 | + default: | |
| 524 | + $question_media_filename = basename( $question_media_url ); | |
| 525 | + $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>'; | |
| 526 | + break; | |
| 527 | + } | |
| 528 | + } | |
| 529 | + } | |
| 530 | + } | |
| 531 | + | |
| 532 | + $output = ''; | |
| 533 | +		if( $question_media_link ) { | |
| 553 | 534 | |
| 535 | + $output .= '<div class="question_media_display">'; | |
| 536 | + $output .= $question_media_link; | |
| 537 | + $output .= '<dl>'; | |
| 554 | 538 | |
| 555 | - } | |
| 556 | - | |
| 557 | - return $output; | |
| 558 | - | |
| 559 | - } // end get_the_question_media | |
| 560 | - | |
| 539 | +				if( $question_media_title ) { | |
| 561 | 540 | |
| 562 | - /** | |
| 563 | - * Output the question media | |
| 564 | - * | |
| 565 | - * @since 1.9.0 | |
| 566 | - * @param string $question_id | |
| 567 | - */ | |
| 568 | -    public static function the_question_media( $question_id ){ | |
| 541 | + $output .= '<dt>'. $question_media_title. '</dt>'; | |
| 569 | 542 | |
| 570 | - echo self::get_the_question_media( $question_id ); | |
| 543 | + } | |
| 571 | 544 | |
| 572 | - } | |
| 545 | +				if( $question_media_description ) { | |
| 573 | 546 | |
| 574 | - /** | |
| 575 | - * Output a special field for the question needed for question submission. | |
| 576 | - * | |
| 577 | - * @since 1.9.0 | |
| 578 | - * | |
| 579 | - * @param $question_id | |
| 580 | - */ | |
| 581 | -    public static function the_question_hidden_fields( $question_id ){ | |
| 582 | - ?> | |
| 547 | + $output .= '<dd>' . $question_media_description . '</dd>'; | |
| 548 | + | |
| 549 | + } | |
| 550 | + | |
| 551 | + $output .= '</dl>'; | |
| 552 | + $output .= '</div>'; | |
| 553 | + | |
| 554 | + | |
| 555 | + } | |
| 556 | + | |
| 557 | + return $output; | |
| 558 | + | |
| 559 | + } // end get_the_question_media | |
| 560 | + | |
| 561 | + | |
| 562 | + /** | |
| 563 | + * Output the question media | |
| 564 | + * | |
| 565 | + * @since 1.9.0 | |
| 566 | + * @param string $question_id | |
| 567 | + */ | |
| 568 | +	public static function the_question_media( $question_id ){ | |
| 569 | + | |
| 570 | + echo self::get_the_question_media( $question_id ); | |
| 571 | + | |
| 572 | + } | |
| 573 | + | |
| 574 | + /** | |
| 575 | + * Output a special field for the question needed for question submission. | |
| 576 | + * | |
| 577 | + * @since 1.9.0 | |
| 578 | + * | |
| 579 | + * @param $question_id | |
| 580 | + */ | |
| 581 | +	public static function the_question_hidden_fields( $question_id ){ | |
| 582 | + ?> | |
| 583 | 583 | |
| 584 | 584 | <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" /> | 
| 585 | 585 | <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" /> | 
| 586 | 586 | |
| 587 | 587 | <?php | 
| 588 | - } | |
| 588 | + } | |
| 589 | 589 | |
| 590 | - /** | |
| 591 | - * This function can only be run withing the single quiz question loop | |
| 592 | - * | |
| 593 | - * @since 1.9.0 | |
| 594 | - * @param $question_id | |
| 595 | - */ | |
| 596 | -    public static function answer_feedback_notes( $question_id ){ | |
| 590 | + /** | |
| 591 | + * This function can only be run withing the single quiz question loop | |
| 592 | + * | |
| 593 | + * @since 1.9.0 | |
| 594 | + * @param $question_id | |
| 595 | + */ | |
| 596 | +	public static function answer_feedback_notes( $question_id ){ | |
| 597 | 597 | |
| 598 | - //IDS | |
| 599 | - $quiz_id = get_the_ID(); | |
| 600 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 598 | + //IDS | |
| 599 | + $quiz_id = get_the_ID(); | |
| 600 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 601 | 601 | |
| 602 | - // Data to check before showing feedback | |
| 603 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); | |
| 604 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 605 | - $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); | |
| 606 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); | |
| 607 | - $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); | |
| 608 | - $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); | |
| 602 | + // Data to check before showing feedback | |
| 603 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() ); | |
| 604 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 605 | + $not_empty_user_quiz_grade = !empty( $user_quiz_grade ); | |
| 606 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); | |
| 607 | + $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id ); | |
| 608 | + $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true ); | |
| 609 | 609 | |
| 610 | - if( ( $lesson_completed && $not_empty_user_quiz_grade ) | |
| 611 | - || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) | |
| 612 | -            || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { | |
| 610 | + if( ( $lesson_completed && $not_empty_user_quiz_grade ) | |
| 611 | + || ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type ) | |
| 612 | +			|| ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) { | |
| 613 | 613 | |
| 614 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); | |
| 614 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() ); | |
| 615 | 615 | |
| 616 | -            if( $answer_notes ) { ?> | |
| 616 | +			if( $answer_notes ) { ?> | |
| 617 | 617 | |
| 618 | 618 | <div class="sensei-message info info-special answer-feedback"> | 
| 619 | 619 | |
| 620 | 620 | <?php | 
| 621 | 621 | |
| 622 | - /** | |
| 623 | - * Filter the answer feedback | |
| 624 | - * Since 1.9.0 | |
| 625 | - * | |
| 626 | - * @param string $answer_notes | |
| 627 | - * @param string $question_id | |
| 628 | - * @param string $lesson_id | |
| 629 | - */ | |
| 630 | - echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); | |
| 622 | + /** | |
| 623 | + * Filter the answer feedback | |
| 624 | + * Since 1.9.0 | |
| 625 | + * | |
| 626 | + * @param string $answer_notes | |
| 627 | + * @param string $question_id | |
| 628 | + * @param string $lesson_id | |
| 629 | + */ | |
| 630 | + echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ); | |
| 631 | 631 | |
| 632 | - ?> | |
| 632 | + ?> | |
| 633 | 633 | |
| 634 | 634 | </div> | 
| 635 | 635 | |
| 636 | 636 | <?php } | 
| 637 | 637 | |
| 638 | - }// end if we can show answer feedback | |
| 638 | + }// end if we can show answer feedback | |
| 639 | 639 | |
| 640 | - }// end answer_feedback_notes | |
| 640 | + }// end answer_feedback_notes | |
| 641 | 641 | |
| 642 | - /** | |
| 643 | - * This function has to be run inside the quiz question loop on the single quiz page. | |
| 644 | - * | |
| 645 | - * | |
| 646 | - * @since 1.9.0 | |
| 647 | - * @param string $question_id | |
| 648 | - */ | |
| 649 | -    public static function the_answer_result_indication( $question_id ){ | |
| 642 | + /** | |
| 643 | + * This function has to be run inside the quiz question loop on the single quiz page. | |
| 644 | + * | |
| 645 | + * | |
| 646 | + * @since 1.9.0 | |
| 647 | + * @param string $question_id | |
| 648 | + */ | |
| 649 | +	public static function the_answer_result_indication( $question_id ){ | |
| 650 | 650 | |
| 651 | - global $post, $current_user, $sensei_question_loop; | |
| 651 | + global $post, $current_user, $sensei_question_loop; | |
| 652 | 652 | |
| 653 | - // Post Data | |
| 654 | - $quiz_id = $sensei_question_loop['quiz_id']; | |
| 655 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 656 | - $question_item = $sensei_question_loop['current_question']; | |
| 653 | + // Post Data | |
| 654 | + $quiz_id = $sensei_question_loop['quiz_id']; | |
| 655 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 656 | + $question_item = $sensei_question_loop['current_question']; | |
| 657 | 657 | |
| 658 | - // Setup variable needed to determine if the message should show and what it should show | |
| 659 | - $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 660 | - $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); | |
| 661 | - $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); | |
| 662 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 658 | + // Setup variable needed to determine if the message should show and what it should show | |
| 659 | + $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 660 | + $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); | |
| 661 | + $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id ); | |
| 662 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 663 | 663 | |
| 664 | - // retrieve the question total grade | |
| 665 | - $question_grade = Sensei()->question->get_question_grade( $question_id ); | |
| 664 | + // retrieve the question total grade | |
| 665 | + $question_grade = Sensei()->question->get_question_grade( $question_id ); | |
| 666 | 666 | |
| 667 | - // retrieve grade the user achieved | |
| 668 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); | |
| 667 | + // retrieve grade the user achieved | |
| 668 | + $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() ); | |
| 669 | 669 | |
| 670 | - // Question ID | |
| 671 | - $question_id = $question_item->ID; | |
| 670 | + // Question ID | |
| 671 | + $question_id = $question_item->ID; | |
| 672 | 672 | |
| 673 | - // conditions to check | |
| 674 | - $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; | |
| 675 | - $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; | |
| 676 | - $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; | |
| 673 | + // conditions to check | |
| 674 | + $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ; | |
| 675 | + $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed ; | |
| 676 | + $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ; | |
| 677 | 677 | |
| 678 | - if ( $completed_with_valid_grade | |
| 679 | - || $completed_with_valid_grade_and_reset_not_allowed | |
| 680 | -            || $grade_type_auto_a_valid_grade_and_reset_not_allowed  ) { | |
| 678 | + if ( $completed_with_valid_grade | |
| 679 | + || $completed_with_valid_grade_and_reset_not_allowed | |
| 680 | +			|| $grade_type_auto_a_valid_grade_and_reset_not_allowed  ) { | |
| 681 | 681 | |
| 682 | - $user_correct = false; | |
| 683 | - $answer_message = __( 'Incorrect', 'woothemes-sensei' ); | |
| 684 | - $answer_message_class = 'user_wrong'; | |
| 685 | - // For zero grade mark as 'correct' but add no classes | |
| 686 | -            if ( 0 == $question_grade ) { | |
| 682 | + $user_correct = false; | |
| 683 | + $answer_message = __( 'Incorrect', 'woothemes-sensei' ); | |
| 684 | + $answer_message_class = 'user_wrong'; | |
| 685 | + // For zero grade mark as 'correct' but add no classes | |
| 686 | +			if ( 0 == $question_grade ) { | |
| 687 | 687 | |
| 688 | - $user_correct = true; | |
| 689 | - $answer_message = ''; | |
| 690 | - $answer_message_class = ''; | |
| 688 | + $user_correct = true; | |
| 689 | + $answer_message = ''; | |
| 690 | + $answer_message_class = ''; | |
| 691 | 691 | |
| 692 | -            } else if( $user_question_grade > 0 ) { | |
| 692 | +			} else if( $user_question_grade > 0 ) { | |
| 693 | 693 | |
| 694 | - $user_correct = true; | |
| 695 | - $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); | |
| 696 | - $answer_message_class = 'user_right'; | |
| 694 | + $user_correct = true; | |
| 695 | + $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade ); | |
| 696 | + $answer_message_class = 'user_right'; | |
| 697 | 697 | |
| 698 | - } | |
| 698 | + } | |
| 699 | 699 | |
| 700 | - // attach the correct answer if the question is auto gradable and user got it wrong | |
| 701 | -            if( !$reset_quiz_allowed && !$user_correct ){ | |
| 700 | + // attach the correct answer if the question is auto gradable and user got it wrong | |
| 701 | +			if( !$reset_quiz_allowed && !$user_correct ){ | |
| 702 | 702 | |
| 703 | -                $answer_message .=  ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); | |
| 703 | +				$answer_message .=  ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID ); | |
| 704 | 704 | |
| 705 | - } | |
| 705 | + } | |
| 706 | 706 | |
| 707 | - // answer feedback | |
| 708 | - $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); | |
| 709 | -            if( $answer_notes ) { | |
| 710 | - $answer_message_class .= ' has_notes'; | |
| 711 | - } | |
| 712 | - ?> | |
| 707 | + // answer feedback | |
| 708 | + $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID ); | |
| 709 | +			if( $answer_notes ) { | |
| 710 | + $answer_message_class .= ' has_notes'; | |
| 711 | + } | |
| 712 | + ?> | |
| 713 | 713 | |
| 714 | 714 | <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>"> | 
| 715 | 715 | |
| @@ -719,387 +719,387 @@ discard block | ||
| 719 | 719 | |
| 720 | 720 | <?php | 
| 721 | 721 | |
| 722 | - } // end if user can see all the goodies | |
| 723 | - | |
| 724 | - }// end the_answer_result_indication | |
| 725 | - | |
| 726 | - /** | |
| 727 | - * Generate the question template data and return it as an array. | |
| 728 | - * | |
| 729 | - * @since 1.9.0 | |
| 730 | - * | |
| 731 | - * @param string $question_id | |
| 732 | - * @param $quiz_id | |
| 733 | - * @return array $question_data | |
| 734 | - */ | |
| 735 | -    public static function get_template_data( $question_id, $quiz_id ){ | |
| 736 | - | |
| 737 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 738 | - | |
| 739 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); | |
| 740 | - //backwards compatibility | |
| 741 | -        if( 'on' == $reset_allowed ) { | |
| 742 | - $reset_allowed = 1; | |
| 743 | - } | |
| 744 | - | |
| 745 | - // Check again that the lesson is complete | |
| 746 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); | |
| 747 | - $user_lesson_complete = false; | |
| 748 | -        if ( $user_lesson_end ) { | |
| 749 | - $user_lesson_complete = true; | |
| 750 | - } | |
| 751 | - | |
| 752 | - //setup the question data | |
| 753 | - $data[ 'ID' ] = $question_id; | |
| 754 | - $data[ 'title' ] = get_the_title( $question_id ); | |
| 755 | - $data[ 'content' ] = get_post( $question_id )->post_content; | |
| 756 | - $data[ 'quiz_id' ] = $quiz_id; | |
| 757 | - $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 758 | - $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); | |
| 759 | - $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); | |
| 760 | - $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); | |
| 761 | - $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); | |
| 762 | - $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); | |
| 763 | - $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); | |
| 764 | - $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); | |
| 765 | - $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); | |
| 766 | - $data[ 'reset_quiz_allowed' ] = $reset_allowed; | |
| 767 | - $data[ 'lesson_complete' ] = $user_lesson_complete; | |
| 768 | - | |
| 769 | - /** | |
| 770 | - * Filter the question template data. This filter fires in | |
| 771 | - * the get_template_data function | |
| 772 | - * | |
| 773 | - * @hooked self::boolean_load_question_data | |
| 774 | - * | |
| 775 | - * @since 1.9.0 | |
| 776 | - * | |
| 777 | - * @param array $data | |
| 778 | - * @param string $question_id | |
| 779 | - * @param string $quiz_id | |
| 780 | - */ | |
| 781 | - return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); | |
| 722 | + } // end if user can see all the goodies | |
| 782 | 723 | |
| 783 | - } | |
| 724 | + }// end the_answer_result_indication | |
| 784 | 725 | |
| 785 | - /** | |
| 786 | - * Load multiple choice question data on the sensei_get_question_template_data | |
| 787 | - * filter. | |
| 788 | - * | |
| 789 | - * @since 1.9.0 | |
| 790 | - * | |
| 791 | - * @param $question_data | |
| 792 | - * @param $question_id | |
| 793 | - * @param $quiz_id | |
| 794 | - * | |
| 795 | - * @return array() | |
| 796 | - */ | |
| 797 | -    public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ | |
| 726 | + /** | |
| 727 | + * Generate the question template data and return it as an array. | |
| 728 | + * | |
| 729 | + * @since 1.9.0 | |
| 730 | + * | |
| 731 | + * @param string $question_id | |
| 732 | + * @param $quiz_id | |
| 733 | + * @return array $question_data | |
| 734 | + */ | |
| 735 | +	public static function get_template_data( $question_id, $quiz_id ){ | |
| 798 | 736 | |
| 737 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 799 | 738 | |
| 800 | -        if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { | |
| 739 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); | |
| 740 | + //backwards compatibility | |
| 741 | +		if( 'on' == $reset_allowed ) { | |
| 742 | + $reset_allowed = 1; | |
| 743 | + } | |
| 801 | 744 | |
| 802 | - // Get uploaded file | |
| 803 | - $attachment_id = $question_data[ 'user_answer_entry' ]; | |
| 804 | - $answer_media_url = $answer_media_filename = ''; | |
| 745 | + // Check again that the lesson is complete | |
| 746 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() ); | |
| 747 | + $user_lesson_complete = false; | |
| 748 | +		if ( $user_lesson_end ) { | |
| 749 | + $user_lesson_complete = true; | |
| 750 | + } | |
| 805 | 751 | |
| 752 | + //setup the question data | |
| 753 | + $data[ 'ID' ] = $question_id; | |
| 754 | + $data[ 'title' ] = get_the_title( $question_id ); | |
| 755 | + $data[ 'content' ] = get_post( $question_id )->post_content; | |
| 756 | + $data[ 'quiz_id' ] = $quiz_id; | |
| 757 | + $data[ 'lesson_id' ] = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 758 | + $data[ 'type' ] = Sensei()->question->get_question_type( $question_id ); | |
| 759 | + $data[ 'question_grade' ] = Sensei()->question->get_question_grade( $question_id ); | |
| 760 | + $data[ 'user_question_grade' ] = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id , get_current_user_id()); | |
| 761 | + $data[ 'question_right_answer' ] = get_post_meta( $question_id , '_question_right_answer', true ); | |
| 762 | + $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true ); | |
| 763 | + $data[ 'user_answer_entry' ] = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id , get_current_user_id() ); | |
| 764 | + $data[ 'lesson_completed' ] = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) ); | |
| 765 | + $data[ 'quiz_grade_type' ] = get_post_meta( $quiz_id , '_quiz_grade_type', true ); | |
| 766 | + $data[ 'reset_quiz_allowed' ] = $reset_allowed; | |
| 767 | + $data[ 'lesson_complete' ] = $user_lesson_complete; | |
| 768 | + | |
| 769 | + /** | |
| 770 | + * Filter the question template data. This filter fires in | |
| 771 | + * the get_template_data function | |
| 772 | + * | |
| 773 | + * @hooked self::boolean_load_question_data | |
| 774 | + * | |
| 775 | + * @since 1.9.0 | |
| 776 | + * | |
| 777 | + * @param array $data | |
| 778 | + * @param string $question_id | |
| 779 | + * @param string $quiz_id | |
| 780 | + */ | |
| 781 | + return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id ); | |
| 806 | 782 | |
| 807 | - $question_helptext = ''; | |
| 808 | -            if( isset( $question_data['question_wrong_answers'][0] ) ) { | |
| 783 | + } | |
| 809 | 784 | |
| 810 | - $question_helptext = $question_data['question_wrong_answers'][0]; | |
| 785 | + /** | |
| 786 | + * Load multiple choice question data on the sensei_get_question_template_data | |
| 787 | + * filter. | |
| 788 | + * | |
| 789 | + * @since 1.9.0 | |
| 790 | + * | |
| 791 | + * @param $question_data | |
| 792 | + * @param $question_id | |
| 793 | + * @param $quiz_id | |
| 794 | + * | |
| 795 | + * @return array() | |
| 796 | + */ | |
| 797 | +	public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){ | |
| 811 | 798 | |
| 812 | - } | |
| 813 | 799 | |
| 800 | +		if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) { | |
| 814 | 801 | |
| 815 | -            if( 0 < intval( $attachment_id ) ) { | |
| 802 | + // Get uploaded file | |
| 803 | + $attachment_id = $question_data[ 'user_answer_entry' ]; | |
| 804 | + $answer_media_url = $answer_media_filename = ''; | |
| 816 | 805 | |
| 817 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); | |
| 818 | - $answer_media_filename = basename( $answer_media_url ); | |
| 819 | 806 | |
| 820 | - } | |
| 807 | + $question_helptext = ''; | |
| 808 | +			if( isset( $question_data['question_wrong_answers'][0] ) ) { | |
| 821 | 809 | |
| 810 | + $question_helptext = $question_data['question_wrong_answers'][0]; | |
| 822 | 811 | |
| 823 | - // Get max upload file size, formatted for display | |
| 824 | - // Code copied from wp-admin/includes/media.php:1515 | |
| 825 | - $upload_size_unit = $max_upload_size = wp_max_upload_size(); | |
| 826 | - $sizes = array( 'KB', 'MB', 'GB' ); | |
| 827 | -            for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { | |
| 828 | - $upload_size_unit /= 1024; | |
| 829 | - } | |
| 830 | -            if ( $u < 0 ) { | |
| 812 | + } | |
| 831 | 813 | |
| 832 | - $upload_size_unit = 0; | |
| 833 | - $u = 0; | |
| 834 | 814 | |
| 835 | -            } else { | |
| 815 | +			if( 0 < intval( $attachment_id ) ) { | |
| 836 | 816 | |
| 837 | - $upload_size_unit = (int) $upload_size_unit; | |
| 817 | + $answer_media_url = wp_get_attachment_url( $attachment_id ); | |
| 818 | + $answer_media_filename = basename( $answer_media_url ); | |
| 838 | 819 | |
| 839 | - } | |
| 840 | - $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); | |
| 820 | + } | |
| 841 | 821 | |
| 842 | - // Assemble all the data needed by the file upload template | |
| 843 | - $question_data[ 'answer_media_url' ] = $answer_media_url; | |
| 844 | - $question_data[ 'answer_media_filename' ] = $answer_media_filename; | |
| 845 | - $question_data[ 'max_upload_size' ] = $max_upload_size; | |
| 846 | 822 | |
| 847 | - $question_data[ 'question_helptext' ] = $question_helptext; | |
| 823 | + // Get max upload file size, formatted for display | |
| 824 | + // Code copied from wp-admin/includes/media.php:1515 | |
| 825 | + $upload_size_unit = $max_upload_size = wp_max_upload_size(); | |
| 826 | + $sizes = array( 'KB', 'MB', 'GB' ); | |
| 827 | +			for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { | |
| 828 | + $upload_size_unit /= 1024; | |
| 829 | + } | |
| 830 | +			if ( $u < 0 ) { | |
| 848 | 831 | |
| 849 | - }// end if is file upload type | |
| 832 | + $upload_size_unit = 0; | |
| 833 | + $u = 0; | |
| 850 | 834 | |
| 851 | - return $question_data; | |
| 835 | +			} else { | |
| 852 | 836 | |
| 853 | - }// end file_upload_load_question_data | |
| 837 | + $upload_size_unit = (int) $upload_size_unit; | |
| 854 | 838 | |
| 855 | - /** | |
| 856 | - * Load multiple choice question data on the sensei_get_question_template_data | |
| 857 | - * filter. | |
| 858 | - * | |
| 859 | - * @since 1.9.0 | |
| 860 | - * | |
| 861 | - * @param $question_data | |
| 862 | - * @param $question_id | |
| 863 | - * @param $quiz_id | |
| 864 | - * | |
| 865 | - * @return array() | |
| 866 | - */ | |
| 867 | -    public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ | |
| 839 | + } | |
| 840 | + $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) ); | |
| 868 | 841 | |
| 869 | -        if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { | |
| 842 | + // Assemble all the data needed by the file upload template | |
| 843 | + $question_data[ 'answer_media_url' ] = $answer_media_url; | |
| 844 | + $question_data[ 'answer_media_filename' ] = $answer_media_filename; | |
| 845 | + $question_data[ 'max_upload_size' ] = $max_upload_size; | |
| 870 | 846 | |
| 847 | + $question_data[ 'question_helptext' ] = $question_helptext; | |
| 871 | 848 | |
| 872 | - $answer_type = 'radio'; | |
| 873 | -            if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { | |
| 849 | + }// end if is file upload type | |
| 874 | 850 | |
| 875 | - $answer_type = 'checkbox'; | |
| 851 | + return $question_data; | |
| 876 | 852 | |
| 877 | - } | |
| 853 | + }// end file_upload_load_question_data | |
| 878 | 854 | |
| 879 | - // Merge right and wrong answers | |
| 880 | -            if ( is_array( $question_data[ 'question_right_answer' ] ) ) { | |
| 855 | + /** | |
| 856 | + * Load multiple choice question data on the sensei_get_question_template_data | |
| 857 | + * filter. | |
| 858 | + * | |
| 859 | + * @since 1.9.0 | |
| 860 | + * | |
| 861 | + * @param $question_data | |
| 862 | + * @param $question_id | |
| 863 | + * @param $quiz_id | |
| 864 | + * | |
| 865 | + * @return array() | |
| 866 | + */ | |
| 867 | +	public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){ | |
| 881 | 868 | |
| 882 | - $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); | |
| 869 | +		if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) { | |
| 883 | 870 | |
| 884 | -            }  else { | |
| 885 | 871 | |
| 886 | - array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); | |
| 887 | - $merged_options = $question_data[ 'question_wrong_answers' ]; | |
| 872 | + $answer_type = 'radio'; | |
| 873 | +			if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) { | |
| 888 | 874 | |
| 889 | - } | |
| 875 | + $answer_type = 'checkbox'; | |
| 890 | 876 | |
| 891 | - // Setup answer options array. | |
| 892 | - $question_answers_options = array(); | |
| 893 | - $count = 0; | |
| 877 | + } | |
| 894 | 878 | |
| 895 | -            foreach( $merged_options as $answer ) { | |
| 879 | + // Merge right and wrong answers | |
| 880 | +			if ( is_array( $question_data[ 'question_right_answer' ] ) ) { | |
| 896 | 881 | |
| 897 | - $count++; | |
| 898 | - $question_option = array(); | |
| 882 | + $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); | |
| 899 | 883 | |
| 900 | - if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) | |
| 901 | - || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) | |
| 902 | -                    || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ]  && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { | |
| 884 | +			}  else { | |
| 903 | 885 | |
| 904 | - $user_correct = false; | |
| 886 | + array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] ); | |
| 887 | + $merged_options = $question_data[ 'question_wrong_answers' ]; | |
| 905 | 888 | |
| 889 | + } | |
| 906 | 890 | |
| 907 | - // For zero grade mark as 'correct' but add no classes | |
| 908 | -                    if ( 0 == $question_data[ 'question_grade' ] ) { | |
| 891 | + // Setup answer options array. | |
| 892 | + $question_answers_options = array(); | |
| 893 | + $count = 0; | |
| 909 | 894 | |
| 910 | - $user_correct = true; | |
| 895 | +			foreach( $merged_options as $answer ) { | |
| 911 | 896 | |
| 912 | -                    }  else if( $question_data[ 'user_question_grade' ] > 0 ) { | |
| 897 | + $count++; | |
| 898 | + $question_option = array(); | |
| 913 | 899 | |
| 914 | - $user_correct = true; | |
| 900 | + if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' ) | |
| 901 | + || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' ) | |
| 902 | +					|| ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ]  && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) { | |
| 915 | 903 | |
| 916 | - } | |
| 904 | + $user_correct = false; | |
| 917 | 905 | |
| 918 | - } | |
| 919 | 906 | |
| 920 | - // setup the option specific classes | |
| 921 | - $answer_class = ''; | |
| 922 | -                if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { | |
| 923 | -                    if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { | |
| 907 | + // For zero grade mark as 'correct' but add no classes | |
| 908 | +					if ( 0 == $question_data[ 'question_grade' ] ) { | |
| 924 | 909 | |
| 925 | - $answer_class .= ' right_answer'; | |
| 910 | + $user_correct = true; | |
| 926 | 911 | |
| 927 | -                    }  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { | |
| 912 | +					}  else if( $question_data[ 'user_question_grade' ] > 0 ) { | |
| 928 | 913 | |
| 929 | - $answer_class .= ' right_answer'; | |
| 914 | + $user_correct = true; | |
| 930 | 915 | |
| 931 | - } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) | |
| 932 | -                        ||  ( !  $question_data['user_answer_entry'] &&  $question_data['user_answer_entry'] == $answer ) ) { | |
| 916 | + } | |
| 933 | 917 | |
| 934 | - $answer_class = 'user_wrong'; | |
| 935 | -                        if( $user_correct ) { | |
| 918 | + } | |
| 936 | 919 | |
| 937 | - $answer_class = 'user_right'; | |
| 920 | + // setup the option specific classes | |
| 921 | + $answer_class = ''; | |
| 922 | +				if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) { | |
| 923 | +					if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) { | |
| 938 | 924 | |
| 939 | - } | |
| 925 | + $answer_class .= ' right_answer'; | |
| 940 | 926 | |
| 941 | - } | |
| 927 | +					}  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) { | |
| 942 | 928 | |
| 943 | - } | |
| 929 | + $answer_class .= ' right_answer'; | |
| 944 | 930 | |
| 945 | - // determine if the current option must be checked | |
| 946 | - $checked = ''; | |
| 947 | -                if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { | |
| 948 | -                    if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { | |
| 931 | + } elseif( ( is_array( $question_data['user_answer_entry'] ) && in_array($answer, $question_data['user_answer_entry'] ) ) | |
| 932 | +						||  ( !  $question_data['user_answer_entry'] &&  $question_data['user_answer_entry'] == $answer ) ) { | |
| 949 | 933 | |
| 950 | - $checked = 'checked="checked"'; | |
| 934 | + $answer_class = 'user_wrong'; | |
| 935 | +						if( $user_correct ) { | |
| 951 | 936 | |
| 952 | -                    } elseif ( !is_array( $question_data['user_answer_entry'] ) ) { | |
| 937 | + $answer_class = 'user_right'; | |
| 953 | 938 | |
| 954 | - $checked = checked( $answer, $question_data['user_answer_entry'] , false ); | |
| 939 | + } | |
| 955 | 940 | |
| 956 | - } | |
| 941 | + } | |
| 957 | 942 | |
| 958 | - } // End If Statement | |
| 943 | + } | |
| 959 | 944 | |
| 960 | - //Load the answer option data | |
| 961 | - $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); | |
| 962 | - $question_option[ 'answer' ] = $answer; | |
| 963 | - $question_option[ 'option_class'] = $answer_class; | |
| 964 | - $question_option[ 'checked'] = $checked; | |
| 965 | - $question_option[ 'count' ] = $count; | |
| 966 | - $question_option[ 'type' ] = $answer_type; | |
| 945 | + // determine if the current option must be checked | |
| 946 | + $checked = ''; | |
| 947 | +				if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) { | |
| 948 | +					if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) { | |
| 967 | 949 | |
| 968 | - // add the speci fic option to the list of options for this question | |
| 969 | - $question_answers_options[] = $question_option; | |
| 950 | + $checked = 'checked="checked"'; | |
| 970 | 951 | |
| 971 | - } // end for each option | |
| 952 | +					} elseif ( !is_array( $question_data['user_answer_entry'] ) ) { | |
| 972 | 953 | |
| 954 | + $checked = checked( $answer, $question_data['user_answer_entry'] , false ); | |
| 973 | 955 | |
| 974 | - // Shuffle the array depending on the settings | |
| 975 | - $answer_options_sorted = array(); | |
| 976 | - $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); | |
| 977 | -            if(  $random_order && $random_order == 'yes' ) { | |
| 956 | + } | |
| 978 | 957 | |
| 979 | - $answer_options_sorted = $question_answers_options; | |
| 980 | - shuffle( $answer_options_sorted ); | |
| 958 | + } // End If Statement | |
| 981 | 959 | |
| 982 | -            } else { | |
| 960 | + //Load the answer option data | |
| 961 | + $question_option[ 'ID' ] = Sensei()->lesson->get_answer_id( $answer ); | |
| 962 | + $question_option[ 'answer' ] = $answer; | |
| 963 | + $question_option[ 'option_class'] = $answer_class; | |
| 964 | + $question_option[ 'checked'] = $checked; | |
| 965 | + $question_option[ 'count' ] = $count; | |
| 966 | + $question_option[ 'type' ] = $answer_type; | |
| 983 | 967 | |
| 984 | - $answer_order = array(); | |
| 985 | - $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); | |
| 986 | -                if( $answer_order_string ) { | |
| 968 | + // add the speci fic option to the list of options for this question | |
| 969 | + $question_answers_options[] = $question_option; | |
| 987 | 970 | |
| 988 | - $answer_order = array_filter( explode( ',', $answer_order_string ) ); | |
| 989 | -                    if( count( $answer_order ) > 0 ) { | |
| 971 | + } // end for each option | |
| 990 | 972 | |
| 991 | -                        foreach( $answer_order as $answer_id ) { | |
| 992 | 973 | |
| 993 | -                            if( isset( $question_answers_options[ $answer_id ] ) ) { | |
| 974 | + // Shuffle the array depending on the settings | |
| 975 | + $answer_options_sorted = array(); | |
| 976 | + $random_order = get_post_meta( $question_data['ID'], '_random_order', true ); | |
| 977 | +			if(  $random_order && $random_order == 'yes' ) { | |
| 994 | 978 | |
| 995 | - $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; | |
| 996 | - unset( $question_answers_options[ $answer_id ] ); | |
| 979 | + $answer_options_sorted = $question_answers_options; | |
| 980 | + shuffle( $answer_options_sorted ); | |
| 997 | 981 | |
| 998 | - } | |
| 982 | +			} else { | |
| 999 | 983 | |
| 1000 | - } | |
| 984 | + $answer_order = array(); | |
| 985 | + $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true ); | |
| 986 | +				if( $answer_order_string ) { | |
| 1001 | 987 | |
| 1002 | -                        if( count( $question_answers_options ) > 0 ) { | |
| 1003 | -                            foreach( $question_answers_options as $id => $answer ) { | |
| 988 | + $answer_order = array_filter( explode( ',', $answer_order_string ) ); | |
| 989 | +					if( count( $answer_order ) > 0 ) { | |
| 1004 | 990 | |
| 1005 | - $answer_options_sorted[ $id ] = $answer; | |
| 991 | +						foreach( $answer_order as $answer_id ) { | |
| 1006 | 992 | |
| 1007 | - } | |
| 1008 | - } | |
| 993 | +							if( isset( $question_answers_options[ $answer_id ] ) ) { | |
| 1009 | 994 | |
| 1010 | -                    }else{ | |
| 995 | + $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ]; | |
| 996 | + unset( $question_answers_options[ $answer_id ] ); | |
| 1011 | 997 | |
| 1012 | - $answer_options_sorted = $question_answers_options; | |
| 998 | + } | |
| 1013 | 999 | |
| 1014 | - } | |
| 1000 | + } | |
| 1015 | 1001 | |
| 1016 | -                }else{ | |
| 1002 | +						if( count( $question_answers_options ) > 0 ) { | |
| 1003 | +							foreach( $question_answers_options as $id => $answer ) { | |
| 1017 | 1004 | |
| 1018 | - $answer_options_sorted = $question_answers_options; | |
| 1005 | + $answer_options_sorted[ $id ] = $answer; | |
| 1019 | 1006 | |
| 1020 | - } // end if $answer_order_string | |
| 1007 | + } | |
| 1008 | + } | |
| 1021 | 1009 | |
| 1022 | - } // end if random order | |
| 1010 | +					}else{ | |
| 1023 | 1011 | |
| 1012 | + $answer_options_sorted = $question_answers_options; | |
| 1024 | 1013 | |
| 1025 | - // assemble and setup the data for the templates data array | |
| 1026 | - $question_data[ 'answer_options' ] = $answer_options_sorted; | |
| 1014 | + } | |
| 1027 | 1015 | |
| 1028 | - } | |
| 1016 | +				}else{ | |
| 1029 | 1017 | |
| 1030 | - return $question_data; | |
| 1018 | + $answer_options_sorted = $question_answers_options; | |
| 1031 | 1019 | |
| 1032 | - }// end multiple_choice_load_question_data | |
| 1020 | + } // end if $answer_order_string | |
| 1033 | 1021 | |
| 1034 | - /** | |
| 1035 | - * Load the gap fill question data on the sensei_get_question_template_data | |
| 1036 | - * filter. | |
| 1037 | - * | |
| 1038 | - * @since 1.9.0 | |
| 1039 | - * | |
| 1040 | - * @param $question_data | |
| 1041 | - * @param $question_id | |
| 1042 | - * @param $quiz_id | |
| 1043 | - * | |
| 1044 | - * @return array() | |
| 1045 | - */ | |
| 1046 | -    public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ | |
| 1022 | + } // end if random order | |
| 1047 | 1023 | |
| 1048 | -        if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { | |
| 1049 | 1024 | |
| 1050 | - $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); | |
| 1051 | - $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; | |
| 1052 | - $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; | |
| 1053 | - $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; | |
| 1025 | + // assemble and setup the data for the templates data array | |
| 1026 | + $question_data[ 'answer_options' ] = $answer_options_sorted; | |
| 1054 | 1027 | |
| 1055 | - } | |
| 1028 | + } | |
| 1056 | 1029 | |
| 1057 | - return $question_data; | |
| 1030 | + return $question_data; | |
| 1058 | 1031 | |
| 1059 | - }// end gap_fill_load_question_data | |
| 1032 | + }// end multiple_choice_load_question_data | |
| 1033 | + | |
| 1034 | + /** | |
| 1035 | + * Load the gap fill question data on the sensei_get_question_template_data | |
| 1036 | + * filter. | |
| 1037 | + * | |
| 1038 | + * @since 1.9.0 | |
| 1039 | + * | |
| 1040 | + * @param $question_data | |
| 1041 | + * @param $question_id | |
| 1042 | + * @param $quiz_id | |
| 1043 | + * | |
| 1044 | + * @return array() | |
| 1045 | + */ | |
| 1046 | +	public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){ | |
| 1047 | + | |
| 1048 | +		if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) { | |
| 1049 | + | |
| 1050 | + $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] ); | |
| 1051 | + $question_data[ 'gapfill_pre' ] = isset( $gapfill_array[0] ) ? $gapfill_array[0] : ''; | |
| 1052 | + $question_data[ 'gapfill_gap' ] = isset( $gapfill_array[1] ) ? $gapfill_array[1] : ''; | |
| 1053 | + $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : ''; | |
| 1054 | + | |
| 1055 | + } | |
| 1056 | + | |
| 1057 | + return $question_data; | |
| 1058 | + | |
| 1059 | + }// end gap_fill_load_question_data | |
| 1060 | 1060 | |
| 1061 | 1061 | |
| 1062 | - /** | |
| 1063 | - * Get the correct answer for a question | |
| 1064 | - * | |
| 1065 | - * @param $question_id | |
| 1066 | - * @return string $correct_answer or empty | |
| 1067 | - */ | |
| 1068 | -    public static function get_correct_answer( $question_id ){ | |
| 1062 | + /** | |
| 1063 | + * Get the correct answer for a question | |
| 1064 | + * | |
| 1065 | + * @param $question_id | |
| 1066 | + * @return string $correct_answer or empty | |
| 1067 | + */ | |
| 1068 | +	public static function get_correct_answer( $question_id ){ | |
| 1069 | 1069 | |
| 1070 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); | |
| 1071 | - $type = Sensei()->question->get_question_type( $question_id ); | |
| 1072 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); | |
| 1073 | - $grade_type = 'manual-grade'; | |
| 1070 | + $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); | |
| 1071 | + $type = Sensei()->question->get_question_type( $question_id ); | |
| 1072 | + $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); | |
| 1073 | + $grade_type = 'manual-grade'; | |
| 1074 | 1074 | |
| 1075 | -        if ('boolean'== $type ) { | |
| 1075 | +		if ('boolean'== $type ) { | |
| 1076 | 1076 | |
| 1077 | - $right_answer = ucfirst($right_answer); | |
| 1077 | + $right_answer = ucfirst($right_answer); | |
| 1078 | 1078 | |
| 1079 | -        }elseif( 'multiple-choice' == $type ) { | |
| 1079 | +		}elseif( 'multiple-choice' == $type ) { | |
| 1080 | 1080 | |
| 1081 | - $right_answer = (array) $right_answer; | |
| 1082 | - $right_answer = implode( ', ', $right_answer ); | |
| 1081 | + $right_answer = (array) $right_answer; | |
| 1082 | + $right_answer = implode( ', ', $right_answer ); | |
| 1083 | 1083 | |
| 1084 | -        }elseif( 'gap-fill' == $type ) { | |
| 1084 | +		}elseif( 'gap-fill' == $type ) { | |
| 1085 | 1085 | |
| 1086 | - $right_answer_array = explode( '||', $right_answer ); | |
| 1087 | -            if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } | |
| 1088 | -            if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } | |
| 1089 | -            if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } | |
| 1086 | + $right_answer_array = explode( '||', $right_answer ); | |
| 1087 | +			if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } | |
| 1088 | +			if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } | |
| 1089 | +			if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } | |
| 1090 | 1090 | |
| 1091 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; | |
| 1091 | + $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; | |
| 1092 | 1092 | |
| 1093 | -        }else{ | |
| 1093 | +		}else{ | |
| 1094 | 1094 | |
| 1095 | - // for non auto gradable question types no answer should be returned. | |
| 1096 | - $right_answer = ''; | |
| 1095 | + // for non auto gradable question types no answer should be returned. | |
| 1096 | + $right_answer = ''; | |
| 1097 | 1097 | |
| 1098 | - } | |
| 1098 | + } | |
| 1099 | 1099 | |
| 1100 | - return $right_answer; | |
| 1100 | + return $right_answer; | |
| 1101 | 1101 | |
| 1102 | - } // get_correct_answer | |
| 1102 | + } // get_correct_answer | |
| 1103 | 1103 | |
| 1104 | 1104 | } // End Class | 
| 1105 | 1105 | |
| @@ -123,7 +123,7 @@ discard block | ||
| 123 | 123 | * | 
| 124 | 124 | * This function hooks into the quiz page and accepts the answer form save post. | 
| 125 | 125 | * @since 1.7.3 | 
| 126 | - * @return bool $saved; | |
| 126 | + * @return boolean|null $saved; | |
| 127 | 127 | */ | 
| 128 | 128 |      public function user_save_quiz_answers_listener(){ | 
| 129 | 129 | |
| @@ -214,7 +214,7 @@ discard block | ||
| 214 | 214 | * @param int $lesson_id | 
| 215 | 215 | * @param int $user_id | 
| 216 | 216 | * | 
| 217 | - * @return array $answers or false | |
| 217 | + * @return boolean $answers or false | |
| 218 | 218 | */ | 
| 219 | 219 |  	public function get_user_answers( $lesson_id, $user_id ){ | 
| 220 | 220 | |
| @@ -707,7 +707,7 @@ discard block | ||
| 707 | 707 | * @type int $question_id | 
| 708 | 708 | * @type int $question_grade | 
| 709 | 709 | * } | 
| 710 | - * @param $lesson_id | |
| 710 | + * @param integer $lesson_id | |
| 711 | 711 | * @param $user_id (Optional) will use the current user if not supplied | 
| 712 | 712 | * | 
| 713 | 713 | * @return bool | 
| @@ -754,7 +754,7 @@ discard block | ||
| 754 | 754 | * | 
| 755 | 755 | * @since 1.7.4 | 
| 756 | 756 | * | 
| 757 | - * @param $lesson_id | |
| 757 | + * @param integer $lesson_id | |
| 758 | 758 | * @param $user_id (Optional) will use the current user if not supplied | 
| 759 | 759 | * | 
| 760 | 760 | * @return array $user_quiz_grades or false if none exists for this users | 
| @@ -1090,7 +1090,6 @@ discard block | ||
| 1090 | 1090 | * Filter the single title and add the Quiz to it. | 
| 1091 | 1091 | * | 
| 1092 | 1092 | * @param string $title | 
| 1093 | - * @param int $id title post id | |
| 1094 | 1093 | * @return string $quiz_title | 
| 1095 | 1094 | */ | 
| 1096 | 1095 |       public static function single_quiz_title( $title, $post_id ){ | 
| @@ -25,70 +25,70 @@ discard block | ||
| 25 | 25 | */ | 
| 26 | 26 |  	public function __construct ( $file = __FILE__ ) { | 
| 27 | 27 | $this->file = $file; | 
| 28 | - $this->token = 'quiz'; | |
| 28 | + $this->token = 'quiz'; | |
| 29 | 29 | $this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' ); | 
| 30 | 30 | add_action( 'save_post', array( $this, 'update_author' )); | 
| 31 | 31 | |
| 32 | 32 | // listen to the reset button click | 
| 33 | 33 | add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); | 
| 34 | 34 | |
| 35 | - // fire the complete quiz button submit for grading action | |
| 36 | - add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); | |
| 35 | + // fire the complete quiz button submit for grading action | |
| 36 | + add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) ); | |
| 37 | 37 | |
| 38 | 38 | // fire the save user answers quiz button click responder | 
| 39 | 39 | add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) ); | 
| 40 | 40 | |
| 41 | - // fire the load global data function | |
| 42 | - add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); | |
| 41 | + // fire the load global data function | |
| 42 | + add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 ); | |
| 43 | 43 | |
| 44 | - add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); | |
| 44 | + add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); | |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - } // End __construct() | |
| 47 | + } // End __construct() | |
| 48 | 48 | |
| 49 | 49 | /** | 
| 50 | - * Update the quiz author when the lesson post type is save | |
| 51 | - * | |
| 52 | - * @param int $post_id | |
| 53 | - * @return void | |
| 54 | - */ | |
| 50 | + * Update the quiz author when the lesson post type is save | |
| 51 | + * | |
| 52 | + * @param int $post_id | |
| 53 | + * @return void | |
| 54 | + */ | |
| 55 | 55 |  	public function update_author( $post_id ){ | 
| 56 | 56 | |
| 57 | 57 | |
| 58 | 58 | // If this isn't a 'lesson' post, don't update it. | 
| 59 | - // if this is a revision don't save it | |
| 60 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] | |
| 61 | -            || wp_is_post_revision( $post_id ) ) { | |
| 59 | + // if this is a revision don't save it | |
| 60 | + if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] | |
| 61 | +			|| wp_is_post_revision( $post_id ) ) { | |
| 62 | 62 | |
| 63 | - return; | |
| 63 | + return; | |
| 64 | 64 | |
| 65 | - } | |
| 66 | - // get the lesson author id to be use late | |
| 67 | - $saved_post = get_post( $post_id ); | |
| 68 | - $new_lesson_author_id = $saved_post->post_author; | |
| 65 | + } | |
| 66 | + // get the lesson author id to be use late | |
| 67 | + $saved_post = get_post( $post_id ); | |
| 68 | + $new_lesson_author_id = $saved_post->post_author; | |
| 69 | 69 | |
| 70 | - //get the lessons quiz | |
| 70 | + //get the lessons quiz | |
| 71 | 71 | $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); | 
| 72 | -	    foreach ( (array) $lesson_quizzes as $quiz_item ) { | |
| 72 | +		foreach ( (array) $lesson_quizzes as $quiz_item ) { | |
| 73 | 73 | |
| 74 | -	    	if( ! $quiz_item ) { | |
| 75 | - continue; | |
| 76 | - } | |
| 74 | +			if( ! $quiz_item ) { | |
| 75 | + continue; | |
| 76 | + } | |
| 77 | 77 | |
| 78 | - // setup the quiz items new author value | |
| 78 | + // setup the quiz items new author value | |
| 79 | 79 | $my_post = array( | 
| 80 | - 'ID' => $quiz_item, | |
| 81 | - 'post_author' => $new_lesson_author_id | |
| 80 | + 'ID' => $quiz_item, | |
| 81 | + 'post_author' => $new_lesson_author_id | |
| 82 | 82 | ); | 
| 83 | 83 | |
| 84 | - // remove the action so that it doesn't fire again | |
| 85 | - remove_action( 'save_post', array( $this, 'update_author' )); | |
| 84 | + // remove the action so that it doesn't fire again | |
| 85 | + remove_action( 'save_post', array( $this, 'update_author' )); | |
| 86 | 86 | |
| 87 | 87 | // Update the post into the database | 
| 88 | 88 | wp_update_post( $my_post ); | 
| 89 | - } | |
| 89 | + } | |
| 90 | 90 | |
| 91 | - return; | |
| 91 | + return; | |
| 92 | 92 | }// end update_author | 
| 93 | 93 | |
| 94 | 94 | |
| @@ -119,32 +119,32 @@ discard block | ||
| 119 | 119 | } // end lesson | 
| 120 | 120 | |
| 121 | 121 | |
| 122 | - /** | |
| 123 | - * user_save_quiz_answers_listener | |
| 124 | - * | |
| 125 | - * This function hooks into the quiz page and accepts the answer form save post. | |
| 126 | - * @since 1.7.3 | |
| 127 | - * @return bool $saved; | |
| 128 | - */ | |
| 129 | -    public function user_save_quiz_answers_listener(){ | |
| 122 | + /** | |
| 123 | + * user_save_quiz_answers_listener | |
| 124 | + * | |
| 125 | + * This function hooks into the quiz page and accepts the answer form save post. | |
| 126 | + * @since 1.7.3 | |
| 127 | + * @return bool $saved; | |
| 128 | + */ | |
| 129 | +	public function user_save_quiz_answers_listener(){ | |
| 130 | 130 | |
| 131 | - if( ! isset( $_POST[ 'quiz_save' ]) | |
| 132 | - || !isset( $_POST[ 'sensei_question' ] ) | |
| 133 | - || empty( $_POST[ 'sensei_question' ] ) | |
| 134 | -            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) { | |
| 135 | - return; | |
| 136 | - } | |
| 131 | + if( ! isset( $_POST[ 'quiz_save' ]) | |
| 132 | + || !isset( $_POST[ 'sensei_question' ] ) | |
| 133 | + || empty( $_POST[ 'sensei_question' ] ) | |
| 134 | +			||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) { | |
| 135 | + return; | |
| 136 | + } | |
| 137 | 137 | |
| 138 | - global $post; | |
| 139 | - $lesson_id = $this->get_lesson_id( $post->ID ); | |
| 140 | - $quiz_answers = $_POST[ 'sensei_question' ]; | |
| 141 | - // call the save function | |
| 142 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); | |
| 138 | + global $post; | |
| 139 | + $lesson_id = $this->get_lesson_id( $post->ID ); | |
| 140 | + $quiz_answers = $_POST[ 'sensei_question' ]; | |
| 141 | + // call the save function | |
| 142 | + self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); | |
| 143 | 143 | |
| 144 | - // remove the hook as it should only fire once per click | |
| 145 | - remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); | |
| 144 | + // remove the hook as it should only fire once per click | |
| 145 | + remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' ); | |
| 146 | 146 | |
| 147 | - } // end user_save_quiz_answers_listener | |
| 147 | + } // end user_save_quiz_answers_listener | |
| 148 | 148 | |
| 149 | 149 | /** | 
| 150 | 150 | * Save the user answers for the given lesson's quiz | 
| @@ -155,7 +155,7 @@ discard block | ||
| 155 | 155 | * @access public | 
| 156 | 156 | * | 
| 157 | 157 | * @param array $quiz_answers | 
| 158 | - * @param array $files from global $_FILES | |
| 158 | + * @param array $files from global $_FILES | |
| 159 | 159 | * @param int $lesson_id | 
| 160 | 160 | * @param int $user_id | 
| 161 | 161 | * | 
| @@ -163,11 +163,11 @@ discard block | ||
| 163 | 163 | */ | 
| 164 | 164 |  	public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ | 
| 165 | 165 | |
| 166 | -        if( ! ( $user_id > 0 ) ){ | |
| 167 | - $user_id = get_current_user_id(); | |
| 168 | - } | |
| 166 | +		if( ! ( $user_id > 0 ) ){ | |
| 167 | + $user_id = get_current_user_id(); | |
| 168 | + } | |
| 169 | 169 | |
| 170 | - // make sure the parameters are valid before continuing | |
| 170 | + // make sure the parameters are valid before continuing | |
| 171 | 171 | if( empty( $lesson_id ) || empty( $user_id ) | 
| 172 | 172 | || 'lesson' != get_post_type( $lesson_id ) | 
| 173 | 173 | ||!get_userdata( $user_id ) | 
| @@ -178,25 +178,25 @@ discard block | ||
| 178 | 178 | } | 
| 179 | 179 | |
| 180 | 180 | |
| 181 | - // start the lesson before saving the data in case the user has not started the lesson | |
| 182 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); | |
| 181 | + // start the lesson before saving the data in case the user has not started the lesson | |
| 182 | + $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); | |
| 183 | 183 | |
| 184 | 184 | //prepare the answers | 
| 185 | 185 | $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); | 
| 186 | 186 | |
| 187 | 187 | // save the user data | 
| 188 | - $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; | |
| 188 | + $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; | |
| 189 | 189 | |
| 190 | 190 | // were the answers saved correctly? | 
| 191 | 191 |  		if( intval( $answers_saved ) > 0){ | 
| 192 | 192 | |
| 193 | - // save transient to make retrieval faster | |
| 194 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | |
| 195 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); | |
| 193 | + // save transient to make retrieval faster | |
| 194 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | |
| 195 | + set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); | |
| 196 | 196 | |
| 197 | - // update the message showed to user | |
| 198 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; | |
| 199 | - } | |
| 197 | + // update the message showed to user | |
| 198 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; | |
| 199 | + } | |
| 200 | 200 | |
| 201 | 201 | return $answers_saved; | 
| 202 | 202 | |
| @@ -204,9 +204,9 @@ discard block | ||
| 204 | 204 | |
| 205 | 205 | /** | 
| 206 | 206 | * Get the user answers for the given lesson's quiz. | 
| 207 | - * | |
| 208 | - * This function returns the data that is stored on the lesson as meta and is not compatible with | |
| 209 | - * retrieving data for quiz answer before sensei 1.7.4 | |
| 207 | + * | |
| 208 | + * This function returns the data that is stored on the lesson as meta and is not compatible with | |
| 209 | + * retrieving data for quiz answer before sensei 1.7.4 | |
| 210 | 210 | * | 
| 211 | 211 | * | 
| 212 | 212 | * @since 1.7.4 | 
| @@ -226,27 +226,27 @@ discard block | ||
| 226 | 226 | return false; | 
| 227 | 227 | } | 
| 228 | 228 | |
| 229 | - // save some time and get the transient cached data | |
| 230 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | |
| 231 | - $transient_cached_answers = get_transient( $transient_key ); | |
| 229 | + // save some time and get the transient cached data | |
| 230 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | |
| 231 | + $transient_cached_answers = get_transient( $transient_key ); | |
| 232 | 232 | |
| 233 | - // return the transient or get the values get the values from the comment meta | |
| 234 | -        if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){ | |
| 233 | + // return the transient or get the values get the values from the comment meta | |
| 234 | +		if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){ | |
| 235 | 235 | |
| 236 | - $encoded_user_answers = $transient_cached_answers; | |
| 236 | + $encoded_user_answers = $transient_cached_answers; | |
| 237 | 237 | |
| 238 | -        }else{ | |
| 238 | +		}else{ | |
| 239 | 239 | |
| 240 | - $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); | |
| 240 | + $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); | |
| 241 | 241 | |
| 242 | - } // end if transient check | |
| 242 | + } // end if transient check | |
| 243 | 243 | |
| 244 | 244 |  		if( ! is_array( $encoded_user_answers ) ){ | 
| 245 | 245 | return false; | 
| 246 | 246 | } | 
| 247 | 247 | |
| 248 | - //set the transient with the new valid data for faster retrieval in future | |
| 249 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); | |
| 248 | + //set the transient with the new valid data for faster retrieval in future | |
| 249 | + set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); | |
| 250 | 250 | |
| 251 | 251 | // decode an unserialize all answers | 
| 252 | 252 |  		foreach( $encoded_user_answers as $question_id => $encoded_answer ) { | 
| @@ -280,8 +280,8 @@ discard block | ||
| 280 | 280 | $current_quiz_id = $post->ID; | 
| 281 | 281 | $lesson_id = $this->get_lesson_id( $current_quiz_id ); | 
| 282 | 282 | |
| 283 | - // reset all user data | |
| 284 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); | |
| 283 | + // reset all user data | |
| 284 | + $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); | |
| 285 | 285 | |
| 286 | 286 | //this function should only run once | 
| 287 | 287 | remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); | 
| @@ -292,7 +292,7 @@ discard block | ||
| 292 | 292 | * Complete/ submit quiz hooked function | 
| 293 | 293 | * | 
| 294 | 294 | * This function listens to the complete button submit action and processes the users submitted answers | 
| 295 | - * not that this function submits the given users quiz answers for grading. | |
| 295 | + * not that this function submits the given users quiz answers for grading. | |
| 296 | 296 | * | 
| 297 | 297 | * @since 1.7.4 | 
| 298 | 298 | * @access public | 
| @@ -302,90 +302,90 @@ discard block | ||
| 302 | 302 | */ | 
| 303 | 303 |  	public function user_quiz_submit_listener() { | 
| 304 | 304 | |
| 305 | - // only respond to valid quiz completion submissions | |
| 306 | - if( ! isset( $_POST[ 'quiz_complete' ]) | |
| 307 | - || !isset( $_POST[ 'sensei_question' ] ) | |
| 308 | - || empty( $_POST[ 'sensei_question' ] ) | |
| 309 | -            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) { | |
| 310 | - return; | |
| 311 | - } | |
| 305 | + // only respond to valid quiz completion submissions | |
| 306 | + if( ! isset( $_POST[ 'quiz_complete' ]) | |
| 307 | + || !isset( $_POST[ 'sensei_question' ] ) | |
| 308 | + || empty( $_POST[ 'sensei_question' ] ) | |
| 309 | +			||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) { | |
| 310 | + return; | |
| 311 | + } | |
| 312 | 312 | |
| 313 | - global $post, $current_user; | |
| 314 | - $lesson_id = $this->get_lesson_id( $post->ID ); | |
| 315 | - $quiz_answers = $_POST[ 'sensei_question' ]; | |
| 313 | + global $post, $current_user; | |
| 314 | + $lesson_id = $this->get_lesson_id( $post->ID ); | |
| 315 | + $quiz_answers = $_POST[ 'sensei_question' ]; | |
| 316 | 316 | |
| 317 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); | |
| 317 | + self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); | |
| 318 | 318 | |
| 319 | 319 | } // End sensei_complete_quiz() | 
| 320 | 320 | |
| 321 | - /** | |
| 322 | - * This function set's up the data need for the quiz page | |
| 323 | - * | |
| 324 | - * This function hooks into sensei_complete_quiz and load the global data for the | |
| 325 | - * current quiz. | |
| 326 | - * | |
| 327 | - * @since 1.7.4 | |
| 328 | - * @access public | |
| 329 | - * | |
| 330 | - */ | |
| 331 | -    public function load_global_quiz_data(){ | |
| 321 | + /** | |
| 322 | + * This function set's up the data need for the quiz page | |
| 323 | + * | |
| 324 | + * This function hooks into sensei_complete_quiz and load the global data for the | |
| 325 | + * current quiz. | |
| 326 | + * | |
| 327 | + * @since 1.7.4 | |
| 328 | + * @access public | |
| 329 | + * | |
| 330 | + */ | |
| 331 | +	public function load_global_quiz_data(){ | |
| 332 | 332 | |
| 333 | - global $post, $current_user; | |
| 334 | - $this->data = new stdClass(); | |
| 333 | + global $post, $current_user; | |
| 334 | + $this->data = new stdClass(); | |
| 335 | 335 | |
| 336 | - // Default grade | |
| 337 | - $grade = 0; | |
| 336 | + // Default grade | |
| 337 | + $grade = 0; | |
| 338 | 338 | |
| 339 | - // Get Quiz Questions | |
| 340 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); | |
| 339 | + // Get Quiz Questions | |
| 340 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); | |
| 341 | 341 | |
| 342 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); | |
| 342 | + $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); | |
| 343 | 343 | |
| 344 | - // Get quiz grade type | |
| 345 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); | |
| 344 | + // Get quiz grade type | |
| 345 | + $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); | |
| 346 | 346 | |
| 347 | - // Get quiz pass setting | |
| 348 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); | |
| 347 | + // Get quiz pass setting | |
| 348 | + $pass_required = get_post_meta( $post->ID, '_pass_required', true ); | |
| 349 | 349 | |
| 350 | - // Get quiz pass mark | |
| 351 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); | |
| 350 | + // Get quiz pass mark | |
| 351 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); | |
| 352 | 352 | |
| 353 | - // Get latest quiz answers and grades | |
| 354 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); | |
| 355 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); | |
| 356 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); | |
| 357 | - $user_quiz_grade = 0; | |
| 358 | -        if( isset( $user_lesson_status->comment_ID ) ) { | |
| 359 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 360 | - } | |
| 353 | + // Get latest quiz answers and grades | |
| 354 | + $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); | |
| 355 | + $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); | |
| 356 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); | |
| 357 | + $user_quiz_grade = 0; | |
| 358 | +		if( isset( $user_lesson_status->comment_ID ) ) { | |
| 359 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 360 | + } | |
| 361 | 361 | |
| 362 | -        if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } | |
| 362 | +		if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } | |
| 363 | 363 | |
| 364 | - // Check again that the lesson is complete | |
| 365 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); | |
| 366 | - $user_lesson_complete = false; | |
| 367 | -        if ( $user_lesson_end ) { | |
| 368 | - $user_lesson_complete = true; | |
| 369 | - } // End If Statement | |
| 364 | + // Check again that the lesson is complete | |
| 365 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); | |
| 366 | + $user_lesson_complete = false; | |
| 367 | +		if ( $user_lesson_end ) { | |
| 368 | + $user_lesson_complete = true; | |
| 369 | + } // End If Statement | |
| 370 | 370 | |
| 371 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); | |
| 372 | - //backwards compatibility | |
| 373 | -        if( 'on' == $reset_allowed ) { | |
| 374 | - $reset_allowed = 1; | |
| 375 | - } | |
| 371 | + $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); | |
| 372 | + //backwards compatibility | |
| 373 | +		if( 'on' == $reset_allowed ) { | |
| 374 | + $reset_allowed = 1; | |
| 375 | + } | |
| 376 | 376 | |
| 377 | - // Build frontend data object for backwards compatibility | |
| 378 | - // using this is no longer recommended | |
| 379 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 380 | - $this->data->quiz_passmark = $quiz_passmark; | |
| 381 | - $this->data->quiz_lesson = $quiz_lesson_id; | |
| 382 | - $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 383 | - $this->data->user_lesson_end = $user_lesson_end; | |
| 384 | - $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); | |
| 385 | - $this->data->lesson_quiz_questions = $lesson_quiz_questions; | |
| 386 | - $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); | |
| 377 | + // Build frontend data object for backwards compatibility | |
| 378 | + // using this is no longer recommended | |
| 379 | + $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); | |
| 380 | + $this->data->quiz_passmark = $quiz_passmark; | |
| 381 | + $this->data->quiz_lesson = $quiz_lesson_id; | |
| 382 | + $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 383 | + $this->data->user_lesson_end = $user_lesson_end; | |
| 384 | + $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); | |
| 385 | + $this->data->lesson_quiz_questions = $lesson_quiz_questions; | |
| 386 | + $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); | |
| 387 | 387 | |
| 388 | - } // end load_global_quiz_data | |
| 388 | + } // end load_global_quiz_data | |
| 389 | 389 | |
| 390 | 390 | |
| 391 | 391 | /** | 
| @@ -415,25 +415,25 @@ discard block | ||
| 415 | 415 |  		foreach( $unprepared_answers as $question_id => $answer ) { | 
| 416 | 416 | |
| 417 | 417 | //get the current questions question type | 
| 418 | - $question_type = Sensei()->question->get_question_type( $question_id ); | |
| 418 | + $question_type = Sensei()->question->get_question_type( $question_id ); | |
| 419 | 419 | |
| 420 | 420 | // Sanitise answer | 
| 421 | 421 |  			if( 0 == get_magic_quotes_gpc() ) { | 
| 422 | 422 | $answer = wp_unslash( $answer ); | 
| 423 | 423 | } | 
| 424 | 424 | |
| 425 | - // compress the answer for saving | |
| 425 | + // compress the answer for saving | |
| 426 | 426 |  			if( 'multi-line' == $question_type ) { | 
| 427 | - $answer = esc_html( $answer ); | |
| 428 | -            }elseif( 'file-upload' == $question_type  ){ | |
| 429 | - $file_key = 'file_upload_' . $question_id; | |
| 430 | -                if( isset( $files[ $file_key ] ) ) { | |
| 431 | - $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); | |
| 432 | -                        if( $attachment_id ) { | |
| 433 | - $answer = $attachment_id; | |
| 434 | - } | |
| 435 | - } | |
| 436 | - } // end if | |
| 427 | + $answer = esc_html( $answer ); | |
| 428 | +			}elseif( 'file-upload' == $question_type  ){ | |
| 429 | + $file_key = 'file_upload_' . $question_id; | |
| 430 | +				if( isset( $files[ $file_key ] ) ) { | |
| 431 | + $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); | |
| 432 | +						if( $attachment_id ) { | |
| 433 | + $answer = $attachment_id; | |
| 434 | + } | |
| 435 | + } | |
| 436 | + } // end if | |
| 437 | 437 | |
| 438 | 438 | $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); | 
| 439 | 439 | |
| @@ -442,814 +442,814 @@ discard block | ||
| 442 | 442 | return $prepared_answers; | 
| 443 | 443 | } // prepare_form_submitted_answers | 
| 444 | 444 | |
| 445 | - /** | |
| 446 | - * Reset user submitted questions | |
| 447 | - * | |
| 448 | - * This function resets the quiz data for a user that has been submitted fro grading already. It is different to | |
| 449 | - * the save_user_answers as currently the saved and submitted answers are stored differently. | |
| 450 | - * | |
| 451 | - * @since 1.7.4 | |
| 452 | - * @access public | |
| 453 | - * | |
| 454 | - * @return bool $reset_success | |
| 455 | - * @param int $user_id | |
| 456 | - * @param int $lesson_id | |
| 457 | - */ | |
| 458 | -    public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ | |
| 445 | + /** | |
| 446 | + * Reset user submitted questions | |
| 447 | + * | |
| 448 | + * This function resets the quiz data for a user that has been submitted fro grading already. It is different to | |
| 449 | + * the save_user_answers as currently the saved and submitted answers are stored differently. | |
| 450 | + * | |
| 451 | + * @since 1.7.4 | |
| 452 | + * @access public | |
| 453 | + * | |
| 454 | + * @return bool $reset_success | |
| 455 | + * @param int $user_id | |
| 456 | + * @param int $lesson_id | |
| 457 | + */ | |
| 458 | +	public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ | |
| 459 | + | |
| 460 | + //make sure the parameters are valid | |
| 461 | + if( empty( $lesson_id ) || empty( $user_id ) | |
| 462 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 463 | +			|| ! get_userdata( $user_id ) ){ | |
| 464 | + return false; | |
| 465 | + } | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + //get the users lesson status to make | |
| 470 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 471 | +		if( ! isset( $user_lesson_status->comment_ID ) ) { | |
| 472 | + // this user is not taking this lesson so this process is not needed | |
| 473 | + return false; | |
| 474 | + } | |
| 475 | + | |
| 476 | + //get the lesson quiz and course | |
| 477 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 478 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); | |
| 479 | + | |
| 480 | + // reset the transients | |
| 481 | + $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | |
| 482 | + $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; | |
| 483 | + $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | |
| 484 | + delete_transient( $answers_transient_key ); | |
| 485 | + delete_transient( $grades_transient_key ); | |
| 486 | + delete_transient( $answers_feedback_transient_key ); | |
| 487 | + | |
| 488 | + // reset the quiz answers and feedback notes | |
| 489 | + $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); | |
| 490 | + $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); | |
| 491 | + $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); | |
| 492 | + | |
| 493 | + // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade | |
| 494 | + Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); | |
| 495 | + | |
| 496 | + Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); | |
| 497 | + | |
| 498 | + // Update course completion | |
| 499 | + Sensei_Utils::update_course_status( $user_id, $course_id ); | |
| 459 | 500 | |
| 460 | - //make sure the parameters are valid | |
| 461 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 462 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 463 | -            || ! get_userdata( $user_id ) ){ | |
| 464 | - return false; | |
| 465 | - } | |
| 466 | - | |
| 467 | - | |
| 468 | - | |
| 469 | - //get the users lesson status to make | |
| 470 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 471 | -        if( ! isset( $user_lesson_status->comment_ID ) ) { | |
| 472 | - // this user is not taking this lesson so this process is not needed | |
| 473 | - return false; | |
| 474 | - } | |
| 501 | + // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() | |
| 502 | + do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); | |
| 503 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; | |
| 475 | 504 | |
| 476 | - //get the lesson quiz and course | |
| 477 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 478 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); | |
| 505 | + return ( $deleted_answers && $deleted_grades ) ; | |
| 479 | 506 | |
| 480 | - // reset the transients | |
| 481 | - $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; | |
| 482 | - $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; | |
| 483 | - $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | |
| 484 | - delete_transient( $answers_transient_key ); | |
| 485 | - delete_transient( $grades_transient_key ); | |
| 486 | - delete_transient( $answers_feedback_transient_key ); | |
| 507 | + } // end reset_user_lesson_data | |
| 487 | 508 | |
| 488 | - // reset the quiz answers and feedback notes | |
| 489 | - $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); | |
| 490 | - $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); | |
| 491 | - $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); | |
| 509 | + /** | |
| 510 | + * Submit the users quiz answers for grading | |
| 511 | + * | |
| 512 | + * This function accepts users answers and stores it but also initiates the grading | |
| 513 | + * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. | |
| 514 | + * | |
| 515 | + * @since 1.7.4 | |
| 516 | + * @access public | |
| 517 | + * | |
| 518 | + * @param array $quiz_answers | |
| 519 | + * @param array $files from $_FILES | |
| 520 | + * @param int $user_id | |
| 521 | + * @param int $lesson_id | |
| 522 | + * | |
| 523 | + * @return bool $answers_submitted | |
| 524 | + */ | |
| 525 | +	 public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ | |
| 492 | 526 | |
| 493 | - // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade | |
| 494 | - Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); | |
| 527 | + $answers_submitted = false; | |
| 495 | 528 | |
| 496 | - Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); | |
| 529 | + // get the user_id if none was passed in use the current logged in user | |
| 530 | +		 if( ! intval( $user_id ) > 0 ) { | |
| 531 | + $user_id = get_current_user_id(); | |
| 532 | + } | |
| 497 | 533 | |
| 498 | - // Update course completion | |
| 499 | - Sensei_Utils::update_course_status( $user_id, $course_id ); | |
| 534 | + // make sure the parameters are valid before continuing | |
| 535 | + if( empty( $lesson_id ) || empty( $user_id ) | |
| 536 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 537 | + ||!get_userdata( $user_id ) | |
| 538 | +			 || !is_array( $quiz_answers ) ){ | |
| 500 | 539 | |
| 501 | - // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() | |
| 502 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); | |
| 503 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; | |
| 540 | + return false; | |
| 504 | 541 | |
| 505 | - return ( $deleted_answers && $deleted_grades ) ; | |
| 542 | + } | |
| 506 | 543 | |
| 507 | - } // end reset_user_lesson_data | |
| 544 | + // Default grade | |
| 545 | + $grade = 0; | |
| 508 | 546 | |
| 509 | - /** | |
| 510 | - * Submit the users quiz answers for grading | |
| 511 | - * | |
| 512 | - * This function accepts users answers and stores it but also initiates the grading | |
| 513 | - * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. | |
| 514 | - * | |
| 515 | - * @since 1.7.4 | |
| 516 | - * @access public | |
| 517 | - * | |
| 518 | - * @param array $quiz_answers | |
| 519 | - * @param array $files from $_FILES | |
| 520 | - * @param int $user_id | |
| 521 | - * @param int $lesson_id | |
| 522 | - * | |
| 523 | - * @return bool $answers_submitted | |
| 524 | - */ | |
| 525 | -     public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ | |
| 547 | + // Get Quiz ID | |
| 548 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 526 | 549 | |
| 527 | - $answers_submitted = false; | |
| 550 | + // Get quiz grade type | |
| 551 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 528 | 552 | |
| 529 | - // get the user_id if none was passed in use the current logged in user | |
| 530 | -         if( ! intval( $user_id ) > 0 ) { | |
| 531 | - $user_id = get_current_user_id(); | |
| 532 | - } | |
| 553 | + // Get quiz pass setting | |
| 554 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); | |
| 533 | 555 | |
| 534 | - // make sure the parameters are valid before continuing | |
| 535 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 536 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 537 | - ||!get_userdata( $user_id ) | |
| 538 | -             || !is_array( $quiz_answers ) ){ | |
| 556 | + // Get the minimum percentage need to pass this quiz | |
| 557 | + $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); | |
| 539 | 558 | |
| 540 | - return false; | |
| 559 | + // Handle Quiz Questions asked | |
| 560 | + // This is to ensure we save the questions that we've asked this user and that this can't be change unless | |
| 561 | + // the quiz is reset by admin or user( user: only if the setting is enabled ). | |
| 562 | + // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions | |
| 563 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 564 | + $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); | |
| 565 | +		 if( empty( $questions_asked ) ){ | |
| 541 | 566 | |
| 542 | - } | |
| 567 | + $questions_asked = array_keys( $quiz_answers ); | |
| 568 | + $questions_asked_string = implode( ',', $questions_asked ); | |
| 543 | 569 | |
| 544 | - // Default grade | |
| 545 | - $grade = 0; | |
| 570 | + // Save questions that were asked in this quiz | |
| 571 | + update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); | |
| 546 | 572 | |
| 547 | - // Get Quiz ID | |
| 548 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 573 | + } | |
| 549 | 574 | |
| 550 | - // Get quiz grade type | |
| 551 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); | |
| 575 | + // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson | |
| 576 | + self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); | |
| 552 | 577 | |
| 553 | - // Get quiz pass setting | |
| 554 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); | |
| 578 | + // Grade quiz | |
| 579 | + $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); | |
| 555 | 580 | |
| 556 | - // Get the minimum percentage need to pass this quiz | |
| 557 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); | |
| 581 | + // Get Lesson Grading Setting | |
| 582 | + $lesson_metadata = array(); | |
| 583 | + $lesson_status = 'ungraded'; // Default when completing a quiz | |
| 558 | 584 | |
| 559 | - // Handle Quiz Questions asked | |
| 560 | - // This is to ensure we save the questions that we've asked this user and that this can't be change unless | |
| 561 | - // the quiz is reset by admin or user( user: only if the setting is enabled ). | |
| 562 | - // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions | |
| 563 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 564 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); | |
| 565 | -         if( empty( $questions_asked ) ){ | |
| 585 | + // At this point the answers have been submitted | |
| 586 | + $answers_submitted = true; | |
| 566 | 587 | |
| 567 | - $questions_asked = array_keys( $quiz_answers ); | |
| 568 | - $questions_asked_string = implode( ',', $questions_asked ); | |
| 569 | - | |
| 570 | - // Save questions that were asked in this quiz | |
| 571 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); | |
| 588 | + // if this condition is false the quiz should manually be graded by admin | |
| 589 | +		 if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) { | |
| 572 | 590 | |
| 573 | - } | |
| 591 | + // Quiz has been automatically Graded | |
| 592 | +			 if ( 'on' == $pass_required ) { | |
| 574 | 593 | |
| 575 | - // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson | |
| 576 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); | |
| 594 | + // Student has reached the pass mark and lesson is complete | |
| 595 | +				 if ( $quiz_pass_percentage <= $grade ) { | |
| 577 | 596 | |
| 578 | - // Grade quiz | |
| 579 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); | |
| 597 | + $lesson_status = 'passed'; | |
| 580 | 598 | |
| 581 | - // Get Lesson Grading Setting | |
| 582 | - $lesson_metadata = array(); | |
| 583 | - $lesson_status = 'ungraded'; // Default when completing a quiz | |
| 599 | +				 } else { | |
| 584 | 600 | |
| 585 | - // At this point the answers have been submitted | |
| 586 | - $answers_submitted = true; | |
| 601 | + $lesson_status = 'failed'; | |
| 587 | 602 | |
| 588 | - // if this condition is false the quiz should manually be graded by admin | |
| 589 | -         if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) { | |
| 603 | + } // End If Statement | |
| 590 | 604 | |
| 591 | - // Quiz has been automatically Graded | |
| 592 | -             if ( 'on' == $pass_required ) { | |
| 605 | +			 } else { | |
| 593 | 606 | |
| 594 | - // Student has reached the pass mark and lesson is complete | |
| 595 | -                 if ( $quiz_pass_percentage <= $grade ) { | |
| 607 | + // Student only has to partake the quiz | |
| 608 | + $lesson_status = 'graded'; | |
| 609 | + | |
| 610 | + } | |
| 611 | + | |
| 612 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above | |
| 613 | + | |
| 614 | + } // end if ! is_wp_error( $grade ... | |
| 615 | + | |
| 616 | + Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); | |
| 596 | 617 | |
| 597 | - $lesson_status = 'passed'; | |
| 618 | +		 if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ | |
| 598 | 619 | |
| 599 | -                 } else { | |
| 620 | + /** | |
| 621 | + * Lesson end action hook | |
| 622 | + * | |
| 623 | + * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' | |
| 624 | + * | |
| 625 | + * @param int $user_id | |
| 626 | + * @param int $lesson_id | |
| 627 | + */ | |
| 628 | + do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); | |
| 600 | 629 | |
| 601 | - $lesson_status = 'failed'; | |
| 630 | + } | |
| 602 | 631 | |
| 603 | - } // End If Statement | |
| 632 | + /** | |
| 633 | + * User quiz has been submitted | |
| 634 | + * | |
| 635 | + * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission | |
| 636 | + * results. | |
| 637 | + * | |
| 638 | + * @param int $user_id | |
| 639 | + * @param int $quiz_id | |
| 640 | + * @param string $grade | |
| 641 | + * @param string $quiz_pass_percentage | |
| 642 | + * @param string $quiz_grade_type | |
| 643 | + */ | |
| 644 | + do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); | |
| 604 | 645 | |
| 605 | -             } else { | |
| 646 | + return $answers_submitted; | |
| 606 | 647 | |
| 607 | - // Student only has to partake the quiz | |
| 608 | - $lesson_status = 'graded'; | |
| 609 | - | |
| 610 | - } | |
| 611 | - | |
| 612 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above | |
| 613 | - | |
| 614 | - } // end if ! is_wp_error( $grade ... | |
| 615 | - | |
| 616 | - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); | |
| 648 | + }// end submit_answers_for_grading | |
| 617 | 649 | |
| 618 | -         if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ | |
| 650 | + /** | |
| 651 | + * Get the user question answer | |
| 652 | + * | |
| 653 | + * This function gets the the users saved answer on given quiz for the given question parameter | |
| 654 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 | |
| 655 | + * | |
| 656 | + * @since 1.7.4 | |
| 657 | + * | |
| 658 | + * @param int $lesson_id | |
| 659 | + * @param int $question_id | |
| 660 | + * @param int $user_id ( optional ) | |
| 661 | + * | |
| 662 | + * @return bool $answers_submitted | |
| 663 | + */ | |
| 664 | +	 public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ | |
| 619 | 665 | |
| 620 | - /** | |
| 621 | - * Lesson end action hook | |
| 622 | - * | |
| 623 | - * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' | |
| 624 | - * | |
| 625 | - * @param int $user_id | |
| 626 | - * @param int $lesson_id | |
| 627 | - */ | |
| 628 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); | |
| 666 | + // parameter validation | |
| 667 | + if( empty( $lesson_id ) || empty( $question_id ) | |
| 668 | + || ! ( intval( $lesson_id ) > 0 ) | |
| 669 | + || ! ( intval( $question_id ) > 0 ) | |
| 670 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 671 | +			 || 'question' != get_post_type( $question_id )) { | |
| 629 | 672 | |
| 630 | - } | |
| 673 | + return false; | |
| 674 | + } | |
| 675 | + | |
| 676 | +		 if( ! ( intval( $user_id ) > 0 )   ){ | |
| 677 | + $user_id = get_current_user_id(); | |
| 678 | + } | |
| 679 | + | |
| 680 | + $users_answers = $this->get_user_answers( $lesson_id, $user_id ); | |
| 681 | + | |
| 682 | + if( !$users_answers || empty( $users_answers ) | |
| 683 | +		 ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ | |
| 684 | + | |
| 685 | + //Fallback for pre 1.7.4 data | |
| 686 | + $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); | |
| 687 | + | |
| 688 | +			 if( ! isset( $comment->comment_content ) ){ | |
| 689 | + return false; | |
| 690 | + } | |
| 691 | + | |
| 692 | + return maybe_unserialize( base64_decode( $comment->comment_content ) ); | |
| 693 | + } | |
| 694 | + | |
| 695 | + return $users_answers[ $question_id ]; | |
| 696 | + | |
| 697 | + }// end get_user_question_answer | |
| 698 | + | |
| 699 | + /** | |
| 700 | + * Saving the users quiz question grades | |
| 701 | + * | |
| 702 | + * This function save all the grades for all the question in a given quiz on the lesson | |
| 703 | + * comment meta. It makes use of transients to save the grades for easier access at a later stage | |
| 704 | + * | |
| 705 | + * @since 1.7.4 | |
| 706 | + * | |
| 707 | +	  * @param array $quiz_grades{ | |
| 708 | + * @type int $question_id | |
| 709 | + * @type int $question_grade | |
| 710 | + * } | |
| 711 | + * @param $lesson_id | |
| 712 | + * @param $user_id (Optional) will use the current user if not supplied | |
| 713 | + * | |
| 714 | + * @return bool | |
| 715 | + */ | |
| 716 | +	 public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ | |
| 717 | + | |
| 718 | + // get the user_id if none was passed in use the current logged in user | |
| 719 | +		 if( ! intval( $user_id ) > 0 ) { | |
| 720 | + $user_id = get_current_user_id(); | |
| 721 | + } | |
| 722 | + | |
| 723 | + // make sure the parameters are valid before continuing | |
| 724 | + if( empty( $lesson_id ) || empty( $user_id ) | |
| 725 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 726 | + ||!get_userdata( $user_id ) | |
| 727 | +			 || !is_array( $quiz_grades ) ){ | |
| 728 | + | |
| 729 | + return false; | |
| 730 | + | |
| 731 | + } | |
| 732 | + | |
| 733 | + $success = false; | |
| 734 | + | |
| 735 | + // save that data for the user on the lesson comment meta | |
| 736 | + $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); | |
| 737 | + | |
| 738 | + // were the grades save successfully ? | |
| 739 | +		 if( intval( $comment_meta_id ) > 0 ) { | |
| 740 | + | |
| 741 | + $success = true; | |
| 742 | + // save transient | |
| 743 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; | |
| 744 | + set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); | |
| 745 | + } | |
| 746 | + | |
| 747 | + return $success; | |
| 748 | + | |
| 749 | + }// end set_user_grades | |
| 750 | + | |
| 751 | + /** | |
| 752 | + * Retrieve the users quiz question grades | |
| 753 | + * | |
| 754 | + * This function gets all the grades for all the questions in the given lesson quiz for a specific user. | |
| 755 | + * | |
| 756 | + * @since 1.7.4 | |
| 757 | + * | |
| 758 | + * @param $lesson_id | |
| 759 | + * @param $user_id (Optional) will use the current user if not supplied | |
| 760 | + * | |
| 761 | + * @return array $user_quiz_grades or false if none exists for this users | |
| 762 | + */ | |
| 763 | +	 public function get_user_grades( $lesson_id, $user_id = 0 ){ | |
| 764 | + | |
| 765 | + $user_grades = array(); | |
| 766 | + | |
| 767 | + // get the user_id if none was passed in use the current logged in user | |
| 768 | +		 if( ! intval( $user_id ) > 0 ) { | |
| 769 | + $user_id = get_current_user_id(); | |
| 770 | + } | |
| 771 | + | |
| 772 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) | |
| 773 | +			 || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) { | |
| 774 | + return false; | |
| 775 | + } | |
| 776 | + | |
| 777 | + // save some time and get the transient cached data | |
| 778 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; | |
| 779 | + $user_grades = get_transient( $transient_key ); | |
| 780 | + | |
| 781 | + // get the data if nothing was stored in the transient | |
| 782 | +		 if( empty( $user_grades  ) || false != $user_grades ){ | |
| 783 | + | |
| 784 | + $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); | |
| 785 | + | |
| 786 | + //set the transient with the new valid data for faster retrieval in future | |
| 787 | + set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); | |
| 788 | + | |
| 789 | + } // end if transient check | |
| 790 | + | |
| 791 | + // if there is no data for this user | |
| 792 | +		 if( ! is_array( $user_grades ) ){ | |
| 793 | + return false; | |
| 794 | + } | |
| 795 | + | |
| 796 | + return $user_grades; | |
| 797 | + | |
| 798 | + }// end get_user_grades | |
| 799 | + | |
| 800 | + /** | |
| 801 | + * Get the user question grade | |
| 802 | + * | |
| 803 | + * This function gets the grade on a quiz for the given question parameter | |
| 804 | + * It does NOT do any grading. It simply retrieves the data that was stored during grading. | |
| 805 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 | |
| 806 | + * | |
| 807 | + * @since 1.7.4 | |
| 808 | + * | |
| 809 | + * @param int $lesson_id | |
| 810 | + * @param int $question_id | |
| 811 | + * @param int $user_id ( optional ) | |
| 812 | + * | |
| 813 | + * @return bool $question_grade | |
| 814 | + */ | |
| 815 | +	 public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ | |
| 816 | + | |
| 817 | + // parameter validation | |
| 818 | + if( empty( $lesson_id ) || empty( $question_id ) | |
| 819 | + || ! ( intval( $lesson_id ) > 0 ) | |
| 820 | + || ! ( intval( $question_id ) > 0 ) | |
| 821 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 822 | +			 || 'question' != get_post_type( $question_id )) { | |
| 823 | + | |
| 824 | + return false; | |
| 825 | + } | |
| 826 | + | |
| 827 | + $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); | |
| 828 | + | |
| 829 | +		 if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){ | |
| 830 | + | |
| 831 | + //fallback to data pre 1.7.4 | |
| 832 | + $args = array( | |
| 833 | + 'post_id' => $question_id, | |
| 834 | + 'user_id' => $user_id, | |
| 835 | + 'type' => 'sensei_user_answer' | |
| 836 | + ); | |
| 837 | + | |
| 838 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); | |
| 839 | + $fall_back_grade = false; | |
| 840 | +			 if( isset( $question_activity->comment_ID ) ){ | |
| 841 | + $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); | |
| 842 | + } | |
| 843 | + | |
| 844 | + return $fall_back_grade; | |
| 845 | + | |
| 846 | + } // end if $all_user_grades... | |
| 847 | + | |
| 848 | + return $all_user_grades[ $question_id ]; | |
| 849 | + | |
| 850 | + }// end get_user_question_grade | |
| 851 | + | |
| 852 | + /** | |
| 853 | + * Save the user's answers feedback | |
| 854 | + * | |
| 855 | + * For this function you must supply all three parameters. If will return false one is left out. | |
| 856 | + * The data will be saved on the lesson ID supplied. | |
| 857 | + * | |
| 858 | + * @since 1.7.5 | |
| 859 | + * @access public | |
| 860 | + * | |
| 861 | +	  * @param array $answers_feedback{ | |
| 862 | + * $type int $question_id | |
| 863 | + * $type string $question_feedback | |
| 864 | + * } | |
| 865 | + * @param int $lesson_id | |
| 866 | + * @param int $user_id | |
| 867 | + * | |
| 868 | + * @return false or int $feedback_saved | |
| 869 | + */ | |
| 870 | +	public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ | |
| 871 | + | |
| 872 | + // make sure the parameters are valid before continuing | |
| 873 | + if( empty( $lesson_id ) || empty( $user_id ) | |
| 874 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 875 | + ||!get_userdata( $user_id ) | |
| 876 | +			|| !is_array( $answers_feedback ) ){ | |
| 877 | + | |
| 878 | + return false; | |
| 879 | + | |
| 880 | + } | |
| 881 | + | |
| 882 | + | |
| 883 | + // check if the lesson is started before saving, if not start the lesson for the user | |
| 884 | +		if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { | |
| 885 | + Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); | |
| 886 | + } | |
| 631 | 887 | |
| 632 | - /** | |
| 633 | - * User quiz has been submitted | |
| 634 | - * | |
| 635 | - * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission | |
| 636 | - * results. | |
| 637 | - * | |
| 638 | - * @param int $user_id | |
| 639 | - * @param int $quiz_id | |
| 640 | - * @param string $grade | |
| 641 | - * @param string $quiz_pass_percentage | |
| 642 | - * @param string $quiz_grade_type | |
| 643 | - */ | |
| 644 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); | |
| 888 | + // encode the feedback | |
| 889 | + $encoded_answers_feedback = array(); | |
| 890 | +		foreach( $answers_feedback as $question_id => $feedback ){ | |
| 891 | + $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); | |
| 892 | + } | |
| 893 | + | |
| 894 | + // save the user data | |
| 895 | + $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; | |
| 896 | + | |
| 897 | + //Were the the question feedback save correctly? | |
| 898 | +		if( intval( $feedback_saved ) > 0){ | |
| 899 | + | |
| 900 | + // save transient to make retrieval faster in future | |
| 901 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | |
| 902 | + set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); | |
| 645 | 903 | |
| 646 | - return $answers_submitted; | |
| 904 | + } | |
| 905 | + | |
| 906 | + return $feedback_saved; | |
| 907 | + | |
| 908 | + } // end save_user_answers_feedback | |
| 909 | + | |
| 910 | + /** | |
| 911 | + * Get the user's answers feedback. | |
| 912 | + * | |
| 913 | + * This function returns the feedback submitted by the teacher/admin | |
| 914 | + * during grading. Grading occurs manually or automatically. | |
| 915 | + * | |
| 916 | + * @since 1.7.5 | |
| 917 | + * @access public | |
| 918 | + * | |
| 919 | + * @param int $lesson_id | |
| 920 | + * @param int $user_id | |
| 921 | + * | |
| 922 | +	  * @return false | array $answers_feedback{ | |
| 923 | + * $type int $question_id | |
| 924 | + * $type string $question_feedback | |
| 925 | + * } | |
| 926 | + */ | |
| 927 | +	 public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ | |
| 928 | + | |
| 929 | + $answers_feedback = array(); | |
| 647 | 930 | |
| 648 | - }// end submit_answers_for_grading | |
| 931 | + // get the user_id if none was passed in use the current logged in user | |
| 932 | +		 if( ! intval( $user_id ) > 0 ) { | |
| 933 | + $user_id = get_current_user_id(); | |
| 934 | + } | |
| 649 | 935 | |
| 650 | - /** | |
| 651 | - * Get the user question answer | |
| 652 | - * | |
| 653 | - * This function gets the the users saved answer on given quiz for the given question parameter | |
| 654 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 | |
| 655 | - * | |
| 656 | - * @since 1.7.4 | |
| 657 | - * | |
| 658 | - * @param int $lesson_id | |
| 659 | - * @param int $question_id | |
| 660 | - * @param int $user_id ( optional ) | |
| 661 | - * | |
| 662 | - * @return bool $answers_submitted | |
| 663 | - */ | |
| 664 | -     public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ | |
| 936 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) | |
| 937 | +			 || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) { | |
| 938 | + return false; | |
| 939 | + } | |
| 940 | + | |
| 941 | + // first check the transient to save a few split seconds | |
| 942 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | |
| 943 | + $encoded_feedback = get_transient( $transient_key ); | |
| 944 | + | |
| 945 | + // get the data if nothing was stored in the transient | |
| 946 | +		 if( empty( $encoded_feedback  ) || !$encoded_feedback ){ | |
| 665 | 947 | |
| 666 | - // parameter validation | |
| 667 | - if( empty( $lesson_id ) || empty( $question_id ) | |
| 668 | - || ! ( intval( $lesson_id ) > 0 ) | |
| 669 | - || ! ( intval( $question_id ) > 0 ) | |
| 670 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 671 | -             || 'question' != get_post_type( $question_id )) { | |
| 948 | + $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); | |
| 949 | + | |
| 950 | + //set the transient with the new valid data for faster retrieval in future | |
| 951 | + set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); | |
| 952 | + | |
| 953 | + } // end if transient check | |
| 672 | 954 | |
| 673 | - return false; | |
| 674 | - } | |
| 675 | - | |
| 676 | -         if( ! ( intval( $user_id ) > 0 )   ){ | |
| 677 | - $user_id = get_current_user_id(); | |
| 678 | - } | |
| 679 | - | |
| 680 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); | |
| 681 | - | |
| 682 | - if( !$users_answers || empty( $users_answers ) | |
| 683 | -         ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ | |
| 684 | - | |
| 685 | - //Fallback for pre 1.7.4 data | |
| 686 | - $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); | |
| 687 | - | |
| 688 | -             if( ! isset( $comment->comment_content ) ){ | |
| 689 | - return false; | |
| 690 | - } | |
| 691 | - | |
| 692 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); | |
| 693 | - } | |
| 694 | - | |
| 695 | - return $users_answers[ $question_id ]; | |
| 696 | - | |
| 697 | - }// end get_user_question_answer | |
| 698 | - | |
| 699 | - /** | |
| 700 | - * Saving the users quiz question grades | |
| 701 | - * | |
| 702 | - * This function save all the grades for all the question in a given quiz on the lesson | |
| 703 | - * comment meta. It makes use of transients to save the grades for easier access at a later stage | |
| 704 | - * | |
| 705 | - * @since 1.7.4 | |
| 706 | - * | |
| 707 | -      * @param array $quiz_grades{ | |
| 708 | - * @type int $question_id | |
| 709 | - * @type int $question_grade | |
| 710 | - * } | |
| 711 | - * @param $lesson_id | |
| 712 | - * @param $user_id (Optional) will use the current user if not supplied | |
| 713 | - * | |
| 714 | - * @return bool | |
| 715 | - */ | |
| 716 | -     public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ | |
| 717 | - | |
| 718 | - // get the user_id if none was passed in use the current logged in user | |
| 719 | -         if( ! intval( $user_id ) > 0 ) { | |
| 720 | - $user_id = get_current_user_id(); | |
| 721 | - } | |
| 722 | - | |
| 723 | - // make sure the parameters are valid before continuing | |
| 724 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 725 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 726 | - ||!get_userdata( $user_id ) | |
| 727 | -             || !is_array( $quiz_grades ) ){ | |
| 728 | - | |
| 729 | - return false; | |
| 730 | - | |
| 731 | - } | |
| 732 | - | |
| 733 | - $success = false; | |
| 734 | - | |
| 735 | - // save that data for the user on the lesson comment meta | |
| 736 | - $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); | |
| 737 | - | |
| 738 | - // were the grades save successfully ? | |
| 739 | -         if( intval( $comment_meta_id ) > 0 ) { | |
| 740 | - | |
| 741 | - $success = true; | |
| 742 | - // save transient | |
| 743 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; | |
| 744 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); | |
| 745 | - } | |
| 746 | - | |
| 747 | - return $success; | |
| 748 | - | |
| 749 | - }// end set_user_grades | |
| 750 | - | |
| 751 | - /** | |
| 752 | - * Retrieve the users quiz question grades | |
| 753 | - * | |
| 754 | - * This function gets all the grades for all the questions in the given lesson quiz for a specific user. | |
| 755 | - * | |
| 756 | - * @since 1.7.4 | |
| 757 | - * | |
| 758 | - * @param $lesson_id | |
| 759 | - * @param $user_id (Optional) will use the current user if not supplied | |
| 760 | - * | |
| 761 | - * @return array $user_quiz_grades or false if none exists for this users | |
| 762 | - */ | |
| 763 | -     public function get_user_grades( $lesson_id, $user_id = 0 ){ | |
| 764 | - | |
| 765 | - $user_grades = array(); | |
| 766 | - | |
| 767 | - // get the user_id if none was passed in use the current logged in user | |
| 768 | -         if( ! intval( $user_id ) > 0 ) { | |
| 769 | - $user_id = get_current_user_id(); | |
| 770 | - } | |
| 771 | - | |
| 772 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) | |
| 773 | -             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) { | |
| 774 | - return false; | |
| 775 | - } | |
| 776 | - | |
| 777 | - // save some time and get the transient cached data | |
| 778 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; | |
| 779 | - $user_grades = get_transient( $transient_key ); | |
| 780 | - | |
| 781 | - // get the data if nothing was stored in the transient | |
| 782 | -         if( empty( $user_grades  ) || false != $user_grades ){ | |
| 783 | - | |
| 784 | - $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); | |
| 785 | - | |
| 786 | - //set the transient with the new valid data for faster retrieval in future | |
| 787 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); | |
| 788 | - | |
| 789 | - } // end if transient check | |
| 790 | - | |
| 791 | - // if there is no data for this user | |
| 792 | -         if( ! is_array( $user_grades ) ){ | |
| 793 | - return false; | |
| 794 | - } | |
| 795 | - | |
| 796 | - return $user_grades; | |
| 797 | - | |
| 798 | - }// end get_user_grades | |
| 799 | - | |
| 800 | - /** | |
| 801 | - * Get the user question grade | |
| 802 | - * | |
| 803 | - * This function gets the grade on a quiz for the given question parameter | |
| 804 | - * It does NOT do any grading. It simply retrieves the data that was stored during grading. | |
| 805 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 | |
| 806 | - * | |
| 807 | - * @since 1.7.4 | |
| 808 | - * | |
| 809 | - * @param int $lesson_id | |
| 810 | - * @param int $question_id | |
| 811 | - * @param int $user_id ( optional ) | |
| 812 | - * | |
| 813 | - * @return bool $question_grade | |
| 814 | - */ | |
| 815 | -     public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ | |
| 816 | - | |
| 817 | - // parameter validation | |
| 818 | - if( empty( $lesson_id ) || empty( $question_id ) | |
| 819 | - || ! ( intval( $lesson_id ) > 0 ) | |
| 820 | - || ! ( intval( $question_id ) > 0 ) | |
| 821 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 822 | -             || 'question' != get_post_type( $question_id )) { | |
| 823 | - | |
| 824 | - return false; | |
| 825 | - } | |
| 826 | - | |
| 827 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); | |
| 828 | - | |
| 829 | -         if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){ | |
| 830 | - | |
| 831 | - //fallback to data pre 1.7.4 | |
| 832 | - $args = array( | |
| 833 | - 'post_id' => $question_id, | |
| 834 | - 'user_id' => $user_id, | |
| 835 | - 'type' => 'sensei_user_answer' | |
| 836 | - ); | |
| 837 | - | |
| 838 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); | |
| 839 | - $fall_back_grade = false; | |
| 840 | -             if( isset( $question_activity->comment_ID ) ){ | |
| 841 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); | |
| 842 | - } | |
| 843 | - | |
| 844 | - return $fall_back_grade; | |
| 845 | - | |
| 846 | - } // end if $all_user_grades... | |
| 847 | - | |
| 848 | - return $all_user_grades[ $question_id ]; | |
| 849 | - | |
| 850 | - }// end get_user_question_grade | |
| 851 | - | |
| 852 | - /** | |
| 853 | - * Save the user's answers feedback | |
| 854 | - * | |
| 855 | - * For this function you must supply all three parameters. If will return false one is left out. | |
| 856 | - * The data will be saved on the lesson ID supplied. | |
| 857 | - * | |
| 858 | - * @since 1.7.5 | |
| 859 | - * @access public | |
| 860 | - * | |
| 861 | -      * @param array $answers_feedback{ | |
| 862 | - * $type int $question_id | |
| 863 | - * $type string $question_feedback | |
| 864 | - * } | |
| 865 | - * @param int $lesson_id | |
| 866 | - * @param int $user_id | |
| 867 | - * | |
| 868 | - * @return false or int $feedback_saved | |
| 869 | - */ | |
| 870 | -    public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ | |
| 871 | - | |
| 872 | - // make sure the parameters are valid before continuing | |
| 873 | - if( empty( $lesson_id ) || empty( $user_id ) | |
| 874 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 875 | - ||!get_userdata( $user_id ) | |
| 876 | -            || !is_array( $answers_feedback ) ){ | |
| 877 | - | |
| 878 | - return false; | |
| 879 | - | |
| 880 | - } | |
| 881 | - | |
| 882 | - | |
| 883 | - // check if the lesson is started before saving, if not start the lesson for the user | |
| 884 | -        if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { | |
| 885 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); | |
| 886 | - } | |
| 887 | - | |
| 888 | - // encode the feedback | |
| 889 | - $encoded_answers_feedback = array(); | |
| 890 | -        foreach( $answers_feedback as $question_id => $feedback ){ | |
| 891 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); | |
| 892 | - } | |
| 893 | - | |
| 894 | - // save the user data | |
| 895 | - $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; | |
| 896 | - | |
| 897 | - //Were the the question feedback save correctly? | |
| 898 | -        if( intval( $feedback_saved ) > 0){ | |
| 899 | - | |
| 900 | - // save transient to make retrieval faster in future | |
| 901 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | |
| 902 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); | |
| 903 | - | |
| 904 | - } | |
| 905 | - | |
| 906 | - return $feedback_saved; | |
| 907 | - | |
| 908 | - } // end save_user_answers_feedback | |
| 909 | - | |
| 910 | - /** | |
| 911 | - * Get the user's answers feedback. | |
| 912 | - * | |
| 913 | - * This function returns the feedback submitted by the teacher/admin | |
| 914 | - * during grading. Grading occurs manually or automatically. | |
| 915 | - * | |
| 916 | - * @since 1.7.5 | |
| 917 | - * @access public | |
| 918 | - * | |
| 919 | - * @param int $lesson_id | |
| 920 | - * @param int $user_id | |
| 921 | - * | |
| 922 | -      * @return false | array $answers_feedback{ | |
| 923 | - * $type int $question_id | |
| 924 | - * $type string $question_feedback | |
| 925 | - * } | |
| 926 | - */ | |
| 927 | -     public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ | |
| 928 | - | |
| 929 | - $answers_feedback = array(); | |
| 930 | - | |
| 931 | - // get the user_id if none was passed in use the current logged in user | |
| 932 | -         if( ! intval( $user_id ) > 0 ) { | |
| 933 | - $user_id = get_current_user_id(); | |
| 934 | - } | |
| 935 | - | |
| 936 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) | |
| 937 | -             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) { | |
| 938 | - return false; | |
| 939 | - } | |
| 940 | - | |
| 941 | - // first check the transient to save a few split seconds | |
| 942 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; | |
| 943 | - $encoded_feedback = get_transient( $transient_key ); | |
| 944 | - | |
| 945 | - // get the data if nothing was stored in the transient | |
| 946 | -         if( empty( $encoded_feedback  ) || !$encoded_feedback ){ | |
| 947 | - | |
| 948 | - $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); | |
| 949 | - | |
| 950 | - //set the transient with the new valid data for faster retrieval in future | |
| 951 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); | |
| 952 | - | |
| 953 | - } // end if transient check | |
| 954 | - | |
| 955 | - // if there is no data for this user | |
| 956 | -         if( ! is_array( $encoded_feedback ) ){ | |
| 957 | - return false; | |
| 958 | - } | |
| 955 | + // if there is no data for this user | |
| 956 | +		 if( ! is_array( $encoded_feedback ) ){ | |
| 957 | + return false; | |
| 958 | + } | |
| 959 | 959 | |
| 960 | -         foreach( $encoded_feedback as $question_id => $feedback ){ | |
| 960 | +		 foreach( $encoded_feedback as $question_id => $feedback ){ | |
| 961 | 961 | |
| 962 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); | |
| 962 | + $answers_feedback[ $question_id ] = base64_decode( $feedback ); | |
| 963 | 963 | |
| 964 | - } | |
| 964 | + } | |
| 965 | 965 | |
| 966 | - return $answers_feedback; | |
| 966 | + return $answers_feedback; | |
| 967 | 967 | |
| 968 | - } // end get_user_answers_feedback | |
| 968 | + } // end get_user_answers_feedback | |
| 969 | 969 | |
| 970 | - /** | |
| 971 | - * Get the user's answer feedback for a specific question. | |
| 972 | - * | |
| 973 | - * This function gives you a single answer note/feedback string | |
| 974 | - * for the user on the given question. | |
| 975 | - * | |
| 976 | - * @since 1.7.5 | |
| 977 | - * @access public | |
| 978 | - * | |
| 979 | - * @param int $lesson_id | |
| 980 | - * @param int $question_id | |
| 981 | - * @param int $user_id | |
| 982 | - * | |
| 983 | - * @return string $feedback or bool if false | |
| 984 | - */ | |
| 985 | -     public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ | |
| 970 | + /** | |
| 971 | + * Get the user's answer feedback for a specific question. | |
| 972 | + * | |
| 973 | + * This function gives you a single answer note/feedback string | |
| 974 | + * for the user on the given question. | |
| 975 | + * | |
| 976 | + * @since 1.7.5 | |
| 977 | + * @access public | |
| 978 | + * | |
| 979 | + * @param int $lesson_id | |
| 980 | + * @param int $question_id | |
| 981 | + * @param int $user_id | |
| 982 | + * | |
| 983 | + * @return string $feedback or bool if false | |
| 984 | + */ | |
| 985 | +	 public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ | |
| 986 | 986 | |
| 987 | - $feedback = false; | |
| 987 | + $feedback = false; | |
| 988 | 988 | |
| 989 | - // parameter validation | |
| 990 | - if( empty( $lesson_id ) || empty( $question_id ) | |
| 991 | - || ! ( intval( $lesson_id ) > 0 ) | |
| 992 | - || ! ( intval( $question_id ) > 0 ) | |
| 993 | - || 'lesson' != get_post_type( $lesson_id ) | |
| 994 | -             || 'question' != get_post_type( $question_id )) { | |
| 989 | + // parameter validation | |
| 990 | + if( empty( $lesson_id ) || empty( $question_id ) | |
| 991 | + || ! ( intval( $lesson_id ) > 0 ) | |
| 992 | + || ! ( intval( $question_id ) > 0 ) | |
| 993 | + || 'lesson' != get_post_type( $lesson_id ) | |
| 994 | +			 || 'question' != get_post_type( $question_id )) { | |
| 995 | 995 | |
| 996 | - return false; | |
| 997 | - } | |
| 996 | + return false; | |
| 997 | + } | |
| 998 | 998 | |
| 999 | - // get all the feedback for the user on the given lesson | |
| 1000 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); | |
| 999 | + // get all the feedback for the user on the given lesson | |
| 1000 | + $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); | |
| 1001 | 1001 | |
| 1002 | - if( !$all_feedback || empty( $all_feedback ) | |
| 1003 | -             || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ | |
| 1002 | + if( !$all_feedback || empty( $all_feedback ) | |
| 1003 | +			 || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ | |
| 1004 | 1004 | |
| 1005 | - //fallback to data pre 1.7.4 | |
| 1005 | + //fallback to data pre 1.7.4 | |
| 1006 | 1006 | |
| 1007 | - // setup the sensei data query | |
| 1008 | - $args = array( | |
| 1009 | - 'post_id' => $question_id, | |
| 1010 | - 'user_id' => $user_id, | |
| 1011 | - 'type' => 'sensei_user_answer' | |
| 1012 | - ); | |
| 1013 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); | |
| 1007 | + // setup the sensei data query | |
| 1008 | + $args = array( | |
| 1009 | + 'post_id' => $question_id, | |
| 1010 | + 'user_id' => $user_id, | |
| 1011 | + 'type' => 'sensei_user_answer' | |
| 1012 | + ); | |
| 1013 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); | |
| 1014 | 1014 | |
| 1015 | - // set the default to false and return that if no old data is available. | |
| 1016 | -             if( isset( $question_activity->comment_ID ) ){ | |
| 1017 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); | |
| 1018 | - } | |
| 1015 | + // set the default to false and return that if no old data is available. | |
| 1016 | +			 if( isset( $question_activity->comment_ID ) ){ | |
| 1017 | + $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); | |
| 1018 | + } | |
| 1019 | 1019 | |
| 1020 | - // finally use the default question feedback | |
| 1021 | -             if( empty( $feedback ) ){ | |
| 1022 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); | |
| 1023 | - } | |
| 1020 | + // finally use the default question feedback | |
| 1021 | +			 if( empty( $feedback ) ){ | |
| 1022 | + $feedback = get_post_meta( $question_id, '_answer_feedback', true ); | |
| 1023 | + } | |
| 1024 | 1024 | |
| 1025 | - return $feedback; | |
| 1025 | + return $feedback; | |
| 1026 | 1026 | |
| 1027 | - } | |
| 1027 | + } | |
| 1028 | 1028 | |
| 1029 | - return $all_feedback[ $question_id ]; | |
| 1029 | + return $all_feedback[ $question_id ]; | |
| 1030 | 1030 | |
| 1031 | - } // end get_user_question_feedback | |
| 1031 | + } // end get_user_question_feedback | |
| 1032 | 1032 | |
| 1033 | - /** | |
| 1034 | - * Check if a quiz has no questions, and redirect back to lesson. | |
| 1035 | - * | |
| 1036 | - * Though a quiz is created for each lesson, it should not be visible | |
| 1037 | - * unless it has questions. | |
| 1038 | - * | |
| 1039 | - * @since 1.9.0 | |
| 1040 | - * @access public | |
| 1041 | - * @param none | |
| 1042 | - * @return void | |
| 1043 | - */ | |
| 1033 | + /** | |
| 1034 | + * Check if a quiz has no questions, and redirect back to lesson. | |
| 1035 | + * | |
| 1036 | + * Though a quiz is created for each lesson, it should not be visible | |
| 1037 | + * unless it has questions. | |
| 1038 | + * | |
| 1039 | + * @since 1.9.0 | |
| 1040 | + * @access public | |
| 1041 | + * @param none | |
| 1042 | + * @return void | |
| 1043 | + */ | |
| 1044 | 1044 | |
| 1045 | -     public function quiz_has_no_questions() { | |
| 1045 | +	 public function quiz_has_no_questions() { | |
| 1046 | 1046 | |
| 1047 | 1047 | |
| 1048 | -         if( ! is_singular( 'quiz' ) )  { | |
| 1049 | - return; | |
| 1050 | - } | |
| 1048 | +		 if( ! is_singular( 'quiz' ) )  { | |
| 1049 | + return; | |
| 1050 | + } | |
| 1051 | 1051 | |
| 1052 | - global $post; | |
| 1052 | + global $post; | |
| 1053 | 1053 | |
| 1054 | - $lesson_id = $this->get_lesson_id($post->ID); | |
| 1054 | + $lesson_id = $this->get_lesson_id($post->ID); | |
| 1055 | 1055 | |
| 1056 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); | |
| 1056 | + $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); | |
| 1057 | 1057 | |
| 1058 | - $lesson = get_post($lesson_id); | |
| 1058 | + $lesson = get_post($lesson_id); | |
| 1059 | 1059 | |
| 1060 | -         if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { | |
| 1060 | +		 if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { | |
| 1061 | 1061 | |
| 1062 | - wp_redirect(get_permalink($lesson->ID), 301); | |
| 1063 | - exit; | |
| 1062 | + wp_redirect(get_permalink($lesson->ID), 301); | |
| 1063 | + exit; | |
| 1064 | 1064 | |
| 1065 | - } | |
| 1065 | + } | |
| 1066 | 1066 | |
| 1067 | - } // end quiz_has_no_questions | |
| 1067 | + } // end quiz_has_no_questions | |
| 1068 | 1068 | |
| 1069 | 1069 | /** | 
| 1070 | - * Deprecate the sensei_single_main_content on the single-quiz template. | |
| 1071 | - * | |
| 1072 | - * @deprecated since 1.9.0 | |
| 1073 | - */ | |
| 1070 | + * Deprecate the sensei_single_main_content on the single-quiz template. | |
| 1071 | + * | |
| 1072 | + * @deprecated since 1.9.0 | |
| 1073 | + */ | |
| 1074 | 1074 |   public static function deprecate_quiz_sensei_single_main_content_hook(){ | 
| 1075 | 1075 | |
| 1076 | -     sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); | |
| 1076 | +	 sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); | |
| 1077 | 1077 | |
| 1078 | 1078 | } | 
| 1079 | - /* | |
| 1079 | + /* | |
| 1080 | 1080 | * Deprecate the sensei_quiz_single_title on the single-quiz template. | 
| 1081 | 1081 | * | 
| 1082 | 1082 | * @deprecated since 1.9.0 | 
| 1083 | 1083 | */ | 
| 1084 | -     public static function deprecate_quiz_sensei_quiz_single_title_hook(){ | |
| 1084 | +	 public static function deprecate_quiz_sensei_quiz_single_title_hook(){ | |
| 1085 | 1085 | |
| 1086 | -         sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); | |
| 1086 | +		 sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); | |
| 1087 | 1087 | |
| 1088 | - } | |
| 1088 | + } | |
| 1089 | 1089 | |
| 1090 | - /** | |
| 1091 | - * Filter the single title and add the Quiz to it. | |
| 1092 | - * | |
| 1093 | - * @param string $title | |
| 1094 | - * @param int $id title post id | |
| 1095 | - * @return string $quiz_title | |
| 1096 | - */ | |
| 1097 | -     public static function single_quiz_title( $title, $post_id ){ | |
| 1090 | + /** | |
| 1091 | + * Filter the single title and add the Quiz to it. | |
| 1092 | + * | |
| 1093 | + * @param string $title | |
| 1094 | + * @param int $id title post id | |
| 1095 | + * @return string $quiz_title | |
| 1096 | + */ | |
| 1097 | +	 public static function single_quiz_title( $title, $post_id ){ | |
| 1098 | 1098 | |
| 1099 | -         if( 'quiz' == get_post_type( $post_id ) ){ | |
| 1099 | +		 if( 'quiz' == get_post_type( $post_id ) ){ | |
| 1100 | 1100 | |
| 1101 | - $title_with_no_quizzes = $title; | |
| 1101 | + $title_with_no_quizzes = $title; | |
| 1102 | 1102 | |
| 1103 | - // if the title has quiz, remove it: legacy titles have the word quiz stored. | |
| 1104 | -             if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ | |
| 1103 | + // if the title has quiz, remove it: legacy titles have the word quiz stored. | |
| 1104 | +			 if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ | |
| 1105 | 1105 | |
| 1106 | - // remove all possible appearances of quiz | |
| 1107 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); | |
| 1108 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); | |
| 1109 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); | |
| 1106 | + // remove all possible appearances of quiz | |
| 1107 | + $title_with_no_quizzes = str_replace( 'quiz', '', $title ); | |
| 1108 | + $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); | |
| 1109 | + $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); | |
| 1110 | 1110 | |
| 1111 | - } | |
| 1111 | + } | |
| 1112 | 1112 | |
| 1113 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); | |
| 1114 | - } | |
| 1113 | + $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); | |
| 1114 | + } | |
| 1115 | 1115 | |
| 1116 | - /** | |
| 1117 | - * hook document in class-woothemes-sensei-message.php | |
| 1118 | - */ | |
| 1119 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); | |
| 1116 | + /** | |
| 1117 | + * hook document in class-woothemes-sensei-message.php | |
| 1118 | + */ | |
| 1119 | + return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); | |
| 1120 | 1120 | |
| 1121 | - } | |
| 1121 | + } | |
| 1122 | 1122 | |
| 1123 | - /** | |
| 1124 | - * Initialize the quiz question loop on the single quiz template | |
| 1125 | - * | |
| 1126 | - * The function will create a global quiz loop varialbe. | |
| 1127 | - * | |
| 1128 | - * @since 1.9.0 | |
| 1129 | - * | |
| 1130 | - */ | |
| 1131 | -     public static function start_quiz_questions_loop(){ | |
| 1123 | + /** | |
| 1124 | + * Initialize the quiz question loop on the single quiz template | |
| 1125 | + * | |
| 1126 | + * The function will create a global quiz loop varialbe. | |
| 1127 | + * | |
| 1128 | + * @since 1.9.0 | |
| 1129 | + * | |
| 1130 | + */ | |
| 1131 | +	 public static function start_quiz_questions_loop(){ | |
| 1132 | 1132 | |
| 1133 | - global $sensei_question_loop; | |
| 1133 | + global $sensei_question_loop; | |
| 1134 | 1134 | |
| 1135 | - //intialize the questions loop object | |
| 1136 | - $sensei_question_loop['current'] = -1; | |
| 1137 | - $sensei_question_loop['total'] = 0; | |
| 1138 | - $sensei_question_loop['questions'] = array(); | |
| 1135 | + //intialize the questions loop object | |
| 1136 | + $sensei_question_loop['current'] = -1; | |
| 1137 | + $sensei_question_loop['total'] = 0; | |
| 1138 | + $sensei_question_loop['questions'] = array(); | |
| 1139 | 1139 | |
| 1140 | 1140 | |
| 1141 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); | |
| 1141 | + $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); | |
| 1142 | 1142 | |
| 1143 | -         if( count( $questions  ) > 0  ){ | |
| 1143 | +		 if( count( $questions  ) > 0  ){ | |
| 1144 | 1144 | |
| 1145 | - $sensei_question_loop['total'] = count( $questions ); | |
| 1146 | - $sensei_question_loop['questions'] = $questions; | |
| 1147 | - $sensei_question_loop['quiz_id'] = get_the_ID(); | |
| 1145 | + $sensei_question_loop['total'] = count( $questions ); | |
| 1146 | + $sensei_question_loop['questions'] = $questions; | |
| 1147 | + $sensei_question_loop['quiz_id'] = get_the_ID(); | |
| 1148 | 1148 | |
| 1149 | - } | |
| 1149 | + } | |
| 1150 | 1150 | |
| 1151 | - }// static function | |
| 1151 | + }// static function | |
| 1152 | 1152 | |
| 1153 | - /** | |
| 1154 | - * Initialize the quiz question loop on the single quiz template | |
| 1155 | - * | |
| 1156 | - * The function will create a global quiz loop varialbe. | |
| 1157 | - * | |
| 1158 | - * @since 1.9.0 | |
| 1159 | - * | |
| 1160 | - */ | |
| 1161 | -     public static function stop_quiz_questions_loop(){ | |
| 1153 | + /** | |
| 1154 | + * Initialize the quiz question loop on the single quiz template | |
| 1155 | + * | |
| 1156 | + * The function will create a global quiz loop varialbe. | |
| 1157 | + * | |
| 1158 | + * @since 1.9.0 | |
| 1159 | + * | |
| 1160 | + */ | |
| 1161 | +	 public static function stop_quiz_questions_loop(){ | |
| 1162 | 1162 | |
| 1163 | - $sensei_question_loop['total'] = 0; | |
| 1164 | - $sensei_question_loop['questions'] = array(); | |
| 1165 | - $sensei_question_loop['quiz_id'] = ''; | |
| 1163 | + $sensei_question_loop['total'] = 0; | |
| 1164 | + $sensei_question_loop['questions'] = array(); | |
| 1165 | + $sensei_question_loop['quiz_id'] = ''; | |
| 1166 | 1166 | |
| 1167 | - } | |
| 1167 | + } | |
| 1168 | 1168 | |
| 1169 | - /** | |
| 1170 | - * Output the title for the single quiz page | |
| 1171 | - * | |
| 1172 | - * @since 1.9.0 | |
| 1173 | - */ | |
| 1174 | -     public static function the_title(){ | |
| 1175 | - ?> | |
| 1169 | + /** | |
| 1170 | + * Output the title for the single quiz page | |
| 1171 | + * | |
| 1172 | + * @since 1.9.0 | |
| 1173 | + */ | |
| 1174 | +	 public static function the_title(){ | |
| 1175 | + ?> | |
| 1176 | 1176 | <header> | 
| 1177 | 1177 | |
| 1178 | 1178 | <h1> | 
| 1179 | 1179 | |
| 1180 | 1180 | <?php | 
| 1181 | - /** | |
| 1182 | - * Filter documented in class-sensei-messages.php the_title | |
| 1183 | - */ | |
| 1184 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); | |
| 1185 | - ?> | |
| 1181 | + /** | |
| 1182 | + * Filter documented in class-sensei-messages.php the_title | |
| 1183 | + */ | |
| 1184 | + echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); | |
| 1185 | + ?> | |
| 1186 | 1186 | |
| 1187 | 1187 | </h1> | 
| 1188 | 1188 | |
| 1189 | 1189 | </header> | 
| 1190 | 1190 | |
| 1191 | 1191 | <?php | 
| 1192 | - }//the_title | |
| 1192 | + }//the_title | |
| 1193 | 1193 | |
| 1194 | - /** | |
| 1195 | - * Output the sensei quiz status message. | |
| 1196 | - * | |
| 1197 | - * @param $quiz_id | |
| 1198 | - */ | |
| 1199 | -    public static function  the_user_status_message( $quiz_id ){ | |
| 1194 | + /** | |
| 1195 | + * Output the sensei quiz status message. | |
| 1196 | + * | |
| 1197 | + * @param $quiz_id | |
| 1198 | + */ | |
| 1199 | +	public static function  the_user_status_message( $quiz_id ){ | |
| 1200 | 1200 | |
| 1201 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 1202 | - $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); | |
| 1203 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; | |
| 1201 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
| 1202 | + $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); | |
| 1203 | + echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; | |
| 1204 | 1204 | |
| 1205 | - } | |
| 1205 | + } | |
| 1206 | 1206 | |
| 1207 | - /** | |
| 1208 | - * This functions runs the old sensei_quiz_action_buttons action | |
| 1209 | - * for backwards compatiblity sake. | |
| 1210 | - * | |
| 1211 | - * @since 1.9.0 | |
| 1212 | - * @deprecated | |
| 1213 | - */ | |
| 1214 | -     public static function deprecate_sensei_quiz_action_buttons_hook(){ | |
| 1207 | + /** | |
| 1208 | + * This functions runs the old sensei_quiz_action_buttons action | |
| 1209 | + * for backwards compatiblity sake. | |
| 1210 | + * | |
| 1211 | + * @since 1.9.0 | |
| 1212 | + * @deprecated | |
| 1213 | + */ | |
| 1214 | +	 public static function deprecate_sensei_quiz_action_buttons_hook(){ | |
| 1215 | 1215 | |
| 1216 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); | |
| 1216 | + sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); | |
| 1217 | 1217 | |
| 1218 | - } | |
| 1218 | + } | |
| 1219 | 1219 | |
| 1220 | - /** | |
| 1221 | - * The quiz action buttons needed to ouput quiz | |
| 1222 | - * action such as reset complete and save. | |
| 1223 | - * | |
| 1224 | - * @since 1.3.0 | |
| 1225 | - */ | |
| 1226 | -     public static function action_buttons() { | |
| 1220 | + /** | |
| 1221 | + * The quiz action buttons needed to ouput quiz | |
| 1222 | + * action such as reset complete and save. | |
| 1223 | + * | |
| 1224 | + * @since 1.3.0 | |
| 1225 | + */ | |
| 1226 | +	 public static function action_buttons() { | |
| 1227 | 1227 | |
| 1228 | - global $post, $current_user; | |
| 1228 | + global $post, $current_user; | |
| 1229 | 1229 | |
| 1230 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); | |
| 1231 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); | |
| 1232 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); | |
| 1233 | - $show_actions = true; | |
| 1234 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); | |
| 1230 | + $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); | |
| 1231 | + $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); | |
| 1232 | + $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); | |
| 1233 | + $show_actions = true; | |
| 1234 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); | |
| 1235 | 1235 | |
| 1236 | - //setup quiz grade | |
| 1237 | - $user_quiz_grade = ''; | |
| 1238 | -         if( ! empty( $user_lesson_status  ) ){ | |
| 1239 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 1240 | - } | |
| 1236 | + //setup quiz grade | |
| 1237 | + $user_quiz_grade = ''; | |
| 1238 | +		 if( ! empty( $user_lesson_status  ) ){ | |
| 1239 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 1240 | + } | |
| 1241 | 1241 | |
| 1242 | 1242 | |
| 1243 | -         if( intval( $lesson_prerequisite ) > 0 ) { | |
| 1243 | +		 if( intval( $lesson_prerequisite ) > 0 ) { | |
| 1244 | 1244 | |
| 1245 | - // If the user hasn't completed the prereq then hide the current actions | |
| 1246 | - $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); | |
| 1245 | + // If the user hasn't completed the prereq then hide the current actions | |
| 1246 | + $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); | |
| 1247 | 1247 | |
| 1248 | - } | |
| 1249 | -         if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { | |
| 1248 | + } | |
| 1249 | +		 if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { | |
| 1250 | 1250 | |
| 1251 | - // Get Reset Settings | |
| 1252 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> | |
| 1251 | + // Get Reset Settings | |
| 1252 | + $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> | |
| 1253 | 1253 | |
| 1254 | 1254 | <!-- Action Nonce's --> | 
| 1255 | 1255 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" | 
| @@ -1276,55 +1276,55 @@ discard block | ||
| 1276 | 1276 | |
| 1277 | 1277 | <?php } | 
| 1278 | 1278 | |
| 1279 | - } // End sensei_quiz_action_buttons() | |
| 1280 | - | |
| 1281 | - /** | |
| 1282 | - * Fetch the quiz grade | |
| 1283 | - * | |
| 1284 | - * @since 1.9.0 | |
| 1285 | - * | |
| 1286 | - * @param int $lesson_id | |
| 1287 | - * @param int $user_id | |
| 1288 | - * | |
| 1289 | - * @return double $user_quiz_grade | |
| 1290 | - */ | |
| 1291 | -     public static function get_user_quiz_grade( $lesson_id, $user_id ){ | |
| 1292 | - | |
| 1293 | - // get the quiz grade | |
| 1294 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 1295 | - $user_quiz_grade = 0; | |
| 1296 | -         if( isset( $user_lesson_status->comment_ID ) ) { | |
| 1297 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 1298 | - } | |
| 1299 | - | |
| 1300 | - return (double) $user_quiz_grade; | |
| 1301 | - | |
| 1302 | - } | |
| 1303 | - | |
| 1304 | - /** | |
| 1305 | - * Check the quiz reset property for a given lesson's quiz. | |
| 1306 | - * | |
| 1307 | - * The data is stored on the quiz but going forward the quiz post | |
| 1308 | - * type will be retired, hence the lesson_id is a require parameter. | |
| 1309 | - * | |
| 1310 | - * @since 1.9.0 | |
| 1311 | - * | |
| 1312 | - * @param int $lesson_id | |
| 1313 | - * @return bool | |
| 1314 | - */ | |
| 1315 | -     public static function is_reset_allowed( $lesson_id ){ | |
| 1316 | - | |
| 1317 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 1318 | - | |
| 1319 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); | |
| 1320 | - //backwards compatibility | |
| 1321 | -         if( 'on' == $reset_allowed ) { | |
| 1322 | - $reset_allowed = 1; | |
| 1323 | - } | |
| 1324 | - | |
| 1325 | - return (bool) $reset_allowed; | |
| 1326 | - | |
| 1327 | - } | |
| 1279 | + } // End sensei_quiz_action_buttons() | |
| 1280 | + | |
| 1281 | + /** | |
| 1282 | + * Fetch the quiz grade | |
| 1283 | + * | |
| 1284 | + * @since 1.9.0 | |
| 1285 | + * | |
| 1286 | + * @param int $lesson_id | |
| 1287 | + * @param int $user_id | |
| 1288 | + * | |
| 1289 | + * @return double $user_quiz_grade | |
| 1290 | + */ | |
| 1291 | +	 public static function get_user_quiz_grade( $lesson_id, $user_id ){ | |
| 1292 | + | |
| 1293 | + // get the quiz grade | |
| 1294 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); | |
| 1295 | + $user_quiz_grade = 0; | |
| 1296 | +		 if( isset( $user_lesson_status->comment_ID ) ) { | |
| 1297 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); | |
| 1298 | + } | |
| 1299 | + | |
| 1300 | + return (double) $user_quiz_grade; | |
| 1301 | + | |
| 1302 | + } | |
| 1303 | + | |
| 1304 | + /** | |
| 1305 | + * Check the quiz reset property for a given lesson's quiz. | |
| 1306 | + * | |
| 1307 | + * The data is stored on the quiz but going forward the quiz post | |
| 1308 | + * type will be retired, hence the lesson_id is a require parameter. | |
| 1309 | + * | |
| 1310 | + * @since 1.9.0 | |
| 1311 | + * | |
| 1312 | + * @param int $lesson_id | |
| 1313 | + * @return bool | |
| 1314 | + */ | |
| 1315 | +	 public static function is_reset_allowed( $lesson_id ){ | |
| 1316 | + | |
| 1317 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); | |
| 1318 | + | |
| 1319 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); | |
| 1320 | + //backwards compatibility | |
| 1321 | +		 if( 'on' == $reset_allowed ) { | |
| 1322 | + $reset_allowed = 1; | |
| 1323 | + } | |
| 1324 | + | |
| 1325 | + return (bool) $reset_allowed; | |
| 1326 | + | |
| 1327 | + } | |
| 1328 | 1328 | |
| 1329 | 1329 | } // End Class WooThemes_Sensei_Quiz | 
| 1330 | 1330 | |