Browse Source

Add new field for student availability,

allow statuses to be hidden from students during self marking.
MOODLE_34_STABLE
Dan Marsden 8 years ago
parent
commit
255303e447
  1. 2
      classes/event/status_updated.php
  2. 4
      db/install.xml
  3. 15
      db/upgrade.php
  4. 13
      defaultstatus.php
  5. 4
      lang/en/attendance.php
  6. 57
      locallib.php
  7. 17
      preferences.php
  8. 19
      renderer.php
  9. 27
      student_attendance_form.php
  10. 2
      version.php

2
classes/event/status_updated.php

@ -84,7 +84,7 @@ class status_updated extends \core\event\base {
*/ */
protected function get_legacy_logdata() { protected function get_legacy_logdata() {
return array($this->courseid, 'attendance', 'status updated', $this->get_url(), return array($this->courseid, 'attendance', 'status updated', $this->get_url(),
$this->other['updated'], $this->contextinstanceid); '', $this->contextinstanceid);
} }
/** /**

4
db/install.xml

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/attendance/db" VERSION="20170307" COMMENT="XMLDB file for Moodle mod/attendance" <XMLDB PATH="mod/attendance/db" VERSION="20170511" COMMENT="XMLDB file for Moodle mod/attendance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd" xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
> >
@ -78,6 +79,7 @@
<FIELD NAME="acronym" TYPE="char" LENGTH="2" NOTNULL="true" SEQUENCE="false"/> <FIELD NAME="acronym" TYPE="char" LENGTH="2" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="description" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false"/> <FIELD NAME="description" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="grade" TYPE="number" LENGTH="5" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="2"/> <FIELD NAME="grade" TYPE="number" LENGTH="5" NOTNULL="true" DEFAULT="0" SEQUENCE="false" DECIMALS="2"/>
<FIELD NAME="studentavailability" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="How many minutes this status is available when self marking is enabled."/>
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/> <FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="deleted" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> <FIELD NAME="deleted" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="setnumber" TYPE="int" LENGTH="5" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Allows different sets of statuses to be allocated to different sessions"/> <FIELD NAME="setnumber" TYPE="int" LENGTH="5" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Allows different sets of statuses to be allocated to different sessions"/>

15
db/upgrade.php

@ -245,5 +245,20 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2017042800, 'attendance'); 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; return $result;
} }

13
defaultstatus.php

@ -51,10 +51,18 @@ switch ($action) {
$newacronym = optional_param('newacronym', null, PARAM_TEXT); $newacronym = optional_param('newacronym', null, PARAM_TEXT);
$newdescription = optional_param('newdescription', null, PARAM_TEXT); $newdescription = optional_param('newdescription', null, PARAM_TEXT);
$newgrade = optional_param('newgrade', 0, PARAM_RAW); $newgrade = optional_param('newgrade', 0, PARAM_RAW);
$newstudentavailability = optional_param('newstudentavailability', null, PARAM_INT);
$newgrade = unformat_float($newgrade); $newgrade = unformat_float($newgrade);
// Default value uses setnumber/attendanceid = 0. // 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; break;
case mod_attendance_preferences_page_params::ACTION_DELETE: case mod_attendance_preferences_page_params::ACTION_DELETE:
@ -92,6 +100,7 @@ switch ($action) {
$acronym = required_param_array('acronym', PARAM_TEXT); $acronym = required_param_array('acronym', PARAM_TEXT);
$description = required_param_array('description', PARAM_TEXT); $description = required_param_array('description', PARAM_TEXT);
$grade = required_param_array('grade', PARAM_RAW); $grade = required_param_array('grade', PARAM_RAW);
$studentavailability = required_param_array('studentavailability', PARAM_RAW);
foreach ($grade as &$val) { foreach ($grade as &$val) {
$val = unformat_float($val); $val = unformat_float($val);
} }
@ -99,7 +108,7 @@ switch ($action) {
foreach ($acronym as $id => $v) { foreach ($acronym as $id => $v) {
$status = $statuses[$id]; $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'); echo $OUTPUT->notification(get_string('eventstatusupdated', 'attendance'), 'success');

4
lang/en/attendance.php

@ -380,3 +380,7 @@ $string['defaultstatus'] = 'Default status set';
$string['defaultsessionsettings'] = 'Default session settings'; $string['defaultsessionsettings'] = 'Default session settings';
$string['defaultsessionsettings_help'] = 'These settings define the defaults for all new sessions'; $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';

57
locallib.php

@ -258,40 +258,31 @@ function attendance_update_users_grade($attendance, $userids=array()) {
/** /**
* Add an attendance status variable * Add an attendance status variable
* *
* @param string $acronym * @param stdClass $status
* @param string $description
* @param int $grade
* @param int $attendanceid
* @param int $setnumber
* @param stdClass $context
* @param stdClass $cm
* @return bool * @return bool
*/ */
function attendance_add_status($acronym, $description, $grade, $attendanceid, $setnumber = 0, $context = null, $cm = null) { function attendance_add_status($status) {
global $DB; global $DB;
if (empty($context)) { if (empty($status->context)) {
$context = context_system::instance(); $status->context = context_system::instance();
} }
if ($acronym && $description) {
$rec = new stdClass(); if (!empty($status->acronym) && !empty($status->description)) {
$rec->attendanceid = $attendanceid; $status->deleted = 0;
$rec->acronym = $acronym; $status->visible = 1;
$rec->description = $description; $id = $DB->insert_record('attendance_statuses', $status);
$rec->grade = $grade; $status->id = $id;
$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;
$event = \mod_attendance\event\status_added::create(array( $event = \mod_attendance\event\status_added::create(array(
'objectid' => $attendanceid, 'objectid' => $status->attendanceid,
'context' => $context, 'context' => $status->context,
'other' => array('acronym' => $acronym, 'description' => $description, 'grade' => $grade))); 'other' => array('acronym' => $status->acronym,
if (!empty($cm)) { 'description' => $status->description,
$event->add_record_snapshot('course_modules', $cm); '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(); $event->trigger();
return true; return true;
} else { } else {
@ -338,7 +329,7 @@ function attendance_remove_status($status, $context = null, $cm = null) {
* @param stdClass $cm * @param stdClass $cm
* @return array * @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; global $DB;
if (empty($context)) { if (empty($context)) {
@ -366,6 +357,16 @@ function attendance_update_status($status, $acronym, $description, $grade, $visi
$status->grade = $grade; $status->grade = $grade;
$updated[] = $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); $DB->update_record('attendance_statuses', $status);
$event = \mod_attendance\event\status_updated::create(array( $event = \mod_attendance\event\status_updated::create(array(

17
preferences.php

@ -68,10 +68,20 @@ switch ($att->pageparams->action) {
$newacronym = optional_param('newacronym', null, PARAM_TEXT); $newacronym = optional_param('newacronym', null, PARAM_TEXT);
$newdescription = optional_param('newdescription', null, PARAM_TEXT); $newdescription = optional_param('newdescription', null, PARAM_TEXT);
$newgrade = optional_param('newgrade', 0, PARAM_RAW); $newgrade = optional_param('newgrade', 0, PARAM_RAW);
$newstudentavailability = optional_param('newstudentavailability', null, PARAM_INT);
$newgrade = unformat_float($newgrade); $newgrade = unformat_float($newgrade);
$status = attendance_add_status($newacronym, $newdescription, $newgrade, $att->id, $newstatus = new stdClass();
$att->pageparams->statusset, $att->context, $att->cm); $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) { if (!$status) {
print_error('cantaddstatus', 'attendance', $this->url_preferences()); print_error('cantaddstatus', 'attendance', $this->url_preferences());
} }
@ -118,6 +128,7 @@ switch ($att->pageparams->action) {
$acronym = required_param_array('acronym', PARAM_TEXT); $acronym = required_param_array('acronym', PARAM_TEXT);
$description = required_param_array('description', PARAM_TEXT); $description = required_param_array('description', PARAM_TEXT);
$grade = required_param_array('grade', PARAM_RAW); $grade = required_param_array('grade', PARAM_RAW);
$studentavailability = optional_param_array('studentavailability', null, PARAM_RAW);
foreach ($grade as &$val) { foreach ($grade as &$val) {
$val = unformat_float($val); $val = unformat_float($val);
} }
@ -126,7 +137,7 @@ switch ($att->pageparams->action) {
foreach ($acronym as $id => $v) { foreach ($acronym as $id => $v) {
$status = $statuses[$id]; $status = $statuses[$id];
$errors[$id] = attendance_update_status($status, $acronym[$id], $description[$id], $grade[$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); attendance_update_users_grade($att);
break; break;

19
renderer.php

@ -1620,14 +1620,23 @@ class mod_attendance_renderer extends plugin_renderer_base {
protected function render_attendance_preferences_data($prefdata) { protected function render_attendance_preferences_data($prefdata) {
$this->page->requires->js('/mod/attendance/module.js'); $this->page->requires->js('/mod/attendance/module.js');
$studentscanmark = false;
if (!empty(get_config('attendance', 'studentscanmark'))) {
$studentscanmark = true;
}
$table = new html_table(); $table = new html_table();
$table->width = '100%'; $table->width = '100%';
$table->head = array('#', $table->head = array('#',
get_string('acronym', 'attendance'), get_string('acronym', 'attendance'),
get_string('description'), get_string('description'),
get_string('points', 'attendance'), get_string('points', 'attendance'));
get_string('action'));
$table->align = array('center', 'center', 'center', 'center', 'center', 'center'); $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; $i = 1;
foreach ($prefdata->statuses as $st) { 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) . $table->data[$i][] = $this->construct_text_input('description['.$st->id.']', 30, 30, $st->description) .
$emptydescription; $emptydescription;
$table->data[$i][] = $this->construct_text_input('grade['.$st->id.']', 4, 4, $st->grade); $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); $table->data[$i][] = $this->construct_preferences_actions_icons($st, $prefdata);
$i++; $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('newacronym', 2, 2);
$table->data[$i][] = $this->construct_text_input('newdescription', 30, 30); $table->data[$i][] = $this->construct_text_input('newdescription', 30, 30);
$table->data[$i][] = $this->construct_text_input('newgrade', 4, 4); $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'), $table->data[$i][] = $this->construct_preferences_button(get_string('add', 'attendance'),
mod_attendance_preferences_page_params::ACTION_ADD); mod_attendance_preferences_page_params::ACTION_ADD);

27
student_attendance_form.php

@ -46,6 +46,18 @@ class mod_attendance_student_attendance_form extends moodleform {
$attblock = $this->_customdata['attendance']; $attblock = $this->_customdata['attendance'];
$statuses = $attblock->get_statuses(); $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->addElement('hidden', 'sessid', null);
$mform->setType('sessid', PARAM_INT); $mform->setType('sessid', PARAM_INT);
@ -75,10 +87,23 @@ class mod_attendance_student_attendance_form extends moodleform {
foreach ($statuses as $status) { foreach ($statuses as $status) {
$radioarray[] =& $mform->createElement('radio', 'status', '', $status->description, $status->id, array()); $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. // 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->addGroup($radioarray, 'statusarray', $USER->firstname.' '.$USER->lastname.':', array(''), false);
$mform->addRule('statusarray', get_string('attendancenotset', 'attendance'), 'required', '', 'client', false, false); $mform->addRule('statusarray', get_string('attendancenotset', 'attendance'), 'required', '', 'client', false, false);
$this->add_action_buttons(); $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;
}
} }

2
version.php

@ -23,7 +23,7 @@
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017051100; $plugin->version = 2017051101;
$plugin->requires = 2017042100; $plugin->requires = 2017042100;
$plugin->release = '3.3.4'; $plugin->release = '3.3.4';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;

Loading…
Cancel
Save