[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/lp/classes/form/ -> plan.php (source)

   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_competency\plan as planpersistent;
  29  use required_capability_exception;
  30  
  31  /**
  32   * Learning plan form.
  33   *
  34   * @package   tool_lp
  35   * @copyright 2015 David Monllao
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class plan extends persistent {
  39  
  40      protected static $persistentclass = 'core_competency\\plan';
  41  
  42      /**
  43       * Define the form - called by parent constructor
  44       */
  45      public function definition() {
  46          $mform = $this->_form;
  47          $context = $this->_customdata['context'];
  48  
  49          $mform->addElement('hidden', 'userid');
  50          $mform->setType('userid', PARAM_INT);
  51          $mform->setConstant('userid', $this->_customdata['userid']);
  52  
  53          $mform->addElement('header', 'generalhdr', get_string('general'));
  54  
  55          // Name.
  56          $mform->addElement('text', 'name', get_string('planname', 'tool_lp'), 'maxlength="100"');
  57          $mform->setType('name', PARAM_TEXT);
  58          $mform->addRule('name', null, 'required', null, 'client');
  59          $mform->addRule('name', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
  60          // Description.
  61          $mform->addElement('editor', 'description', get_string('plandescription', 'tool_lp'), array('rows' => 4));
  62          $mform->setType('description', PARAM_RAW);
  63  
  64          $mform->addElement('date_time_selector', 'duedate', get_string('duedate', 'tool_lp'), array('optional' => true));
  65          $mform->addHelpButton('duedate', 'duedate', 'tool_lp');
  66  
  67          // Display status selector in form.
  68          // When the plan was already saved then the status can not be changed via this form.
  69          $status = planpersistent::get_status_list($this->_customdata['userid']);
  70          $plan = $this->get_persistent();
  71          if ($plan->get_id()) {
  72              // The current status is not selectable (workflow status probably), we just display it.
  73              $mform->addElement('static', 'staticstatus', get_string('status', 'tool_lp'), $plan->get_statusname());
  74          } else if (!empty($status) && count($status) > 1) {
  75              // There is more than one status to select from.
  76              $mform->addElement('select', 'status', get_string('status', 'tool_lp'), $status);
  77          } else if (count($status) === 1) {
  78              // There is only one status to select from.
  79              $mform->addElement('static', 'staticstatus', get_string('status', 'tool_lp'), current($status));
  80          } else {
  81              throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
  82          }
  83  
  84          // Disable short forms.
  85          $mform->setDisableShortforms();
  86          $this->add_action_buttons(true, get_string('savechanges', 'tool_lp'));
  87      }
  88  
  89  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1