You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
4.5 KiB
116 lines
4.5 KiB
<?php
|
|
// This file is part of Moodle - http://moodle.org/
|
|
//
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
/**
|
|
* Update form
|
|
*
|
|
* @package mod_attendance
|
|
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
require_once($CFG->libdir.'/formslib.php');
|
|
|
|
/**
|
|
* class for displaying update form.
|
|
*
|
|
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
class mod_attendance_update_form extends moodleform {
|
|
|
|
/**
|
|
* Called to define this moodle form
|
|
*
|
|
* @return void
|
|
*/
|
|
public function definition() {
|
|
|
|
global $DB;
|
|
$mform =& $this->_form;
|
|
|
|
$modcontext = $this->_customdata['modcontext'];
|
|
$sessionid = $this->_customdata['sessionid'];
|
|
|
|
if (!$sess = $DB->get_record('attendance_sessions', array('id' => $sessionid) )) {
|
|
error('No such session in this course');
|
|
}
|
|
$defopts = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext);
|
|
$sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attendance', 'session', $sess->id);
|
|
|
|
$starttime = $sess->sessdate - usergetmidnight($sess->sessdate);
|
|
$starthour = floor($starttime / HOURSECS);
|
|
$startminute = floor(($starttime - $starthour * HOURSECS) / MINSECS);
|
|
|
|
$enddate = $sess->sessdate + $sess->duration;
|
|
$endtime = $enddate - usergetmidnight($enddate);
|
|
$endhour = floor($endtime / HOURSECS);
|
|
$endminute = floor(($endtime - $endhour * HOURSECS) / MINSECS);
|
|
|
|
$data = array('sessiondate' => $sess->sessdate,
|
|
'sestime' => array('starthour' => $starthour, 'startminute' => $startminute,
|
|
'endhour' => $endhour, 'endminute' => $endminute),
|
|
'sdescription' => $sess->description_editor);
|
|
|
|
$mform->addElement('header', 'general', get_string('changesession', 'attendance'));
|
|
|
|
if ($sess->groupid == 0) {
|
|
$strtype = get_string('commonsession', 'attendance');
|
|
} else {
|
|
$groupname = $DB->get_field('groups', 'name', array('id' => $sess->groupid));
|
|
$strtype = get_string('group') . ': ' . $groupname;
|
|
}
|
|
$mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attendance'), $strtype);
|
|
|
|
$olddate = construct_session_full_date_time($sess->sessdate, $sess->duration);
|
|
$mform->addElement('static', 'olddate', get_string('olddate', 'attendance'), $olddate);
|
|
|
|
attendance_form_sessiondate_selector($mform);
|
|
|
|
// Show which status set is in use.
|
|
$maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id);
|
|
if ($maxstatusset > 0) {
|
|
$mform->addElement('static', 'statusset', get_string('usestatusset', 'mod_attendance'),
|
|
attendance_get_setname($this->_customdata['att']->id, $sess->statusset));
|
|
}
|
|
|
|
$mform->addElement('editor', 'sdescription', get_string('description', 'attendance'),
|
|
array('rows' => 1, 'columns' => 80), $defopts);
|
|
$mform->setType('sdescription', PARAM_RAW);
|
|
|
|
$mform->setDefaults($data);
|
|
|
|
$this->add_action_buttons(true);
|
|
}
|
|
|
|
/**
|
|
* Perform minimal validation on the settings form
|
|
* @param array $data
|
|
* @param array $files
|
|
*/
|
|
public function validation($data, $files) {
|
|
$errors = parent::validation($data, $files);
|
|
|
|
$sesstarttime = $data['sestime']['starthour'] * HOURSECS + $data['sestime']['startminute'] * MINSECS;
|
|
$sesendtime = $data['sestime']['endhour'] * HOURSECS + $data['sestime']['endminute'] * MINSECS;
|
|
if ($sesendtime < $sesstarttime) {
|
|
$errors['sestime'] = get_string('invalidsessionendtime', 'attendance');
|
|
}
|
|
|
|
return $errors;
|
|
}
|
|
}
|
|
|