Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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 to edit handlers.
19
 *
20
 * @package    tool_messageinbound
21
 * @copyright  2014 Andrew Nicols
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
require_once($CFG->libdir . '/formslib.php');
28
 
29
/**
30
 * Form to edit handlers.
31
 *
32
 * @copyright  2014 Andrew Nicols
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class tool_messageinbound_edit_handler_form extends moodleform {
36
 
37
    /**
38
     * The form definition
39
     */
40
    public function definition() {
41
        $mform = $this->_form;
42
 
43
        $handler = $this->_customdata['handler'];
44
 
45
        // Set up the options for formatting text for descriptions, etc.
46
        $formatoptions = new stdClass();
47
        $formatoptions->trusted = false;
48
        $formatoptions->noclean = false;
49
        $formatoptions->filter = false;
50
        $formatoptions->para = true;
51
        $formatoptions->newlines = false;
52
        $formatoptions->overflowdiv = true;
53
 
54
        // General information about the handler.
55
        $mform->addElement('header', 'general', get_string('general'));
56
        $mform->addElement('static', 'name', get_string('name', 'tool_messageinbound'),
57
            $handler->name);
58
        $mform->addElement('static', 'classname', get_string('classname', 'tool_messageinbound'));
59
 
60
        $description = format_text($handler->description, FORMAT_MARKDOWN, $formatoptions);
61
 
62
        $mform->addElement('static', 'description', get_string('description', 'tool_messageinbound'),
63
            $description);
64
 
65
        // Items which can be configured.
66
        $mform->addElement('header', 'configuration', get_string('configuration'));
67
 
68
        if ($handler->can_change_defaultexpiration()) {
69
            // Show option to change expiry only if the handler supports it.
70
            $options = array(
71
                HOURSECS => get_string('onehour', 'tool_messageinbound'),
72
                DAYSECS => get_string('oneday', 'tool_messageinbound'),
73
                WEEKSECS => get_string('oneweek', 'tool_messageinbound'),
74
                YEARSECS => get_string('oneyear', 'tool_messageinbound'),
75
 
76
            );
77
            $mform->addElement('select', 'defaultexpiration', get_string('defaultexpiration', 'tool_messageinbound'), $options);
78
            $mform->addHelpButton('defaultexpiration', 'defaultexpiration', 'tool_messageinbound');
79
        } else {
80
            $text = $this->get_defaultexpiration_text($handler);
81
            $mform->addElement('static', 'defaultexpiration_fake', get_string('defaultexpiration', 'tool_messageinbound'), $text);
82
            $mform->addElement('hidden', 'defaultexpiration');
83
            $mform->addHelpButton('defaultexpiration_fake', 'defaultexpiration', 'tool_messageinbound');
84
            $mform->setType('defaultexpiration', PARAM_INT);
85
        }
86
 
87
        if ($handler->can_change_validateaddress()) {
88
            $mform->addElement('checkbox', 'validateaddress', get_string('requirevalidation', 'tool_messageinbound'));
89
            $mform->addHelpButton('validateaddress', 'validateaddress', 'tool_messageinbound');
90
        } else {
91
            if ($handler->validateaddress) {
92
                $text = get_string('yes');
93
            } else {
94
                $text = get_string('no');
95
            }
96
            $mform->addElement('static', 'validateaddress_fake', get_string('requirevalidation', 'tool_messageinbound'), $text);
97
            $mform->addElement('hidden', 'validateaddress');
98
            $mform->addHelpButton('validateaddress_fake', 'fixedvalidateaddress', 'tool_messageinbound');
99
            $mform->setType('validateaddress', PARAM_INT);
100
        }
101
 
102
        if ($handler->can_change_enabled()) {
103
            $mform->addElement('checkbox', 'enabled', get_string('enabled', 'tool_messageinbound'));
104
        } else {
105
            if ($handler->enabled) {
106
                $text = get_string('yes');
107
            } else {
108
                $text = get_string('no');
109
            }
110
            $mform->addElement('static', 'enabled_fake', get_string('enabled', 'tool_messageinbound'), $text);
111
            $mform->addHelpButton('enabled', 'fixedenabled', 'tool_messageinbound');
112
            $mform->addElement('hidden', 'enabled');
113
            $mform->setType('enabled', PARAM_INT);
114
        }
115
 
116
        $this->add_action_buttons(true, get_string('savechanges'));
117
    }
118
 
119
    /**
120
     * Return a text string representing the selected default expiration for the handler.
121
     *
122
     * @param \core\message\inbound\handler $handler handler instance.
123
     *
124
     * @return string localised text string.
125
     */
126
    protected function get_defaultexpiration_text(\core\message\inbound\handler $handler) {
127
        switch($handler->defaultexpiration) {
128
            case HOURSECS :
129
                    return get_string('onehour', 'tool_messageinbound');
130
            case DAYSECS :
131
                    return get_string('oneday', 'tool_messageinbound');
132
            case WEEKSECS :
133
                    return get_string('oneweek', 'tool_messageinbound');
134
            case YEARSECS :
135
                    return get_string('oneyear', 'tool_messageinbound');
136
            case 0:
137
                    return get_string('noexpiry', 'tool_messageinbound');
138
            default:
139
                    return ''; // Should never happen.
140
        }
141
    }
142
}