Browse files

MDL-31983 navigation: Move reports from Navigation to Settings

  • Loading branch information...
1 parent 1dd6835 commit ebd9ae65234c56f652559ba9d31feae7e814cfd0 @FMCorz FMCorz committed Feb 15, 2013
Showing with 99 additions and 115 deletions.
  1. +78 −72 lib/navigationlib.php
  2. +20 −42 mod/quiz/lib.php
  3. +1 −1 mod/quiz/version.php
View
150 lib/navigationlib.php
@@ -2169,38 +2169,6 @@ protected function load_for_user($user=null, $forceforcontext=false) {
$usernode->add(get_string('notes', 'notes'), $url);
}
- // Add reports node
- $reporttab = $usernode->add(get_string('activityreports'));
- $reports = get_plugin_list_with_function('report', 'extend_navigation_user', 'lib.php');
- foreach ($reports as $reportfunction) {
- $reportfunction($reporttab, $user, $course);
- }
- $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $usercontext);
- if ($anyreport || ($course->showreports && $iscurrentuser && $forceforcontext)) {
- // Add grade hardcoded grade report if necessary
- $gradeaccess = false;
- if (has_capability('moodle/grade:viewall', $coursecontext)) {
- //ok - can view all course grades
- $gradeaccess = true;
- } else if ($course->showgrades) {
- if ($iscurrentuser && has_capability('moodle/grade:view', $coursecontext)) {
- //ok - can view own grades
- $gradeaccess = true;
- } else if (has_capability('moodle/grade:viewall', $usercontext)) {
- // ok - can view grades of this user - parent most probably
- $gradeaccess = true;
- } else if ($anyreport) {
- // ok - can view grades of this user - parent most probably
- $gradeaccess = true;
- }
- }
- if ($gradeaccess) {
- $reporttab->add(get_string('grade'), new moodle_url('/course/user.php', array('mode'=>'grade', 'id'=>$course->id, 'user'=>$usercontext->instanceid)));
- }
- }
- // Check the number of nodes in the report node... if there are none remove the node
- $reporttab->trim_if_empty();
-
// If the user is the current user add the repositories for the current user
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
if ($iscurrentuser) {
@@ -2439,26 +2407,6 @@ public function add_course_essentials($coursenode, stdClass $course) {
$participants = $coursenode->add(get_string('participants'), null, self::TYPE_CONTAINER, get_string('participants'), 'participants');
}
- // View course reports
- if (has_capability('moodle/site:viewreports', $this->page->context)) { // basic capability for listing of reports
- $reportnav = $coursenode->add(get_string('reports'), null, self::TYPE_CONTAINER, null, null, new pix_icon('i/stats', ''));
- $coursereports = get_plugin_list('coursereport'); // deprecated
- foreach ($coursereports as $report=>$dir) {
- $libfile = $CFG->dirroot.'/course/report/'.$report.'/lib.php';
- if (file_exists($libfile)) {
- require_once($libfile);
- $reportfunction = $report.'_report_extend_navigation';
- if (function_exists($report.'_report_extend_navigation')) {
- $reportfunction($reportnav, $course, $this->page->context);
- }
- }
- }
-
- $reports = get_plugin_list_with_function('report', 'extend_navigation_course', 'lib.php');
- foreach ($reports as $reportfunction) {
- $reportfunction($reportnav, $course, $this->page->context);
- }
- }
return true;
}
/**
@@ -2514,26 +2462,6 @@ public function add_front_page_course_essentials(navigation_node $coursenode, st
$coursenode->add(get_string('calendar', 'calendar'), $calendarurl, self::TYPE_CUSTOM, null, 'calendar');
}
- // View course reports
- if (has_capability('moodle/site:viewreports', $this->page->context)) { // basic capability for listing of reports
- $reportnav = $coursenode->add(get_string('reports'), null, self::TYPE_CONTAINER, null, null, new pix_icon('i/stats', ''));
- $coursereports = get_plugin_list('coursereport'); // deprecated
- foreach ($coursereports as $report=>$dir) {
- $libfile = $CFG->dirroot.'/course/report/'.$report.'/lib.php';
- if (file_exists($libfile)) {
- require_once($libfile);
- $reportfunction = $report.'_report_extend_navigation';
- if (function_exists($report.'_report_extend_navigation')) {
- $reportfunction($reportnav, $course, $this->page->context);
- }
- }
- }
-
- $reports = get_plugin_list_with_function('report', 'extend_navigation_course', 'lib.php');
- foreach ($reports as $reportfunction) {
- $reportfunction($reportnav, $course, $this->page->context);
- }
- }
return true;
}
@@ -3470,6 +3398,28 @@ protected function load_course_settings($forceopen = false) {
$coursenode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/filter', ''));
}
+ // View course reports.
+ if (has_capability('moodle/site:viewreports', $coursecontext)) { // Basic capability for listing of reports.
+ $reportnav = $coursenode->add(get_string('reports'), null, self::TYPE_CONTAINER, null, null,
+ new pix_icon('i/stats', ''));
+ $coursereports = get_plugin_list('coursereport');
+ foreach ($coursereports as $report => $dir) {
+ $libfile = $CFG->dirroot.'/course/report/'.$report.'/lib.php';
+ if (file_exists($libfile)) {
+ require_once($libfile);
+ $reportfunction = $report.'_report_extend_navigation';
+ if (function_exists($report.'_report_extend_navigation')) {
+ $reportfunction($reportnav, $course, $coursecontext);
+ }
+ }
+ }
+
+ $reports = get_plugin_list_with_function('report', 'extend_navigation_course', 'lib.php');
+ foreach ($reports as $reportfunction) {
+ $reportfunction($reportnav, $course, $coursecontext);
+ }
+ }
+
// Add view grade report is permitted
$reportavailable = false;
if (has_capability('moodle/grade:viewall', $coursecontext)) {
@@ -3976,6 +3926,40 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr
}
}
+ // Add reports node.
+ $reporttab = $usersetting->add(get_string('activityreports'));
+ $reports = get_plugin_list_with_function('report', 'extend_navigation_user', 'lib.php');
+ foreach ($reports as $reportfunction) {
+ $reportfunction($reporttab, $user, $course);
+ }
+ $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $usercontext);
+ if ($anyreport || ($course->showreports && $iscurrentuser && $forceforcontext)) {
+ // Add grade hardcoded grade report if necessary.
+ $gradeaccess = false;
+ if (has_capability('moodle/grade:viewall', $coursecontext)) {
+ // Can view all course grades.
+ $gradeaccess = true;
+ } else if ($course->showgrades) {
+ if ($iscurrentuser && has_capability('moodle/grade:view', $coursecontext)) {
+ // Can view own grades.
+ $gradeaccess = true;
+ } else if (has_capability('moodle/grade:viewall', $usercontext)) {
+ // Can view grades of this user - parent most probably.
+ $gradeaccess = true;
+ } else if ($anyreport) {
+ // Can view grades of this user - parent most probably.
+ $gradeaccess = true;
+ }
+ }
+ if ($gradeaccess) {
+ $reporttab->add(get_string('grade'), new moodle_url('/course/user.php', array('mode'=>'grade', 'id'=>$course->id,
+ 'user'=>$usercontext->instanceid)));
+ }
+ }
+ // Check the number of nodes in the report node... if there are none remove the node
+ $reporttab->trim_if_empty();
+
+
// Login as ...
if (!$user->deleted and !$currentuser && !session_is_loggedinas() && has_capability('moodle/user:loginas', $coursecontext) && !is_siteadmin($user->id)) {
$url = new moodle_url('/course/loginas.php', array('id'=>$course->id, 'user'=>$user->id, 'sesskey'=>sesskey()));
@@ -4141,6 +4125,28 @@ protected function load_front_page_settings($forceopen = false) {
$frontpage->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/filter', ''));
}
+ // View course reports.
+ if (has_capability('moodle/site:viewreports', $coursecontext)) { // Basic capability for listing of reports.
+ $frontpagenav = $frontpage->add(get_string('reports'), null, self::TYPE_CONTAINER, null, null,
+ new pix_icon('i/stats', ''));
+ $coursereports = get_plugin_list('coursereport');
+ foreach ($coursereports as $report=>$dir) {
+ $libfile = $CFG->dirroot.'/course/report/'.$report.'/lib.php';
+ if (file_exists($libfile)) {
+ require_once($libfile);
+ $reportfunction = $report.'_report_extend_navigation';
+ if (function_exists($report.'_report_extend_navigation')) {
+ $reportfunction($frontpagenav, $course, $coursecontext);
+ }
+ }
+ }
+
+ $reports = get_plugin_list_with_function('report', 'extend_navigation_course', 'lib.php');
+ foreach ($reports as $reportfunction) {
+ $reportfunction($frontpagenav, $course, $coursecontext);
+ }
+ }
+
// Backup this course
if (has_capability('moodle/backup:backupcourse', $coursecontext)) {
$url = new moodle_url('/backup/backup.php', array('id'=>$course->id));
View
62 mod/quiz/lib.php
@@ -1554,55 +1554,14 @@ function quiz_get_extra_capabilities() {
}
/**
- * This fucntion extends the global navigation 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 $quiznode The quiz node within the global navigation
- * @param object $course The course object returned from the DB
- * @param object $module The module object returned from the DB
- * @param object $cm The course module instance returned from the DB
- */
-function quiz_extend_navigation($quiznode, $course, $module, $cm) {
- global $CFG;
-
- $context = context_module::instance($cm->id);
-
- 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', ''));
- }
-
- if (has_any_capability(array('mod/quiz:viewreports', 'mod/quiz:grade'), $context)) {
- 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) {
- $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, 'quiz_report_' . $report, new pix_icon('i/item', ''));
- }
- }
-}
-
-/**
* 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 settings_navigation $settings
* @param navigation_node $quiznode
+ * @return void
*/
function quiz_extend_settings_navigation($settings, $quiznode) {
global $PAGE, $CFG;
@@ -1652,6 +1611,25 @@ function quiz_extend_settings_navigation($settings, $quiznode) {
$quiznode->add_node($node, $beforekey);
}
+ if (has_any_capability(array('mod/quiz:viewreports', 'mod/quiz:grade'), $PAGE->cm->context)) {
+ require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
+ $reportlist = quiz_report_list($PAGE->cm->context);
+
+ $url = new moodle_url('/mod/quiz/report.php',
+ array('id' => $PAGE->cm->id, 'mode' => reset($reportlist)));
+ $reportnode = $quiznode->add_node(navigation_node::create(get_string('results', 'quiz'), $url,
+ navigation_node::TYPE_SETTING,
+ null, null, new pix_icon('i/report', '')), $beforekey);
+
+ foreach ($reportlist as $report) {
+ $url = new moodle_url('/mod/quiz/report.php',
+ array('id' => $PAGE->cm->id, 'mode' => $report));
+ $reportnode->add_node(navigation_node::create(get_string($report, 'quiz_'.$report), $url,
+ navigation_node::TYPE_SETTING,
+ null, 'quiz_report_' . $report, new pix_icon('i/item', '')));
+ }
+ }
+
question_extend_settings_navigation($quiznode, $PAGE->cm->context)->trim_if_empty();
}
View
2 mod/quiz/version.php
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
-$module->version = 2012112900; // The current module version (Date: YYYYMMDDXX).
+$module->version = 2013310100; // The current module version (Date: YYYYMMDDXX).
$module->requires = 2012112900; // Requires this Moodle version.
$module->component = 'mod_quiz'; // Full name of the plugin (used for diagnostics).
$module->cron = 60;

0 comments on commit ebd9ae6

Please sign in to comment.