public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/classes/unitfrontend.php
/**
		 * Checks the supplied answers to see which questions are correct.
		 *
		 * @return Boolean Returns true if the trainee can continue (either passed in blocking, or survey/non-blocking), false otherwise.
		 */
Checks the supplied answers to see which questions are correct.
@return Boolean Returns true if the trainee can continue (either passed in blocking, or survey/non-blocking), false otherwise.
Checks the supplied answers to see which questions are correct . @return Boolean Returns true if the trainee can continue ( either passed in blocking or survey / non - blocking ) false otherwise .
public function check_quizzes_gradeQuestionsForQuiz() {
			$resultsList   = $this->unchecked_QuizAnswersToGrade;
			$resultDetails = array(
				'correct' => array(),
				'wrong'   => array(),
			);
			$gradingNeeded               = false;
			$gradingNeededBeforeContinue = false;
			$quizGradeNotificationNeeded = false;
						if ( 'survey' == $this->unitQuizDetails->quiz_type ) {
				$this->unitQuizDetails->quiz_show_answers = 'hide_answers';
				if ( 'show_responses' == $this->unitQuizDetails->quiz_show_survey_responses ) {
					$this->unitQuizDetails->quiz_show_answers = 'show_answers';
				}
			} 
			else {
				$resultDetails = $this->check_quizzes_checkForCorrectAnswers( $resultsList['answer_list'] );
				if ( ! empty( $resultDetails['needs_marking'] ) ) {
					$gradingNeeded = true;
					$courseDetails = WPCW_courses_getCourseDetails( $this->unitQuizDetails->parent_course_id );
					if ( 'quiz_block' == $this->unitQuizDetails->quiz_type ) {
						$gradingNeededBeforeContinue = true;
					}
				} 
				else {
					$resultsList['wrong_answer_list'] = $resultDetails['wrong'];
					$correctCount      = count( $resultDetails['correct'] );
					$totalQuestions    = count( $this->unitQuizDetails->questions );
					$correctPercentage = number_format( ( $correctCount / $totalQuestions ) * 100, 1 );
					if ( 'quiz_noblock' == $this->unitQuizDetails->quiz_type ) {
						$quizGradeNotificationNeeded = true;
					} 
					else {
						$minPassQuestions = ceil( ( $this->unitQuizDetails->quiz_pass_mark / 100 ) * $totalQuestions );
						if ( $correctPercentage >= $this->unitQuizDetails->quiz_pass_mark ) {
							$quizGradeNotificationNeeded = true;
						} 
						else {
							$this->update_quizzes_saveUserProgress_completeQuiz( $resultDetails, $resultsList['answer_list'], $resultsList['all_answer_list'] );
							if ( ! $this->check_quizzes_canUserRequestRetake() ) {
								$this->update_quizzes_setNextStepData( 'quiz_fail_no_retakes', false );
								do_action( 'wpcw_quiz_user_needs_unblocking', $this->currentUserID, $this->unitQuizDetails );
							}
							return false;
						}
					} 
				}
			}    
			$this->update_quizzes_saveUserProgress_completeQuiz( $resultDetails, $resultsList['answer_list'], $resultsList['all_answer_list'] );
			if ( $quizGradeNotificationNeeded ) {
				do_action( 'wpcw_quiz_graded', $this->currentUserID, $this->unitQuizDetails, false, false );
			}
			if ( $gradingNeeded ) {
				do_action( 'wpcw_quiz_needs_grading', $this->currentUserID, $this->unitQuizDetails );
			}
			if ( $gradingNeededBeforeContinue ) {
				return false;
			}
			return true;
		}
