All events equals all calendar events including completion events.
* only assignment events belonging to the course specified are checked.
*
* @param int $courseid
+ * @param int|stdClass $instance Assign module instance or ID.
+ * @param int|stdClass $cm Course module object or ID (not used in this module).
* @return bool
*/
-function assign_refresh_events($courseid = 0) {
+function assign_refresh_events($courseid = 0, $instance = null, $cm = null) {
global $CFG, $DB;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
+ // If we have instance information then we can just update the one event instead of updating all events.
+ if (isset($instance)) {
+ if (!is_object($instance)) {
+ $instance = $DB->get_record('assign', array('id' => $instance), '*', MUST_EXIST);
+ }
+ if (isset($cm)) {
+ if (!is_object($cm)) {
+ assign_prepare_update_events($instance);
+ return true;
+ } else {
+ $course = get_course($instance->course);
+ assign_prepare_update_events($instance, $course, $cm);
+ return true;
+ }
+ }
+ }
+
if ($courseid) {
// Make sure that the course id is numeric.
if (!is_numeric($courseid)) {
}
}
foreach ($assigns as $assign) {
+ assign_prepare_update_events($assign);
+ }
+
+ return true;
+}
+
+/**
+ * This actually updates the normal and completion calendar events.
+ *
+ * @param stdClass $assign Assignment object (from DB).
+ * @param stdClass $course Course object.
+ * @param stdClass $cm Course module object.
+ */
+function assign_prepare_update_events($assign, $course = null, $cm = null) {
+ global $DB;
+ if (!isset($course)) {
// Get course and course module for the assignment.
list($course, $cm) = get_course_and_cm_from_instance($assign->id, 'assign', $assign->course);
-
- // Refresh the assignment's calendar events.
- $context = context_module::instance($cm->id);
- $assignment = new assign($context, $cm, $course);
- $assignment->update_calendar($cm->id);
-
- // Refresh the calendar events also for the assignment overrides.
- $overrides = $DB->get_records('assign_overrides', ['assignid' => $assign->id], '',
- 'id, groupid, userid, duedate, sortorder');
- foreach ($overrides as $override) {
- if (empty($override->userid)) {
- unset($override->userid);
- }
- if (empty($override->groupid)) {
- unset($override->groupid);
- }
- assign_update_events($assignment, $override);
+ }
+ // Refresh the assignment's calendar events.
+ $context = context_module::instance($cm->id);
+ $assignment = new assign($context, $cm, $course);
+ $assignment->update_calendar($cm->id);
+ // Refresh the calendar events also for the assignment overrides.
+ $overrides = $DB->get_records('assign_overrides', ['assignid' => $assign->id], '',
+ 'id, groupid, userid, duedate, sortorder');
+ foreach ($overrides as $override) {
+ if (empty($override->userid)) {
+ unset($override->userid);
}
+ if (empty($override->groupid)) {
+ unset($override->groupid);
+ }
+ assign_update_events($assignment, $override);
}
-
- return true;
}
/**
// In the case of upgrades the coursemodule has not been set,
// so we need to wait before calling these two.
$this->update_calendar($formdata->coursemodule);
+ if (!empty($formdata->completionexpected)) {
+ \core_completion\api::update_completion_date_event($formdata->coursemodule, 'assign', $this->instance,
+ $formdata->completionexpected);
+ }
$this->update_gradebook(false, $formdata->coursemodule);
}
}
$this->update_calendar($this->get_course_module()->id);
+ $completionexpected = (!empty($formdata->completionexpected)) ? $formdata->completionexpected : null;
+ \core_completion\api::update_completion_date_event($this->get_course_module()->id, 'assign', $this->instance,
+ $completionexpected);
$this->update_gradebook(false, $this->get_course_module()->id);
$update = new stdClass();
* 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.
+* assign_refresh_events() Now takes two additional parameters to refine the update to a specific instance. This function
+ now optionally takes the module instance object or ID, and the course module object or ID. Please try to send the full
+ objects instead of the ids to save DB calls.
=== 3.2 ===
* External function mod_assign_external::get_assignments now returns additional optional fields:
calendar_event::create($event);
}
+
+ if (!empty($chat->completionexpected)) {
+ \core_completion\api::update_completion_date_event($chat->coursemodule, 'chat', $returnid, $chat->completionexpected);
+ }
+
return $returnid;
}
}
}
+ $completionexpected = (!empty($chat->completionexpected)) ? $chat->completionexpected : null;
+ \core_completion\api::update_completion_date_event($chat->coursemodule, 'chat', $chat->id, $completionexpected);
+
return true;
}
*
* @global object
* @param int $courseid
+ * @param int|stdClass $instance Chat module instance or ID.
+ * @param int|stdClass $cm Course module object or ID.
* @return bool
*/
-function chat_refresh_events($courseid = 0) {
+function chat_refresh_events($courseid = 0, $instance = null, $cm = null) {
global $DB;
+ // If we have instance information then we can just update the one event instead of updating all events.
+ if (isset($instance)) {
+ if (!is_object($instance)) {
+ $instance = $DB->get_record('chat', array('id' => $instance), '*', MUST_EXIST);
+ }
+ if (isset($cm)) {
+ if (!is_object($cm)) {
+ chat_prepare_update_events($instance);
+ return true;
+ } else {
+ chat_prepare_update_events($instance, $cm);
+ return true;
+ }
+ }
+ }
+
if ($courseid) {
if (! $chats = $DB->get_records("chat", array("course" => $courseid))) {
return true;
return true;
}
}
- $moduleid = $DB->get_field('modules', 'id', array('name' => 'chat'));
-
foreach ($chats as $chat) {
- $cm = get_coursemodule_from_instance('chat', $chat->id, $chat->course);
- $event = new stdClass();
- $event->name = $chat->name;
- $event->type = CALENDAR_EVENT_TYPE_ACTION;
- $event->description = format_module_intro('chat', $chat, $cm->id);
- $event->timestart = $chat->chattime;
- $event->timesort = $chat->chattime;
-
- if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'chat', 'instance' => $chat->id))) {
- $calendarevent = calendar_event::load($event->id);
- $calendarevent->update($event);
- } else if ($chat->schedule > 0) {
- // The chat is scheduled and the event should be published.
- $event->courseid = $chat->course;
- $event->groupid = 0;
- $event->userid = 0;
- $event->modulename = 'chat';
- $event->instance = $chat->id;
- $event->eventtype = CHAT_EVENT_TYPE_CHATTIME;
- $event->timeduration = 0;
- $event->visible = $DB->get_field('course_modules', 'visible', array('module' => $moduleid, 'instance' => $chat->id));
-
- calendar_event::create($event);
- }
+ chat_prepare_update_events($chat);
}
return true;
}
+/**
+ * Updates both the normal and completion calendar events for chat.
+ *
+ * @param stdClass $chat The chat object (from the DB)
+ * @param stdClass $cm The course module object.
+ */
+function chat_prepare_update_events($chat, $cm = null) {
+ global $DB;
+ if (!isset($cm)) {
+ $cm = get_coursemodule_from_instance('chat', $chat->id, $chat->course);
+ }
+ $event = new stdClass();
+ $event->name = $chat->name;
+ $event->type = CALENDAR_EVENT_TYPE_ACTION;
+ $event->description = format_module_intro('chat', $chat, $cm->id);
+ $event->timestart = $chat->chattime;
+ $event->timesort = $chat->chattime;
+ if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'chat', 'instance' => $chat->id))) {
+ $calendarevent = calendar_event::load($event->id);
+ $calendarevent->update($event);
+ } else if ($chat->schedule > 0) {
+ // The chat is scheduled and the event should be published.
+ $event->courseid = $chat->course;
+ $event->groupid = 0;
+ $event->userid = 0;
+ $event->modulename = 'chat';
+ $event->instance = $chat->id;
+ $event->eventtype = CHAT_EVENT_TYPE_CHATTIME;
+ $event->timeduration = 0;
+ $event->visible = $cm->visible;
+ calendar_event::create($event);
+ }
+}
+
// Functions that require some SQL.
/**
This files describes API changes in /mod/chat/*,
information provided here is intended especially for developers.
+=== 3.3 ===
+
+* chat_refresh_events() Now takes two additional parameters to refine the update to a specific instance. This function
+ now optionally takes the module instance object or ID, and the course module object or ID. Please try to send the full
+ objects instead of the ids to save DB calls.
=== 2.4 ===
// Add calendar events if necessary.
choice_set_events($choice);
+ if (!empty($choice->completionexpected)) {
+ \core_completion\api::update_completion_date_event($choice->coursemodule, 'choice', $choice->id,
+ $choice->completionexpected);
+ }
return $choice->id;
}
// Add calendar events if necessary.
choice_set_events($choice);
+ $completionexpected = (!empty($choice->completionexpected)) ? $choice->completionexpected : null;
+ \core_completion\api::update_completion_date_event($choice->coursemodule, 'choice', $choice->id, $completionexpected);
return $DB->update_record('choice', $choice);
/**
* This standard function will check all instances of this module
* and make sure there are up-to-date events created for each of them.
- * If courseid = 0, then every chat event in the site is checked, else
- * only chat events belonging to the course specified are checked.
+ * If courseid = 0, then every choice event in the site is checked, else
+ * only choice events belonging to the course specified are checked.
* This function is used, in its new format, by restore_refresh_events()
*
* @param int $courseid
+ * @param int|stdClass $instance Choice module instance or ID.
+ * @param int|stdClass $cm Course module object or ID (not used in this module).
* @return bool
*/
-function choice_refresh_events($courseid = 0) {
+function choice_refresh_events($courseid = 0, $instance = null, $cm = null) {
global $DB, $CFG;
require_once($CFG->dirroot.'/mod/choice/locallib.php');
+ // If we have instance information then we can just update the one event instead of updating all events.
+ if (isset($instance)) {
+ if (!is_object($instance)) {
+ $instance = $DB->get_record('choice', array('id' => $instance), '*', MUST_EXIST);
+ }
+ choice_set_events($instance);
+ return true;
+ }
+
if ($courseid) {
if (! $choices = $DB->get_records("choice", array("course" => $courseid))) {
return true;
This files describes API changes in /mod/choice/*,
information provided here is intended especially for developers.
+=== 3.3 ===
+
+* choice_refresh_events() Now takes two additional parameters to refine the update to a specific instance. This function
+ now optionally takes the module instance object or ID, and the course module object or ID. Please try to send the full
+ objects instead of the ids to save DB calls.
+
=== 3.2 ===
* Events mod_choice\event\answer_submitted and mod_choice\event\answer_updated
// Add calendar events if necessary.
data_set_events($data);
+ if (!empty($data->completionexpected)) {
+ \core_completion\api::update_completion_date_event($data->coursemodule, 'data', $data->id, $data->completionexpected);
+ }
data_grade_item_update($data);
// Add calendar events if necessary.
data_set_events($data);
+ $completionexpected = (!empty($data->completionexpected)) ? $data->completionexpected : null;
+ \core_completion\api::update_completion_date_event($data->coursemodule, 'data', $data->id, $completionexpected);
data_grade_item_update($data);
* This function is used, in its new format, by restore_refresh_events()
*
* @param int $courseid
+ * @param int|stdClass $instance Data module instance or ID.
+ * @param int|stdClass $cm Course module object or ID (not used in this module).
* @return bool
*/
-function data_refresh_events($courseid = 0) {
+function data_refresh_events($courseid = 0, $instance = null, $cm = null) {
global $DB, $CFG;
require_once($CFG->dirroot.'/mod/data/locallib.php');
+ // If we have instance information then we can just update the one event instead of updating all events.
+ if (isset($instance)) {
+ if (!is_object($instance)) {
+ $instance = $DB->get_record('data', array('id' => $instance), '*', MUST_EXIST);
+ }
+ data_set_events($instance);
+ return true;
+ }
+
if ($courseid) {
if (! $data = $DB->get_records("data", array("course" => $courseid))) {
return true;
* Required entries has been added to the Activity completion setting of mod_form. Entries required for completion
(in the entries section) is no longer displayed for new instances and will be deprecated in a future release
in favour of the new completion setting.
+* data_refresh_events() Now takes two additional parameters to refine the update to a specific instance. This function
+ now optionally takes the module instance object or ID, and the course module object or ID. Please try to send the full
+ objects instead of the ids to save DB calls.
=== 3.2 ===
}
$context = context_module::instance($feedback->coursemodule);
+ if (!empty($feedback->completionexpected)) {
+ \core_completion\api::update_completion_date_event($feedback->coursemodule, 'feedback', $feedback->id,
+ $feedback->completionexpected);
+ }
+
$editoroptions = feedback_get_editor_options();
// process the custom wysiwyg editor in page_after_submit
//create or update the new events
feedback_set_events($feedback);
+ $completionexpected = (!empty($feedback->completionexpected)) ? $feedback->completionexpected : null;
+ \core_completion\api::update_completion_date_event($feedback->coursemodule, 'feedback', $feedback->id, $completionexpected);
$context = context_module::instance($feedback->coursemodule);
* This function is used, in its new format, by restore_refresh_events()
*
* @param int $courseid
+ * @param int|stdClass $instance Feedback module instance or ID.
+ * @param int|stdClass $cm Course module object or ID (not used in this module).
* @return bool
*/
-function feedback_refresh_events($courseid = 0) {
+function feedback_refresh_events($courseid = 0, $instance = null, $cm = null) {
global $DB;
+ // If we have instance information then we can just update the one event instead of updating all events.
+ if (isset($instance)) {
+ if (!is_object($instance)) {
+ $instance = $DB->get_record('feedback', array('id' => $instance), '*', MUST_EXIST);
+ }
+ feedback_set_events($instance);
+ return true;
+ }
+
if ($courseid) {
if (! $feedbacks = $DB->get_records("feedback", array("course" => $courseid))) {
return true;
* Method get_current_completed_tmp in mod_feedback_completion class is now public.
* Function feedback_set_tmp_values is not deprecated anymore.
+* feedback_refresh_events() Now takes two additional parameters to refine the update to a specific instance. This function
+ now optionally takes the module instance object or ID, and the course module object or ID. Please try to send the full
+ objects instead of the ids to save DB calls.
=== 3.1 ===
* This function is used, in its new format, by restore_refresh_events()
*
* @param int $courseid
+ * @param int|stdClass $instance Lesson module instance or ID.
+ * @param int|stdClass $cm Course module object or ID (not used in this module).
* @return bool
*/
-function lesson_refresh_events($courseid = 0) {
+function lesson_refresh_events($courseid = 0, $instance = null, $cm = null) {
global $DB;
+ // If we have instance information then we can just update the one event instead of updating all events.
+ if (isset($instance)) {
+ if (!is_object($instance)) {
+ $instance = $DB->get_record('lesson', array('id' => $instance), '*', MUST_EXIST);
+ }
+ lesson_update_events($instance);
+ return true;
+ }
+
if ($courseid == 0) {
if (!$lessons = $DB->get_records('lesson')) {
return true;
function lesson_process_post_save(&$lesson) {
// Update the events relating to this lesson.
lesson_update_events($lesson);
+ $completionexpected = (!empty($lesson->completionexpected)) ? $lesson->completionexpected : null;
+ \core_completion\api::update_completion_date_event($lesson->coursemodule, 'lesson', $lesson, $completionexpected);
}
* lesson::callback_on_view() has an additional optional parameter $redirect default to true.
It can be set to false to avoid redirection and return the page to redirect.
+* lesson_refresh_events() Now takes two additional parameters to refine the update to a specific instance. This function
+ now optionally takes the module instance object or ID, and the course module object or ID. Please try to send the full
+ objects instead of the ids to save DB calls.
=== 3.1 ===
* Removed the unused file reformat.php
* This function is used, in its new format, by restore_refresh_events()
*
* @param int $courseid
+ * @param int|stdClass $instance Quiz module instance or ID.
+ * @param int|stdClass $cm Course module object or ID (not used in this module).
* @return bool
*/
-function quiz_refresh_events($courseid = 0) {
+function quiz_refresh_events($courseid = 0, $instance = null, $cm = null) {
global $DB;
+ // If we have instance information then we can just update the one event instead of updating all events.
+ if (isset($instance)) {
+ if (!is_object($instance)) {
+ $instance = $DB->get_record('quiz', array('id' => $instance), '*', MUST_EXIST);
+ }
+ quiz_update_events($instance);
+ return true;
+ }
+
if ($courseid == 0) {
if (!$quizzes = $DB->get_records('quiz')) {
return true;
// Update the events relating to this quiz.
quiz_update_events($quiz);
+ $completionexpected = (!empty($quiz->completionexpected)) ? $quiz->completionexpected : null;
+ \core_completion\api::update_completion_date_event($quiz->coursemodule, 'quiz', $quiz->id, $completionexpected);
// Update related grade item.
quiz_grade_item_update($quiz);
This files describes API changes in the quiz code.
+=== 3.3 ===
+
+* quiz_refresh_events() Now takes two additional parameters to refine the update to a specific instance. This function
+ now optionally takes the module instance object or ID, and the course module object or ID. Please try to send the full
+ objects instead of the ids to save DB calls.
+
=== 3.2 ===
* External functions mod_quiz_external::get_attempt_data, mod_quiz_external::get_attempt_summary
scorm_grade_item_update($record);
scorm_update_calendar($record, $cmid);
+ if (!empty($scorm->completionexpected)) {
+ \core_completion\api::update_completion_date_event($cmid, 'scorm', $record, $scorm->completionexpected);
+ }
return $record->id;
}
}
$DB->update_record('scorm', $scorm);
+ // We need to find this out before we blow away the form data.
+ $completionexpected = (!empty($scorm->completionexpected)) ? $scorm->completionexpected : null;
$scorm = $DB->get_record('scorm', array('id' => $scorm->id));
scorm_grade_item_update($scorm);
scorm_update_grades($scorm);
scorm_update_calendar($scorm, $cmid);
+ \core_completion\api::update_completion_date_event($cmid, 'scorm', $scorm, $completionexpected);
return true;
}
* only scorm events belonging to the course specified are checked.
*
* @param int $courseid
+ * @param int|stdClass $instance scorm module instance or ID.
+ * @param int|stdClass $cm Course module object or ID.
* @return bool
*/
-function scorm_refresh_events($courseid = 0) {
+function scorm_refresh_events($courseid = 0, $instance = null, $cm = null) {
global $CFG, $DB;
require_once($CFG->dirroot . '/mod/scorm/locallib.php');
+ // If we have instance information then we can just update the one event instead of updating all events.
+ if (isset($instance)) {
+ if (!is_object($instance)) {
+ $instance = $DB->get_record('scorm', array('id' => $instance), '*', MUST_EXIST);
+ }
+ if (isset($cm)) {
+ if (!is_object($cm)) {
+ $cm = (object)array('id' => $cm);
+ }
+ } else {
+ $cm = get_coursemodule_from_instance('scorm', $instance->id);
+ }
+ scorm_update_calendar($instance, $cm->id);
+ return true;
+ }
+
if ($courseid) {
// Make sure that the course id is numeric.
if (!is_numeric($courseid)) {
This files describes API changes in the mod_scorm code.
+=== 3.3 ===
+
+* scorm_refresh_events() Now takes two additional parameters to refine the update to a specific instance. This function
+ now optionally takes the module instance object or ID, and the course module object or ID. Please try to send the full
+ objects instead of the ids to save DB calls.
+
=== 3.1 ===
* Group and groupings support has now been enabled.
// create calendar events
workshop_calendar_update($workshop, $workshop->coursemodule);
+ if (!empty($workshop->completionexpected)) {
+ \core_completion\api::update_completion_date_event($cmid, 'workshop', $workshop->id, $workshop->completionexpected);
+ }
return $workshop->id;
}
// update calendar events
workshop_calendar_update($workshop, $workshop->coursemodule);
+ $completionexpected = (!empty($workshop->completionexpected)) ? $workshop->completionexpected : null;
+ \core_completion\api::update_completion_date_event($workshop->coursemodule, 'workshop', $workshop->id, $completionexpected);
return true;
}
* only workshop events belonging to the course specified are checked.
*
* @param integer $courseid The Course ID.
+ * @param int|stdClass $instance workshop module instance or ID.
+ * @param int|stdClass $cm Course module object or ID.
* @return bool Returns true if the calendar events were successfully updated.
*/
-function workshop_refresh_events($courseid = 0) {
+function workshop_refresh_events($courseid = 0, $instance = null, $cm = null) {
global $DB;
+ // If we have instance information then we can just update the one event instead of updating all events.
+ if (isset($instance)) {
+ if (!is_object($instance)) {
+ $instance = $DB->get_record('workshop', array('id' => $instance), '*', MUST_EXIST);
+ }
+ if (isset($cm)) {
+ if (!is_object($cm)) {
+ $cm = (object)array('id' => $cm);
+ }
+ } else {
+ $cm = get_coursemodule_from_instance('workshop', $instance->id);
+ }
+ workshop_calendar_update($instance, $cm->id);
+ return true;
+ }
+
if ($courseid) {
// Make sure that the course id is numeric.
if (!is_numeric($courseid)) {
This files describes API changes in /mod/workshop - activity modules,
information provided here is intended especially for developers.
+=== 3.3 ===
+
+* workshop_refresh_events() Now takes two additional parameters to refine the update to a specific instance. This function
+ now optionally takes the module instance object or ID, and the course module object or ID. Please try to send the full
+ objects instead of the ids to save DB calls.
+
=== 2.7 ===
* The method workshop::log() has been deprecated in the workshop module. Please use the event classes instead