Browse Source

More coding guideline fixes

MOODLE_29_STABLE
Dan Marsden 9 years ago
parent
commit
9d92017ff4
  1. 19
      add_form.php
  2. 64
      locallib.php
  3. 16
      renderables.php
  4. 80
      renderer.php
  5. 6
      renderhelpers.php
  6. 6
      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. 15
      tests/behat/behat_mod_attendance.php
  13. 4
      update_form.php

19
add_form.php

@ -141,14 +141,15 @@ class mod_attendance_add_form extends moodleform {
$mform->addGroup($sdays, 'sdays', get_string('sessiondays', 'attendance'), array('     '), true); $mform->addGroup($sdays, 'sdays', get_string('sessiondays', 'attendance'), array('     '), 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();
@ -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');
} }
@ -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']);
} }

64
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);
@ -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;
@ -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
@ -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';
@ -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,10 +1317,12 @@ 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,
al.statusid, al.remarks, ats.studentscanmark
FROM {attendance_sessions} ats FROM {attendance_sessions} ats
RIGHT JOIN {attendance_log} al RIGHT JOIN {attendance_log} al
ON ats.id = al.sessionid AND al.studentid = :uid ON ats.id = al.sessionid AND al.studentid = :uid
@ -1325,7 +1330,8 @@ class attendance {
WHERE $where AND (ats.groupid = 0 or gm.id is NOT NULL) WHERE $where AND (ats.groupid = 0 or gm.id is NOT NULL)
ORDER BY ats.sessdate ASC"; 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,
al.statusid, al.remarks, ats.studentscanmark
FROM {attendance_sessions} ats FROM {attendance_sessions} ats
RIGHT JOIN {attendance_log} al RIGHT JOIN {attendance_log} al
ON ats.id = al.sessionid AND al.studentid = :uid ON ats.id = al.sessionid AND al.studentid = :uid
@ -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
@ -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;
} }

16
renderables.php

@ -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);
} }

80
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)) {
@ -105,29 +103,34 @@ 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,
'page' => $fcontrols->pageparams->page - 1)),
$this->output->larrow()); $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,
'page' => $fcontrols->pageparams->page + 1)),
$this->output->rarrow()); $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,7 +332,8 @@ 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'));
@ -338,11 +343,13 @@ class mod_attendance_renderer extends plugin_renderer_base {
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]++;
}
} }
} }
@ -379,7 +386,7 @@ 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);
@ -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());
@ -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'));
@ -895,7 +904,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$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');
@ -903,7 +912,9 @@ class mod_attendance_renderer extends plugin_renderer_base {
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]++;
}
} }
} }
} }
@ -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);

6
renderhelpers.php

@ -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[] = '←';

6
sessions.php

@ -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());
} }

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

15
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$/
@ -55,7 +55,7 @@ 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) {
@ -66,7 +66,7 @@ class behat_mod_attendance extends behat_base {
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++;
@ -96,21 +96,18 @@ class behat_mod_attendance extends behat_base {
*/ */
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) { foreach ($this->filecontents as $arrayfield => $arrayvalue) {
if ($field == $array_field) { if ($field == $arrayfield) {
if ($value == $array_value) { if ($value == $arrayvalue) {
return true; return true;
} else { } else {
throw new PendingException(); throw new PendingException();
} }
} }
} }
} }
} }

4
update_form.php

@ -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