MDL-32941 use + operator instead array merge to avoid duplicate. Sort resulting array...
[moodle.git] / report / outline / lib.php
blob11b27fe6ff7bb278b895cec643b5807a4478692c
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * This file contains public API of outline report
20 * @package report
21 * @subpackage outline
22 * @copyright 2009 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die;
28 /**
29 * This function extends the course navigation with the report items
31 * @param navigation_node $navigation The navigation node to extend
32 * @param stdClass $course The course to object for the report
33 * @param stdClass $context The context of the course
35 function report_outline_extend_navigation_course($navigation, $course, $context) {
36 if (has_capability('report/outline:view', $context)) {
37 $url = new moodle_url('/report/outline/index.php', array('id'=>$course->id));
38 $navigation->add(get_string('pluginname', 'report_outline'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
42 /**
43 * This function extends the course navigation with the report items
45 * @param navigation_node $navigation The navigation node to extend
46 * @param stdClass $user
47 * @param stdClass $course The course to object for the report
49 function report_outline_extend_navigation_user($navigation, $user, $course) {
50 if (report_outline_can_access_user_report($user, $course)) {
51 $url = new moodle_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>'outline'));
52 $navigation->add(get_string('outlinereport'), $url);
53 $url = new moodle_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>'complete'));
54 $navigation->add(get_string('completereport'), $url);
58 /**
59 * Is current user allowed to access this report
61 * @private defined in lib.php for performance reasons
63 * @param stdClass $user
64 * @param stdClass $course
65 * @return bool
67 function report_outline_can_access_user_report($user, $course) {
68 global $USER;
70 $coursecontext = context_course::instance($course->id);
71 $personalcontext = context_user::instance($user->id);
73 if (has_capability('report/outline:view', $coursecontext)) {
74 return true;
77 if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
78 if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
79 return true;
82 } else if ($user->id == $USER->id) {
83 if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
84 return true;
88 return false;
91 /**
92 * Return a list of page types
93 * @param string $pagetype current page type
94 * @param stdClass $parentcontext Block's parent context
95 * @param stdClass $currentcontext Current context of block
96 * @return array
98 function report_outline_page_type_list($pagetype, $parentcontext, $currentcontext) {
99 $array = array(
100 '*' => get_string('page-x', 'pagetype'),
101 'report-*' => get_string('page-report-x', 'pagetype'),
102 'report-outline-*' => get_string('page-report-outline-x', 'report_outline'),
103 'report-outline-index' => get_string('page-report-outline-index', 'report_outline'),
104 'report-outline-user' => get_string('page-report-outline-user', 'report_outline')
106 return $array;