Browse Source

Make events optional per-session.

MOODLE_35_STABLE
Nick Phillips 7 years ago
committed by Dan Marsden
parent
commit
965e7f5e02
  1. 5
      add_form.php
  2. 36
      classes/calendar_helpers.php
  3. 7
      classes/import/sessions.php
  4. 5
      classes/structure.php
  5. 1
      db/install.xml
  6. 10
      db/upgrade.php
  7. 3
      lang/en/attendance.php
  8. 7
      locallib.php
  9. 6
      resetcalendar.php
  10. 1
      tests/attendance_webservices_test.php
  11. 35
      update_form.php
  12. 2
      version.php

5
add_form.php

@ -125,6 +125,11 @@ class mod_attendance_add_form extends moodleform {
array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext)); array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext));
$mform->setType('sdescription', PARAM_RAW); $mform->setType('sdescription', PARAM_RAW);
$mform->addElement('checkbox', 'calendarevent', '', get_string('calendarevent', 'attendance'));
$mform->addHelpButton('calendarevent', 'calendarevent', 'attendance');
// XXX - this should be modified to use a different config setting if we keep enablecalendar's current meaning
$mform->setDefault('calendarevent', get_config('attendance', 'enablecalendar'));
// If warnings allow selector for reporting. // If warnings allow selector for reporting.
if (!empty(get_config('attendance', 'enablewarnings'))) { if (!empty(get_config('attendance', 'enablewarnings'))) {
$mform->addElement('checkbox', 'absenteereport', '', get_string('includeabsentee', 'attendance')); $mform->addElement('checkbox', 'absenteereport', '', get_string('includeabsentee', 'attendance'));

36
classes/calendar_helpers.php

@ -38,8 +38,8 @@ function attendance_create_calendar_event(&$session) {
if ($session->caleventid) { if ($session->caleventid) {
return $session->caleventid; return $session->caleventid;
} }
if (empty(get_config('attendance', 'enablecalendar'))) { if (empty(get_config('attendance', 'enablecalendar')) || $session->calendarevent === 0) {
// Calendar events are not used. // Calendar events are not used, or event not required for this session.
return true; return true;
} }
@ -98,18 +98,42 @@ function attendance_create_calendar_events($sessionsids) {
/** /**
* Update calendar event duration and date * Update calendar event duration and date
* *
* @param int $caleventid calendar event id * @param stdClass $session Session data
* @param int $timeduration duration of the event
* @param int $timestart start time of the event
* @return bool result of updating * @return bool result of updating
*/ */
function attendance_update_calendar_event($caleventid, $timeduration, $timestart) { function attendance_update_calendar_event($session) {
global $DB;
$caleventid = $session->caleventid;
$timeduration = $session->duration;
$timestart = $session->sessdate;
if (empty(get_config('attendance', 'enablecalendar'))) { if (empty(get_config('attendance', 'enablecalendar'))) {
// Calendar events are not used. // Calendar events are not used.
return true; return true;
} }
// Should there even be an event?
if ($session->calendarevent == 0) {
if ($session->caleventid != 0) {
// There is an existing event we should delete
// (calendarevent option just got turned off)
$DB->delete_records_list('event', 'id', array($caleventid));
$session->caleventid = 0;
$DB->update_record('attendance_sessions', $session);
return true;
} else {
// This should be the common case when session does not want event
return true;
}
}
// Do we need new event (calendarevent option has just been turned on)?
if ($session->caleventid == 0) {
return attendance_create_calendar_event($session);
}
// Boring update
$caleventdata = new stdClass(); $caleventdata = new stdClass();
$caleventdata->timeduration = $timeduration; $caleventdata->timeduration = $timeduration;
$caleventdata->timestart = $timestart; $caleventdata->timestart = $timestart;

7
classes/import/sessions.php

@ -109,7 +109,8 @@ class sessions {
get_string('autoassignstatus', 'attendance'), get_string('autoassignstatus', 'attendance'),
get_string('absenteereport', 'attendance'), get_string('absenteereport', 'attendance'),
get_string('preventsharedip', 'attendance'), get_string('preventsharedip', 'attendance'),
get_string('preventsharediptime', 'attendance') get_string('preventsharediptime', 'attendance'),
get_string('calendarevent', 'attendance')
); );
} }
@ -148,6 +149,7 @@ class sessions {
'absenteereport' => $data->header15, 'absenteereport' => $data->header15,
'preventsharedip' => $data->header16, 'preventsharedip' => $data->header16,
'preventsharediptime' => $data->header17, 'preventsharediptime' => $data->header17,
'calendarevent' => $data->header18
); );
} else { } else {
return array( return array(
@ -168,7 +170,8 @@ class sessions {
'autoassignstatus' => 14, 'autoassignstatus' => 14,
'absenteereport' => 15, 'absenteereport' => 15,
'preventsharedip' => 16, 'preventsharedip' => 16,
'preventsharediptime' => 17 'preventsharediptime' => 17,
'calendarevent' => 18
); );
} }
} }

