Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]
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 * This page contains navigation hooks for learning plans. 19 * 20 * @package tool_lp 21 * @copyright 2015 Damyon Wiese 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 /** 28 * This function extends the user navigation. 29 * 30 * @param navigation_node $navigation The navigation node to extend 31 * @param stdClass $user The user object 32 * @param context_user $usercontext The user context 33 * @param stdClass $course The course object 34 * @param context_course $coursecontext The context of the course 35 */ 36 function tool_lp_extend_navigation_user($navigation, $user, $usercontext, $course, $coursecontext) { 37 if (!get_config('core_competency', 'enabled')) { 38 return; 39 } 40 41 if (\core_competency\plan::can_read_user($user->id)) { 42 $node = $navigation->add(get_string('learningplans', 'tool_lp'), 43 new moodle_url('/admin/tool/lp/plans.php', array('userid' => $user->id))); 44 45 if (\core_competency\user_evidence::can_read_user($user->id)) { 46 $node->add(get_string('userevidence', 'tool_lp'), 47 new moodle_url('/admin/tool/lp/user_evidence_list.php', array('userid' => $user->id))); 48 } 49 } 50 51 } 52 53 /** 54 * Add nodes to myprofile page. 55 * 56 * @param \core_user\output\myprofile\tree $tree Tree object 57 * @param stdClass $user user object 58 * @param bool $iscurrentuser 59 * @param stdClass $course Course object 60 * 61 * @return bool 62 */ 63 function tool_lp_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) { 64 if (!get_config('core_competency', 'enabled')) { 65 return false; 66 } else if (!\core_competency\plan::can_read_user($user->id)) { 67 return false; 68 } 69 70 $url = new moodle_url('/admin/tool/lp/plans.php', array('userid' => $user->id)); 71 $node = new core_user\output\myprofile\node('miscellaneous', 'learningplans', 72 get_string('learningplans', 'tool_lp'), null, $url); 73 $tree->add_node($node); 74 75 return true; 76 } 77 78 /** 79 * This function extends the category navigation to add learning plan links. 80 * 81 * @param navigation_node $navigation The navigation node to extend 82 * @param context $coursecategorycontext The context of the course category 83 */ 84 function tool_lp_extend_navigation_category_settings($navigation, $coursecategorycontext) { 85 if (!get_config('core_competency', 'enabled')) { 86 return false; 87 } 88 89 // We check permissions before renderring the links. 90 $templatereadcapability = \core_competency\template::can_read_context($coursecategorycontext); 91 $competencyreadcapability = \core_competency\competency_framework::can_read_context($coursecategorycontext); 92 if (!$templatereadcapability && !$competencyreadcapability) { 93 return false; 94 } 95 96 // The link to the learning plan page. 97 if ($templatereadcapability) { 98 $title = get_string('templates', 'tool_lp'); 99 $path = new moodle_url("/admin/tool/lp/learningplans.php", array('pagecontextid' => $coursecategorycontext->id)); 100 $settingsnode = navigation_node::create($title, 101 $path, 102 navigation_node::TYPE_SETTING, 103 null, 104 null, 105 new pix_icon('i/competencies', '')); 106 if (isset($settingsnode)) { 107 $navigation->add_node($settingsnode); 108 } 109 } 110 111 // The link to the competency frameworks page. 112 if ($competencyreadcapability) { 113 $title = get_string('competencyframeworks', 'tool_lp'); 114 $path = new moodle_url("/admin/tool/lp/competencyframeworks.php", array('pagecontextid' => $coursecategorycontext->id)); 115 $settingsnode = navigation_node::create($title, 116 $path, 117 navigation_node::TYPE_SETTING, 118 null, 119 null, 120 new pix_icon('i/competencies', '')); 121 if (isset($settingsnode)) { 122 $navigation->add_node($settingsnode); 123 } 124 } 125 } 126 127 /** 128 * Inject the competencies elements into all moodle module settings forms. 129 * 130 * @param moodleform $formwrapper The moodle quickforms wrapper object. 131 * @param MoodleQuickForm $mform The actual form object (required to modify the form). 132 */ 133 function tool_lp_coursemodule_standard_elements($formwrapper, $mform) { 134 global $CFG, $COURSE; 135 136 if (!get_config('core_competency', 'enabled')) { 137 return; 138 } else if (!has_capability('moodle/competency:coursecompetencymanage', $formwrapper->get_context())) { 139 return; 140 } 141 142 $mform->addElement('header', 'competenciessection', get_string('competencies', 'core_competency')); 143 144 MoodleQuickForm::registerElementType('course_competencies', 145 "$CFG->dirroot/$CFG->admin/tool/lp/classes/course_competencies_form_element.php", 146 'tool_lp_course_competencies_form_element'); 147 $cmid = null; 148 if ($cm = $formwrapper->get_coursemodule()) { 149 $cmid = $cm->id; 150 } 151 $options = array( 152 'courseid' => $COURSE->id, 153 'cmid' => $cmid 154 ); 155 $mform->addElement('course_competencies', 'competencies', get_string('modcompetencies', 'tool_lp'), $options); 156 $mform->addHelpButton('competencies', 'modcompetencies', 'tool_lp'); 157 MoodleQuickForm::registerElementType('course_competency_rule', 158 "$CFG->dirroot/$CFG->admin/tool/lp/classes/course_competency_rule_form_element.php", 159 'tool_lp_course_competency_rule_form_element'); 160 // Reuse the same options. 161 $mform->addElement('course_competency_rule', 'competency_rule', get_string('uponcoursemodulecompletion', 'tool_lp'), $options); 162 } 163 164 /** 165 * Hook the add/edit of the course module. 166 * 167 * @param stdClass $data Data from the form submission. 168 * @param stdClass $course The course. 169 */ 170 function tool_lp_coursemodule_edit_post_actions($data, $course) { 171 if (!get_config('core_competency', 'enabled')) { 172 return $data; 173 } 174 175 // It seems like the form did not contain any of the form fields, we can return. 176 if (!isset($data->competency_rule) && !isset($data->competencies)) { 177 return $data; 178 } 179 180 // We bypass the API here and go direct to the persistent layer - because we don't want to do permission 181 // checks here - we need to load the real list of existing course module competencies. 182 $existing = \core_competency\course_module_competency::list_course_module_competencies($data->coursemodule); 183 184 $existingids = array(); 185 foreach ($existing as $cmc) { 186 array_push($existingids, $cmc->get('competencyid')); 187 } 188 189 $newids = isset($data->competencies) ? $data->competencies : array(); 190 191 $removed = array_diff($existingids, $newids); 192 $added = array_diff($newids, $existingids); 193 194 foreach ($removed as $removedid) { 195 \core_competency\api::remove_competency_from_course_module($data->coursemodule, $removedid); 196 } 197 foreach ($added as $addedid) { 198 \core_competency\api::add_competency_to_course_module($data->coursemodule, $addedid); 199 } 200 201 if (isset($data->competency_rule)) { 202 // Now update the rules for each course_module_competency. 203 $current = \core_competency\api::list_course_module_competencies_in_course_module($data->coursemodule); 204 foreach ($current as $coursemodulecompetency) { 205 \core_competency\api::set_course_module_competency_ruleoutcome($coursemodulecompetency, $data->competency_rule); 206 } 207 } 208 209 return $data; 210 } 211 212 /** 213 * Map icons for font-awesome themes. 214 */ 215 function tool_lp_get_fontawesome_icon_map() { 216 return [ 217 'tool_lp:url' => 'fa-external-link' 218 ]; 219 } 220 221 /** 222 * Render a short bit of information about a competency. 223 * 224 * @param \core_competency\competency $competency The competency to show. 225 * @param \core_competency\competency_framework $framework The competency framework. 226 * @param boolean $includerelated If true, show related competencies. 227 * @param boolean $includecourses If true, show courses using this competency. 228 * @param boolean $skipenabled If true, show this competency even if competencies are disabled. 229 * @return string The html summary for the competency. 230 */ 231 function tool_lp_render_competency_summary(\core_competency\competency $competency, 232 \core_competency\competency_framework $framework, 233 $includerelated, 234 $includecourses, 235 $skipenabled = false) { 236 global $PAGE; 237 238 if (!$skipenabled && !get_config('core_competency', 'enabled')) { 239 return; 240 } 241 242 $summary = new \tool_lp\output\competency_summary($competency, $framework, $includerelated, $includecourses); 243 244 $output = $PAGE->get_renderer('tool_lp'); 245 246 return $output->render($summary); 247 } 248 249 /** 250 * Inject a course competency picker into the form. 251 * 252 * @param MoodleQuickForm $mform The actual form object (required to modify the form). 253 * @param integer $courseid - SITEID or a course id 254 * @param context $context - The page context 255 * @param string $elementname - The name of the form element to create 256 */ 257 function tool_lp_competency_picker($mform, $courseid, $context, $elementname) { 258 global $CFG, $COURSE; 259 260 if (!get_config('core_competency', 'enabled')) { 261 return; 262 } 263 264 if ($courseid == SITEID) { 265 if (!has_capability('moodle/competency:competencymanage', $context)) { 266 return; 267 } 268 269 MoodleQuickForm::registerElementType('site_competencies', 270 "$CFG->dirroot/$CFG->admin/tool/lp/classes/site_competencies_form_element.php", 271 'tool_lp_site_competencies_form_element'); 272 $mform->addElement('site_competencies', $elementname); 273 } else { 274 if (!has_capability('moodle/competency:coursecompetencymanage', $context)) { 275 return; 276 } 277 278 MoodleQuickForm::registerElementType('course_competencies', 279 "$CFG->dirroot/$CFG->admin/tool/lp/classes/course_competencies_form_element.php", 280 'tool_lp_course_competencies_form_element'); 281 $options = array( 282 'courseid' => $COURSE->id 283 ); 284 $mform->addElement('course_competencies', $elementname, get_string('modcompetencies', 'tool_lp'), $options); 285 } 286 $mform->setType($elementname, PARAM_SEQUENCE); 287 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body