From: samhemelryk Date: Wed, 16 Sep 2009 05:15:22 +0000 (+0000) Subject: mod-quiz MDL-20276 Created callback methods to expand navigation and settings blocks X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=55f599f00e6113e961c5d36641c2cf3a8718ed60;p=moodle.git mod-quiz MDL-20276 Created callback methods to expand navigation and settings blocks --- diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index 3bb53d50e3..cab7a41cd6 100644 --- a/lang/en_utf8/quiz.php +++ b/lang/en_utf8/quiz.php @@ -542,6 +542,7 @@ $string['questiontext'] = 'Question text'; $string['questiontextisempty'] = '[Empty question text]'; $string['questiontype'] = 'Question type $a'; $string['questiontypesetupoptions'] = 'Setup options for question types:'; +$string['quizadministration'] = 'Quiz administration'; $string['quiz:attempt'] = 'Attempt quizzes'; $string['quiz:deleteattempts'] = 'Delete quiz attempts'; $string['quiz:emailconfirmsubmission'] = 'Get email confirmation when submitting'; diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 5be89bd53e..cb0a786cd7 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -27,6 +27,12 @@ $attemptid = required_param('attempt', PARAM_INT); $page = optional_param('page', 0, PARAM_INT); + $url = new moodle_url($CFG->wwwroot.'/mod/quiz/attempt.php', array('attempt'=>$attemptid)); + if ($page !== 0) { + $url->param('page', $page); + } + $PAGE->set_url($url); + $attemptobj = new quiz_attempt($attemptid); /// Check login. diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 379a960a94..199744525c 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -1404,3 +1404,74 @@ function quiz_get_extra_capabilities() { $caps[] = 'moodle/site:accessallgroups'; return $caps; } + +/** + * This fucntion extends the global navigaiton for the site. + * It is important to note that you should not rely on PAGE objects within this + * body of code as there is no guarantee that during an AJAX request they are + * available + * + * @param navigation_node $navigation The quiz node within the global navigation + * @param stdClass $course The course object returned from the DB + * @param stdClass $module The module object returned from the DB + * @param stdClass $cm The course module isntance returned from the DB + */ +function quiz_extend_navigation($navigation, $course, $module, $cm) { + /** + * This is currently just a stub so that it can be easily expanded upon. + * When expanding just remove this comment and the line below and then add + * you content. + */ + $navigation->nodetype = navigation_node::NODETYPE_LEAF; +} + +/** + * This function extends the settings navigation block for the site. + * + * It is safe to rely on PAGE here as we will only ever be within the module + * context when this is called + * + * @param navigation_node $settings + * @param stdClass $module + */ +function quiz_extend_settings_navigation($settings, $module) { + global $PAGE, $CFG, $DB, $USER, $OUTPUT; + + $quiz = $DB->get_record('quiz', array('id'=>$PAGE->cm->instance)); + $quiznavkey = $settings->add(get_string('quizadministration', 'quiz')); + $quiznav = $settings->get($quiznavkey); + $quiznav->forceopen = true; + + if (has_capability('mod/quiz:view', $PAGE->cm->context)) { + $url = new moodle_url($CFG->wwwroot.'/mod/quiz/view.php', array('id'=>$PAGE->cm->id)); + $quiznav->add(get_string('info', 'quiz'), $url, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('i/info')); + } + if (has_capability('mod/quiz:viewreports', $PAGE->cm->context)) { + $url = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', array('q'=>$quiz->id)); + $reportkey = $quiznav->add(get_string('results', 'quiz'), $url, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('i/report')); + + require_once($CFG->dirroot.'/mod/quiz/report/reportlib.php'); + $reportlist = quiz_report_list($PAGE->cm->context); + foreach ($reportlist as $report) { + $url = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', array('q'=>$quiz->id, 'mode'=>$report)); + $quiznav->get($reportkey)->add(get_string($report, 'quiz_'.$report), $url, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('i/item')); + } + } + if (has_capability('mod/quiz:preview', $PAGE->cm->context)) { + $url = new moodle_url($CFG->wwwroot.'/mod/quiz/startattempt.php', array('cmid'=>$PAGE->cm->id, 'sesskey'=>sesskey())); + $quiznav->add(get_string('preview', 'quiz'), $url, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('t/preview')); + } + if (has_capability('mod/quiz:manage', $PAGE->cm->context)) { + $url = new moodle_url($CFG->wwwroot.'/mod/quiz/edit.php', array('cmid'=>$PAGE->cm->id)); + $quiznav->add(get_string('edit'), $url, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url('t/edit')); + } + + if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) { + $url = new moodle_url($CFG->wwwroot.'/course/mod.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey())); + $quiznav->add(get_string('updatethis', '', get_string('modulename', 'quiz')), $url); + } + + if (count($quiznav->children)<1) { + $settings->remove_child($quiznavkey); + } +} \ No newline at end of file diff --git a/mod/quiz/report.php b/mod/quiz/report.php index 6e2c74f320..69813442cc 100644 --- a/mod/quiz/report.php +++ b/mod/quiz/report.php @@ -36,6 +36,16 @@ } } + $url = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php'); + if ($id !== 0) { + $url->param('id', $id); + } else { + $url->param('q', $q); + } + if ($mode !== '') { + $url->param('mode', $mode); + } + $PAGE->set_url($url); require_login($course, false, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); diff --git a/mod/quiz/review.php b/mod/quiz/review.php index 4424791af6..0a823e162a 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -15,6 +15,15 @@ $page = optional_param('page', 0, PARAM_INT); $showall = optional_param('showall', 0, PARAM_BOOL); + $url = new moodle_url($CFG->wwwroot.'/mod/quiz/review.php', array('attempt'=>$attemptid)); + if ($page !== 0) { + $url->param('page', $page); + } + if ($showall !== 0) { + $url->param('showall', $showall); + } + $PAGE->set_url($url); + $attemptobj = new quiz_attempt($attemptid); /// Check login.