on-demand release 3.8dev+
[moodle.git] / badges / classes / form / message.php
blob6e7d0b5e7f0629b1b748adba2519b6582c3d0e91
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.
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/>.
17 /**
18 * Form class for badge message.
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>
27 namespace core_badges\form;
29 defined('MOODLE_INTERNAL') || die();
31 require_once($CFG->libdir . '/formslib.php');
32 require_once($CFG->libdir . '/badgeslib.php');
33 require_once($CFG->libdir . '/filelib.php');
35 use moodleform;
37 /**
38 * Form to edit badge message.
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
43 class message extends moodleform {
45 /**
46 * Create the form.
48 public function definition() {
49 global $CFG, $OUTPUT;
51 $mform = $this->_form;
52 $badge = $this->_customdata['badge'];
53 $action = $this->_customdata['action'];
54 $editoroptions = $this->_customdata['editoroptions'];
56 // Add hidden fields.
57 $mform->addElement('hidden', 'id', $badge->id);
58 $mform->setType('id', PARAM_INT);
60 $mform->addElement('hidden', 'action', $action);
61 $mform->setType('action', PARAM_TEXT);
63 $mform->addElement('header', 'badgemessage', get_string('configuremessage', 'badges'));
64 $mform->addHelpButton('badgemessage', 'variablesubstitution', 'badges');
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);
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');
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');
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'),
88 $mform->addElement('select', 'notification', get_string('notification', 'badges'), $options);
89 $mform->addHelpButton('notification', 'notification', 'badges');
91 $this->add_action_buttons();
92 $this->set_data($badge);