Browse Source

Added ability to automatically mark all students with a status

MOODLE_33_STABLE
James Voong 7 years ago
committed by Dan Marsden
parent
commit
8982de60e4
  1. 8
      add_form.php
  2. 27
      attendance.php
  3. 4
      backup/moodle2/backup_attendance_stepslib.php
  4. 18
      classes/structure.php
  5. 1
      db/install.xml
  6. 12
      db/upgrade.php
  7. 1
      externallib.php
  8. 2
      lang/en/attendance.php
  9. 10
      locallib.php
  10. 4
      sessions.php
  11. 3
      settings.php
  12. 38
      student_attendance_form.php
  13. 6
      update_form.php
  14. 2
      version.php

8
add_form.php

@ -211,6 +211,11 @@ class mod_attendance_add_form extends moodleform {
$mform->disabledif('studentpassword', 'randompassword', 'checked');
$mform->disabledif('studentpassword', 'automark', 'eq', ATTENDANCE_AUTOMARK_ALL);
$mform->disabledif('randompassword', 'automark', 'eq', ATTENDANCE_AUTOMARK_ALL);
$mform->addElement('checkbox', 'autoassignstatus', '', get_string('autoassignstatus', 'attendance'));
$mform->addHelpButton('autoassignstatus', 'autoassignstatus', 'attendance');
if (isset($pluginconfig->autoassignstatus)) {
$mform->setDefault('autoassignstatus', $pluginconfig->autoassignstatus);
}
if (isset($pluginconfig->studentscanmark_default)) {
$mform->setDefault('studentscanmark', $pluginconfig->studentscanmark_default);
}
@ -244,6 +249,9 @@ class mod_attendance_add_form extends moodleform {
$mform->settype('studentscanmark', PARAM_INT);
$mform->addElement('hidden', 'automark', '0');
$mform->setType('automark', PARAM_INT);
$mform->addElement('hidden', 'autoassignstatus', '0');
$mform->setType('autoassignstatus', PARAM_INT);
$mform->addElement('hidden', 'subnet', '');
$mform->setType('subnet', PARAM_TEXT);
}

27
attendance.php

@ -75,6 +75,31 @@ if ($mform->is_cancelled()) {
$url = new moodle_url('/mod/attendance/attendance.php', array('sessid' => $id, 'sesskey' => sesskey()));
redirect($url, get_string('incorrectpassword', 'mod_attendance'), null, \core\output\notification::NOTIFY_ERROR);
}
if ($attforsession->autoassignstatus) {
// Find the status to set here.
$statuses = $att->get_statuses();
$highestavailablegrade = 0;
$highestavailablestatus;
foreach ($statuses as $status) {
if ($status->studentavailability === '0') {
// This status is never available to students.
continue;
}
if (!empty($status->studentavailability)) {
$toolateforstatus = (($attforsession->sessdate + ($status->studentavailability * 60)) < time());
if ($toolateforstatus) {
continue;
}
}
// This status is available to the student.
if ($status->grade > $highestavailablegrade) {
// This is the most favourable grade so far; save it.
$highestavailablegrade = $status->grade;
$highestavailablestatus = $status;
}
}
$fromform->status = $highestavailablestatus->id;
}
if (!empty($fromform->status)) {
$success = $att->take_from_student($fromform);
@ -84,7 +109,7 @@ if ($mform->is_cancelled()) {
// Redirect back to the view page for the block.
redirect($url);
} else {
print_error ('attendance_already_submitted', 'mod_attendance', $url);
print_error('attendance_already_submitted', 'mod_attendance', $url);
}
}

4
backup/moodle2/backup_attendance_stepslib.php

@ -56,8 +56,8 @@ class backup_attendance_activity_structure_step extends backup_activity_structur
$sessions = new backup_nested_element('sessions');
$session = new backup_nested_element('session', array('id'), array(
'groupid', 'sessdate', 'duration', 'lasttaken', 'lasttakenby',
'timemodified', 'description', 'descriptionformat', 'studentscanmark', 'studentpassword',
'groupid', 'sessdate', 'duration', 'lasttaken', 'lasttakenby', 'timemodified',
'description', 'descriptionformat', 'studentscanmark', 'studentpassword', 'autoassignstatus',
'subnet', 'automark', 'automarkcompleted', 'statusset', 'absenteereport', 'caleventid'));
// XML nodes declaration - user data.

18
classes/structure.php

@ -477,6 +477,9 @@ class mod_attendance_structure {
if (!isset($sess->studentscanmark)) {
$sess->studentscanmark = 0;
}
if (!isset($sess->autoassignstatus)) {
$sess->autoassignstatus = 0;
}
if (!isset($sess->studentpassword)) {
$sess->studentpassword = '';
}
@ -515,15 +518,19 @@ class mod_attendance_structure {
$sess->descriptionformat = $formdata->sdescription['format'];
$sess->studentscanmark = 0;
$sess->autoassignstatus = 0;
$sess->studentpassword = '';
$sess->subnet = '';
$sess->automark = 0;
$sess->automarkcompleted = 0;
if (!empty($formdata->autoassignstatus)) {
$sess->autoassignstatus = $formdata->autoassignstatus;
}
if (!empty(get_config('attendance', 'studentscanmark')) &&
!empty($formdata->studentscanmark)) {
$sess->studentscanmark = $formdata->studentscanmark;
$sess->studentpassword = $formdata->studentpassword;
$sess->autoassignstatus = $formdata->autoassignstatus;
if (!empty($formdata->usedefaultsubnet)) {
$sess->subnet = $this->subnet;
} else {
@ -537,6 +544,7 @@ class mod_attendance_structure {
$sess->timemodified = time();
$DB->update_record('attendance_sessions', $sess);
if (empty($sess->caleventid)) {
// This shouldn't really happen, but just in case to prevent fatal error.
attendance_create_calendar_event($sess);
@ -1058,7 +1066,7 @@ class mod_attendance_structure {
$id = $DB->sql_concat(':value', 'ats.id');
if ($this->get_group_mode()) {
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description,
al.statusid, al.remarks, ats.studentscanmark
al.statusid, al.remarks, ats.studentscanmark, ats.autoassignstatus
FROM {attendance_sessions} ats
RIGHT JOIN {attendance_log} al
ON ats.id = al.sessionid AND al.studentid = :uid
@ -1067,7 +1075,7 @@ class mod_attendance_structure {
ORDER BY ats.sessdate ASC";
} else {
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, ats.statusset,
al.statusid, al.remarks, ats.studentscanmark
al.statusid, al.remarks, ats.studentscanmark, ats.autoassignstatus
FROM {attendance_sessions} ats
RIGHT JOIN {attendance_log} al
ON ats.id = al.sessionid AND al.studentid = :uid
@ -1096,9 +1104,9 @@ class mod_attendance_structure {
} else {
$where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND ats.groupid $gsql";
}
//James
$sql = "SELECT $id, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description, ats.statusset,
al.statusid, al.remarks, ats.studentscanmark
al.statusid, al.remarks, ats.studentscanmark, ats.autoassignstatus
FROM {attendance_sessions} ats
LEFT JOIN {attendance_log} al
ON ats.id = al.sessionid AND al.studentid = :uid

1
db/install.xml

@ -37,6 +37,7 @@
<FIELD NAME="description" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="studentscanmark" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="autoassignstatus" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="studentpassword" TYPE="char" LENGTH="50" NOTNULL="false" DEFAULT="" SEQUENCE="false"/>
<FIELD NAME="subnet" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Restrict ability for students to mark by subnet."/>
<FIELD NAME="automark" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>

12
db/upgrade.php

@ -453,5 +453,17 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2017050219, 'attendance');
}
if ($oldversion < 2017050220) {
$table = new xmldb_table('attendance_sessions');
$field = new xmldb_field('autoassignstatus');
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'studentscanmark');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_mod_savepoint(true, 2017050220, 'attendance');
}
return $result;
}

1
externallib.php

@ -69,6 +69,7 @@ class mod_wsattendance_external extends external_api {
'descriptionformat' => new external_value(PARAM_INT, 'Session description format.'),
'studentscanmark' => new external_value(PARAM_INT, 'Students can mark their own presence.'),
'absenteereport' => new external_value(PARAM_INT, 'Session included in absetee reports.'),
'autoassignstatus' => new external_value(PARAM_INT, 'Automatically assign a status to students.'),
'statusset' => new external_value(PARAM_INT, 'Session statusset.'));
return $session;

2
lang/en/attendance.php

@ -108,6 +108,8 @@ The sessions begin on the date of the base session and continue until the \'repe
* <strong>Repeat every</strong>: This allows for a frequency setting. If your class will meet every week, select 1; if it will meet every other week, select 2; every 3rd week, select 3, etc.
* <strong>Repeat until</strong>: Select the last day of class (the last day you want to take attendance).
';
$string['autoassignstatus'] = 'Automatically select highest status available';
$string['autoassignstatus_help'] = 'If this is selected, students will automatically be assigned the highest available grade.';
$string['createonesession'] = 'Create one session for the course';
$string['csvdelimiter'] = 'CSV delimiter';
$string['date'] = 'Date';

10
locallib.php

@ -539,6 +539,9 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
if (empty(get_config('attendance', 'studentscanmark'))) {
$formdata->studentscanmark = 0;
}
if (empty(get_config('attendance', 'autoassignstatus'))) {
$formdata->autoassignstatus = 0;
}
$sessions = array();
if (isset($formdata->addmultiply)) {
@ -581,6 +584,9 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
$sess->subnet = $formdata->subnet;
}
$sess->automark = $formdata->automark;
if (isset($formdata->autoassignstatus)) {
$sess->autoassignstatus = 1;
}
$sess->automarkcompleted = 0;
if (!empty($formdata->randompassword)) {
$sess->studentpassword = attendance_random_string();
@ -612,6 +618,7 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
$sess->descriptionformat = $formdata->sdescription['format'];
$sess->timemodified = $now;
$sess->studentscanmark = 0;
$sess->autoassignstatus = 0;
$sess->subnet = '';
$sess->studentpassword = '';
$sess->automark = 0;
@ -621,6 +628,9 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
if (isset($formdata->studentscanmark) && !empty($formdata->studentscanmark)) {
// Students will be able to mark their own attendance.
$sess->studentscanmark = 1;
if (isset($formdata->autoassignstatus) && !empty($formdata->autoassignstatus)) {
$sess->autoassignstatus = 1;
}
if (!empty($formdata->randompassword)) {
$sess->studentpassword = attendance_random_string();
} else if (!empty($formdata->studentpassword)) {

4
sessions.php

@ -99,6 +99,10 @@ switch ($att->pageparams->action) {
}
if ($formdata = $mform->get_data()) {
error_log(var_export($formdata, true));
if (empty($formdata->autoassignstatus)) {
$formdata->autoassignstatus = 0;
}
$att->update_session_from_form_data($formdata, $sessionid);
mod_attendance_notifyqueue::notify_success(get_string('sessionupdated', 'attendance'));

3
settings.php

@ -118,6 +118,9 @@ if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configcheckbox('attendance/randompassword_default',
get_string('randompassword', 'attendance'), '', 0));
$settings->add(new admin_setting_configcheckbox('attendance/autoassignstatus',
get_string('autoassignstatus', 'attendance'), '', 0));
$name = new lang_string('defaultwarningsettings', 'mod_attendance');
$description = new lang_string('defaultwarningsettings_help', 'mod_attendance');
$settings->add(new admin_setting_heading('defaultwarningsettings', $name, $description));

38
student_attendance_form.php

@ -82,21 +82,23 @@ class mod_attendance_student_attendance_form extends moodleform {
$mform->setType('studentpassword', PARAM_TEXT);
$mform->addRule('studentpassword', get_string('passwordrequired', 'attendance'), 'required');
}
// Create radio buttons for setting the attendance status.
$radioarray = array();
foreach ($statuses as $status) {
$name = html_writer::span($status->description, 'statusdesc');
$radioarray[] =& $mform->createElement('radio', 'status', '', $name, $status->id, array());
}
if ($disabledduetotime) {
$warning = html_writer::span(get_string('somedisabledstatus', 'attendance'), 'somedisabledstatus');
$radioarray[] =& $mform->createElement('static', '', '', $warning);
}
if (!$attforsession->autoassignstatus) {
// Add the radio buttons as a control with the user's name in front.
$radiogroup = $mform->addGroup($radioarray, 'statusarray', $USER->firstname.' '.$USER->lastname.':', array(''), false);
$radiogroup->setAttributes(array('class' => 'statusgroup'));
$mform->addRule('statusarray', get_string('attendancenotset', 'attendance'), 'required', '', 'client', false, false);
// Create radio buttons for setting the attendance status.
$radioarray = array();
foreach ($statuses as $status) {
$name = html_writer::span($status->description, 'statusdesc');
$radioarray[] =& $mform->createElement('radio', 'status', '', $name, $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.
$radiogroup = $mform->addGroup($radioarray, 'statusarray', $USER->firstname.' '.$USER->lastname.':', array(''), false);
$radiogroup->setAttributes(array('class' => 'statusgroup'));
$mform->addRule('statusarray', get_string('attendancenotset', 'attendance'), 'required', '', 'client', false, false);
}
$this->add_action_buttons();
}
@ -109,9 +111,11 @@ class mod_attendance_student_attendance_form extends moodleform {
*/
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');
if (!($this->_customdata['session']->autoassignstatus)) {
// Check if this status is allowed to be set.
if (empty($data['status'])) {
$errors['statusarray'] = get_string('invalidstatus', 'attendance');
}
}
return $errors;

6
update_form.php

@ -68,6 +68,7 @@ class mod_attendance_update_form extends moodleform {
'sdescription' => $sess->description_editor,
'studentscanmark' => $sess->studentscanmark,
'studentpassword' => $sess->studentpassword,
'autoassignstatus' => $sess->autoassignstatus,
'subnet' => $sess->subnet,
'automark' => $sess->automark,
'automarkcompleted' => 0);
@ -127,7 +128,8 @@ class mod_attendance_update_form extends moodleform {
$mform->disabledif('studentpassword', 'studentscanmark', 'notchecked');
$mform->disabledif('studentpassword', 'automark', 'eq', ATTENDANCE_AUTOMARK_ALL);
$mform->disabledif('randompassword', 'automark', 'eq', ATTENDANCE_AUTOMARK_ALL);
$mform->addElement('checkbox', 'autoassignstatus', '', get_string('autoassignstatus', 'attendance'));
$mform->addHelpButton('autoassignstatus', 'autoassignstatus', 'attendance');
$mgroup = array();
$mgroup[] = & $mform->createElement('text', 'subnet', get_string('requiresubnet', 'attendance'));
$mform->setDefault('subnet', $this->_customdata['att']->subnet);
@ -155,6 +157,8 @@ class mod_attendance_update_form extends moodleform {
$mform->settype('automark', PARAM_INT);
$mform->addElement('hidden', 'automarkcompleted', '0');
$mform->settype('automarkcompleted', PARAM_INT);
$mform->addElement('hidden', 'autoassignstatus', '0');
$mform->setType('autoassignstatus', PARAM_INT);
}
$mform->setDefaults($data);

2
version.php

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

Loading…
Cancel
Save