2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
20 * @package mod_attendance
21 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once($CFG->libdir
.'/formslib.php');
29 * class for displaying update form.
31 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class mod_attendance_update_form
extends moodleform
{
37 * Called to define this moodle form
41 public function definition() {
44 $mform =& $this->_form
;
46 $modcontext = $this->_customdata
['modcontext'];
47 $sessionid = $this->_customdata
['sessionid'];
49 if (!$sess = $DB->get_record('attendance_sessions', array('id' => $sessionid) )) {
50 error('No such session in this course');
52 $defopts = array('maxfiles' => EDITOR_UNLIMITED_FILES
, 'noclean' => true
, 'context' => $modcontext);
53 $sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attendance', 'session', $sess->id
);
55 $starttime = $sess->sessdate
- usergetmidnight($sess->sessdate
);
56 $starthour = floor($starttime / HOURSECS
);
57 $startminute = floor(($starttime - $starthour * HOURSECS
) / MINSECS
);
59 $enddate = $sess->sessdate +
$sess->duration
;
60 $endtime = $enddate - usergetmidnight($enddate);
61 $endhour = floor($endtime / HOURSECS
);
62 $endminute = floor(($endtime - $endhour * HOURSECS
) / MINSECS
);
64 $sesendtime = $sess->sessdate +
$sess->duration
;
65 $data = array('sessiondate' => $sess->sessdate
,
66 'sestime' => array('starthour' => $starthour, 'startminute' => $startminute,
67 'endhour' => $endhour, 'endminute' => $endminute),
68 'sdescription' => $sess->description_editor
);
70 $mform->addElement('header', 'general', get_string('changesession', 'attendance'));
72 if ($sess->groupid
== 0) {
73 $strtype = get_string('commonsession', 'attendance');
75 $groupname = $DB->get_field('groups', 'name', array('id' => $sess->groupid
));
76 $strtype = get_string('group') . ': ' . $groupname;
78 $mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attendance'), $strtype);
80 $olddate = construct_session_full_date_time($sess->sessdate
, $sess->duration
);
81 $mform->addElement('static', 'olddate', get_string('olddate', 'attendance'), $olddate);
83 attendance_form_sessiondate_selector($mform);
85 // Show which status set is in use.
86 $maxstatusset = attendance_get_max_statusset($this->_customdata
['att']->id
);
87 if ($maxstatusset > 0) {
88 $mform->addElement('static', 'statusset', get_string('usestatusset', 'mod_attendance'),
89 attendance_get_setname($this->_customdata
['att']->id
, $sess->statusset
));
92 $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'),
93 array('rows' => 1, 'columns' => 80), $defopts);
94 $mform->setType('sdescription', PARAM_RAW
);
96 $mform->setDefaults($data);
98 $this->add_action_buttons(true
);
102 * Perform minimal validation on the settings form
104 * @param array $files
106 public function validation($data, $files) {
107 $errors = parent
::validation($data, $files);
109 $sesstarttime = $data['sestime']['starthour'] * HOURSECS +
$data['sestime']['startminute'] * MINSECS
;
110 $sesendtime = $data['sestime']['endhour'] * HOURSECS +
$data['sestime']['endminute'] * MINSECS
;
111 if ($sesendtime < $sesstarttime) {
112 $errors['sestime'] = get_string('invalidsessionendtime', 'attendance');