Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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   * Form class for badge message.
  19   *
  20   * @package    core
  21   * @subpackage badges
  22   * @copyright  2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   * @author     Yuliya Bozhko <yuliya.bozhko@totaralms.com>
  25   */
  26  
  27  namespace core_badges\form;
  28  
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  require_once($CFG->libdir . '/formslib.php');
  32  require_once($CFG->libdir . '/badgeslib.php');
  33  require_once($CFG->libdir . '/filelib.php');
  34  
  35  use moodleform;
  36  
  37  /**
  38   * Form to edit badge message.
  39   *
  40   * @copyright  2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
  41   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42   */
  43  class message extends moodleform {
  44  
  45      /**
  46       * Create the form.
  47       */
  48      public function definition() {
  49          global $CFG, $OUTPUT;
  50  
  51          $mform = $this->_form;
  52          $badge = $this->_customdata['badge'];
  53          $action = $this->_customdata['action'];
  54          $editoroptions = $this->_customdata['editoroptions'];
  55  
  56          // Add hidden fields.
  57          $mform->addElement('hidden', 'id', $badge->id);
  58          $mform->setType('id', PARAM_INT);
  59  
  60          $mform->addElement('hidden', 'action', $action);
  61          $mform->setType('action', PARAM_TEXT);
  62  
  63          $mform->addElement('header', 'badgemessage', get_string('configuremessage', 'badges'));
  64          $mform->addHelpButton('badgemessage', 'variablesubstitution', 'badges');
  65  
  66          $mform->addElement('text', 'messagesubject', get_string('subject', 'badges'), array('size' => '70'));
  67          $mform->setType('messagesubject', PARAM_TEXT);
  68          $mform->addRule('messagesubject', null, 'required');
  69          $mform->addRule('messagesubject', get_string('maximumchars', '', 255), 'maxlength', 255);
  70  
  71          $mform->addElement('editor', 'message_editor', get_string('message', 'badges'), null, $editoroptions);
  72          $mform->setType('message_editor', PARAM_RAW);
  73          $mform->addRule('message_editor', null, 'required');
  74  
  75          $mform->addElement('advcheckbox', 'attachment', get_string('attachment', 'badges'), '', null, array(0, 1));
  76          $mform->addHelpButton('attachment', 'attachment', 'badges');
  77          if (empty($CFG->allowattachments)) {
  78              $mform->freeze('attachment');
  79          }
  80  
  81          $options = array(
  82                  BADGE_MESSAGE_NEVER   => get_string('never'),
  83                  BADGE_MESSAGE_ALWAYS  => get_string('notifyevery', 'badges'),
  84                  BADGE_MESSAGE_DAILY   => get_string('notifydaily', 'badges'),
  85                  BADGE_MESSAGE_WEEKLY  => get_string('notifyweekly', 'badges'),
  86                  BADGE_MESSAGE_MONTHLY => get_string('notifymonthly', 'badges'),
  87                  );
  88          $mform->addElement('select', 'notification', get_string('notification', 'badges'), $options);
  89          $mform->addHelpButton('notification', 'notification', 'badges');
  90  
  91          $this->add_action_buttons();
  92          $this->set_data($badge);
  93      }
  94  }