Browse Source

Fix #365 - allow automarking to be used when studentscanmark is off.

MOODLE_36_STABLE
Dan Marsden 6 years ago
parent
commit
3918bc41f1
  1. 40
      add_form.php
  2. 13
      classes/structure.php
  3. 55
      locallib.php
  4. 15
      renderer.php
  5. 28
      update_form.php

40
add_form.php

@ -189,27 +189,33 @@ class mod_attendance_add_form extends moodleform {
$mform->setType('previoussessiondate', PARAM_INT);
// Students can mark own attendance.
if (!empty(get_config('attendance', 'studentscanmark'))) {
$studentscanmark = get_config('attendance', 'studentscanmark');
$mform->addElement('header', 'headerstudentmarking', get_string('studentmarking', 'attendance'), true);
if (!empty($pluginconfig->studentrecordingexpanded)) {
$mform->setExpanded('headerstudentmarking');
}
if (!empty($studentscanmark)) {
$mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance'));
$mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance');
} else {
$mform->addElement('hidden', 'studentscanmark', '0');
$mform->settype('studentscanmark', PARAM_INT);
}
$options = attendance_get_automarkoptions();
$mform->addElement('select', 'automark', get_string('automark', 'attendance'), $options);
$mform->setType('automark', PARAM_INT);
$mform->addHelpButton('automark', 'automark', 'attendance');
$mform->hideif('automark', 'studentscanmark', 'notchecked');
$mform->setDefault('automark', $this->_customdata['att']->automark);
if (!empty($studentscanmark)) {
$mgroup = array();
$mgroup[] = & $mform->createElement('text', 'studentpassword', get_string('studentpassword', 'attendance'));
$mgroup[] = & $mform->createElement('checkbox', 'randompassword', '', get_string('randompassword', 'attendance'));
$mgroup[] = & $mform->createElement('checkbox', 'includeqrcode', '', get_string('includeqrcode', 'attendance'));
$mgroup[] = &$mform->createElement('text', 'studentpassword', get_string('studentpassword', 'attendance'));
$mgroup[] = &$mform->createElement('checkbox', 'randompassword', '', get_string('randompassword', 'attendance'));
$mgroup[] = &$mform->createElement('checkbox', 'includeqrcode', '', get_string('includeqrcode', 'attendance'));
$mform->addGroup($mgroup, 'passwordgrp', get_string('passwordgrp', 'attendance'), array(' '), false);
$mform->setType('studentpassword', PARAM_TEXT);
@ -237,6 +243,7 @@ class mod_attendance_add_form extends moodleform {
if (isset($pluginconfig->automark_default)) {
$mform->setDefault('automark', $pluginconfig->automark_default);
}
}
$mgroup2 = array();
$mgroup2[] = & $mform->createElement('text', 'subnet', get_string('requiresubnet', 'attendance'));
if (empty(get_config('attendance', 'subnetactivitylevel'))) {
@ -252,8 +259,6 @@ class mod_attendance_add_form extends moodleform {
$mform->addGroup($mgroup2, 'subnetgrp', get_string('requiresubnet', 'attendance'), array(' '), false);
$mform->setAdvanced('subnetgrp');
$mform->addHelpButton('subnetgrp', 'requiresubnet', 'attendance');
$mform->hideif('subnetgrp', 'studentscanmark', 'notchecked');
$mform->hideif('subnet', 'usedefaultsubnet', 'checked');
$mgroup3 = array();
@ -267,8 +272,6 @@ class mod_attendance_add_form extends moodleform {
$mform->setAdvanced('preventsharedgroup');
$mform->setType('preventsharedip', PARAM_INT);
$mform->setType('preventsharediptime', PARAM_INT);
$mform->hideif('preventsharedgroup', 'studentscanmark', 'notchecked');
$mform->hideIf('preventsharediptime', 'preventsharedip', 'noteq', ATTENDANCE_SHAREDIP_MINUTES);
if (isset($pluginconfig->preventsharedip)) {
$mform->setDefault('preventsharedip', $pluginconfig->preventsharedip);
@ -277,25 +280,6 @@ class mod_attendance_add_form extends moodleform {
$mform->setDefault('preventsharediptime', $pluginconfig->preventsharediptime);
}
} else {
$mform->addElement('hidden', 'studentscanmark', '0');
$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);
$mform->addElement('hidden', 'preventsharedip', '0');
$mform->setType('preventsharedip', PARAM_INT);
$sharedtime = isset($pluginconfig->preventsharediptime) ? $pluginconfig->preventsharediptime : null;
$mform->addElement('hidden', 'preventsharediptime', $sharedtime);
$mform->setType('preventsharediptime', PARAM_INT);
}
$this->add_action_buttons(true, get_string('add', 'attendance'));
}

13
classes/structure.php

@ -558,11 +558,17 @@ class mod_attendance_structure {
if (!empty($formdata->autoassignstatus)) {
$sess->autoassignstatus = $formdata->autoassignstatus;
}
if (!empty(get_config('attendance', 'studentscanmark')) &&
$studentscanmark = get_config('attendance', 'studentscanmark');
if (!empty($studentscanmark) &&
!empty($formdata->studentscanmark)) {
$sess->studentscanmark = $formdata->studentscanmark;
$sess->studentpassword = $formdata->studentpassword;
$sess->autoassignstatus = $formdata->autoassignstatus;
if (!empty($formdata->includeqrcode)) {
$sess->includeqrcode = $formdata->includeqrcode;
}
}
if (!empty($formdata->usedefaultsubnet)) {
$sess->subnet = $this->subnet;
} else {
@ -578,11 +584,6 @@ class mod_attendance_structure {
if (!empty($formdata->preventsharediptime)) {
$sess->preventsharediptime = $formdata->preventsharediptime;
}
if (!empty($formdata->includeqrcode)) {
$sess->includeqrcode = $formdata->includeqrcode;
}
}
$sess->timemodified = time();
$DB->update_record('attendance_sessions', $sess);

55
locallib.php

@ -634,18 +634,26 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
$sess->absenteereport = $absenteereport;
$sess->studentpassword = '';
$sess->includeqrcode = 0;
if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance.
$sess->studentscanmark = 1;
if (!empty($formdata->usedefaultsubnet)) {
$sess->subnet = $att->subnet;
} else {
$sess->subnet = $formdata->subnet;
}
$sess->automark = $formdata->automark;
$sess->automarkcompleted = 0;
if (!empty($formdata->preventsharedip)) {
$sess->preventsharedip = $formdata->preventsharedip;
}
if (!empty($formdata->preventsharediptime)) {
$sess->preventsharediptime = $formdata->preventsharediptime;
}
if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance.
$sess->studentscanmark = 1;
if (isset($formdata->autoassignstatus)) {
$sess->autoassignstatus = 1;
}
$sess->automarkcompleted = 0;
if (!empty($formdata->randompassword)) {
$sess->studentpassword = attendance_random_string();
} else if (!empty($formdata->studentpassword)) {
@ -654,18 +662,6 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
if (!empty($formdata->includeqrcode)) {
$sess->includeqrcode = $formdata->includeqrcode;
}
if (!empty($formdata->preventsharedip)) {
$sess->preventsharedip = $formdata->preventsharedip;
}
if (!empty($formdata->preventsharediptime)) {
$sess->preventsharediptime = $formdata->preventsharediptime;
}
} else {
$sess->subnet = '';
$sess->automark = 0;
$sess->automarkcompleted = 0;
$sess->preventsharedip = 0;
$sess->preventsharediptime = '';
}
$sess->statusset = $formdata->statusset;
@ -695,20 +691,6 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
$sess->absenteereport = $absenteereport;
$sess->includeqrcode = 0;
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)) {
$sess->studentpassword = $formdata->studentpassword;
}
if (!empty($formdata->includeqrcode)) {
$sess->includeqrcode = $formdata->includeqrcode;
}
if (!empty($formdata->usedefaultsubnet)) {
$sess->subnet = $att->subnet;
} else {
@ -724,6 +706,21 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
if (!empty($formdata->preventsharediptime)) {
$sess->preventsharediptime = $formdata->preventsharediptime;
}
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)) {
$sess->studentpassword = $formdata->studentpassword;
}
if (!empty($formdata->includeqrcode)) {
$sess->includeqrcode = $formdata->includeqrcode;
}
}
$sess->statusset = $formdata->statusset;

15
renderer.php

@ -1742,11 +1742,6 @@ 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('#',
@ -1754,7 +1749,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
get_string('description'),
get_string('points', 'attendance'));
$table->align = array('center', 'center', 'center', 'center', 'center', 'center');
if ($studentscanmark) {
$table->head[] = get_string('studentavailability', 'attendance').
$this->output->help_icon('studentavailability', 'attendance');
$table->align[] = 'center';
@ -1762,7 +1757,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->head[] = get_string('setunmarked', 'attendance').
$this->output->help_icon('setunmarked', 'attendance');
$table->align[] = 'center';
}
$table->head[] = get_string('action');
$i = 1;
@ -1783,14 +1778,13 @@ class mod_attendance_renderer extends plugin_renderer_base {
$cells[] = $this->construct_text_input('description['.$st->id.']', 30, 30, $st->description) .
$emptydescription;
$cells[] = $this->construct_text_input('grade['.$st->id.']', 4, 4, $st->grade);
if ($studentscanmark) {
$checked = '';
if ($st->setunmarked) {
$checked = ' checked ';
}
$cells[] = $this->construct_text_input('studentavailability['.$st->id.']', 4, 5, $st->studentavailability);
$cells[] = '<input type="radio" name="setunmarked" value="'.$st->id.'"'.$checked.'>';
}
$cells[] = $this->construct_preferences_actions_icons($st, $prefdata);
$table->data[$i] = new html_table_row($cells);
@ -1802,9 +1796,8 @@ 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);

28
update_form.php

@ -128,20 +128,25 @@ class mod_attendance_update_form extends moodleform {
}
// Students can mark own attendance.
if (!empty(get_config('attendance', 'studentscanmark'))) {
$studentscanmark = get_config('attendance', 'studentscanmark');
$mform->addElement('header', 'headerstudentmarking', get_string('studentmarking', 'attendance'), true);
$mform->setExpanded('headerstudentmarking');
if (!empty($studentscanmark)) {
$mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance'));
$mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance');
} else {
$mform->addElement('hidden', 'studentscanmark', '0');
$mform->settype('studentscanmark', PARAM_INT);
}
$options2 = attendance_get_automarkoptions();
$mform->addElement('select', 'automark', get_string('automark', 'attendance'), $options2);
$mform->setType('automark', PARAM_INT);
$mform->addHelpButton('automark', 'automark', 'attendance');
$mform->hideif('automark', 'studentscanmark', 'notchecked');
if (!empty($studentscanmark)) {
$mform->addElement('text', 'studentpassword', get_string('studentpassword', 'attendance'));
$mform->setType('studentpassword', PARAM_TEXT);
$mform->addHelpButton('studentpassword', 'passwordgrp', 'attendance');
@ -153,6 +158,7 @@ class mod_attendance_update_form extends moodleform {
$mform->addElement('checkbox', 'autoassignstatus', '', get_string('autoassignstatus', 'attendance'));
$mform->addHelpButton('autoassignstatus', 'autoassignstatus', 'attendance');
$mform->hideif('autoassignstatus', 'studentscanmark', 'notchecked');
}
$mgroup = array();
$mgroup[] = & $mform->createElement('text', 'subnet', get_string('requiresubnet', 'attendance'));
@ -164,8 +170,6 @@ class mod_attendance_update_form extends moodleform {
$mform->addGroup($mgroup, 'subnetgrp', get_string('requiresubnet', 'attendance'), array(' '), false);
$mform->setAdvanced('subnetgrp');
$mform->addHelpButton('subnetgrp', 'requiresubnet', 'attendance');
$mform->hideif('subnetgrp', 'studentscanmark', 'notchecked');
$mform->hideif('subnet', 'usedefaultsubnet', 'checked');
$mform->addElement('hidden', 'automarkcompleted', '0');
@ -182,20 +186,6 @@ class mod_attendance_update_form extends moodleform {
$mform->addHelpButton('preventsharedgroup', 'preventsharedip', 'attendance');
$mform->setAdvanced('preventsharedgroup');
$mform->setType('preventsharediptime', PARAM_INT);
$mform->hideif('preventsharedgroup', 'studentscanmark', 'notchecked');
$mform->hideIf('preventsharediptime', 'preventsharedip', 'noteq', ATTENDANCE_SHAREDIP_MINUTES);
} else {
$mform->addElement('hidden', 'studentscanmark', '0');
$mform->settype('studentscanmark', PARAM_INT);
$mform->addElement('hidden', 'subnet', '0');
$mform->settype('subnet', PARAM_TEXT);
$mform->addElement('hidden', 'automark', '0');
$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);
$this->add_action_buttons(true);

Loading…
Cancel
Save