public function check_quizzes_gradeQuestionsForQuiz ( ) { $ resultsList = $ this -> unchecked_QuizAnswersToGrade ; $ resultDetails = array ( 'correct' => array ( ) , 'wrong' => array ( ) , ) ; $ gradingNeeded = false ; $ gradingNeededBeforeContinue = false ; $ quizGradeNotificationNeeded = false ; if ( 'survey' == $ this -> unitQuizDetails -> quiz_type ) { $ this -> unitQuizDetails -> quiz_show_answers = 'hide_answers' ; if ( 'show_responses' == $ this -> unitQuizDetails -> quiz_show_survey_responses ) { $ this -> unitQuizDetails -> quiz_show_answers = 'show_answers' ; } } else { $ resultDetails = $ this -> check_quizzes_checkForCorrectAnswers ( $ resultsList [ 'answer_list' ] ) ; if ( ! empty ( $ resultDetails [ 'needs_marking' ] ) ) { $ gradingNeeded = true ; $ courseDetails = WPCW_courses_getCourseDetails ( $ this -> unitQuizDetails -> parent_course_id ) ; if ( 'quiz_block' == $ this -> unitQuizDetails -> quiz_type ) { $ gradingNeededBeforeContinue = true ; } } else { $ resultsList [ 'wrong_answer_list' ] = $ resultDetails [ 'wrong' ] ; $ correctCount = count ( $ resultDetails [ 'correct' ] ) ; $ totalQuestions = count ( $ this -> unitQuizDetails -> questions ) ; $ correctPercentage = number_format ( ( $ correctCount / $ totalQuestions ) * 100 , 1 ) ; if ( 'quiz_noblock' == $ this -> unitQuizDetails -> quiz_type ) { $ quizGradeNotificationNeeded = true ; } else { $ minPassQuestions = ceil ( ( $ this -> unitQuizDetails -> quiz_pass_mark / 100 ) * $ totalQuestions ) ; if ( $ correctPercentage >= $ this -> unitQuizDetails -> quiz_pass_mark ) { $ quizGradeNotificationNeeded = true ; } else { $ this -> update_quizzes_saveUserProgress_completeQuiz ( $ resultDetails , $ resultsList [ 'answer_list' ] , $ resultsList [ 'all_answer_list' ] ) ; if ( ! $ this -> check_quizzes_canUserRequestRetake ( ) ) { $ this -> update_quizzes_setNextStepData ( 'quiz_fail_no_retakes' , false ) ; do_action ( 'wpcw_quiz_user_needs_unblocking' , $ this -> currentUserID , $ this -> unitQuizDetails ) ; } return false ; } } } } $ this -> update_quizzes_saveUserProgress_completeQuiz ( $ resultDetails , $ resultsList [ 'answer_list' ] , $ resultsList [ 'all_answer_list' ] ) ; if ( $ quizGradeNotificationNeeded ) { do_action ( 'wpcw_quiz_graded' , $ this -> currentUserID , $ this -> unitQuizDetails , false , false ) ; } if ( $ gradingNeeded ) { do_action ( 'wpcw_quiz_needs_grading' , $ this -> currentUserID , $ this -> unitQuizDetails ) ; } if ( $ gradingNeededBeforeContinue ) { return false ; } return true ; }
Checks the supplied answers to see which questions are correct.
Checks the supplied answers to see which questions are correct .
// Use the quiz answers that need grading, stored in the local variable. // Flag to indicate if grading is needed before the user continues. // If true, then we notify the user of the grade. // ### 3 - Do we need to check for correct answers?
 // Show answers only if this is a survey where we want trainees to see the results. // @since V2.90 // No answers to check. Say thanks // echo self::message_createMessage_success( __( 'Thank you for your responses. This unit is now complete.', 'wp-courseware' ) ); // #### Quiz Mode - so yes, we do check for correct answers. // We should answers for all questions by this point. // #### Step A - have open-ended questions that need marking. // Non-blocking quiz - so allowed to continue, but will be graded later. // Grading is needed before they continue, but don't want them to re-take the quiz. // #### Step B - we have no-open-ended questions, just T/F or Multiple-choice // Copy over the wrong answers. // Some statistics // Non-blocking quiz. // Store user quiz results // 2014-07-11 - Deprecated. Now being generated by the message summary for quizzes. /*
						  echo WPCW_UnitFrontend::message_createMessage_success(sprintf(__('You got <b>%d out of %d (%d%%)</b> questions correct! This unit is now complete.', 'wp-courseware'),
						  $correctCount, $totalQuestions, $correctPercentage
						  )) */ // Notify the user of their grade. // Blocking quiz (quiz_type == quiz_block). // 2014-01-15 - Added ceil() calculation to ensure calculation is consistent when showing the quiz title // above around the .wpcw_fe_quiz_title div. // They've passed. Report how many they got right. // 2014-07-11 - Deprecated. Now being generated by the message summary for quizzes. /* echo WPCW_UnitFrontend::message_createMessage_success(sprintf(__('You got <b>%d out of %d (%d%%)</b> questions correct! This unit is now complete.', 'wp-courseware'),
							  $correctCount, $totalQuestions, $correctPercentage
							  )); */ // Notify the user of their grade. // They've failed. Report which questions are correct or incorrect. // 2014-07-11 - Deprecated. Now being generated by the message summary for quizzes. // Show error that they've failed /* echo WPCW_UnitFrontend::message_createMessage_error(
							  sprintf(__('Unfortunately, you only got <b>%d out of %d (%d%%)</b> questions correct. You need to correctly answer <b>at least %d questions (%d%%)</b>.', 'wp-courseware'),
							  $correctCount, $totalQuestions, $correctPercentage,
							  $minPassQuestions, $this->unitQuizDetails->quiz_pass_mark
							  )); */ // Save the user progress anyway, so that we can record attempts. // Have they run out of quiz attempts? If so, we need to notify the admin and mark the latest attempt // as being the the last blocked one they can use. // Update progress in database with next new step. // Notify the admin that this user is blocked and needs unblocking // 2014-07-11 - Deprecated. Now being generated by the message summary for quizzes. // How many attempts have they now had?
 /*
							  $attemptCount = $this->fetch_quizzes_getQuizAttemptCount();
							  echo WPCW_UnitFrontend::message_createMessage_error(
							  ($attemptCount == 1
							  ? __('You have already had 1 previous attempt at this quiz.', 'wp-courseware')
							  : sprintf(__('You have already had %d previous attempts at this quiz.', 'wp-courseware'), $attemptCount)
							  )); */ // 2014-07-11 - Deprecated. Now being generated by the message summary for quizzes. // If quiz is a no-answers quiz, show the form without the errors, so that the user cannot keep guesssing to pass. //echo $this->render_quizzes_old_handleQuizRendering($resultsList, ('no_answers' != $this->unitQuizDetails->quiz_show_answers)); // Errors, so the user cannot progress yet. // end of blocking quiz check // end of survey check // ### 4 - Save the user progress // ### 5 - Notify the user of their grade. // Questions need grading, notify the admin // Notify the admin that questions need answering. // Questions need grading, so don't allow user to continue // If we get this far, the user may progress to next unit