diff --git a/add_form.php b/add_form.php index 5755187..025de7b 100644 --- a/add_form.php +++ b/add_form.php @@ -65,7 +65,7 @@ class mod_attendance_add_form extends moodleform { $mform->setType('sessiontype', PARAM_INT); break; case VISIBLEGROUPS: - $radio=array(); + $radio = array(); $radio[] = &$mform->createElement('radio', 'sessiontype', '', get_string('commonsession', 'attendance'), attendance::SESSION_COMMON); $radio[] = &$mform->createElement('radio', 'sessiontype', '', @@ -92,7 +92,7 @@ class mod_attendance_add_form extends moodleform { $mform->disabledIf('groups', 'sessiontype', 'neq', attendance::SESSION_GROUP); } else { if ($groupmode == VISIBLEGROUPS) { - $mform->updateElementAttr($radio, array('disabled'=>'disabled')); + $mform->updateElementAttr($radio, array('disabled' => 'disabled')); } $mform->addElement('static', 'groups', get_string('groups', 'group'), get_string('nogroups', 'attendance')); @@ -106,15 +106,15 @@ class mod_attendance_add_form extends moodleform { $mform->addHelpButton('addmultiply', 'createmultiplesessions', '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->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); } - for ($i=0; $i<60; $i+=5) { + for ($i = 0; $i < 60; $i+=5) { $minutes[$i] = sprintf("%02d", $i); } $durtime = array(); @@ -141,18 +141,19 @@ class mod_attendance_add_form extends moodleform { $mform->addGroup($sdays, 'sdays', get_string('sessiondays', 'attendance'), array('     '), true); $mform->disabledIf('sdays', 'addmultiply', 'notchecked'); - $period = array(1=>1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36); + $period = array(1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36); $periodgroup = array(); $periodgroup[] =& $mform->createElement('select', 'period', '', $period, false, true); $periodgroup[] =& $mform->createElement('static', 'perioddesc', '', get_string('week', 'attendance')); $mform->addGroup($periodgroup, 'periodgroup', get_string('period', 'attendance'), array(' '), false); $mform->disabledIf('periodgroup', 'addmultiply', 'notchecked'); - // Select which status set to use: + // Select which status set to use. $maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id); if ($maxstatusset > 0) { $opts = array(); - for ($i=0; $i<=$maxstatusset; $i++) { + for ($i = 0; $i <= $maxstatusset; $i++) { $opts[$i] = att_get_setname($this->_customdata['att']->id, $i); } $mform->addElement('select', 'statusset', get_string('usestatusset', 'mod_attendance'), $opts); @@ -161,8 +162,8 @@ class mod_attendance_add_form extends moodleform { $mform->setType('statusset', PARAM_INT); } - $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), - null, array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext)); + $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), null, + array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext)); $mform->setType('sdescription', PARAM_RAW); $mform->addElement('hidden', 'coursestartdate', $course->startdate); @@ -171,8 +172,8 @@ class mod_attendance_add_form extends moodleform { $mform->addElement('hidden', 'previoussessiondate', 0); $mform->setType('previoussessiondate', PARAM_INT); - $submit_string = get_string('addsession', 'attendance'); - $this->add_action_buttons(false, $submit_string); + $submitstring = get_string('addsession', 'attendance'); + $this->add_action_buttons(false, $submitstring); } /** @@ -183,7 +184,8 @@ class mod_attendance_add_form extends moodleform { public function 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'); } @@ -191,7 +193,7 @@ class mod_attendance_add_form extends moodleform { $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']))) { $data['sdays']= array(); $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']) { - $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']); } @@ -218,9 +221,9 @@ class mod_attendance_add_form extends moodleform { $found = false; $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'); - $end = new DateTime( date("Y-m-d",$sessionenddate) ); + $end = new DateTime( date("Y-m-d", $sessionenddate) ); $end->add( new DateInterval('P1D') ); $period = new DatePeriod($start, $interval, $end); diff --git a/locallib.php b/locallib.php index 4a8df9e..c58c131 100644 --- a/locallib.php +++ b/locallib.php @@ -205,7 +205,7 @@ class att_page_with_filter_controls { if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $PAGE->context)) { $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'); foreach ($allowedgroups as $group) { $this->sessgroupslist[$group->id] = format_string($group->name); @@ -569,7 +569,7 @@ class attendance { $where = "attendanceid = :aid AND sessdate < :csdate"; $params = array( 'aid' => $this->id, - 'csdate'=> $this->course->startdate); + 'csdate' => $this->course->startdate); return $DB->count_records_select('attendance_sessions', $where, $params); } @@ -587,7 +587,7 @@ class attendance { $where = "attendanceid = :aid AND sessdate < :csdate"; $params = array( 'aid' => $this->id, - 'csdate'=> $this->course->startdate); + 'csdate' => $this->course->startdate); return $DB->get_records_select('attendance_sessions', $where, $params); } @@ -731,14 +731,14 @@ class attendance { $sess->description); $DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id)); - $info_array = array(); - $info_array[] = construct_session_full_date_time($sess->sessdate, $sess->duration); + $infoarray = array(); + $infoarray[] = construct_session_full_date_time($sess->sessdate, $sess->duration); // Trigger a session added event. $event = \mod_attendance\event\session_added::create(array( 'objectid' => $this->id, 'context' => $this->context, - 'other' => array('info' => implode(',', $info_array)) + 'other' => array('info' => implode(',', $infoarray)) )); $event->add_record_snapshot('course_modules', $this->cm); $sess->description = $description; @@ -758,7 +758,7 @@ class attendance { } $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'], $this->context->id, 'mod_attendance', 'session', $sessionid, array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $formdata->sdescription['text']); @@ -885,7 +885,7 @@ class attendance { $this->update_users_grade(array_keys($sesslog)); } - // create url for link in log screen + // Create url for link in log screen. $params = array( 'sessionid' => $this->pageparams->sessionid, 'grouptype' => $this->pageparams->grouptype); @@ -898,7 +898,7 @@ class attendance { $event->trigger(); $group = 0; - if ($this->pageparams->grouptype != attendance::SESSION_COMMON) { + if ($this->pageparams->grouptype != self::SESSION_COMMON) { $group = $this->pageparams->grouptype; } else { if ($this->pageparams->group) { @@ -950,7 +950,8 @@ class attendance { '', false, true); } else { $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 { if (!empty($CFG->enablegroupmembersonly) and $this->cm->groupmembersonly) { @@ -972,11 +973,11 @@ class attendance { if (!empty($users)) { 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)'; $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, $mintime AS mintime, $maxtime AS maxtime @@ -986,7 +987,7 @@ class attendance { AND e.status = :estatus AND e.courseid = :courseid 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); foreach ($users as $user) { @@ -1040,7 +1041,7 @@ class attendance { $user->type = 'standard'; - // CONTRIB-4868 + // See CONTRIB-4868. $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'; @@ -1053,7 +1054,7 @@ class attendance { AND e.status = :estatus AND e.courseid = :courseid 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); $user->enrolmentstatus = $enrolments->status; @@ -1134,9 +1135,12 @@ class attendance { public function get_user_taken_sessions_count($userid) { if (!array_key_exists($userid, $this->usertakensesscount)) { 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 { - $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]; @@ -1156,22 +1160,21 @@ class attendance { 'cstartdate' => $this->course->startdate, 'uid' => $userid); - $processed_filters = array(); + $processedfilters = array(); // We test for any valid filters sent. if (isset($filters['enddate'])) { - $processed_filters[] = 'ats.sessdate <= :enddate'; + $processedfilters[] = 'ats.sessdate <= :enddate'; $params['enddate'] = $filters['enddate']; } // Make the filter array into a SQL string. - if (!empty($processed_filters)) { - $processed_filters = ' AND '.implode(' AND ', $processed_filters); + if (!empty($processedfilters)) { + $processedfilters = ' AND '.implode(' AND ', $processedfilters); } else { - $processed_filters = ''; + $processedfilters = ''; } - $period = ''; if (!empty($this->pageparams->startdate) && !empty($this->pageparams->enddate)) { $period = ' AND ats.sessdate >= :sdate AND ats.sessdate < :edate '; @@ -1187,7 +1190,7 @@ class attendance { WHERE ats.attendanceid = :aid AND ats.sessdate >= :cstartdate 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"; } else { $qry = "SELECT al.statusid, count(al.statusid) AS stcnt @@ -1196,7 +1199,7 @@ class attendance { ON al.sessionid = ats.id WHERE ats.attendanceid = :aid AND ats.sessdate >= :cstartdate AND - al.studentid = :uid".$period.$processed_filters." + al.studentid = :uid".$period.$processedfilters." 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. // 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'); if ($this->get_group_mode()) { - $sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks, ats.studentscanmark - FROM {attendance_sessions} ats - RIGHT JOIN {attendance_log} al - ON ats.id = al.sessionid AND al.studentid = :uid - LEFT JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid - WHERE $where AND (ats.groupid = 0 or gm.id is NOT NULL) - ORDER BY ats.sessdate ASC"; + $sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, + al.statusid, al.remarks, ats.studentscanmark + FROM {attendance_sessions} ats + RIGHT JOIN {attendance_log} al + ON ats.id = al.sessionid AND al.studentid = :uid + LEFT JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid + WHERE $where AND (ats.groupid = 0 or gm.id is NOT NULL) + ORDER BY ats.sessdate ASC"; } else { - $sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks, ats.studentscanmark - FROM {attendance_sessions} ats - RIGHT JOIN {attendance_log} al - ON ats.id = al.sessionid AND al.studentid = :uid - WHERE $where - ORDER BY ats.sessdate ASC"; + $sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, + al.statusid, al.remarks, ats.studentscanmark + FROM {attendance_sessions} ats + RIGHT JOIN {attendance_log} al + ON ats.id = al.sessionid AND al.studentid = :uid + WHERE $where + ORDER BY ats.sessdate ASC"; } $params = array( @@ -1355,7 +1361,8 @@ class attendance { $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 LEFT JOIN {attendance_log} al 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)); $event = \mod_attendance\event\status_removed::create(array( 'objectid' => $status->id, - 'context' => $this->context, + 'context' => $this->context, 'other' => array( 'acronym' => $status->acronym, 'description' => $status->description @@ -1508,7 +1515,8 @@ class attendance { $event = \mod_attendance\event\status_updated::create(array( 'objectid' => $this->id, '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('attendance_statuses', $status); $event->trigger(); @@ -1716,9 +1724,9 @@ function att_update_all_users_grades($attid, $course, $context, $coursemodule) { $dbparams = array('id' => -($this->grade)); $this->scale = $DB->get_record('scale', $dbparams); $scalearray = explode(',', $this->scale->scale); - $gradebook_maxgrade = count($scalearray); + $gradebookmaxgrade = count($scalearray); } else { - $gradebook_maxgrade = att_get_gradebook_maxgrade($attid); + $gradebookmaxgrade = att_get_gradebook_maxgrade($attid); } foreach ($userids as $userid) { $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); $usergrade = att_get_user_grade($userstatusesstat, $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; } @@ -1738,7 +1746,7 @@ function att_update_all_users_grades($attid, $course, $context, $coursemodule) { function att_has_logs_for_status($statusid) { 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) { diff --git a/renderables.php b/renderables.php index 575803e..abe8cb6 100644 --- a/renderables.php +++ b/renderables.php @@ -147,7 +147,7 @@ class attendance_filter_controls implements renderable { $format = get_string('strftimedm', 'attendance'); $this->prevcur = 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; case ATT_VIEW_WEEKS: $format = get_string('strftimedm', 'attendance'); @@ -395,24 +395,24 @@ class attendance_user_data implements renderable { continue; } $statuses = att_get_statuses($ca->attid); - $user_taken_sessions_count = 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); + $usertakensessionscount = att_get_user_taken_sessions_count($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->stat[$ca->attid]['completed'] = $user_taken_sessions_count; - $this->stat[$ca->attid]['statuses'] = $user_statuses_stat; + $this->stat[$ca->attid]['completed'] = $usertakensessionscount; + $this->stat[$ca->attid]['statuses'] = $userstatusesstat; $this->gradable[$ca->attid] = $ca->attgrade > 0; 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. // It can have error if users don't have attendance info for some sessions. // In the future we can implement another methods: // * all sessions between user start enrolment date and now; // * 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 { // For more comfortable and universal work with arrays. $this->grade[$ca->attid] = null; @@ -555,8 +555,8 @@ class attendance_preferences_data implements renderable { $this->att = $att; } - public function url($params=array(), $significant_params=true) { - if ($significant_params) { + public function url($params=array(), $significantparams=true) { + if ($significantparams) { $params = array_merge($this->att->pageparams->get_significant_params(), $params); } diff --git a/renderer.php b/renderer.php index b604607..dafa78e 100644 --- a/renderer.php +++ b/renderer.php @@ -94,9 +94,7 @@ class mod_attendance_renderer extends plugin_renderer_base { } protected function render_paging_controls(attendance_filter_controls $fcontrols) { - global $CFG; - - $paging_controls = ''; + $pagingcontrols = ''; $group = 0; 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); - - if (empty($fcontrols->pageparams->page) || !$fcontrols->pageparams->page || !$totalusers || empty($fcontrols->pageparams->perpage)) { - return $paging_controls; + + if (empty($fcontrols->pageparams->page) || !$fcontrols->pageparams->page || !$totalusers || + empty($fcontrols->pageparams->perpage)) { + + return $pagingcontrols; } $numberofpages = ceil($totalusers / $fcontrols->pageparams->perpage); if ($fcontrols->pageparams->page > 1) { - $paging_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->curdate, 'page' => $fcontrols->pageparams->page - 1)), - $this->output->larrow()); + $pagingcontrols .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->curdate, + '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) { - $paging_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->curdate, 'page' => $fcontrols->pageparams->page + 1)), - $this->output->rarrow()); + $pagingcontrols .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->curdate, + 'page' => $fcontrols->pageparams->page + 1)), + $this->output->rarrow()); } - return $paging_controls ; + return $pagingcontrols; } protected function render_curdate_controls(attendance_filter_controls $fcontrols) { global $CFG; - $curdate_controls = ''; + $curdatecontrols = ''; if ($fcontrols->curdatetxt) { $this->page->requires->strings_for_js(array('calclose', 'caltoday'), 'attendance'); $jsvals = array( @@ -135,24 +138,24 @@ class mod_attendance_renderer extends plugin_renderer_base { 'cal_week_days' => explode(',', get_string('calweekdays', 'attendance')), 'cal_start_weekday' => $CFG->calendar_startwday, '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'); - $curdate_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->prevcur)), + $curdatecontrols .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->prevcur)), $this->output->larrow()); $params = array( 'title' => get_string('calshow', 'attendance'), 'id' => 'show', '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) { $params = array( 'type' => 'hidden', 'id' => $name, 'name' => $name, 'value' => $value); - $button_form .= html_writer::empty_tag('input', $params); + $buttonform .= html_writer::empty_tag('input', $params); } $params = array( 'id' => 'currentdate', @@ -160,14 +163,14 @@ class mod_attendance_renderer extends plugin_renderer_base { 'method' => 'post' ); - $button_form = html_writer::tag('form', $button_form, $params); - $curdate_controls .= $button_form; + $buttonform = html_writer::tag('form', $buttonform, $params); + $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()); } - return $curdate_controls; + return $curdatecontrols; } 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][] = $sess->description; $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); @@ -328,26 +332,29 @@ class mod_attendance_renderer extends plugin_renderer_base { } else { $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( 'type' => 'submit', 'value' => get_string('save', 'attendance')); $table .= html_writer::tag('center', html_writer::empty_tag('input', $params)); $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; } - // Calculate the sum of statuses for each user + // Calculate the sum of statuses for each user. $sessionstats[] = array(); foreach ($takedata->sessionlog as $userlog) { - foreach($takedata->statuses as $status) { - if ($userlog->statusid == $status->id) $sessionstats[$status->id]++; + foreach ($takedata->statuses as $status) { + if ($userlog->statusid == $status->id) { + $sessionstats[$status->id]++; + } } } $statsoutput = '
'; - foreach($takedata->statuses as $status) { + foreach ($takedata->statuses as $status) { $statsoutput .= "$status->description = ".$sessionstats[$status->id]."
"; } @@ -379,8 +386,8 @@ class mod_attendance_renderer extends plugin_renderer_base { } private function construct_take_controls(attendance_take_data $takedata) { - GLOBAL $CFG; - + global $CFG; + $controls = ''; $context = context_module::instance($takedata->cm->id); $group = 0; @@ -412,9 +419,11 @@ class mod_attendance_renderer extends plugin_renderer_base { $numberofpages = ceil($totalusers / $usersperpage); 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) { $controls .= html_writer::link($takedata->url(array('page' => $takedata->pageparams->page + 1, '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) { $table = new html_table(); - for ($i=0; $i < $takedata->pageparams->gridcols; $i++) { + for ($i = 0; $i < $takedata->pageparams->gridcols; $i++) { $table->align[] = 'center'; $table->size[] = '110px'; } @@ -682,7 +691,8 @@ class mod_attendance_renderer extends plugin_renderer_base { $table->attributes['class'] = 'userinfobox'; $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); $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) { - global $PAGE; + global $PAGE, $COURSE; // Initilise Javascript used to (un)check all checkboxes. $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'; } - 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. $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. $row->cells[] = html_writer::checkbox('user'.$user->id, 'on', false); } - + $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->cells[] = ''; $statrow->cells[] = get_string('summary'); foreach ($reportdata->sessions as $sess) { foreach ($reportdata->users as $user) { - foreach($reportdata->statuses as $status) { + foreach ($reportdata->statuses as $status) { 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 = '
'; - foreach($reportdata->statuses as $status) { + foreach ($reportdata->statuses as $status) { $statsoutput .= "$status->description:".$sessionstats[$status->id]."
"; } $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. // 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' => 'formaction', 'type' => 'hidden', 'value' => 'messageselect.php')); - $output .= html_writer::empty_tag('input', array('name' => 'id', 'type' => 'hidden', 'value' => $GLOBALS['COURSE']->id)); + $output .= html_writer::empty_tag('input', array('name' => 'formaction', 'type' => 'hidden', + '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::table($table).html_writer::tag('div', get_string('users').': '.count($reportdata->users));; $output .= html_writer::tag('div', @@ -932,7 +944,6 @@ class mod_attendance_renderer extends plugin_renderer_base { } else { 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][] = $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_preferences_actions_icons($st, $prefdata); diff --git a/renderhelpers.php b/renderhelpers.php index 918af32..832127e 100644 --- a/renderhelpers.php +++ b/renderhelpers.php @@ -103,7 +103,7 @@ class user_sessions_cells_generator { protected function construct_not_taken_cell($text) { $this->cells[] = $text; } - + protected function construct_remarks_cell($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->cells[] = $text; } - + protected function construct_remarks_cell($text) { 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 */ 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) { $this->cells[] = '-'.$text; } protected function construct_enrolments_info_cell($text) { - if ($this->enrolments_info_cell_text != $text) { - $this->enrolments_info_cell_text = $text; + if ($this->enrolmentsinfocelltext != $text) { + $this->enrolmentsinfocelltext = $text; $this->cells[] = $text; } else { $this->cells[] = '←'; diff --git a/sessions.php b/sessions.php index 564f9fe..817f98b 100644 --- a/sessions.php +++ b/sessions.php @@ -55,7 +55,7 @@ require_capability('mod/attendance:manageattendances', $context); $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_heading($course->fullname); $PAGE->set_cacheable(true); @@ -71,10 +71,10 @@ switch ($att->pageparams->action) { if ($formdata = $mform->get_data()) { $sessions = construct_sessions_data_for_add($formdata); $att->add_sessions($sessions); - $message = count($sessions) == 1 ? get_string('sessiongenerated', 'attendance') - : get_string('sessionsgenerated', 'attendance', count($sessions)); + $message = count($sessions) == 1 ? get_string('sessiongenerated', 'attendance') : + get_string('sessionsgenerated', 'attendance', count($sessions)); mod_attendance_notifyqueue::notify_success($message); - // 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; redirect($att->url_manage()); } @@ -177,7 +177,7 @@ switch ($att->pageparams->action) { if ($formdata = $mform->get_data()) { $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); redirect($att->url_manage(), get_string('sessionupdated', 'attendance')); } @@ -221,7 +221,7 @@ echo $OUTPUT->footer(); function construct_sessions_data_for_add($formdata) { global $CFG; - $duration = $formdata->durtime['hours']*HOURSECS + $formdata->durtime['minutes']*MINSECS; + $duration = $formdata->durtime['hours'] * HOURSECS + $formdata->durtime['minutes'] * MINSECS; $now = time(); $sessions = array(); @@ -243,17 +243,17 @@ function construct_sessions_data_for_add($formdata) { $startweek = $startdate - $dinfo['wday'] * DAYSECS; // Call new variable. } else { $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) { if ($sdate < $startweek + WEEKSECS) { $dinfo = usergetdate($sdate); if (isset($formdata->sdays) && array_key_exists($wdaydesc[$dinfo['wday']], $formdata->sdays)) { $sess = new stdClass(); - $sess->sessdate = usergetmidnight($sdate) + $starttime; + $sess->sessdate = usergetmidnight($sdate) + $starttime; $sess->duration = $duration; $sess->descriptionitemid = $formdata->sdescription['itemid']; $sess->description = $formdata->sdescription['text']; @@ -281,7 +281,7 @@ function construct_sessions_data_for_add($formdata) { $sess->descriptionformat = $formdata->sdescription['format']; $sess->timemodified = $now; if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance. - $sess->studentscanmark = 1; + $sess->studentscanmark = 1; } $sess->statusset = $formdata->statusset; diff --git a/temp_form.php b/temp_form.php index 1fd5eec..fe7bd32 100644 --- a/temp_form.php +++ b/temp_form.php @@ -28,7 +28,7 @@ global $CFG; require_once($CFG->libdir.'/formslib.php'); class temp_form extends moodleform { - function definition() { + public function definition() { $mform = $this->_form; @@ -49,12 +49,12 @@ class temp_form extends moodleform { $mform->closeHeaderBefore('submit'); } - function definition_after_data() { + public function definition_after_data() { $mform = $this->_form; $mform->applyFilter('tname', 'trim'); } - function validation($data, $files) { + public function validation($data, $files) { $errors = parent::validation($data, $files); if ($err = attendance::check_existing_email($data['temail'])) { diff --git a/tempedit_form.php b/tempedit_form.php index 362b196..5b00433 100644 --- a/tempedit_form.php +++ b/tempedit_form.php @@ -29,7 +29,7 @@ require_once($CFG->libdir.'/formslib.php'); class tempedit_form extends moodleform { - function definition() { + public function definition() { $mform = $this->_form; @@ -55,12 +55,12 @@ class tempedit_form extends moodleform { $mform->closeHeaderBefore('submit'); } - function definition_after_data() { + public function definition_after_data() { $mform = $this->_form; $mform->applyFilter('tname', 'trim'); } - function validation($data, $files) { + public function validation($data, $files) { $errors = parent::validation($data, $files); if ($err = attendance::check_existing_email($data['temail'], $data['userid'])) { diff --git a/tempmerge_form.php b/tempmerge_form.php index 5e5de29..c5e5510 100644 --- a/tempmerge_form.php +++ b/tempmerge_form.php @@ -1,4 +1,18 @@ . defined('MOODLE_INTERNAL') || die(); @@ -7,7 +21,7 @@ require_once($CFG->libdir.'/formslib.php'); class tempmerge_form extends moodleform { - function definition() { + public function definition() { global $COURSE; $context = context_course::instance($COURSE->id); diff --git a/tempusers.php b/tempusers.php index 38c56ba..62bf19b 100644 --- a/tempusers.php +++ b/tempusers.php @@ -45,7 +45,6 @@ $PAGE->set_heading($course->fullname); $PAGE->set_cacheable(true); $PAGE->navbar->add(get_string('tempusers', 'attendance')); -/** @var mod_attendance_renderer $output */ $output = $PAGE->get_renderer('mod_attendance'); $tabs = new attendance_tabs($att, attendance_tabs::TAB_TEMPORARYUSERS); @@ -79,7 +78,7 @@ if ($data = $mform->get_data()) { redirect($att->url_managetemp()); } -/// Output starts here +// Output starts here. echo $output->header(); echo $output->heading(get_string('tempusers', 'attendance').' : '.format_string($course->fullname)); echo $output->render($tabs); @@ -97,14 +96,15 @@ echo $output->footer($course); function print_tempusers($tempusers, attendance $att) { echo '

