MDL-55956 mod: Set event priority for activity overrides
Set the event priority of the following activity overrides: * mod_assign * mod_lesson * mod_quiz Always create separate events for start and end dates of activities.
This commit is contained in:
@@ -233,5 +233,18 @@ 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);
|
||||
|
||||
// Assign savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2017021500, 'assign');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+27
-30
@@ -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();
|
||||
@@ -268,8 +267,9 @@ function assign_update_events($assign, $override = null) {
|
||||
$event->visible = instance_is_visible('assign', $assign);
|
||||
$event->eventtype = 'open';
|
||||
|
||||
// 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,48 +278,45 @@ 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.
|
||||
// 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;
|
||||
$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);
|
||||
} 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-1
@@ -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;
|
||||
|
||||
@@ -8818,6 +8824,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
This files describes API changes in the assign code.
|
||||
|
||||
=== 3.3 ===
|
||||
* Fixed calendar event types for overridden due dates from 'close' to 'due'.
|
||||
|
||||
=== 3.2 ===
|
||||
* External function mod_assign_external::get_assignments now returns additional optional fields:
|
||||
- preventsubmissionnotingroup: Prevent submission not in group.
|
||||
|
||||
@@ -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;
|
||||
|
||||
+37
-28
@@ -123,10 +123,9 @@ function lesson_update_events($lesson, $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 lesson, so we
|
||||
// need to add all the overrides.
|
||||
// We are updating the primary settings for the lesson, so we need to add all the overrides.
|
||||
$overrides = $DB->get_records('lesson_overrides', array('lessonid' => $lesson->id));
|
||||
// As well as the original lesson (empty override).
|
||||
$overrides[] = new stdClass();
|
||||
@@ -135,6 +134,9 @@ function lesson_update_events($lesson, $override = null) {
|
||||
$overrides = array($override);
|
||||
}
|
||||
|
||||
// Get group override priorities.
|
||||
$grouppriorities = lesson_get_group_override_priorities($lesson->id);
|
||||
|
||||
foreach ($overrides as $current) {
|
||||
$groupid = isset($current->groupid) ? $current->groupid : 0;
|
||||
$userid = isset($current->userid) ? $current->userid : 0;
|
||||
@@ -164,8 +166,9 @@ function lesson_update_events($lesson, $override = null) {
|
||||
$event->visible = instance_is_visible('lesson', $lesson);
|
||||
$event->eventtype = 'open';
|
||||
|
||||
// Determine the event name.
|
||||
// Determine the event name and priority.
|
||||
if ($groupid) {
|
||||
// Group override event.
|
||||
$params = new stdClass();
|
||||
$params->lesson = $lesson->name;
|
||||
$params->group = groups_get_group_name($groupid);
|
||||
@@ -174,48 +177,54 @@ function lesson_update_events($lesson, $override = null) {
|
||||
continue;
|
||||
}
|
||||
$eventname = get_string('overridegroupeventname', 'lesson', $params);
|
||||
// Set group override priority.
|
||||
if ($grouppriorities !== null) {
|
||||
$openpriorities = $grouppriorities['open'];
|
||||
if (isset($openpriorities[$available])) {
|
||||
$event->priority = $openpriorities[$available];
|
||||
}
|
||||
}
|
||||
} else if ($userid) {
|
||||
// User override event.
|
||||
$params = new stdClass();
|
||||
$params->lesson = $lesson->name;
|
||||
$eventname = get_string('overrideusereventname', 'lesson', $params);
|
||||
// Set user override priority.
|
||||
$event->priority = CALENDAR_EVENT_USER_OVERRIDE_PRIORITY;
|
||||
} else {
|
||||
// The parent event.
|
||||
$eventname = $lesson->name;
|
||||
}
|
||||
|
||||
if ($addopen or $addclose) {
|
||||
if ($deadline and $available and $event->timeduration <= LESSON_MAX_EVENT_LENGTH) {
|
||||
// Single event for the whole lesson.
|
||||
// Separate start and end events.
|
||||
$event->timeduration = 0;
|
||||
if ($available && $addopen) {
|
||||
if ($oldevent = array_shift($oldevents)) {
|
||||
$event->id = $oldevent->id;
|
||||
} else {
|
||||
unset($event->id);
|
||||
}
|
||||
$event->name = $eventname;
|
||||
$event->name = $eventname.' ('.get_string('lessonopens', 'lesson').')';
|
||||
// The method calendar_event::create will reuse a db record if the id field is set.
|
||||
calendar_event::create($event);
|
||||
} else {
|
||||
// Separate start and end events.
|
||||
$event->timeduration = 0;
|
||||
if ($available && $addopen) {
|
||||
if ($oldevent = array_shift($oldevents)) {
|
||||
$event->id = $oldevent->id;
|
||||
} else {
|
||||
unset($event->id);
|
||||
}
|
||||
$event->name = $eventname.' ('.get_string('lessonopens', 'lesson').')';
|
||||
// The method calendar_event::create will reuse a db record if the id field is set.
|
||||
calendar_event::create($event);
|
||||
}
|
||||
if ($deadline && $addclose) {
|
||||
if ($oldevent = array_shift($oldevents)) {
|
||||
$event->id = $oldevent->id;
|
||||
} else {
|
||||
unset($event->id);
|
||||
}
|
||||
if ($deadline && $addclose) {
|
||||
if ($oldevent = array_shift($oldevents)) {
|
||||
$event->id = $oldevent->id;
|
||||
} else {
|
||||
unset($event->id);
|
||||
$event->name = $eventname.' ('.get_string('lessoncloses', 'lesson').')';
|
||||
$event->timestart = $deadline;
|
||||
$event->eventtype = 'close';
|
||||
if ($groupid && $grouppriorities !== null) {
|
||||
$closepriorities = $grouppriorities['close'];
|
||||
if (isset($closepriorities[$deadline])) {
|
||||
$event->priority = $closepriorities[$deadline];
|
||||
}
|
||||
$event->name = $eventname.' ('.get_string('lessoncloses', 'lesson').')';
|
||||
$event->timestart = $deadline;
|
||||
$event->eventtype = 'close';
|
||||
calendar_event::create($event);
|
||||
}
|
||||
calendar_event::create($event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,14 @@ if ($mform->is_cancelled()) {
|
||||
$event->trigger();
|
||||
}
|
||||
|
||||
lesson_update_events($lesson, $fromform);
|
||||
if ($groupmode) {
|
||||
// Priorities may have shifted, so we need to update all of the calendar events for group overrides.
|
||||
lesson_update_events($lesson);
|
||||
} else {
|
||||
// User override. We only need to update the calendar event for this user override.
|
||||
lesson_update_events($lesson, $fromform);
|
||||
}
|
||||
|
||||
|
||||
if (!empty($fromform->submitbutton)) {
|
||||
redirect($overridelisturl);
|
||||
|
||||
+37
-28
@@ -1202,10 +1202,9 @@ function quiz_update_events($quiz, $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 quiz, so we
|
||||
// need to add all the overrides.
|
||||
// We are updating the primary settings for the lesson, so we need to add all the overrides.
|
||||
$overrides = $DB->get_records('quiz_overrides', array('quiz' => $quiz->id));
|
||||
// As well as the original quiz (empty override).
|
||||
$overrides[] = new stdClass();
|
||||
@@ -1214,6 +1213,9 @@ function quiz_update_events($quiz, $override = null) {
|
||||
$overrides = array($override);
|
||||
}
|
||||
|
||||
// Get group override priorities.
|
||||
$grouppriorities = quiz_get_group_override_priorities($quiz->id);
|
||||
|
||||
foreach ($overrides as $current) {
|
||||
$groupid = isset($current->groupid)? $current->groupid : 0;
|
||||
$userid = isset($current->userid)? $current->userid : 0;
|
||||
@@ -1243,8 +1245,9 @@ function quiz_update_events($quiz, $override = null) {
|
||||
$event->visible = instance_is_visible('quiz', $quiz);
|
||||
$event->eventtype = 'open';
|
||||
|
||||
// Determine the event name.
|
||||
// Determine the event name and priority.
|
||||
if ($groupid) {
|
||||
// Group override event.
|
||||
$params = new stdClass();
|
||||
$params->quiz = $quiz->name;
|
||||
$params->group = groups_get_group_name($groupid);
|
||||
@@ -1253,48 +1256,54 @@ function quiz_update_events($quiz, $override = null) {
|
||||
continue;
|
||||
}
|
||||
$eventname = get_string('overridegroupeventname', 'quiz', $params);
|
||||
// Set group override priority.
|
||||
if ($grouppriorities !== null) {
|
||||
$openpriorities = $grouppriorities['open'];
|
||||
if (isset($openpriorities[$timeopen])) {
|
||||
$event->priority = $openpriorities[$timeopen];
|
||||
}
|
||||
}
|
||||
} else if ($userid) {
|
||||
// User override event.
|
||||
$params = new stdClass();
|
||||
$params->quiz = $quiz->name;
|
||||
$eventname = get_string('overrideusereventname', 'quiz', $params);
|
||||
// Set user override priority.
|
||||
$event->priority = CALENDAR_EVENT_USER_OVERRIDE_PRIORITY;
|
||||
} else {
|
||||
// The parent event.
|
||||
$eventname = $quiz->name;
|
||||
}
|
||||
|
||||
if ($addopen or $addclose) {
|
||||
if ($timeclose and $timeopen and $event->timeduration <= QUIZ_MAX_EVENT_LENGTH) {
|
||||
// Single event for the whole quiz.
|
||||
// Separate start and end events.
|
||||
$event->timeduration = 0;
|
||||
if ($timeopen && $addopen) {
|
||||
if ($oldevent = array_shift($oldevents)) {
|
||||
$event->id = $oldevent->id;
|
||||
} else {
|
||||
unset($event->id);
|
||||
}
|
||||
$event->name = $eventname;
|
||||
$event->name = $eventname.' ('.get_string('quizopens', 'quiz').')';
|
||||
// The method calendar_event::create will reuse a db record if the id field is set.
|
||||
calendar_event::create($event);
|
||||
} else {
|
||||
// Separate start and end events.
|
||||
$event->timeduration = 0;
|
||||
if ($timeopen && $addopen) {
|
||||
if ($oldevent = array_shift($oldevents)) {
|
||||
$event->id = $oldevent->id;
|
||||
} else {
|
||||
unset($event->id);
|
||||
}
|
||||
$event->name = $eventname.' ('.get_string('quizopens', 'quiz').')';
|
||||
// The method calendar_event::create will reuse a db record if the id field is set.
|
||||
calendar_event::create($event);
|
||||
}
|
||||
if ($timeclose && $addclose) {
|
||||
if ($oldevent = array_shift($oldevents)) {
|
||||
$event->id = $oldevent->id;
|
||||
} else {
|
||||
unset($event->id);
|
||||
}
|
||||
if ($timeclose && $addclose) {
|
||||
if ($oldevent = array_shift($oldevents)) {
|
||||
$event->id = $oldevent->id;
|
||||
} else {
|
||||
unset($event->id);
|
||||
$event->name = $eventname.' ('.get_string('quizcloses', 'quiz').')';
|
||||
$event->timestart = $timeclose;
|
||||
$event->eventtype = 'close';
|
||||
if ($groupid && $grouppriorities !== null) {
|
||||
$closepriorities = $grouppriorities['close'];
|
||||
if (isset($closepriorities[$timeclose])) {
|
||||
$event->priority = $closepriorities[$timeclose];
|
||||
}
|
||||
$event->name = $eventname.' ('.get_string('quizcloses', 'quiz').')';
|
||||
$event->timestart = $timeclose;
|
||||
$event->eventtype = 'close';
|
||||
calendar_event::create($event);
|
||||
}
|
||||
calendar_event::create($event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +198,13 @@ if ($mform->is_cancelled()) {
|
||||
}
|
||||
|
||||
quiz_update_open_attempts(array('quizid'=>$quiz->id));
|
||||
quiz_update_events($quiz, $fromform);
|
||||
if ($groupmode) {
|
||||
// Priorities may have shifted, so we need to update all of the calendar events for group overrides.
|
||||
quiz_update_events($quiz);
|
||||
} else {
|
||||
// User override. We only need to update the calendar event for this user override.
|
||||
quiz_update_events($quiz, $fromform);
|
||||
}
|
||||
|
||||
if (!empty($fromform->submitbutton)) {
|
||||
redirect($overridelisturl);
|
||||
|
||||
Reference in New Issue
Block a user