From 6b2e5a1bba1627644ed54857d63773b626460330 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Thu, 2 Feb 2017 12:23:24 +1300 Subject: [PATCH] Fixes #240 Save comment fields even when status not set. --- classes/structure.php | 20 +++++++++++--------- renderhelpers.php | 3 ++- version.php | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/classes/structure.php b/classes/structure.php index b5381de..e5386d2 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -492,24 +492,25 @@ class mod_attendance_structure { 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. + // This whole function could do with a nice clean up. $statuses = implode(',', array_keys( (array)$this->get_statuses() )); $now = time(); $sesslog = array(); $formdata = (array)$formdata; foreach ($formdata as $key => $value) { - if (substr($key, 0, 4) == 'user') { - $sid = substr($key, 4); - if (!(is_numeric($sid) && is_numeric($value))) { // Sanity check on $sid and $value. + // Look at Remarks field because the user options may not be passed if empty. + if (substr($key, 0, 7) == 'remarks') { + $sid = substr($key, 7); + if (!(is_numeric($sid))) { // Sanity check on $sid. print_error('nonnumericid', 'attendance'); } $sesslog[$sid] = new stdClass(); $sesslog[$sid]->studentid = $sid; // We check is_numeric on this above. - $sesslog[$sid]->statusid = $value; // We check is_numeric on this above. - $sesslog[$sid]->statusset = $statuses; - $sesslog[$sid]->remarks = ''; - if (array_key_exists('remarks'.$sid, $formdata)) { - $sesslog[$sid]->remarks = clean_param($formdata['remarks' . $sid], PARAM_TEXT); + if (array_key_exists('user'.$sid, $formdata) && is_numeric($formdata['user' . $sid])) { + $sesslog[$sid]->statusid = $formdata['user' . $sid]; } + $sesslog[$sid]->statusset = $statuses; + $sesslog[$sid]->remarks = $value; $sesslog[$sid]->sessionid = $this->pageparams->sessionid; $sesslog[$sid]->timetaken = $now; $sesslog[$sid]->takenby = $USER->id; @@ -518,7 +519,8 @@ class mod_attendance_structure { $dbsesslog = $this->get_session_log($this->pageparams->sessionid); foreach ($sesslog as $log) { - if ($log->statusid) { + // Don't save a record if no statusid or remark. + if (!empty($log->statusid) || !empty($log->remarks)) { if (array_key_exists($log->studentid, $dbsesslog)) { $log->id = $dbsesslog[$log->studentid]->id; $DB->update_record('attendance_log', $log); diff --git a/renderhelpers.php b/renderhelpers.php index 780fb6b..9c1a5c6 100644 --- a/renderhelpers.php +++ b/renderhelpers.php @@ -46,7 +46,8 @@ class user_sessions_cells_generator { 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])) { + if (array_key_exists($sess->id, $this->reportdata->sessionslog[$this->user->id]) && + !empty($this->reportdata->sessionslog[$this->user->id][$sess->id]->statusid)) { $statusid = $this->reportdata->sessionslog[$this->user->id][$sess->id]->statusid; if (array_key_exists($statusid, $this->reportdata->statuses)) { $points = format_float($this->reportdata->statuses[$statusid]->grade, 1, true, true); diff --git a/version.php b/version.php index 9913c3b..b9ce0a8 100644 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016121300; +$plugin->version = 2017020202; $plugin->requires = 2016111800; -$plugin->release = '3.2.2'; +$plugin->release = '3.2.3'; $plugin->maturity = MATURITY_STABLE; $plugin->cron = 0; $plugin->component = 'mod_attendance'; -- 2.11.0