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 */ 24 namespace report_competency\output; 25 26 use renderable; 27 use renderer_base; 28 use templatable; 29 use context_course; 30 use core_user\external\user_summary_exporter; 31 use core_course\external\course_module_summary_exporter; 32 use stdClass; 33 34 /** 35 * User course navigation class. 36 * 37 * @package report_competency 38 * @copyright 2015 Damyon Wiese 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 */ 41 class user_course_navigation implements renderable, templatable { 42 43 /** @var userid */ 44 protected $userid; 45 46 /** @var courseid */ 47 protected $courseid; 48 49 /** @var moduleid */ 50 protected $moduleid; 51 52 /** @var baseurl */ 53 protected $baseurl; 54 55 /** 56 * Construct. 57 * 58 * @param int $userid 59 * @param int $courseid 60 * @param int $moduleid 61 * @param string $baseurl 62 */ 63 public function __construct($userid, $courseid, $baseurl, $moduleid) { 64 $this->userid = $userid; 65 $this->courseid = $courseid; 66 $this->moduleid = $moduleid; 67 $this->baseurl = $baseurl; 68 } 69 70 /** 71 * Export the data. 72 * 73 * @param renderer_base $output 74 * @return stdClass 75 */ 76 public function export_for_template(renderer_base $output) { 77 global $CFG, $DB, $SESSION, $PAGE; 78 79 $context = context_course::instance($this->courseid); 80 81 $data = new stdClass(); 82 $data->userid = $this->userid; 83 $data->courseid = $this->courseid; 84 $data->moduleid = $this->moduleid; 85 if (empty($data->moduleid)) { 86 // Moduleid is optional. 87 $data->moduleid = 0; 88 } 89 $data->baseurl = $this->baseurl; 90 $data->groupselector = ''; 91 92 if (has_any_capability(array('moodle/competency:usercompetencyview', 'moodle/competency:coursecompetencymanage'), 93 $context)) { 94 $course = $DB->get_record('course', array('id' => $this->courseid)); 95 $currentgroup = groups_get_course_group($course, true); 96 if ($currentgroup !== false) { 97 $select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup); 98 $data->groupselector = $select; 99 } 100 // Fetch showactive. 101 $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); 102 $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); 103 $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context); 104 105 // Fetch current active group. 106 $groupmode = groups_get_course_groupmode($course); 107 108 $users = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup, 109 'u.*', null, 0, 0, $showonlyactiveenrol); 110 111 $data->users = array(); 112 foreach ($users as $user) { 113 $data->users[] = (object)[ 114 'id' => $user->id, 115 'fullname' => fullname($user, has_capability('moodle/site:viewfullnames', $context)), 116 'selected' => $user->id == $this->userid 117 ]; 118 } 119 $data->hasusers = true; 120 121 $data->hasmodules = true; 122 $data->modules = array(); 123 $empty = (object)['id' => 0, 'name' => get_string('nofiltersapplied')]; 124 $data->modules[] = $empty; 125 126 $modinfo = get_fast_modinfo($this->courseid); 127 foreach ($modinfo->get_cms() as $cm) { 128 if ($cm->uservisible) { 129 $exporter = new course_module_summary_exporter(null, ['cm' => $cm]); 130 $module = $exporter->export($output); 131 if ($module->id == $this->moduleid) { 132 $module->selected = true; 133 } 134 $data->modules[] = $module; 135 $data->hasmodules = true; 136 } 137 } 138 139 } else { 140 $data->users = array(); 141 $data->hasusers = false; 142 } 143 144 return $data; 145 } 146 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body