editcompetencyframework.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * This page lets users to manage site wide competencies.
  18. *
  19. * @package tool_lp
  20. * @copyright 2015 Damyon Wiese
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require_once(__DIR__ . '/../../../config.php');
  24. require_once($CFG->libdir.'/adminlib.php');
  25. $id = optional_param('id', 0, PARAM_INT);
  26. $returntype = optional_param('return', null, PARAM_TEXT);
  27. $pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to where we can from.
  28. $framework = null;
  29. if (!empty($id)) {
  30. // Always use the context from the framework when it exists.
  31. $framework = new \core_competency\competency_framework($id);
  32. $context = $framework->get_context();
  33. } else {
  34. $context = context::instance_by_id($pagecontextid);
  35. }
  36. // We check that we have the permission to edit this framework, in its own context.
  37. require_login();
  38. \core_competency\api::require_enabled();
  39. require_capability('moodle/competency:competencymanage', $context);
  40. // Set up the framework page.
  41. list($pagetitle, $pagesubtitle, $url, $frameworksurl) = tool_lp\page_helper::setup_for_framework($id,
  42. $pagecontextid, $framework, $returntype);
  43. $output = $PAGE->get_renderer('tool_lp');
  44. $form = new \tool_lp\form\competency_framework($url->out(false), array('context' => $context, 'persistent' => $framework));
  45. if ($form->is_cancelled()) {
  46. redirect($frameworksurl);
  47. } else if ($data = $form->get_data()) {
  48. if (empty($data->id)) {
  49. // Create new framework.
  50. $data->contextid = $context->id;
  51. $framework = \core_competency\api::create_framework($data);
  52. $frameworkmanageurl = new moodle_url('/admin/tool/lp/competencies.php', array(
  53. 'pagecontextid' => $pagecontextid,
  54. 'competencyframeworkid' => $framework->get_id()
  55. ));
  56. $messagesuccess = get_string('competencyframeworkcreated', 'tool_lp');
  57. redirect($frameworkmanageurl, $messagesuccess, 0, \core\output\notification::NOTIFY_SUCCESS);
  58. } else {
  59. \core_competency\api::update_framework($data);
  60. $messagesuccess = get_string('competencyframeworkupdated', 'tool_lp');
  61. redirect($frameworksurl, $messagesuccess, 0, \core\output\notification::NOTIFY_SUCCESS);
  62. }
  63. }
  64. echo $output->header();
  65. echo $output->heading($pagetitle, 2);
  66. echo $output->heading($pagesubtitle, 3);
  67. $form->display();
  68. echo $output->footer();