/** * Course delete event observer. * This observer monitors course delete event, and when a course is deleted it deletes any rules and subscriptions associated * with it, so no orphan data is left behind. * * @param \core\event\course_deleted $event The course deleted event. */ public static function course_deleted(\core\event\course_deleted $event) { $rules = rule_manager::get_rules_by_courseid($event->courseid, 0, 0, false); foreach ($rules as $rule) { rule_manager::delete_rule($rule->id, $event->get_context()); } }
/** * Course delete event observer. * This observer monitors course delete event, and when a course is deleted it deletes any rules and subscriptions associated * with it, so no orphan data is left behind. * * @param \core\event\course_deleted $event The course deleted event. */ public static function course_deleted(\core\event\course_deleted $event) { $rules = rule_manager::get_rules_by_courseid($event->courseid); $context = null; if ($event->contextlevel == CONTEXT_COURSE) { $context = $event->get_context(); } foreach ($rules as $rule) { rule_manager::delete_rule($rule->id, $context); } }
/** * Delete a course, including all related data from the database, and any associated files. * * @param mixed $courseorid The id of the course or course object to delete. * @param bool $showfeedback Whether to display notifications of each action the function performs. * @return bool true if all the removals succeeded. false if there were any failures. If this * method returns false, some of the removals will probably have succeeded, and others * failed, but you have no way of knowing which. */ function delete_course($courseorid, $showfeedback = true) { global $DB; if (is_object($courseorid)) { $courseid = $courseorid->id; $course = $courseorid; } else { $courseid = $courseorid; if (!($course = $DB->get_record('course', array('id' => $courseid)))) { return false; } } $context = context_course::instance($courseid); // Frontpage course can not be deleted!! if ($courseid == SITEID) { return false; } // Allow plugins to use this course before we completely delete it. if ($pluginsfunction = get_plugins_with_function('pre_course_delete')) { foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { $pluginfunction($course); } } } // Make the course completely empty. remove_course_contents($courseid, $showfeedback); // Delete the course and related context instance. context_helper::delete_instance(CONTEXT_COURSE, $courseid); $DB->delete_records("course", array("id" => $courseid)); $DB->delete_records("course_format_options", array("courseid" => $courseid)); // Reset all course related caches here. if (class_exists('format_base', false)) { format_base::reset_course_cache($courseid); } // Trigger a course deleted event. $event = \core\event\course_deleted::create(array('objectid' => $course->id, 'context' => $context, 'other' => array('shortname' => $course->shortname, 'fullname' => $course->fullname, 'idnumber' => $course->idnumber))); $event->add_record_snapshot('course', $course); $event->trigger(); return true; }
/** * Delete a course, including all related data from the database, and any associated files. * * @param mixed $courseorid The id of the course or course object to delete. * @param bool $showfeedback Whether to display notifications of each action the function performs. * @return bool true if all the removals succeeded. false if there were any failures. If this * method returns false, some of the removals will probably have succeeded, and others * failed, but you have no way of knowing which. */ function delete_course($courseorid, $showfeedback = true) { global $DB; if (is_object($courseorid)) { $courseid = $courseorid->id; $course = $courseorid; } else { $courseid = $courseorid; if (!($course = $DB->get_record('course', array('id' => $courseid)))) { return false; } } $context = context_course::instance($courseid); // Frontpage course can not be deleted!! if ($courseid == SITEID) { return false; } // Make the course completely empty. remove_course_contents($courseid, $showfeedback); // Delete the course and related context instance. context_helper::delete_instance(CONTEXT_COURSE, $courseid); $DB->delete_records("course", array("id" => $courseid)); $DB->delete_records("course_format_options", array("courseid" => $courseid)); // Trigger a course deleted event. $event = \core\event\course_deleted::create(array('objectid' => $course->id, 'context' => $context, 'other' => array('shortname' => $course->shortname, 'fullname' => $course->fullname, 'idnumber' => $course->idnumber))); $event->add_record_snapshot('course', $course); $event->trigger(); return true; }
public static function course_deleted(\core\event\course_deleted $event) { $course = $event->get_record_snapshot('course', $event->objectid); $groups_delete = get_config('auth/joomdle', 'jomsocial_groups_delete'); $autosell = get_config('auth/joomdle', 'auto_sell'); $use_kunena_forums = get_config('auth/joomdle', 'use_kunena_forums'); $joomla_user_groups = get_config('auth/joomdle', 'joomla_user_groups'); $auth_joomdle = new auth_plugin_joomdle(); if ($groups_delete) { $auth_joomdle->call_method('deleteSocialGroup', $course->id); } if ($autosell) { $cid = array($course->id); $auth_joomdle->call_method("deleteCourseShop", array((int) $course->id)); } if ($joomla_user_groups) { $auth_joomdle->call_method("removeUserGroups", (int) $course->id); } if ($use_kunena_forums) { $auth_joomdle->call_method("removeCourseForums", (int) $course->id); } return true; }