5
classes/structure.php

@ -534,6 +534,7 @@ class mod_attendance_structure {
array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $formdata->sdescription['text']); array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $formdata->sdescription['text']);
$sess->description = $description; $sess->description = $description;
$sess->descriptionformat = $formdata->sdescription['format']; $sess->descriptionformat = $formdata->sdescription['format'];
$sess->calendarevent = empty($formdata->calendarevent) ? 0 : $formdata->calendarevent;
$sess->studentscanmark = 0; $sess->studentscanmark = 0;
$sess->autoassignstatus = 0; $sess->autoassignstatus = 0;
@ -579,7 +580,7 @@ class mod_attendance_structure {
// This shouldn't really happen, but just in case to prevent fatal error. // This shouldn't really happen, but just in case to prevent fatal error.
attendance_create_calendar_event($sess); attendance_create_calendar_event($sess);
} else { } else {
attendance_update_calendar_event($sess->caleventid, $sess->duration, $sess->sessdate); attendance_update_calendar_event($sess);
} }
$info = construct_session_full_date_time($sess->sessdate, $sess->duration); $info = construct_session_full_date_time($sess->sessdate, $sess->duration);
@ -1200,7 +1201,7 @@ class mod_attendance_structure {
$sess->timemodified = $now; $sess->timemodified = $now;
$DB->update_record('attendance_sessions', $sess); $DB->update_record('attendance_sessions', $sess);
if ($sess->caleventid) { if ($sess->caleventid) {
attendance_update_calendar_event($sess->caleventid, $duration, $sess->sessdate); attendance_update_calendar_event($sess);
} }
$event = \mod_attendance\event\session_duration_updated::create(array( $event = \mod_attendance\event\session_duration_updated::create(array(
'objectid' => $this->id, 'objectid' => $this->id,

1
db/install.xml

@ -48,6 +48,7 @@
<FIELD NAME="preventsharedip" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/> <FIELD NAME="preventsharedip" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="preventsharediptime" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/> <FIELD NAME="preventsharediptime" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="caleventid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> <FIELD NAME="caleventid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="calendarevent" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance_sessions"/> <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance_sessions"/>

10
db/upgrade.php

@ -511,5 +511,15 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2018050100, 'attendance'); upgrade_mod_savepoint(true, 2018050100, 'attendance');
} }
if ($oldversion < 2018051402) {
$table = new xmldb_table('attendance_sessions');
$field = new xmldb_field('calendarevent', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
XMLDB_NOTNULL, null, '1', 'caleventid');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_mod_savepoint(true, 2018051402, 'attendance');
}
return $result; return $result;
} }

3
lang/en/attendance.php

@ -78,6 +78,9 @@ $string['autorecorded'] = 'system auto recorded';
$string['averageattendance'] = 'Average attendance'; $string['averageattendance'] = 'Average attendance';
$string['averageattendancegraded'] = 'Average attendance'; $string['averageattendancegraded'] = 'Average attendance';
$string['calclose'] = 'Close'; $string['calclose'] = 'Close';
$string['calendarevent'] = 'Create calendar event for session';
$string['calendarevent_help'] = 'If enabled, a calendar event will be created for this session.
If disabled, any existing calendar event for this session will be deleted.';
$string['caleventcreated'] = 'Calendar event for session successfully created'; $string['caleventcreated'] = 'Calendar event for session successfully created';
$string['caleventdeleted'] = 'Calendar event for session successfully deleted'; $string['caleventdeleted'] = 'Calendar event for session successfully deleted';
$string['calmonths'] = 'January,February,March,April,May,June,July,August,September,October,November,December'; $string['calmonths'] = 'January,February,March,April,May,June,July,August,September,October,November,December';

