Merge branch 'MDL-55956-master-5' of git://github.com/junpataleta/moodle

This commit is contained in:
Andrew Nicols 2017-03-07 12:07:50 +08:00
commit 342af35ab8
19 changed files with 864 additions and 174 deletions

View file

@ -233,5 +233,25 @@ function xmldb_assign_upgrade($oldversion) {
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2017021500) {
// Fix event types of assign events.
$params = [
'modulename' => 'assign',
'eventtype' => 'close'
];
$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');
}
return true;
}

View file

@ -226,10 +226,9 @@ function assign_update_events($assign, $override = null) {
}
$oldevents = $DB->get_records('event', $conds);
// Now make a todo list of all that needs to be updated.
// Now make a to-do list of all that needs to be updated.
if (empty($override)) {
// We are updating the primary settings for the assign, so we
// need to add all the overrides.
// We are updating the primary settings for the assign, so we need to add all the overrides.
$overrides = $DB->get_records('assign_overrides', array('assignid' => $assign->id));
// As well as the original assign (empty override).
$overrides[] = new stdClass();
@ -241,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)) {
@ -263,13 +259,14 @@ 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.
// Determine the event name and priority.
if ($groupid) {
// Group override event.
$params = new stdClass();
$params->assign = $assign->get_context()->name;
$params->group = groups_get_group_name($groupid);
@ -278,49 +275,32 @@ function assign_update_events($assign, $override = null) {
continue;
}
$eventname = get_string('overridegroupeventname', 'assign', $params);
// Set group override priority.
if (isset($current->sortorder)) {
$event->priority = $current->sortorder;
}
} else if ($userid) {
// User override event.
$params = new stdClass();
$params->assign = $assign->get_context()->name;
$eventname = get_string('overrideusereventname', 'assign', $params);
// Set user override priority.
$event->priority = CALENDAR_EVENT_USER_OVERRIDE_PRIORITY;
} else {
// The parent event.
$eventname = $assign->name;
}
if ($addopen or $addclose) {
if ($duedate and $allowsubmissionsfromdate and $event->timeduration <= ASSIGN_MAX_EVENT_LENGTH) {
// Single event for the whole assign.
if ($oldevent = array_shift($oldevents)) {
$event->id = $oldevent->id;
} else {
unset($event->id);
}
$event->name = $eventname;
// 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 {
// 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;
} else {
unset($event->id);
}
$event->name = $eventname.' ('.get_string('duedate', 'assign').')';
$event->timestart = $duedate;
$event->eventtype = 'close';
calendar_event::create($event);
}
unset($event->id);
}
$event->name = $eventname.' ('.get_string('duedate', 'assign').')';
$event->timestart = $duedate;
$event->eventtype = 'due';
calendar_event::create($event);
}
}

View file

@ -1160,8 +1160,14 @@ class assign {
if ($instance->duedate) {
$event = new stdClass();
// Fetch the original due date event. It will have a non-zero course ID and a zero group ID.
$select = "modulename = :modulename
AND instance = :instance
AND eventtype = :eventtype
AND groupid = 0
AND courseid <> 0";
$params = array('modulename' => 'assign', 'instance' => $instance->id, 'eventtype' => $eventtype);
$event->id = $DB->get_field('event', 'id', $params);
$event->id = $DB->get_field_select('event', 'id', $select, $params);
$event->name = $instance->name;
$event->timestart = $instance->duedate;
@ -8822,6 +8828,14 @@ function reorder_group_overrides($assignid) {
$f->id = $override->id;
$f->sortorder = $i++;
$DB->update_record('assign_overrides', $f);
// Update priorities of group overrides.
$params = [
'modulename' => 'assign',
'instance' => $override->assignid,
'groupid' => $override->groupid
];
$DB->set_field('event', 'priority', $f->sortorder, $params);
}
}
}

View file

@ -1,5 +1,10 @@
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:
- preventsubmissionnotingroup: Prevent submission not in group.

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'mod_assign'; // Full name of the plugin (used for diagnostics).
$plugin->version = 2016120500; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2017021500; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2016112900; // Requires this Moodle version.
$plugin->cron = 60;