本文整理汇总了PHP中get_default_role_archetype_allows函数的典型用法代码示例。如果您正苦于以下问题:PHP get_default_role_archetype_allows函数的具体用法?PHP get_default_role_archetype_allows怎么用?PHP get_default_role_archetype_allows使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_default_role_archetype_allows函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmldb_main_install
//.........这里部分代码省略.........
$guest->password = hash_internal_user_password('guest');
$guest->firstname = get_string('guestuser');
$guest->lastname = ' ';
$guest->email = 'root@localhost';
$guest->description = get_string('guestuserinfo');
$guest->mnethostid = $CFG->mnet_localhost_id;
$guest->confirmed = 1;
$guest->lang = $CFG->lang;
$guest->timemodified = time();
$guest->id = $DB->insert_record('user', $guest);
if ($guest->id != 1) {
echo $OUTPUT->notification('Unexpected id generated for the Guest account. Your database configuration or clustering setup may not be fully supported', 'notifyproblem');
}
// Store guest id
set_config('siteguest', $guest->id);
// Make sure user context exists
context_user::instance($guest->id);
// Now create admin user
$admin = new stdClass();
$admin->auth = 'manual';
$admin->firstname = get_string('admin');
$admin->lastname = get_string('user');
$admin->username = 'admin';
$admin->password = 'adminsetuppending';
$admin->email = '';
$admin->confirmed = 1;
$admin->mnethostid = $CFG->mnet_localhost_id;
$admin->lang = $CFG->lang;
$admin->maildisplay = 1;
$admin->timemodified = time();
$admin->lastip = CLI_SCRIPT ? '0.0.0.0' : getremoteaddr();
// installation hijacking prevention
$admin->id = $DB->insert_record('user', $admin);
if ($admin->id != 2) {
echo $OUTPUT->notification('Unexpected id generated for the Admin account. Your database configuration or clustering setup may not be fully supported', 'notifyproblem');
}
if ($admin->id != $guest->id + 1) {
echo $OUTPUT->notification('Nonconsecutive id generated for the Admin account. Your database configuration or clustering setup may not be fully supported.', 'notifyproblem');
}
// Store list of admins
set_config('siteadmins', $admin->id);
// Make sure user context exists
context_user::instance($admin->id);
// Install the roles system.
$managerrole = create_role('', 'manager', '', 'manager');
$coursecreatorrole = create_role('', 'coursecreator', '', 'coursecreator');
$editteacherrole = create_role('', 'editingteacher', '', 'editingteacher');
$noneditteacherrole = create_role('', 'teacher', '', 'teacher');
$studentrole = create_role('', 'student', '', 'student');
$guestrole = create_role('', 'guest', '', 'guest');
$userrole = create_role('', 'user', '', 'user');
$frontpagerole = create_role('', 'frontpage', '', 'frontpage');
// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
update_capabilities('moodle');
// Default allow role matrices.
foreach ($DB->get_records('role') as $role) {
foreach (array('assign', 'override', 'switch') as $type) {
$function = 'allow_' . $type;
$allows = get_default_role_archetype_allows($type, $role->archetype);
foreach ($allows as $allowid) {
$function($role->id, $allowid);
}
}
}
// Set up the context levels where you can assign each role.
set_role_contextlevels($managerrole, get_default_contextlevels('manager'));
set_role_contextlevels($coursecreatorrole, get_default_contextlevels('coursecreator'));
set_role_contextlevels($editteacherrole, get_default_contextlevels('editingteacher'));
set_role_contextlevels($noneditteacherrole, get_default_contextlevels('teacher'));
set_role_contextlevels($studentrole, get_default_contextlevels('student'));
set_role_contextlevels($guestrole, get_default_contextlevels('guest'));
set_role_contextlevels($userrole, get_default_contextlevels('user'));
// Init theme and JS revisions
set_config('themerev', time());
set_config('jsrev', time());
// No admin setting for this any more, GD is now required, remove in Moodle 2.6.
set_config('gdversion', 2);
// Install licenses
require_once $CFG->libdir . '/licenselib.php';
license_manager::install_licenses();
// Init profile pages defaults
if ($DB->record_exists('my_pages', array())) {
throw new moodle_exception('generalexceptionmessage', 'error', '', 'Can not create default profile pages, records already exist.');
}
$mypage = new stdClass();
$mypage->userid = NULL;
$mypage->name = '__default';
$mypage->private = 0;
$mypage->sortorder = 0;
$DB->insert_record('my_pages', $mypage);
$mypage->private = 1;
$DB->insert_record('my_pages', $mypage);
// Set a sensible default sort order for the most-used question types.
set_config('multichoice_sortorder', 1, 'question');
set_config('truefalse_sortorder', 2, 'question');
set_config('match_sortorder', 3, 'question');
set_config('shortanswer_sortorder', 4, 'question');
set_config('numerical_sortorder', 5, 'question');
set_config('essay_sortorder', 6, 'question');
}
示例2: create_role
/**
* Creates a new role in the system.
*
* You can fill $record with the role 'name',
* 'shortname', 'description' and 'archetype'.
*
* If an archetype is specified it's capabilities,
* context where the role can be assigned and
* all other properties are copied from the archetype;
* if no archetype is specified it will create an
* empty role.
*
* @param array|stdClass $record
* @return int The new role id
*/
public function create_role($record=null) {
global $DB;
$this->rolecount++;
$i = $this->rolecount;
$record = (array)$record;
if (empty($record['shortname'])) {
$record['shortname'] = 'role-' . $i;
}
if (empty($record['name'])) {
$record['name'] = 'Test role ' . $i;
}
if (empty($record['description'])) {
$record['description'] = 'Test role ' . $i . ' description';
}
if (empty($record['archetype'])) {
$record['archetype'] = '';
} else {
$archetypes = get_role_archetypes();
if (empty($archetypes[$record['archetype']])) {
throw new coding_exception('\'role\' requires the field \'archetype\' to specify a ' .
'valid archetype shortname (editingteacher, student...)');
}
}
// Creates the role.
if (!$newroleid = create_role($record['name'], $record['shortname'], $record['description'], $record['archetype'])) {
throw new coding_exception('There was an error creating \'' . $record['shortname'] . '\' role');
}
// If no archetype was specified we allow it to be added to all contexts,
// otherwise we allow it in the archetype contexts.
if (!$record['archetype']) {
$contextlevels = array_keys(context_helper::get_all_levels());
} else {
// Copying from the archetype default rol.
$archetyperoleid = $DB->get_field(
'role',
'id',
array('shortname' => $record['archetype'], 'archetype' => $record['archetype'])
);
$contextlevels = get_role_contextlevels($archetyperoleid);
}
set_role_contextlevels($newroleid, $contextlevels);
if ($record['archetype']) {
// We copy all the roles the archetype can assign, override and switch to.
if ($record['archetype']) {
$types = array('assign', 'override', 'switch');
foreach ($types as $type) {
$rolestocopy = get_default_role_archetype_allows($type, $record['archetype']);
foreach ($rolestocopy as $tocopy) {
$functionname = 'allow_' . $type;
$functionname($newroleid, $tocopy);
}
}
}
// Copying the archetype capabilities.
$sourcerole = $DB->get_record('role', array('id' => $archetyperoleid));
role_cap_duplicate($sourcerole, $newroleid);
}
return $newroleid;
}
示例3: test_get_default_role_archetype_allows
/**
* Test role default allows.
*/
public function test_get_default_role_archetype_allows()
{
$archetypes = get_role_archetypes();
foreach ($archetypes as $archetype) {
$result = get_default_role_archetype_allows('assign', $archetype);
$this->assertInternalType('array', $result);
$result = get_default_role_archetype_allows('override', $archetype);
$this->assertInternalType('array', $result);
$result = get_default_role_archetype_allows('switch', $archetype);
$this->assertInternalType('array', $result);
}
$result = get_default_role_archetype_allows('assign', '');
$this->assertSame(array(), $result);
$result = get_default_role_archetype_allows('override', '');
$this->assertSame(array(), $result);
$result = get_default_role_archetype_allows('switch', '');
$this->assertSame(array(), $result);
$result = get_default_role_archetype_allows('assign', 'wrongarchetype');
$this->assertSame(array(), $result);
$this->assertDebuggingCalled();
$result = get_default_role_archetype_allows('override', 'wrongarchetype');
$this->assertSame(array(), $result);
$this->assertDebuggingCalled();
$result = get_default_role_archetype_allows('switch', 'wrongarchetype');
$this->assertSame(array(), $result);
$this->assertDebuggingCalled();
}
示例4: force_archetype
/**
* Change the role definition to match given archetype.
*
* @param string $archetype
* @param array $options array with following keys:
* 'name', 'shortname', 'description', 'permissions', 'archetype',
* 'contextlevels', 'allowassign', 'allowoverride', 'allowswitch'
*/
public function force_archetype($archetype, array $options)
{
$archetypes = get_role_archetypes();
if (!isset($archetypes[$archetype])) {
throw new coding_exception('Unknown archetype: ' . $archetype);
}
if ($options['shortname']) {
$this->role->shortname = '';
}
if ($options['name']) {
$this->role->name = '';
}
if ($options['description']) {
$this->role->description = '';
}
if ($options['archetype']) {
$this->role->archetype = $archetype;
}
if ($options['contextlevels']) {
$this->contextlevels = array();
$defaults = get_default_contextlevels($archetype);
foreach ($defaults as $cl) {
$this->contextlevels[$cl] = $cl;
}
}
if ($options['allowassign']) {
$this->allowassign = get_default_role_archetype_allows('assign', $archetype);
}
if ($options['allowoverride']) {
$this->allowoverride = get_default_role_archetype_allows('override', $archetype);
}
if ($options['allowswitch']) {
$this->allowswitch = get_default_role_archetype_allows('switch', $archetype);
}
if ($options['permissions']) {
$defaultpermissions = get_default_capabilities($archetype);
foreach ($this->permissions as $k => $v) {
if (isset($defaultpermissions[$k])) {
$this->permissions[$k] = $defaultpermissions[$k];
continue;
}
$this->permissions[$k] = CAP_INHERIT;
}
}
}