/** * Called to define this moodle form * * @return void */ public function definition() { global $DB; $mform =& $this->_form; $course = $this->_customdata['course']; $cm = $this->_customdata['cm']; $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'); } $dhours = floor($sess->duration / HOURSECS); $dmins = floor(($sess->duration - $dhours * HOURSECS) / MINSECS); $defopts = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext); $sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attendance', 'session', $sess->id); $data = array('sessiondate' => $sess->sessdate, 'durtime' => array('hours' => $dhours, 'minutes' => $dmins), 'sdescription' => $sess->description_editor); $mform->addElement('header', 'general', get_string('changesession', 'attendance')); $mform->addElement('static', 'olddate', get_string('olddate', 'attendance'), userdate($sess->sessdate, get_string('strftimedmyhm', 'attendance'))); $mform->addElement('date_time_selector', 'sessiondate', get_string('newdate', 'attendance')); for ($i = 0; $i <= 23; $i++) { $hours[$i] = sprintf("%02d", $i); } for ($i = 0; $i < 60; $i += 5) { $minutes[$i] = sprintf("%02d", $i); } $durselect[] =& $mform->createElement('select', 'hours', '', $hours); $durselect[] =& $mform->createElement('select', 'minutes', '', $minutes, false, true); $mform->addGroup($durselect, 'durtime', get_string('duration', 'attendance'), array(' '), true); // 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'), att_get_setname($this->_customdata['att']->id, $sess->statusset)); } $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), null, $defopts); $mform->setType('sdescription', PARAM_RAW); $mform->setDefaults($data); $submit_string = get_string('update', 'attendance'); $this->add_action_buttons(true, $submit_string); }
public function get_status_name($statusset) { return att_get_setname($this->att->id, $statusset, true); }
/** * Called to define this moodle form * * @return void */ public function definition() { global $CFG, $USER; $mform =& $this->_form; $course = $this->_customdata['course']; $cm = $this->_customdata['cm']; $modcontext = $this->_customdata['modcontext']; $mform->addElement('header', 'general', get_string('addsession', 'attendance')); $groupmode = groups_get_activity_groupmode($cm); switch ($groupmode) { case NOGROUPS: $mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attendance'), get_string('commonsession', 'attendance')); $mform->addHelpButton('sessiontypedescription', 'sessiontype', 'attendance'); $mform->addElement('hidden', 'sessiontype', attendance::SESSION_COMMON); $mform->setType('sessiontype', PARAM_INT); break; case SEPARATEGROUPS: $mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attendance'), get_string('groupsession', 'attendance')); $mform->addHelpButton('sessiontypedescription', 'sessiontype', 'attendance'); $mform->addElement('hidden', 'sessiontype', attendance::SESSION_GROUP); $mform->setType('sessiontype', PARAM_INT); break; case VISIBLEGROUPS: $radio = array(); $radio[] =& $mform->createElement('radio', 'sessiontype', '', get_string('commonsession', 'attendance'), attendance::SESSION_COMMON); $radio[] =& $mform->createElement('radio', 'sessiontype', '', get_string('groupsession', 'attendance'), attendance::SESSION_GROUP); $mform->addGroup($radio, 'sessiontype', get_string('sessiontype', 'attendance'), ' ', false); $mform->setType('sessiontype', PARAM_INT); $mform->addHelpButton('sessiontype', 'sessiontype', 'attendance'); $mform->setDefault('sessiontype', attendance::SESSION_COMMON); break; } if ($groupmode == SEPARATEGROUPS or $groupmode == VISIBLEGROUPS) { if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $modcontext)) { $groups = groups_get_all_groups($course->id, $USER->id, $cm->groupingid); } else { $groups = groups_get_all_groups($course->id, 0, $cm->groupingid); } if ($groups) { $selectgroups = array(); foreach ($groups as $group) { $selectgroups[$group->id] = $group->name; } $select =& $mform->addElement('select', 'groups', get_string('groups', 'group'), $selectgroups); $select->setMultiple(true); $mform->disabledIf('groups', 'sessiontype', 'neq', attendance::SESSION_GROUP); } else { if ($groupmode == VISIBLEGROUPS) { $mform->updateElementAttr($radio, array('disabled' => 'disabled')); } $mform->addElement('static', 'groups', get_string('groups', 'group'), get_string('nogroups', 'attendance')); if ($groupmode == SEPARATEGROUPS) { return; } } } $mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions', 'attendance')); $mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attendance'); // Students can mark own attendance. $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance')); $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance'); $mform->addElement('date_time_selector', 'sessiondate', get_string('sessiondate', 'attendance')); for ($i = 0; $i <= 23; $i++) { $hours[$i] = sprintf("%02d", $i); } for ($i = 0; $i < 60; $i += 5) { $minutes[$i] = sprintf("%02d", $i); } $durtime = array(); $durtime[] =& $mform->createElement('select', 'hours', get_string('hour', 'form'), $hours, false, true); $durtime[] =& $mform->createElement('select', 'minutes', get_string('minute', 'form'), $minutes, false, true); $mform->addGroup($durtime, 'durtime', get_string('duration', 'attendance'), array(' '), true); $mform->addElement('date_selector', 'sessionenddate', get_string('sessionenddate', 'attendance')); $mform->disabledIf('sessionenddate', 'addmultiply', 'notchecked'); $sdays = array(); if ($CFG->calendar_startwday === '0') { // Week start from sunday. $sdays[] =& $mform->createElement('checkbox', 'Sun', '', get_string('sunday', 'calendar')); } $sdays[] =& $mform->createElement('checkbox', 'Mon', '', get_string('monday', 'calendar')); $sdays[] =& $mform->createElement('checkbox', 'Tue', '', get_string('tuesday', 'calendar')); $sdays[] =& $mform->createElement('checkbox', 'Wed', '', get_string('wednesday', 'calendar')); $sdays[] =& $mform->createElement('checkbox', 'Thu', '', get_string('thursday', 'calendar')); $sdays[] =& $mform->createElement('checkbox', 'Fri', '', get_string('friday', 'calendar')); $sdays[] =& $mform->createElement('checkbox', 'Sat', '', get_string('saturday', 'calendar')); if ($CFG->calendar_startwday !== '0') { // Week start from sunday. $sdays[] =& $mform->createElement('checkbox', 'Sun', '', get_string('sunday', 'calendar')); } $mform->addGroup($sdays, 'sdays', get_string('sessiondays', 'attendance'), array(' '), true); $mform->disabledIf('sdays', 'addmultiply', 'notchecked'); $period = array(1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36); $periodgroup = array(); $periodgroup[] =& $mform->createElement('select', 'period', '', $period, false, true); $periodgroup[] =& $mform->createElement('static', 'perioddesc', '', get_string('week', 'attendance')); $mform->addGroup($periodgroup, 'periodgroup', get_string('period', 'attendance'), array(' '), false); $mform->disabledIf('periodgroup', 'addmultiply', 'notchecked'); // Select which status set to use. $maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id); if ($maxstatusset > 0) { $opts = array(); for ($i = 0; $i <= $maxstatusset; $i++) { $opts[$i] = att_get_setname($this->_customdata['att']->id, $i); } $mform->addElement('select', 'statusset', get_string('usestatusset', 'mod_attendance'), $opts); } else { $mform->addElement('hidden', 'statusset', 0); $mform->setType('statusset', PARAM_INT); } $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), null, array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext)); $mform->setType('sdescription', PARAM_RAW); $mform->addElement('hidden', 'coursestartdate', $course->startdate); $mform->setType('coursestartdate', PARAM_INT); $mform->addElement('hidden', 'previoussessiondate', 0); $mform->setType('previoussessiondate', PARAM_INT); $submitstring = get_string('addsession', 'attendance'); $this->add_action_buttons(false, $submitstring); }