2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * This page lets users to manage site wide competencies.
20 * @package report_competency
21 * @copyright 2015 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 use core\report_helper
;
27 require_once(__DIR__
. '/../../config.php');
29 $id = required_param('id', PARAM_INT
);
31 $params = array('id' => $id);
32 $course = $DB->get_record('course', $params, '*', MUST_EXIST
);
33 require_login($course);
34 $context = context_course
::instance($course->id
);
35 $currentuser = optional_param('user', null, PARAM_INT
);
36 $currentmodule = optional_param('mod', null, PARAM_INT
);
37 if ($currentmodule > 0) {
38 $cm = get_coursemodule_from_id('', $currentmodule, 0, false, MUST_EXIST
);
39 $context = context_module
::instance($cm->id
);
42 // Fetch current active group.
43 $groupmode = groups_get_course_groupmode($course);
44 $currentgroup = groups_get_course_group($course, true);
45 if (empty($currentuser)) {
46 $gradable = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup, 'u.id', null, 0, 1);
47 if (empty($gradable)) {
50 $currentuser = array_pop($gradable)->id
;
53 $gradable = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup, 'u.id');
54 if (count($gradable) == 0) {
56 } else if (!in_array($currentuser, array_keys($gradable))) {
57 $currentuser = array_shift($gradable)->id
;
61 $urlparams = array('id' => $id);
62 $navurl = new moodle_url('/report/competency/index.php', $urlparams);
63 $urlparams['user'] = $currentuser;
64 $urlparams['mod'] = $currentmodule;
65 $url = new moodle_url('/report/competency/index.php', $urlparams);
67 $title = get_string('pluginname', 'report_competency');
68 $coursename = format_string($course->fullname
, true, array('context' => $context));
70 $PAGE->navigation
->override_active_url($navurl);
72 $PAGE->set_title($title);
73 $PAGE->set_heading($coursename);
74 $PAGE->set_pagelayout('incourse');
76 $output = $PAGE->get_renderer('report_competency');
78 echo $output->header();
79 $pluginname = get_string('pluginname', 'report_competency');
80 report_helper
::print_report_selector($pluginname);
82 $baseurl = new moodle_url('/report/competency/index.php');
83 $nav = new \report_competency\output\
user_course_navigation($currentuser, $course->id
, $baseurl, $currentmodule);
84 $top = $output->render($nav);
85 if ($currentuser > 0) {
86 $user = core_user
::get_user($currentuser);
87 $usercontext = context_user
::instance($currentuser);
89 'heading' => fullname($user, has_capability('moodle/site:viewfullnames', $context)),
91 'usercontext' => $usercontext
93 if ($currentmodule > 0) {
94 $title = get_string('filtermodule', 'report_competency', format_string($cm->name
));
96 $top .= $output->context_header($userheading, 3);
98 echo $output->container($top, 'clearfix');
100 if ($currentuser > 0) {
101 $page = new \report_competency\output\report
($course->id
, $currentuser, $currentmodule);
102 echo $output->render($page);
104 echo $output->container('', 'clearfix');
105 echo $output->notify_problem(get_string('noparticipants', 'tool_lp'));
107 echo $output->footer();