本文整理汇总了PHP中remove_course_contents函数的典型用法代码示例。如果您正苦于以下问题:PHP remove_course_contents函数的具体用法?PHP remove_course_contents怎么用?PHP remove_course_contents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remove_course_contents函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_remove_course_contents
/**
* Test remove_course_content deletes course contents
* TODO Add asserts to verify other data related to course is deleted as well.
*/
public function test_remove_course_contents()
{
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$user = $this->getDataGenerator()->create_user();
$gen = $this->getDataGenerator()->get_plugin_generator('core_notes');
$note = $gen->create_instance(array('courseid' => $course->id, 'userid' => $user->id));
$this->assertNotEquals(false, note_load($note->id));
remove_course_contents($course->id, false);
$this->assertFalse(note_load($note->id));
}
示例2: test_course_content_deleted_event
/**
* Test that triggering a course_content_deleted event works as expected.
*/
public function test_course_content_deleted_event()
{
global $DB;
$this->resetAfterTest();
// Create the course.
$course = $this->getDataGenerator()->create_course();
// Get the course from the DB. The data generator adds some extra properties, such as
// numsections, to the course object which will fail the assertions later on.
$course = $DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST);
// Save the course context before we delete the course.
$coursecontext = context_course::instance($course->id);
// Catch the update event.
$sink = $this->redirectEvents();
remove_course_contents($course->id, false);
// Capture the event.
$events = $sink->get_events();
$sink->close();
// Validate the event.
$event = array_pop($events);
$this->assertInstanceOf('\\core\\event\\course_content_deleted', $event);
$this->assertEquals('course', $event->objecttable);
$this->assertEquals($course->id, $event->objectid);
$this->assertEquals($coursecontext->id, $event->contextid);
$this->assertEquals($course, $event->get_record_snapshot('course', $course->id));
$this->assertEquals('course_content_removed', $event->get_legacy_eventname());
// The legacy data also passed the context and options in the course object.
$course->context = $coursecontext;
$course->options = array();
$this->assertEventLegacyData($course, $event);
$this->assertEventContextNotUsed($event);
}
示例3: delete_course
/**
* 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;
}
示例4: delete_course
/**
* Delete a course, including all related data from the database,
* and any associated files from the moodledata folder.
*
* @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 $CFG;
$result = true;
if (is_object($courseorid)) {
$courseid = $courseorid->id;
$course = $courseorid;
} else {
$courseid = $courseorid;
if (!($course = get_record('course', 'id', $courseid))) {
return false;
}
}
// frontpage course can not be deleted!!
if ($courseid == SITEID) {
return false;
}
if (!remove_course_contents($courseid, $showfeedback)) {
if ($showfeedback) {
notify("An error occurred while deleting some of the course contents.");
}
$result = false;
}
if (!delete_records("course", "id", $courseid)) {
if ($showfeedback) {
notify("An error occurred while deleting the main course record.");
}
$result = false;
}
/// Delete all roles and overiddes in the course context
if (!delete_context(CONTEXT_COURSE, $courseid)) {
if ($showfeedback) {
notify("An error occurred while deleting the main course context.");
}
$result = false;
}
if (!fulldelete($CFG->dataroot . '/' . $courseid)) {
if ($showfeedback) {
notify("An error occurred while deleting the course files.");
}
$result = false;
}
if ($result) {
//trigger events
events_trigger('course_deleted', $course);
}
return $result;
}
示例5: restore_execute
function restore_execute(&$restore, $info, $course_header, &$errorstr)
{
global $CFG, $USER;
$status = true;
//Checks for the required files/functions to restore every module
//and include them
if ($allmods = get_records("modules")) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$modfile = "{$CFG->dirroot}/mod/{$modname}/restorelib.php";
//If file exists and we have selected to restore that type of module
if (file_exists($modfile) and !empty($restore->mods[$modname]) and $restore->mods[$modname]->restore) {
include_once $modfile;
}
}
}
if (!defined('RESTORE_SILENTLY')) {
//Start the main table
echo "<table cellpadding=\"5\">";
echo "<tr><td>";
//Start the main ul
echo "<ul>";
}
//Location of the xml file
$xml_file = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/moodle.xml";
//Preprocess the moodle.xml file spliting into smaller chucks (modules, users, logs...)
//for optimal parsing later in the restore process.
if (!empty($CFG->experimentalsplitrestore)) {
if (!defined('RESTORE_SILENTLY')) {
echo '<li>' . get_string('preprocessingbackupfile') . '</li>';
}
//First of all, split moodle.xml into handy files
if (!restore_split_xml($xml_file, $restore)) {
if (!defined('RESTORE_SILENTLY')) {
notify("Error proccessing moodle.xml file. Process ended.");
} else {
$errorstr = "Error proccessing moodle.xml file. Process ended.";
}
return false;
}
}
//If we've selected to restore into new course
//create it (course)
//Saving conversion id variables into backup_tables
if ($restore->restoreto == RESTORETO_NEW_COURSE) {
if (!defined('RESTORE_SILENTLY')) {
echo '<li>' . get_string('creatingnewcourse') . '</li>';
}
$oldidnumber = $course_header->course_idnumber;
if (!($status = restore_create_new_course($restore, $course_header))) {
if (!defined('RESTORE_SILENTLY')) {
notify("Error while creating the new empty course.");
} else {
$errorstr = "Error while creating the new empty course.";
return false;
}
}
//Print course fullname and shortname and category
if ($status) {
if (!defined('RESTORE_SILENTLY')) {
echo "<ul>";
echo "<li>" . $course_header->course_fullname . " (" . $course_header->course_shortname . ")" . '</li>';
echo "<li>" . get_string("category") . ": " . $course_header->category->name . '</li>';
if (!empty($oldidnumber)) {
echo "<li>" . get_string("nomoreidnumber", "moodle", $oldidnumber) . "</li>";
}
echo "</ul>";
//Put the destination course_id
}
$restore->course_id = $course_header->course_id;
}
if ($status = restore_open_html($restore, $course_header)) {
if (!defined('RESTORE_SILENTLY')) {
echo "<li>Creating the Restorelog.html in the course backup folder</li>";
}
}
} else {
$course = get_record("course", "id", $restore->course_id);
if ($course) {
if (!defined('RESTORE_SILENTLY')) {
echo "<li>" . get_string("usingexistingcourse");
echo "<ul>";
echo "<li>" . get_string("from") . ": " . $course_header->course_fullname . " (" . $course_header->course_shortname . ")" . '</li>';
echo "<li>" . get_string("to") . ": " . format_string($course->fullname) . " (" . format_string($course->shortname) . ")" . '</li>';
if ($restore->deleting) {
echo "<li>" . get_string("deletingexistingcoursedata") . '</li>';
} else {
echo "<li>" . get_string("addingdatatoexisting") . '</li>';
}
echo "</ul></li>";
}
//If we have selected to restore deleting, we do it now.
if ($restore->deleting) {
if (!defined('RESTORE_SILENTLY')) {
echo "<li>" . get_string("deletingolddata") . '</li>';
}
$status = remove_course_contents($restore->course_id, false) and delete_dir_contents($CFG->dataroot . "/" . $restore->course_id, "backupdata");
if ($status) {
//Now , this situation is equivalent to the "restore to new course" one (we
//have a course record and nothing more), so define it as "to new course"
//.........这里部分代码省略.........
示例6: delete_course
/**
* 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;
}
示例7: delete_course
/**
* Delete a course, including all related data from the database,
* and any associated files.
*
* @global object
* @global object
* @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 = get_context_instance(CONTEXT_COURSE, $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
delete_context(CONTEXT_COURSE, $courseid);
$DB->delete_records("course", array("id" => $courseid));
//trigger events
$course->context = $context;
// you can not fetch context in the event because it was already deleted
events_trigger('course_deleted', $course);
return true;
}
示例8: delete_course_content
/**
* Deletes all of the content associated with the given course (courseid)
* @param int $courseid
* @param array $options
* @return bool True for success
*/
public static function delete_course_content($courseid, array $options = null)
{
return remove_course_contents($courseid, false, $options);
}
示例9: delete_course
/**
* Delete a course, including all related data from the database,
* and any associated files.
*
* @global object
* @global object
* @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 = get_context_instance(CONTEXT_COURSE, $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
delete_context(CONTEXT_COURSE, $courseid);
// We will update the course's timemodified, as it will be passed to the course_deleted event,
// which should know about this updated property, as this event is meant to pass the full course record
$course->timemodified = time();
$DB->delete_records("course", array("id" => $courseid));
//trigger events
$course->context = $context;
// you can not fetch context in the event because it was already deleted
events_trigger('course_deleted', $course);
return true;
}
示例10: local_ltiprovider_duplicate_course
/**
* Duplicate a course
*
* @param int $courseid
* @param string $fullname Duplicated course fullname
* @param int $newcourse Destination course
* @param array $options List of backup options
* @return stdClass New course info
*/
function local_ltiprovider_duplicate_course($courseid, $newcourse, $visible = 1, $options = array(), $useridcreating = null, $context)
{
global $CFG, $USER, $DB;
require_once $CFG->dirroot . '/backup/util/includes/backup_includes.php';
require_once $CFG->dirroot . '/backup/util/includes/restore_includes.php';
if (empty($USER)) {
// Emulate session.
cron_setup_user();
}
// Context validation.
if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
throw new moodle_exception('invalidcourseid', 'error');
}
$removeoptions = array();
$removeoptions['keep_roles_and_enrolments'] = true;
$removeoptions['keep_groups_and_groupings'] = true;
remove_course_contents($newcourse->id, false, $removeoptions);
$backupdefaults = array('activities' => 1, 'blocks' => 1, 'filters' => 1, 'users' => 0, 'role_assignments' => 0, 'comments' => 0, 'userscompletion' => 0, 'logs' => 0, 'grade_histories' => 0);
$backupsettings = array();
// Check for backup and restore options.
if (!empty($options)) {
foreach ($options as $option) {
// Strict check for a correct value (allways 1 or 0, true or false).
$value = clean_param($option['value'], PARAM_INT);
if ($value !== 0 and $value !== 1) {
throw new moodle_exception('invalidextparam', 'webservice', '', $option['name']);
}
if (!isset($backupdefaults[$option['name']])) {
throw new moodle_exception('invalidextparam', 'webservice', '', $option['name']);
}
$backupsettings[$option['name']] = $value;
}
}
// Backup the course.
$admin = get_admin();
$bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_SAMESITE, $admin->id);
foreach ($backupsettings as $name => $value) {
$bc->get_plan()->get_setting($name)->set_value($value);
}
$backupid = $bc->get_backupid();
$backupbasepath = $bc->get_plan()->get_basepath();
$bc->execute_plan();
$results = $bc->get_results();
$file = $results['backup_destination'];
$bc->destroy();
// Restore the backup immediately.
// Check if we need to unzip the file because the backup temp dir does not contains backup files.
if (!file_exists($backupbasepath . "/moodle_backup.xml")) {
$file->extract_to_pathname(get_file_packer(), $backupbasepath);
}
$rc = new restore_controller($backupid, $newcourse->id, backup::INTERACTIVE_NO, backup::MODE_SAMESITE, $admin->id, backup::TARGET_CURRENT_DELETING);
foreach ($backupsettings as $name => $value) {
$setting = $rc->get_plan()->get_setting($name);
if ($setting->get_status() == backup_setting::NOT_LOCKED) {
$setting->set_value($value);
}
}
if (!$rc->execute_precheck()) {
$precheckresults = $rc->get_precheck_results();
if (is_array($precheckresults) && !empty($precheckresults['errors'])) {
if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($backupbasepath);
}
$errorinfo = '';
foreach ($precheckresults['errors'] as $error) {
$errorinfo .= $error;
}
if (array_key_exists('warnings', $precheckresults)) {
foreach ($precheckresults['warnings'] as $warning) {
$errorinfo .= $warning;
}
}
throw new moodle_exception('backupprecheckerrors', 'webservice', '', $errorinfo);
}
}
$rc->execute_plan();
$rc->destroy();
$course = $DB->get_record('course', array('id' => $newcourse->id), '*', MUST_EXIST);
$course->visible = $visible;
$course->fullname = $newcourse->fullname;
$course->shortname = $newcourse->shortname;
$course->idnumber = $newcourse->idnumber;
// Set shortname and fullname back.
$DB->update_record('course', $course);
if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($backupbasepath);
}
// Delete the course backup file created by this WebService. Originally located in the course backups area.
$file->delete();
// We have to unenroll all the user except the one that create the course.
if (get_config('local_ltiprovider', 'duplicatecourseswithoutusers') and $useridcreating) {
//.........这里部分代码省略.........
示例11: test_course_content_deleted_event
/**
* Test that triggering a course_content_deleted event works as expected.
*/
public function test_course_content_deleted_event()
{
global $DB;
$this->resetAfterTest();
// Create the course.
$course = $this->getDataGenerator()->create_course();
// Get the course from the DB. The data generator adds some extra properties, such as
// numsections, to the course object which will fail the assertions later on.
$course = $DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST);
// Save the course context before we delete the course.
$coursecontext = context_course::instance($course->id);
// Catch the update event.
$sink = $this->redirectEvents();
// Call remove_course_contents() which will trigger the course_content_deleted event.
// This function prints out data to the screen, which we do not want during a PHPUnit
// test, so use ob_start and ob_end_clean to prevent this.
ob_start();
remove_course_contents($course->id);
ob_end_clean();
// Capture the event.
$events = $sink->get_events();
$sink->close();
// Validate the event.
$event = $events[0];
$this->assertInstanceOf('\\core\\event\\course_content_deleted', $event);
$this->assertEquals('course', $event->objecttable);
$this->assertEquals($course->id, $event->objectid);
$this->assertEquals($coursecontext->id, $event->contextid);
$this->assertEquals($course, $event->get_record_snapshot('course', $course->id));
$this->assertEquals('course_content_removed', $event->get_legacy_eventname());
// The legacy data also passed the context and options in the course object.
$course->context = $coursecontext;
$course->options = array();
$this->assertEventLegacyData($course, $event);
}
示例12: delete_course
/**
* Delete a course, including all related data from the database,
* and any associated files from the moodledata folder.
*
* @param int $courseid The id of the course 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($courseid, $showfeedback = true)
{
global $CFG;
require_once $CFG->libdir . '/gradelib.php';
$result = true;
if (!remove_course_contents($courseid, $showfeedback)) {
if ($showfeedback) {
notify("An error occurred while deleting some of the course contents.");
}
$result = false;
}
remove_course_grades($courseid, $showfeedback);
if (!delete_records("course", "id", $courseid)) {
if ($showfeedback) {
notify("An error occurred while deleting the main course record.");
}
$result = false;
}
if (!delete_records('context', 'contextlevel', CONTEXT_COURSE, 'instanceid', $courseid)) {
if ($showfeedback) {
notify("An error occurred while deleting the main context record.");
}
$result = false;
}
if (!fulldelete($CFG->dataroot . '/' . $courseid)) {
if ($showfeedback) {
notify("An error occurred while deleting the course files.");
}
$result = false;
}
return $result;
}
示例13: delete_course_content
/**
* Deletes all of the content associated with the given course (courseid)
* @param int $courseid
* @return bool True for success
*/
public static function delete_course_content($courseid)
{
return remove_course_contents($courseid, false);
}