Browse Source

Fixes #240 Save comment fields even when status not set.

MOODLE_32_STABLE
Dan Marsden 8 years ago
parent
commit
6895d64c92
  1. 20
      classes/structure.php
  2. 3
      renderhelpers.php

20
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);

3
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);

Loading…
Cancel
Save