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
25 defined('MOODLE_INTERNAL') ||
die();
26 require_once($CFG->libdir
.'/formslib.php');
29 * Class mod_attendance_student_attendance_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_student_attendance_form
extends moodleform
{
36 * Called to define this moodle form
40 public function definition() {
43 $mform =& $this->_form
;
45 $attforsession = $this->_customdata
['session'];
46 $attblock = $this->_customdata
['attendance'];
48 $statuses = $attblock->get_statuses();
49 // Check if user has access to all statuses.
50 $disabledduetotime = false
;
51 foreach ($statuses as $status) {
52 if ($status->studentavailability
=== '0') {
53 unset($statuses[$status->id
]);
55 if (!empty($status->studentavailability
) &&
56 time() > $attforsession->sessdate +
($status->studentavailability
* 60)) {
57 unset($statuses[$status->id
]);
58 $disabledduetotime = true
;
62 $mform->addElement('hidden', 'sessid', null
);
63 $mform->setType('sessid', PARAM_INT
);
64 $mform->setConstant('sessid', $attforsession->id
);
66 $mform->addElement('hidden', 'sesskey', null
);
67 $mform->setType('sesskey', PARAM_INT
);
68 $mform->setConstant('sesskey', sesskey());
70 // Set a title as the date and time of the session.
71 $sesstiontitle = userdate($attforsession->sessdate
, get_string('strftimedate')).' '
72 .attendance_strftimehm($attforsession->sessdate
);
74 $mform->addElement('header', 'session', $sesstiontitle);
76 // If a session description is set display it.
77 if (!empty($attforsession->description
)) {
78 $mform->addElement('html', $attforsession->description
);
80 if (!empty($attforsession->studentpassword
)) {
81 $mform->addElement('text', 'studentpassword', get_string('password', 'attendance'));
82 $mform->setType('studentpassword', PARAM_TEXT
);
83 $mform->addRule('studentpassword', get_string('passwordrequired', 'attendance'), 'required');
85 if (!$attforsession->autoassignstatus
) {
87 // Create radio buttons for setting the attendance status.
88 $radioarray = array();
89 foreach ($statuses as $status) {
90 $name = html_writer
::span($status->description
, 'statusdesc');
91 $radioarray[] =& $mform->createElement('radio', 'status', '', $name, $status->id
, array());
93 if ($disabledduetotime) {
94 $warning = html_writer
::span(get_string('somedisabledstatus', 'attendance'), 'somedisabledstatus');
95 $radioarray[] =& $mform->createElement('static', '', '', $warning);
97 // Add the radio buttons as a control with the user's name in front.
98 $radiogroup = $mform->addGroup($radioarray, 'statusarray', $USER->firstname
.' '.$USER->lastname
.':', array(''), false
);
99 $radiogroup->setAttributes(array('class' => 'statusgroup'));
100 $mform->addRule('statusarray', get_string('attendancenotset', 'attendance'), 'required', '', 'client', false
, false
);
102 $this->add_action_buttons();
109 * @param array $files
112 public function validation($data, $files) {
114 if (!($this->_customdata
['session']->autoassignstatus
)) {
115 // Check if this status is allowed to be set.
116 if (empty($data['status'])) {
117 $errors['statusarray'] = get_string('invalidstatus', 'attendance');