NOBUG more consistent use of URLs for the quiz reports.

This commit is contained in:
Tim Hunt 2010-07-28 15:08:34 +00:00
parent a88ba5700c
commit a49cb927fd
10 changed files with 62 additions and 55 deletions

View File

@ -522,8 +522,7 @@ if (!$quiz_reordertool) {
$notifystrings = array();
if ($quizhasattempts) {
$reviewlink = '<a href="' . $CFG->wwwroot . '/mod/quiz/report.php?mode=overview&amp;id=' . $cm->id . '">' .
quiz_num_attempt_summary($quiz, $cm) . '</a>';
$reviewlink = quiz_attempt_summary_link_to_reports($quiz, $cm, $contexts->lowest());
$notifystrings[] = get_string('cannoteditafterattempts', 'quiz', $reviewlink);
}
if ($quiz->shufflequestions) {

View File

@ -138,14 +138,9 @@
if ($showing == 'stats') {
// The $quiz objects returned by get_all_instances_in_course have the necessary $cm
// fields set to make the following call work.
$attemptcount = quiz_num_attempt_summary($quiz, $quiz);
if ($attemptcount) {
$data[] = "<a$class href=\"report.php?id=$quiz->coursemodule\">$attemptcount</a>";
} else {
$data[] = '';
}
} else if ($showing == 'scores') {
$data[] = quiz_attempt_summary_link_to_reports($quiz, $cm, $context);
} else if ($showing == 'scores') {
// Grade and feedback.
$attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'all');
list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context);

View File

@ -1510,9 +1510,6 @@ function quiz_print_overview($courses, &$htmlarray) {
* Return a textual summary of the number of attemtps that have been made at a particular quiz,
* returns '' if no attemtps have been made yet, unless $returnzero is passed as true.
*
* @global stdClass
* @global object
* @global object
* @param object $quiz the quiz object. Only $quiz->id is used at the moment.
* @param object $cm the cm object. Only $cm->course, $cm->groupmode and $cm->groupingid fields are used at the moment.
* @param boolean $returnzero if false (default), when no attempts have been made '' is returned instead of 'Attempts: 0'.
@ -1522,7 +1519,7 @@ function quiz_print_overview($courses, &$htmlarray) {
* "Attemtps 123 (45 from this group)".
*/
function quiz_num_attempt_summary($quiz, $cm, $returnzero = false, $currentgroup = 0) {
global $CFG, $USER, $DB;
global $DB, $USER;
$numattempts = $DB->count_records('quiz_attempts', array('quiz'=> $quiz->id, 'preview'=>0));
if ($numattempts || $returnzero) {
if (groups_get_activity_groupmode($cm)) {
@ -1549,13 +1546,31 @@ function quiz_num_attempt_summary($quiz, $cm, $returnzero = false, $currentgroup
}
/**
* @uses FEATURE_GROUPS
* @uses FEATURE_GROUPINGS
* @uses FEATURE_GROUPMEMBERSONLY
* @uses FEATURE_MOD_INTRO
* @uses FEATURE_COMPLETION_TRACKS_VIEWS
* @uses FEATURE_GRADE_HAS_GRADE
* @uses FEATURE_GRADE_OUTCOMES
* Returns the same as {@link quiz_num_attempt_summary()} but wrapped in a link
* to the quiz reports.
*
* @param object $quiz the quiz object. Only $quiz->id is used at the moment.
* @param object $cm the cm object. Only $cm->course, $cm->groupmode and $cm->groupingid fields are used at the moment.
* @param object $context the quiz context.
* @param boolean $returnzero if false (default), when no attempts have been made '' is returned instead of 'Attempts: 0'.
* @param int $currentgroup if there is a concept of current group where this method is being called
* (e.g. a report) pass it in here. Default 0 which means no current group.
* @return string HTML fragment for the link.
*/
function quiz_attempt_summary_link_to_reports($quiz, $cm, $context, $returnzero = false, $currentgroup = 0) {
global $CFG;
$summary = quiz_num_attempt_summary($quiz, $cm, $returnzero, $currentgroup);
if (!$summary) {
return '';
}
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
$url = new moodle_url('/mod/quiz/report.php', array(
'id' => $cm->id, 'mode' => quiz_report_default_report($context)));
return html_writer::link($url, $summary);
}
/**
* @param string $feature FEATURE_xx constant for requested feature
* @return bool True if quiz supports feature
*/
@ -1606,22 +1621,22 @@ function quiz_extend_navigation($quiznode, $course, $module, $cm) {
if (has_capability('mod/quiz:view', $context)) {
$url = new moodle_url('/mod/quiz/view.php', array('id'=>$cm->id));
$quiznode->add(get_string('info', 'quiz'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/info', ''));
$quiznode->add(get_string('info', 'quiz'), $url, navigation_node::TYPE_SETTING,
null, null, new pix_icon('i/info', ''));
}
if (has_capability('mod/quiz:viewreports', $context)) {
$url = new moodle_url('/mod/quiz/report.php', array('q'=>$cm->instance));
$reportnode = $quiznode->add(get_string('results', 'quiz'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
require_once($CFG->dirroot.'/mod/quiz/report/reportlib.php');
$reportlist = quiz_report_list($context);
$url = new moodle_url('/mod/quiz/report.php', array('id' => $cm->id, 'mode' => reset($reportlist)));
$reportnode = $quiznode->add(get_string('results', 'quiz'), $url, navigation_node::TYPE_SETTING,
null, null, new pix_icon('i/report', ''));
foreach ($reportlist as $report) {
if ($report != 'overview') {
$url = new moodle_url('/mod/quiz/report.php', array('q'=>$cm->instance, 'mode'=>$report));
} else {
$url = new moodle_url('/mod/quiz/report.php', array('q'=>$cm->instance));
}
$reportnode->add(get_string($report, 'quiz_'.$report), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/item', ''));
$url = new moodle_url('/mod/quiz/report.php', array('id' => $cm->id, 'mode' => $report));
$reportnode->add(get_string($report, 'quiz_'.$report), $url, navigation_node::TYPE_SETTING,
null, null, new pix_icon('i/item', ''));
}
}
}

View File

@ -1118,11 +1118,11 @@ function quiz_send_notification_emails($course, $quiz, $attempt, $context, $cm)
$a->courseshortname = $course->shortname;
// quiz info
$a->quizname = $quiz->name;
$a->quizreporturl = $CFG->wwwroot . '/mod/quiz/report.php?q=' . $quiz->id;
$a->quizreporturl = $CFG->wwwroot . '/mod/quiz/report.php?id=' . $cm->id;
$a->quizreportlink = '<a href="' . $a->quizreporturl . '">' . format_string($quiz->name) . ' report</a>';
$a->quizreviewurl = $CFG->wwwroot . '/mod/quiz/review.php?attempt=' . $attempt->id;
$a->quizreviewlink = '<a href="' . $a->quizreviewurl . '">' . format_string($quiz->name) . ' review</a>';
$a->quizurl = $CFG->wwwroot . '/mod/quiz/view.php?q=' . $quiz->id;
$a->quizurl = $CFG->wwwroot . '/mod/quiz/view.php?id=' . $cm->id;
$a->quizlink = '<a href="' . $a->quizurl . '">' . format_string($quiz->name) . '</a>';
// attempt info
$a->submissiontime = userdate($attempt->timefinish);

View File

@ -36,12 +36,7 @@
}
}
$url = new moodle_url('/mod/quiz/report.php');
if ($id !== 0) {
$url->param('id', $id);
} else {
$url->param('q', $q);
}
$url = new moodle_url('/mod/quiz/report.php', array('id' => $cm->id));
if ($mode !== '') {
$url->param('mode', $mode);
}
@ -54,15 +49,17 @@
if (count($reportlist)==0){
print_error('erroraccessingreport', 'quiz');
}
if ($mode == ''){
$mode = reset($reportlist);//first element in array
} elseif (!in_array($mode, $reportlist)){
if ($mode == '') {
// Default to first accessible report and redirect.
$url->param('mode', reset($reportlist));
redirect($url);
} else if (!in_array($mode, $reportlist)){
print_error('erroraccessingreport', 'quiz');
}
// if no questions have been set up yet redirect to edit.php
if (!$quiz->questions and has_capability('mod/quiz:manage', $context)) {
redirect('edit.php?cmid='.$cm->id);
redirect('edit.php?cmid=' . $cm->id);
}
// Upgrade any attempts that have not yet been upgraded to the
@ -79,17 +76,17 @@
/// Open the selected quiz report and display it
if (! is_readable("report/$mode/report.php")) {
if (!is_readable("report/$mode/report.php")) {
print_error('reportnotfound', 'quiz', '', $mode);
}
include("report/default.php"); // Parent class
include("report/default.php"); // Parent class
include("report/$mode/report.php");
$reportclassname = "quiz_{$mode}_report";
$report = new $reportclassname();
if (! $report->display($quiz, $cm, $course)) { // Run the report!
if (!$report->display($quiz, $cm, $course)) { // Run the report!
print_error("preprocesserror", 'quiz');
}

View File

@ -56,7 +56,6 @@ class quiz_overview_report extends quiz_default_report {
$pageoptions = array();
$pageoptions['id'] = $cm->id;
$pageoptions['q'] = $quiz->id;
$pageoptions['mode'] = 'overview';
$reporturl = new moodle_url('/mod/quiz/report.php', $pageoptions);

View File

@ -347,14 +347,14 @@ function quiz_report_scale_sumgrades_as_percentage($rawgrade, $quiz, $round = tr
* Returns an array of reports to which the current user has access to.
* Reports are ordered as they should be for display in tabs.
*/
function quiz_report_list($context){
function quiz_report_list($context) {
global $DB;
static $reportlist = null;
if (!is_null($reportlist)){
return $reportlist;
}
$reports = $DB->get_records('quiz_report', null, 'displayorder DESC', 'name, capability');
$reportdirs = get_plugin_list("quiz");
$reportdirs = get_plugin_list('quiz');
// Order the reports tab in descending order of displayorder
$reportcaps = array();
@ -382,4 +382,10 @@ function quiz_report_list($context){
return $reportlist;
}
/**
* Get the default report for the current user.
* @param object $context the quiz context.
*/
function quiz_report_default_report($context) {
return reset(quiz_report_list($context));
}

View File

@ -35,7 +35,6 @@ class quiz_responses_report extends quiz_default_report {
$pageoptions = array();
$pageoptions['id'] = $cm->id;
$pageoptions['q'] = $quiz->id;
$pageoptions['mode'] = 'responses';
$reporturl = new moodle_url('/mod/quiz/report.php', $pageoptions);

View File

@ -33,7 +33,6 @@ class quiz_statistics_report extends quiz_default_report {
$qid = optional_param('qid', 0, PARAM_INT);
$pageoptions = array();
$pageoptions['id'] = $cm->id;
$pageoptions['q'] = $quiz->id;
$pageoptions['mode'] = 'statistics';
$questions = quiz_report_load_questions($quiz);
@ -42,7 +41,6 @@ class quiz_statistics_report extends quiz_default_report {
print_error('cannotloadquestion', 'question');
}
$reporturl = new moodle_url('/mod/quiz/report.php', $pageoptions);
$mform = new mod_quiz_report_statistics($reporturl);

View File

@ -102,9 +102,8 @@
/// Show number of attempts summary to those who can view reports.
if (has_capability('mod/quiz:viewreports', $context)) {
if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm)) {
echo '<div class="quizattemptcounts"><a href="report.php?mode=overview&amp;id=' .
$cm->id . '">' . $strattemptnum . "</a></div>\n";
if ($strattemptnum = quiz_attempt_summary_link_to_reports($quiz, $cm, $context)) {
echo '<div class="quizattemptcounts">' . $strattemptnum . "</div>\n";
}
}