Browse Source

More coding guideline fixes

MOODLE_29_STABLE
Dan Marsden 9 years ago
parent
commit
9d92017ff4
  1. 37
      add_form.php
  2. 100
      locallib.php
  3. 18
      renderables.php
  4. 102
      renderer.php
  5. 10
      renderhelpers.php
  6. 20
      sessions.php
  7. 6
      temp_form.php
  8. 6
      tempedit_form.php
  9. 16
      tempmerge_form.php
  10. 8
      tempusers.php
  11. 2
      tests/behat/attendance_taken_by_student.php
  12. 27
      tests/behat/behat_mod_attendance.php
  13. 12
      update_form.php

37
add_form.php

@ -65,7 +65,7 @@ class mod_attendance_add_form extends moodleform {
$mform->setType('sessiontype', PARAM_INT); $mform->setType('sessiontype', PARAM_INT);
break; break;
case VISIBLEGROUPS: case VISIBLEGROUPS:
$radio=array(); $radio = array();
$radio[] = &$mform->createElement('radio', 'sessiontype', '', $radio[] = &$mform->createElement('radio', 'sessiontype', '',
get_string('commonsession', 'attendance'), attendance::SESSION_COMMON); get_string('commonsession', 'attendance'), attendance::SESSION_COMMON);
$radio[] = &$mform->createElement('radio', 'sessiontype', '', $radio[] = &$mform->createElement('radio', 'sessiontype', '',
@ -92,7 +92,7 @@ class mod_attendance_add_form extends moodleform {
$mform->disabledIf('groups', 'sessiontype', 'neq', attendance::SESSION_GROUP); $mform->disabledIf('groups', 'sessiontype', 'neq', attendance::SESSION_GROUP);
} else { } else {
if ($groupmode == VISIBLEGROUPS) { if ($groupmode == VISIBLEGROUPS) {
$mform->updateElementAttr($radio, array('disabled'=>'disabled')); $mform->updateElementAttr($radio, array('disabled' => 'disabled'));
} }
$mform->addElement('static', 'groups', get_string('groups', 'group'), $mform->addElement('static', 'groups', get_string('groups', 'group'),
get_string('nogroups', 'attendance')); get_string('nogroups', 'attendance'));
@ -106,15 +106,15 @@ class mod_attendance_add_form extends moodleform {
$mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attendance'); $mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attendance');
// Students can mark own attendance. // Students can mark own attendance.
$mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark','attendance')); $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance'));
$mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance'); $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance');
$mform->addElement('date_time_selector', 'sessiondate', get_string('sessiondate', '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);
} }
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 = array();
@ -141,18 +141,19 @@ class mod_attendance_add_form extends moodleform {
$mform->addGroup($sdays, 'sdays', get_string('sessiondays', 'attendance'), array('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'), true); $mform->addGroup($sdays, 'sdays', get_string('sessiondays', '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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36); $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 = 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('period', 'attendance'), array(' '), false);
$mform->disabledIf('periodgroup', 'addmultiply', 'notchecked'); $mform->disabledIf('periodgroup', 'addmultiply', 'notchecked');
// Select which status set to use: // Select which status set to use.
$maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id); $maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id);
if ($maxstatusset > 0) { if ($maxstatusset > 0) {
$opts = array(); $opts = array();
for ($i=0; $i<=$maxstatusset; $i++) { for ($i = 0; $i <= $maxstatusset; $i++) {
$opts[$i] = att_get_setname($this->_customdata['att']->id, $i); $opts[$i] = att_get_setname($this->_customdata['att']->id, $i);
} }
$mform->addElement('select', 'statusset', get_string('usestatusset', 'mod_attendance'), $opts); $mform->addElement('select', 'statusset', get_string('usestatusset', 'mod_attendance'), $opts);
@ -161,8 +162,8 @@ class mod_attendance_add_form extends moodleform {
$mform->setType('statusset', PARAM_INT); $mform->setType('statusset', PARAM_INT);
} }
$mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), null,
null, array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext)); array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext));
$mform->setType('sdescription', PARAM_RAW); $mform->setType('sdescription', PARAM_RAW);
$mform->addElement('hidden', 'coursestartdate', $course->startdate); $mform->addElement('hidden', 'coursestartdate', $course->startdate);
@ -171,8 +172,8 @@ 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);
$submit_string = get_string('addsession', 'attendance'); $submitstring = get_string('addsession', 'attendance');
$this->add_action_buttons(false, $submit_string); $this->add_action_buttons(false, $submitstring);
} }
/** /**
@ -183,7 +184,8 @@ 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);
if (!empty($data['addmultiply']) && $data['sessiondate'] != 0 && $data['sessionenddate'] != 0 && $data['sessionenddate'] < $data['sessiondate']) { if (!empty($data['addmultiply']) && $data['sessiondate'] != 0 && $data['sessionenddate'] != 0 &&
$data['sessionenddate'] < $data['sessiondate']) {
$errors['sessionenddate'] = get_string('invalidsessionenddate', 'attendance'); $errors['sessionenddate'] = get_string('invalidsessionenddate', 'attendance');
} }
@ -191,7 +193,7 @@ class mod_attendance_add_form extends moodleform {
$errors['groups'] = get_string('errorgroupsnotselected', 'attendance'); $errors['groups'] = get_string('errorgroupsnotselected', 'attendance');
} }
$addmulti = isset($data['addmultiply'])? (int)$data['addmultiply'] : 0; $addmulti = isset($data['addmultiply']) ? (int)$data['addmultiply'] : 0;
if (($addmulti != 0) && (!array_key_exists('sdays',$data) || empty($data['sdays']))) { if (($addmulti != 0) && (!array_key_exists('sdays',$data) || empty($data['sdays']))) {
$data['sdays']= array(); $data['sdays']= array();
$errors['sdays'] = get_string('required', 'attendance'); $errors['sdays'] = get_string('required', 'attendance');
@ -206,7 +208,8 @@ class mod_attendance_add_form extends moodleform {
} }
if ($data['sessiondate'] < $data['coursestartdate'] && $data['sessiondate'] != $data['previoussessiondate']) { if ($data['sessiondate'] < $data['coursestartdate'] && $data['sessiondate'] != $data['previoussessiondate']) {
$errors['sessiondate'] = get_string('priorto', 'attendance', userdate($data['coursestartdate'], get_string('strftimedmy', 'attendance'))); $errors['sessiondate'] = get_string('priorto', 'attendance',
userdate($data['coursestartdate'], get_string('strftimedmy', 'attendance')));
$this->_form->setConstant('previoussessiondate', $data['sessiondate']); $this->_form->setConstant('previoussessiondate', $data['sessiondate']);
} }
@ -218,9 +221,9 @@ class mod_attendance_add_form extends moodleform {
$found = false; $found = false;
$daysOfWeek = array(0 => "Sun", 1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat"); $daysOfWeek = array(0 => "Sun", 1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat");
$start = new DateTime( date("Y-m-d",$sessiondate) ); $start = new DateTime( date("Y-m-d", $sessiondate) );
$interval = new DateInterval('P1D'); $interval = new DateInterval('P1D');
$end = new DateTime( date("Y-m-d",$sessionenddate) ); $end = new DateTime( date("Y-m-d", $sessionenddate) );
$end->add( new DateInterval('P1D') ); $end->add( new DateInterval('P1D') );
$period = new DatePeriod($start, $interval, $end); $period = new DatePeriod($start, $interval, $end);

100
locallib.php

@ -205,7 +205,7 @@ class att_page_with_filter_controls {
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) { if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) {
$this->sessgroupslist[self::SESSTYPE_ALL] = get_string('all', 'attendance'); $this->sessgroupslist[self::SESSTYPE_ALL] = get_string('all', 'attendance');
} }
// 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] = format_string($group->name);
@ -569,7 +569,7 @@ class attendance {
$where = "attendanceid = :aid AND sessdate < :csdate"; $where = "attendanceid = :aid AND sessdate < :csdate";
$params = array( $params = array(
'aid' => $this->id, 'aid' => $this->id,
'csdate'=> $this->course->startdate); 'csdate' => $this->course->startdate);
return $DB->count_records_select('attendance_sessions', $where, $params); return $DB->count_records_select('attendance_sessions', $where, $params);
} }
@ -587,7 +587,7 @@ class attendance {
$where = "attendanceid = :aid AND sessdate < :csdate"; $where = "attendanceid = :aid AND sessdate < :csdate";
$params = array( $params = array(
'aid' => $this->id, 'aid' => $this->id,
'csdate'=> $this->course->startdate); 'csdate' => $this->course->startdate);
return $DB->get_records_select('attendance_sessions', $where, $params); return $DB->get_records_select('attendance_sessions', $where, $params);
} }
@ -731,14 +731,14 @@ class attendance {
$sess->description); $sess->description);
$DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id)); $DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id));
$info_array = array(); $infoarray = array();
$info_array[] = construct_session_full_date_time($sess->sessdate, $sess->duration); $infoarray[] = construct_session_full_date_time($sess->sessdate, $sess->duration);
// Trigger a session added event. // Trigger a session added event.
$event = \mod_attendance\event\session_added::create(array( $event = \mod_attendance\event\session_added::create(array(
'objectid' => $this->id, 'objectid' => $this->id,
'context' => $this->context, 'context' => $this->context,
'other' => array('info' => implode(',', $info_array)) 'other' => array('info' => implode(',', $infoarray))
)); ));
$event->add_record_snapshot('course_modules', $this->cm); $event->add_record_snapshot('course_modules', $this->cm);
$sess->description = $description; $sess->description = $description;
@ -758,7 +758,7 @@ class attendance {
} }
$sess->sessdate = $formdata->sessiondate; $sess->sessdate = $formdata->sessiondate;
$sess->duration = $formdata->durtime['hours']*HOURSECS + $formdata->durtime['minutes']*MINSECS; $sess->duration = $formdata->durtime['hours'] * HOURSECS + $formdata->durtime['minutes'] * MINSECS;
$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']);
@ -885,7 +885,7 @@ class attendance {
$this->update_users_grade(array_keys($sesslog)); $this->update_users_grade(array_keys($sesslog));
} }
// create url for link in log screen // Create url for link in log screen.
$params = array( $params = array(
'sessionid' => $this->pageparams->sessionid, 'sessionid' => $this->pageparams->sessionid,
'grouptype' => $this->pageparams->grouptype); 'grouptype' => $this->pageparams->grouptype);
@ -898,7 +898,7 @@ class attendance {
$event->trigger(); $event->trigger();
$group = 0; $group = 0;
if ($this->pageparams->grouptype != attendance::SESSION_COMMON) { if ($this->pageparams->grouptype != self::SESSION_COMMON) {
$group = $this->pageparams->grouptype; $group = $this->pageparams->grouptype;
} else { } else {
if ($this->pageparams->group) { if ($this->pageparams->group) {
@ -950,7 +950,8 @@ class attendance {
'', false, true); '', false, true);
} else { } else {
$startusers = ($page - 1) * $usersperpage; $startusers = ($page - 1) * $usersperpage;
$users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, $orderby, $startusers, $usersperpage); $users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields,
$orderby, $startusers, $usersperpage);
} }
} else { } else {
if (!empty($CFG->enablegroupmembersonly) and $this->cm->groupmembersonly) { if (!empty($CFG->enablegroupmembersonly) and $this->cm->groupmembersonly) {
@ -972,11 +973,11 @@ class attendance {
if (!empty($users)) { if (!empty($users)) {
list($sql, $params) = $DB->get_in_or_equal(array_keys($users), SQL_PARAMS_NAMED, 'usid0'); list($sql, $params) = $DB->get_in_or_equal(array_keys($users), SQL_PARAMS_NAMED, 'usid0');
// CONTRIB-4868 // See CONTRIB-4868.
$mintime = 'MIN(CASE WHEN (ue.timestart > :zerotime) THEN ue.timestart ELSE ue.timecreated END)'; $mintime = 'MIN(CASE WHEN (ue.timestart > :zerotime) THEN ue.timestart ELSE ue.timecreated END)';
$maxtime = 'CASE WHEN MIN(ue.timeend) = 0 THEN 0 ELSE MAX(ue.timeend) END'; $maxtime = 'CASE WHEN MIN(ue.timeend) = 0 THEN 0 ELSE MAX(ue.timeend) END';
// CONTRIB-3549 // See CONTRIB-3549.
$sql = "SELECT ue.userid, MIN(ue.status) as status, $sql = "SELECT ue.userid, MIN(ue.status) as status,
$mintime AS mintime, $mintime AS mintime,
$maxtime AS maxtime $maxtime AS maxtime
@ -986,7 +987,7 @@ class attendance {
AND e.status = :estatus AND e.status = :estatus
AND e.courseid = :courseid AND e.courseid = :courseid
GROUP BY ue.userid"; GROUP BY ue.userid";
$params += array('zerotime'=>0, 'estatus'=>ENROL_INSTANCE_ENABLED, 'courseid'=>$this->course->id); $params += array('zerotime' => 0, 'estatus' => ENROL_INSTANCE_ENABLED, 'courseid' => $this->course->id);
$enrolments = $DB->get_records_sql($sql, $params); $enrolments = $DB->get_records_sql($sql, $params);
foreach ($users as $user) { foreach ($users as $user) {
@ -1040,7 +1041,7 @@ class attendance {
$user->type = 'standard'; $user->type = 'standard';
// CONTRIB-4868 // See CONTRIB-4868.
$mintime = 'MIN(CASE WHEN (ue.timestart > :zerotime) THEN ue.timestart ELSE ue.timecreated END)'; $mintime = 'MIN(CASE WHEN (ue.timestart > :zerotime) THEN ue.timestart ELSE ue.timecreated END)';
$maxtime = 'CASE WHEN MIN(ue.timeend) = 0 THEN 0 ELSE MAX(ue.timeend) END'; $maxtime = 'CASE WHEN MIN(ue.timeend) = 0 THEN 0 ELSE MAX(ue.timeend) END';
@ -1053,7 +1054,7 @@ class attendance {
AND e.status = :estatus AND e.status = :estatus
AND e.courseid = :courseid AND e.courseid = :courseid
GROUP BY ue.userid, ue.status"; GROUP BY ue.userid, ue.status";
$params = array('zerotime'=>0, 'uid'=>$userid, 'estatus'=>ENROL_INSTANCE_ENABLED, 'courseid'=>$this->course->id); $params = array('zerotime' => 0, 'uid' => $userid, 'estatus' => ENROL_INSTANCE_ENABLED, 'courseid' => $this->course->id);
$enrolments = $DB->get_record_sql($sql, $params); $enrolments = $DB->get_record_sql($sql, $params);
$user->enrolmentstatus = $enrolments->status; $user->enrolmentstatus = $enrolments->status;
@ -1134,9 +1135,12 @@ class attendance {
public function get_user_taken_sessions_count($userid) { public function get_user_taken_sessions_count($userid) {
if (!array_key_exists($userid, $this->usertakensesscount)) { if (!array_key_exists($userid, $this->usertakensesscount)) {
if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) { if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) {
$this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate, $userid, $this->cm, $this->pageparams->startdate, $this->pageparams->enddate); $this->usertakensesscount[$userid] =
att_get_user_taken_sessions_count($this->id, $this->course->startdate, $userid,
$this->cm, $this->pageparams->startdate, $this->pageparams->enddate);
} else { } else {
$this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate, $userid, $this->cm); $this->usertakensesscount[$userid] = att_get_user_taken_sessions_count($this->id, $this->course->startdate,
$userid, $this->cm);
} }
} }
return $this->usertakensesscount[$userid]; return $this->usertakensesscount[$userid];
@ -1156,22 +1160,21 @@ class attendance {
'cstartdate' => $this->course->startdate, 'cstartdate' => $this->course->startdate,
'uid' => $userid); 'uid' => $userid);
$processed_filters = array(); $processedfilters = array();
// We test for any valid filters sent. // We test for any valid filters sent.
if (isset($filters['enddate'])) { if (isset($filters['enddate'])) {
$processed_filters[] = 'ats.sessdate <= :enddate'; $processedfilters[] = 'ats.sessdate <= :enddate';
$params['enddate'] = $filters['enddate']; $params['enddate'] = $filters['enddate'];
} }
// Make the filter array into a SQL string. // Make the filter array into a SQL string.
if (!empty($processed_filters)) { if (!empty($processedfilters)) {
$processed_filters = ' AND '.implode(' AND ', $processed_filters); $processedfilters = ' AND '.implode(' AND ', $processedfilters);
} else { } else {
$processed_filters = ''; $processedfilters = '';
} }
$period = ''; $period = '';
if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) { if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) {
$period = ' AND ats.sessdate >= :sdate AND ats.sessdate < :edate '; $period = ' AND ats.sessdate >= :sdate AND ats.sessdate < :edate ';
@ -1187,7 +1190,7 @@ class attendance {
WHERE ats.attendanceid = :aid AND WHERE ats.attendanceid = :aid AND
ats.sessdate >= :cstartdate AND ats.sessdate >= :cstartdate AND
al.studentid = :uid AND al.studentid = :uid AND
(ats.groupid = 0 or gm.id is NOT NULL)".$period.$processed_filters." (ats.groupid = 0 or gm.id is NOT NULL)".$period.$processedfilters."
GROUP BY al.statusid"; GROUP BY al.statusid";
} else { } else {
$qry = "SELECT al.statusid, count(al.statusid) AS stcnt $qry = "SELECT al.statusid, count(al.statusid) AS stcnt
@ -1196,7 +1199,7 @@ class attendance {
ON al.sessionid = ats.id ON al.sessionid = ats.id
WHERE ats.attendanceid = :aid AND WHERE ats.attendanceid = :aid AND
ats.sessdate >= :cstartdate AND ats.sessdate >= :cstartdate AND
al.studentid = :uid".$period.$processed_filters." al.studentid = :uid".$period.$processedfilters."
GROUP BY al.statusid"; GROUP BY al.statusid";
} }
@ -1314,23 +1317,26 @@ class attendance {
// We need to add this concatination so that moodle will use it as the array index that is a string. // We need to add this concatination so that moodle will use it as the array index that is a string.
// If the array's index is a number it will not merge entries. // If the array's index is a number it will not merge entries.
// It would be better as a UNION query butunfortunatly MS SQL does not seem to support doing a DISTINCT on a the description field. // It would be better as a UNION query but unfortunatly MS SQL does not seem to support doing a
// DISTINCT on a the description field.
$id = $DB->sql_concat(':value', 'ats.id'); $id = $DB->sql_concat(':value', 'ats.id');
if ($this->get_group_mode()) { if ($this->get_group_mode()) {
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks, ats.studentscanmark $sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description,
FROM {attendance_sessions} ats al.statusid, al.remarks, ats.studentscanmark
RIGHT JOIN {attendance_log} al FROM {attendance_sessions} ats
ON ats.id = al.sessionid AND al.studentid = :uid RIGHT JOIN {attendance_log} al
LEFT JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid ON ats.id = al.sessionid AND al.studentid = :uid
WHERE $where AND (ats.groupid = 0 or gm.id is NOT NULL) LEFT JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid
ORDER BY ats.sessdate ASC"; WHERE $where AND (ats.groupid = 0 or gm.id is NOT NULL)
ORDER BY ats.sessdate ASC";
} else { } else {
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks, ats.studentscanmark $sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description,
FROM {attendance_sessions} ats al.statusid, al.remarks, ats.studentscanmark
RIGHT JOIN {attendance_log} al FROM {attendance_sessions} ats
ON ats.id = al.sessionid AND al.studentid = :uid RIGHT JOIN {attendance_log} al
WHERE $where ON ats.id = al.sessionid AND al.studentid = :uid
ORDER BY ats.sessdate ASC"; WHERE $where
ORDER BY ats.sessdate ASC";
} }
$params = array( $params = array(
@ -1355,7 +1361,8 @@ class attendance {
$where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND ats.groupid $gsql"; $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND ats.groupid $gsql";
} }
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks, ats.studentscanmark $sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description,
al.statusid, al.remarks, ats.studentscanmark
FROM {attendance_sessions} ats FROM {attendance_sessions} ats
LEFT JOIN {attendance_log} al LEFT JOIN {attendance_log} al
ON ats.id = al.sessionid AND al.studentid = :uid ON ats.id = al.sessionid AND al.studentid = :uid
@ -1423,7 +1430,7 @@ class attendance {
$DB->set_field('attendance_statuses', 'deleted', 1, array('id' => $status->id)); $DB->set_field('attendance_statuses', 'deleted', 1, array('id' => $status->id));
$event = \mod_attendance\event\status_removed::create(array( $event = \mod_attendance\event\status_removed::create(array(
'objectid' => $status->id, 'objectid' => $status->id,
'context' => $this->context, 'context' => $this->context,
'other' => array( 'other' => array(
'acronym' => $status->acronym, 'acronym' => $status->acronym,
'description' => $status->description 'description' => $status->description
@ -1508,7 +1515,8 @@ class attendance {
$event = \mod_attendance\event\status_updated::create(array( $event = \mod_attendance\event\status_updated::create(array(
'objectid' => $this->id, 'objectid' => $this->id,
'context' => $this->context, 'context' => $this->context,
'other' => array('acronym' => $acronym, 'description' => $description, 'grade' => $grade, 'updated' => implode(' ', $updated)))); 'other' => array('acronym' => $acronym, 'description' => $description, 'grade' => $grade,
'updated' => implode(' ', $updated))));
$event->add_record_snapshot('course_modules', $this->cm); $event->add_record_snapshot('course_modules', $this->cm);
$event->add_record_snapshot('attendance_statuses', $status); $event->add_record_snapshot('attendance_statuses', $status);
$event->trigger(); $event->trigger();
@ -1716,9 +1724,9 @@ function att_update_all_users_grades($attid, $course, $context, $coursemodule) {
$dbparams = array('id' => -($this->grade)); $dbparams = array('id' => -($this->grade));
$this->scale = $DB->get_record('scale', $dbparams); $this->scale = $DB->get_record('scale', $dbparams);
$scalearray = explode(',', $this->scale->scale); $scalearray = explode(',', $this->scale->scale);
$gradebook_maxgrade = count($scalearray); $gradebookmaxgrade = count($scalearray);
} else { } else {
$gradebook_maxgrade = att_get_gradebook_maxgrade($attid); $gradebookmaxgrade = att_get_gradebook_maxgrade($attid);
} }
foreach ($userids as $userid) { foreach ($userids as $userid) {
$grade = new stdClass; $grade = new stdClass;
@ -1727,7 +1735,7 @@ function att_update_all_users_grades($attid, $course, $context, $coursemodule) {
$usertakensesscount = att_get_user_taken_sessions_count($attid, $course->startdate, $userid, $coursemodule); $usertakensesscount = att_get_user_taken_sessions_count($attid, $course->startdate, $userid, $coursemodule);
$usergrade = att_get_user_grade($userstatusesstat, $statuses); $usergrade = att_get_user_grade($userstatusesstat, $statuses);
$usermaxgrade = att_get_user_max_grade($usertakensesscount, $statuses); $usermaxgrade = att_get_user_max_grade($usertakensesscount, $statuses);
$grade->rawgrade = att_calc_user_grade_fraction($usergrade, $usermaxgrade) * $gradebook_maxgrade; $grade->rawgrade = att_calc_user_grade_fraction($usergrade, $usermaxgrade) * $gradebookmaxgrade;
$grades[$userid] = $grade; $grades[$userid] = $grade;
} }
@ -1738,7 +1746,7 @@ function att_update_all_users_grades($attid, $course, $context, $coursemodule) {
function att_has_logs_for_status($statusid) { function att_has_logs_for_status($statusid) {
global $DB; global $DB;
return $DB->count_records('attendance_log', array('statusid'=> $statusid)) > 0; return $DB->count_records('attendance_log', array('statusid' => $statusid)) > 0;
} }
function att_log_convert_url(moodle_url $fullurl) { function att_log_convert_url(moodle_url $fullurl) {

18
renderables.php

@ -147,7 +147,7 @@ class attendance_filter_controls implements renderable {
$format = get_string('strftimedm', 'attendance'); $format = get_string('strftimedm', 'attendance');
$this->prevcur = make_timestamp($year, $mon, $mday - 1); $this->prevcur = make_timestamp($year, $mon, $mday - 1);
$this->nextcur = make_timestamp($year, $mon, $mday + 1); $this->nextcur = make_timestamp($year, $mon, $mday + 1);
$this->curdatetxt = userdate($att->pageparams->startdate, $format); $this->curdatetxt = userdate($att->pageparams->startdate, $format);
break; break;
case ATT_VIEW_WEEKS: case ATT_VIEW_WEEKS:
$format = get_string('strftimedm', 'attendance'); $format = get_string('strftimedm', 'attendance');
@ -395,24 +395,24 @@ class attendance_user_data implements renderable {
continue; continue;
} }
$statuses = att_get_statuses($ca->attid); $statuses = att_get_statuses($ca->attid);
$user_taken_sessions_count = att_get_user_taken_sessions_count($ca->attid, $ca->coursestartdate, $userid, $att->cm); $usertakensessionscount = att_get_user_taken_sessions_count($ca->attid, $ca->coursestartdate, $userid, $att->cm);
$user_statuses_stat = att_get_user_statuses_stat($ca->attid, $ca->coursestartdate, $userid, $att->cm); $userstatusesstat = att_get_user_statuses_stat($ca->attid, $ca->coursestartdate, $userid, $att->cm);
$this->statuses[$ca->attid] = $statuses; $this->statuses[$ca->attid] = $statuses;
$this->stat[$ca->attid]['completed'] = $user_taken_sessions_count; $this->stat[$ca->attid]['completed'] = $usertakensessionscount;
$this->stat[$ca->attid]['statuses'] = $user_statuses_stat; $this->stat[$ca->attid]['statuses'] = $userstatusesstat;
$this->gradable[$ca->attid] = $ca->attgrade > 0; $this->gradable[$ca->attid] = $ca->attgrade > 0;
if ($this->gradable[$ca->attid]) { if ($this->gradable[$ca->attid]) {
$this->grade[$ca->attid] = att_get_user_grade($user_statuses_stat, $statuses); $this->grade[$ca->attid] = att_get_user_grade($userstatusesstat, $statuses);
// For getting sessions count implemented simplest method - taken sessions. // For getting sessions count implemented simplest method - taken sessions.
// It can have error if users don't have attendance info for some sessions. // It can have error if users don't have attendance info for some sessions.
// In the future we can implement another methods: // In the future we can implement another methods:
// * all sessions between user start enrolment date and now; // * all sessions between user start enrolment date and now;
// * all sessions between user start and end enrolment date. // * all sessions between user start and end enrolment date.
$this->maxgrade[$ca->attid] = att_get_user_max_grade($user_taken_sessions_count, $statuses); $this->maxgrade[$ca->attid] = att_get_user_max_grade($usertakensessionscount, $statuses);
} else { } else {
// For more comfortable and universal work with arrays. // For more comfortable and universal work with arrays.
$this->grade[$ca->attid] = null; $this->grade[$ca->attid] = null;
@ -555,8 +555,8 @@ class attendance_preferences_data implements renderable {
$this->att = $att; $this->att = $att;
} }
public function url($params=array(), $significant_params=true) { public function url($params=array(), $significantparams=true) {
if ($significant_params) { if ($significantparams) {
$params = array_merge($this->att->pageparams->get_significant_params(), $params); $params = array_merge($this->att->pageparams->get_significant_params(), $params);
} }

102
renderer.php

@ -94,9 +94,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
} }
protected function render_paging_controls(attendance_filter_controls $fcontrols) { protected function render_paging_controls(attendance_filter_controls $fcontrols) {
global $CFG; $pagingcontrols = '';
$paging_controls = '';
$group = 0; $group = 0;
if (!empty($fcontrols->pageparams->group)) { if (!empty($fcontrols->pageparams->group)) {
@ -104,30 +102,35 @@ class mod_attendance_renderer extends plugin_renderer_base {
} }
$totalusers = count_enrolled_users(context_module::instance($fcontrols->cm->id), 'mod/attendance:canbelisted', $group); $totalusers = count_enrolled_users(context_module::instance($fcontrols->cm->id), 'mod/attendance:canbelisted', $group);
if (empty($fcontrols->pageparams->page) || !$fcontrols->pageparams->page || !$totalusers || empty($fcontrols->pageparams->perpage)) { if (empty($fcontrols->pageparams->page) || !$fcontrols->pageparams->page || !$totalusers ||
return $paging_controls; empty($fcontrols->pageparams->perpage)) {
return $pagingcontrols;
} }
$numberofpages = ceil($totalusers / $fcontrols->pageparams->perpage); $numberofpages = ceil($totalusers / $fcontrols->pageparams->perpage);
if ($fcontrols->pageparams->page > 1) { if ($fcontrols->pageparams->page > 1) {
$paging_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->curdate, 'page' => $fcontrols->pageparams->page - 1)), $pagingcontrols .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->curdate,
$this->output->larrow()); 'page' => $fcontrols->pageparams->page - 1)),
$this->output->larrow());
} }
$paging_controls .= html_writer::tag('span', "Page {$fcontrols->pageparams->page} of $numberofpages", array('class' => 'attbtn')); $pagingcontrols .= html_writer::tag('span', "Page {$fcontrols->pageparams->page} of $numberofpages",
array('class' => 'attbtn'));
if ($fcontrols->pageparams->page < $numberofpages) { if ($fcontrols->pageparams->page < $numberofpages) {
$paging_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->curdate, 'page' => $fcontrols->pageparams->page + 1)), $pagingcontrols .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->curdate,
$this->output->rarrow()); 'page' => $fcontrols->pageparams->page + 1)),
$this->output->rarrow());
} }
return $paging_controls ; return $pagingcontrols;
} }
protected function render_curdate_controls(attendance_filter_controls $fcontrols) { protected function render_curdate_controls(attendance_filter_controls $fcontrols) {
global $CFG; global $CFG;
$curdate_controls = ''; $curdatecontrols = '';
if ($fcontrols->curdatetxt) { if ($fcontrols->curdatetxt) {
$this->page->requires->strings_for_js(array('calclose', 'caltoday'), 'attendance'); $this->page->requires->strings_for_js(array('calclose', 'caltoday'), 'attendance');
$jsvals = array( $jsvals = array(
@ -135,24 +138,24 @@ class mod_attendance_renderer extends plugin_renderer_base {
'cal_week_days' => explode(',', get_string('calweekdays', 'attendance')), 'cal_week_days' => explode(',', get_string('calweekdays', 'attendance')),
'cal_start_weekday' => $CFG->calendar_startwday, 'cal_start_weekday' => $CFG->calendar_startwday,
'cal_cur_date' => $fcontrols->curdate); 'cal_cur_date' => $fcontrols->curdate);
$curdate_controls = html_writer::script(js_writer::set_variable('M.attendance', $jsvals)); $curdatecontrols = html_writer::script(js_writer::set_variable('M.attendance', $jsvals));
$this->page->requires->js('/mod/attendance/calendar.js'); $this->page->requires->js('/mod/attendance/calendar.js');
$curdate_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->prevcur)), $curdatecontrols .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->prevcur)),
$this->output->larrow()); $this->output->larrow());
$params = array( $params = array(
'title' => get_string('calshow', 'attendance'), 'title' => get_string('calshow', 'attendance'),
'id' => 'show', 'id' => 'show',
'type' => 'button'); 'type' => 'button');
$button_form = html_writer::tag('button', $fcontrols->curdatetxt, $params); $buttonform = html_writer::tag('button', $fcontrols->curdatetxt, $params);
foreach ($fcontrols->url_params(array('curdate' => '')) as $name => $value) { foreach ($fcontrols->url_params(array('curdate' => '')) as $name => $value) {
$params = array( $params = array(
'type' => 'hidden', 'type' => 'hidden',
'id' => $name, 'id' => $name,
'name' => $name, 'name' => $name,
'value' => $value); 'value' => $value);
$button_form .= html_writer::empty_tag('input', $params); $buttonform .= html_writer::empty_tag('input', $params);
} }
$params = array( $params = array(
'id' => 'currentdate', 'id' => 'currentdate',
@ -160,14 +163,14 @@ class mod_attendance_renderer extends plugin_renderer_base {
'method' => 'post' 'method' => 'post'
); );
$button_form = html_writer::tag('form', $button_form, $params); $buttonform = html_writer::tag('form', $buttonform, $params);
$curdate_controls .= $button_form; $curdatecontrols .= $buttonform;
$curdate_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->nextcur)), $curdatecontrols .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->nextcur)),
$this->output->rarrow()); $this->output->rarrow());
} }
return $curdate_controls; return $curdatecontrols;
} }
protected function render_view_controls(attendance_filter_controls $fcontrols) { protected function render_view_controls(attendance_filter_controls $fcontrols) {
@ -237,7 +240,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->data[$sess->id][] = $dta['time']; $table->data[$sess->id][] = $dta['time'];
$table->data[$sess->id][] = $sess->description; $table->data[$sess->id][] = $sess->description;
$table->data[$sess->id][] = $dta['actions']; $table->data[$sess->id][] = $dta['actions'];
$table->data[$sess->id][] = html_writer::checkbox('sessid[]', $sess->id, false, '', array('class' => 'attendancesesscheckbox')); $table->data[$sess->id][] = html_writer::checkbox('sessid[]', $sess->id, false, '',
array('class' => 'attendancesesscheckbox'));
} }
return html_writer::table($table); return html_writer::table($table);
@ -328,26 +332,29 @@ class mod_attendance_renderer extends plugin_renderer_base {
} else { } else {
$table = $this->render_attendance_take_grid($takedata); $table = $this->render_attendance_take_grid($takedata);
} }
$table .= html_writer::input_hidden_params($takedata->url(array('sesskey' => sesskey(), 'page' => $takedata->pageparams->page))); $table .= html_writer::input_hidden_params($takedata->url(array('sesskey' => sesskey(),
'page' => $takedata->pageparams->page)));
$params = array( $params = array(
'type' => 'submit', 'type' => 'submit',
'value' => get_string('save', 'attendance')); 'value' => get_string('save', 'attendance'));
$table .= html_writer::tag('center', html_writer::empty_tag('input', $params)); $table .= html_writer::tag('center', html_writer::empty_tag('input', $params));
$table = html_writer::tag('form', $table, array('method' => 'post', 'action' => $takedata->url_path())); $table = html_writer::tag('form', $table, array('method' => 'post', 'action' => $takedata->url_path()));
foreach($takedata->statuses as $status) { foreach ($takedata->statuses as $status) {
$sessionstats[$status->id] = 0; $sessionstats[$status->id] = 0;
} }
// Calculate the sum of statuses for each user // Calculate the sum of statuses for each user.
$sessionstats[] = array(); $sessionstats[] = array();
foreach ($takedata->sessionlog as $userlog) { foreach ($takedata->sessionlog as $userlog) {
foreach($takedata->statuses as $status) { foreach ($takedata->statuses as $status) {
if ($userlog->statusid == $status->id) $sessionstats[$status->id]++; if ($userlog->statusid == $status->id) {
$sessionstats[$status->id]++;
}
} }
} }
$statsoutput = '<br/>'; $statsoutput = '<br/>';
foreach($takedata->statuses as $status) { foreach ($takedata->statuses as $status) {
$statsoutput .= "$status->description = ".$sessionstats[$status->id]." <br/>"; $statsoutput .= "$status->description = ".$sessionstats[$status->id]." <br/>";
} }
@ -379,8 +386,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
} }
private function construct_take_controls(attendance_take_data $takedata) { private function construct_take_controls(attendance_take_data $takedata) {
GLOBAL $CFG; global $CFG;
$controls = ''; $controls = '';
$context = context_module::instance($takedata->cm->id); $context = context_module::instance($takedata->cm->id);
$group = 0; $group = 0;
@ -412,9 +419,11 @@ class mod_attendance_renderer extends plugin_renderer_base {
$numberofpages = ceil($totalusers / $usersperpage); $numberofpages = ceil($totalusers / $usersperpage);
if ($takedata->pageparams->page > 1) { if ($takedata->pageparams->page > 1) {
$controls .= html_writer::link($takedata->url(array('page' => $takedata->pageparams->page - 1)), $this->output->larrow()); $controls .= html_writer::link($takedata->url(array('page' => $takedata->pageparams->page - 1)),
$this->output->larrow());
} }
$controls .= html_writer::tag('span', "Page {$takedata->pageparams->page} of $numberofpages", array('class' => 'attbtn')); $controls .= html_writer::tag('span', "Page {$takedata->pageparams->page} of $numberofpages",
array('class' => 'attbtn'));
if ($takedata->pageparams->page < $numberofpages) { if ($takedata->pageparams->page < $numberofpages) {
$controls .= html_writer::link($takedata->url(array('page' => $takedata->pageparams->page + 1, $controls .= html_writer::link($takedata->url(array('page' => $takedata->pageparams->page + 1,
'perpage' => $takedata->pageparams->perpage)), $this->output->rarrow()); 'perpage' => $takedata->pageparams->perpage)), $this->output->rarrow());
@ -550,7 +559,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
protected function render_attendance_take_grid(attendance_take_data $takedata) { protected function render_attendance_take_grid(attendance_take_data $takedata) {
$table = new html_table(); $table = new html_table();
for ($i=0; $i < $takedata->pageparams->gridcols; $i++) { for ($i = 0; $i < $takedata->pageparams->gridcols; $i++) {
$table->align[] = 'center'; $table->align[] = 'center';
$table->size[] = '110px'; $table->size[] = '110px';
} }
@ -682,7 +691,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->attributes['class'] = 'userinfobox'; $table->attributes['class'] = 'userinfobox';
$table->colclasses = array('left side', ''); $table->colclasses = array('left side', '');
$table->data[0][] = $this->user_picture($userdata->user, array('size' => 100)); // Show different picture if it is a temporary user. // Show different picture if it is a temporary user.
$table->data[0][] = $this->user_picture($userdata->user, array('size' => 100));
$table->data[0][] = $this->construct_user_data($userdata); $table->data[0][] = $this->construct_user_data($userdata);
$o .= html_writer::table($table); $o .= html_writer::table($table);
@ -805,7 +815,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
} }
protected function render_attendance_report_data(attendance_report_data $reportdata) { protected function render_attendance_report_data(attendance_report_data $reportdata) {
global $PAGE; global $PAGE, $COURSE;
// Initilise Javascript used to (un)check all checkboxes. // Initilise Javascript used to (un)check all checkboxes.
$this->page->requires->js_init_call('M.mod_attendance.init_manage'); $this->page->requires->js_init_call('M.mod_attendance.init_manage');
@ -859,7 +869,6 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->size[] = '1px'; $table->size[] = '1px';
} }
if ($bulkmessagecapability) { // Display the table header for bulk messaging. if ($bulkmessagecapability) { // Display the table header for bulk messaging.
// The checkbox must have an id of cb_selector so that the JavaScript will pick it up. // The checkbox must have an id of cb_selector so that the JavaScript will pick it up.
$table->head[] = html_writer::checkbox('cb_selector', 0, false, '', array('id' => 'cb_selector')); $table->head[] = html_writer::checkbox('cb_selector', 0, false, '', array('id' => 'cb_selector'));
@ -891,25 +900,27 @@ class mod_attendance_renderer extends plugin_renderer_base {
if ($bulkmessagecapability) { // Create the checkbox for bulk messaging. if ($bulkmessagecapability) { // Create the checkbox for bulk messaging.
$row->cells[] = html_writer::checkbox('user'.$user->id, 'on', false); $row->cells[] = html_writer::checkbox('user'.$user->id, 'on', false);
} }
$table->data[] = $row; $table->data[] = $row;
} }
// Calculate the sum of statuses for each user // Calculate the sum of statuses for each user.
$statrow = new html_table_row(); $statrow = new html_table_row();
$statrow->cells[] = ''; $statrow->cells[] = '';
$statrow->cells[] = get_string('summary'); $statrow->cells[] = get_string('summary');
foreach ($reportdata->sessions as $sess) { foreach ($reportdata->sessions as $sess) {
foreach ($reportdata->users as $user) { foreach ($reportdata->users as $user) {
foreach($reportdata->statuses as $status) { foreach ($reportdata->statuses as $status) {
if (!empty($reportdata->sessionslog[$user->id][$sess->id])) { if (!empty($reportdata->sessionslog[$user->id][$sess->id])) {
if ($reportdata->sessionslog[$user->id][$sess->id]->statusid == $status->id) $sessionstats[$status->id]++; if ($reportdata->sessionslog[$user->id][$sess->id]->statusid == $status->id) {
$sessionstats[$status->id]++;
}
} }
} }
} }
$statsoutput = '<br/>'; $statsoutput = '<br/>';
foreach($reportdata->statuses as $status) { foreach ($reportdata->statuses as $status) {
$statsoutput .= "$status->description:".$sessionstats[$status->id]." <br/>"; $statsoutput .= "$status->description:".$sessionstats[$status->id]." <br/>";
} }
$statrow->cells[] = $statsoutput; $statrow->cells[] = $statsoutput;
@ -920,8 +931,9 @@ class mod_attendance_renderer extends plugin_renderer_base {
if ($bulkmessagecapability) { // Require that the user can bulk message users. if ($bulkmessagecapability) { // Require that the user can bulk message users.
// Display check boxes that will allow the user to send a message to the students that have been checked. // Display check boxes that will allow the user to send a message to the students that have been checked.
$output = html_writer::empty_tag('input', array('name' => 'sesskey', 'type' => 'hidden', 'value' => sesskey())); $output = html_writer::empty_tag('input', array('name' => 'sesskey', 'type' => 'hidden', 'value' => sesskey()));
$output .= html_writer::empty_tag('input', array('name' => 'formaction', 'type' => 'hidden', 'value' => 'messageselect.php')); $output .= html_writer::empty_tag('input', array('name' => 'formaction', 'type' => 'hidden',
$output .= html_writer::empty_tag('input', array('name' => 'id', 'type' => 'hidden', 'value' => $GLOBALS['COURSE']->id)); 'value' => 'messageselect.php'));
$output .= html_writer::empty_tag('input', array('name' => 'id', 'type' => 'hidden', 'value' => $COURSE->id));
$output .= html_writer::empty_tag('input', array('name' => 'returnto', 'type' => 'hidden', 'value' => s(me()))); $output .= html_writer::empty_tag('input', array('name' => 'returnto', 'type' => 'hidden', 'value' => s(me())));
$output .= html_writer::table($table).html_writer::tag('div', get_string('users').': '.count($reportdata->users));; $output .= html_writer::table($table).html_writer::tag('div', get_string('users').': '.count($reportdata->users));;
$output .= html_writer::tag('div', $output .= html_writer::tag('div',
@ -932,7 +944,6 @@ class mod_attendance_renderer extends plugin_renderer_base {
} else { } else {
return html_writer::table($table).html_writer::tag('div', get_string('users').': '.count($reportdata->users)); return html_writer::table($table).html_writer::tag('div', get_string('users').': '.count($reportdata->users));
} }
} }
/** /**
@ -989,7 +1000,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->data[$i][] = $i; $table->data[$i][] = $i;
$table->data[$i][] = $this->construct_text_input('acronym['.$st->id.']', 2, 2, $st->acronym) . $emptyacronym; $table->data[$i][] = $this->construct_text_input('acronym['.$st->id.']', 2, 2, $st->acronym) . $emptyacronym;
$table->data[$i][] = $this->construct_text_input('description['.$st->id.']', 30, 30, $st->description) . $emptydescription; $table->data[$i][] = $this->construct_text_input('description['.$st->id.']', 30, 30, $st->description) .
$emptydescription;
$table->data[$i][] = $this->construct_text_input('grade['.$st->id.']', 4, 4, $st->grade); $table->data[$i][] = $this->construct_text_input('grade['.$st->id.']', 4, 4, $st->grade);
$table->data[$i][] = $this->construct_preferences_actions_icons($st, $prefdata); $table->data[$i][] = $this->construct_preferences_actions_icons($st, $prefdata);

10
renderhelpers.php

@ -103,7 +103,7 @@ class user_sessions_cells_generator {
protected function construct_not_taken_cell($text) { protected function construct_not_taken_cell($text) {
$this->cells[] = $text; $this->cells[] = $text;
} }
protected function construct_remarks_cell($text) { protected function construct_remarks_cell($text) {
$this->cells[] = $text; $this->cells[] = $text;
} }
@ -160,7 +160,7 @@ class user_sessions_cells_html_generator extends user_sessions_cells_generator {
$this->close_open_cell_if_needed(); $this->close_open_cell_if_needed();
$this->cells[] = $text; $this->cells[] = $text;
} }
protected function construct_remarks_cell($text) { protected function construct_remarks_cell($text) {
global $OUTPUT; global $OUTPUT;
@ -198,15 +198,15 @@ class user_sessions_cells_html_generator extends user_sessions_cells_generator {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class user_sessions_cells_text_generator extends user_sessions_cells_generator { class user_sessions_cells_text_generator extends user_sessions_cells_generator {
private $enrolments_info_cell_text; private $enrolmentsinfocelltext;
protected function construct_hidden_status_cell($text) { protected function construct_hidden_status_cell($text) {
$this->cells[] = '-'.$text; $this->cells[] = '-'.$text;
} }
protected function construct_enrolments_info_cell($text) { protected function construct_enrolments_info_cell($text) {
if ($this->enrolments_info_cell_text != $text) { if ($this->enrolmentsinfocelltext != $text) {
$this->enrolments_info_cell_text = $text; $this->enrolmentsinfocelltext = $text;
$this->cells[] = $text; $this->cells[] = $text;
} else { } else {
$this->cells[] = '←'; $this->cells[] = '←';

20
sessions.php

@ -55,7 +55,7 @@ require_capability('mod/attendance:manageattendances', $context);
$att = new attendance($att, $cm, $course, $context, $pageparams); $att = new attendance($att, $cm, $course, $context, $pageparams);
$PAGE->set_url($att->url_sessions(array('action'=>$pageparams->action))); $PAGE->set_url($att->url_sessions(array('action' => $pageparams->action)));
$PAGE->set_title($course->shortname. ": ".$att->name); $PAGE->set_title($course->shortname. ": ".$att->name);
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true); $PAGE->set_cacheable(true);
@ -71,10 +71,10 @@ switch ($att->pageparams->action) {
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') $message = count($sessions) == 1 ? get_string('sessiongenerated', 'attendance') :
: get_string('sessionsgenerated', 'attendance', count($sessions)); 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;
redirect($att->url_manage()); redirect($att->url_manage());
} }
@ -177,7 +177,7 @@ switch ($att->pageparams->action) {
if ($formdata = $mform->get_data()) { if ($formdata = $mform->get_data()) {
$sessionsids = explode('_', $ids); $sessionsids = explode('_', $ids);
$duration = $formdata->durtime['hours']*HOURSECS + $formdata->durtime['minutes']*MINSECS; $duration = $formdata->durtime['hours'] * HOURSECS + $formdata->durtime['minutes'] * MINSECS;
$att->update_sessions_duration($sessionsids, $duration); $att->update_sessions_duration($sessionsids, $duration);
redirect($att->url_manage(), get_string('sessionupdated', 'attendance')); redirect($att->url_manage(), get_string('sessionupdated', 'attendance'));
} }
@ -221,7 +221,7 @@ 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; $duration = $formdata->durtime['hours'] * HOURSECS + $formdata->durtime['minutes'] * MINSECS;
$now = time(); $now = time();
$sessions = array(); $sessions = array();
@ -243,17 +243,17 @@ function construct_sessions_data_for_add($formdata) {
$startweek = $startdate - $dinfo['wday'] * DAYSECS; // Call new variable. $startweek = $startdate - $dinfo['wday'] * DAYSECS; // Call new variable.
} else { } else {
$wday = $dinfo['wday'] === 0 ? 7 : $dinfo['wday']; $wday = $dinfo['wday'] === 0 ? 7 : $dinfo['wday'];
$startweek = $startdate - ($wday-1) * DAYSECS; $startweek = $startdate - ($wday - 1) * DAYSECS;
} }
$wdaydesc = array(0=>'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); $wdaydesc = array(0 => 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
while ($sdate < $enddate) { while ($sdate < $enddate) {
if ($sdate < $startweek + WEEKSECS) { if ($sdate < $startweek + WEEKSECS) {
$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) + $starttime;
$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'];
@ -281,7 +281,7 @@ function construct_sessions_data_for_add($formdata) {
$sess->descriptionformat = $formdata->sdescription['format']; $sess->descriptionformat = $formdata->sdescription['format'];
$sess->timemodified = $now; $sess->timemodified = $now;
if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance. if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance.
$sess->studentscanmark = 1; $sess->studentscanmark = 1;
} }
$sess->statusset = $formdata->statusset; $sess->statusset = $formdata->statusset;

6
temp_form.php

@ -28,7 +28,7 @@ global $CFG;
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
class temp_form extends moodleform { class temp_form extends moodleform {
function definition() { public function definition() {
$mform = $this->_form; $mform = $this->_form;
@ -49,12 +49,12 @@ class temp_form extends moodleform {
$mform->closeHeaderBefore('submit'); $mform->closeHeaderBefore('submit');
} }
function definition_after_data() { public function definition_after_data() {
$mform = $this->_form; $mform = $this->_form;
$mform->applyFilter('tname', 'trim'); $mform->applyFilter('tname', 'trim');
} }
function validation($data, $files) { public function validation($data, $files) {
$errors = parent::validation($data, $files); $errors = parent::validation($data, $files);
if ($err = attendance::check_existing_email($data['temail'])) { if ($err = attendance::check_existing_email($data['temail'])) {

6
tempedit_form.php

@ -29,7 +29,7 @@ require_once($CFG->libdir.'/formslib.php');
class tempedit_form extends moodleform { class tempedit_form extends moodleform {
function definition() { public function definition() {
$mform = $this->_form; $mform = $this->_form;
@ -55,12 +55,12 @@ class tempedit_form extends moodleform {
$mform->closeHeaderBefore('submit'); $mform->closeHeaderBefore('submit');
} }
function definition_after_data() { public function definition_after_data() {
$mform = $this->_form; $mform = $this->_form;
$mform->applyFilter('tname', 'trim'); $mform->applyFilter('tname', 'trim');
} }
function validation($data, $files) { public function validation($data, $files) {
$errors = parent::validation($data, $files); $errors = parent::validation($data, $files);
if ($err = attendance::check_existing_email($data['temail'], $data['userid'])) { if ($err = attendance::check_existing_email($data['temail'], $data['userid'])) {

16
tempmerge_form.php

@ -1,4 +1,18 @@
<?php <?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/>.
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
@ -7,7 +21,7 @@ require_once($CFG->libdir.'/formslib.php');
class tempmerge_form extends moodleform { class tempmerge_form extends moodleform {
function definition() { public function definition() {
global $COURSE; global $COURSE;
$context = context_course::instance($COURSE->id); $context = context_course::instance($COURSE->id);

8
tempusers.php

@ -45,7 +45,6 @@ $PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true); $PAGE->set_cacheable(true);
$PAGE->navbar->add(get_string('tempusers', 'attendance')); $PAGE->navbar->add(get_string('tempusers', 'attendance'));
/** @var mod_attendance_renderer $output */
$output = $PAGE->get_renderer('mod_attendance'); $output = $PAGE->get_renderer('mod_attendance');
$tabs = new attendance_tabs($att, attendance_tabs::TAB_TEMPORARYUSERS); $tabs = new attendance_tabs($att, attendance_tabs::TAB_TEMPORARYUSERS);
@ -79,7 +78,7 @@ if ($data = $mform->get_data()) {
redirect($att->url_managetemp()); redirect($att->url_managetemp());
} }
/// Output starts here // Output starts here.
echo $output->header(); echo $output->header();
echo $output->heading(get_string('tempusers', 'attendance').' : '.format_string($course->fullname)); echo $output->heading(get_string('tempusers', 'attendance').' : '.format_string($course->fullname));
echo $output->render($tabs); echo $output->render($tabs);
@ -97,14 +96,15 @@ echo $output->footer($course);
function print_tempusers($tempusers, attendance $att) { function print_tempusers($tempusers, attendance $att) {
echo '<p></p>'; echo '<p></p>';
echo '<table border="1" bordercolor="#EEEEEE" style="background-color:#fff" cellpadding="2" align="center" width="80%" summary="'.get_string('temptable', 'attendance').'"><tr>'; echo '<table border="1" bordercolor="#EEEEEE" style="background-color:#fff" cellpadding="2" align="center"'.
'width="80%" summary="'.get_string('temptable', 'attendance').'"><tr>';
echo '<th class="header">'.get_string('tusername', 'attendance').'</th>'; echo '<th class="header">'.get_string('tusername', 'attendance').'</th>';
echo '<th class="header">'.get_string('tuseremail', 'attendance').'</th>'; echo '<th class="header">'.get_string('tuseremail', 'attendance').'</th>';
echo '<th class="header">'.get_string('tcreated', 'attendance').'</th>'; echo '<th class="header">'.get_string('tcreated', 'attendance').'</th>';
echo '<th class="header">'.get_string('tactions', 'attendance').'</th>'; echo '<th class="header">'.get_string('tactions', 'attendance').'</th>';
echo '</tr>'; echo '</tr>';
$even = false; // used to colour rows $even = false; // Used to colour rows.
foreach ($tempusers as $tempuser) { foreach ($tempusers as $tempuser) {
if ($even) { if ($even) {
echo '<tr style="background-color: #FCFCFC">'; echo '<tr style="background-color: #FCFCFC">';

2
tests/behat/attendance_taken_by_student.php

@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
* @property-read array $other { * @property-read array $other {
* Extra information about event properties. * Extra information about event properties.
* *
* @string mode Mode of the report viewed. * string mode Mode of the report viewed.
* } * }
* @package mod_attendance * @package mod_attendance
* @since Moodle 2.7 * @since Moodle 2.7

27
tests/behat/behat_mod_attendance.php

@ -34,7 +34,7 @@ use Behat\Mink\Exception\ExpectationException as ExpectationException,
*/ */
class behat_mod_attendance extends behat_base { class behat_mod_attendance extends behat_base {
protected $file_contents; protected $filecontents;
/** /**
* @Then /^attendance export file is ok$/ * @Then /^attendance export file is ok$/
@ -42,7 +42,7 @@ class behat_mod_attendance extends behat_base {
public function attendance_export_file_is_ok() { public function attendance_export_file_is_ok() {
global $CFG; global $CFG;
$check = true; $check = true;
// Location selenium will download to. // Location selenium will download to.
@ -55,26 +55,26 @@ class behat_mod_attendance extends behat_base {
$header = null; $header = null;
// The file is tab seperated but not exactly a tsv. // The file is tab seperated but not exactly a tsv.
while (($row = fgetcsv($file, 0, "\t")) !== FALSE) { while (($row = fgetcsv($file, 0, "\t")) !== false) {
// Ignore unwanted information at the start of the file. // Ignore unwanted information at the start of the file.
if ($count < 3) { if ($count < 3) {
$count++; $count++;
continue; continue;
} }
if (!$header) { if (!$header) {
$header = $row; $header = $row;
} else { } else {
$this->file_contents = array_combine($header, $row); $this->filecontents = array_combine($header, $row);
} }
$count++; $count++;
} }
fclose($file); fclose($file);
unlink($dir . $filename); unlink($dir . $filename);
// Check if data rows exist. // Check if data rows exist.
if ($count < 2) { if ($count < 2) {
$check = false; $check = false;
@ -95,22 +95,19 @@ class behat_mod_attendance extends behat_base {
* @Given /^I should see "([^"]*)" as "([^"]*)" in the file$/ * @Given /^I should see "([^"]*)" as "([^"]*)" in the file$/
*/ */
public function i_should_see_as_in_the_file($field, $value) { public function i_should_see_as_in_the_file($field, $value) {
foreach ($this->file_contents as $array_field => $array_value) {
if ($field == $array_field) { foreach ($this->filecontents as $arrayfield => $arrayvalue) {
if ($field == $arrayfield) {
if ($value == $array_value) { if ($value == $arrayvalue) {
return true; return true;
} else { } else {
throw new PendingException(); throw new PendingException();
} }
} }
} }
} }
} }

12
update_form.php

@ -48,12 +48,12 @@ class mod_attendance_update_form extends moodleform {
$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); $dhours = floor($sess->duration / HOURSECS);
$dmins = floor(($sess->duration - $dhours * HOURSECS) / MINSECS); $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);
$data = array('sessiondate' => $sess->sessdate, $data = array('sessiondate' => $sess->sessdate,
'durtime' => array('hours' => $dhours, 'minutes' => $dmins), 'durtime' => array('hours' => $dhours, 'minutes' => $dmins),
@ -65,10 +65,10 @@ class mod_attendance_update_form extends moodleform {
userdate($sess->sessdate, get_string('strftimedmyhm', 'attendance'))); userdate($sess->sessdate, get_string('strftimedmyhm', 'attendance')));
$mform->addElement('date_time_selector', 'sessiondate', get_string('newdate', 'attendance')); $mform->addElement('date_time_selector', 'sessiondate', get_string('newdate', 'attendance'));
for ($i=0; $i<=23; $i++) { for ($i = 0; $i <= 23; $i++) {
$hours[$i] = sprintf("%02d", $i); $hours[$i] = sprintf("%02d", $i);
} }
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', 'hours', '', $hours);
@ -86,7 +86,7 @@ class mod_attendance_update_form extends moodleform {
$mform->setDefaults($data); $mform->setDefaults($data);
$submit_string = get_string('update', 'attendance'); $submitstring = get_string('update', 'attendance');
$this->add_action_buttons(true, $submit_string); $this->add_action_buttons(true, $submitstring);
} }
} }

Loading…
Cancel
Save