diff --git a/classes/event/status_updated.php b/classes/event/status_updated.php index 1934b54..b7ed879 100644 --- a/classes/event/status_updated.php +++ b/classes/event/status_updated.php @@ -84,7 +84,7 @@ class status_updated extends \core\event\base { */ protected function get_legacy_logdata() { return array($this->courseid, 'attendance', 'status updated', $this->get_url(), - $this->other['updated'], $this->contextinstanceid); + '', $this->contextinstanceid); } /** diff --git a/db/install.xml b/db/install.xml index 3842add..2d6f509 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,8 +1,9 @@ + - +> @@ -78,6 +79,7 @@ + @@ -109,4 +111,4 @@
-
+ \ No newline at end of file diff --git a/db/upgrade.php b/db/upgrade.php index 89388a8..42cf604 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -245,5 +245,20 @@ function xmldb_attendance_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2017042800, 'attendance'); } + if ($oldversion < 2017051101) { + + // Define field studentavailability to be added to attendance_statuses. + $table = new xmldb_table('attendance_statuses'); + $field = new xmldb_field('studentavailability', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'grade'); + + // Conditionally launch add field studentavailability. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Attendance savepoint reached. + upgrade_mod_savepoint(true, 2017051101, 'attendance'); + } + return $result; } diff --git a/defaultstatus.php b/defaultstatus.php index 65b3074..e02ade3 100644 --- a/defaultstatus.php +++ b/defaultstatus.php @@ -51,10 +51,18 @@ switch ($action) { $newacronym = optional_param('newacronym', null, PARAM_TEXT); $newdescription = optional_param('newdescription', null, PARAM_TEXT); $newgrade = optional_param('newgrade', 0, PARAM_RAW); + $newstudentavailability = optional_param('newstudentavailability', null, PARAM_INT); $newgrade = unformat_float($newgrade); // Default value uses setnumber/attendanceid = 0. - attendance_add_status($newacronym, $newdescription, $newgrade, 0); + $status = new stdClass(); + $status->attendanceid = 0; + $status->acronym = $newacronym; + $status->description = $newdescription; + $status->grade = $newgrade; + $status->studentavailability = $newstudentavailability; + $status->setnumber = 0; + attendance_add_status($status); break; case mod_attendance_preferences_page_params::ACTION_DELETE: @@ -92,6 +100,7 @@ switch ($action) { $acronym = required_param_array('acronym', PARAM_TEXT); $description = required_param_array('description', PARAM_TEXT); $grade = required_param_array('grade', PARAM_RAW); + $studentavailability = required_param_array('studentavailability', PARAM_RAW); foreach ($grade as &$val) { $val = unformat_float($val); } @@ -99,7 +108,7 @@ switch ($action) { foreach ($acronym as $id => $v) { $status = $statuses[$id]; - $errors[$id] = attendance_update_status($status, $acronym[$id], $description[$id], $grade[$id], null); + $errors[$id] = attendance_update_status($status, $acronym[$id], $description[$id], $grade[$id], null, null, null, $studentavailability[$id]); } echo $OUTPUT->notification(get_string('eventstatusupdated', 'attendance'), 'success'); diff --git a/lang/en/attendance.php b/lang/en/attendance.php index 242ad5f..2ce8aa1 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -379,4 +379,8 @@ $string['defaultsettings_help'] = 'These settings define the defaults for all ne $string['defaultstatus'] = 'Default status set'; $string['defaultsessionsettings'] = 'Default session settings'; -$string['defaultsessionsettings_help'] = 'These settings define the defaults for all new sessions'; \ No newline at end of file +$string['defaultsessionsettings_help'] = 'These settings define the defaults for all new sessions'; + +$string['studentavailability'] = 'Available for students (minutes)'; +$string['somedisabledstatus'] = '(Some options have been removed as the session has started.)'; +$string['invalidstatus'] = 'You have selected an invalid status, please try again'; \ No newline at end of file diff --git a/locallib.php b/locallib.php index 4b121bc..1af86d2 100644 --- a/locallib.php +++ b/locallib.php @@ -258,40 +258,31 @@ function attendance_update_users_grade($attendance, $userids=array()) { /** * Add an attendance status variable * - * @param string $acronym - * @param string $description - * @param int $grade - * @param int $attendanceid - * @param int $setnumber - * @param stdClass $context - * @param stdClass $cm + * @param stdClass $status * @return bool */ -function attendance_add_status($acronym, $description, $grade, $attendanceid, $setnumber = 0, $context = null, $cm = null) { +function attendance_add_status($status) { global $DB; - if (empty($context)) { - $context = context_system::instance(); + if (empty($status->context)) { + $status->context = context_system::instance(); } - if ($acronym && $description) { - $rec = new stdClass(); - $rec->attendanceid = $attendanceid; - $rec->acronym = $acronym; - $rec->description = $description; - $rec->grade = $grade; - $rec->setnumber = $setnumber; // Save which set it is part of. - $rec->deleted = 0; - $rec->visible = 1; - $id = $DB->insert_record('attendance_statuses', $rec); - $rec->id = $id; + + if (!empty($status->acronym) && !empty($status->description)) { + $status->deleted = 0; + $status->visible = 1; + $id = $DB->insert_record('attendance_statuses', $status); + $status->id = $id; $event = \mod_attendance\event\status_added::create(array( - 'objectid' => $attendanceid, - 'context' => $context, - 'other' => array('acronym' => $acronym, 'description' => $description, 'grade' => $grade))); - if (!empty($cm)) { - $event->add_record_snapshot('course_modules', $cm); + 'objectid' => $status->attendanceid, + 'context' => $status->context, + 'other' => array('acronym' => $status->acronym, + 'description' => $status->description, + 'grade' => $status->grade))); + if (!empty($status->cm)) { + $event->add_record_snapshot('course_modules', $status->cm); } - $event->add_record_snapshot('attendance_statuses', $rec); + $event->add_record_snapshot('attendance_statuses', $status); $event->trigger(); return true; } else { @@ -338,7 +329,7 @@ function attendance_remove_status($status, $context = null, $cm = null) { * @param stdClass $cm * @return array */ -function attendance_update_status($status, $acronym, $description, $grade, $visible, $context = null, $cm = null) { +function attendance_update_status($status, $acronym, $description, $grade, $visible, $context = null, $cm = null, $studentavailability = null) { global $DB; if (empty($context)) { @@ -366,6 +357,16 @@ function attendance_update_status($status, $acronym, $description, $grade, $visi $status->grade = $grade; $updated[] = $grade; } + if (isset($studentavailability)) { + if (empty($studentavailability)) { + if ($studentavailability !== '0') { + $studentavailability = null; + } + } + + $status->studentavailability = $studentavailability; + $updated[] = $studentavailability; + } $DB->update_record('attendance_statuses', $status); $event = \mod_attendance\event\status_updated::create(array( diff --git a/preferences.php b/preferences.php index eceb428..56762c6 100644 --- a/preferences.php +++ b/preferences.php @@ -68,10 +68,20 @@ switch ($att->pageparams->action) { $newacronym = optional_param('newacronym', null, PARAM_TEXT); $newdescription = optional_param('newdescription', null, PARAM_TEXT); $newgrade = optional_param('newgrade', 0, PARAM_RAW); + $newstudentavailability = optional_param('newstudentavailability', null, PARAM_INT); $newgrade = unformat_float($newgrade); - $status = attendance_add_status($newacronym, $newdescription, $newgrade, $att->id, - $att->pageparams->statusset, $att->context, $att->cm); + $newstatus = new stdClass(); + $newstatus->attendanceid = $att->id; + $newstatus->acronym = $newacronym; + $newstatus->description = $newdescription; + $newstatus->grade = $newgrade; + $newstatus->studentavailability = $newstudentavailability; + $newstatus->setnumber = $att->pageparams->statusset; + $newstatus->cm = $att->cm; + $newstatus->context = $att->context; + + $status = attendance_add_status($newstatus); if (!$status) { print_error('cantaddstatus', 'attendance', $this->url_preferences()); } @@ -118,6 +128,7 @@ switch ($att->pageparams->action) { $acronym = required_param_array('acronym', PARAM_TEXT); $description = required_param_array('description', PARAM_TEXT); $grade = required_param_array('grade', PARAM_RAW); + $studentavailability = optional_param_array('studentavailability', null, PARAM_RAW); foreach ($grade as &$val) { $val = unformat_float($val); } @@ -126,7 +137,7 @@ switch ($att->pageparams->action) { foreach ($acronym as $id => $v) { $status = $statuses[$id]; $errors[$id] = attendance_update_status($status, $acronym[$id], $description[$id], $grade[$id], - null, $att->context, $att->cm); + null, $att->context, $att->cm, $studentavailability[$id]); } attendance_update_users_grade($att); break; diff --git a/renderer.php b/renderer.php index 05e2163..9b63828 100644 --- a/renderer.php +++ b/renderer.php @@ -1620,14 +1620,23 @@ class mod_attendance_renderer extends plugin_renderer_base { protected function render_attendance_preferences_data($prefdata) { $this->page->requires->js('/mod/attendance/module.js'); + $studentscanmark = false; + if (!empty(get_config('attendance', 'studentscanmark'))) { + $studentscanmark = true; + } + $table = new html_table(); $table->width = '100%'; $table->head = array('#', get_string('acronym', 'attendance'), get_string('description'), - get_string('points', 'attendance'), - get_string('action')); + get_string('points', 'attendance')); $table->align = array('center', 'center', 'center', 'center', 'center', 'center'); + if ($studentscanmark) { + $table->head[] = get_string('studentavailability', 'attendance'); + $table->align[] = 'center'; + } + $table->head[] = get_string('action'); $i = 1; foreach ($prefdata->statuses as $st) { @@ -1647,6 +1656,9 @@ class mod_attendance_renderer extends plugin_renderer_base { $table->data[$i][] = $this->construct_text_input('description['.$st->id.']', 30, 30, $st->description) . $emptydescription; $table->data[$i][] = $this->construct_text_input('grade['.$st->id.']', 4, 4, $st->grade); + if ($studentscanmark) { + $table->data[$i][] = $this->construct_text_input('studentavailability['.$st->id.']', 4, 5, $st->studentavailability); + } $table->data[$i][] = $this->construct_preferences_actions_icons($st, $prefdata); $i++; @@ -1656,6 +1668,9 @@ class mod_attendance_renderer extends plugin_renderer_base { $table->data[$i][] = $this->construct_text_input('newacronym', 2, 2); $table->data[$i][] = $this->construct_text_input('newdescription', 30, 30); $table->data[$i][] = $this->construct_text_input('newgrade', 4, 4); + if ($studentscanmark) { + $table->data[$i][] = $this->construct_text_input('newstudentavailability', 4, 5); + } $table->data[$i][] = $this->construct_preferences_button(get_string('add', 'attendance'), mod_attendance_preferences_page_params::ACTION_ADD); diff --git a/student_attendance_form.php b/student_attendance_form.php index 888507f..dd1f928 100644 --- a/student_attendance_form.php +++ b/student_attendance_form.php @@ -46,6 +46,18 @@ class mod_attendance_student_attendance_form extends moodleform { $attblock = $this->_customdata['attendance']; $statuses = $attblock->get_statuses(); + // Check if user has access to all statuses. + $disabledduetotime = false; + foreach ($statuses as $status) { + if ($status->studentavailability === '0') { + unset($statuses[$status->id]); + } + if (!empty($status->studentavailability) && + time() > $attforsession->sessdate + ($status->studentavailability * 60)) { + unset($statuses[$status->id]); + $disabledduetotime = true; + } + } $mform->addElement('hidden', 'sessid', null); $mform->setType('sessid', PARAM_INT); @@ -75,10 +87,23 @@ class mod_attendance_student_attendance_form extends moodleform { foreach ($statuses as $status) { $radioarray[] =& $mform->createElement('radio', 'status', '', $status->description, $status->id, array()); } + if ($disabledduetotime) { + $warning = html_writer::span(get_string('somedisabledstatus', 'attendance'), 'somedisabledstatus'); + $radioarray[] =& $mform->createElement('static', '', '', $warning); + } + // 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', 'attendance'), 'required', '', 'client', false, false); - $this->add_action_buttons(); } + public function validation($data, $files) { + $errors = array(); + // Check if this status is allowed to be set. + if (empty($data['status'])) { + $errors['statusarray'] = get_string('invalidstatus', 'attendance'); + } + + return $errors; + } } \ No newline at end of file diff --git a/version.php b/version.php index cd7c4cb..2e12ba8 100644 --- a/version.php +++ b/version.php @@ -23,7 +23,7 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017051100; +$plugin->version = 2017051101; $plugin->requires = 2017042100; $plugin->release = '3.3.4'; $plugin->maturity = MATURITY_STABLE;