7
locallib.php

@ -575,6 +575,11 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
$formdata->studentscanmark = 0; $formdata->studentscanmark = 0;
} }
$calendarevent = 0;
if (isset($formdata->calendarevent)) { // Calendar event should be created
$calendarevent = 1;
}
$sessions = array(); $sessions = array();
if (isset($formdata->addmultiply)) { if (isset($formdata->addmultiply)) {
$startdate = $sessiondate; $startdate = $sessiondate;
@ -607,6 +612,7 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
$sess->descriptionitemid = $formdata->sdescription['itemid']; $sess->descriptionitemid = $formdata->sdescription['itemid'];
$sess->description = $formdata->sdescription['text']; $sess->description = $formdata->sdescription['text'];
$sess->descriptionformat = $formdata->sdescription['format']; $sess->descriptionformat = $formdata->sdescription['format'];
$sess->calendarevent = $calendarevent;
$sess->timemodified = $now; $sess->timemodified = $now;
$sess->absenteereport = $absenteereport; $sess->absenteereport = $absenteereport;
$sess->studentpassword = ''; $sess->studentpassword = '';
@ -657,6 +663,7 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
$sess->descriptionitemid = $formdata->sdescription['itemid']; $sess->descriptionitemid = $formdata->sdescription['itemid'];
$sess->description = $formdata->sdescription['text']; $sess->description = $formdata->sdescription['text'];
$sess->descriptionformat = $formdata->sdescription['format']; $sess->descriptionformat = $formdata->sdescription['format'];
$sess->calendarevent = $calendarevent;
$sess->timemodified = $now; $sess->timemodified = $now;
$sess->studentscanmark = 0; $sess->studentscanmark = 0;
$sess->autoassignstatus = 0; $sess->autoassignstatus = 0;

6
resetcalendar.php

@ -47,9 +47,9 @@ $tabmenu = attendance_print_settings_tabs('resetcalendar');
echo $tabmenu; echo $tabmenu;
if (get_config('attendance', 'enablecalendar')) { if (get_config('attendance', 'enablecalendar')) {
// Check to see if all sessions have calendar events. // Check to see if all sessions that need them have calendar events.
if ($action == 'create' && confirm_sesskey()) { if ($action == 'create' && confirm_sesskey()) {
$sessions = $DB->get_recordset('attendance_sessions', array('caleventid' => 0)); $sessions = $DB->get_recordset('attendance_sessions', array('caleventid' => 0, 'calendarevent' => 1));
foreach ($sessions as $session) { foreach ($sessions as $session) {
attendance_create_calendar_event($session); attendance_create_calendar_event($session);
if ($session->caleventid) { if ($session->caleventid) {
@ -59,7 +59,7 @@ if (get_config('attendance', 'enablecalendar')) {
$sessions->close(); $sessions->close();
echo $OUTPUT->notification(get_string('eventscreated', 'mod_attendance'), 'notifysuccess'); echo $OUTPUT->notification(get_string('eventscreated', 'mod_attendance'), 'notifysuccess');
} else { } else {
if ($DB->record_exists('attendance_sessions', array('caleventid' => 0))) { if ($DB->record_exists('attendance_sessions', array('caleventid' => 0, 'calendarevent' => 1))) {
$createurl = new moodle_url('/mod/attendance/resetcalendar.php', array('action' => 'create')); $createurl = new moodle_url('/mod/attendance/resetcalendar.php', array('action' => 'create'));
$returnurl = new moodle_url('/admin/settings.php', array('section' => 'modsettingattendance')); $returnurl = new moodle_url('/admin/settings.php', array('section' => 'modsettingattendance'));

1
tests/attendance_webservices_test.php

@ -86,6 +86,7 @@ class attendance_webservices_tests extends advanced_testcase {
$session->statusset = 0; $session->statusset = 0;
$session->groupid = 0; $session->groupid = 0;
$session->absenteereport = 1; $session->absenteereport = 1;
$session->calendarevent = 0;
// Creating two sessions. // Creating two sessions.
$this->sessions[] = $session; $this->sessions[] = $session;

35
update_form.php

@ -62,19 +62,22 @@ class mod_attendance_update_form extends moodleform {
$endhour = floor($endtime / HOURSECS); $endhour = floor($endtime / HOURSECS);
$endminute = floor(($endtime - $endhour * HOURSECS) / MINSECS); $endminute = floor(($endtime - $endhour * HOURSECS) / MINSECS);
$data = array('sessiondate' => $sess->sessdate, $data = array(
'sestime' => array('starthour' => $starthour, 'startminute' => $startminute, 'sessiondate' => $sess->sessdate,
'endhour' => $endhour, 'endminute' => $endminute), 'sestime' => array('starthour' => $starthour, 'startminute' => $startminute,
'sdescription' => $sess->description_editor, 'endhour' => $endhour, 'endminute' => $endminute),
'studentscanmark' => $sess->studentscanmark, 'sdescription' => $sess->description_editor,
'studentpassword' => $sess->studentpassword, 'calendarevent' => $sess->calendarevent,
'autoassignstatus' => $sess->autoassignstatus, 'studentscanmark' => $sess->studentscanmark,
'subnet' => $sess->subnet, 'studentpassword' => $sess->studentpassword,
'automark' => $sess->automark, 'autoassignstatus' => $sess->autoassignstatus,
'absenteereport' => $sess->absenteereport, 'subnet' => $sess->subnet,
'automarkcompleted' => 0, 'automark' => $sess->automark,
'preventsharedip' => $sess->preventsharedip, 'absenteereport' => $sess->absenteereport,
'preventsharediptime' => $sess->preventsharediptime); 'automarkcompleted' => 0,
'preventsharedip' => $sess->preventsharedip,
'preventsharediptime' => $sess->preventsharediptime
);
if ($sess->subnet == $attendancesubnet) { if ($sess->subnet == $attendancesubnet) {
$data['usedefaultsubnet'] = 1; $data['usedefaultsubnet'] = 1;
} else { } else {
@ -110,6 +113,11 @@ class mod_attendance_update_form extends moodleform {
array('rows' => 1, 'columns' => 80), $defopts); array('rows' => 1, 'columns' => 80), $defopts);
$mform->setType('sdescription', PARAM_RAW); $mform->setType('sdescription', PARAM_RAW);
$mform->addElement('checkbox', 'calendarevent', '', get_string('calendarevent', 'attendance'));
$mform->addHelpButton('calendarevent', 'calendarevent', 'attendance');
// XXX - this should be modified to use a different config setting if we keep enablecalendar's current meaning
// $mform->setDefault('calendarevent', get_config('attendance', 'enablecalendar'));
// If warnings allow selector for reporting. // If warnings allow selector for reporting.
if (!empty(get_config('attendance', 'enablewarnings'))) { if (!empty(get_config('attendance', 'enablewarnings'))) {
$mform->addElement('checkbox', 'absenteereport', '', get_string('includeabsentee', 'attendance')); $mform->addElement('checkbox', 'absenteereport', '', get_string('includeabsentee', 'attendance'));
@ -185,7 +193,6 @@ class mod_attendance_update_form extends moodleform {
} }
$mform->setDefaults($data); $mform->setDefaults($data);
$this->add_action_buttons(true); $this->add_action_buttons(true);
} }

2
version.php

@ -23,7 +23,7 @@
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2018051401; $plugin->version = 2018051402;
$plugin->requires = 2018050800; // Requires 3.5. $plugin->requires = 2018050800; // Requires 3.5.
$plugin->release = '3.5.1'; $plugin->release = '3.5.1';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;

Loading…
Cancel
Save