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. 13
      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));
$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 (!empty(get_config('attendance', 'enablewarnings'))) {
$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) {
return $session->caleventid;
}
if (empty(get_config('attendance', 'enablecalendar'))) {
// Calendar events are not used.
if (empty(get_config('attendance', 'enablecalendar')) || $session->calendarevent === 0) {
// Calendar events are not used, or event not required for this session.
return true;
}
@ -98,18 +98,42 @@ function attendance_create_calendar_events($sessionsids) {
/**
* Update calendar event duration and date
*
* @param int $caleventid calendar event id
* @param int $timeduration duration of the event
* @param int $timestart start time of the event
* @param stdClass $session Session data
* @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'))) {
// Calendar events are not used.
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->timeduration = $timeduration;
$caleventdata->timestart = $timestart;

7
classes/import/sessions.php

@ -109,7 +109,8 @@ class sessions {
get_string('autoassignstatus', 'attendance'),
get_string('absenteereport', '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,
'preventsharedip' => $data->header16,
'preventsharediptime' => $data->header17,
'calendarevent' => $data->header18
);
} else {
return array(
@ -168,7 +170,8 @@ class sessions {
'autoassignstatus' => 14,
'absenteereport' => 15,
'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']);
$sess->description = $description;
$sess->descriptionformat = $formdata->sdescription['format'];
$sess->calendarevent = empty($formdata->calendarevent) ? 0 : $formdata->calendarevent;
$sess->studentscanmark = 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.
attendance_create_calendar_event($sess);
} 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);
@ -1200,7 +1201,7 @@ class mod_attendance_structure {
$sess->timemodified = $now;
$DB->update_record('attendance_sessions', $sess);
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(
'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="preventsharediptime" TYPE="int" LENGTH="10" NOTNULL="false" 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>
<KEYS>
<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');
}
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;
}

3
lang/en/attendance.php

@ -78,6 +78,9 @@ $string['autorecorded'] = 'system auto recorded';
$string['averageattendance'] = 'Average attendance';
$string['averageattendancegraded'] = 'Average attendance';
$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['caleventdeleted'] = 'Calendar event for session successfully deleted';
$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;
}
$calendarevent = 0;
if (isset($formdata->calendarevent)) { // Calendar event should be created
$calendarevent = 1;
}
$sessions = array();
if (isset($formdata->addmultiply)) {
$startdate = $sessiondate;
@ -607,6 +612,7 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
$sess->descriptionitemid = $formdata->sdescription['itemid'];
$sess->description = $formdata->sdescription['text'];
$sess->descriptionformat = $formdata->sdescription['format'];
$sess->calendarevent = $calendarevent;
$sess->timemodified = $now;
$sess->absenteereport = $absenteereport;
$sess->studentpassword = '';
@ -657,6 +663,7 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st
$sess->descriptionitemid = $formdata->sdescription['itemid'];
$sess->description = $formdata->sdescription['text'];
$sess->descriptionformat = $formdata->sdescription['format'];
$sess->calendarevent = $calendarevent;
$sess->timemodified = $now;
$sess->studentscanmark = 0;
$sess->autoassignstatus = 0;

6
resetcalendar.php

@ -47,9 +47,9 @@ $tabmenu = attendance_print_settings_tabs('resetcalendar');
echo $tabmenu;
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()) {
$sessions = $DB->get_recordset('attendance_sessions', array('caleventid' => 0));
$sessions = $DB->get_recordset('attendance_sessions', array('caleventid' => 0, 'calendarevent' => 1));
foreach ($sessions as $session) {
attendance_create_calendar_event($session);
if ($session->caleventid) {
@ -59,7 +59,7 @@ if (get_config('attendance', 'enablecalendar')) {
$sessions->close();
echo $OUTPUT->notification(get_string('eventscreated', 'mod_attendance'), 'notifysuccess');
} 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'));
$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->groupid = 0;
$session->absenteereport = 1;
$session->calendarevent = 0;
// Creating two sessions.
$this->sessions[] = $session;

13
update_form.php

@ -62,10 +62,12 @@ class mod_attendance_update_form extends moodleform {
$endhour = floor($endtime / HOURSECS);
$endminute = floor(($endtime - $endhour * HOURSECS) / MINSECS);
$data = array('sessiondate' => $sess->sessdate,
$data = array(
'sessiondate' => $sess->sessdate,
'sestime' => array('starthour' => $starthour, 'startminute' => $startminute,
'endhour' => $endhour, 'endminute' => $endminute),
'sdescription' => $sess->description_editor,
'calendarevent' => $sess->calendarevent,
'studentscanmark' => $sess->studentscanmark,
'studentpassword' => $sess->studentpassword,
'autoassignstatus' => $sess->autoassignstatus,
@ -74,7 +76,8 @@ class mod_attendance_update_form extends moodleform {
'absenteereport' => $sess->absenteereport,
'automarkcompleted' => 0,
'preventsharedip' => $sess->preventsharedip,
'preventsharediptime' => $sess->preventsharediptime);
'preventsharediptime' => $sess->preventsharediptime
);
if ($sess->subnet == $attendancesubnet) {
$data['usedefaultsubnet'] = 1;
} else {
@ -110,6 +113,11 @@ class mod_attendance_update_form extends moodleform {
array('rows' => 1, 'columns' => 80), $defopts);
$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 (!empty(get_config('attendance', 'enablewarnings'))) {
$mform->addElement('checkbox', 'absenteereport', '', get_string('includeabsentee', 'attendance'));
@ -185,7 +193,6 @@ class mod_attendance_update_form extends moodleform {
}
$mform->setDefaults($data);
$this->add_action_buttons(true);
}

2
version.php

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

Loading…
Cancel
Save