MDL-51504 tool_lp: Validate the templates' due date
[moodle.git] / admin / tool / lp / editcompetency.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 lets users to manage site wide competencies.
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
25require_once(__DIR__ . '/../../../config.php');
26require_once($CFG->libdir.'/adminlib.php');
27
d9a39950
DW
28$title = get_string('competencies', 'tool_lp');
29$id = optional_param('id', 0, PARAM_INT);
30$competencyframeworkid = required_param('competencyframeworkid', PARAM_INT);
2de75345 31$pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to the context we came from.
d9a39950
DW
32$parentid = optional_param('parentid', 0, PARAM_INT);
33
2de75345
FM
34require_login();
35$pagecontext = context::instance_by_id($pagecontextid);
36
d9a39950
DW
37if (empty($id)) {
38 $pagetitle = get_string('addnewcompetency', 'tool_lp');
39} else {
40 $pagetitle = get_string('editcompetency', 'tool_lp');
41}
2de75345 42
d9a39950 43// Set up the page.
2de75345
FM
44$url = new moodle_url("/admin/tool/lp/editcompetency.php", array('id' => $id, 'competencyframeworkid' => $competencyframeworkid,
45 'parentid' => $parentid, 'pagecontextid' => $pagecontextid));
46$frameworksurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', array('pagecontextid' => $pagecontextid));
47$frameworkurl = new moodle_url('/admin/tool/lp/competencies.php', array('competencyframeworkid' => $competencyframeworkid,
48 'pagecontextid' => $pagecontextid));
d9a39950
DW
49
50$competencyframework = \tool_lp\api::read_framework($competencyframeworkid);
51$parent = null;
52if ($parentid) {
53 $parent = \tool_lp\api::read_competency($parentid);
54}
55
2de75345
FM
56$PAGE->navigation->override_active_url($frameworksurl);
57$PAGE->set_context($pagecontext);
58$PAGE->set_pagelayout('admin');
59$PAGE->set_url($url);
60$PAGE->set_title($title);
61$PAGE->set_heading($title);
62$PAGE->navbar->add($competencyframework->get_shortname(), $frameworkurl);
63$output = $PAGE->get_renderer('tool_lp');
64
65$form = new \tool_lp\form\competency($url->out(false), array('id' => $id, 'competencyframework' => $competencyframework,
66 'parent' => $parent));
d9a39950
DW
67
68if ($form->is_cancelled()) {
2de75345 69 redirect($frameworkurl);
d9a39950
DW
70}
71
72echo $output->header();
73echo $output->heading($pagetitle);
74
75$data = $form->get_data();
76if ($data) {
77 // Save the changes and continue back to the manage page.
78 // Massage the editor data.
79 $data->descriptionformat = $data->description['format'];
80 $data->description = $data->description['text'];
81 if (empty($data->id)) {
82 // Create new framework.
83 require_sesskey();
84 \tool_lp\api::create_competency($data);
85 echo $output->notification(get_string('competencycreated', 'tool_lp'), 'notifysuccess');
2de75345 86 echo $output->continue_button($frameworkurl);
d9a39950
DW
87 } else {
88 require_sesskey();
89 \tool_lp\api::update_competency($data);
90 echo $output->notification(get_string('competencyupdated', 'tool_lp'), 'notifysuccess');
2de75345 91 echo $output->continue_button($frameworkurl);
d9a39950
DW
92 }
93} else {
94 $form->display();
95}
96
d9a39950 97echo $output->footer();