예제 #1
0
 /**
  * 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.
  */
 function check_quizzes_gradeQuestionsForQuiz()
 {
     // Use the quiz answers that need grading, stored in the local variable.
     $resultsList = $this->unchecked_QuizAnswersToGrade;
     $resultDetails = array('correct' => array(), 'wrong' => array());
     // Flag to indicate if grading is needed before the user continues.
     $gradingNeeded = false;
     $gradingNeededBeforeContinue = false;
     // If true, then we notify the user of the grade.
     $quizGradeNotificationNeeded = false;
     // ### 3 - Do we need to check for correct answers?
     if ('survey' == $this->unitQuizDetails->quiz_type) {
         // Show answers only if this is a survey where we want trainees to see the results.
         // @since V2.90
         $this->unitQuizDetails->quiz_show_answers = 'hide_answers';
         if ('show_responses' == $this->unitQuizDetails->quiz_show_survey_responses) {
             $this->unitQuizDetails->quiz_show_answers = 'show_answers';
         }
         // No answers to check. Say thanks
         echo WPCW_UnitFrontend::message_createMessage_success(__('Thank you for your responses. This unit is now complete.', 'wp_courseware'));
     } else {
         $resultDetails = $this->check_quizzes_checkForCorrectAnswers($resultsList['answer_list']);
         // #### Step A - have open-ended questions that need marking.
         if (!empty($resultDetails['needs_marking'])) {
             $gradingNeeded = true;
             $courseDetails = WPCW_courses_getCourseDetails($this->unitQuizDetails->parent_course_id);
             // Non-blocking quiz - so allowed to continue, but will be graded later.
             if ('quiz_block' == $this->unitQuizDetails->quiz_type) {
                 // Grading is needed before they continue, but don't want them to re-take the quiz.
                 $gradingNeededBeforeContinue = true;
             }
         } else {
             // Copy over the wrong answers.
             $resultsList['wrong_answer_list'] = $resultDetails['wrong'];
             // Some statistics
             $correctCount = count($resultDetails['correct']);
             $totalQuestions = count($this->unitQuizDetails->questions);
             $correctPercentage = number_format($correctCount / $totalQuestions * 100, 1);
             // Non-blocking quiz.
             if ('quiz_noblock' == $this->unitQuizDetails->quiz_type) {
                 // 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.
                 $quizGradeNotificationNeeded = true;
             } else {
                 // 2014-01-15 - Added ceil() calculation to ensure calculation is consistent when showing the quiz title
                 // above around the .wpcw_fe_quiz_title div.
                 $minPassQuestions = ceil($this->unitQuizDetails->quiz_pass_mark / 100 * $totalQuestions);
                 // They've passed. Report how many they got right.
                 if ($correctPercentage >= $this->unitQuizDetails->quiz_pass_mark) {
                     // 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.
                     $quizGradeNotificationNeeded = true;
                 } else {
                     // 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.
                     $this->update_quizzes_saveUserProgress_completeQuiz($resultDetails, $resultsList['answer_list']);
                     // 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.
                     if (!$this->check_quizzes_canUserRequestRetake()) {
                         // Update progress in database with next new step.
                         $this->update_quizzes_setNextStepData('quiz_fail_no_retakes', false);
                         // Notify the admin that this user is blocked and needs unblocking
                         do_action('wpcw_quiz_user_needs_unblocking', $this->currentUserID, $this->unitQuizDetails);
                     }
                     // 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.
                     return false;
                 }
             }
             // end of blocking quiz check
         }
     }
     // end of survey check
     // ### 4 - Save the user progress
     $this->update_quizzes_saveUserProgress_completeQuiz($resultDetails, $resultsList['answer_list']);
     // ### 5 - Notify the user of their grade.
     if ($quizGradeNotificationNeeded) {
         do_action('wpcw_quiz_graded', $this->currentUserID, $this->unitQuizDetails, false, false);
     }
     // Questions need grading, notify the admin
     if ($gradingNeeded) {
         // Notify the admin that questions need answering.
         do_action('wpcw_quiz_needs_grading', $this->currentUserID, $this->unitQuizDetails);
     }
     // Questions need grading, so don't allow user to continue
     if ($gradingNeededBeforeContinue) {
         return false;
     }
     // If we get this far, the user may progress to next unit
     return true;
 }