本文整理汇总了PHP中fetch_context_capabilities函数的典型用法代码示例。如果您正苦于以下问题:PHP fetch_context_capabilities函数的具体用法?PHP fetch_context_capabilities怎么用?PHP fetch_context_capabilities使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fetch_context_capabilities函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: definition
function definition()
{
$mform = $this->_form;
$service = isset($this->_customdata) ? $this->_customdata : new stdClass();
$mform->addElement('header', 'extservice', get_string('externalservice', 'webservice'));
$mform->addElement('text', 'name', get_string('name'));
$mform->addRule('name', get_string('required'), 'required', null, 'client');
$mform->setType('name', PARAM_TEXT);
$mform->addElement('advcheckbox', 'enabled', get_string('enabled', 'webservice'));
$mform->setType('enabled', PARAM_BOOL);
$mform->addElement('advcheckbox', 'restrictedusers', get_string('restrictedusers', 'webservice'));
$mform->addHelpButton('restrictedusers', 'restrictedusers', 'webservice');
$mform->setType('restrictedusers', PARAM_BOOL);
//can users download files
$mform->addElement('advcheckbox', 'downloadfiles', get_string('downloadfiles', 'webservice'));
$mform->setAdvanced('downloadfiles');
$mform->addHelpButton('downloadfiles', 'downloadfiles', 'webservice');
$mform->setType('downloadfiles', PARAM_BOOL);
/// needed to select automatically the 'No required capability" option
$currentcapabilityexist = false;
if (empty($service->requiredcapability)) {
$service->requiredcapability = "norequiredcapability";
$currentcapabilityexist = true;
}
// Prepare the list of capabilities to choose from
$systemcontext = context_system::instance();
$allcapabilities = fetch_context_capabilities($systemcontext);
$capabilitychoices = array();
$capabilitychoices['norequiredcapability'] = get_string('norequiredcapability', 'webservice');
foreach ($allcapabilities as $cap) {
$capabilitychoices[$cap->name] = $cap->name . ': ' . get_capability_string($cap->name);
if (!empty($service->requiredcapability) && $service->requiredcapability == $cap->name) {
$currentcapabilityexist = true;
}
}
$mform->addElement('searchableselector', 'requiredcapability', get_string('requiredcapability', 'webservice'), $capabilitychoices);
$mform->addHelpButton('requiredcapability', 'requiredcapability', 'webservice');
$mform->setAdvanced('requiredcapability');
$mform->setType('requiredcapability', PARAM_RAW);
/// display notification error if the current requiredcapability doesn't exist anymore
if (empty($currentcapabilityexist)) {
global $OUTPUT;
$mform->addElement('static', 'capabilityerror', '', $OUTPUT->notification(get_string('selectedcapabilitydoesntexit', 'webservice', $service->requiredcapability)));
$service->requiredcapability = "norequiredcapability";
}
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
if (!empty($service->id)) {
$buttonlabel = get_string('savechanges');
} else {
$buttonlabel = get_string('addaservice', 'webservice');
}
$this->add_action_buttons(true, $buttonlabel);
$this->set_data($service);
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:55,代码来源:forms.php
示例2: get_string
$strcurrentrole = get_string('currentrole', 'role');
$strparticipants = get_string('participants');
/// Make sure this user can override that role
if ($roleid) {
if (!isset($overridableroles[$roleid])) {
error('you can not override this role in this context');
}
}
if ($userid) {
$user = get_record('user', 'id', $userid);
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
}
/// get all cababilities
$safeoverridenotice = false;
if ($roleid) {
if ($capabilities = fetch_context_capabilities($context)) {
// find out if we need to lock some capabilities
foreach ($capabilities as $capname => $capability) {
$capabilities[$capname]->locked = false;
if ($canoverride) {
//ok no locking at all
continue;
}
//only limited safe overrides - spam only allowed
if (RISK_DATALOSS & (int) $capability->riskbitmask or RISK_MANAGETRUST & (int) $capability->riskbitmask or RISK_CONFIG & (int) $capability->riskbitmask or RISK_XSS & (int) $capability->riskbitmask or RISK_PERSONAL & (int) $capability->riskbitmask) {
$capabilities[$capname]->locked = true;
$safeoverridenotice = true;
}
}
}
} else {
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:31,代码来源:override.php
示例3: __construct
/**
* Constructor
* @param object $context the context this table relates to.
* @param string $id what to put in the id="" attribute.
*/
public function __construct($context, $id)
{
$this->context = $context;
$this->capabilities = fetch_context_capabilities($context);
$this->id = $id;
}
开发者ID:vinoth4891,项目名称:clinique,代码行数:11,代码来源:lib.php
示例4: 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);
}
开发者ID:numbas,项目名称:moodle,代码行数:101,代码来源:accesslib_test.php
示例5: stripslashes_safe
if ($action == 'edit' and !empty($errors) and !empty($newrole)) {
$role = stripslashes_safe($newrole);
} else {
if (!($role = get_record('role', 'id', $roleid))) {
error('Incorrect role ID!');
}
$role->legacytype = get_legacy_type($role->id);
}
}
foreach ($roles as $rolex) {
$roleoptions[$rolex->id] = strip_tags(format_string($rolex->name));
}
// this is the array holding capabilities of this role sorted till this context
$r_caps = role_context_capabilities($roleid, $sitecontext);
// this is the available capabilities assignable in this context
$capabilities = fetch_context_capabilities($sitecontext);
$usehtmleditor = can_use_html_editor();
switch ($action) {
case 'add':
print_heading_with_help(get_string('addrole', 'role'), 'roles');
break;
case 'view':
print_heading_with_help(get_string('viewrole', 'role'), 'roles');
break;
case 'edit':
print_heading_with_help(get_string('editrole', 'role'), 'roles');
break;
}
echo '<div class="selector">';
if ($action == 'view') {
popup_form('manage.php?action=view&roleid=', $roleoptions, 'switchrole', $roleid, '', '', '', false, 'self', get_string('selectrole', 'role'));
开发者ID:r007,项目名称:PMoodle,代码行数:31,代码来源:manage.php
示例6: 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);
}
开发者ID:rolandovanegas,项目名称:moodle,代码行数:101,代码来源:fulltestaccesslib.php
示例7: 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');
//.........这里部分代码省略.........
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:101,代码来源:lib.php
示例8: array_keys
if (array_key_exists($roleid, $allroles)) {
$cleanedroleids[] = $roleid;
}
}
if (empty($cleanedroleids)) {
$cleanedroleids = array_keys($allroles);
}
// Include the required JavaScript.
$PAGE->requires->js_init_call('M.report_capability.init', array(get_string('search')));
// Log.
add_to_log(SITEID, "admin", "report capability", "report/capability/index.php?capability={$capability}", $capability);
// Print the header.
admin_externalpage_setup('reportcapability');
echo $OUTPUT->header();
// Prepare the list of capabilities to choose from
$allcapabilities = fetch_context_capabilities($systemcontext);
$capabilitychoices = array();
foreach ($allcapabilities as $cap) {
$capabilitychoices[$cap->name] = $cap->name . ': ' . get_capability_string($cap->name);
}
// Prepare the list of roles to choose from
$rolechoices = array('0' => get_string('all'));
foreach ($allroles as $role) {
$rolechoices[$role->id] = $role->name;
}
if (count($cleanedroleids) == count($allroles)) {
// Select 'All', rather than each role individually.
$selectedroleids = array('0');
} else {
$selectedroleids = $cleanedroleids;
}
开发者ID:vuchannguyen,项目名称:web,代码行数:31,代码来源:index.php
注:本文中的fetch_context_capabilities函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论