]> git.mjollnir.org Git - moodle.git/commitdiff
mod-quiz MDL-20276 Created callback methods to expand navigation and settings blocks
authorsamhemelryk <samhemelryk>
Wed, 16 Sep 2009 05:15:22 +0000 (05:15 +0000)
committersamhemelryk <samhemelryk>
Wed, 16 Sep 2009 05:15:22 +0000 (05:15 +0000)
lang/en_utf8/quiz.php
mod/quiz/attempt.php
mod/quiz/lib.php
mod/quiz/report.php
mod/quiz/review.php

index 3bb53d50e31d43e8e93eeab0b83a6cd06bfff599..cab7a41cd6afcce60c030a47ea40b37635887a10 100644 (file)
@@ -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';
index 5be89bd53ef4302d61577a632b4b7a75fc29eba2..cb0a786cd748aedb9baa7d466a964a642783a0a5 100644 (file)
     $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.
index 379a960a94e14b75128e1182feb8b98377570b45..199744525c1cc422b4a1ed74d3bbfdad3aeba9f3 100644 (file)
@@ -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
index 6e2c74f32019a60fc6d078e639db6baa12a237f2..69813442cc8c43040a1e0eb0a5447c9502183592 100644 (file)
         }
     }
 
+    $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);
index 4424791af6e92d912e566c13e6891eb0a58258c9..0a823e162aab31e74cfe563315b2ad082a8b760d 100644 (file)
     $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.