MDL-51027 tool_lp: Require ID numbers for frameworks and competencies
[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
28admin_externalpage_setup('toollpcompetencies');
29
30$title = get_string('competencies', 'tool_lp');
31$id = optional_param('id', 0, PARAM_INT);
32$competencyframeworkid = required_param('competencyframeworkid', PARAM_INT);
33$parentid = optional_param('parentid', 0, PARAM_INT);
34
35if (empty($id)) {
36 $pagetitle = get_string('addnewcompetency', 'tool_lp');
37} else {
38 $pagetitle = get_string('editcompetency', 'tool_lp');
39}
40// Set up the page.
b17d3d10 41$params = array('id' => $id, 'competencyframeworkid' => $competencyframeworkid, 'parentid' => $parentid);
d9a39950
DW
42$url = new moodle_url("/admin/tool/lp/editcompetency.php", $params);
43$PAGE->set_url($url);
44$PAGE->set_title($title);
45$PAGE->set_heading($title);
46$output = $PAGE->get_renderer('tool_lp');
47
48$competencyframework = \tool_lp\api::read_framework($competencyframeworkid);
49$parent = null;
50if ($parentid) {
51 $parent = \tool_lp\api::read_competency($parentid);
52}
53
54$form = new \tool_lp\form\competency(null, array('id' => $id, 'competencyframework' => $competencyframework, 'parent' => $parent));
55
56if ($form->is_cancelled()) {
b17d3d10 57 redirect(new moodle_url('/admin/tool/lp/competencies.php', array('competencyframeworkid' => $competencyframeworkid)));
d9a39950
DW
58}
59
60echo $output->header();
61echo $output->heading($pagetitle);
62
63$data = $form->get_data();
64if ($data) {
65 // Save the changes and continue back to the manage page.
66 // Massage the editor data.
67 $data->descriptionformat = $data->description['format'];
68 $data->description = $data->description['text'];
69 if (empty($data->id)) {
70 // Create new framework.
71 require_sesskey();
72 \tool_lp\api::create_competency($data);
73 echo $output->notification(get_string('competencycreated', 'tool_lp'), 'notifysuccess');
b17d3d10
AA
74 echo $output->continue_button(new moodle_url('/admin/tool/lp/competencies.php',
75 array('competencyframeworkid' => $competencyframeworkid)));
d9a39950
DW
76 } else {
77 require_sesskey();
78 \tool_lp\api::update_competency($data);
79 echo $output->notification(get_string('competencyupdated', 'tool_lp'), 'notifysuccess');
b17d3d10
AA
80 echo $output->continue_button(new moodle_url('/admin/tool/lp/competencies.php',
81 array('competencyframeworkid' => $competencyframeworkid)));
d9a39950
DW
82 }
83} else {
84 $form->display();
85}
86
d9a39950 87echo $output->footer();