'; - echo ''; + echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; - $even = false; // used to colour rows + $even = false; // Used to colour rows. foreach ($tempusers as $tempuser) { if ($even) { echo ''; diff --git a/tests/behat/attendance_taken_by_student.php b/tests/behat/attendance_taken_by_student.php index ffc667b..fdf55c1 100644 --- a/tests/behat/attendance_taken_by_student.php +++ b/tests/behat/attendance_taken_by_student.php @@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die(); * @property-read array $other { * Extra information about event properties. * - * @string mode Mode of the report viewed. + * string mode Mode of the report viewed. * } * @package mod_attendance * @since Moodle 2.7 diff --git a/tests/behat/behat_mod_attendance.php b/tests/behat/behat_mod_attendance.php index cbcd3b0..8633a94 100644 --- a/tests/behat/behat_mod_attendance.php +++ b/tests/behat/behat_mod_attendance.php @@ -34,7 +34,7 @@ use Behat\Mink\Exception\ExpectationException as ExpectationException, */ class behat_mod_attendance extends behat_base { - protected $file_contents; + protected $filecontents; /** * @Then /^attendance export file is ok$/ @@ -42,7 +42,7 @@ class behat_mod_attendance extends behat_base { public function attendance_export_file_is_ok() { global $CFG; - + $check = true; // Location selenium will download to. @@ -55,26 +55,26 @@ class behat_mod_attendance extends behat_base { $header = null; // 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. if ($count < 3) { $count++; continue; } - + if (!$header) { $header = $row; } else { - $this->file_contents = array_combine($header, $row); + $this->filecontents = array_combine($header, $row); } - + $count++; } - + fclose($file); unlink($dir . $filename); - + // Check if data rows exist. if ($count < 2) { $check = false; @@ -95,22 +95,19 @@ class behat_mod_attendance extends behat_base { * @Given /^I should see "([^"]*)" as "([^"]*)" in the file$/ */ 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; } else { - throw new PendingException(); - } } } } - } diff --git a/update_form.php b/update_form.php index 2b03195..2959940 100644 --- a/update_form.php +++ b/update_form.php @@ -48,12 +48,12 @@ class mod_attendance_update_form extends moodleform { $modcontext = $this->_customdata['modcontext']; $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'); } $dhours = floor($sess->duration / HOURSECS); $dmins = floor(($sess->duration - $dhours * HOURSECS) / MINSECS); - $defopts = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext); + $defopts = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext); $sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attendance', 'session', $sess->id); $data = array('sessiondate' => $sess->sessdate, 'durtime' => array('hours' => $dhours, 'minutes' => $dmins), @@ -65,10 +65,10 @@ class mod_attendance_update_form extends moodleform { userdate($sess->sessdate, get_string('strftimedmyhm', '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); } - for ($i=0; $i<60; $i+=5) { + for ($i = 0; $i < 60; $i+=5) { $minutes[$i] = sprintf("%02d", $i); } $durselect[] =& $mform->createElement('select', 'hours', '', $hours); @@ -86,7 +86,7 @@ class mod_attendance_update_form extends moodleform { $mform->setDefaults($data); - $submit_string = get_string('update', 'attendance'); - $this->add_action_buttons(true, $submit_string); + $submitstring = get_string('update', 'attendance'); + $this->add_action_buttons(true, $submitstring); } }
'.get_string('tusername', 'attendance').''.get_string('tuseremail', 'attendance').''.get_string('tcreated', 'attendance').''.get_string('tactions', 'attendance').'