本文整理汇总了PHP中enrol_course_delete函数的典型用法代码示例。如果您正苦于以下问题:PHP enrol_course_delete函数的具体用法?PHP enrol_course_delete怎么用?PHP enrol_course_delete使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enrol_course_delete函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: remove_course_contents
/**
* Clear a course out completely, deleting all content
* but don't delete the course itself.
* This function does not verify any permissions.
*
* Please note this function also deletes all user enrolments,
* enrolment instances and role assignments.
*
* @param int $courseid The id of the course that is being deleted
* @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 remove_course_contents($courseid, $showfeedback = true)
{
global $CFG, $DB, $OUTPUT;
require_once $CFG->libdir . '/completionlib.php';
require_once $CFG->libdir . '/questionlib.php';
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->dirroot . '/group/lib.php';
require_once $CFG->dirroot . '/tag/coursetagslib.php';
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context = get_context_instance(CONTEXT_COURSE, $courseid, MUST_EXIST);
$strdeleted = get_string('deleted');
// Delete course completion information,
// this has to be done before grades and enrols
$cc = new completion_info($course);
$cc->clear_criteria();
// remove roles and enrolments
role_unassign_all(array('contextid' => $context->id), true);
enrol_course_delete($course);
// Clean up course formats (iterate through all formats in the even the course format was ever changed)
$formats = get_plugin_list('format');
foreach ($formats as $format => $formatdir) {
$formatdelete = 'format_' . $format . '_delete_course';
$formatlib = "{$formatdir}/lib.php";
if (file_exists($formatlib)) {
include_once $formatlib;
if (function_exists($formatdelete)) {
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . ' ' . $format);
}
$formatdelete($course->id);
}
}
}
// Remove all data from gradebook - this needs to be done before course modules
// because while deleting this information, the system may need to reference
// the course modules that own the grades.
remove_course_grades($courseid, $showfeedback);
remove_grade_letters($context, $showfeedback);
// Remove all data from availability and completion tables that is associated
// with course-modules belonging to this course. Note this is done even if the
// features are not enabled now, in case they were enabled previously
$DB->delete_records_select('course_modules_completion', 'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)', array($courseid));
$DB->delete_records_select('course_modules_availability', 'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)', array($courseid));
// Delete course blocks - they may depend on modules so delete them first
blocks_delete_all_for_context($context->id);
// Delete every instance of every module
if ($allmods = $DB->get_records('modules')) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$modfile = $CFG->dirroot . '/mod/' . $modname . '/lib.php';
$moddelete = $modname . '_delete_instance';
// Delete everything connected to an instance
$moddeletecourse = $modname . '_delete_course';
// Delete other stray stuff (uncommon)
$count = 0;
if (file_exists($modfile)) {
include_once $modfile;
if (function_exists($moddelete)) {
if ($instances = $DB->get_records($modname, array('course' => $course->id))) {
foreach ($instances as $instance) {
if ($cm = get_coursemodule_from_instance($modname, $instance->id, $course->id)) {
/// Delete activity context questions and question categories
question_delete_activity($cm, $showfeedback);
}
if ($moddelete($instance->id)) {
$count++;
} else {
echo $OUTPUT->notification('Could not delete ' . $modname . ' instance ' . $instance->id . ' (' . format_string($instance->name) . ')');
}
if ($cm) {
// delete cm and its context in correct order
delete_context(CONTEXT_MODULE, $cm->id);
// some callbacks may try to fetch context, better delete first
$DB->delete_records('course_modules', array('id' => $cm->id));
}
}
}
} else {
//note: we should probably delete these anyway
echo $OUTPUT->notification('Function ' . $moddelete . '() doesn\'t exist!');
}
if (function_exists($moddeletecourse)) {
$moddeletecourse($course, $showfeedback);
}
}
if ($showfeedback) {
//.........这里部分代码省略.........
开发者ID:hitphp,项目名称:moodle,代码行数:101,代码来源:moodlelib.php
示例2: remove_course_contents
//.........这里部分代码省略.........
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('type_mod_plural', 'plugin'), 'notifysuccess');
}
// Cleanup the rest of plugins. Deprecated since Moodle 3.2. TODO MDL-53297 remove in 3.6.
$cleanuplugintypes = array('report', 'coursereport', 'format');
$callbacks = get_plugins_with_function('delete_course', 'lib.php');
foreach ($cleanuplugintypes as $type) {
if (!empty($callbacks[$type])) {
foreach ($callbacks[$type] as $pluginfunction) {
debugging("Callback delete_course is deprecated. Function {$pluginfunction} should be converted " . 'to observer of event \\core\\event\\course_content_deleted', DEBUG_DEVELOPER);
$pluginfunction($course->id, $showfeedback);
}
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('type_' . $type . '_plural', 'plugin'), 'notifysuccess');
}
}
}
// Delete questions and question categories.
question_delete_course($course, $showfeedback);
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('questions', 'question'), 'notifysuccess');
}
// Make sure there are no subcontexts left - all valid blocks and modules should be already gone.
$childcontexts = $coursecontext->get_child_contexts();
// Returns all subcontexts since 2.2.
foreach ($childcontexts as $childcontext) {
$childcontext->delete();
}
unset($childcontexts);
// Remove all roles and enrolments by default.
if (empty($options['keep_roles_and_enrolments'])) {
// This hack is used in restore when deleting contents of existing course.
role_unassign_all(array('contextid' => $coursecontext->id, 'component' => ''), true);
enrol_course_delete($course);
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('type_enrol_plural', 'plugin'), 'notifysuccess');
}
}
// Delete any groups, removing members and grouping/course links first.
if (empty($options['keep_groups_and_groupings'])) {
groups_delete_groupings($course->id, $showfeedback);
groups_delete_groups($course->id, $showfeedback);
}
// Filters be gone!
filter_delete_all_for_context($coursecontext->id);
// Notes, you shall not pass!
note_delete_all($course->id);
// Die comments!
comment::delete_comments($coursecontext->id);
// Ratings are history too.
$delopt = new stdclass();
$delopt->contextid = $coursecontext->id;
$rm = new rating_manager();
$rm->delete_ratings($delopt);
// Delete course tags.
core_tag_tag::remove_all_item_tags('core', 'course', $course->id);
// Notify the competency subsystem.
\core_competency\api::hook_course_deleted($course);
// Delete calendar events.
$DB->delete_records('event', array('courseid' => $course->id));
$fs->delete_area_files($coursecontext->id, 'calendar');
// Delete all related records in other core tables that may have a courseid
// This array stores the tables that need to be cleared, as
// table_name => column_name that contains the course id.
$tablestoclear = array('backup_courses' => 'courseid', 'user_lastaccess' => 'courseid');
foreach ($tablestoclear as $table => $col) {
开发者ID:lucaboesch,项目名称:moodle,代码行数:67,代码来源:moodlelib.php
示例3: remove_course_contents
//.........这里部分代码省略.........
context_helper::delete_instance(CONTEXT_MODULE, $cm->id);
$DB->delete_records('course_modules', array('id' => $cm->id));
}
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('type_mod_plural', 'plugin'), 'notifysuccess');
}
// Cleanup the rest of plugins
$cleanuplugintypes = array('report', 'coursereport', 'format');
foreach ($cleanuplugintypes as $type) {
$plugins = get_plugin_list_with_function($type, 'delete_course', 'lib.php');
foreach ($plugins as $plugin => $pluginfunction) {
$pluginfunction($course->id, $showfeedback);
}
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('type_' . $type . '_plural', 'plugin'), 'notifysuccess');
}
}
// Delete questions and question categories
question_delete_course($course, $showfeedback);
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('questions', 'question'), 'notifysuccess');
}
// Make sure there are no subcontexts left - all valid blocks and modules should be already gone
$childcontexts = $coursecontext->get_child_contexts();
// returns all subcontexts since 2.2
foreach ($childcontexts as $childcontext) {
$childcontext->delete();
}
unset($childcontexts);
// Remove all roles and enrolments by default
if (empty($options['keep_roles_and_enrolments'])) {
// this hack is used in restore when deleting contents of existing course
role_unassign_all(array('contextid' => $coursecontext->id, 'component' => ''), true);
enrol_course_delete($course);
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('type_enrol_plural', 'plugin'), 'notifysuccess');
}
}
// Delete any groups, removing members and grouping/course links first.
if (empty($options['keep_groups_and_groupings'])) {
groups_delete_groupings($course->id, $showfeedback);
groups_delete_groups($course->id, $showfeedback);
}
// filters be gone!
filter_delete_all_for_context($coursecontext->id);
// die comments!
comment::delete_comments($coursecontext->id);
// ratings are history too
$delopt = new stdclass();
$delopt->contextid = $coursecontext->id;
$rm = new rating_manager();
$rm->delete_ratings($delopt);
// Delete course tags
coursetag_delete_course_tags($course->id, $showfeedback);
// Delete calendar events
$DB->delete_records('event', array('courseid' => $course->id));
$fs->delete_area_files($coursecontext->id, 'calendar');
// Delete all related records in other core tables that may have a courseid
// This array stores the tables that need to be cleared, as
// table_name => column_name that contains the course id.
$tablestoclear = array('log' => 'course', 'backup_courses' => 'courseid', 'user_lastaccess' => 'courseid');
foreach ($tablestoclear as $table => $col) {
$DB->delete_records($table, array($col => $course->id));
}
// delete all course backup files
$fs->delete_area_files($coursecontext->id, 'backup');
开发者ID:nmicha,项目名称:moodle,代码行数:67,代码来源:moodlelib.php
注:本文中的enrol_course_delete函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论