Browse Source

Changing the add and update session interfaces

MOODLE_29_STABLE
antonio.c.mariani 9 years ago
committed by Dan Marsden
parent
commit
80dbeb3757
  1. 82
      add_form.php
  2. 44
      lang/en/attendance.php
  3. 12
      locallib.php
  4. 11
      renderables.php
  5. 9
      renderer.php
  6. 25
      sessions.php
  7. 69
      update_form.php

82
add_form.php

@ -102,14 +102,7 @@ class mod_attendance_add_form extends moodleform {
} }
} }
$mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions', 'attendance')); $mform->addElement('date_selector', 'sessiondate', get_string('sessiondate', '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++) { for ($i = 0; $i <= 23; $i++) {
$hours[$i] = sprintf("%02d", $i); $hours[$i] = sprintf("%02d", $i);
@ -117,13 +110,43 @@ class mod_attendance_add_form extends moodleform {
for ($i = 0; $i < 60; $i += 5) { for ($i = 0; $i < 60; $i += 5) {
$minutes[$i] = sprintf("%02d", $i); $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')); $sesendtime = array();
$mform->disabledIf('sessionenddate', 'addmultiply', 'notchecked'); $sesendtime[] =& $mform->createElement('static', 'from', '', get_string('from', 'attendance'));
$sesendtime[] =& $mform->createElement('select', 'starthour', get_string('hour', 'form'), $hours, false, true);
$sesendtime[] =& $mform->createElement('select', 'startminute', get_string('minute', 'form'), $minutes, false, true);
$sesendtime[] =& $mform->createElement('static', 'to', '', get_string('to', 'attendance'));
$sesendtime[] =& $mform->createElement('select', 'endhour', get_string('hour', 'form'), $hours, false, true);
$sesendtime[] =& $mform->createElement('select', 'endminute', get_string('minute', 'form'), $minutes, false, true);
$mform->addGroup($sesendtime, 'sestime', get_string('time', 'attendance'), array(' '), true);
// 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);
}
// Students can mark own attendance.
$mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance'));
$mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance');
$mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), array('rows' => 1, 'columns' => 80),
array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext));
$mform->setType('sdescription', PARAM_RAW);
// For multiple sessions.
$mform->addElement('header', 'headeraddmultiplesessions', get_string('addmultiplesessions', 'attendance'));
$mform->addElement('checkbox', 'addmultiply', '', get_string('repeatasfollows', 'attendance'));
$mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attendance');
$sdays = array(); $sdays = array();
if ($CFG->calendar_startwday === '0') { // Week start from sunday. if ($CFG->calendar_startwday === '0') { // Week start from sunday.
@ -138,7 +161,7 @@ class mod_attendance_add_form extends moodleform {
if ($CFG->calendar_startwday !== '0') { // Week start from sunday. if ($CFG->calendar_startwday !== '0') { // Week start from sunday.
$sdays[] =& $mform->createElement('checkbox', 'Sun', '', get_string('sunday', 'calendar')); $sdays[] =& $mform->createElement('checkbox', 'Sun', '', get_string('sunday', 'calendar'));
} }
$mform->addGroup($sdays, 'sdays', get_string('sessiondays', 'attendance'), array('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'), true); $mform->addGroup($sdays, 'sdays', get_string('repeaton', 'attendance'), array('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'), true);
$mform->disabledIf('sdays', 'addmultiply', 'notchecked'); $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, $period = array(1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
@ -146,25 +169,11 @@ class mod_attendance_add_form extends moodleform {
$periodgroup = array(); $periodgroup = array();
$periodgroup[] =& $mform->createElement('select', 'period', '', $period, false, true); $periodgroup[] =& $mform->createElement('select', 'period', '', $period, false, true);
$periodgroup[] =& $mform->createElement('static', 'perioddesc', '', get_string('week', 'attendance')); $periodgroup[] =& $mform->createElement('static', 'perioddesc', '', get_string('week', 'attendance'));
$mform->addGroup($periodgroup, 'periodgroup', get_string('period', 'attendance'), array(' '), false); $mform->addGroup($periodgroup, 'periodgroup', get_string('repeatevery', 'attendance'), array(' '), false);
$mform->disabledIf('periodgroup', 'addmultiply', 'notchecked'); $mform->disabledIf('periodgroup', 'addmultiply', 'notchecked');
// Select which status set to use. $mform->addElement('date_selector', 'sessionenddate', get_string('repeatuntil', 'attendance'));
$maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id); $mform->disabledIf('sessionenddate', 'addmultiply', 'notchecked');
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->addElement('hidden', 'coursestartdate', $course->startdate);
$mform->setType('coursestartdate', PARAM_INT); $mform->setType('coursestartdate', PARAM_INT);
@ -172,8 +181,7 @@ class mod_attendance_add_form extends moodleform {
$mform->addElement('hidden', 'previoussessiondate', 0); $mform->addElement('hidden', 'previoussessiondate', 0);
$mform->setType('previoussessiondate', PARAM_INT); $mform->setType('previoussessiondate', PARAM_INT);
$submitstring = get_string('addsession', 'attendance'); $this->add_action_buttons(true, get_string('add', 'attendance'));
$this->add_action_buttons(false, $submitstring);
} }
/** /**
@ -184,6 +192,12 @@ class mod_attendance_add_form extends moodleform {
public function validation($data, $files) { public function validation($data, $files) {
$errors = parent::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');
}
if (!empty($data['addmultiply']) && $data['sessiondate'] != 0 && $data['sessionenddate'] != 0 && if (!empty($data['addmultiply']) && $data['sessiondate'] != 0 && $data['sessionenddate'] != 0 &&
$data['sessionenddate'] < $data['sessiondate']) { $data['sessionenddate'] < $data['sessiondate']) {
$errors['sessionenddate'] = get_string('invalidsessionenddate', 'attendance'); $errors['sessionenddate'] = get_string('invalidsessionenddate', 'attendance');

44
lang/en/attendance.php

@ -34,7 +34,7 @@ $string['Pacronym'] = 'P';
$string['Pfull'] = 'Present'; $string['Pfull'] = 'Present';
$string['acronym'] = 'Acronym'; $string['acronym'] = 'Acronym';
$string['add'] = 'Add'; $string['add'] = 'Add';
$string['addmultiplesessions'] = 'Add multiple sessions'; $string['addmultiplesessions'] = 'Multiple sessions';
$string['addsession'] = 'Add session'; $string['addsession'] = 'Add session';
$string['allcourses'] = 'All courses'; $string['allcourses'] = 'All courses';
$string['all'] = 'All'; $string['all'] = 'All';
@ -70,21 +70,21 @@ $string['changesession'] = 'Change session';
$string['checkweekdays'] = 'Select weekdays that fall within your selected session date range.'; $string['checkweekdays'] = 'Select weekdays that fall within your selected session date range.';
$string['column'] = 'column'; $string['column'] = 'column';
$string['columns'] = 'columns'; $string['columns'] = 'columns';
$string['commonsession'] = 'Common'; $string['commonsession'] = 'All students';
$string['commonsessions'] = 'Common'; $string['commonsessions'] = 'All students';
$string['confirmdeleteuser'] = 'Are you sure you want to delete user \'{$a->fullname}\' ({$a->email})?<br/>All of their attendance records will be permanently deleted.'; $string['confirmdeleteuser'] = 'Are you sure you want to delete user \'{$a->fullname}\' ({$a->email})?<br/>All of their attendance records will be permanently deleted.';
$string['countofselected'] = 'Count of selected'; $string['countofselected'] = 'Count of selected';
$string['copyfrom'] = 'Copy attendance data from'; $string['copyfrom'] = 'Copy attendance data from';
$string['createmultiplesessions'] = 'Create multiple sessions'; $string['createmultiplesessions'] = 'Create multiple sessions';
$string['createmultiplesessions_help'] = 'This function allows you to create multiple sessions in one simple step. $string['createmultiplesessions_help'] = 'This function allows you to create multiple sessions in one simple step.
The sessions begin on the date of the base session and continue until the \'repeat until\' date.
* <strong>Session Start Date</strong>: Select the start date of your course (the first day of class) * <strong>Repeat on</strong>: Select the days of the week when your class will meet (for example, Monday/Wednesday/Friday).
* <strong>Session End Date</strong>: Select the last day of class (the last day you want to take attendance). * <strong>Repeat every</strong>: This allows for a frequency setting. If your class will meet every week, select 1; if it will meet every other week, select 2; every 3rd week, select 3, etc.
* <strong>Session Days</strong>: Select the days of the week when your class will meet (for example, Monday/Wednesday/Friday). * <strong>Repeat until</strong>: Select the last day of class (the last day you want to take attendance).
* <strong>Frequency</strong>: This allows for a frequency setting. If your class will meet every week, select 1; if it will meet every other week, select 2; every 3rd week, select 3, etc.
'; ';
$string['createonesession'] = 'Create one session for the course'; $string['createonesession'] = 'Create one session for the course';
$string['days'] = 'Day'; $string['days'] = 'Days';
$string['defaults'] = 'Defaults'; $string['defaults'] = 'Defaults';
$string['defaultdisplaymode'] = 'Default display mode'; $string['defaultdisplaymode'] = 'Default display mode';
$string['delete'] = 'Delete'; $string['delete'] = 'Delete';
@ -120,7 +120,7 @@ $string['gradebookexplanation_help'] = 'The Attendance module displays your curr
For example, if you have earned 8 of 10 points to date (80% attendance) and attendance for the entire course is worth 50 points, the Attendance module will display 8/10 and the gradebook will display 40/50. You have not yet earned 40 points but 40 is the equivalent point value to your current attendance percentage of 80%. The point value you have earned in the Attendance module can never decrease, as it is based only on attendance to date; however, the attendance point value shown in the gradebook may increase or decrease depending on your future attendance, as it is based on attendance for the entire course.'; For example, if you have earned 8 of 10 points to date (80% attendance) and attendance for the entire course is worth 50 points, the Attendance module will display 8/10 and the gradebook will display 40/50. You have not yet earned 40 points but 40 is the equivalent point value to your current attendance percentage of 80%. The point value you have earned in the Attendance module can never decrease, as it is based only on attendance to date; however, the attendance point value shown in the gradebook may increase or decrease depending on your future attendance, as it is based on attendance for the entire course.';
$string['gridcolumns'] = 'Grid columns'; $string['gridcolumns'] = 'Grid columns';
$string['groupsession'] = 'Group'; $string['groupsession'] = 'Group of students';
$string['hiddensessions'] = 'Hidden sessions'; $string['hiddensessions'] = 'Hidden sessions';
$string['hiddensessions_help'] = 'Sessions are hidden if they are scheduled before the course start date. $string['hiddensessions_help'] = 'Sessions are hidden if they are scheduled before the course start date.
@ -130,7 +130,7 @@ $string['includeall'] = 'Select all sessions';
$string['includenottaken'] = 'Include not taken sessions'; $string['includenottaken'] = 'Include not taken sessions';
$string['includeremarks'] = 'Include remarks'; $string['includeremarks'] = 'Include remarks';
$string['indetail'] = 'In detail...'; $string['indetail'] = 'In detail...';
$string['invalidsessionenddate'] = 'The session end date can not be earlier than the session start date'; $string['invalidsessionenddate'] = 'This date can not be earlier than the session date';
$string['invalidaction'] = 'You must select an action'; $string['invalidaction'] = 'You must select an action';
$string['jumpto'] = 'Jump to'; $string['jumpto'] = 'Jump to';
$string['mergeuser'] = 'Merge user'; $string['mergeuser'] = 'Merge user';
@ -165,7 +165,6 @@ $string['olddate'] = 'Old date';
$string['onlyselectedusers'] = 'Export specific users'; $string['onlyselectedusers'] = 'Export specific users';
$string['participant'] = 'Participant'; $string['participant'] = 'Participant';
$string['percentage'] = 'Percentage'; $string['percentage'] = 'Percentage';
$string['period'] = 'Frequency';
$string['pluginname'] = 'Attendance'; $string['pluginname'] = 'Attendance';
$string['pluginadministration'] = 'Attendance administration'; $string['pluginadministration'] = 'Attendance administration';
$string['remark'] = 'Remark for: {$a}'; $string['remark'] = 'Remark for: {$a}';
@ -217,10 +216,9 @@ $string['session'] = 'Session';
$string['session_help'] = 'Session'; $string['session_help'] = 'Session';
$string['sessionadded'] = 'Session successfully added'; $string['sessionadded'] = 'Session successfully added';
$string['sessionalreadyexists'] = 'Session already exists for this date'; $string['sessionalreadyexists'] = 'Session already exists for this date';
$string['sessiondate'] = 'Session Date'; $string['sessiondate'] = 'Date';
$string['sessiondays'] = 'Session Days'; $string['sessiondays'] = 'Session Days';
$string['sessiondeleted'] = 'Session successfully deleted'; $string['sessiondeleted'] = 'Session successfully deleted';
$string['sessionenddate'] = 'Session end date';
$string['sessionexist'] = 'Session not added (already exists)!'; $string['sessionexist'] = 'Session not added (already exists)!';
$string['sessions'] = 'Sessions'; $string['sessions'] = 'Sessions';
$string['sessionscompleted'] = 'Sessions completed'; $string['sessionscompleted'] = 'Sessions completed';
@ -229,12 +227,12 @@ $string['sessiongenerated'] = 'One session was successfully generated';
$string['sessionsgenerated'] = '{$a} sessions were successfully generated'; $string['sessionsgenerated'] = '{$a} sessions were successfully generated';
$string['sessionsnotfound'] = 'There is no sessions in the selected timespan'; $string['sessionsnotfound'] = 'There is no sessions in the selected timespan';
$string['sessionstartdate'] = 'Session start date'; $string['sessionstartdate'] = 'Session start date';
$string['sessiontype'] = 'Session type'; $string['sessiontype'] = 'Type';
$string['sessiontype_help'] = 'There are two types of sessions: common and groups. Ability to add different types depends on activity group mode. $string['sessiontype_help'] = 'You can add sessions for all students or for a group of students. Ability to add different types depends on activity group mode.
* In group mode "No groups" you can add only common sessions. * In group mode "No groups" you can add only sessions for all students.
* In group mode "Visible groups" you can add common and group sessions. * In group mode "Separate groups" you can add only sessions for a group of students.
* In group mode "Separate groups" you can add only group sessions. * In group mode "Visible groups" you can add both types of sessions.
'; ';
$string['sessiontypeshort'] = 'Type'; $string['sessiontypeshort'] = 'Type';
$string['sessionupdated'] = 'Session successfully updated'; $string['sessionupdated'] = 'Session successfully updated';
@ -273,7 +271,7 @@ $string['tempusermerge'] = 'Merge temporary user';
$string['tuseremail'] = 'Email'; $string['tuseremail'] = 'Email';
$string['tusername'] = 'Full name'; $string['tusername'] = 'Full name';
$string['update'] = 'Update'; $string['update'] = 'Update';
$string['usestatusset'] = 'Use status set'; $string['usestatusset'] = 'Status set';
$string['userexists'] = 'There is already a real user with this email address'; $string['userexists'] = 'There is already a real user with this email address';
$string['users'] = 'Users to export'; $string['users'] = 'Users to export';
$string['variable'] = 'variable'; $string['variable'] = 'variable';
@ -313,3 +311,11 @@ $string['hiddensessionsdeleted'] = 'All hidden sessions were delete';
$string['timeahead'] = 'Multiple sessions that exceed one year cannot be created, please adjust the start and end dates.'; $string['timeahead'] = 'Multiple sessions that exceed one year cannot be created, please adjust the start and end dates.';
$string['priorto'] = 'The session date is prior to the course start date ({$a}) so that the new sessions scheduled before this date will be hidden (not accessible). You can change the course start date at any time (see course settings) in order to have access to earlier sessions.<br><br>Please change the session date or just click the "Add session" button again to confirm?'; $string['priorto'] = 'The session date is prior to the course start date ({$a}) so that the new sessions scheduled before this date will be hidden (not accessible). You can change the course start date at any time (see course settings) in order to have access to earlier sessions.<br><br>Please change the session date or just click the "Add session" button again to confirm?';
$string['noattendanceusers'] = 'It is not possible to export any data as there are no students enrolled in the course.'; $string['noattendanceusers'] = 'It is not possible to export any data as there are no students enrolled in the course.';
$string['time'] = 'Time';
$string['from'] = 'from:';
$string['to'] = 'to:';
$string['repeatasfollows'] = 'Repeat the session above as follows';
$string['repeatevery'] = 'Repeat every';
$string['repeatuntil'] = 'Repeat until';
$string['repeaton'] = 'Repeat on';
$string['invalidsessionendtime'] = 'The end time must be greater than start time';

12
locallib.php

@ -38,7 +38,6 @@ define('ATT_VIEW_NOTPRESENT', 6);
define('ATT_SORT_LASTNAME', 1); define('ATT_SORT_LASTNAME', 1);
define('ATT_SORT_FIRSTNAME', 2); define('ATT_SORT_FIRSTNAME', 2);
class att_page_with_filter_controls { class att_page_with_filter_controls {
const SELECTOR_NONE = 1; const SELECTOR_NONE = 1;
const SELECTOR_GROUP = 2; const SELECTOR_GROUP = 2;
@ -208,7 +207,7 @@ class att_page_with_filter_controls {
// Show Common groups always. // Show Common groups always.
$this->sessgroupslist[self::SESSTYPE_COMMON] = get_string('commonsessions', 'attendance'); $this->sessgroupslist[self::SESSTYPE_COMMON] = get_string('commonsessions', 'attendance');
foreach ($allowedgroups as $group) { foreach ($allowedgroups as $group) {
$this->sessgroupslist[$group->id] = format_string($group->name); $this->sessgroupslist[$group->id] = get_string('group') . ': ' . format_string($group->name);
} }
} }
} }
@ -757,13 +756,18 @@ class attendance {
print_error('No such session in this course'); print_error('No such session in this course');
} }
$sess->sessdate = $formdata->sessiondate; $sesstarttime = $formdata->sestime['starthour']*HOURSECS + $formdata->sestime['startminute'] * MINSECS;
$sess->duration = $formdata->durtime['hours'] * HOURSECS + $formdata->durtime['minutes'] * MINSECS; $sesendtime = $formdata->sestime['endhour']*HOURSECS + $formdata->sestime['endminute'] * MINSECS;
$sess->sessdate = $formdata->sessiondate + $sesstarttime;
$sess->duration = $sesendtime - $sesstarttime;
$description = file_save_draft_area_files($formdata->sdescription['itemid'], $description = file_save_draft_area_files($formdata->sdescription['itemid'],
$this->context->id, 'mod_attendance', 'session', $sessionid, $this->context->id, 'mod_attendance', 'session', $sessionid,
array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $formdata->sdescription['text']); array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $formdata->sdescription['text']);
$sess->description = $description; $sess->description = $description;
$sess->descriptionformat = $formdata->sdescription['format']; $sess->descriptionformat = $formdata->sdescription['format'];
$sess->timemodified = time(); $sess->timemodified = time();
$DB->update_record('attendance_sessions', $sess); $DB->update_record('attendance_sessions', $sess);

11
renderables.php

@ -43,6 +43,7 @@ class attendance_tabs implements renderable {
const TAB_EXPORT = 4; const TAB_EXPORT = 4;
const TAB_PREFERENCES = 5; const TAB_PREFERENCES = 5;
const TAB_TEMPORARYUSERS = 6; // Tab for managing temporary users. const TAB_TEMPORARYUSERS = 6; // Tab for managing temporary users.
const TAB_UPDATE = 7;
public $currenttab; public $currenttab;
@ -80,7 +81,7 @@ class attendance_tabs implements renderable {
if (has_capability('mod/attendance:manageattendances', $context)) { if (has_capability('mod/attendance:manageattendances', $context)) {
$toprow[] = new tabobject(self::TAB_ADD, $toprow[] = new tabobject(self::TAB_ADD,
$this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)), $this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)),
get_string('add', 'attendance')); get_string('addsession', 'attendance'));
} }
if (has_capability('mod/attendance:viewreports', $context)) { if (has_capability('mod/attendance:viewreports', $context)) {
$toprow[] = new tabobject(self::TAB_REPORT, $this->att->url_report()->out(), $toprow[] = new tabobject(self::TAB_REPORT, $this->att->url_report()->out(),
@ -100,6 +101,11 @@ class attendance_tabs implements renderable {
$toprow[] = new tabobject(self::TAB_TEMPORARYUSERS, $this->att->url_managetemp()->out(), $toprow[] = new tabobject(self::TAB_TEMPORARYUSERS, $this->att->url_managetemp()->out(),
get_string('tempusers', 'attendance')); get_string('tempusers', 'attendance'));
} }
if ($this->currenttab == self::TAB_UPDATE && has_capability('mod/attendance:manageattendances', $context)) {
$toprow[] = new tabobject(self::TAB_UPDATE,
$this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_UPDATE)),
get_string('changesession', 'attendance'));
}
return array($toprow); return array($toprow);
} }
@ -138,7 +144,6 @@ class attendance_filter_controls implements renderable {
$date = usergetdate($att->pageparams->curdate); $date = usergetdate($att->pageparams->curdate);
$mday = $date['mday']; $mday = $date['mday'];
$wday = $date['wday'];
$mon = $date['mon']; $mon = $date['mon'];
$year = $date['year']; $year = $date['year'];
@ -355,7 +360,7 @@ class attendance_user_data implements renderable {
private $urlparams; private $urlparams;
public function __construct(attendance $att, $userid) { public function __construct(attendance $att, $userid) {
global $CFG, $USER; global $CFG;
$this->user = $att->get_user($userid); $this->user = $att->get_user($userid);

9
renderer.php

@ -234,7 +234,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
$dta = $this->construct_date_time_actions($sessdata, $sess); $dta = $this->construct_date_time_actions($sessdata, $sess);
$table->data[$sess->id][] = $i; $table->data[$sess->id][] = $i;
$table->data[$sess->id][] = $sess->groupid ? $sessdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance'); $table->data[$sess->id][] = $sess->groupid ? get_string('group') . ': ' . $sessdata->groups[$sess->groupid]->name :
get_string('commonsession', 'attendance');
$table->data[$sess->id][] = $dta['date']; $table->data[$sess->id][] = $dta['date'];
$table->data[$sess->id][] = $dta['time']; $table->data[$sess->id][] = $dta['time'];
$table->data[$sess->id][] = $sess->description; $table->data[$sess->id][] = $sess->description;
@ -769,7 +770,9 @@ class mod_attendance_renderer extends plugin_renderer_base {
$row = new html_table_row(); $row = new html_table_row();
$row->cells[] = $i; $row->cells[] = $i;
$row->cells[] = html_writer::tag('nobr', $sess->groupid ? $userdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance')); $sessiontypeshort = $sess->groupid ? get_string('group') . ': ' . $userdata->groups[$sess->groupid]->name :
get_string('commonsession', 'attendance');
$row->cells[] = html_writer::tag('nobr', $sessiontypeshort);
$row->cells[] = userdate($sess->sessdate, get_string('strftimedmyw', 'attendance')); $row->cells[] = userdate($sess->sessdate, get_string('strftimedmyw', 'attendance'));
$row->cells[] = $this->construct_time($sess->sessdate, $sess->duration); $row->cells[] = $this->construct_time($sess->sessdate, $sess->duration);
$row->cells[] = $sess->description; $row->cells[] = $sess->description;
@ -847,7 +850,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$sesstext = html_writer::link($reportdata->url_take($sess->id, $sess->groupid), $sesstext); $sesstext = html_writer::link($reportdata->url_take($sess->id, $sess->groupid), $sesstext);
} }
$sesstext .= html_writer::empty_tag('br'); $sesstext .= html_writer::empty_tag('br');
$sesstext .= $sess->groupid ? $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance'); $sesstext .= $sess->groupid ? get_string('group') . ': ' . $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance');
$table->head[] = $sesstext; $table->head[] = $sesstext;
$table->align[] = 'center'; $table->align[] = 'center';

25
sessions.php

@ -62,16 +62,22 @@ $PAGE->set_cacheable(true);
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance')); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance'));
$PAGE->navbar->add($att->name); $PAGE->navbar->add($att->name);
$currenttab = attendance_tabs::TAB_ADD;
$formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $context, 'att' => $att); $formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $context, 'att' => $att);
switch ($att->pageparams->action) { switch ($att->pageparams->action) {
case att_sessions_page_params::ACTION_ADD: case att_sessions_page_params::ACTION_ADD:
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_ADD)); $url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_ADD));
$mform = new mod_attendance_add_form($url, $formparams); $mform = new mod_attendance_add_form($url, $formparams);
if ($mform->is_cancelled()) {
redirect($att->url_manage());
}
if ($formdata = $mform->get_data()) { if ($formdata = $mform->get_data()) {
$sessions = construct_sessions_data_for_add($formdata); $sessions = construct_sessions_data_for_add($formdata);
$att->add_sessions($sessions); $att->add_sessions($sessions);
$message = count($sessions) == 1 ? get_string('sessiongenerated', 'attendance') : get_string('sessionsgenerated', 'attendance', count($sessions)); $message = count($sessions) == 1 ? get_string('sessiongenerated', 'attendance') :
get_string('sessionsgenerated', 'attendance', count($sessions));
mod_attendance_notifyqueue::notify_success($message); mod_attendance_notifyqueue::notify_success($message);
// Redirect to the sessions tab always showing all sessions. // Redirect to the sessions tab always showing all sessions.
$SESSION->attcurrentattview[$cm->course] = ATT_VIEW_ALL; $SESSION->attcurrentattview[$cm->course] = ATT_VIEW_ALL;
@ -95,6 +101,7 @@ switch ($att->pageparams->action) {
mod_attendance_notifyqueue::notify_success(get_string('sessionupdated', 'attendance')); mod_attendance_notifyqueue::notify_success(get_string('sessionupdated', 'attendance'));
redirect($att->url_manage()); redirect($att->url_manage());
} }
$currenttab = attendance_tabs::TAB_UPDATE;
break; break;
case att_sessions_page_params::ACTION_DELETE: case att_sessions_page_params::ACTION_DELETE:
$sessionid = required_param('sessionid', PARAM_INT); $sessionid = required_param('sessionid', PARAM_INT);
@ -208,7 +215,7 @@ switch ($att->pageparams->action) {
} }
$output = $PAGE->get_renderer('mod_attendance'); $output = $PAGE->get_renderer('mod_attendance');
$tabs = new attendance_tabs($att, attendance_tabs::TAB_ADD); $tabs = new attendance_tabs($att, $currenttab);
echo $output->header(); echo $output->header();
echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .format_string($course->fullname)); echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .format_string($course->fullname));
echo $output->render($tabs); echo $output->render($tabs);
@ -220,21 +227,21 @@ echo $OUTPUT->footer();
function construct_sessions_data_for_add($formdata) { function construct_sessions_data_for_add($formdata) {
global $CFG; global $CFG;
$duration = $formdata->durtime['hours'] * HOURSECS + $formdata->durtime['minutes'] * MINSECS; $sesstarttime = $formdata->sestime['starthour'] * HOURSECS + $formdata->sestime['startminute'] * MINSECS;
$sesendtime = $formdata->sestime['endhour'] * HOURSECS + $formdata->sestime['endminute'] * MINSECS;
$sessiondate = $formdata->sessiondate + $sesstarttime;
$duration = $sesendtime - $sesstarttime;
$now = time(); $now = time();
$sessions = array(); $sessions = array();
if (isset($formdata->addmultiply)) { if (isset($formdata->addmultiply)) {
$startdate = $formdata->sessiondate; $startdate = $sessiondate;
$starttime = $startdate - usergetmidnight($startdate);
$enddate = $formdata->sessionenddate + DAYSECS; // Because enddate in 0:0am. $enddate = $formdata->sessionenddate + DAYSECS; // Because enddate in 0:0am.
if ($enddate < $startdate) { if ($enddate < $startdate) {
return null; return null;
} }
$days = (int)ceil(($enddate - $startdate) / DAYSECS);
// Getting first day of week. // Getting first day of week.
$sdate = $startdate; $sdate = $startdate;
$dinfo = usergetdate($sdate); $dinfo = usergetdate($sdate);
@ -252,7 +259,7 @@ function construct_sessions_data_for_add($formdata) {
$dinfo = usergetdate($sdate); $dinfo = usergetdate($sdate);
if (isset($formdata->sdays) && array_key_exists($wdaydesc[$dinfo['wday']], $formdata->sdays)) { if (isset($formdata->sdays) && array_key_exists($wdaydesc[$dinfo['wday']], $formdata->sdays)) {
$sess = new stdClass(); $sess = new stdClass();
$sess->sessdate = usergetmidnight($sdate) + $starttime; $sess->sessdate = usergetmidnight($sdate) + $sesstarttime;
$sess->duration = $duration; $sess->duration = $duration;
$sess->descriptionitemid = $formdata->sdescription['itemid']; $sess->descriptionitemid = $formdata->sdescription['itemid'];
$sess->description = $formdata->sdescription['text']; $sess->description = $formdata->sdescription['text'];
@ -273,7 +280,7 @@ function construct_sessions_data_for_add($formdata) {
} }
} else { } else {
$sess = new stdClass(); $sess = new stdClass();
$sess->sessdate = $formdata->sessiondate; $sess->sessdate = $sessiondate;
$sess->duration = $duration; $sess->duration = $duration;
$sess->descriptionitemid = $formdata->sdescription['itemid']; $sess->descriptionitemid = $formdata->sdescription['itemid'];
$sess->description = $formdata->sdescription['text']; $sess->description = $formdata->sdescription['text'];

69
update_form.php

@ -43,27 +43,44 @@ class mod_attendance_update_form extends moodleform {
global $DB; global $DB;
$mform =& $this->_form; $mform =& $this->_form;
$course = $this->_customdata['course'];
$cm = $this->_customdata['cm'];
$modcontext = $this->_customdata['modcontext']; $modcontext = $this->_customdata['modcontext'];
$sessionid = $this->_customdata['sessionid']; $sessionid = $this->_customdata['sessionid'];
if (!$sess = $DB->get_record('attendance_sessions', array('id' => $sessionid) )) { if (!$sess = $DB->get_record('attendance_sessions', array('id' => $sessionid) )) {
error('No such session in this course'); 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); $defopts = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext);
$sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attendance', 'session', $sess->id); $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);
$sesendtime = $sess->sessdate + $sess->duration;
$data = array('sessiondate' => $sess->sessdate, $data = array('sessiondate' => $sess->sessdate,
'durtime' => array('hours' => $dhours, 'minutes' => $dmins), 'sestime' => array('starthour' => $starthour, 'startminute' => $startminute,
'endhour' => $endhour, 'endminute' => $endminute),
'sdescription' => $sess->description_editor); 'sdescription' => $sess->description_editor);
$mform->addElement('header', 'general', get_string('changesession', 'attendance')); $mform->addElement('header', 'general', get_string('changesession', 'attendance'));
$mform->addElement('static', 'olddate', get_string('olddate', 'attendance'), if ($sess->groupid == 0) {
userdate($sess->sessdate, get_string('strftimedmyhm', 'attendance'))); $strtype = get_string('commonsession', 'attendance');
$mform->addElement('date_time_selector', 'sessiondate', get_string('newdate', '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);
$mform->addElement('date_selector', 'sessiondate', get_string('sessiondate', 'attendance'));
for ($i = 0; $i <= 23; $i++) { for ($i = 0; $i <= 23; $i++) {
$hours[$i] = sprintf("%02d", $i); $hours[$i] = sprintf("%02d", $i);
@ -71,9 +88,15 @@ class mod_attendance_update_form extends moodleform {
for ($i = 0; $i < 60; $i += 5) { for ($i = 0; $i < 60; $i += 5) {
$minutes[$i] = sprintf("%02d", $i); $minutes[$i] = sprintf("%02d", $i);
} }
$durselect[] =& $mform->createElement('select', 'hours', '', $hours);
$durselect[] =& $mform->createElement('select', 'minutes', '', $minutes, false, true); $sesendtime = array();
$mform->addGroup($durselect, 'durtime', get_string('duration', 'attendance'), array(' '), true); $sesendtime[] =& $mform->createElement('static', 'from', '', get_string('from', 'attendance'));
$sesendtime[] =& $mform->createElement('select', 'starthour', get_string('hour', 'form'), $hours, false, true);
$sesendtime[] =& $mform->createElement('select', 'startminute', get_string('minute', 'form'), $minutes, false, true);
$sesendtime[] =& $mform->createElement('static', 'to', '', get_string('to', 'attendance'));
$sesendtime[] =& $mform->createElement('select', 'endhour', get_string('hour', 'form'), $hours, false, true);
$sesendtime[] =& $mform->createElement('select', 'endminute', get_string('minute', 'form'), $minutes, false, true);
$mform->addGroup($sesendtime, 'sestime', get_string('time', 'attendance'), array(' '), true);
// Show which status set is in use. // Show which status set is in use.
$maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id); $maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id);
@ -81,12 +104,30 @@ class mod_attendance_update_form extends moodleform {
$mform->addElement('static', 'statusset', get_string('usestatusset', 'mod_attendance'), $mform->addElement('static', 'statusset', get_string('usestatusset', 'mod_attendance'),
att_get_setname($this->_customdata['att']->id, $sess->statusset)); att_get_setname($this->_customdata['att']->id, $sess->statusset));
} }
$mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), null, $defopts);
$mform->addElement('editor', 'sdescription', get_string('description', 'attendance'),
array('rows' => 1, 'columns' => 80), $defopts);
$mform->setType('sdescription', PARAM_RAW); $mform->setType('sdescription', PARAM_RAW);
$mform->setDefaults($data); $mform->setDefaults($data);
$submitstring = get_string('update', 'attendance'); $this->add_action_buttons(true);
$this->add_action_buttons(true, $submitstring); }
/**
* 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;
} }
} }

Loading…
Cancel
Save