Пример #1
0
 /**
  * Get the quiz and question statistics, either by loading the cached results,
  * or by recomputing them.
  *
  * @param object $quiz the quiz settings.
  * @param string $whichattempts which attempts to use, represented internally as one of the constants as used in
  *                                   $quiz->grademethod ie.
  *                                   QUIZ_GRADEAVERAGE, QUIZ_GRADEHIGHEST, QUIZ_ATTEMPTLAST or QUIZ_ATTEMPTFIRST
  *                                   we calculate stats based on which attempts would affect the grade for each student.
  * @param array $groupstudents students in this group.
  * @param array $questions full question data.
  * @return array with 4 elements:
  *     - $quizstats The statistics for overall attempt scores.
  *     - $questionstats array of \core_question\statistics\questions\calculated objects keyed by slot.
  *     - $subquestionstats array of \core_question\statistics\questions\calculated_for_subquestion objects keyed by question id.
  */
 public function get_quiz_and_questions_stats($quiz, $whichattempts, $groupstudents, $questions)
 {
     $qubaids = quiz_statistics_qubaids_condition($quiz->id, $groupstudents, $whichattempts);
     $qcalc = new \core_question\statistics\questions\calculator($questions);
     $quizcalc = new quiz_statistics_calculator();
     if ($quizcalc->get_last_calculated_time($qubaids) === false) {
         // Recalculate now.
         list($questionstats, $subquestionstats) = $qcalc->calculate($qubaids);
         $quizstats = $quizcalc->calculate($quiz->id, $whichattempts, $groupstudents, count($questions), $qcalc->get_sum_of_mark_variance());
         if ($quizstats->s()) {
             $this->analyse_responses_for_all_questions_and_subquestions($qubaids, $questions, $subquestionstats);
         }
     } else {
         $quizstats = $quizcalc->get_cached($qubaids);
         list($questionstats, $subquestionstats) = $qcalc->get_cached($qubaids);
     }
     return array($quizstats, $questionstats, $subquestionstats);
 }