Skip to content

Commit

Permalink
MDL-31983 navigation: Move reports from Navigation to Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Feb 15, 2013
1 parent 1dd6835 commit ebd9ae6
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 115 deletions.
150 changes: 78 additions & 72 deletions lib/navigationlib.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
/**
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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));
Expand Down
62 changes: 20 additions & 42 deletions mod/quiz/lib.php
Expand Up @@ -1553,48 +1553,6 @@ function quiz_get_extra_capabilities() {
return $caps;
}

/**
* 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.
*
Expand All @@ -1603,6 +1561,7 @@ function quiz_extend_navigation($quiznode, $course, $module, $cm) {
*
* @param settings_navigation $settings
* @param navigation_node $quiznode
* @return void
*/
function quiz_extend_settings_navigation($settings, $quiznode) {
global $PAGE, $CFG;
Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/version.php
Expand Up @@ -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.