Commit b3bd7a66 authored by Mark Nelson's avatar Mark Nelson Committed by Damyon Wiese
Browse files

MDL-57878 mod_*: added inclusion of completion event and callbacks

Part of MDL-55611 epic.
parent 88d14007
......@@ -88,7 +88,12 @@ function book_add_instance($data, $mform) {
$data->customtitles = 0;
}
return $DB->insert_record('book', $data);
$id = $DB->insert_record('book', $data);
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($data->coursemodule, 'book', $id, $completiontimeexpected);
return $id;
}
/**
......@@ -112,6 +117,9 @@ function book_update_instance($data, $mform) {
$book = $DB->get_record('book', array('id'=>$data->id));
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($data->coursemodule, 'book', $book->id, $completiontimeexpected);
return true;
}
......@@ -128,6 +136,9 @@ function book_delete_instance($id) {
return false;
}
$cm = get_coursemodule_from_instance('book', $id);
\core_completion\api::update_completion_date_event($cm->id, 'book', $id, null);
$DB->delete_records('book_chapters', array('bookid'=>$book->id));
$DB->delete_records('book', array('id'=>$book->id));
......@@ -686,3 +697,37 @@ function mod_book_get_fontawesome_icon_map() {
'mod_book:nav_exit' => 'fa-arrow-up',
];
}
/**
* Handles creating actions for events.
*
* @param \core_calendar\event $event
* @param \core_calendar\action_factory $factory
* @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
*/
function mod_book_core_calendar_provide_event_action(\core_calendar\event $event,
\core_calendar\action_factory $factory) {
$cm = get_fast_modinfo($event->courseid)->instances['book'][$event->instance];
$context = context_module::instance($cm->id);
if (!has_capability('mod/book:read', $context)) {
return null;
}
$course = new stdClass();
$course->id = $event->courseid;
$completion = new \completion_info($course);
$completiondata = $completion->get_data($cm, false);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/book/view.php', ['id' => $cm->id]),
1,
true
);
}
\ No newline at end of file
......@@ -119,6 +119,9 @@ function folder_add_instance($data, $mform) {
file_save_draft_area_files($draftitemid, $context->id, 'mod_folder', 'content', 0, array('subdirs'=>true));
}
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($data->coursemodule, 'folder', $data->id, $completiontimeexpected);
return $data->id;
}
......@@ -145,6 +148,9 @@ function folder_update_instance($data, $mform) {
file_save_draft_area_files($draftitemid, $context->id, 'mod_folder', 'content', 0, array('subdirs'=>true));
}
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($data->coursemodule, 'folder', $data->id, $completiontimeexpected);
return true;
}
......@@ -160,6 +166,9 @@ function folder_delete_instance($id) {
return false;
}
$cm = get_coursemodule_from_instance('folder', $id);
\core_completion\api::update_completion_date_event($cm->id, 'folder', $folder->id, null);
// note: all context files are deleted automatically
$DB->delete_records('folder', array('id'=>$folder->id));
......@@ -761,3 +770,32 @@ function folder_check_updates_since(cm_info $cm, $from, $filter = array()) {
$updates = course_check_module_updates_since($cm, $from, array('content'), $filter);
return $updates;
}
/**
* Handles creating actions for events.
*
* @param \core_calendar\event $event
* @param \core_calendar\action_factory $factory
* @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
*/
function mod_folder_core_calendar_provide_event_action(\core_calendar\event $event,
\core_calendar\action_factory $factory) {
$cm = get_fast_modinfo($event->courseid)->instances['folder'][$event->instance];
$course = new stdClass();
$course->id = $event->courseid;
$completion = new \completion_info($course);
$completiondata = $completion->get_data($cm, false);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/folder/view.php', ['id' => $cm->id]),
1,
true
);
}
......@@ -130,6 +130,9 @@ function forum_add_instance($forum, $mform = null) {
forum_grade_item_update($forum);
$completiontimeexpected = !empty($forum->completionexpected) ? $forum->completionexpected : null;
\core_completion\api::update_completion_date_event($forum->coursemodule, 'forum', $forum->id, $completiontimeexpected);
return $forum->id;
}
......@@ -249,6 +252,9 @@ function forum_update_instance($forum, $mform) {
forum_grade_item_update($forum);
$completiontimeexpected = !empty($forum->completionexpected) ? $forum->completionexpected : null;
\core_completion\api::update_completion_date_event($forum->coursemodule, 'forum', $forum->id, $completiontimeexpected);
return true;
}
......@@ -283,6 +289,8 @@ function forum_delete_instance($id) {
$result = true;
\core_completion\api::update_completion_date_event($cm->id, 'forum', $forum->id, null);
// Delete digest and subscription preferences.
$DB->delete_records('forum_digests', array('forum' => $forum->id));
$DB->delete_records('forum_subscriptions', array('forum'=>$forum->id));
......@@ -8128,4 +8136,38 @@ function mod_forum_get_fontawesome_icon_map() {
function mod_forum_core_calendar_event_action_shows_item_count(\core_calendar\event $event, $itemcount = 0) {
// Always show item count for forums if item count is greater than 0.
return $itemcount > 0;
}
\ No newline at end of file
}
/**
* Handles creating actions for events.
*
* @param \core_calendar\event $event
* @param \core_calendar\action_factory $factory
* @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
*/
function mod_forum_core_calendar_provide_event_action(\core_calendar\event $event,
\core_calendar\action_factory $factory) {
$cm = get_fast_modinfo($event->courseid)->instances['forum'][$event->instance];
$context = context_module::instance($cm->id);
if (!has_capability('mod/forum:viewdiscussion', $context)) {
return null;
}
$course = new stdClass();
$course->id = $event->courseid;
$completion = new \completion_info($course);
$completiondata = $completion->get_data($cm, false);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/forum/view.php', ['id' => $cm->id]),
1,
true
);
}
......@@ -88,6 +88,10 @@ function glossary_add_instance($glossary) {
$glossary->id = $returnid;
glossary_grade_item_update($glossary);
$completiontimeexpected = !empty($glossary->completionexpected) ? $glossary->completionexpected : null;
\core_completion\api::update_completion_date_event($glossary->coursemodule,
'glossary', $glossary->id, $completiontimeexpected);
return $returnid;
}
......@@ -133,6 +137,10 @@ function glossary_update_instance($glossary) {
}
glossary_grade_item_update($glossary);
$completiontimeexpected = !empty($glossary->completionexpected) ? $glossary->completionexpected : null;
\core_completion\api::update_completion_date_event($glossary->coursemodule,
'glossary', $glossary->id, $completiontimeexpected);
return true;
}
......@@ -212,6 +220,8 @@ function glossary_delete_instance($id) {
glossary_grade_item_delete($glossary);
\core_completion\api::update_completion_date_event($cm->id, 'glossary', $glossary->id, null);
$DB->delete_records('glossary', array('id'=>$id));
// Reset caches.
......@@ -4159,3 +4169,32 @@ function forum_get_fontawesome_icon_map() {
'mod_glossary:export' => 'fa-download'
];
}
/**
* Handles creating actions for events.
*
* @param \core_calendar\event $event
* @param \core_calendar\action_factory $factory
* @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
*/
function mod_glossary_core_calendar_provide_event_action(\core_calendar\event $event,
\core_calendar\action_factory $factory) {
$cm = get_fast_modinfo($event->courseid)->instances['glossary'][$event->instance];
$course = new stdClass();
$course->id = $event->courseid;
$completion = new \completion_info($course);
$completiondata = $completion->get_data($cm, false);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/glossary/view.php', ['id' => $cm->id]),
1,
true
);
}
......@@ -133,6 +133,9 @@ function imscp_add_instance($data, $mform) {
}
}
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($cmid, 'imscp', $data->id, $completiontimeexpected);
return $data->id;
}
......@@ -196,6 +199,9 @@ function imscp_update_instance($data, $mform) {
$imscp->structure = is_array($structure) ? serialize($structure) : null;
$DB->update_record('imscp', $imscp);
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($cmid, 'imscp', $imscp->id, $completiontimeexpected);
return true;
}
......@@ -211,6 +217,9 @@ function imscp_delete_instance($id) {
return false;
}
$cm = get_coursemodule_from_instance('imscp', $id);
\core_completion\api::update_completion_date_event($cm->id, 'imscp', $id, null);
// Note: all context files are deleted automatically.
$DB->delete_records('imscp', array('id' => $imscp->id));
......@@ -458,3 +467,32 @@ function imscp_check_updates_since(cm_info $cm, $from, $filter = array()) {
$updates = course_check_module_updates_since($cm, $from, array('content'), $filter);
return $updates;
}
/**
* Handles creating actions for events.
*
* @param \core_calendar\event $event
* @param \core_calendar\action_factory $factory
* @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
*/
function mod_imscp_core_calendar_provide_event_action(\core_calendar\event $event,
\core_calendar\action_factory $factory) {
$cm = get_fast_modinfo($event->courseid)->instances['imscp'][$event->instance];
$course = new stdClass();
$course->id = $event->courseid;
$completion = new \completion_info($course);
$completiondata = $completion->get_data($cm, false);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/imscp/view.php', ['id' => $cm->id]),
1,
true
);
}
......@@ -62,7 +62,12 @@ function label_add_instance($label) {
$label->name = get_label_name($label);
$label->timemodified = time();
return $DB->insert_record("label", $label);
$id = $DB->insert_record("label", $label);
$completiontimeexpected = !empty($label->completionexpected) ? $label->completionexpected : null;
\core_completion\api::update_completion_date_event($label->coursemodule, 'label', $id, $completiontimeexpected);
return $id;
}
/**
......@@ -81,6 +86,9 @@ function label_update_instance($label) {
$label->timemodified = time();
$label->id = $label->instance;
$completiontimeexpected = !empty($label->completionexpected) ? $label->completionexpected : null;
\core_completion\api::update_completion_date_event($label->coursemodule, 'label', $label->id, $completiontimeexpected);
return $DB->update_record("label", $label);
}
......@@ -102,6 +110,9 @@ function label_delete_instance($id) {
$result = true;
$cm = get_coursemodule_from_instance('label', $id);
\core_completion\api::update_completion_date_event('label', $label->id, null);
if (! $DB->delete_records("label", array("id"=>$label->id))) {
$result = false;
}
......@@ -338,3 +349,32 @@ function label_check_updates_since(cm_info $cm, $from, $filter = array()) {
$updates = course_check_module_updates_since($cm, $from, array(), $filter);
return $updates;
}
/**
* Handles creating actions for events.
*
* @param \core_calendar\event $event
* @param \core_calendar\action_factory $factory
* @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
*/
function mod_label_core_calendar_provide_event_action(\core_calendar\event $event,
\core_calendar\action_factory $factory) {
$cm = get_fast_modinfo($event->courseid)->instances['label'][$event->instance];
$course = new stdClass();
$course->id = $event->courseid;
$completion = new \completion_info($course);
$completiondata = $completion->get_data($cm, false);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/label/view.php', ['id' => $cm->id]),
1,
true
);
}
......@@ -127,6 +127,9 @@ function lti_add_instance($lti, $mform) {
lti_grade_item_update($lti);
}
$completiontimeexpected = !empty($lti->completionexpected) ? $lti->completionexpected : null;
\core_completion\api::update_completion_date_event($lti->coursemodule, 'lti', $lti->id, $completiontimeexpected);
return $lti->id;
}
......@@ -171,6 +174,9 @@ function lti_update_instance($lti, $mform) {
$lti->typeid = $lti->urlmatchedtypeid;
}
$completiontimeexpected = !empty($lti->completionexpected) ? $lti->completionexpected : null;
\core_completion\api::update_completion_date_event($lti->coursemodule, 'lti', $lti->id, $completiontimeexpected);
return $DB->update_record('lti', $lti);
}
......@@ -200,6 +206,9 @@ function lti_delete_instance($id) {
array('toolproxyid' => $ltitype->toolproxyid, 'course' => $basiclti->course, 'coursemoduleid' => $id));
}
$cm = get_coursemodule_from_instance('lti', $id);
\core_completion\api::update_completion_date_event($cm->id, 'lti', $id, null);
return $DB->delete_records("lti", array("id" => $basiclti->id));
}
......@@ -615,3 +624,32 @@ function mod_lti_get_fontawesome_icon_map() {
'mod_lti:warning' => 'fa-exclamation text-warning',
];
}
/**
* Handles creating actions for events.
*
* @param \core_calendar\event $event
* @param \core_calendar\action_factory $factory
* @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
*/
function mod_lti_core_calendar_provide_event_action(\core_calendar\event $event,
\core_calendar\action_factory $factory) {
$cm = get_fast_modinfo($event->courseid)->instances['lti'][$event->instance];
$course = new stdClass();
$course->id = $event->courseid;
$completion = new \completion_info($course);
$completiondata = $completion->get_data($cm, false);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/lti/view.php', ['id' => $cm->id]),
1,
true
);
}
\ No newline at end of file
......@@ -128,6 +128,9 @@ function page_add_instance($data, $mform = null) {
$DB->update_record('page', $data);
}
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($cmid, 'page', $data->id, $completiontimeexpected);
return $data->id;
}
......@@ -168,6 +171,9 @@ function page_update_instance($data, $mform) {
$DB->update_record('page', $data);
}
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($cmid, 'page', $data->id, $completiontimeexpected);
return true;
}
......@@ -183,6 +189,9 @@ function page_delete_instance($id) {
return false;
}
$cm = get_coursemodule_from_instance('page', $id);
\core_completion\api::update_completion_date_event($cm->id, 'page', $id, null);
// note: all context files are deleted automatically
$DB->delete_records('page', array('id'=>$page->id));
......@@ -522,3 +531,32 @@ function page_check_updates_since(cm_info $cm, $from, $filter = array()) {
$updates = course_check_module_updates_since($cm, $from, array('content'), $filter);
return $updates;
}
/**
* Handles creating actions for events.
*
* @param \core_calendar\event $event
* @param \core_calendar\action_factory $factory
* @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
*/
function mod_page_core_calendar_provide_event_action(\core_calendar\event $event,
\core_calendar\action_factory $factory) {
$cm = get_fast_modinfo($event->courseid)->instances['page'][$event->instance];
$course = new stdClass();
$course->id = $event->courseid;
$completion = new \completion_info($course);
$completiondata = $completion->get_data($cm, false);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/page/view.php', ['id' => $cm->id]),
1,
true
);
}
......@@ -109,6 +109,10 @@ function resource_add_instance($data, $mform) {
// we need to use context now, so we need to make sure all needed info is already in db
$DB->set_field('course_modules', 'instance', $data->id, array('id'=>$cmid));
resource_set_mainfile($data);
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($cmid, 'resource', $data->id, $completiontimeexpected);
return $data->id;
}
......@@ -129,6 +133,10 @@ function resource_update_instance($data, $mform) {
$DB->update_record('resource', $data);
resource_set_mainfile($data);
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($data->coursemodule, 'resource', $data->id, $completiontimeexpected);
return true;
}
......@@ -172,6 +180,9 @@ function resource_delete_instance($id) {
return false;
}
$cm = get_coursemodule_from_instance('resource', $id);
\core_completion\api::update_completion_date_event($cm->id, 'resource', $id, null);
// note: all context files are deleted automatically
$DB->delete_records('resource', array('id'=>$resource->id));
......@@ -535,3 +546,32 @@ function resource_check_updates_since(cm_info $cm, $from, $filter = array()) {
$updates = course_check_module_updates_since($cm, $from, array('content'), $filter);
return $updates;
}
/**
* Handles creating actions for events.
*
* @param \core_calendar\event $event
* @param \core_calendar\action_factory $factory
* @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
*/
function mod_resource_core_calendar_provide_event_action(\core_calendar\event $event,
\core_calendar\action_factory $factory) {
$cm = get_fast_modinfo($event->courseid)->instances['resource'][$event->instance];
$course = new stdClass();
$course->id = $event->courseid;
$completion = new \completion_info($course);
$completiondata = $completion->get_data($cm, false);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/resource/view.php', ['id' => $cm->id]),
1,
true
);
}
......@@ -78,7 +78,12 @@ function survey_add_instance($survey) {
$survey->timecreated = time();
$survey->timemodified = $survey->timecreated;
return $DB->insert_record("survey", $survey);
$id = $DB->insert_record("survey", $survey);
$completiontimeexpected = !empty($survey->completionexpected) ? $survey->completionexpected : null;
\core_completion\api::update_completion_date_event($survey->coursemodule, 'survey', $id, $completiontimeexpected);
return $id;
}
......@@ -102,6 +107,9 @@ function survey_update_instance($survey) {
$survey->questions = $template->questions;
$survey->timemodified = time();
$completiontimeexpected = !empty($survey->completionexpected) ? $survey->completionexpected : null;
\core_completion\api::update_completion_date_event($survey->coursemodule, 'survey', $survey->id, $completiontimeexpected);
return $DB->update_record("survey", $survey);
}
......@@ -121,6 +129,9 @@ function survey_delete_instance($id) {
return false;
}
$cm = get_coursemodule_from_instance('survey', $id);
\core_completion\api::update_completion_date_event($cm->id, 'survey', $id, null);
$result = true;
if (! $DB->delete_records("survey_analysis", array("survey"=>$survey->id))) {
......@@ -1074,3 +1085,37 @@ function survey_check_updates_since(cm_info $cm, $from, $filter = array()) {
}
return $updates;
}
/**
* Handles creating actions for events.
*
* @param \core_calendar\event $event
* @param \core_calendar\action_factory $factory
* @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
*/
function mod_survey_core_calendar_provide_event_action(\core_calendar\event $event,
\core_calendar\action_factory $factory) {
$cm = get_fast_modinfo($event->courseid)->instances['survey'][$event->instance];