if ($groups) { if ($currentgroup = groups_get_activity_group($cm)) { $groups = array($currentgroup => ''); } else { $groups = false; //all participants mode } } } $line->y_order = array('allusers'); if ($groups) { foreach (array_keys($groups) as $group) { $useridingroup = get_users_by_capability($modcontext, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), '', '', '', '', $group, '', false); if ($useridingroup) { $useridingrouplist = join(',', array_keys($useridingroup)); $groupdata = quiz_report_grade_bands($bandwidth, $bands, $quizid, $useridingrouplist); if ($groupdata) { $line->parameter['bar_size'] = 1.2; $line->y_data['groupusers' . $group] = $groupdata; //only turn on legends if there is more than one set of bars $line->parameter['legend'] = 'outside-top'; $line->parameter['legend_border'] = 'black'; $line->parameter['legend_offset'] = 4; $line->y_format['groupusers' . $group] = array('colour' => graph_get_new_colour(), 'bar' => 'fill', 'shadow_offset' => 1, 'legend' => groups_get_group_name($group)); $line->y_order[] = 'groupusers' . $group; } } } } $line->parameter['y_min_left'] = 0; // start at 0
} $bandwidth = $quiz->grade / $bands; $bands = ceil($bands); $bandlabels = array(); for ($i = 0; $i < $quiz->grade; $i += $bandwidth) { $label = quiz_format_grade($quiz, $i) . ' - '; if ($quiz->grade > $i + $bandwidth) { $label .= quiz_format_grade($quiz, $i + $bandwidth); } else { $label .= quiz_format_grade($quiz, $quiz->grade); } $bandlabels[] = $label; } $line->x_data = $bandlabels; $line->y_format['allusers'] = array('colour' => 'red', 'bar' => 'fill', 'shadow_offset' => 1, 'legend' => get_string('allparticipants')); $line->y_data['allusers'] = quiz_report_grade_bands($bandwidth, $bands, $quizid, $groupusers); $line->y_order = array('allusers'); $line->parameter['y_min_left'] = 0; // start at 0 $line->parameter['y_max_left'] = max($line->y_data['allusers']); $line->parameter['y_decimal_left'] = 0; // 2 decimal places for y axis. //pick a sensible number of gridlines depending on max value on graph. $gridlines = max($line->y_data['allusers']); while ($gridlines >= 10) { if ($gridlines >= 50) { $gridlines = $gridlines / 5; } else { $gridlines = $gridlines / 2; } }
public function display($quiz, $cm, $course) { global $DB, $OUTPUT, $PAGE; list($currentgroup, $studentsjoins, $groupstudentsjoins, $allowedjoins) = $this->init( 'overview', 'quiz_overview_settings_form', $quiz, $cm, $course); $options = new quiz_overview_options('overview', $quiz, $cm, $course); if ($fromform = $this->form->get_data()) { $options->process_settings_from_form($fromform); } else { $options->process_settings_from_params(); } $this->form->set_data($options->get_initial_form_data()); // Load the required questions. $questions = quiz_report_get_significant_questions($quiz); // Prepare for downloading, if applicable. $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $table = new quiz_overview_table($quiz, $this->context, $this->qmsubselect, $options, $groupstudentsjoins, $studentsjoins, $questions, $options->get_url()); $filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'), $courseshortname, $quiz->name); $table->is_downloading($options->download, $filename, $courseshortname . ' ' . format_string($quiz->name, true)); if ($table->is_downloading()) { raise_memory_limit(MEMORY_EXTRA); } $this->hasgroupstudents = false; if (!empty($groupstudentsjoins->joins)) { $sql = "SELECT DISTINCT u.id FROM {user} u $groupstudentsjoins->joins WHERE $groupstudentsjoins->wheres"; $this->hasgroupstudents = $DB->record_exists_sql($sql, $groupstudentsjoins->params); } $hasstudents = false; if (!empty($studentsjoins->joins)) { $sql = "SELECT DISTINCT u.id FROM {user} u $studentsjoins->joins WHERE $studentsjoins->wheres"; $hasstudents = $DB->record_exists_sql($sql, $studentsjoins->params); } if ($options->attempts == self::ALL_WITH) { // This option is only available to users who can access all groups in // groups mode, so setting allowed to empty (which means all quiz attempts // are accessible, is not a security porblem. $allowedjoins = new \core\dml\sql_join(); } $this->course = $course; // Hack to make this available in process_actions. $this->process_actions($quiz, $cm, $currentgroup, $groupstudentsjoins, $allowedjoins, $options->get_url()); // Start output. if (!$table->is_downloading()) { // Only print headers if not asked to download data. $this->print_header_and_tabs($cm, $course, $quiz, $this->mode); } if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used, so output the group selector if we are not downloading. if (!$table->is_downloading()) { groups_print_activity_menu($cm, $options->get_url()); } } // Print information on the number of existing attempts. if (!$table->is_downloading()) { // Do not print notices when downloading. if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) { echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>'; } } $hasquestions = quiz_has_questions($quiz->id); if (!$table->is_downloading()) { if (!$hasquestions) { echo quiz_no_questions_message($quiz, $cm, $this->context); } else if (!$hasstudents) { echo $OUTPUT->notification(get_string('nostudentsyet')); } else if ($currentgroup && !$this->hasgroupstudents) { echo $OUTPUT->notification(get_string('nostudentsingroup')); } // Print the display options. $this->form->display(); } $hasstudents = $hasstudents && (!$currentgroup || $this->hasgroupstudents); if ($hasquestions && ($hasstudents || $options->attempts == self::ALL_WITH)) { // Construct the SQL. list($fields, $from, $where, $params) = $table->base_sql($allowedjoins); $table->set_count_sql("SELECT COUNT(1) FROM $from WHERE $where", $params); // Test to see if there are any regraded attempts to be listed. $fields .= ", COALESCE(( SELECT MAX(qqr.regraded) FROM {quiz_overview_regrades} qqr WHERE qqr.questionusageid = quiza.uniqueid ), -1) AS regraded"; if ($options->onlyregraded) { $where .= " AND COALESCE(( SELECT MAX(qqr.regraded) FROM {quiz_overview_regrades} qqr WHERE qqr.questionusageid = quiza.uniqueid ), -1) <> -1"; } $table->set_sql($fields, $from, $where, $params); if (!$table->is_downloading()) { // Output the regrade buttons. if (has_capability('mod/quiz:regrade', $this->context)) { $regradesneeded = $this->count_question_attempts_needing_regrade( $quiz, $groupstudentsjoins); if ($currentgroup) { $a= new stdClass(); $a->groupname = groups_get_group_name($currentgroup); $a->coursestudents = get_string('participants'); $a->countregradeneeded = $regradesneeded; $regradealldrydolabel = get_string('regradealldrydogroup', 'quiz_overview', $a); $regradealldrylabel = get_string('regradealldrygroup', 'quiz_overview', $a); $regradealllabel = get_string('regradeallgroup', 'quiz_overview', $a); } else { $regradealldrydolabel = get_string('regradealldrydo', 'quiz_overview', $regradesneeded); $regradealldrylabel = get_string('regradealldry', 'quiz_overview'); $regradealllabel = get_string('regradeall', 'quiz_overview'); } $displayurl = new moodle_url($options->get_url(), array('sesskey' => sesskey())); echo '<div class="mdl-align">'; echo '<form action="'.$displayurl->out_omit_querystring().'">'; echo '<div>'; echo html_writer::input_hidden_params($displayurl); echo '<input type="submit" class="btn btn-secondary" name="regradeall" value="'.$regradealllabel.'"/>'; echo '<input type="submit" class="btn btn-secondary m-l-1" name="regradealldry" value="' . $regradealldrylabel . '"/>'; if ($regradesneeded) { echo '<input type="submit" class="btn btn-secondary m-l-1" name="regradealldrydo" value="' . $regradealldrydolabel . '"/>'; } echo '</div>'; echo '</form>'; echo '</div>'; } // Print information on the grading method. if ($strattempthighlight = quiz_report_highlighting_grading_method( $quiz, $this->qmsubselect, $options->onlygraded)) { echo '<div class="quizattemptcounts">' . $strattempthighlight . '</div>'; } } // Define table columns. $columns = array(); $headers = array(); if (!$table->is_downloading() && $options->checkboxcolumn) { $columns[] = 'checkbox'; $headers[] = null; } $this->add_user_columns($table, $columns, $headers); $this->add_state_column($columns, $headers); $this->add_time_columns($columns, $headers); $this->add_grade_columns($quiz, $options->usercanseegrades, $columns, $headers, false); if (!$table->is_downloading() && has_capability('mod/quiz:regrade', $this->context) && $this->has_regraded_questions($from, $where, $params)) { $columns[] = 'regraded'; $headers[] = get_string('regrade', 'quiz_overview'); } if ($options->slotmarks) { foreach ($questions as $slot => $question) { // Ignore questions of zero length. $columns[] = 'qsgrade' . $slot; $header = get_string('qbrief', 'quiz', $question->number); if (!$table->is_downloading()) { $header .= '<br />'; } else { $header .= ' '; } $header .= '/' . quiz_rescale_grade($question->maxmark, $quiz, 'question'); $headers[] = $header; } } $this->set_up_table_columns($table, $columns, $headers, $this->get_base_url(), $options, false); $table->set_attribute('class', 'generaltable generalbox grades'); $table->out($options->pagesize, true); } if (!$table->is_downloading() && $options->usercanseegrades) { $output = $PAGE->get_renderer('mod_quiz'); list($bands, $bandwidth) = self::get_bands_count_and_width($quiz); $labels = self::get_bands_labels($bands, $bandwidth, $quiz); if ($currentgroup && $this->hasgroupstudents) { $sql = "SELECT qg.id FROM {quiz_grades} qg JOIN {user} u on u.id = qg.userid {$groupstudentsjoins->joins} WHERE qg.quiz = $quiz->id AND {$groupstudentsjoins->wheres}"; if ($DB->record_exists_sql($sql, $groupstudentsjoins->params)) { $data = quiz_report_grade_bands($bandwidth, $bands, $quiz->id, $groupstudentsjoins); $chart = self::get_chart($labels, $data); $graphname = get_string('overviewreportgraphgroup', 'quiz_overview', groups_get_group_name($currentgroup)); echo $output->chart($chart, $graphname); } } if ($DB->record_exists('quiz_grades', array('quiz'=> $quiz->id))) { $data = quiz_report_grade_bands($bandwidth, $bands, $quiz->id, new \core\dml\sql_join()); $chart = self::get_chart($labels, $data); $graphname = get_string('overviewreportgraph', 'quiz_overview'); echo $output->chart($chart, $graphname); } } return true; }