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 a users preferred language
19
 *
20
 * @copyright 2015 Shamim Rezaie  http://foodle.org
21
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @package core_user
23
 */
24
 
25
namespace core_user\form;
26
 
27
if (!defined('MOODLE_INTERNAL')) {
28
    die('Direct access to this script is forbidden.');    // It must be included from a Moodle page.
29
}
30
 
31
require_once($CFG->dirroot.'/lib/formslib.php');
32
 
33
/**
34
 * Class user_edit_calendar_form.
35
 *
36
 * @copyright 2015 Shamim Rezaie  http://foodle.org
37
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
class calendar_form extends \moodleform {
40
 
41
    /**
42
     * Define the form.
43
     */
44
    public function definition() {
45
        global $CFG, $USER;
46
 
47
        $mform = $this->_form;
48
        $userid = $USER->id;
49
 
50
        if (is_array($this->_customdata)) {
51
            if (array_key_exists('userid', $this->_customdata)) {
52
                $userid = $this->_customdata['userid'];
53
            }
54
        }
55
 
56
        // Add some extra hidden fields.
57
        $mform->addElement('hidden', 'id');
58
        $mform->setType('id', PARAM_INT);
59
 
60
        // We do not want to show this option unless there is more than one calendar type to display.
61
        if (count(\core_calendar\type_factory::get_list_of_calendar_types()) > 1) {
62
            $calendartypes = \core_calendar\type_factory::get_list_of_calendar_types();
63
            $mform->addElement('select', 'calendartype', get_string('preferredcalendar', 'calendar'), $calendartypes);
64
            $mform->setType('calendartype', PARAM_ALPHANUM);
65
            $mform->setDefault('calendartype', $CFG->calendartype);
66
        } else {
67
            $mform->addElement('hidden', 'calendartype', $CFG->calendartype);
68
            $mform->setType('calendartype', PARAM_ALPHANUM);
69
 
70
        }
71
 
72
        // Date / Time settings.
73
        $options = array(
74
            '0'  => get_string('default', 'calendar'),
75
            CALENDAR_TF_12 => get_string('timeformat_12', 'calendar'),
76
            CALENDAR_TF_24 => get_string('timeformat_24', 'calendar')
77
        );
78
        $mform->addElement('select', 'timeformat', get_string('pref_timeformat', 'calendar'), $options);
79
        $mform->addHelpButton('timeformat', 'pref_timeformat', 'calendar');
80
 
81
        // First day of week.
82
        $options = array(
83
 
84
            1 => get_string('monday', 'calendar'),
85
            2 => get_string('tuesday', 'calendar'),
86
            3 => get_string('wednesday', 'calendar'),
87
            4 => get_string('thursday', 'calendar'),
88
            5 => get_string('friday', 'calendar'),
89
            6 => get_string('saturday', 'calendar')
90
        );
91
        $mform->addElement('select', 'startwday', get_string('pref_startwday', 'calendar'), $options);
92
        $mform->addHelpButton('startwday', 'pref_startwday', 'calendar');
93
 
94
        // Maximum events to display.
95
        $options = array();
96
        for ($i = 1; $i <= 20; $i++) {
97
            $options[$i] = $i;
98
        }
99
        $mform->addElement('select', 'maxevents', get_string('pref_maxevents', 'calendar'), $options);
100
        $mform->addHelpButton('maxevents', 'pref_maxevents', 'calendar');
101
 
102
        // Calendar lookahead.
103
        $options = array(365 => new \lang_string('numyear', '', 1),
104
                270 => get_string('nummonths', '', 9),
105
                180 => get_string('nummonths', '', 6),
106
                150 => get_string('nummonths', '', 5),
107
                120 => get_string('nummonths', '', 4),
108
                90  => get_string('nummonths', '', 3),
109
                60  => get_string('nummonths', '', 2),
110
                30  => get_string('nummonth', '', 1),
111
                21  => get_string('numweeks', '', 3),
112
                14  => get_string('numweeks', '', 2),
113
                7  => get_string('numweek', '', 1),
114
                6  => get_string('numdays', '', 6),
115
                5  => get_string('numdays', '', 5),
116
                4  => get_string('numdays', '', 4),
117
                3  => get_string('numdays', '', 3),
118
                2  => get_string('numdays', '', 2),
119
                1  => get_string('numday', '', 1));
120
        $mform->addElement('select', 'lookahead', get_string('pref_lookahead', 'calendar'), $options);
121
        $mform->addHelpButton('lookahead', 'pref_lookahead', 'calendar');
122
 
123
        // Remember event filtering.
124
        $options = array(
125
 
126
            1 => get_string('yes')
127
        );
128
        $mform->addElement('select', 'persistflt', get_string('pref_persistflt', 'calendar'), $options);
129
        $mform->addHelpButton('persistflt', 'pref_persistflt', 'calendar');
130
        $this->add_action_buttons(true, get_string('savechanges'));
131
    }
132
 
133
    /**
134
     * Extend the form definition after the data has been parsed.
135
     */
136
    public function definition_after_data() {
137
        global $CFG;
138
 
139
        $mform = $this->_form;
140
 
141
        // If calendar type does not exist, use site default calendar type.
142
        if ($calendarselected = $mform->getElementValue('calendartype')) {
143
            if (is_array($calendarselected)) {
144
                // There are multiple calendar types available.
145
                $calendar = reset($calendarselected);
146
            } else {
147
                // There is only one calendar type available.
148
                $calendar = $calendarselected;
149
            }
150
            // Check calendar type exists.
151
            if (!array_key_exists($calendar, \core_calendar\type_factory::get_list_of_calendar_types())) {
152
                $calendartypeel = $mform->getElement('calendartype');
153
                $calendartypeel->setValue($CFG->calendartype);
154
            }
155
        }
156
    }
157
}