Commit f7a9bca8 authored by jun's avatar jun
Browse files

MDL-55956 mod_assign: Remove calendar events with 'open' eventtype

Remove creation of calendar events for mod_assign with
eventtype = 'open'. Since mod_assign instance creation only creates a
calendar event for the due date, there's no point in creating an override
event for an event type that does not exist.
parent f52459bb
......@@ -242,6 +242,13 @@ function xmldb_assign_upgrade($oldversion) {
$select = "modulename = :modulename AND eventtype = :eventtype";
$DB->set_field_select('event', 'eventtype', 'due', $select, $params);
// Delete 'open' events.
$params = [
'modulename' => 'assign',
'eventtype' => 'open'
];
$DB->delete_records('event', $params);
// Assign savepoint reached.
upgrade_mod_savepoint(true, 2017021500, 'assign');
}
......
......@@ -240,12 +240,9 @@ function assign_update_events($assign, $override = null) {
foreach ($overrides as $current) {
$groupid = isset($current->groupid) ? $current->groupid : 0;
$userid = isset($current->userid) ? $current->userid : 0;
$allowsubmissionsfromdate = isset($current->allowsubmissionsfromdate
) ? $current->allowsubmissionsfromdate : $assign->get_context()->allowsubmissionsfromdate;
$duedate = isset($current->duedate) ? $current->duedate : $assign->get_context()->duedate;
// Only add open/close events for an override if they differ from the assign default.
$addopen = empty($current->id) || !empty($current->allowsubmissionsfromdate);
// Only add 'due' events for an override if they differ from the assign default.
$addclose = empty($current->id) || !empty($current->duedate);
if (!empty($assign->coursemodule)) {
......@@ -262,10 +259,10 @@ function assign_update_events($assign, $override = null) {
$event->userid = $userid;
$event->modulename = 'assign';
$event->instance = $assign->get_context()->id;
$event->timestart = $allowsubmissionsfromdate;
$event->timeduration = max($duedate - $allowsubmissionsfromdate, 0);
$event->timestart = $duedate;
$event->timeduration = 0;
$event->visible = instance_is_visible('assign', $assign);
$event->eventtype = 'open';
$event->eventtype = 'due';
// Determine the event name and priority.
if ($groupid) {
......@@ -294,19 +291,6 @@ function assign_update_events($assign, $override = null) {
$eventname = $assign->name;
}
if ($addopen or $addclose) {
// Separate start and end events.
$event->timeduration = 0;
if ($allowsubmissionsfromdate && $addopen) {
if ($oldevent = array_shift($oldevents)) {
$event->id = $oldevent->id;
} else {
unset($event->id);
}
$event->name = $eventname.' ('.get_string('open', 'assign').')';
// The method calendar_event::create will reuse a db record if the id field is set.
calendar_event::create($event);
}
if ($duedate && $addclose) {
if ($oldevent = array_shift($oldevents)) {
$event->id = $oldevent->id;
......@@ -319,7 +303,6 @@ function assign_update_events($assign, $override = null) {
calendar_event::create($event);
}
}
}
// Delete any leftover events.
foreach ($oldevents as $badevent) {
......
......@@ -2,6 +2,8 @@ This files describes API changes in the assign code.
=== 3.3 ===
* Fixed calendar event types for overridden due dates from 'close' to 'due'.
* Removed calendar event type of 'open', since mod_assign only has the 'due' event type. No point in creating an override event
for an event type that does not exist.
=== 3.2 ===
* External function mod_assign_external::get_assignments now returns additional optional fields:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment