本文整理汇总了PHP中delete_course函数的典型用法代码示例。如果您正苦于以下问题:PHP delete_course函数的具体用法?PHP delete_course怎么用?PHP delete_course使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了delete_course函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
global $DB;
foreach ($this->arguments as $argument) {
try {
$course = $DB->get_record('course', array('id' => $argument));
} catch (Exception $e) {
print get_class($e) . " thrown within the exception handler. Message: " . $e->getMessage() . " on line " . $e->getLine();
}
if ($course instanceof \stdClass) {
delete_course($course);
} else {
print "Course not found\n";
}
}
fix_course_sortorder();
}
示例2: tearDown
public function tearDown()
{
global $DB;
if ($course = $DB->get_record('course', array('shortname' => 'simpletest'))) {
delete_course($course, false);
}
}
示例3: test_course_deleted
/**
* Test observer for course delete event.
*/
public function test_course_deleted()
{
global $DB;
$this->setAdminUser();
$this->resetAfterTest(true);
$user = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
$rule = new stdClass();
$rule->userid = $user->id;
$rule->courseid = $course1->id;
$rule->plugin = 'test';
$sub = new stdClass();
$sub->courseid = $course1->id;
$sub->userid = $user->id;
// Add 10 rules for this course with subscriptions.
for ($i = 0; $i < 10; $i++) {
$createdrule = $monitorgenerator->create_rule($rule);
$sub->ruleid = $createdrule->id;
$monitorgenerator->create_subscription($sub);
}
// Add 10 random rules for course 2.
$rule->courseid = $course2->id;
for ($i = 0; $i < 10; $i++) {
$createdrule = $monitorgenerator->create_rule($rule);
$sub->courseid = $rule->courseid;
$sub->ruleid = $createdrule->id;
$monitorgenerator->create_subscription($sub);
}
// Verify data before course delete.
$totalrules = \tool_monitor\rule_manager::get_rules_by_plugin('test');
$this->assertCount(20, $totalrules);
$courserules = \tool_monitor\rule_manager::get_rules_by_courseid($course1->id);
$this->assertCount(10, $courserules);
$totalsubs = $DB->get_records('tool_monitor_subscriptions');
$this->assertCount(20, $totalsubs);
$coursesubs = \tool_monitor\subscription_manager::get_user_subscriptions_for_course($course1->id, 0, 0, $user->id);
$this->assertCount(10, $coursesubs);
// Let us delete the course now.
delete_course($course1->id, false);
// Verify data after course delete.
$totalrules = \tool_monitor\rule_manager::get_rules_by_plugin('test');
$this->assertCount(10, $totalrules);
$courserules = \tool_monitor\rule_manager::get_rules_by_courseid($course1->id);
$this->assertCount(0, $courserules);
// Making sure all rules are deleted.
$totalsubs = $DB->get_records('tool_monitor_subscriptions');
$this->assertCount(10, $totalsubs);
$coursesubs = \tool_monitor\subscription_manager::get_user_subscriptions_for_course($course1->id, 0, 0, $user->id);
$this->assertCount(0, $coursesubs);
// Making sure all subscriptions are deleted.
}
示例4: test_hook_course_deleted
public function test_hook_course_deleted()
{
$this->resetAfterTest();
$dg = $this->getDataGenerator();
$ccg = $dg->get_plugin_generator('core_competency');
$u1 = $dg->create_user();
$framework = $ccg->create_framework();
$comp1 = $ccg->create_competency(['competencyframeworkid' => $framework->get_id()]);
$comp2 = $ccg->create_competency(['competencyframeworkid' => $framework->get_id()]);
$c1 = $dg->create_course();
$cc1a = $ccg->create_course_competency(['competencyid' => $comp1->get_id(), 'courseid' => $c1->id]);
$cc1b = $ccg->create_course_competency(['competencyid' => $comp2->get_id(), 'courseid' => $c1->id]);
$assign1a = $dg->create_module('assign', ['course' => $c1]);
$assign1b = $dg->create_module('assign', ['course' => $c1]);
$cmc1a = $ccg->create_course_module_competency(['competencyid' => $comp1->get_id(), 'cmid' => $assign1a->cmid]);
$cmc1b = $ccg->create_course_module_competency(['competencyid' => $comp1->get_id(), 'cmid' => $assign1b->cmid]);
$ucc1a = $ccg->create_user_competency_course(['competencyid' => $comp1->get_id(), 'courseid' => $c1->id, 'userid' => $u1->id]);
$ucc1b = $ccg->create_user_competency_course(['competencyid' => $comp2->get_id(), 'courseid' => $c1->id, 'userid' => $u1->id]);
$c2 = $dg->create_course();
$cc2a = $ccg->create_course_competency(['competencyid' => $comp1->get_id(), 'courseid' => $c2->id]);
$cc2b = $ccg->create_course_competency(['competencyid' => $comp2->get_id(), 'courseid' => $c2->id]);
$assign2a = $dg->create_module('assign', ['course' => $c2]);
$assign2b = $dg->create_module('assign', ['course' => $c2]);
$cmc2a = $ccg->create_course_module_competency(['competencyid' => $comp1->get_id(), 'cmid' => $assign2a->cmid]);
$cmc2b = $ccg->create_course_module_competency(['competencyid' => $comp1->get_id(), 'cmid' => $assign2b->cmid]);
$ucc2a = $ccg->create_user_competency_course(['competencyid' => $comp1->get_id(), 'courseid' => $c2->id, 'userid' => $u1->id]);
$ucc2b = $ccg->create_user_competency_course(['competencyid' => $comp2->get_id(), 'courseid' => $c2->id, 'userid' => $u1->id]);
delete_course($c1, false);
$this->assertEquals(0, course_competency::count_records(['courseid' => $c1->id]));
$this->assertEquals(2, course_competency::count_records(['courseid' => $c2->id]));
$this->assertEquals(0, course_module_competency::count_records(['cmid' => $assign1a->cmid]));
$this->assertEquals(0, course_module_competency::count_records(['cmid' => $assign1b->cmid]));
$this->assertEquals(1, course_module_competency::count_records(['cmid' => $assign2a->cmid]));
$this->assertEquals(1, course_module_competency::count_records(['cmid' => $assign2b->cmid]));
$this->assertEquals(0, user_competency_course::count_records(['courseid' => $c1->id, 'userid' => $u1->id]));
$this->assertEquals(2, user_competency_course::count_records(['courseid' => $c2->id, 'userid' => $u1->id]));
}
示例5: restore
function restore($material, $action, $backup_id, $from_course_id = 0)
{
global $moduleFactory;
require_once AT_INCLUDE_PATH . 'classes/pclzip.lib.php';
require_once AT_INCLUDE_PATH . '../mods/_core/file_manager/filemanager.inc.php';
if (!$from_course_id) {
$from_course_id = $this->course_id;
}
// 1. get backup row/information
$my_backup = $this->getRow($backup_id, $from_course_id);
@mkdir(AT_CONTENT_DIR . 'import/' . $this->course_id);
$this->import_dir = AT_CONTENT_DIR . 'import/' . $this->course_id . '/';
// 2. extract the backup
$archive = new PclZip(AT_BACKUP_DIR . $from_course_id . '/' . $my_backup['system_file_name'] . '.zip');
if ($archive->extract(PCLZIP_OPT_PATH, $this->import_dir, PCLZIP_CB_PRE_EXTRACT, 'preImportCallBack') == 0) {
die("Error : " . $archive->errorInfo(true));
}
// 3. get the course's max_quota. if backup is too big AND we want to import files then abort/return FALSE
/* get the course's max_quota */
// $this->getFilesSize();
// 4. figure out version number
$this->version = $this->getVersion();
if (!$this->version) {
clr_dir($this->import_dir);
global $msg;
$msg->addError('BACKUP_RESTORE');
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
//exit('version not found. backups < 1.3 are not supported.');
}
if (version_compare($this->version, VERSION, '>') == 1) {
clr_dir($this->import_dir);
global $msg;
$msg->addError('BACKUP_UNSUPPORTED_GREATER_VERSION');
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
if (version_compare($this_version, '1.5.3', '<')) {
if (file_exists($this->import_dir . 'resource_categories.csv')) {
@rename($this->import_dir . 'resource_categories.csv', $this->import_dir . 'links_categories.csv');
}
if (file_exists($this->import_dir . 'resource_links.csv')) {
@rename($this->import_dir . 'resource_links.csv', $this->import_dir . 'links.csv');
}
}
// 5. if override is set then delete the content
if ($action == 'overwrite') {
require_once AT_INCLUDE_PATH . '../mods/_core/properties/lib/delete_course.inc.php';
delete_course($this->course_id, $material);
$_SESSION['s_cid'] = 0;
}
// else: appending content
if ($material === TRUE) {
// restore the entire backup (used when creating a new course)
$module_list = $moduleFactory->getModules(AT_MODULE_ENABLED | AT_MODULE_CORE);
$_POST['material'] = $module_list;
}
foreach ($_POST['material'] as $module_name => $garbage) {
// restore course properties, ONLY BANNER FOR NOW.
if ($module_name == 'properties' && file_exists($this->import_dir . "properties.csv")) {
global $db;
$fp = @fopen($this->import_dir . "properties.csv", 'rb');
if (($row = @fgetcsv($fp, 70000)) !== false) {
//hack for http://www.atutor.ca/atutor/mantis/view.php?id=3839
$row[0] = preg_replace('/\\\\r\\\\n/', "\r\n", $row[0]);
$sql = "UPDATE " . TABLE_PREFIX . "courses \n\t\t\t\t\t SET banner = '" . mysql_real_escape_string($row[0]) . "' \n\t\t\t\t\t WHERE course_id = " . $this->course_id;
$result = mysql_query($sql, $db) or die(mysql_error());
}
}
// restore modules
$module = $moduleFactory->getModule($module_name);
$module->restore($this->course_id, $this->version, $this->import_dir);
}
clr_dir($this->import_dir);
}
示例6: cleanup
/**
* Delete course which is created by restore process
*/
public function cleanup()
{
global $DB;
$courseid = $this->controller->get_courseid();
if ($this->is_temporary_course_created($courseid) && ($course = $DB->get_record('course', array('id' => $courseid)))) {
$course->deletesource = 'restore';
delete_course($course, false);
}
}
示例7: test_cleanup_task
/**
* Test the cleanup task.
*/
public function test_cleanup_task()
{
global $DB;
// Set the expiry to 1 week.
set_config('categorybinexpiry', WEEKSECS, 'tool_recyclebin');
delete_course($this->course, false);
$recyclebin = new \tool_recyclebin\category_bin($this->course->category);
// Set deleted date to the distant past.
foreach ($recyclebin->get_items() as $item) {
$item->timecreated = time() - WEEKSECS;
$DB->update_record('tool_recyclebin_category', $item);
}
// Create another course to delete.
$course = $this->getDataGenerator()->create_course();
delete_course($course, false);
// Should now be two courses in the recycle bin.
$this->assertEquals(2, count($recyclebin->get_items()));
// Execute cleanup task.
$this->expectOutputRegex("/\\[tool_recyclebin\\] Deleting item '\\d+' from the category recycle bin/");
$task = new \tool_recyclebin\task\cleanup_category_bin();
$task->execute();
// Task should only have deleted the course where we updated the time.
$courses = $recyclebin->get_items();
$this->assertEquals(1, count($courses));
$course = reset($courses);
$this->assertEquals('Test course 2', $course->fullname);
}
示例8: isset
<?php
$cid = isset($_POST['cid']) ? $_POST['cid'] : '';
$course = course_load($cid);
if (isset($_POST['submit'])) {
if (course_is_empty($_POST['id'])) {
delete_course($_POST['id']);
sleep(1);
header('location: ' . currentURL() . '?p=course');
print 'Course deleted. Click <a href="?p=course">here</a> to view created courses';
} else {
print '<span style="color: red;">This course contains ' . count_posts_from_cid($_POST['id']) . ' post' . (count_posts_from_cid($_POST['id']) == 0 || count_posts_from_cid($_POST['id']) == 1 ? '' : 's') . '. Please delete all the posts before deleting the course</span>';
}
}
?>
<h3>Do you want to delete the course "<?php
print $course['Course_Name'];
?>
"?</h3>
<form method="post" action="">
<input type="hidden" name="id" value="<?php
print $cid;
?>
"/>
<input type="submit" name="submit" value="Delete" />
<a class="button" href="?p=course">Cancel</a>
</form>
示例9: cleanup
/**
* Delete course which is created by restore process
*/
public function cleanup()
{
$courseid = $this->controller->get_courseid();
if ($this->is_temporary_course_created($courseid)) {
delete_course($courseid, false);
}
}
示例10: delete_full
/**
* Recursively delete category including all subcategories and courses
*
* Function {@link coursecat::can_delete_full()} MUST be called prior
* to calling this function because there is no capability check
* inside this function
*
* @param boolean $showfeedback display some notices
* @return array return deleted courses
* @throws moodle_exception
*/
public function delete_full($showfeedback = true)
{
global $CFG, $DB;
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->libdir . '/questionlib.php';
require_once $CFG->dirroot . '/cohort/lib.php';
$deletedcourses = array();
// Get children. Note, we don't want to use cache here because it would be rebuilt too often.
$children = $DB->get_records('course_categories', array('parent' => $this->id), 'sortorder ASC');
foreach ($children as $record) {
$coursecat = new coursecat($record);
$deletedcourses += $coursecat->delete_full($showfeedback);
}
if ($courses = $DB->get_records('course', array('category' => $this->id), 'sortorder ASC')) {
foreach ($courses as $course) {
if (!delete_course($course, false)) {
throw new moodle_exception('cannotdeletecategorycourse', '', '', $course->shortname);
}
$deletedcourses[] = $course;
}
}
// Move or delete cohorts in this context.
cohort_delete_category($this);
// Now delete anything that may depend on course category context.
grade_course_category_delete($this->id, 0, $showfeedback);
if (!question_delete_course_category($this, 0, $showfeedback)) {
throw new moodle_exception('cannotdeletecategoryquestions', '', '', $this->get_formatted_name());
}
// Finally delete the category and it's context.
$DB->delete_records('course_categories', array('id' => $this->id));
$coursecatcontext = context_coursecat::instance($this->id);
$coursecatcontext->delete();
cache_helper::purge_by_event('changesincoursecat');
// Trigger a course category deleted event.
/* @var \core\event\course_category_deleted $event */
$event = \core\event\course_category_deleted::create(array('objectid' => $this->id, 'context' => $coursecatcontext, 'other' => array('name' => $this->name)));
$event->set_coursecat($this);
$event->trigger();
// If we deleted $CFG->defaultrequestcategory, make it point somewhere else.
if ($this->id == $CFG->defaultrequestcategory) {
set_config('defaultrequestcategory', $DB->get_field('course_categories', 'MIN(id)', array('parent' => 0)));
}
return $deletedcourses;
}
示例11: process_course_group_node
//.........这里部分代码省略.........
if ($end) {
$coursemanagement->enddate = $end->nodeValue;
}
if (isset($coursemanagement->startdate) && $coursemanagement->startdate > 0 && isset($coursemanagement->enddate) && $coursemanagement->enddate > 0) {
// The course validly has both start and end dates.
$coursemanagement->courseid = $course->id;
$coursemanagement->timemodified = time();
$DB->insert_record("eclass_course_management", $coursemanagement);
} else {
if (isset($coursemanagement->startdate) || isset($coursemanagement->enddate)) {
// Something isn't right with the start or end date.
throw new Exception('UAIMS: Course Creation without valid start or end date');
}
}
// No else needed. No actions required if the course is validly lacking both start and end dates.
} else {
// Update existing Course, if corresponding eclass_course_management exist. Otherwise, create a
// corresponding eclass_course_management entry.
$ecourse = $DB->get_record('course', array('idnumber' => $course->idnumber), '*', MUST_EXIST);
$enableqrtoggle = $this->get_config('enableqrvisibilitytoggle');
// Disable or enable QR toggling.
if (!isset($enableqrtoggle) || !$enableqrtoggle) {
unset($course->visible);
} else {
// Otherwise update the startend dates in the eclass_course_management table from uaims documents.
$coursemanagement = $DB->get_record('eclass_course_management', array('courseid' => $ecourse->id), $fields = 'id', $strictness = IGNORE_MISSING);
// Get the start and end date for the course.
$begin = $xpath->evaluate("timeframe/begin", $groupnode)->item(0);
$end = $xpath->evaluate("timeframe/end", $groupnode)->item(0);
// To avoid errors when course is created outside of uaims (doesn't have eclass_course_management entry),
// create and set appropriate attributes of $coursemanagement that matches eclass_course_management
// database schema (or atleast NOT NULL fields).
$coursemanagementexist = $coursemanagement != false;
if (!$coursemanagementexist) {
$enrol = enrol_get_plugin('manual');
if ($audroleid = $DB->get_field('role', 'id', array('shortname' => 'auditor'))) {
$enrol->add_instance($ecourse, array('roleid' => $audroleid));
} else {
$enrol->add_instance($ecourse);
}
$coursemanagement = new stdClass();
// The test process_imsdoc_test::test_process_imsdoc_should_update_course_with_minimal_imsdoc
// implies that one of the requirement of this module is to ignore updates/insert in the case where
// course exist, yet no start/end date. (Note this differ from the case where the course don't exist
// in which case the requirements of this module requires it to throw an exception.
if ($begin and $end) {
// Set appropriate eclass_course_management row attributes and finally insert it to db.
$coursemanagement->courseid = $ecourse->id;
$coursemanagement->startdate = $begin->nodeValue;
$coursemanagement->enddate = $end->nodeValue;
$coursemanagement->timemodified = time();
$DB->insert_record("eclass_course_management", $coursemanagement);
}
} else {
// Since corresponding eclass_course_management entry exist, only we don't need all parameters
// to be present. Either/both $begin/$end dates is/are sufficient.
if ($begin) {
$coursemanagement->startdate = $begin->nodeValue;
}
if ($end) {
$coursemanagement->enddate = $end->nodeValue;
}
if (isset($coursemanagement->startdate) || isset($coursemanagement->enddate)) {
// If one of them is there then do the update.
if ($coursemanagement->startdate || $coursemanagement->enddate) {
$coursemanagement->timemodified = time();
$DB->update_record("eclass_course_management", $coursemanagement);
}
}
}
}
// The $course var should never have an 'id' attribute, but lets make sure.
if (isset($course->id)) {
unset($course->id);
}
$ecourse = $this->extend($ecourse, $course);
$DB->update_record('course', $ecourse);
$classname = context_helper::get_class_for_level(CONTEXT_COURSE);
$context = $classname::instance($ecourse->id, IGNORE_MISSING);
$classname = context_helper::get_class_for_level(CONTEXT_COURSECAT);
$newparent = $classname::instance($ecourse->category, IGNORE_MISSING);
$context->update_moved($newparent);
if (!($instanceid = $DB->get_field('enrol', 'id', array('enrol' => 'manual', 'courseid' => $ecourse->id)))) {
$enrol = enrol_get_plugin('manual');
if ($audroleid = $DB->get_field('role', 'id', array('shortname' => 'auditor'))) {
$enrol->add_instance($ecourse, array('roleid' => $audroleid));
} else {
$enrol->add_instance(${$ecourse});
}
}
}
} else {
$idnumber = $xpath->evaluate("sourcedid/id", $groupnode)->item(0);
if ($idnumber) {
$idnumber = htmlspecialchars_decode($idnumber->nodeValue);
$course = $DB->get_record('course', array('idnumber' => $idnumber));
delete_course($course, false);
}
}
}
示例12: delete_courses
/**
* Delete courses
*
* @param array $courseids A list of course ids
* @since Moodle 2.2
*/
public static function delete_courses($courseids)
{
global $CFG, $DB;
require_once $CFG->dirroot . "/course/lib.php";
// Parameter validation.
$params = self::validate_parameters(self::delete_courses_parameters(), array('courseids' => $courseids));
$warnings = array();
foreach ($params['courseids'] as $courseid) {
$course = $DB->get_record('course', array('id' => $courseid));
if ($course === false) {
$warnings[] = array('item' => 'course', 'itemid' => $courseid, 'warningcode' => 'unknowncourseidnumber', 'message' => 'Unknown course ID ' . $courseid);
continue;
}
// Check if the context is valid.
$coursecontext = context_course::instance($course->id);
self::validate_context($coursecontext);
// Check if the current user has permission.
if (!can_delete_course($courseid)) {
$warnings[] = array('item' => 'course', 'itemid' => $courseid, 'warningcode' => 'cannotdeletecourse', 'message' => 'You do not have the permission to delete this course' . $courseid);
continue;
}
if (delete_course($course, false) === false) {
$warnings[] = array('item' => 'course', 'itemid' => $courseid, 'warningcode' => 'cannotdeletecategorycourse', 'message' => 'Course ' . $courseid . ' failed to be deleted');
continue;
}
}
fix_course_sortorder();
return array('warnings' => $warnings);
}
示例13: test_sync
//.........这里部分代码省略.........
$this->getDataGenerator()->enrol_user($user1->id, $course1->id, $student->id);
$this->assertEquals(13, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(13, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $student));
enrol_meta_sync(null, false);
$this->assertEquals(13, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(13, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $student));
$manplugin->update_user_enrol($manual1, $user1->id, ENROL_USER_SUSPENDED);
$this->assertEquals(13, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(11, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $student));
enrol_meta_sync(null, false);
$this->assertEquals(13, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(11, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $student));
$manplugin->unenrol_user($manual1, $user1->id);
$this->assertEquals(12, $DB->count_records('user_enrolments'));
$this->assertEquals(9, $DB->count_records('role_assignments'));
$this->assertEquals(11, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $student));
enrol_meta_sync(null, false);
$this->assertEquals(12, $DB->count_records('user_enrolments'));
$this->assertEquals(9, $DB->count_records('role_assignments'));
$this->assertEquals(11, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $student));
$this->getDataGenerator()->enrol_user($user1->id, $course1->id, $student->id);
$this->assertEquals(13, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(13, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $student));
enrol_meta_sync(null, false);
$this->assertEquals(13, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(13, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $student));
set_config('syncall', 1, 'enrol_meta');
set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES, 'enrol_meta');
enrol_meta_sync(null, false);
$this->assertEquals(13, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(13, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->getDataGenerator()->enrol_user($user1->id, $course1->id, $student->id);
$this->assertEquals(13, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(13, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $student));
enrol_meta_sync(null, false);
$this->assertEquals(13, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(13, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $student));
$manplugin->unenrol_user($manual1, $user1->id);
$this->assertEquals(12, $DB->count_records('user_enrolments'));
$this->assertEquals(8, $DB->count_records('role_assignments'));
$this->assertEquals(11, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, false));
enrol_meta_sync(null, false);
$this->assertEquals(12, $DB->count_records('user_enrolments'));
$this->assertEquals(8, $DB->count_records('role_assignments'));
$this->assertEquals(11, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, false));
$this->getDataGenerator()->enrol_user($user1->id, $course1->id, $student->id);
$this->assertEquals(13, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(13, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $student));
enrol_meta_sync(null, false);
$this->assertEquals(13, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(13, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
$this->assertTrue($this->is_meta_enrolled($user1, $enrol1, $student));
set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL, 'enrol_meta');
enrol_meta_sync(null, false);
$this->assertEquals(13, $DB->count_records('user_enrolments'));
$this->assertEquals(10, $DB->count_records('role_assignments'));
$this->assertEquals(13, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
delete_course($course1, false);
$this->assertEquals(3, $DB->count_records('user_enrolments'));
$this->assertEquals(3, $DB->count_records('role_assignments'));
$this->assertEquals(3, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
enrol_meta_sync(null, false);
$this->assertEquals(3, $DB->count_records('user_enrolments'));
$this->assertEquals(3, $DB->count_records('role_assignments'));
$this->assertEquals(3, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
delete_course($course2, false);
$this->assertEquals(0, $DB->count_records('user_enrolments'));
$this->assertEquals(0, $DB->count_records('role_assignments'));
$this->assertEquals(0, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
enrol_meta_sync(null, false);
$this->assertEquals(0, $DB->count_records('user_enrolments'));
$this->assertEquals(0, $DB->count_records('role_assignments'));
$this->assertEquals(0, $DB->count_records('user_enrolments', array('status' => ENROL_USER_ACTIVE)));
delete_course($course3, false);
delete_course($course4, false);
}
示例14: test_course_viewed
/**
* There is no api involved so the best we can do is test legacy data by triggering event manually.
*/
public function test_course_viewed()
{
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
$context = context_course::instance($course->id);
// First try with no optional parameters.
$eventparams = array();
$eventparams['context'] = $context;
$event = \core\event\course_viewed::create($eventparams);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$event->trigger();
$events = $sink->get_events();
$event = reset($events);
$this->assertInstanceOf('\\core\\event\\course_viewed', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$expected = array($course->id, 'course', 'view', 'view.php?id=' . $course->id, $course->id);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
// Now try with optional parameters.
$sectionid = 34;
$eventparams = array();
$eventparams['context'] = $context;
$eventparams['other'] = array('coursesectionid' => $sectionid);
$event = \core\event\course_viewed::create($eventparams);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$event->trigger();
$loggeddata = $event->get_data();
$events = $sink->get_events();
$event = reset($events);
$this->assertInstanceOf('\\core\\event\\course_viewed', $event);
$this->assertEquals(context_course::instance($course->id), $event->get_context());
$expected = array($course->id, 'course', 'view section', 'view.php?id=' . $course->id . '&section=' . $sectionid, $sectionid);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
delete_course($course->id, false);
$restored = \core\event\base::restore($loggeddata, array('origin' => 'web', 'ip' => '127.0.0.1'));
$this->assertInstanceOf('\\core\\event\\course_viewed', $restored);
$this->assertNull($restored->get_url());
}
示例15: delete_full
/**
* Recursively delete category including all subcategories and courses
*
* Function {@link coursecat::can_delete_full()} MUST be called prior
* to calling this function because there is no capability check
* inside this function
*
* @param boolean $showfeedback display some notices
* @return array return deleted courses
*/
public function delete_full($showfeedback = true)
{
global $CFG, $DB;
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->libdir . '/questionlib.php';
require_once $CFG->dirroot . '/cohort/lib.php';
$deletedcourses = array();
// Get children. Note, we don't want to use cache here because
// it would be rebuilt too often
$children = $DB->get_records('course_categories', array('parent' => $this->id), 'sortorder ASC');
foreach ($children as $record) {
$coursecat = new coursecat($record);
$deletedcourses += $coursecat->delete_full($showfeedback);
}
if ($courses = $DB->get_records('course', array('category' => $this->id), 'sortorder ASC')) {
foreach ($courses as $course) {
if (!delete_course($course, false)) {
throw new moodle_exception('cannotdeletecategorycourse', '', '', $course->shortname);
}
$deletedcourses[] = $course;
}
}
// move or delete cohorts in this context
cohort_delete_category($this);
// now delete anything that may depend on course category context
grade_course_category_delete($this->id, 0, $showfeedback);
if (!question_delete_course_category($this, 0, $showfeedback)) {
throw new moodle_exception('cannotdeletecategoryquestions', '', '', $this->get_formatted_name());
}
// finally delete the category and it's context
$DB->delete_records('course_categories', array('id' => $this->id));
delete_context(CONTEXT_COURSECAT, $this->id);
add_to_log(SITEID, "category", "delete", "index.php", "{$this->name} (ID {$this->id})");
cache_helper::purge_by_event('changesincoursecat');
events_trigger('course_category_deleted', $this);
// If we deleted $CFG->defaultrequestcategory, make it point somewhere else.
if ($this->id == $CFG->defaultrequestcategory) {
set_config('defaultrequestcategory', $DB->get_field('course_categories', 'MIN(id)', array('parent' => 0)));
}
return $deletedcourses;
}