Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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 file contains the form add/update a learning plan.
  19   *
  20   * @package   tool_lp
  21   * @copyright 2015 David Monllao
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace tool_lp\form;
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  use core\form\persistent;
  29  use core_competency\plan as planpersistent;
  30  use required_capability_exception;
  31  
  32  /**
  33   * Learning plan form.
  34   *
  35   * @package   tool_lp
  36   * @copyright 2015 David Monllao
  37   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class plan extends persistent {
  40  
  41      protected static $persistentclass = 'core_competency\\plan';
  42  
  43      /**
  44       * Define the form - called by parent constructor
  45       */
  46      public function definition() {
  47          $mform = $this->_form;
  48          $context = $this->_customdata['context'];
  49  
  50          $mform->addElement('hidden', 'userid');
  51          $mform->setType('userid', PARAM_INT);
  52          $mform->setConstant('userid', $this->_customdata['userid']);
  53  
  54          $mform->addElement('header', 'generalhdr', get_string('general'));
  55  
  56          // Name.
  57          $mform->addElement('text', 'name', get_string('planname', 'tool_lp'), 'maxlength="100"');
  58          $mform->setType('name', PARAM_TEXT);
  59          $mform->addRule('name', null, 'required', null, 'client');
  60          $mform->addRule('name', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
  61          // Description.
  62          $mform->addElement('editor', 'description', get_string('plandescription', 'tool_lp'), array('rows' => 4));
  63          $mform->setType('description', PARAM_CLEANHTML);
  64  
  65          $mform->addElement('date_time_selector', 'duedate', get_string('duedate', 'tool_lp'), array('optional' => true));
  66          $mform->addHelpButton('duedate', 'duedate', 'tool_lp');
  67  
  68          // Display status selector in form.
  69          // When the plan was already saved then the status can not be changed via this form.
  70          $status = planpersistent::get_status_list($this->_customdata['userid']);
  71          $plan = $this->get_persistent();
  72          if ($plan->get('id')) {
  73              // The current status is not selectable (workflow status probably), we just display it.
  74              $mform->addElement('static', 'staticstatus', get_string('status', 'tool_lp'), $plan->get_statusname());
  75          } else if (!empty($status) && count($status) > 1) {
  76              // There is more than one status to select from.
  77              $mform->addElement('select', 'status', get_string('status', 'tool_lp'), $status);
  78          } else if (count($status) === 1) {
  79              // There is only one status to select from.
  80              $mform->addElement('static', 'staticstatus', get_string('status', 'tool_lp'), current($status));
  81          } else {
  82              throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
  83          }
  84  
  85          // Disable short forms.
  86          $mform->setDisableShortforms();
  87          $this->add_action_buttons(true, get_string('savechanges', 'tool_lp'));
  88      }
  89  
  90  }