本文整理汇总了PHP中mark_context_dirty函数的典型用法代码示例。如果您正苦于以下问题:PHP mark_context_dirty函数的具体用法?PHP mark_context_dirty怎么用?PHP mark_context_dirty使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mark_context_dirty函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_learning_path_editing_access
/**
* Check course status and update editing rights for learning path authors
*
* @param integer $status
* @param object $course
*
* @return bool
*/
function update_learning_path_editing_access($status, $course)
{
if (!($context = get_context_instance(CONTEXT_COURSE, $course->id))) {
print_error('nocontext');
}
// get a list of our authors
$authors = tao_get_lpauthors($context);
if (!empty($authors)) {
if ($course->approval_status_id == COURSE_STATUS_NOTSUBMITTED || $course->approval_status_id == COURSE_STATUS_NEEDSCHANGE) {
// give editing rights to learning path authors
foreach ($authors as $author) {
tao_role_assign_by_shortname(ROLE_LPEDITOR, $author->id, $context->id);
}
} else {
// remove editing rights to learning path authors
foreach ($authors as $author) {
tao_role_unassign_by_shortname(ROLE_LPEDITOR, $author->id, $context->id);
}
}
}
// force accessinfo refresh for users visiting this context.
mark_context_dirty($context->path);
// success!
return true;
}
示例2: save_category
/**
* Save the course category
*
* @author Andrew Zoltay
* date 2011-05-30
* @global type $DB
* @param string $categoryname
* @param int $parent
* @return boolean - success or failure
*/
function save_category($categoryname, $parent = 0)
{
global $DB;
// First off - don't save any categories that are null.
if (empty($categoryname) or is_null($categoryname)) {
return false;
}
// Next check to see if category already exists.
$categoryid = $DB->get_field_select('course_categories', 'id', 'name = ? AND parent = ?', array($categoryname, $parent));
// Finally save the category if it hasnt been found.
if ($categoryid) {
echo 'Found existing cat: ' . $categoryname . ' with id=' . $categoryid . '</br>';
return $categoryid;
} else {
// Save the new category.
$newcategory->name = $categoryname;
$newcategory->description = '';
// Don't define a description.
$newcategory->descriptionformat = 1;
// Default to HTML format.
$newcategory->parent = $parent;
$newcategory->sortorder = 999;
$newcategory->id = $DB->insert_record('course_categories', $newcategory);
$newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
$categorycontext = $newcategory->context;
mark_context_dirty($newcategory->context->path);
// Now that we have the context, we need to update the category's path info.
$DB->update_record('course_categories', $newcategory);
fix_course_sortorder();
echo 'Added new cat: ' . $categoryname . ' with id=' . $newcategory->id . '</br>';
return $newcategory->id;
}
}
示例3: xmldb_main_upgrade
//.........这里部分代码省略.........
/// Changing precision of field shortname on table course_request to (100)
$table = new xmldb_table('course_request');
$field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
/// Before changing the field, drop dependent indexes
/// Define index shortname (not unique) to be dropped form course_request
$index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
/// Conditionally launch drop index shortname
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
/// Launch change of precision for field shortname
$dbman->change_field_precision($table, $field);
/// After changing the field, recreate dependent indexes
/// Define index shortname (not unique) to be added to course_request
$index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
/// Conditionally launch add index shortname
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
/// Main savepoint reached
upgrade_main_savepoint($result, 2008120700);
}
/// For MDL-17501. Ensure that any role that has moodle/course:update also
/// has moodle/course:visibility.
if ($result && $oldversion < 2008120800) {
/// Get the roles with 'moodle/course:update'.
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$roles = get_roles_with_capability('moodle/course:update', CAP_ALLOW, $systemcontext);
/// Give those roles 'moodle/course:visibility'.
foreach ($roles as $role) {
assign_capability('moodle/course:visibility', CAP_ALLOW, $role->id, $systemcontext->id);
}
/// Force all sessions to refresh access data.
mark_context_dirty($systemcontext->path);
/// Main savepoint reached
upgrade_main_savepoint($result, 2008120800);
}
if ($result && $oldversion < 2008120801) {
/// Changing precision of field shortname on table mnet_enrol_course to (100)
$table = new xmldb_table('mnet_enrol_course');
$field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
/// Launch change of precision for field shortname
$dbman->change_field_precision($table, $field);
/// Main savepoint reached
upgrade_main_savepoint($result, 2008120801);
}
if ($result && $oldversion < 2008121701) {
/// Define field availablefrom to be added to course_modules
$table = new xmldb_table('course_modules');
$field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionexpected');
/// Conditionally launch add field availablefrom
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define field availableuntil to be added to course_modules
$field = new xmldb_field('availableuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availablefrom');
/// Conditionally launch add field availableuntil
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define field showavailability to be added to course_modules
$field = new xmldb_field('showavailability', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availableuntil');
/// Conditionally launch add field showavailability
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
示例4: get_course_category
/**
* Return specified category, default if given does not exist
*
* @global object
* @uses MAX_COURSES_IN_CATEGORY
* @uses CONTEXT_COURSECAT
* @uses SYSCONTEXTID
* @param int $catid course category id
* @return object caregory
*/
function get_course_category($catid = 0)
{
global $DB;
$category = false;
if (!empty($catid)) {
$category = $DB->get_record('course_categories', array('id' => $catid));
}
if (!$category) {
// the first category is considered default for now
if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) {
$category = reset($category);
} else {
$cat = new stdClass();
$cat->name = get_string('miscellaneous');
$cat->depth = 1;
$cat->sortorder = MAX_COURSES_IN_CATEGORY;
$cat->timemodified = time();
$catid = $DB->insert_record('course_categories', $cat);
// make sure category context exists
get_context_instance(CONTEXT_COURSECAT, $catid);
mark_context_dirty('/' . SYSCONTEXTID);
fix_course_sortorder();
// Required to build course_categories.depth and .path.
$category = $DB->get_record('course_categories', array('id' => $catid));
}
}
return $category;
}
示例5: assign_capability
if (!in_array($value, $allowed_values)) {
continue;
}
if (isset($localoverrides[$capname])) {
// Something exists, so update it
assign_capability($capname, $value, $roleid, $context->id, true);
} else {
// insert a record
if ($value != CAP_INHERIT) {
// Ignore inherits
assign_capability($capname, $value, $roleid, $context->id);
}
}
}
// force accessinfo refresh for users visiting this context...
mark_context_dirty($context->path);
$rolename = get_field('role', 'name', 'id', $roleid);
add_to_log($course->id, 'role', 'override', 'admin/roles/override.php?contextid=' . $context->id . '&roleid=' . $roleid, $rolename, '', $USER->id);
redirect($baseurl);
}
/// Print the header and tabs
if ($context->contextlevel == CONTEXT_USER) {
$navlinks = array();
/// course header
if ($course->id != SITEID) {
if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE, $course->id))) {
$navlinks[] = array('name' => $strparticipants, 'link' => "{$CFG->wwwroot}/user/index.php?id={$course->id}", 'type' => 'misc');
}
$navlinks[] = array('name' => $fullname, 'link' => "{$CFG->wwwroot}/user/view.php?id={$userid}&course={$courseid}", 'type' => 'misc');
$navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
示例6: setup
/**
* Setup the DB fixture data
*/
public function setup()
{
parent::setUp();
$tables = array('block_instance', 'cache_flags', 'capabilities', 'context', 'context_temp', 'course', 'course_modules', 'course_categories', 'course_sections', 'files', 'files_cleanup', 'grade_items', 'grade_categories', 'groups', 'groups_members', 'modules', 'role', 'role_names', 'role_context_levels', 'role_assignments', 'role_capabilities', 'user');
$this->create_test_tables($tables, 'lib');
$this->create_test_table('forum', 'mod/forum');
$this->switch_to_test_db();
global $DB, $CFG;
// Insert needed capabilities
$DB->insert_record('capabilities', array('id' => 45, 'name' => 'moodle/course:update', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 4));
$DB->insert_record('capabilities', array('id' => 14, 'name' => 'moodle/site:backup', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 28));
$DB->insert_record('capabilities', array('id' => 17, 'name' => 'moodle/site:restore', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 28));
$DB->insert_record('capabilities', array('id' => 52, 'name' => 'moodle/course:managefiles', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 4));
$DB->insert_record('capabilities', array('id' => 73, 'name' => 'moodle/user:editownprofile', 'cattype' => 'write', 'contextlevel' => 10, 'component' => 'moodle', 'riskbitmask' => 16));
// Insert system context
$DB->insert_record('context', array('id' => 1, 'contextlevel' => 10, 'instanceid' => 0, 'path' => '/1', 'depth' => 1));
$DB->insert_record('context', array('id' => 2, 'contextlevel' => 50, 'instanceid' => 1, 'path' => '/1/2', 'depth' => 2));
// Insert site course
$DB->insert_record('course', array('category' => 0, 'sortorder' => 1, 'fullname' => 'Test site', 'shortname' => 'test', 'format' => 'site', 'modinfo' => 'a:0:{}'));
// User and capability stuff (stolen from testaccesslib.php)
$syscontext = get_system_context(false);
$adminrole = create_role(get_string('administrator'), 'admin', get_string('administratordescription'), 'moodle/legacy:admin');
/// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
assign_capability('moodle/site:doanything', CAP_ALLOW, $adminrole, $syscontext->id);
update_capabilities('moodle');
update_capabilities('mod/forum');
$contexts = $this->load_test_data('context', array('contextlevel', 'instanceid', 'path', 'depth'), array(1 => array(40, 666, '', 2)));
$contexts[0] = $syscontext;
$contexts[1]->path = $contexts[0]->path . '/' . $contexts[1]->id;
$this->testdb->set_field('context', 'path', $contexts[1]->path, array('id' => $contexts[1]->id));
$users = $this->load_test_data('user', array('username', 'confirmed', 'deleted'), array('a' => array('a', 1, 0)));
$admin = $this->testdb->get_record('role', array('shortname' => 'admin'));
$ras = $this->load_test_data('role_assignments', array('userid', 'roleid', 'contextid'), array('a' => array($users['a']->id, $admin->id, $contexts[0]->id)));
$this->switch_global_user_id(1);
accesslib_clear_all_caches_for_unit_testing();
// Create a coursecat
$newcategory = new stdClass();
$newcategory->name = 'test category';
$newcategory->sortorder = 999;
if (!($newcategory->id = $DB->insert_record('course_categories', $newcategory))) {
print_error('cannotcreatecategory', '', '', format_string($newcategory->name));
}
$newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
mark_context_dirty($newcategory->context->path);
fix_course_sortorder();
// Required to build course_categories.depth and .path.
$this->coursecat = $DB->get_record('course_categories', array('id' => $newcategory->id));
// Create a course
$coursedata = new stdClass();
$coursedata->category = $newcategory->id;
$coursedata->shortname = 'testcourse';
$coursedata->fullname = 'Test Course';
try {
$this->course = create_course($coursedata);
} catch (moodle_exception $e) {
// Most likely the result of an aborted unit test: the test course was not correctly deleted
$this->course = $DB->get_record('course', array('shortname' => $coursedata->shortname));
}
// Create a user
$this->user = new stdClass();
$this->user->username = 'testuser09987654321';
$this->user->password = 'password';
$this->user->firstname = 'TestUser';
$this->user->lastname = 'TestUser';
$this->user->email = 'fakeemail@fake.org';
try {
$this->user->id = create_user($this->user);
} catch (moodle_exception $e) {
// Most likely the result of an aborted unit test: the test user was not correctly deleted
$this->user->id = $DB->get_field('user', 'id', array('username' => $this->user->username));
}
// Assign user to course
// role_assign(5, $this->user->id, 0, get_context_instance(CONTEXT_COURSE, $this->course->id)->id);
// Create a module
$module = new stdClass();
$module->intro = 'Forum used for testing filelib API';
$module->type = 'general';
$module->forcesubscribe = 1;
$module->format = 1;
$module->name = 'Test Forum';
$module->module = $DB->get_field('modules', 'id', array('name' => 'forum'));
$module->modulename = 'forum';
$module->add = 'forum';
$module->cmidnumber = '';
$module->course = $this->course->id;
$module->instance = forum_add_instance($module, '');
$this->section = get_course_section(1, $this->course->id);
$module->section = $this->section->id;
$module->coursemodule = add_course_module($module);
add_mod_to_section($module);
$module->cmidnumber = set_coursemodule_idnumber($module->coursemodule, '');
rebuild_course_cache($this->course->id);
$this->module = $DB->get_record('forum', array('id' => $module->instance));
$this->module->instance = $module->instance;
// Update local copy of course
$this->course = $DB->get_record('course', array('id' => $this->course->id));
}
示例7: test_everything_in_accesslib
//.........这里部分代码省略.........
$context = context::instance_by_id($contextid);
$this->assertSame(get_context_instance_by_id($contextid), $context);
$this->assertSame(get_context_instance($record->contextlevel, $record->instanceid), $context);
$this->assertSame(get_parent_contexts($context), $context->get_parent_context_ids());
if ($context->id == SYSCONTEXTID) {
$this->assertSame(get_parent_contextid($context), false);
} else {
$this->assertSame(get_parent_contextid($context), $context->get_parent_context()->id);
}
}
$CFG->debug = 0;
$children = get_child_contexts($systemcontext);
$CFG->debug = DEBUG_DEVELOPER;
$this->assertEquals(count($children), $DB->count_records('context')-1);
unset($children);
$DB->delete_records('context', array('contextlevel'=>CONTEXT_BLOCK));
create_contexts();
$this->assertFalse($DB->record_exists('context', array('contextlevel'=>CONTEXT_BLOCK)));
$DB->set_field('context', 'depth', 0, array('contextlevel'=>CONTEXT_BLOCK));
build_context_path();
$this->assertFalse($DB->record_exists('context', array('depth'=>0)));
$lastcourse = $DB->get_field_sql("SELECT MAX(id) FROM {course}");
$DB->delete_records('course', array('id'=>$lastcourse));
$lastcategory = $DB->get_field_sql("SELECT MAX(id) FROM {course_categories}");
$DB->delete_records('course_categories', array('id'=>$lastcategory));
$lastuser = $DB->get_field_sql("SELECT MAX(id) FROM {user} WHERE deleted=0");
$DB->delete_records('user', array('id'=>$lastuser));
$DB->delete_records('block_instances', array('parentcontextid'=>$frontpagepagecontext->id));
$DB->delete_records('course_modules', array('id'=>$frontpagepagecontext->instanceid));
cleanup_contexts();
$count = 1; //system
$count += $DB->count_records('user', array('deleted'=>0));
$count += $DB->count_records('course_categories');
$count += $DB->count_records('course');
$count += $DB->count_records('course_modules');
$count += $DB->count_records('block_instances');
$this->assertEquals($DB->count_records('context'), $count);
context_helper::reset_caches();
preload_course_contexts($SITE->id);
$this->assertEquals(context_inspection::test_context_cache_size(), 1);
context_helper::reset_caches();
list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSECAT, 'ctx');
$sql = "SELECT c.id $select FROM {course_categories} c $join";
$records = $DB->get_records_sql($sql);
foreach ($records as $record) {
context_instance_preload($record);
$record = (array)$record;
$this->assertEquals(1, count($record)); // only id left
}
$this->assertEquals(count($records), context_inspection::test_context_cache_size());
accesslib_clear_all_caches(true);
$DB->delete_records('cache_flags', array());
mark_context_dirty($systemcontext->path);
$dirty = get_cache_flags('accesslib/dirtycontexts', time()-2);
$this->assertTrue(isset($dirty[$systemcontext->path]));
accesslib_clear_all_caches(false);
$DB->delete_records('cache_flags', array());
$course = $DB->get_record('course', array('id'=>$testcourses[2]));
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$oldpath = $context->path;
$miscid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}");
$categorycontext = context_coursecat::instance($miscid);
$course->category = $miscid;
$DB->update_record('course', $course);
context_moved($context, $categorycontext);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$this->assertEquals($context->get_parent_context(), $categorycontext);
$this->assertTrue($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$testcourses[2])));
delete_context(CONTEXT_COURSE, $testcourses[2]);
$this->assertFalse($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$testcourses[2])));
$name = get_contextlevel_name(CONTEXT_COURSE);
$this->assertFalse(empty($name));
$context = get_context_instance(CONTEXT_COURSE, $testcourses[2]);
$name = print_context_name($context);
$this->assertFalse(empty($name));
$url = get_context_url($coursecontext);
$this->assertFalse($url instanceof modole_url);
$page = $DB->get_record('page', array('id'=>$testpages[7]));
$context = get_context_instance(CONTEXT_MODULE, $page->id);
$coursecontext = get_course_context($context);
$this->assertEquals($coursecontext->contextlevel, CONTEXT_COURSE);
$this->assertEquals(get_courseid_from_context($context), $page->course);
$caps = fetch_context_capabilities($systemcontext);
$this->assertTrue(is_array($caps));
unset($caps);
}
示例8: xmldb_main_upgrade
//.........这里部分代码省略.........
// guest can not be selected in defaultuserroleid!
unset_config('defaultuserroleid');
}
upgrade_main_savepoint($result, 2007101517);
}
if ($result && $oldversion < 2007101526) {
/// Changing the default of field lang on table user to en_utf8
$table = new XMLDBTable('user');
$field = new XMLDBField('lang');
$field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'en_utf8', 'country');
/// Launch change of default for field lang
$result = $result && change_field_default($table, $field);
/// Main savepoint reached
upgrade_main_savepoint($result, 2007101526);
}
if ($result && $oldversion < 2007101527) {
if (!get_config(NULL, 'statsruntimedays')) {
set_config('statsruntimedays', '31');
}
}
/// For MDL-17501. Ensure that any role that has moodle/course:update also
/// has moodle/course:visibility.
if ($result && $oldversion < 2007101532.1) {
if (!empty($CFG->rolesactive)) {
// In case we are upgrading from Moodle 1.6.
/// Get the roles with 'moodle/course:update'.
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$roles = get_roles_with_capability('moodle/course:update', CAP_ALLOW, $systemcontext);
/// Give those roles 'moodle/course:visibility'.
foreach ($roles as $role) {
assign_capability('moodle/course:visibility', CAP_ALLOW, $role->id, $systemcontext->id);
}
/// Force all sessions to refresh access data.
mark_context_dirty($systemcontext->path);
}
/// Main savepoint reached
upgrade_main_savepoint($result, 2007101532.1);
}
if ($result && $oldversion < 2007101542) {
if (empty($CFG->hiddenuserfields)) {
set_config('hiddenuserfields', 'firstaccess');
} else {
if (strpos($CFG->hiddenuserfields, 'firstaccess') === false) {
//firstaccess should not already be listed but just in case
set_config('hiddenuserfields', $CFG->hiddenuserfields . ',firstaccess');
}
}
/// Main savepoint reached
upgrade_main_savepoint($result, 2007101542);
}
if ($result && $oldversion < 2007101545.01) {
require_once "{$CFG->dirroot}/filter/tex/lib.php";
filter_tex_updatedcallback(null);
/// Main savepoint reached
upgrade_main_savepoint($result, 2007101545.01);
}
if ($result && $oldversion < 2007101546.02) {
if (empty($CFG->gradebook_latest195_upgrade)) {
require_once $CFG->libdir . '/gradelib.php';
// we need constants only
// reset current coef for simple mean items - it may contain some rubbish ;-)
$sql = "UPDATE {$CFG->prefix}grade_items\n SET aggregationcoef = 0\n WHERE categoryid IN (SELECT gc.id\n FROM {$CFG->prefix}grade_categories gc\n WHERE gc.aggregation = " . GRADE_AGGREGATE_WEIGHTED_MEAN2 . ")";
$result = execute_sql($sql);
} else {
// direct upgrade from 1.8.x - no need to reset coef, because it is already ok
unset_config('gradebook_latest195_upgrade');
示例9: reset_course_userdata
/**
* This function will empty a course of user data.
* It will retain the activities and the structure of the course.
*
* @param object $data an object containing all the settings including courseid (without magic quotes)
* @return array status array of array component, item, error
*/
function reset_course_userdata($data)
{
global $CFG, $USER, $DB;
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->libdir . '/completionlib.php';
require_once $CFG->dirroot . '/group/lib.php';
$data->courseid = $data->id;
$context = get_context_instance(CONTEXT_COURSE, $data->courseid);
// calculate the time shift of dates
if (!empty($data->reset_start_date)) {
// time part of course startdate should be zero
$data->timeshift = $data->reset_start_date - usergetmidnight($data->reset_start_date_old);
} else {
$data->timeshift = 0;
}
// result array: component, item, error
$status = array();
// start the resetting
$componentstr = get_string('general');
// move the course start time
if (!empty($data->reset_start_date) and $data->timeshift) {
// change course start data
$DB->set_field('course', 'startdate', $data->reset_start_date, array('id' => $data->courseid));
// update all course and group events - do not move activity events
$updatesql = "UPDATE {event}\n SET timestart = timestart + ?\n WHERE courseid=? AND instance=0";
$DB->execute($updatesql, array($data->timeshift, $data->courseid));
$status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
}
if (!empty($data->reset_logs)) {
$DB->delete_records('log', array('course' => $data->courseid));
$status[] = array('component' => $componentstr, 'item' => get_string('deletelogs'), 'error' => false);
}
if (!empty($data->reset_events)) {
$DB->delete_records('event', array('courseid' => $data->courseid));
$status[] = array('component' => $componentstr, 'item' => get_string('deleteevents', 'calendar'), 'error' => false);
}
if (!empty($data->reset_notes)) {
require_once $CFG->dirroot . '/notes/lib.php';
note_delete_all($data->courseid);
$status[] = array('component' => $componentstr, 'item' => get_string('deletenotes', 'notes'), 'error' => false);
}
if (!empty($data->delete_blog_associations)) {
require_once $CFG->dirroot . '/blog/lib.php';
blog_remove_associations_for_course($data->courseid);
$status[] = array('component' => $componentstr, 'item' => get_string('deleteblogassociations', 'blog'), 'error' => false);
}
if (!empty($data->reset_course_completion)) {
// Delete course completion information
$course = $DB->get_record('course', array('id' => $data->courseid));
$cc = new completion_info($course);
$cc->delete_course_completion_data();
$status[] = array('component' => $componentstr, 'item' => get_string('deletecoursecompletiondata', 'completion'), 'error' => false);
}
$componentstr = get_string('roles');
if (!empty($data->reset_roles_overrides)) {
$children = get_child_contexts($context);
foreach ($children as $child) {
$DB->delete_records('role_capabilities', array('contextid' => $child->id));
}
$DB->delete_records('role_capabilities', array('contextid' => $context->id));
//force refresh for logged in users
mark_context_dirty($context->path);
$status[] = array('component' => $componentstr, 'item' => get_string('deletecourseoverrides', 'role'), 'error' => false);
}
if (!empty($data->reset_roles_local)) {
$children = get_child_contexts($context);
foreach ($children as $child) {
role_unassign_all(array('contextid' => $child->id));
}
//force refresh for logged in users
mark_context_dirty($context->path);
$status[] = array('component' => $componentstr, 'item' => get_string('deletelocalroles', 'role'), 'error' => false);
}
// First unenrol users - this cleans some of related user data too, such as forum subscriptions, tracking, etc.
$data->unenrolled = array();
if (!empty($data->unenrol_users)) {
$plugins = enrol_get_plugins(true);
$instances = enrol_get_instances($data->courseid, true);
foreach ($instances as $key => $instance) {
if (!isset($plugins[$instance->enrol])) {
unset($instances[$key]);
continue;
}
if (!$plugins[$instance->enrol]->allow_unenrol($instance)) {
unset($instances[$key]);
}
}
$sqlempty = $DB->sql_empty();
foreach ($data->unenrol_users as $withroleid) {
$sql = "SELECT DISTINCT ue.userid, ue.enrolid\n FROM {user_enrolments} ue\n JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)\n JOIN {context} c ON (c.contextlevel = :courselevel AND c.instanceid = e.courseid)\n JOIN {role_assignments} ra ON (ra.contextid = c.id AND ra.roleid = :roleid AND ra.userid = ue.userid)";
$params = array('courseid' => $data->courseid, 'roleid' => $withroleid, 'courselevel' => CONTEXT_COURSE);
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $ue) {
//.........这里部分代码省略.........
示例10: test_everything_in_accesslib
//.........这里部分代码省略.........
$prevsize = context_inspection::test_context_cache_size();
for ($i = 0; $i < 100; $i++) {
context_user::instance($testusers[$i]);
$this->assertEqual(context_inspection::test_context_cache_size(), $prevsize);
}
context_user::instance($testusers[102]);
$this->assertEqual(context_inspection::test_context_cache_size(), $prevsize + 1);
unset($testusers);
// =================================================================
// ======= basic test of legacy functions ==========================
// =================================================================
// note: watch out, the fake site might be pretty borked already
$this->assertIdentical(get_system_context(), context_system::instance());
foreach ($DB->get_records('context') as $contextid => $record) {
$context = context::instance_by_id($contextid);
$this->assertIdentical(get_context_instance_by_id($contextid), $context);
$this->assertIdentical(get_context_instance($record->contextlevel, $record->instanceid), $context);
$this->assertIdentical(get_parent_contexts($context), $context->get_parent_context_ids());
if ($context->id == SYSCONTEXTID) {
$this->assertIdentical(get_parent_contextid($context), false);
} else {
$this->assertIdentical(get_parent_contextid($context), $context->get_parent_context()->id);
}
}
$children = get_child_contexts($systemcontext);
$this->assertEqual(count($children), $DB->count_records('context') - 1);
unset($children);
$DB->delete_records('context', array('contextlevel' => CONTEXT_BLOCK));
create_contexts();
$this->assertFalse($DB->record_exists('context', array('contextlevel' => CONTEXT_BLOCK)));
$DB->set_field('context', 'depth', 0, array('contextlevel' => CONTEXT_BLOCK));
build_context_path();
$this->assertFalse($DB->record_exists('context', array('depth' => 0)));
$lastcourse = $DB->get_field_sql("SELECT MAX(id) FROM {course}");
$DB->delete_records('course', array('id' => $lastcourse));
$lastcategory = $DB->get_field_sql("SELECT MAX(id) FROM {course_categories}");
$DB->delete_records('course_categories', array('id' => $lastcategory));
$lastuser = $DB->get_field_sql("SELECT MAX(id) FROM {user} WHERE deleted=0");
$DB->delete_records('user', array('id' => $lastuser));
$DB->delete_records('block_instances', array('parentcontextid' => $frontpagepagecontext->id));
$DB->delete_records('course_modules', array('id' => $frontpagepagecontext->instanceid));
cleanup_contexts();
$count = 1;
//system
$count += $DB->count_records('user', array('deleted' => 0));
$count += $DB->count_records('course_categories');
$count += $DB->count_records('course');
$count += $DB->count_records('course_modules');
$count += $DB->count_records('block_instances');
$this->assertEqual($DB->count_records('context'), $count);
context_helper::reset_caches();
preload_course_contexts($SITE->id);
$this->assertEqual(context_inspection::test_context_cache_size(), 1);
context_helper::reset_caches();
list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSECAT, 'ctx');
$sql = "SELECT c.id {$select} FROM {course_categories} c {$join}";
$records = $DB->get_records_sql($sql);
foreach ($records as $record) {
context_instance_preload($record);
$record = (array) $record;
$this->assertEqual(1, count($record));
// only id left
}
$this->assertEqual(count($records), context_inspection::test_context_cache_size());
accesslib_clear_all_caches(true);
$DB->delete_records('cache_flags', array());
mark_context_dirty($systemcontext->path);
$dirty = get_cache_flags('accesslib/dirtycontexts', time() - 2);
$this->assertTrue(isset($dirty[$systemcontext->path]));
accesslib_clear_all_caches(false);
$DB->delete_records('cache_flags', array());
$course = $DB->get_record('course', array('id' => $testcourses[2]));
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$oldpath = $context->path;
$miscid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}");
$categorycontext = context_coursecat::instance($miscid);
$course->category = $miscid;
$DB->update_record('course', $course);
context_moved($context, $categorycontext);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$this->assertIdentical($context->get_parent_context(), $categorycontext);
$this->assertTrue($DB->record_exists('context', array('contextlevel' => CONTEXT_COURSE, 'instanceid' => $testcourses[2])));
delete_context(CONTEXT_COURSE, $testcourses[2]);
$this->assertFalse($DB->record_exists('context', array('contextlevel' => CONTEXT_COURSE, 'instanceid' => $testcourses[2])));
$name = get_contextlevel_name(CONTEXT_COURSE);
$this->assertFalse(empty($name));
$context = get_context_instance(CONTEXT_COURSE, $testcourses[2]);
$name = print_context_name($context);
$this->assertFalse(empty($name));
$url = get_context_url($coursecontext);
$this->assertFalse($url instanceof modole_url);
$page = $DB->get_record('page', array('id' => $testpages[7]));
$context = get_context_instance(CONTEXT_MODULE, $page->id);
$coursecontext = get_course_context($context);
$this->assertEqual($coursecontext->contextlevel, CONTEXT_COURSE);
$this->assertEqual(get_courseid_from_context($context), $page->course);
$caps = fetch_context_capabilities($systemcontext);
$this->assertTrue(is_array($caps));
unset($caps);
}
示例11: local_postinst
function local_postinst()
{
global $db, $CFG;
$olddebug = $db->debug;
$db->debug = $CFG->debug;
set_config('theme', 'intel');
$db->debug = $olddebug;
// set frontpage blocks
tao_reset_frontpage_blocks();
// set sticky blocks
tao_reset_stickyblocks();
// create the TAO Site Forum
$forum = local_create_forum(SITEID, NOGROUPS, get_string('siteforumname', 'local'), get_string('siteforumintro', 'local'));
// remove guest access to the site level forum
$required = array("mod/forum:addnews", "mod/forum:createattachment", "mod/forum:deleteanypost", "mod/forum:deleteownpost", "mod/forum:editanypost", "mod/forum:initialsubscriptions", "mod/forum:managesubscriptions", "mod/forum:movediscussions", "mod/forum:rate", "mod/forum:replynews", "mod/forum:replypost", "mod/forum:splitdiscussions", "mod/forum:startdiscussion", "mod/forum:throttlingapplies", "mod/forum:viewanyrating", "mod/forum:viewdiscussion", "mod/forum:viewhiddentimedposts", "mod/forum:viewqandawithoutposting", "mod/forum:viewrating", "mod/forum:viewsubscribers");
if (!($cm = get_coursemodule_from_id("forum", $forum->coursemodule, SITEID))) {
error("Could not determine which course module this belonged to!");
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// find the exisiting list of capabilities
$capabilities = fetch_context_capabilities($context);
if ($roles = get_records_select('role', 'shortname IN (\'guest\')')) {
foreach ($roles as $role) {
foreach ($capabilities as $capability) {
// check against the list of capabilities that we want to block
if (!in_array($capability->name, $required)) {
continue;
}
assign_capability($capability->name, -1000, $role->id, $context->id);
}
}
mark_context_dirty($context->path);
}
// give everyone else access to the site level forum
$required = array("mod/forum:addnews", "mod/forum:createattachment", "mod/forum:deleteownpost", "mod/forum:initialsubscriptions", "mod/forum:rate", "mod/forum:replynews", "mod/forum:replypost", "mod/forum:startdiscussion", "mod/forum:viewanyrating", "mod/forum:viewdiscussion", "mod/forum:viewrating");
if ($roles = get_records_select('role', 'shortname NOT IN (\'guest\', \'user\')')) {
foreach ($roles as $role) {
foreach ($capabilities as $capability) {
// check against the list of capabilities that we want to block
if (!in_array($capability->name, $required)) {
continue;
}
assign_capability($capability->name, 1, $role->id, $context->id);
}
}
mark_context_dirty($context->path);
}
// add TAO site wide FAQ
$glossary = local_create_glossary(SITEID, get_string('defaultglossaryname', 'local'), get_string('defaultglossarydescription', 'local'));
// set of capabilities that we want to orverride
$required = array('mod/glossary:approve', 'mod/glossary:comment', 'mod/glossary:import', 'mod/glossary:managecategories', 'mod/glossary:managecomments', 'mod/glossary:manageentries', 'mod/glossary:rate', 'mod/glossary:write');
if (!($cm = get_coursemodule_from_id("glossary", $glossary->coursemodule, SITEID))) {
error("Could not determine which course module this belonged to!");
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// find the exisiting list of capabilities
$capabilities = fetch_context_capabilities($context);
if ($roles = get_records_select('role', 'shortname NOT IN (\'admin\', \'superadmin\')')) {
foreach ($roles as $role) {
foreach ($capabilities as $capability) {
// check against the list of capabilities that we want to block
if (!in_array($capability->name, $required)) {
continue;
}
assign_capability($capability->name, -1000, $role->id, $context->id);
}
}
mark_context_dirty($context->path);
}
//set up default Course Categories
$course_cat = new stdclass();
$course_cat->name = get_string('taocatlp', 'local');
$course_cat->description = '';
$course_cat->parent = 0;
$course_cat->sortorder = 2;
$course_cat->coursecount = 0;
$course_cat->visible = 1;
$course_cat->timemodified = time();
$course_cat->depth = 1;
$course_cat->path = "''";
$course_cat->theme = '';
$lpid = insert_record('course_categories', $course_cat);
//insert learning path category and keep id for use later.
$catcontext = get_context_instance(CONTEXT_COURSECAT, $lpid);
mark_context_dirty($catcontext->path);
$course_cat->name = get_string('taocatlptemplates', 'local');
$course_cat->sortorder = 3;
$course_cat->visible = 0;
$lptempid = insert_record('course_categories', $course_cat);
//insert my sections category keep id for use later.
$catcontext = get_context_instance(CONTEXT_COURSECAT, $lptempid);
mark_context_dirty($catcontext->path);
$course_cat->name = get_string('taotrainingcourses', 'local');
$course_cat->sortorder = 5;
$course_cat->visible = 1;
$taotrainingid = insert_record('course_categories', $course_cat);
//insert my sections category keep id for use later.
$catcontext = get_context_instance(CONTEXT_COURSECAT, $taotrainingid);
mark_context_dirty($catcontext->path);
$course_cat->name = get_string('taocatworkshop', 'local');
//.........这里部分代码省略.........
示例12: tao_create_lp
function tao_create_lp($data, $author, $creatorroleid, $createtemplate = 0, $preferences = array())
{
global $CFG;
if (empty($data)) {
error("invalid call to tao_create_lp");
}
// get course template
if (!($course = get_record('course', 'id', $data->course_template))) {
error('Invalid course id');
}
// get a handle on the most recent backup for the selected course
$wdir = "/backupdata";
$fullpath = $CFG->dataroot . "/" . $course->id . $wdir;
$dirlist = array();
$filelist = array();
if (!is_dir($fullpath)) {
error("No templates for selected course");
}
$directory = opendir($fullpath);
// Find all files
while (false !== ($file = readdir($directory))) {
if ($file == "." || $file == "..") {
continue;
}
if (strchr($file, ".") != ".zip") {
continue;
}
if (is_dir($fullpath . "/" . $file)) {
$dirlist[] = $file;
} else {
$filelist[] = $file;
}
}
closedir($directory);
asort($filelist);
// get the last file
$file = array_pop($filelist);
$fullpathtofile = "{$fullpath}/{$file}";
if (!$file) {
error("No templates for selected course");
}
// attempt to create the new course
if (!($newcourse = create_course($data))) {
print_error('coursenotcreated');
}
$context = get_context_instance(CONTEXT_COURSE, $newcourse->id);
$sitecontext = get_context_instance(CONTEXT_COURSE, SITEID);
// assign our initial user - note this means automatic assigning by the backup should be skipped, which is based
// the on the manage:activities role being present
role_assign($creatorroleid, $author->id, 0, $context->id);
if ($data->learning_path_mode == LEARNING_PATH_MODE_RAFL) {
//now set role override for PT users to prevent them from being able to add blocks and activities.
$ptroleid = get_field('role', 'id', 'shortname', ROLE_PT);
$ispt = user_has_role_assignment($author->id, $ptroleid, $sitecontext->id);
if ($ispt) {
//prevent from being able to change the structure of the pages.
assign_capability('format/learning:manageactivities', CAP_PREVENT, $creatorroleid, $context->id);
}
}
// create default the TAO Course (LP) Forum
/// ** load this in template instead? ** local_create_forum($newcourse->id, SEPARATEGROUPS, get_string('defaultforumname', 'local'), get_string('defaultforumintro', 'local'));
// create default the TAO Course (LP) Wiki
/// ** load this in template instead? ** local_create_wiki($newcourse->id, SEPARATEGROUPS, get_string('defaultwikiname', 'local'), get_string('defaultwikisummary', 'local'));
if (!$createtemplate) {
// set course status
if (!tao_update_course_status(COURSE_STATUS_NOTSUBMITTED, "Created new learning path from template", $newcourse)) {
error('could not update status');
}
}
//set up preferences for pasign to backup_file_silently
$preferences['course_format'] = 1;
if ($data->learning_path_mode == LEARNING_PATH_MODE_STANDARD) {
// load the backup data into course //TODO some way of validating this
import_backup_file_silently($fullpathtofile, $newcourse->id, false, false, $preferences, RESTORETO_CURRENT_DELETING);
// if valid
// set course status
if (!tao_update_course_status(COURSE_STATUS_NOTSUBMITTED, "Created new learning path from template", $newcourse)) {
error('could not update status');
}
// ensure we can use the course right after creating it
// this means trigger a reload of accessinfo...
mark_context_dirty($context->path);
$author->raflmode = 0;
// Redirect to course page
return $newcourse->id;
} elseif ($data->learning_path_mode == LEARNING_PATH_MODE_RAFL) {
//set pref to not restore pages for all RAFL imports:
$preferences['nopages'] = 1;
// load the template, but leave out actual content pages - they are created by rafl structure.
// note: we must do this before adding the new pages otherwise this process will remove them
import_backup_file_silently($fullpathtofile, $newcourse->id, false, false, $preferences);
// todo do a non-fatal check for rafl module, and give a friendly message if not found
require_once $CFG->dirroot . '/mod/rafl/lib.php';
require_once $CFG->dirroot . '/mod/rafl/locallib.php';
require_once $CFG->dirroot . '/course/format/learning/lib.php';
require_once $CFG->dirroot . '/course/format/learning/pagelib.php';
$rafl = new localLibRafl();
$pageid = $newcourse->id;
// pageid is actually courseid in the blockinstance context. i know!
$pagetype = 'course-view';
//.........这里部分代码省略.........
示例13: context_moved
/**
* Update the path field of the context and
* all the dependent subcontexts that follow
* the move.
*
* The most important thing here is to be as
* DB efficient as possible. This op can have a
* massive impact in the DB.
*
* @param obj current context obj
* @param obj newparent new parent obj
*
*/
function context_moved($context, $newparent)
{
global $CFG;
$frompath = $context->path;
$newpath = $newparent->path . '/' . $context->id;
$setdepth = '';
if ($newparent->depth + 1 != $context->depth) {
$setdepth = ", depth= depth + ({$newparent->depth} - {$context->depth}) + 1";
}
$sql = "UPDATE {$CFG->prefix}context \n SET path='{$newpath}'\n {$setdepth}\n WHERE path='{$frompath}'";
execute_sql($sql, false);
$len = strlen($frompath);
$sql = "UPDATE {$CFG->prefix}context\n SET path = " . sql_concat("'{$newpath}'", 'SUBSTR(path, ' . $len . ' +1)') . "\n {$setdepth}\n WHERE path LIKE '{$frompath}/%'";
execute_sql($sql, false);
mark_context_dirty($frompath);
mark_context_dirty($newpath);
}
示例14: unenrol_user
/**
* Unenrol a user from a course
*
* @param string $username The username
* @param int $courseid The id of the local course
* @return bool Whether the user can login from the remote host
*/
function unenrol_user($user, $courseid)
{
global $MNET_REMOTE_CLIENT;
$userrecord = get_record('user', 'username', $user['username'], 'mnethostid', $MNET_REMOTE_CLIENT->id);
if ($userrecord == false) {
// TODO: Error out
}
if (!($course = get_record('course', 'id', $courseid))) {
// TODO: Error out
}
if (!($context = get_context_instance(CONTEXT_COURSE, $course->id))) {
// TODO: Error out (Invalid context)
}
// Are we a *real* user or the shady MNET Daemon?
// require_capability('moodle/role:assign', $context, NULL, false);
if (role_unassign(0, $userrecord->id, 0, $context->id)) {
// force accessinfo refresh for users visiting this context...
mark_context_dirty($context->path);
} else {
error("An error occurred while trying to unenrol that person.");
}
return true;
}
示例15: context_moved
/**
* Update the path field of the context and
* all the dependent subcontexts that follow
* the move.
*
* The most important thing here is to be as
* DB efficient as possible. This op can have a
* massive impact in the DB.
*
* @param obj current context obj
* @param obj newparent new parent obj
*
*/
function context_moved($context, $newparent)
{
global $DB;
$frompath = $context->path;
$newpath = $newparent->path . '/' . $context->id;
$setdepth = '';
if ($newparent->depth + 1 != $context->depth) {
$diff = $newparent->depth - $context->depth + 1;
$setdepth = ", depth = depth + {$diff}";
}
$sql = "UPDATE {context}\n SET path = ?\n {$setdepth}\n WHERE path = ?";
$params = array($newpath, $frompath);
$DB->execute($sql, $params);
$sql = "UPDATE {context}\n SET path = " . $DB->sql_concat("?", $DB->sql_substr("path", strlen($frompath) + 1)) . "\n {$setdepth}\n WHERE path LIKE ?";
$params = array($newpath, "{$frompath}/%");
$DB->execute($sql, $params);
mark_context_dirty($frompath);
mark_context_dirty($newpath);
}