• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP get_default_role_archetype_allows函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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');
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:101,代码来源:install.php


示例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;
    }
开发者ID:jtibbetts,项目名称:moodle,代码行数:86,代码来源:data_generator.php


示例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();
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:30,代码来源:accesslib_test.php


示例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;
         }
     }
 }
开发者ID:Gavinthisisit,项目名称:Moodle,代码行数:53,代码来源:define_role_table_advanced.php



注:本文中的get_default_role_archetype_allows函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_default_tva函数代码示例发布时间:2022-05-15
下一篇:
PHP get_default_profile_photo函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap