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

PHP get_role_archetypes函数代码示例

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

本文整理汇总了PHP中get_role_archetypes函数的典型用法代码示例。如果您正苦于以下问题:PHP get_role_archetypes函数的具体用法?PHP get_role_archetypes怎么用?PHP get_role_archetypes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_role_archetypes函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: definition

 /**
  * Definition of this form.
  */
 protected function definition()
 {
     $mform = $this->_form;
     $data = $this->_customdata;
     $options = array();
     $group = get_string('other');
     $options[$group] = array();
     $options[$group][0] = get_string('norole', 'core_role');
     $group = get_string('role', 'core');
     $options[$group] = array();
     foreach (role_get_names(null, ROLENAME_BOTH) as $role) {
         // Allow reset to self too, it may be useful when importing incomplete XML preset.
         $options[$group][$role->id] = $role->localname;
     }
     $group = get_string('archetype', 'core_role');
     $options[$group] = array();
     foreach (get_role_archetypes() as $type) {
         $options[$group][$type] = get_string('archetype' . $type, 'core_role');
     }
     $mform->addElement('header', 'presetheader', get_string('roleresetdefaults', 'core_role'));
     $mform->addElement('selectgroups', 'resettype', get_string('roleresetrole', 'core_role'), $options);
     $mform->addElement('filepicker', 'rolepreset', get_string('rolerepreset', 'core_role'));
     if ($data['roleid']) {
         $mform->addElement('header', 'resetheader', get_string('resetrole', 'core_role'));
         $mform->addElement('advcheckbox', 'shortname', get_string('roleshortname', 'core_role'));
         $mform->addElement('advcheckbox', 'name', get_string('customrolename', 'core_role'));
         $mform->addElement('advcheckbox', 'description', get_string('customroledescription', 'core_role'));
         $mform->addElement('advcheckbox', 'archetype', get_string('archetype', 'core_role'));
         $mform->addElement('advcheckbox', 'contextlevels', get_string('maybeassignedin', 'core_role'));
         $mform->addElement('advcheckbox', 'allowassign', get_string('allowassign', 'core_role'));
         $mform->addElement('advcheckbox', 'allowoverride', get_string('allowoverride', 'core_role'));
         $mform->addElement('advcheckbox', 'allowswitch', get_string('allowswitch', 'core_role'));
         $mform->addElement('advcheckbox', 'permissions', get_string('permissions', 'core_role'));
     }
     $mform->addElement('hidden', 'roleid');
     $mform->setType('roleid', PARAM_INT);
     $mform->addElement('hidden', 'action');
     $mform->setType('action', PARAM_ALPHA);
     $mform->addElement('hidden', 'return');
     $mform->setType('return', PARAM_ALPHA);
     $this->add_action_buttons(true, get_string('continue', 'core'));
     $this->set_data($data);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:46,代码来源:preset_form.php


示例2: create_role

/**
 * Function that creates a role
 *
 * @param string $name role name
 * @param string $shortname role short name
 * @param string $description role description
 * @param string $archetype
 * @return int id or dml_exception
 */
function create_role($name, $shortname, $description, $archetype = '')
{
    global $DB;
    if (strpos($archetype, 'moodle/legacy:') !== false) {
        throw new coding_exception('Use new role archetype parameter in create_role() instead of old legacy capabilities.');
    }
    // verify role archetype actually exists
    $archetypes = get_role_archetypes();
    if (empty($archetypes[$archetype])) {
        $archetype = '';
    }
    // Insert the role record.
    $role = new stdClass();
    $role->name = $name;
    $role->shortname = $shortname;
    $role->description = $description;
    $role->archetype = $archetype;
    //find free sortorder number
    $role->sortorder = $DB->get_field('role', 'MAX(sortorder) + 1', array());
    if (empty($role->sortorder)) {
        $role->sortorder = 1;
    }
    $id = $DB->insert_record('role', $role);
    return $id;
}
开发者ID:rolandovanegas,项目名称:moodle,代码行数:34,代码来源:accesslib.php


示例3: parse_preset

 /**
  * Parse role preset xml file.
  *
  * @param string $xml
  * @return array role info, null on error
  */
 public static function parse_preset($xml)
 {
     global $DB;
     $info = array();
     if (!self::is_valid_preset($xml)) {
         return null;
     }
     $dom = new DOMDocument();
     $dom->loadXML($xml);
     $info['shortname'] = self::get_node_value($dom, '/role/shortname');
     if (isset($info['shortname'])) {
         $info['shortname'] = strtolower(clean_param($info['shortname'], PARAM_ALPHANUMEXT));
     }
     $info['name'] = self::get_node_value($dom, '/role/name');
     if (isset($value)) {
         $info['name'] = clean_param($info['name'], PARAM_TEXT);
     }
     $info['description'] = self::get_node_value($dom, '/role/description');
     if (isset($value)) {
         $info['description'] = clean_param($info['description'], PARAM_CLEANHTML);
     }
     $info['archetype'] = self::get_node_value($dom, '/role/archetype');
     if (isset($value)) {
         $archetypes = get_role_archetypes();
         if (!isset($archetypes[$info['archetype']])) {
             $info['archetype'] = null;
         }
     }
     $values = self::get_node_children_values($dom, '/role/contextlevels', 'level');
     if (isset($values)) {
         $info['contextlevels'] = array();
         $levelmap = array_flip(context_helper::get_all_levels());
         foreach ($values as $value) {
             $level = 'context_' . $value;
             if (isset($levelmap[$level])) {
                 $cl = $levelmap[$level];
                 $info['contextlevels'][$cl] = $cl;
             }
         }
     }
     foreach (array('assign', 'override', 'switch') as $type) {
         $values = self::get_node_children_values($dom, '/role/allow' . $type, 'shortname');
         if (!isset($values)) {
             $info['allow' . $type] = null;
             continue;
         }
         $info['allow' . $type] = array();
         foreach ($values as $value) {
             if ($value === $info['shortname']) {
                 array_unshift($info['allow' . $type], -1);
                 // Means self.
             }
             if ($role = $DB->get_record('role', array('shortname' => $value))) {
                 $info['allow' . $type][] = $role->id;
                 continue;
             }
         }
     }
     $info['permissions'] = array();
     $values = self::get_node_children_values($dom, '/role/permissions', 'inherit');
     if (isset($values)) {
         foreach ($values as $value) {
             if ($value = clean_param($value, PARAM_CAPABILITY)) {
                 $info['permissions'][$value] = CAP_INHERIT;
             }
         }
     }
     $values = self::get_node_children_values($dom, '/role/permissions', 'allow');
     if (isset($values)) {
         foreach ($values as $value) {
             if ($value = clean_param($value, PARAM_CAPABILITY)) {
                 $info['permissions'][$value] = CAP_ALLOW;
             }
         }
     }
     $values = self::get_node_children_values($dom, '/role/permissions', 'prevent');
     if (isset($values)) {
         foreach ($values as $value) {
             if ($value = clean_param($value, PARAM_CAPABILITY)) {
                 $info['permissions'][$value] = CAP_PREVENT;
             }
         }
     }
     $values = self::get_node_children_values($dom, '/role/permissions', 'prohibit');
     if (isset($values)) {
         foreach ($values as $value) {
             if ($value = clean_param($value, PARAM_CAPABILITY)) {
                 $info['permissions'][$value] = CAP_PROHIBIT;
             }
         }
     }
     return $info;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:99,代码来源:preset.php


示例4: get_archetype_field

 protected function get_archetype_field($id)
 {
     $options = array();
     $options[''] = get_string('none');
     foreach (get_role_archetypes() as $type) {
         $options[$type] = get_string('archetype' . $type, 'role');
     }
     return html_writer::select($options, 'archetype', $this->role->archetype, false);
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:9,代码来源:lib.php


示例5: test_get_default_enrol_roles

 /**
  * Test default enrol roles.
  */
 public function test_get_default_enrol_roles()
 {
     $this->resetAfterTest();
     $course = $this->getDataGenerator()->create_course();
     $coursecontext = context_course::instance($course->id);
     $id2 = create_role('New student role', 'student2', 'New student description', 'student');
     set_role_contextlevels($id2, array(CONTEXT_COURSE));
     $allroles = get_all_roles();
     $expected = array($id2 => $allroles[$id2]);
     foreach (get_role_archetypes() as $archetype) {
         $defaults = get_default_contextlevels($archetype);
         if (in_array(CONTEXT_COURSE, $defaults)) {
             $roles = get_archetype_roles($archetype);
             foreach ($roles as $role) {
                 $expected[$role->id] = $role;
             }
         }
     }
     $roles = get_default_enrol_roles($coursecontext);
     foreach ($allroles as $role) {
         $this->assertEquals(isset($expected[$role->id]), isset($roles[$role->id]));
         if (isset($roles[$role->id])) {
             $this->assertSame(role_get_name($role, $coursecontext), $roles[$role->id]);
         }
     }
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:29,代码来源:accesslib_test.php


示例6: 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


示例7: admin_setting_heading

 //
 $settings->add(new admin_setting_heading('equella_lti_settings', ecs('lti.heading'), ecs('lti.help')));
 $settings->add(new admin_setting_configcheckbox('equella_enable_lti', ecs('enablelti'), ecs('enablelti.desc'), 0));
 $settings->add(new admin_setting_configtext('equella_lti_oauth_key', ecs('lti.key.title'), ecs('lti.key.help'), ''));
 $settings->add(new admin_setting_configtext('equella_lti_oauth_secret', ecs('lti.secret.title'), ecs('lti.secret.help'), ''));
 // ///////////////////////////////////////////////////////////////////////////////
 //
 // SHARED SECRETS
 //
 $settings->add(new admin_setting_heading('equella_sharedsecrets_settings', ecs('sharedsecrets.heading'), ecs('sharedsecrets.help')));
 $defaultvalue = '';
 $description = '';
 $settings->add(new equella_setting_left_heading('equella_default_group', ecs('group', ecs('group.default')), ''));
 $settings->add(new admin_setting_configtext('equella_shareid', ecs('sharedid.title'), $description, $defaultvalue));
 $settings->add(new admin_setting_configtext('equella_sharedsecret', ecs('sharedsecret.title'), $description, $defaultvalue));
 $rolearchetypes = get_role_archetypes();
 foreach (get_all_editing_roles() as $role) {
     $shortname = clean_param($role->shortname, PARAM_ALPHANUM);
     if (in_array($shortname, $rolearchetypes)) {
         $heading = ecs('group.' . $shortname);
     } else {
         $heading = ecs('group.noname', $shortname);
         if (!empty($role->name)) {
             $heading = ecs('group', $role->name);
         }
     }
     $sectionname = 'equella_' . $shortname . '_role_group';
     $settings->add(new equella_setting_left_heading($sectionname, $heading, ''));
     $settings->add(new admin_setting_configtext("equella_{$shortname}_shareid", ecs('sharedid.title'), $description, $defaultvalue, PARAM_TEXT));
     $settings->add(new admin_setting_configtext("equella_{$shortname}_sharedsecret", ecs('sharedsecret.title'), $description, $defaultvalue, PARAM_TEXT));
 }
开发者ID:CTANZ,项目名称:moodle-mod_equella,代码行数:31,代码来源:settings.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP get_role_contextlevels函数代码示例发布时间:2022-05-15
下一篇:
PHP get_role_access函数代码示例发布时间: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