MDL-52485 tool_lp: Template due date can be changed at will
[moodle.git] / admin / tool / lp / lib.php
CommitLineData
d9a39950
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 * 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
dd1ce763 25defined('MOODLE_INTERNAL') || die();
d9a39950
DW
26
27/**
28 * This function extends the course navigation
29 *
30 * @param navigation_node $navigation The navigation node to extend
31 * @param stdClass $course The course to object for the tool
32 * @param context $coursecontext The context of the course
33 */
34function tool_lp_extend_navigation_course($navigation, $course, $coursecontext) {
35 // Just a link to course report.
36 $title = get_string('coursecompetencies', 'tool_lp');
37 $path = new moodle_url("/admin/tool/lp/coursecompetencies.php", array('courseid' => $course->id));
38 $settingsnode = navigation_node::create($title,
39 $path,
40 navigation_node::TYPE_SETTING,
41 null,
42 null,
43 new pix_icon('competency', '', 'tool_lp'));
44 if (isset($settingsnode)) {
45 $navigation->add_node($settingsnode);
46 }
47}
4db373d5 48
5c7383fd
JPG
49
50/**
51 * This function extends the user navigation.
52 *
53 * @param navigation_node $navigation The navigation node to extend
54 * @param stdClass $user The user object
55 * @param context_user $usercontext The user context
56 * @param stdClass $course The course object
57 * @param context_course $coursecontext The context of the course
58 */
59function tool_lp_extend_navigation_user($navigation, $user, $usercontext, $course, $coursecontext) {
6c2b163c
FM
60 $node = $navigation->add(get_string('learningplans', 'tool_lp'),
61 new moodle_url('/admin/tool/lp/plans.php', array('userid' => $user->id)));
62
63 if (\tool_lp\user_evidence::can_read_user($user->id)) {
64 $node->add(get_string('userevidence', 'tool_lp'),
65 new moodle_url('/admin/tool/lp/user_evidence_list.php', array('userid' => $user->id)));
66 }
5c7383fd
JPG
67}
68
4db373d5
DM
69/**
70 * Add nodes to myprofile page.
71 *
72 * @param \core_user\output\myprofile\tree $tree Tree object
73 * @param stdClass $user user object
74 * @param bool $iscurrentuser
75 * @param stdClass $course Course object
76 *
77 * @return bool
78 */
79function tool_lp_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
5159d679 80 if (!\tool_lp\plan::can_read_user($user->id)) {
4db373d5
DM
81 return false;
82 }
83
5c7383fd 84 $url = new moodle_url('/admin/tool/lp/plans.php', array('userid' => $user->id));
4db373d5
DM
85 $node = new core_user\output\myprofile\node('miscellaneous', 'learningplans',
86 get_string('learningplans', 'tool_lp'), null, $url);
87 $tree->add_node($node);
5c7383fd
JPG
88
89 return true;
4db373d5 90}
904291f2
IT
91
92/**
93 * This function extends the category navigation to add learning plan links.
94 *
95 * @param navigation_node $navigation The navigation node to extend
96 * @param context $coursecategorycontext The context of the course category
97 */
98function tool_lp_extend_navigation_category_settings($navigation, $coursecategorycontext) {
99 // We check permissions before renderring the links.
935e9e90 100 $templatereadcapability = \tool_lp\template::can_read_context($coursecategorycontext);
904291f2 101 $competencymanagecapability = has_capability('tool/lp:competencymanage', $coursecategorycontext);
935e9e90 102 if (!$templatereadcapability && !$competencymanagecapability) {
904291f2
IT
103 return false;
104 }
105
106 // The link to the learning plan page.
935e9e90 107 if ($templatereadcapability) {
904291f2
IT
108 $title = get_string('learningplans', 'tool_lp');
109 $path = new moodle_url("/admin/tool/lp/learningplans.php", array('pagecontextid' => $coursecategorycontext->id));
110 $settingsnode = navigation_node::create($title,
111 $path,
112 navigation_node::TYPE_SETTING,
113 null,
114 null,
115 new pix_icon('competency', '', 'tool_lp'));
116 if (isset($settingsnode)) {
117 $navigation->add_node($settingsnode);
118 }
119 }
120
121 // The link to the competency frameworks page.
122 if ($competencymanagecapability) {
123 $title = get_string('competencyframeworks', 'tool_lp');
124 $path = new moodle_url("/admin/tool/lp/competencyframeworks.php", array('pagecontextid' => $coursecategorycontext->id));
125 $settingsnode = navigation_node::create($title,
126 $path,
127 navigation_node::TYPE_SETTING,
128 null,
129 null,
130 new pix_icon('competency', '', 'tool_lp'));
131 if (isset($settingsnode)) {
132 $navigation->add_node($settingsnode);
133 }
134 }
6c2b163c
FM
135}
136
137
138/**
139 * File serving.
140 *
141 * @param stdClass $course The course object.
142 * @param stdClass $cm The cm object.
143 * @param context $context The context object.
144 * @param string $filearea The file area.
145 * @param array $args List of arguments.
146 * @param bool $forcedownload Whether or not to force the download of the file.
147 * @param array $options Array of options.
148 * @return void|false
149 */
150function tool_lp_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
151 global $CFG;
152
153 $fs = get_file_storage();
154 $file = null;
155
156 $itemid = array_shift($args);
157 $filename = array_shift($args);
158 $filepath = $args ? '/' .implode('/', $args) . '/' : '/';
159
160 if ($filearea == 'userevidence' && $context->contextlevel == CONTEXT_USER) {
161 if (\tool_lp\user_evidence::can_read_user($context->instanceid)) {
162 $file = $fs->get_file($context->id, 'tool_lp', $filearea, $itemid, $filepath, $filename);
163 }
164 }
165
166 if (!$file) {
167 return false;
168 }
169
170 send_stored_file($file, null, 0, $forcedownload);
171}