/** * Display the report. */ public function display($quiz, $cm, $course) { global $CFG, $DB, $OUTPUT, $PAGE; $this->context = context_module::instance($cm->id); // Work out the display options. $download = optional_param('download', '', PARAM_ALPHA); $everything = optional_param('everything', 0, PARAM_BOOL); $recalculate = optional_param('recalculate', 0, PARAM_BOOL); // A qid paramter indicates we should display the detailed analysis of a question. $qid = optional_param('qid', 0, PARAM_INT); $slot = optional_param('slot', 0, PARAM_INT); $pageoptions = array(); $pageoptions['id'] = $cm->id; $pageoptions['mode'] = 'statistics'; $reporturl = new moodle_url('/mod/quiz/report.php', $pageoptions); $mform = new quiz_statistics_settings_form($reporturl); if ($fromform = $mform->get_data()) { $useallattempts = $fromform->useallattempts; if ($fromform->useallattempts) { set_user_preference('quiz_report_statistics_useallattempts', $fromform->useallattempts); } else { unset_user_preference('quiz_report_statistics_useallattempts'); } } else { $useallattempts = get_user_preferences('quiz_report_statistics_useallattempts', 0); } // Find out current groups mode. $currentgroup = $this->get_current_group($cm, $course, $this->context); $nostudentsingroup = false; // True if a group is selected and there is no one in it. if (empty($currentgroup)) { $currentgroup = 0; $groupstudents = array(); } else if ($currentgroup == self::NO_GROUPS_ALLOWED) { $groupstudents = array(); $nostudentsingroup = true; } else { // All users who can attempt quizzes and who are in the currently selected group. $groupstudents = get_users_by_capability($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), '', '', '', '', $currentgroup, '', false); if (!$groupstudents) { $nostudentsingroup = true; } } // If recalculate was requested, handle that. if ($recalculate && confirm_sesskey()) { $this->clear_cached_data($quiz->id, $currentgroup, $useallattempts); redirect($reporturl); } // Set up the main table. $this->table = new quiz_statistics_table(); if ($everything) { $report = get_string('completestatsfilename', 'quiz_statistics'); } else { $report = get_string('questionstatsfilename', 'quiz_statistics'); } $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $filename = quiz_report_download_filename($report, $courseshortname, $quiz->name); $this->table->is_downloading($download, $filename, get_string('quizstructureanalysis', 'quiz_statistics')); // Load the questions. $questions = quiz_report_get_significant_questions($quiz); $questionids = array(); foreach ($questions as $question) { $questionids[] = $question->id; } $fullquestions = question_load_questions($questionids); foreach ($questions as $qno => $question) { $q = $fullquestions[$question->id]; $q->maxmark = $question->maxmark; $q->slot = $qno; $q->number = $question->number; $questions[$qno] = $q; } // Get the data to be displayed. list($quizstats, $questions, $subquestions, $s) = $this->get_quiz_and_questions_stats($quiz, $currentgroup, $nostudentsingroup, $useallattempts, $groupstudents, $questions); $quizinfo = $this->get_formatted_quiz_info_data($course, $cm, $quiz, $quizstats); // Set up the table, if there is data. if ($s) { $this->table->statistics_setup($quiz, $cm->id, $reporturl, $s); } // Print the page header stuff (if not downloading. if (!$this->table->is_downloading()) { $this->print_header_and_tabs($cm, $course, $quiz, 'statistics'); if (groups_get_activity_groupmode($cm)) { groups_print_activity_menu($cm, $reporturl->out()); if ($currentgroup && !$groupstudents) { $OUTPUT->notification(get_string('nostudentsingroup', 'quiz_statistics')); } } if (!quiz_questions_in_quiz($quiz->questions)) { echo quiz_no_questions_message($quiz, $cm, $this->context); } else if (!$this->table->is_downloading() && $s == 0) { echo $OUTPUT->notification(get_string('noattempts', 'quiz')); } // Print display options form. $mform->set_data(array('useallattempts' => $useallattempts)); $mform->display(); } if ($everything) { // Implies is downloading. // Overall report, then the analysis of each question. $this->download_quiz_info_table($quizinfo); if ($s) { $this->output_quiz_structure_analysis_table($s, $questions, $subquestions); if ($this->table->is_downloading() == 'xhtml') { $this->output_statistics_graph($quizstats->id, $s); } foreach ($questions as $question) { if (question_bank::get_qtype( $question->qtype, false)->can_analyse_responses()) { $this->output_individual_question_response_analysis( $question, $reporturl, $quizstats); } else if (!empty($question->_stats->subquestions)) { $subitemstodisplay = explode(',', $question->_stats->subquestions); foreach ($subitemstodisplay as $subitemid) { $this->output_individual_question_response_analysis( $subquestions[$subitemid], $reporturl, $quizstats); } } } } $this->table->export_class_instance()->finish_document(); } else if ($slot) { // Report on an individual question indexed by position. if (!isset($questions[$slot])) { print_error('questiondoesnotexist', 'question'); } $this->output_individual_question_data($quiz, $questions[$slot]); $this->output_individual_question_response_analysis( $questions[$slot], $reporturl, $quizstats); // Back to overview link. echo $OUTPUT->box('<a href="' . $reporturl->out() . '">' . get_string('backtoquizreport', 'quiz_statistics') . '</a>', 'backtomainstats boxaligncenter generalbox boxwidthnormal mdl-align'); } else if ($qid) { // Report on an individual sub-question indexed questionid. if (!isset($subquestions[$qid])) { print_error('questiondoesnotexist', 'question'); } $this->output_individual_question_data($quiz, $subquestions[$qid]); $this->output_individual_question_response_analysis( $subquestions[$qid], $reporturl, $quizstats); // Back to overview link. echo $OUTPUT->box('<a href="' . $reporturl->out() . '">' . get_string('backtoquizreport', 'quiz_statistics') . '</a>', 'boxaligncenter generalbox boxwidthnormal mdl-align'); } else if ($this->table->is_downloading()) { // Downloading overview report. $this->download_quiz_info_table($quizinfo); $this->output_quiz_structure_analysis_table($s, $questions, $subquestions); $this->table->finish_output(); } else { // On-screen display of overview report. echo $OUTPUT->heading(get_string('quizinformation', 'quiz_statistics')); echo $this->output_caching_info($quizstats, $quiz->id, $currentgroup, $groupstudents, $useallattempts, $reporturl); echo $this->everything_download_options(); echo $this->output_quiz_info_table($quizinfo); if ($s) { echo $OUTPUT->heading(get_string('quizstructureanalysis', 'quiz_statistics')); $this->output_quiz_structure_analysis_table($s, $questions, $subquestions); $this->output_statistics_graph($quizstats->id, $s); } } return true; }
/** * Display the report. */ public function display($quiz, $cm, $course) { global $OUTPUT; raise_memory_limit(MEMORY_HUGE); $this->context = context_module::instance($cm->id); if (!quiz_has_questions($quiz->id)) { $this->print_header_and_tabs($cm, $course, $quiz, 'statistics'); echo quiz_no_questions_message($quiz, $cm, $this->context); return true; } // Work out the display options. $download = optional_param('download', '', PARAM_ALPHA); $everything = optional_param('everything', 0, PARAM_BOOL); $recalculate = optional_param('recalculate', 0, PARAM_BOOL); // A qid paramter indicates we should display the detailed analysis of a sub question. $qid = optional_param('qid', 0, PARAM_INT); $slot = optional_param('slot', 0, PARAM_INT); $variantno = optional_param('variant', null, PARAM_INT); $whichattempts = optional_param('whichattempts', $quiz->grademethod, PARAM_INT); $whichtries = optional_param('whichtries', question_attempt::LAST_TRY, PARAM_ALPHA); $pageoptions = array(); $pageoptions['id'] = $cm->id; $pageoptions['mode'] = 'statistics'; $reporturl = new moodle_url('/mod/quiz/report.php', $pageoptions); $mform = new quiz_statistics_settings_form($reporturl, compact('quiz')); $mform->set_data(array('whichattempts' => $whichattempts, 'whichtries' => $whichtries)); if ($whichattempts != $quiz->grademethod) { $reporturl->param('whichattempts', $whichattempts); } if ($whichtries != question_attempt::LAST_TRY) { $reporturl->param('whichtries', $whichtries); } // Find out current groups mode. $currentgroup = $this->get_current_group($cm, $course, $this->context); $nostudentsingroup = false; // True if a group is selected and there is no one in it. if (empty($currentgroup)) { $currentgroup = 0; $groupstudents = array(); } else { if ($currentgroup == self::NO_GROUPS_ALLOWED) { $groupstudents = array(); $nostudentsingroup = true; } else { // All users who can attempt quizzes and who are in the currently selected group. $groupstudents = get_users_by_capability($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), '', '', '', '', $currentgroup, '', false); if (!$groupstudents) { $nostudentsingroup = true; } } } $qubaids = quiz_statistics_qubaids_condition($quiz->id, $groupstudents, $whichattempts); // If recalculate was requested, handle that. if ($recalculate && confirm_sesskey()) { $this->clear_cached_data($qubaids); redirect($reporturl); } // Set up the main table. $this->table = new quiz_statistics_table(); if ($everything) { $report = get_string('completestatsfilename', 'quiz_statistics'); } else { $report = get_string('questionstatsfilename', 'quiz_statistics'); } $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $filename = quiz_report_download_filename($report, $courseshortname, $quiz->name); $this->table->is_downloading($download, $filename, get_string('quizstructureanalysis', 'quiz_statistics')); $questions = $this->load_and_initialise_questions_for_calculations($quiz); // Print the page header stuff (if not downloading. if (!$this->table->is_downloading()) { $this->print_header_and_tabs($cm, $course, $quiz, 'statistics'); } if (!$nostudentsingroup) { // Get the data to be displayed. $progress = $this->get_progress_trace_instance(); list($quizstats, $questionstats) = $this->get_all_stats_and_analysis($quiz, $whichattempts, $whichtries, $groupstudents, $questions, $progress); } else { // Or create empty stats containers. $quizstats = new \quiz_statistics\calculated($whichattempts); $questionstats = new \core_question\statistics\questions\all_calculated_for_qubaid_condition(); } // Set up the table, if there is data. if ($quizstats->s()) { $this->table->statistics_setup($quiz, $cm->id, $reporturl, $quizstats->s()); } // Print the rest of the page header stuff (if not downloading. if (!$this->table->is_downloading()) { if (groups_get_activity_groupmode($cm)) { groups_print_activity_menu($cm, $reporturl->out()); if ($currentgroup && !$groupstudents) { $OUTPUT->notification(get_string('nostudentsingroup', 'quiz_statistics')); } } if (!$this->table->is_downloading() && $quizstats->s() == 0) { echo $OUTPUT->notification(get_string('noattempts', 'quiz')); } foreach ($questionstats->any_error_messages() as $errormessage) { echo $OUTPUT->notification($errormessage); } // Print display options form. $mform->display(); } if ($everything) { // Implies is downloading. // Overall report, then the analysis of each question. $quizinfo = $quizstats->get_formatted_quiz_info_data($course, $cm, $quiz); $this->download_quiz_info_table($quizinfo); if ($quizstats->s()) { $this->output_quiz_structure_analysis_table($questionstats); if ($this->table->is_downloading() == 'xhtml' && $quizstats->s() != 0) { $this->output_statistics_graph($quiz->id, $currentgroup, $whichattempts); } $this->output_all_question_response_analysis($qubaids, $questions, $questionstats, $reporturl, $whichtries); } $this->table->export_class_instance()->finish_document(); } else { if ($qid) { // Report on an individual sub-question indexed questionid. if (is_null($questionstats->for_subq($qid, $variantno))) { print_error('questiondoesnotexist', 'question'); } $this->output_individual_question_data($quiz, $questionstats->for_subq($qid, $variantno)); $this->output_individual_question_response_analysis($questionstats->for_subq($qid, $variantno)->question, $variantno, $questionstats->for_subq($qid, $variantno)->s, $reporturl, $qubaids, $whichtries); // Back to overview link. echo $OUTPUT->box('<a href="' . $reporturl->out() . '">' . get_string('backtoquizreport', 'quiz_statistics') . '</a>', 'boxaligncenter generalbox boxwidthnormal mdl-align'); } else { if ($slot) { // Report on an individual question indexed by position. if (!isset($questions[$slot])) { print_error('questiondoesnotexist', 'question'); } if ($variantno === null && ($questionstats->for_slot($slot)->get_sub_question_ids() || $questionstats->for_slot($slot)->get_variants())) { if (!$this->table->is_downloading()) { $number = $questionstats->for_slot($slot)->question->number; echo $OUTPUT->heading(get_string('slotstructureanalysis', 'quiz_statistics', $number), 3); } $this->table->define_baseurl(new moodle_url($reporturl, array('slot' => $slot))); $this->table->format_and_add_array_of_rows($questionstats->structure_analysis_for_one_slot($slot)); } else { $this->output_individual_question_data($quiz, $questionstats->for_slot($slot, $variantno)); $this->output_individual_question_response_analysis($questions[$slot], $variantno, $questionstats->for_slot($slot, $variantno)->s, $reporturl, $qubaids, $whichtries); } if (!$this->table->is_downloading()) { // Back to overview link. echo $OUTPUT->box('<a href="' . $reporturl->out() . '">' . get_string('backtoquizreport', 'quiz_statistics') . '</a>', 'backtomainstats boxaligncenter generalbox boxwidthnormal mdl-align'); } else { $this->table->finish_output(); } } else { if ($this->table->is_downloading()) { // Downloading overview report. $quizinfo = $quizstats->get_formatted_quiz_info_data($course, $cm, $quiz); $this->download_quiz_info_table($quizinfo); if ($quizstats->s()) { $this->output_quiz_structure_analysis_table($questionstats); } $this->table->finish_output(); } else { // On-screen display of overview report. echo $OUTPUT->heading(get_string('quizinformation', 'quiz_statistics'), 3); echo $this->output_caching_info($quizstats->timemodified, $quiz->id, $groupstudents, $whichattempts, $reporturl); echo $this->everything_download_options(); $quizinfo = $quizstats->get_formatted_quiz_info_data($course, $cm, $quiz); echo $this->output_quiz_info_table($quizinfo); if ($quizstats->s()) { echo $OUTPUT->heading(get_string('quizstructureanalysis', 'quiz_statistics'), 3); $this->output_quiz_structure_analysis_table($questionstats); $this->output_statistics_graph($quiz->id, $currentgroup, $whichattempts); } } } } } return true; }