From ee20e101bb56c2307bf886d1a14cf58a63d3ece7 Mon Sep 17 00:00:00 2001 From: Joseph Baxter Date: Wed, 21 May 2014 14:51:27 +0100 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 4/6] 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 5/6] 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 6/6] 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) {