MDL-64032 enrol_manual: Make consistent the UI for setting enrolment
[moodle.git] / report / outline / user.php
bloba1e6515389abc6d8c8e6ee0f46dc79f1e8a3c078
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 * Display user activity reports for a course (totals)
20 * @package report
21 * @subpackage outline
22 * @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require('../../config.php');
27 require_once($CFG->dirroot.'/report/outline/locallib.php');
28 require_once($CFG->dirroot.'/report/outline/lib.php');
30 $userid = required_param('id', PARAM_INT);
31 $courseid = required_param('course', PARAM_INT);
32 $mode = optional_param('mode', 'outline', PARAM_ALPHA);
34 if ($mode !== 'complete' and $mode !== 'outline') {
35 $mode = 'outline';
38 $user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0), '*', MUST_EXIST);
39 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
41 $coursecontext = context_course::instance($course->id);
42 $personalcontext = context_user::instance($user->id);
44 if ($courseid == SITEID) {
45 $PAGE->set_context($personalcontext);
48 if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)
49 and !is_enrolled($coursecontext, $USER) and is_enrolled($coursecontext, $user)) {
50 //TODO: do not require parents to be enrolled in courses - this is a hack!
51 require_login();
52 $PAGE->set_course($course);
53 } else {
54 require_login($course);
56 $PAGE->set_url('/report/outline/user.php', array('id'=>$userid, 'course'=>$courseid, 'mode'=>$mode));
58 if (!report_outline_can_access_user_report($user, $course)) {
59 print_error('nocapability', 'report_outline');
62 $stractivityreport = get_string('activityreport');
64 $PAGE->set_pagelayout('report');
65 $PAGE->set_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>$mode));
66 $PAGE->navigation->extend_for_user($user);
67 $PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
68 $PAGE->set_title("$course->shortname: $stractivityreport");
70 // Create the appropriate breadcrumb.
71 $navigationnode = array(
72 'url' => new moodle_url('/report/outline/user.php', array('id' => $user->id, 'course' => $course->id, 'mode' => $mode))
74 if ($mode === 'complete') {
75 $navigationnode['name'] = get_string('completereport');
76 } else {
77 $navigationnode['name'] = get_string('outlinereport');
79 $PAGE->add_report_nodes($user->id, $navigationnode);
81 if ($courseid == SITEID) {
82 $PAGE->set_heading(fullname($user));
83 } else {
84 $PAGE->set_heading($course->fullname);
87 // Trigger a report viewed event.
88 $event = \report_outline\event\report_viewed::create(array('context' => context_course::instance($course->id),
89 'relateduserid' => $userid, 'other' => array('mode' => $mode)));
90 $event->trigger();
92 echo $OUTPUT->header();
93 if ($courseid != SITEID) {
94 echo $OUTPUT->context_header(
95 array(
96 'heading' => fullname($user),
97 'user' => $user,
98 'usercontext' => $personalcontext
99 ), 2);
102 $modinfo = get_fast_modinfo($course, $user->id);
103 $sections = $modinfo->get_section_info_all();
104 $itemsprinted = false;
106 foreach ($sections as $i => $section) {
108 if ($section->uservisible) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert!
109 // Check the section has modules/resources, if not there is nothing to display.
110 if (!empty($modinfo->sections[$i])) {
111 $itemsprinted = true;
112 echo '<div class="section">';
113 echo '<h2>';
114 echo get_section_name($course, $section);
115 echo "</h2>";
117 echo '<div class="content">';
119 if ($mode == "outline") {
120 echo "<table cellpadding=\"4\" cellspacing=\"0\">";
123 foreach ($modinfo->sections[$i] as $cmid) {
124 $mod = $modinfo->cms[$cmid];
126 if (empty($mod->uservisible)) {
127 continue;
130 $instance = $DB->get_record("$mod->modname", array("id"=>$mod->instance));
131 $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
133 if (file_exists($libfile)) {
134 require_once($libfile);
136 switch ($mode) {
137 case "outline":
138 $user_outline = $mod->modname."_user_outline";
139 if (function_exists($user_outline)) {
140 $output = $user_outline($course, $user, $mod, $instance);
141 } else {
142 $output = report_outline_user_outline($user->id, $cmid, $mod->modname, $instance->id);
144 report_outline_print_row($mod, $instance, $output);
145 break;
146 case "complete":
147 $user_complete = $mod->modname."_user_complete";
148 $image = $OUTPUT->pix_icon('icon', $mod->modfullname, 'mod_'.$mod->modname, array('class'=>'icon'));
149 echo "<h4>$image $mod->modfullname: ".
150 "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
151 format_string($instance->name,true)."</a></h4>";
153 ob_start();
155 echo "<ul>";
156 if (function_exists($user_complete)) {
157 $user_complete($course, $user, $mod, $instance);
158 } else {
159 echo report_outline_user_complete($user->id, $cmid, $mod->modname, $instance->id);
161 echo "</ul>";
163 $output = ob_get_contents();
164 ob_end_clean();
166 if (str_replace(' ', '', $output) != '<ul></ul>') {
167 echo $output;
169 break;
174 if ($mode == "outline") {
175 echo "</table>";
177 echo '</div>'; // content
178 echo '</div>'; // section
183 if (!$itemsprinted) {
184 echo $OUTPUT->notification(get_string('nothingtodisplay'));
187 echo $OUTPUT->footer();