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 learning plan templates.
21 * @copyright 2015 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(__DIR__ . '/../../../config.php');
26 require_once($CFG->libdir.'/adminlib.php');
28 $id = optional_param('id', 0, PARAM_INT);
29 $returntype = optional_param('return', null, PARAM_ALPHA);
30 $pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to where we can from.
34 // Always use the context from the framework when it exists.
35 $template = new \tool_lp\template($id);
36 $context = $template->get_context();
38 $context = context::instance_by_id($pagecontextid);
41 // We check that we have the permission to edit this framework, in its own context.
42 require_login(0, false);
43 \tool_lp\api::require_enabled();
44 require_capability('tool/lp:templatemanage', $context);
46 // We keep the original context in the URLs, so that we remain in the same context.
47 $url = new moodle_url("/admin/tool/lp/edittemplate.php", [
49 'pagecontextid' => $pagecontextid,
50 'return' => $returntype
54 $pagetitle = get_string('addnewtemplate', 'tool_lp');
55 list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, null, $pagetitle,
58 $template = \tool_lp\api::read_template($id);
59 $pagetitle = get_string('edittemplate', 'tool_lp');
60 list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template,
61 $pagetitle, $returntype);
64 $form = new \tool_lp\form\template($url->out(false), array('persistent' => $template, 'context' => $context));
65 if ($form->is_cancelled()) {
69 $data = $form->get_data();
72 if (empty($data->id)) {
73 $template = \tool_lp\api::create_template($data);
74 $returnurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', [
75 'templateid' => $template->get_id(),
76 'pagecontextid' => $pagecontextid
78 $returnmsg = get_string('templatecreated', 'tool_lp');
80 \tool_lp\api::update_template($data);
81 $returnmsg = get_string('templateupdated', 'tool_lp');
83 redirect($returnurl, $returnmsg, null, \core\output\notification::NOTIFY_SUCCESS);
86 $output = $PAGE->get_renderer('tool_lp');
87 echo $output->header();
88 echo $output->heading($title);
89 if (!empty($subtitle)) {
90 echo $output->heading($subtitle, 3);
95 echo $output->footer();