on-demand release 3.7dev+
[moodle.git] / report / competency / classes / output / user_course_navigation.php
CommitLineData
21e0dd61
DW
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.
13//
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/>.
16
17/**
18 * User navigation class.
19 *
20 * @package report_competency
21 * @copyright 2015 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24namespace report_competency\output;
25
26use renderable;
27use renderer_base;
28use templatable;
29use context_course;
f5f02ac0 30use core_user\external\user_summary_exporter;
21e0dd61
DW
31use stdClass;
32
33/**
34 * User course navigation class.
35 *
96c2b847 36 * @package report_competency
21e0dd61
DW
37 * @copyright 2015 Damyon Wiese
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 */
40class user_course_navigation implements renderable, templatable {
41
42 /** @var userid */
43 protected $userid;
44
45 /** @var courseid */
46 protected $courseid;
47
48 /** @var baseurl */
49 protected $baseurl;
50
51 /**
52 * Construct.
53 *
96c2b847
FM
54 * @param int $userid
55 * @param int $courseid
56 * @param string $baseurl
21e0dd61
DW
57 */
58 public function __construct($userid, $courseid, $baseurl) {
59 $this->userid = $userid;
60 $this->courseid = $courseid;
61 $this->baseurl = $baseurl;
62 }
63
64 /**
65 * Export the data.
66 *
67 * @param renderer_base $output
68 * @return stdClass
69 */
70 public function export_for_template(renderer_base $output) {
71 global $CFG, $DB, $SESSION, $PAGE;
72
73 $context = context_course::instance($this->courseid);
74
75 $data = new stdClass();
76 $data->userid = $this->userid;
77 $data->courseid = $this->courseid;
78 $data->baseurl = $this->baseurl;
a8007119 79 $data->groupselector = '';
21e0dd61 80
eeb47707
SG
81 if (has_any_capability(array('moodle/competency:usercompetencyview', 'moodle/competency:coursecompetencymanage'),
82 $context)) {
21e0dd61 83 $course = $DB->get_record('course', array('id' => $this->courseid));
a8007119
DW
84 $currentgroup = groups_get_course_group($course, true);
85 if ($currentgroup !== false) {
86 $select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup);
87 $data->groupselector = $select;
88 }
21e0dd61
DW
89 // Fetch showactive.
90 $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
91 $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
92 $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
93
94 // Fetch current active group.
95 $groupmode = groups_get_course_groupmode($course);
21e0dd61 96
a6a722d4 97 $users = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup,
21e0dd61
DW
98 'u.*', null, 0, 0, $showonlyactiveenrol);
99
100 $data->users = array();
101 foreach ($users as $user) {
102 $exporter = new user_summary_exporter($user);
103 $user = $exporter->export($output);
104 if ($user->id == $this->userid) {
105 $user->selected = true;
106 }
107 $data->users[] = $user;
108 }
109 $data->hasusers = true;
110 } else {
111 $data->users = array();
112 $data->hasusers = false;
113 }
114
115 return $data;
116 }
117}