From 3bfcc5a4765add9febf5d124600ef6c165dd75bf Mon Sep 17 00:00:00 2001 From: Gregory Faller Date: Fri, 6 Dec 2013 13:08:38 +1030 Subject: [PATCH 1/3] Option to export remarks --- export.php | 5 ++++- export_form.php | 1 + lang/en/attendance.php | 1 + renderer.php | 3 ++- renderhelpers.php | 17 ++++++++++++++++- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/export.php b/export.php index 5d2d32f..e56d8db 100644 --- a/export.php +++ b/export.php @@ -98,6 +98,9 @@ if ($mform->is_submitted()) { $text .= ' '; $text .= $sess->groupid ? $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance'); $data->tabhead[] = $text; + if (isset($formdata->includeremarks)) { + $data->tabhead[] = get_string('remark', 'attendance', $text); + } } } else { print_error('sessionsnotfound', 'attendance', $att->url_manage()); @@ -118,7 +121,7 @@ if ($mform->is_submitted()) { $data->table[$i][] = $user->lastname; $data->table[$i][] = $user->firstname; $cellsgenerator = new user_sessions_cells_text_generator($reportdata, $user); - $data->table[$i] = array_merge($data->table[$i], $cellsgenerator->get_cells()); + $data->table[$i] = array_merge($data->table[$i], $cellsgenerator->get_cells($formdata->includeremarks)); if ($reportdata->gradable) { $data->table[$i][] = $reportdata->grades[$user->id].' / '.$reportdata->maxgrades[$user->id]; } diff --git a/export_form.php b/export_form.php index e43e1c6..17a932c 100644 --- a/export_form.php +++ b/export_form.php @@ -72,6 +72,7 @@ class mod_attendance_export_form extends moodleform { $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')); + $mform->addElement('checkbox', 'includeremarks', get_string('includeremarks', 'attendance'), get_string('yes')); $mform->addElement('date_selector', 'sessionstartdate', get_string('startofperiod', 'attendance')); $mform->setDefault('sessionstartdate', $course->startdate); $mform->disabledIf('sessionstartdate', 'includeallsessions', 'checked'); diff --git a/lang/en/attendance.php b/lang/en/attendance.php index e8697a9..8c53022 100755 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -153,6 +153,7 @@ $string['olddate'] = 'Old date'; $string['period'] = 'Frequency'; $string['pluginname'] = 'Attendance'; $string['pluginadministration'] = 'Attendance administration'; +$string['remark'] = 'Remark for: {a}'; $string['remarks'] = 'Remarks'; $string['report'] = 'Report'; $string['required'] = 'Required*'; diff --git a/renderer.php b/renderer.php index e49578b..0a58dc9 100755 --- a/renderer.php +++ b/renderer.php @@ -600,7 +600,8 @@ class mod_attendance_renderer extends plugin_renderer_base { } $params = array( 'type' => 'text', - 'name' => 'remarks'.$user->id); + 'name' => 'remarks'.$user->id, + 'maxlength' => 255); if (array_key_exists($user->id, $takedata->sessionlog)) { $params['value'] = $takedata->sessionlog[$user->id]->remarks; } diff --git a/renderhelpers.php b/renderhelpers.php index e25bfb0..a501537 100644 --- a/renderhelpers.php +++ b/renderhelpers.php @@ -43,7 +43,7 @@ class user_sessions_cells_generator { $this->user = $user; } - public function get_cells() { + public function get_cells($remarks = false) { $this->init_cells(); foreach ($this->reportdata->sessions as $sess) { if (array_key_exists($sess->id, $this->reportdata->sessionslog[$this->user->id])) { @@ -53,6 +53,9 @@ class user_sessions_cells_generator { } else { $this->construct_hidden_status_cell($this->reportdata->allstatuses[$statusid]->acronym); } + if ($remarks) { + $this->construct_remarks_cell($this->reportdata->sessionslog[$this->user->id][$sess->id]->remarks); + } } else { if ($this->user->enrolmentstart > $sess->sessdate) { $starttext = get_string('enrolmentstart', 'attendance', userdate($this->user->enrolmentstart, '%d.%m.%Y')); @@ -71,6 +74,9 @@ class user_sessions_cells_generator { $this->construct_not_existing_for_user_session_cell(''); } } + if ($remarks) { + $this->construct_remarks_cell(''); + } } } $this->finalize_cells(); @@ -97,6 +103,10 @@ class user_sessions_cells_generator { protected function construct_not_taken_cell($text) { $this->cells[] = $text; } + + protected function construct_remarks_cell($text) { + $this->cells[] = $text; + } protected function construct_not_existing_for_user_session_cell($text) { $this->cells[] = $text; @@ -150,6 +160,11 @@ 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) { + $this->close_open_cell_if_needed(); + $this->cells[] = $text; + } protected function construct_not_existing_for_user_session_cell($text) { $this->close_open_cell_if_needed(); From d4de7cb94a11b748e5085d55fa8d7b37687327ec Mon Sep 17 00:00:00 2001 From: Gregory Faller Date: Fri, 6 Dec 2013 13:09:54 +1030 Subject: [PATCH 2/3] Fix errors when using Activities block Current module throws an error when using the Activities block as set_url is not set. Fixing this throws a seperate error around array_pop. Put this on a separate line. --- index.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index dcb421c..f699052 100644 --- a/index.php +++ b/index.php @@ -29,8 +29,11 @@ $id = required_param('id', PARAM_INT); $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); require_login($course); +$PAGE->set_url('/mod/attendance/index.php', array('id' => $id)); + // TODO: check if this is correct behaviour - other modules list all the instances of the module in the course. -if ($att = array_pop(get_all_instances_in_course('attendance', $course, null, true))) { +if ($att = get_all_instances_in_course('attendance', $course, null, true)) { + $att = array_pop($att); redirect("view.php?id=$att->coursemodule"); } else { print_error('notfound', 'attendance'); From fdc4ef50f62240d131af8b6d501da9f5d3cda4d0 Mon Sep 17 00:00:00 2001 From: cedict Date: Fri, 6 Dec 2013 13:21:16 +1030 Subject: [PATCH 3/3] Export remarks Fixed error when remarks are not being exported --- export.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/export.php b/export.php index e56d8db..215191a 100644 --- a/export.php +++ b/export.php @@ -121,7 +121,7 @@ if ($mform->is_submitted()) { $data->table[$i][] = $user->lastname; $data->table[$i][] = $user->firstname; $cellsgenerator = new user_sessions_cells_text_generator($reportdata, $user); - $data->table[$i] = array_merge($data->table[$i], $cellsgenerator->get_cells($formdata->includeremarks)); + $data->table[$i] = array_merge($data->table[$i], $cellsgenerator->get_cells(isset($formdata->includeremarks))); if ($reportdata->gradable) { $data->table[$i][] = $reportdata->grades[$user->id].' / '.$reportdata->maxgrades[$user->id]; }