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) { ...@@ -242,6 +242,13 @@ function xmldb_assign_upgrade($oldversion) {
$select = "modulename = :modulename AND eventtype = :eventtype"; $select = "modulename = :modulename AND eventtype = :eventtype";
$DB->set_field_select('event', 'eventtype', 'due', $select, $params); $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. // Assign savepoint reached.
upgrade_mod_savepoint(true, 2017021500, 'assign'); upgrade_mod_savepoint(true, 2017021500, 'assign');
} }
......
...@@ -240,12 +240,9 @@ function assign_update_events($assign, $override = null) { ...@@ -240,12 +240,9 @@ function assign_update_events($assign, $override = null) {
foreach ($overrides as $current) { foreach ($overrides as $current) {
$groupid = isset($current->groupid) ? $current->groupid : 0; $groupid = isset($current->groupid) ? $current->groupid : 0;
$userid = isset($current->userid) ? $current->userid : 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; $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. // Only add 'due' events for an override if they differ from the assign default.
$addopen = empty($current->id) || !empty($current->allowsubmissionsfromdate);
$addclose = empty($current->id) || !empty($current->duedate); $addclose = empty($current->id) || !empty($current->duedate);
if (!empty($assign->coursemodule)) { if (!empty($assign->coursemodule)) {
...@@ -262,10 +259,10 @@ function assign_update_events($assign, $override = null) { ...@@ -262,10 +259,10 @@ function assign_update_events($assign, $override = null) {
$event->userid = $userid; $event->userid = $userid;
$event->modulename = 'assign'; $event->modulename = 'assign';
$event->instance = $assign->get_context()->id; $event->instance = $assign->get_context()->id;
$event->timestart = $allowsubmissionsfromdate; $event->timestart = $duedate;
$event->timeduration = max($duedate - $allowsubmissionsfromdate, 0); $event->timeduration = 0;
$event->visible = instance_is_visible('assign', $assign); $event->visible = instance_is_visible('assign', $assign);
$event->eventtype = 'open'; $event->eventtype = 'due';
// Determine the event name and priority. // Determine the event name and priority.
if ($groupid) { if ($groupid) {
...@@ -294,30 +291,16 @@ function assign_update_events($assign, $override = null) { ...@@ -294,30 +291,16 @@ function assign_update_events($assign, $override = null) {
$eventname = $assign->name; $eventname = $assign->name;
} }
if ($addopen or $addclose) { if ($duedate && $addclose) {
// Separate start and end events. if ($oldevent = array_shift($oldevents)) {
$event->timeduration = 0; $event->id = $oldevent->id;
if ($allowsubmissionsfromdate && $addopen) { } else {
if ($oldevent = array_shift($oldevents)) { unset($event->id);
$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;
} else {
unset($event->id);
}
$event->name = $eventname.' ('.get_string('duedate', 'assign').')';
$event->timestart = $duedate;
$event->eventtype = 'due';
calendar_event::create($event);
} }
$event->name = $eventname.' ('.get_string('duedate', 'assign').')';
$event->timestart = $duedate;
$event->eventtype = 'due';
calendar_event::create($event);
} }
} }
......
...@@ -2,6 +2,8 @@ This files describes API changes in the assign code. ...@@ -2,6 +2,8 @@ This files describes API changes in the assign code.
=== 3.3 === === 3.3 ===
* Fixed calendar event types for overridden due dates from 'close' to 'due'. * 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 === === 3.2 ===
* External function mod_assign_external::get_assignments now returns additional optional fields: * 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