From 5dc2534a8752d337fda81d122dc1a1c9720d5dca Mon Sep 17 00:00:00 2001 From: Neill Magill Date: Thu, 29 Aug 2013 14:05:07 +0100 Subject: [PATCH 01/14] UoN Changes to allow students to mark their own attendance on sessions that have been set to allow it. Adds a Report that lists only students who do not have full attendance. Adds the Ability to send e-mails to students. --- add_form.php | 4 ++ attendance.php | 84 +++++++++++++++++++++++++ db/install.xml | 1 + db/upgrade.php | 12 +++- lang/en/attendance.php | 8 +++ locallib.php | 124 +++++++++++++++++++++++++++++++------ renderables.php | 38 +++++++++--- renderer.php | 51 ++++++++++++++- report.php | 2 +- sessions.php | 6 ++ student_attenance_form.php | 63 +++++++++++++++++++ version.php | 2 +- view.php | 2 +- 13 files changed, 364 insertions(+), 33 deletions(-) create mode 100644 attendance.php create mode 100644 student_attenance_form.php diff --git a/add_form.php b/add_form.php index dabaeb1..c92893e 100644 --- a/add_form.php +++ b/add_form.php @@ -103,6 +103,10 @@ class mod_attendance_add_form extends moodleform { $mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions', 'attendance')); $mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attendance'); + // Studetns can mark own attendance. + $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark','attforblock')); + $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attforblock'); + $mform->addElement('date_time_selector', 'sessiondate', get_string('sessiondate', 'attendance')); for ($i=0; $i<=23; $i++) { diff --git a/attendance.php b/attendance.php new file mode 100644 index 0000000..9f5699b --- /dev/null +++ b/attendance.php @@ -0,0 +1,84 @@ +. + +/** + * Prints attendance info for particular user + * + * @package mod + * @subpackage attforblock + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(dirname(__FILE__).'/../../config.php'); +require_once(dirname(__FILE__).'/locallib.php'); +require_once(dirname(__FILE__).'/student_attenance_form.php'); + +$pageparams = new att_sessions_page_params(); + +// Check that the required parameters are present. +$id = required_param('sessid', PARAM_INT); +$attendance_session_id = required_param('sessid', PARAM_INT); + + +$attforsession = $DB->get_record('attendance_sessions', array('id' => $id), '*', MUST_EXIST); +$attforblock = $DB->get_record('attforblock', array('id' => $attforsession->attendanceid), '*', MUST_EXIST); +$cm = get_coursemodule_from_instance('attforblock', $attforblock->id, 0, false, MUST_EXIST); +$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + +// Require the user is logged in. +require_login($course, true, $cm); + +$pageparams->sessionid = $id; +$att = new attforblock($attforblock, $cm, $course, $PAGE->context, $pageparams); + +// Require that a session key is passed to this page. +require_sesskey(); + +// Create the form. +$mform = new mod_attforblock_student_attendance_form(null, + array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context, 'session' => $attforsession, 'attendance' => $att)); + +if ($mform->is_cancelled()) { + // The user cancelled the form, so redirect them to the view page. + $url = new moodle_url('/mod/attforblock/view.php', array('id' => $cm->id)); + redirect($url); +} else if ($fromform = $mform->get_data()) { + if (!empty($fromform->status)) { + $success = $att->take_from_student($fromform); + + $url = new moodle_url('/mod/attforblock/view.php', array('id' => $cm->id)); + if ($success) { + // Redirect back to the view page for the block. + redirect($url); + } else { + print_error ('attendance_already_submitted', 'mod_attforblock', $url); + } + } + + // The form did not validate correctly so we will set it to display the data they submitted. + $mform->set_data($fromform); +} + +$PAGE->set_url($att->url_sessions()); +$PAGE->set_title($course->shortname. ": ".$att->name); +$PAGE->set_heading($course->fullname); +$PAGE->set_cacheable(true); +$PAGE->navbar->add($att->name); + +$output = $PAGE->get_renderer('mod_attforblock'); +echo $output->header(); +$mform->display(); +echo $output->footer(); diff --git a/db/install.xml b/db/install.xml index 1bc5a05..ca4e6b0 100644 --- a/db/install.xml +++ b/db/install.xml @@ -30,6 +30,7 @@ + diff --git a/db/upgrade.php b/db/upgrade.php index 0e9336d..2642874 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -32,7 +32,17 @@ function xmldb_attendance_upgrade($oldversion=0) { global $CFG, $THEME, $DB; $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes. - $result = true; + if ($oldversion < 2013082901) { + $table = new xmldb_table('attendance_sessions'); + + $field = new xmldb_field('studentscanmark'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + upgrade_mod_savepoint(true, 2013082901, 'attendance'); + } // UPGRADES from attforblock are only supported for sites that are running attforblock version 2012120700. return $result; diff --git a/lang/en/attendance.php b/lang/en/attendance.php index 5dd803c..8138358 100755 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -208,3 +208,11 @@ $string['viewmode'] = 'View mode'; $string['week'] = 'week(s)'; $string['weeks'] = 'Weeks'; $string['youcantdo'] = 'You can\'t do anything'; +// New strings. +$string['studentscanmark'] = 'Allow students to record own attendance'; +$string['studentscanmark_help'] = 'If checked students will be able to change their own attendance status for the session.'; +$string['set_by_student'] = 'Self-recorded'; +$string['attendance_already_submitted'] = 'You may not self register attendance that has already been set.'; +$string['lowgrade'] = 'Low grade'; +$string['submitattendance'] = 'Submit attendance'; +$string['attendancenotset'] = 'You must set your attendance'; diff --git a/locallib.php b/locallib.php index 1975b0b..7b62f20 100644 --- a/locallib.php +++ b/locallib.php @@ -33,6 +33,7 @@ define('ATT_VIEW_WEEKS', 2); define('ATT_VIEW_MONTHS', 3); define('ATT_VIEW_ALLPAST', 4); define('ATT_VIEW_ALL', 5); +define('ATT_VIEW_NOTPRESENT', 6); define('ATT_SORT_LASTNAME', 1); define('ATT_SORT_FIRSTNAME', 2); @@ -702,6 +703,8 @@ class attendance { if ($this->pageparams->startdate && $this->pageparams->enddate) { $where = "attendanceid = :aid AND sessdate >= :csdate AND sessdate >= :sdate AND sessdate < :edate"; + } else if ($this->pageparams->enddate) { + $where = "attendanceid = :aid AND sessdate >= :csdate AND sessdate < :edate"; } else { $where = "attendanceid = :aid AND sessdate >= :csdate"; } @@ -834,6 +837,57 @@ class attendance { add_to_log($this->course->id, 'attendance', 'session updated', $url, $info, $this->cm->id); } + /** + * Used to record attendance submitted by the student. + * + * @global type $DB + * @global type $USER + * @param type $mformdata + * @return boolean + */ + public function take_from_student($mformdata) { + global $DB, $USER; + + $statuses = implode(',', array_keys( (array)$this->get_statuses() )); + $now = time(); + + $record = new stdClass(); + $record->studentid = $USER->id; + $record->statusid = $mformdata->status; + $record->statusset = $statuses; + $record->remarks = get_string('set_by_student', 'mod_attforblock'); + $record->sessionid = $mformdata->sessid; + $record->timetaken = $now; + $record->takenby = $USER->id; + + $dbsesslog = $this->get_session_log($mformdata->sessid); + if (array_key_exists($record->studentid, $dbsesslog)) { + // Already recorded do not save. + return false; + } + else { + $DB->insert_record('attendance_log', $record, false); + } + + // Update the session to show that a register has been taken, or staff may overwrite records. + $rec = new object(); + $rec->id = $mformdata->sessid; + $rec->lasttaken = $now; + $rec->lasttakenby = $USER->id; + $DB->update_record('attendance_sessions', $rec); + + // Update the users grade. + $this->update_users_grade(array($USER->id)); + + // Log the change. + $params = array( + 'sessionid' => $mformdata->sessid); + $url = $this->url_take($params); + $this->log('attendance taked', $url, $USER->firstname.' '.$USER->lastname); + + return true; + } + public function take_from_form_data($formdata) { global $DB, $USER; // TODO: WARNING - $formdata is unclean - comes from direct $_POST - ideally needs a rewrite but we do some cleaning below. @@ -1016,31 +1070,65 @@ class attendance { return $this->usertakensesscount[$userid]; } - public function get_user_statuses_stat($userid) { + /** + * + * @global type $DB + * @param type $userid + * @param type $filters - An array things to filter by. For now only enddate is valid. + * @return type + */ + public function get_user_statuses_stat($userid, array $filters = null) { global $DB; - if (!array_key_exists($userid, $this->userstatusesstat)) { - $qry = "SELECT al.statusid, count(al.statusid) AS stcnt - FROM {attendance_log} al - JOIN {attendance_sessions} ats - ON al.sessionid = ats.id - WHERE ats.attendanceid = :aid AND - ats.sessdate >= :cstartdate AND - al.studentid = :uid - GROUP BY al.statusid"; - $params = array( - 'aid' => $this->id, - 'cstartdate' => $this->course->startdate, - 'uid' => $userid); + // Need to start setting the parameters here for the filters to work. + $params = array( + 'aid' => $this->id, + 'cstartdate' => $this->course->startdate, + 'uid' => $userid); + + $processed_filters = array(); + // We test for any valid filters sent. + if (isset($filters['enddate'])) { + $processed_filters[] = '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); + } else { + $processed_filters = ''; + } + + $qry = "SELECT al.statusid, count(al.statusid) AS stcnt + FROM {attendance_log} al + JOIN {attendance_sessions} ats + ON al.sessionid = ats.id + WHERE ats.attendanceid = :aid AND + ats.sessdate >= :cstartdate AND + al.studentid = :uid + $processed_filters + GROUP BY al.statusid"; + + if ($filters !== null) { // We do not want to cache, or use a cached version of the results when a filter is set. + return $DB->get_records_sql($qry, $params); + } else if (!array_key_exists($userid, $this->userstatusesstat)) { + // Not filtered so if we do not already have them do the query. $this->userstatusesstat[$userid] = $DB->get_records_sql($qry, $params); } + // Return the cached stats. return $this->userstatusesstat[$userid]; } - public function get_user_grade($userid) { - return att_get_user_grade($this->get_user_statuses_stat($userid), $this->get_statuses()); + /** + * + * @param type $userid + * @param type $filters - An array things to filter by. For now only enddate is valid. + * @return type + */ + public function get_user_grade($userid, array $filters = null) { + return att_get_user_grade($this->get_user_statuses_stat($userid, $filters), $this->get_statuses()); } // For getting sessions count implemented simplest method - taken sessions. @@ -1115,13 +1203,13 @@ class attendance { $where2 = "ats.attendanceid = :aid2 AND ats.sessdate >= :csdate2 AND ats.groupid $gsql"; } - $sql = "SELECT ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks + $sql = "SELECT 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 UNION - SELECT ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, al.statusid, al.remarks + SELECT 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 = :uid2 diff --git a/renderables.php b/renderables.php index 4234bcd..d62ede4 100644 --- a/renderables.php +++ b/renderables.php @@ -109,19 +109,23 @@ class attendance_filter_controls implements renderable { public $prevcur; public $nextcur; public $curdatetxt; + public $reportcontrol; private $urlpath; private $urlparams; private $att; - public function __construct(attendance $att) { + public function __construct(attendance $att, $report = false) { global $PAGE; $this->pageparams = $att->pageparams; $this->cm = $att->cm; + // This is a report control only if $reports is true and the attendance block can be graded. + $this->reportcontrol = $report && ($att->grade > 0); + $this->curdate = $att->pageparams->curdate; $date = usergetdate($att->pageparams->curdate); @@ -456,6 +460,12 @@ class attendance_report_data implements renderable { global $CFG; $this->perm = $att->perm; + + $currenttime = time(); + if ($att->pageparams->view == ATT_VIEW_NOTPRESENT) { + $att->pageparams->enddate = $currenttime; + } + $this->pageparams = $att->pageparams; $this->users = $att->get_users($att->pageparams->group); @@ -473,16 +483,28 @@ class attendance_report_data implements renderable { $this->decimalpoints = $CFG->grade_decimalpoints; } - foreach ($this->users as $user) { - $this->usersgroups[$user->id] = groups_get_all_groups($att->course->id, $user->id); + $maxgrade = att_get_user_max_grade(count($this->sessions), $this->statuses); - $this->sessionslog[$user->id] = $att->get_user_filtered_sessions_log($user->id); + foreach ($this->users as $key => $user) { + $grade = 0; + if ($this->gradable) { + $grade = $att->get_user_grade($user->id, array('enddate' => $currenttime)); + $totalgrade = $att->get_user_grade($user->id); + } - $this->usersstats[$user->id] = $att->get_user_statuses_stat($user->id); + if ($att->pageparams->view != ATT_VIEW_NOTPRESENT || $grade < $maxgrade) { + $this->usersgroups[$user->id] = groups_get_all_groups($att->course->id, $user->id); - if ($this->gradable) { - $this->grades[$user->id] = $att->get_user_grade($user->id); - $this->maxgrades[$user->id] = $att->get_user_max_grade($user->id); + $this->sessionslog[$user->id] = $att->get_user_filtered_sessions_log($user->id); + + $this->usersstats[$user->id] = $att->get_user_statuses_stat($user->id); + + if ($this->gradable) { + $this->grades[$user->id] = $totalgrade; + $this->maxgrades[$user->id] = $att->get_user_max_grade($user->id);; + } + } else { + unset($this->users[$key]); } } diff --git a/renderer.php b/renderer.php index 2b7dae2..6c36945 100644 --- a/renderer.php +++ b/renderer.php @@ -140,6 +140,9 @@ class mod_attendance_renderer extends plugin_renderer_base { protected function render_view_controls(attendance_filter_controls $fcontrols) { $views[ATT_VIEW_ALL] = get_string('all', 'attendance'); $views[ATT_VIEW_ALLPAST] = get_string('allpast', 'attendance'); + if ($fcontrols->reportcontrol) { + $views[ATT_VIEW_NOTPRESENT] = get_string('lowgrade', 'attforblock'); + } $views[ATT_VIEW_MONTHS] = get_string('months', 'attendance'); $views[ATT_VIEW_WEEKS] = get_string('weeks', 'attendance'); $views[ATT_VIEW_DAYS] = get_string('days', 'attendance'); @@ -644,8 +647,17 @@ class mod_attendance_renderer extends plugin_renderer_base { $cell->colspan = 2; $row->cells[] = $cell; } else { - $row->cells[] = '?'; - $row->cells[] = ''; + if (!empty($sess->studentscanmark)) { // Student can mark their own attendance. + // URL to the page that lets the student modify their attendance. + $url = new moodle_url('/mod/attforblock/attendance.php', + array('sessid' => $sess->id, 'sesskey' => sesskey())); + $cell = new html_table_cell(html_writer::link($url, get_string('submitattendance', 'attforblock'))); + $cell->colspan = 2; + $row->cells[] = $cell; + } else { // Student cannot mark their own attendace. + $row->cells[] = '?'; + $row->cells[] = ''; + } } $table->data[] = $row; @@ -661,6 +673,14 @@ class mod_attendance_renderer extends plugin_renderer_base { } protected function render_attendance_report_data(attendance_report_data $reportdata) { + global $PAGE; + + // Initilise Javascript used to (un)check all checkboxes. + $this->page->requires->js_init_call('M.mod_attforblock.init_manage'); + + // Check if the user should be able to bulk send messages to other users on the course. + $bulkmessagecapability = has_capability('moodle/course:bulkmessaging', $PAGE->context); + $table = new html_table(); $table->attributes['class'] = 'generaltable attwidth'; @@ -701,6 +721,13 @@ 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')); + $table->align[] = 'center'; + $table->size[] = '1px'; + } + foreach ($reportdata->users as $user) { $row = new html_table_row(); @@ -722,10 +749,28 @@ class mod_attendance_renderer extends plugin_renderer_base { $row->cells[] = $reportdata->grades[$user->id].' / '.$reportdata->maxgrades[$user->id]; } + if ($bulkmessagecapability) { // Create the checkbox for bulk messaging. + $row->cells[] = html_writer::checkbox('user'.$user->id, 'on', false); + } + $table->data[] = $row; } - return html_writer::table($table); + 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' => 'returnto', 'type' => 'hidden', 'value' => s(me()))); + $output .= html_writer::table($table); + $output .= html_writer::tag('div', + html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('messageselectadd'))), + array('class' => 'buttons')); + $url = new moodle_url('/user/action_redir.php'); + return html_writer::tag('form', $output, array('action' => $url->out(), 'method' => 'post')); + } else { + return html_writer::table($table); + } } protected function render_attendance_preferences_data(attendance_preferences_data $prefdata) { diff --git a/report.php b/report.php index 032c4fd..c928ec9 100644 --- a/report.php +++ b/report.php @@ -56,7 +56,7 @@ $PAGE->navbar->add(get_string('report', 'attendance')); $output = $PAGE->get_renderer('mod_attendance'); $tabs = new attendance_tabs($att, attendance_tabs::TAB_REPORT); $filtercontrols = new attendance_filter_controls($att); -$reportdata = new attendance_report_data($att); +$reportdata = new attendance_report_data($att, true); add_to_log($course->id, 'attendance', 'report viewed', '/mod/attendance/report.php?id='.$id, '', $cm->id); diff --git a/sessions.php b/sessions.php index 046a596..ea44026 100644 --- a/sessions.php +++ b/sessions.php @@ -216,6 +216,9 @@ function construct_sessions_data_for_add($formdata) { $sess->description = $formdata->sdescription['text']; $sess->descriptionformat = $formdata->sdescription['format']; $sess->timemodified = $now; + if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance. + $sess->studentscanmark = 1; + } fill_groupid($formdata, $sessions, $sess); } @@ -233,6 +236,9 @@ function construct_sessions_data_for_add($formdata) { $sess->description = $formdata->sdescription['text']; $sess->descriptionformat = $formdata->sdescription['format']; $sess->timemodified = $now; + if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance. + $sess->studentscanmark = 1; + } fill_groupid($formdata, $sessions, $sess); } diff --git a/student_attenance_form.php b/student_attenance_form.php new file mode 100644 index 0000000..7089b39 --- /dev/null +++ b/student_attenance_form.php @@ -0,0 +1,63 @@ +. + +require_once($CFG->libdir.'/formslib.php'); + +class mod_attforblock_student_attendance_form extends moodleform { + public function definition() { + global $CFG, $USER; + + $mform =& $this->_form; + + $course = $this->_customdata['course']; + $cm = $this->_customdata['cm']; + $modcontext = $this->_customdata['modcontext']; + $attforsession = $this->_customdata['session']; + $attblock = $this->_customdata['attendance']; + + $statuses = $attblock->get_statuses(); + + $mform->addElement('hidden', 'sessid', null); + $mform->setType('sessid', PARAM_INT); + $mform->setConstant('sessid', $attforsession->id); + + $mform->addElement('hidden', 'sesskey', null); + $mform->setType('sesskey', PARAM_INT); + $mform->setConstant('sesskey', sesskey()); + + // Set a title as the date and time of the session. + $sesstiontitle = userdate($attforsession->sessdate, get_string('strftimedate')).' ' + .userdate($attforsession->sessdate, get_string('strftimehm', 'mod_attforblock')); + + $mform->addElement('header', 'session', $sesstiontitle); + + // If a session description is set display it. + if (!empty($attforsession->description)) { + $mform->addElement('html', $attforsession->description); + } + + // Create radio buttons for setting the attendance status. + $radioarray = array(); + foreach ($statuses as $status) { + $radioarray[] =& $mform->createElement('radio', 'status', '', $status->description, $status->id, array()); + } + // Add the radio buttons as a control with the user's name in front. + $mform->addGroup($radioarray, 'statusarray', $USER->firstname.' '.$USER->lastname.':', array(''), false); + $mform->addRule('statusarray', get_string('attendancenotset', 'attforblock'), 'required', '', 'client', false, false); + + $this->add_action_buttons(); + } +} \ No newline at end of file diff --git a/version.php b/version.php index e7ab8e3..d36b123 100644 --- a/version.php +++ b/version.php @@ -22,7 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$module->version = 2013082900; +$module->version = 2013082901; $module->requires = 2013040500; $module->release = '2.5.1'; $module->maturity = MATURITY_STABLE; diff --git a/view.php b/view.php index 5117605..19e288d 100644 --- a/view.php +++ b/view.php @@ -63,7 +63,7 @@ $PAGE->navbar->add(get_string('attendancereport', 'attendance')); $output = $PAGE->get_renderer('mod_attendance'); -$userid = isset($pageparams->studentid) ? $pageparams->studentid : $USER->id; +$userid = (isset($pageparams->studentid) && ($att->perm->can_manage() || $att->perm->can_take() || $att->perm->can_change())) ? $pageparams->studentid : $USER->id; $userdata = new attendance_user_data($att, $userid); echo $output->header(); From ee20e101bb56c2307bf886d1a14cf58a63d3ece7 Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Wed, 21 May 2014 14:51:27 +0100 Subject: [PATCH 02/14] first round of fixes --- add_form.php | 6 +++--- attendance.php | 18 +++++++++--------- .../backup_attendance_activity_task.class.php | 4 ++-- .../restore_attendance_activity_task.class.php | 4 ++-- locallib.php | 6 +++--- renderer.php | 8 ++++---- student_attenance_form.php | 6 +++--- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/add_form.php b/add_form.php index c92893e..9877980 100644 --- a/add_form.php +++ b/add_form.php @@ -103,9 +103,9 @@ class mod_attendance_add_form extends moodleform { $mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions', 'attendance')); $mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attendance'); - // Studetns can mark own attendance. - $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark','attforblock')); - $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attforblock'); + // Students can mark own attendance. + $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark','attendance')); + $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance'); $mform->addElement('date_time_selector', 'sessiondate', get_string('sessiondate', 'attendance')); diff --git a/attendance.php b/attendance.php index 9f5699b..539354c 100644 --- a/attendance.php +++ b/attendance.php @@ -18,7 +18,7 @@ * Prints attendance info for particular user * * @package mod - * @subpackage attforblock + * @subpackage attendance * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -34,37 +34,37 @@ $attendance_session_id = required_param('sessid', PARAM_INT); $attforsession = $DB->get_record('attendance_sessions', array('id' => $id), '*', MUST_EXIST); -$attforblock = $DB->get_record('attforblock', array('id' => $attforsession->attendanceid), '*', MUST_EXIST); -$cm = get_coursemodule_from_instance('attforblock', $attforblock->id, 0, false, MUST_EXIST); +$attendance = $DB->get_record('attendance', array('id' => $attforsession->attendanceid), '*', MUST_EXIST); +$cm = get_coursemodule_from_instance('attendance', $attendance->id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); // Require the user is logged in. require_login($course, true, $cm); $pageparams->sessionid = $id; -$att = new attforblock($attforblock, $cm, $course, $PAGE->context, $pageparams); +$att = new attendance($attendance, $cm, $course, $PAGE->context, $pageparams); // Require that a session key is passed to this page. require_sesskey(); // Create the form. -$mform = new mod_attforblock_student_attendance_form(null, +$mform = new mod_attendance_student_attendance_form(null, array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context, 'session' => $attforsession, 'attendance' => $att)); if ($mform->is_cancelled()) { // The user cancelled the form, so redirect them to the view page. - $url = new moodle_url('/mod/attforblock/view.php', array('id' => $cm->id)); + $url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id)); redirect($url); } else if ($fromform = $mform->get_data()) { if (!empty($fromform->status)) { $success = $att->take_from_student($fromform); - $url = new moodle_url('/mod/attforblock/view.php', array('id' => $cm->id)); + $url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id)); if ($success) { // Redirect back to the view page for the block. redirect($url); } else { - print_error ('attendance_already_submitted', 'mod_attforblock', $url); + print_error ('attendance_already_submitted', 'mod_attendance', $url); } } @@ -78,7 +78,7 @@ $PAGE->set_heading($course->fullname); $PAGE->set_cacheable(true); $PAGE->navbar->add($att->name); -$output = $PAGE->get_renderer('mod_attforblock'); +$output = $PAGE->get_renderer('mod_attendance'); echo $output->header(); $mform->display(); echo $output->footer(); diff --git a/backup/moodle2/backup_attendance_activity_task.class.php b/backup/moodle2/backup_attendance_activity_task.class.php index 87b5c89..df3b4a0 100644 --- a/backup/moodle2/backup_attendance_activity_task.class.php +++ b/backup/moodle2/backup_attendance_activity_task.class.php @@ -60,11 +60,11 @@ class backup_attendance_activity_task extends backup_activity_task { // Link to attendance view by moduleid. $search = "/(" . $base . "\/mod\/attendance\/view.php\?id\=)([0-9]+)/"; - $content= preg_replace($search, '$@ATTFORBLOCKVIEWBYID*$2@$', $content); + $content= preg_replace($search, '$@ATTENDANCEVIEWBYID*$2@$', $content); // Link to attendance view by moduleid and studentid. $search = "/(" . $base . "\/mod\/attendance\/view.php\?id\=)([0-9]+)\&studentid\=([0-9]+)/"; - $content= preg_replace($search, '$@ATTFORBLOCKVIEWBYIDSTUD*$2*$3@$', $content); + $content= preg_replace($search, '$@ATTENDANCEVIEWBYIDSTUD*$2*$3@$', $content); return $content; } diff --git a/backup/moodle2/restore_attendance_activity_task.class.php b/backup/moodle2/restore_attendance_activity_task.class.php index 5ca7794..629cecd 100644 --- a/backup/moodle2/restore_attendance_activity_task.class.php +++ b/backup/moodle2/restore_attendance_activity_task.class.php @@ -67,9 +67,9 @@ class restore_attendance_activity_task extends restore_activity_task { static public function define_decode_rules() { $rules = array(); - $rules[] = new restore_decode_rule('ATTFORBLOCKVIEWBYID', + $rules[] = new restore_decode_rule('ATTENDANCEVIEWBYID', '/mod/attendance/view.php?id=$1', 'course_module'); - $rules[] = new restore_decode_rule('ATTFORBLOCKVIEWBYIDSTUD', + $rules[] = new restore_decode_rule('ATTENDANCEVIEWBYIDSTUD', '/mod/attendance/view.php?id=$1&studentid=$2', array('course_module', 'user')); return $rules; diff --git a/locallib.php b/locallib.php index 7b62f20..4b03cef 100644 --- a/locallib.php +++ b/locallib.php @@ -855,7 +855,7 @@ class attendance { $record->studentid = $USER->id; $record->statusid = $mformdata->status; $record->statusset = $statuses; - $record->remarks = get_string('set_by_student', 'mod_attforblock'); + $record->remarks = get_string('set_by_student', 'mod_attendance'); $record->sessionid = $mformdata->sessid; $record->timetaken = $now; $record->takenby = $USER->id; @@ -883,8 +883,8 @@ class attendance { $params = array( 'sessionid' => $mformdata->sessid); $url = $this->url_take($params); - $this->log('attendance taked', $url, $USER->firstname.' '.$USER->lastname); - + add_to_log($this->course->id, 'attendance', 'taken', $url, '', $USER->id); + return true; } diff --git a/renderer.php b/renderer.php index 6c36945..7d06d88 100644 --- a/renderer.php +++ b/renderer.php @@ -141,7 +141,7 @@ class mod_attendance_renderer extends plugin_renderer_base { $views[ATT_VIEW_ALL] = get_string('all', 'attendance'); $views[ATT_VIEW_ALLPAST] = get_string('allpast', 'attendance'); if ($fcontrols->reportcontrol) { - $views[ATT_VIEW_NOTPRESENT] = get_string('lowgrade', 'attforblock'); + $views[ATT_VIEW_NOTPRESENT] = get_string('lowgrade', 'attendance'); } $views[ATT_VIEW_MONTHS] = get_string('months', 'attendance'); $views[ATT_VIEW_WEEKS] = get_string('weeks', 'attendance'); @@ -649,9 +649,9 @@ class mod_attendance_renderer extends plugin_renderer_base { } else { if (!empty($sess->studentscanmark)) { // Student can mark their own attendance. // URL to the page that lets the student modify their attendance. - $url = new moodle_url('/mod/attforblock/attendance.php', + $url = new moodle_url('/mod/attendance/attendance.php', array('sessid' => $sess->id, 'sesskey' => sesskey())); - $cell = new html_table_cell(html_writer::link($url, get_string('submitattendance', 'attforblock'))); + $cell = new html_table_cell(html_writer::link($url, get_string('submitattendance', 'attendance'))); $cell->colspan = 2; $row->cells[] = $cell; } else { // Student cannot mark their own attendace. @@ -676,7 +676,7 @@ class mod_attendance_renderer extends plugin_renderer_base { global $PAGE; // Initilise Javascript used to (un)check all checkboxes. - $this->page->requires->js_init_call('M.mod_attforblock.init_manage'); + $this->page->requires->js_init_call('M.mod_attendance.init_manage'); // Check if the user should be able to bulk send messages to other users on the course. $bulkmessagecapability = has_capability('moodle/course:bulkmessaging', $PAGE->context); diff --git a/student_attenance_form.php b/student_attenance_form.php index 7089b39..5f7d7d7 100644 --- a/student_attenance_form.php +++ b/student_attenance_form.php @@ -16,7 +16,7 @@ require_once($CFG->libdir.'/formslib.php'); -class mod_attforblock_student_attendance_form extends moodleform { +class mod_attendance_student_attendance_form extends moodleform { public function definition() { global $CFG, $USER; @@ -40,7 +40,7 @@ class mod_attforblock_student_attendance_form extends moodleform { // Set a title as the date and time of the session. $sesstiontitle = userdate($attforsession->sessdate, get_string('strftimedate')).' ' - .userdate($attforsession->sessdate, get_string('strftimehm', 'mod_attforblock')); + .userdate($attforsession->sessdate, get_string('strftimehm', 'mod_attendance')); $mform->addElement('header', 'session', $sesstiontitle); @@ -56,7 +56,7 @@ class mod_attforblock_student_attendance_form extends moodleform { } // Add the radio buttons as a control with the user's name in front. $mform->addGroup($radioarray, 'statusarray', $USER->firstname.' '.$USER->lastname.':', array(''), false); - $mform->addRule('statusarray', get_string('attendancenotset', 'attforblock'), 'required', '', 'client', false, false); + $mform->addRule('statusarray', get_string('attendancenotset', 'attendance'), 'required', '', 'client', false, false); $this->add_action_buttons(); } From db23bb526f426c7d82c0935402777c1024e61f4e Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Wed, 21 May 2014 16:41:34 +0100 Subject: [PATCH 03/14] fix for log page link --- locallib.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/locallib.php b/locallib.php index 4b03cef..f40fded 100644 --- a/locallib.php +++ b/locallib.php @@ -879,10 +879,23 @@ class attendance { // Update the users grade. $this->update_users_grade(array($USER->id)); - // Log the change. + /* create url for link in log screen + * need to set grouptype to 0 to allow take attendance page to be called + * from report/log page */ + $params = array( - 'sessionid' => $mformdata->sessid); - $url = $this->url_take($params); + 'sessionid' => $this->pageparams->sessionid, + 'grouptype' => 0, + 'id' => $this->cm->id); + + $url = 'take.php?'; + foreach ($params as $param => $value) { + $url = $url . $param . '=' . $value . '&'; + } + + $url = rtrim($url,'&'); + + // Log the change. add_to_log($this->course->id, 'attendance', 'taken', $url, '', $USER->id); return true; @@ -935,10 +948,19 @@ class attendance { $this->update_users_grade(array_keys($sesslog)); } + // create url for link in log screen $params = array( 'sessionid' => $this->pageparams->sessionid, - 'grouptype' => $this->pageparams->grouptype); - $url = $this->url_take($params); + 'grouptype' => $this->pageparams->grouptype, + 'id' => $this->cm->id); + + $url = 'take.php?'; + foreach ($params as $param => $value) { + $url = $url . $param . '=' . $value . '&'; + } + + $url = rtrim($url,'&'); + add_to_log($this->course->id, 'attendance', 'taken', $url, '', $this->cm->id); redirect($this->url_manage(), get_string('attendancesuccess', 'attendance')); From 066ac506029f3ad8de38612b83cb925b5263e56c Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Thu, 22 May 2014 10:05:00 +0100 Subject: [PATCH 04/14] low grade report fix --- report.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/report.php b/report.php index c928ec9..addb4f6 100644 --- a/report.php +++ b/report.php @@ -55,8 +55,8 @@ $PAGE->navbar->add(get_string('report', 'attendance')); $output = $PAGE->get_renderer('mod_attendance'); $tabs = new attendance_tabs($att, attendance_tabs::TAB_REPORT); -$filtercontrols = new attendance_filter_controls($att); -$reportdata = new attendance_report_data($att, true); +$filtercontrols = new attendance_filter_controls($att, true); +$reportdata = new attendance_report_data($att); add_to_log($course->id, 'attendance', 'report viewed', '/mod/attendance/report.php?id='.$id, '', $cm->id); From 28bc551ab4e09624fcee1478f07c9ec3e0fbd8dc Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Thu, 22 May 2014 10:41:57 +0100 Subject: [PATCH 05/14] found log function in attforblock --- locallib.php | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/locallib.php b/locallib.php index f40fded..651d6a0 100644 --- a/locallib.php +++ b/locallib.php @@ -811,8 +811,8 @@ class attendance { } $i++; } - add_to_log($this->course->id, 'attendance', 'sessions added', $this->url_manage(), - implode(',', $info_array), $this->cm->id); + + $this->log('sessions added', $this->url_manage(), implode(', ', $info_array)); } public function update_session_from_form_data($formdata, $sessionid) { @@ -834,7 +834,7 @@ class attendance { $url = $this->url_sessions(array('sessionid' => $sessionid, 'action' => att_sessions_page_params::ACTION_UPDATE)); $info = construct_session_full_date_time($sess->sessdate, $sess->duration); - add_to_log($this->course->id, 'attendance', 'session updated', $url, $info, $this->cm->id); + $this->log('session updated', $url, $info); } /** @@ -885,18 +885,12 @@ class attendance { $params = array( 'sessionid' => $this->pageparams->sessionid, - 'grouptype' => 0, - 'id' => $this->cm->id); - - $url = 'take.php?'; - foreach ($params as $param => $value) { - $url = $url . $param . '=' . $value . '&'; - } - - $url = rtrim($url,'&'); + 'grouptype' => 0); + + $url = $this->url_take($params); // Log the change. - add_to_log($this->course->id, 'attendance', 'taken', $url, '', $USER->id); + $this->log('attendance taken', $url, $USER->firstname.' '.$USER->lastname); return true; } @@ -951,17 +945,12 @@ class attendance { // create url for link in log screen $params = array( 'sessionid' => $this->pageparams->sessionid, - 'grouptype' => $this->pageparams->grouptype, - 'id' => $this->cm->id); + 'grouptype' => $this->pageparams->grouptype); + + $url = $this->url_take($params); - $url = 'take.php?'; - foreach ($params as $param => $value) { - $url = $url . $param . '=' . $value . '&'; - } - - $url = rtrim($url,'&'); - - add_to_log($this->course->id, 'attendance', 'taken', $url, '', $this->cm->id); + // Log the change. + $this->log('attendance taken', $url, $USER->firstname.' '.$USER->lastname); redirect($this->url_manage(), get_string('attendancesuccess', 'attendance')); } @@ -1270,8 +1259,7 @@ class attendance { list($sql, $params) = $DB->get_in_or_equal($sessionsids); $DB->delete_records_select('attendance_log', "sessionid $sql", $params); $DB->delete_records_list('attendance_sessions', 'id', $sessionsids); - add_to_log($this->course->id, 'attendance', 'sessions deleted', $this->url_manage(), - get_string('sessionsids', 'attendance').implode(', ', $sessionsids), $this->cm->id); + $this->log('sessions deleted', null, get_string('sessionsids', 'attforblock').implode(', ', $sessionsids)); } public function update_sessions_duration($sessionsids, $duration) { @@ -1284,8 +1272,8 @@ class attendance { $sess->timemodified = $now; $DB->update_record('attendance_sessions', $sess); } - add_to_log($this->course->id, 'attendance', 'sessions duration updated', $this->url_manage(), - get_string('sessionsids', 'attendance').implode(', ', $sessionsids), $this->cm->id); + + $this->log('sessions duration updated', $this->url_manage(), get_string('sessionsids', 'attforblock').implode(', ', $sessionsids)); } public function remove_status($statusid) { @@ -1306,8 +1294,7 @@ class attendance { $rec->grade = $grade; $DB->insert_record('attendance_statuses', $rec); - add_to_log($this->course->id, 'attendance', 'status added', $this->url_preferences(), - $acronym.': '.$description.' ('.$grade.')', $this->cm->id); + $this->log('status added', $this->url_preferences(), $acronym.': '.$description.' ('.$grade.')'); } else { print_error('cantaddstatus', 'attendance', $this->url_preferences()); } @@ -1338,8 +1325,7 @@ class attendance { } $DB->update_record('attendance_statuses', $status); - add_to_log($this->course->id, 'attendance', 'status updated', $this->url_preferences(), - implode(' ', $updated), $this->cm->id); + $this->log('status updated', $this->url_preferences(), implode(' ', $updated)); } } From d39f0367f1e816b0603e274b51a63e17d57b1ae6 Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Thu, 22 May 2014 10:57:08 +0100 Subject: [PATCH 06/14] removed duplicate log word --- locallib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locallib.php b/locallib.php index 651d6a0..966de68 100644 --- a/locallib.php +++ b/locallib.php @@ -890,7 +890,7 @@ class attendance { $url = $this->url_take($params); // Log the change. - $this->log('attendance taken', $url, $USER->firstname.' '.$USER->lastname); + $this->log('taken by student', $url, $USER->firstname.' '.$USER->lastname); return true; } @@ -950,7 +950,7 @@ class attendance { $url = $this->url_take($params); // Log the change. - $this->log('attendance taken', $url, $USER->firstname.' '.$USER->lastname); + $this->log('taken', $url, $USER->firstname.' '.$USER->lastname); redirect($this->url_manage(), get_string('attendancesuccess', 'attendance')); } From 5909afa1a459b664e28e85402641f9a3a4ae1478 Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Fri, 23 May 2014 11:21:10 +0100 Subject: [PATCH 07/14] changes attforblock to attendance --- locallib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locallib.php b/locallib.php index 966de68..cda5fc5 100644 --- a/locallib.php +++ b/locallib.php @@ -1259,7 +1259,7 @@ class attendance { list($sql, $params) = $DB->get_in_or_equal($sessionsids); $DB->delete_records_select('attendance_log', "sessionid $sql", $params); $DB->delete_records_list('attendance_sessions', 'id', $sessionsids); - $this->log('sessions deleted', null, get_string('sessionsids', 'attforblock').implode(', ', $sessionsids)); + $this->log('sessions deleted', null, get_string('sessionsids', 'attendance').implode(', ', $sessionsids)); } public function update_sessions_duration($sessionsids, $duration) { @@ -1273,7 +1273,7 @@ class attendance { $DB->update_record('attendance_sessions', $sess); } - $this->log('sessions duration updated', $this->url_manage(), get_string('sessionsids', 'attforblock').implode(', ', $sessionsids)); + $this->log('sessions duration updated', $this->url_manage(), get_string('sessionsids', 'attendance').implode(', ', $sessionsids)); } public function remove_status($statusid) { From 4be6603034be46b004af6e40f9ab1e6cc0e30030 Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Fri, 23 May 2014 14:47:22 +0100 Subject: [PATCH 08/14] MOODLE-845 add idnumber to export --- export.php | 7 ++++++- export_form.php | 7 ++++--- locallib.php | 6 +++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/export.php b/export.php index 57d7ebc..13949e5 100644 --- a/export.php +++ b/export.php @@ -87,10 +87,12 @@ if ($mform->is_submitted()) { if (isset($formdata->ident['uname'])) { $data->tabhead[] = get_string('username'); } + if (isset($formdata->ident['idnumber'])) { + $data->tabhead[] = get_string('idnumber'); + } $data->tabhead[] = get_string('lastname'); $data->tabhead[] = get_string('firstname'); - if (count($reportdata->sessions) > 0) { foreach ($reportdata->sessions as $sess) { $text = userdate($sess->sessdate, get_string('strftimedmyhm', 'attendance')); @@ -114,6 +116,9 @@ if ($mform->is_submitted()) { if (isset($formdata->ident['uname'])) { $data->table[$i][] = $user->username; } + if (isset($formdata->ident['idnumber'])) { + $data->table[$i][] = $user->idnumber; + } $data->table[$i][] = $user->lastname; $data->table[$i][] = $user->firstname; $cellsgenerator = new user_sessions_cells_text_generator($reportdata, $user); diff --git a/export_form.php b/export_form.php index e43e1c6..5ec04f1 100644 --- a/export_form.php +++ b/export_form.php @@ -62,13 +62,14 @@ class mod_attendance_export_form extends moodleform { $ident = array(); $ident[] =& $mform->createElement('checkbox', 'id', '', get_string('studentid', 'attendance')); - $ident[] =& $mform->createElement('checkbox', 'uname', '', get_string('username')); + $ident[] =& $mform->createElement('checkbox', 'idnumber', '', get_string('idnumber')); $mform->addGroup($ident, 'ident', get_string('identifyby', 'attendance'), array('
'), true); - $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true)); + $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true, 'ident[idnumber]' => false)); $mform->setType('id', PARAM_INT); $mform->setType('uname', PARAM_INT); - + $mform->setType('idnumber', PARAM_NOTAGS); + $mform->addElement('checkbox', 'includeallsessions', get_string('includeall', 'attendance'), get_string('yes')); $mform->setDefault('includeallsessions', true); $mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attendance'), get_string('yes')); diff --git a/locallib.php b/locallib.php index cda5fc5..5fa8fd6 100644 --- a/locallib.php +++ b/locallib.php @@ -962,12 +962,12 @@ class attendance { global $DB; // Fields we need from the user table. - $userfields = user_picture::fields('u').',u.username'; + $userfields = user_picture::fields('u').',u.username,u.idnumber'; if (isset($this->pageparams->sort) and ($this->pageparams->sort == ATT_SORT_FIRSTNAME)) { - $orderby = "u.firstname ASC, u.lastname ASC"; + $orderby = "u.firstname ASC, u.lastname ASC, u.idnumber ASC"; } else { - $orderby = "u.lastname ASC, u.firstname ASC"; + $orderby = "u.lastname ASC, u.firstname ASC, u.idnumber ASC"; } $users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, $orderby); From 8ddd624c6c6ad6a3f364875d0533ce4759a238ff Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Fri, 23 May 2014 15:12:51 +0100 Subject: [PATCH 09/14] MOODLE-845 add department and institution --- export.php | 12 ++++++++++++ export_form.php | 11 ++++++++--- locallib.php | 6 +++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/export.php b/export.php index 13949e5..ad6bcf0 100644 --- a/export.php +++ b/export.php @@ -90,6 +90,12 @@ if ($mform->is_submitted()) { if (isset($formdata->ident['idnumber'])) { $data->tabhead[] = get_string('idnumber'); } + if (isset($formdata->ident['institution'])) { + $data->tabhead[] = get_string('institution'); + } + if (isset($formdata->ident['department'])) { + $data->tabhead[] = get_string('department'); + } $data->tabhead[] = get_string('lastname'); $data->tabhead[] = get_string('firstname'); @@ -119,6 +125,12 @@ if ($mform->is_submitted()) { if (isset($formdata->ident['idnumber'])) { $data->table[$i][] = $user->idnumber; } + if (isset($formdata->ident['institution'])) { + $data->table[$i][] = $user->institution; + } + if (isset($formdata->ident['department'])) { + $data->table[$i][] = $user->department; + } $data->table[$i][] = $user->lastname; $data->table[$i][] = $user->firstname; $cellsgenerator = new user_sessions_cells_text_generator($reportdata, $user); diff --git a/export_form.php b/export_form.php index 5ec04f1..351d21f 100644 --- a/export_form.php +++ b/export_form.php @@ -63,12 +63,17 @@ class mod_attendance_export_form extends moodleform { $ident = array(); $ident[] =& $mform->createElement('checkbox', 'id', '', get_string('studentid', 'attendance')); $ident[] =& $mform->createElement('checkbox', 'uname', '', get_string('username')); - $ident[] =& $mform->createElement('checkbox', 'idnumber', '', get_string('idnumber')); + + $optional = array('idnumber', 'institution', 'department'); + foreach ($optional as $opt) { + $ident[] =& $mform->createElement('checkbox', $opt, '', get_string($opt)); + $mform->setType($opt, PARAM_NOTAGS); + } + $mform->addGroup($ident, 'ident', get_string('identifyby', 'attendance'), array('
'), true); - $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true, 'ident[idnumber]' => false)); + $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true)); $mform->setType('id', PARAM_INT); $mform->setType('uname', PARAM_INT); - $mform->setType('idnumber', PARAM_NOTAGS); $mform->addElement('checkbox', 'includeallsessions', get_string('includeall', 'attendance'), get_string('yes')); $mform->setDefault('includeallsessions', true); diff --git a/locallib.php b/locallib.php index 5fa8fd6..c2b257c 100644 --- a/locallib.php +++ b/locallib.php @@ -962,12 +962,12 @@ class attendance { global $DB; // Fields we need from the user table. - $userfields = user_picture::fields('u').',u.username,u.idnumber'; + $userfields = user_picture::fields('u').',u.username,u.idnumber,u.institution,u.department'; if (isset($this->pageparams->sort) and ($this->pageparams->sort == ATT_SORT_FIRSTNAME)) { - $orderby = "u.firstname ASC, u.lastname ASC, u.idnumber ASC"; + $orderby = "u.firstname ASC, u.lastname ASC, u.idnumber ASC, u.institution ASC, u.department ASC"; } else { - $orderby = "u.lastname ASC, u.firstname ASC, u.idnumber ASC"; + $orderby = "u.lastname ASC, u.firstname ASC, u.idnumber ASC, u.institution ASC, u.department ASC"; } $users = get_enrolled_users($this->context, 'mod/attendance:canbelisted', $groupid, $userfields, $orderby); From 2de47f26cec0739e50e00675c5e898e0612c98c5 Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Fri, 23 May 2014 15:43:18 +0100 Subject: [PATCH 10/14] tidy up --- export.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/export.php b/export.php index ad6bcf0..fab396f 100644 --- a/export.php +++ b/export.php @@ -87,15 +87,14 @@ if ($mform->is_submitted()) { if (isset($formdata->ident['uname'])) { $data->tabhead[] = get_string('username'); } - if (isset($formdata->ident['idnumber'])) { - $data->tabhead[] = get_string('idnumber'); - } - if (isset($formdata->ident['institution'])) { - $data->tabhead[] = get_string('institution'); - } - if (isset($formdata->ident['department'])) { - $data->tabhead[] = get_string('department'); + + $optional = array('idnumber', 'institution', 'department'); + foreach ($optional as $opt) { + if (isset($formdata->ident[$opt])) { + $data->tabhead[] = get_string($opt); + } } + $data->tabhead[] = get_string('lastname'); $data->tabhead[] = get_string('firstname'); @@ -122,15 +121,14 @@ if ($mform->is_submitted()) { if (isset($formdata->ident['uname'])) { $data->table[$i][] = $user->username; } - if (isset($formdata->ident['idnumber'])) { - $data->table[$i][] = $user->idnumber; - } - if (isset($formdata->ident['institution'])) { - $data->table[$i][] = $user->institution; - } - if (isset($formdata->ident['department'])) { - $data->table[$i][] = $user->department; + + $optional_row = array('idnumber', 'institution', 'department'); + foreach ($$optional_row as $opt) { + if (isset($formdata->ident[$opt])) { + $data->table[$i][] = $user->$opt; + } } + $data->table[$i][] = $user->lastname; $data->table[$i][] = $user->firstname; $cellsgenerator = new user_sessions_cells_text_generator($reportdata, $user); From aa12bb4f2240c947f8f502f709fca6f33b27cba6 Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Fri, 23 May 2014 15:45:20 +0100 Subject: [PATCH 11/14] typo --- export.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/export.php b/export.php index fab396f..995e937 100644 --- a/export.php +++ b/export.php @@ -123,7 +123,7 @@ if ($mform->is_submitted()) { } $optional_row = array('idnumber', 'institution', 'department'); - foreach ($$optional_row as $opt) { + foreach ($optional_row as $opt) { if (isset($formdata->ident[$opt])) { $data->table[$i][] = $user->$opt; } From a1e9d1ff60142be359d8e87e89710aa712d69b08 Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Tue, 27 May 2014 08:55:04 +0100 Subject: [PATCH 12/14] code review: removed new line --- export_form.php | 1 - 1 file changed, 1 deletion(-) diff --git a/export_form.php b/export_form.php index 351d21f..0751090 100644 --- a/export_form.php +++ b/export_form.php @@ -74,7 +74,6 @@ class mod_attendance_export_form extends moodleform { $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true)); $mform->setType('id', PARAM_INT); $mform->setType('uname', PARAM_INT); - $mform->addElement('checkbox', 'includeallsessions', get_string('includeall', 'attendance'), get_string('yes')); $mform->setDefault('includeallsessions', true); $mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attendance'), get_string('yes')); From cdd1079f667f044ec3325f2d436019387d55f7d4 Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Tue, 27 May 2014 08:59:22 +0100 Subject: [PATCH 13/14] code review change new line without whitespace --- export_form.php | 1 + 1 file changed, 1 insertion(+) diff --git a/export_form.php b/export_form.php index 0751090..351d21f 100644 --- a/export_form.php +++ b/export_form.php @@ -74,6 +74,7 @@ class mod_attendance_export_form extends moodleform { $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true)); $mform->setType('id', PARAM_INT); $mform->setType('uname', PARAM_INT); + $mform->addElement('checkbox', 'includeallsessions', get_string('includeall', 'attendance'), get_string('yes')); $mform->setDefault('includeallsessions', true); $mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attendance'), get_string('yes')); From 89b1c5cf2a199182c0a40d86282feee30dc6eb4d Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Tue, 27 May 2014 09:07:04 +0100 Subject: [PATCH 14/14] fixing whitespce --- export_form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/export_form.php b/export_form.php index 351d21f..ef33010 100644 --- a/export_form.php +++ b/export_form.php @@ -74,7 +74,7 @@ class mod_attendance_export_form extends moodleform { $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true)); $mform->setType('id', PARAM_INT); $mform->setType('uname', PARAM_INT); - + $mform->addElement('checkbox', 'includeallsessions', get_string('includeall', 'attendance'), get_string('yes')); $mform->setDefault('includeallsessions', true); $mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attendance'), get_string('yes'));