当前位置: 首页>>代码示例>>PHP>>正文


PHP reset_role_capabilities函数代码示例

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


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

示例1: xmldb_block_demostudent_install

/**
 * @package block
 * @subpackage demostudent
 * @author Dominik Royko royko@ualberta.ca
 */
function xmldb_block_demostudent_install()
{
    global $DB;
    $result = true;
    $systemcontext = context_system::instance();
    // Create DemoStudent role.
    $contextlevels = array(CONTEXT_COURSE, CONTEXT_MODULE);
    if (!($demostudentrole = $DB->get_record('role', array('shortname' => 'demostudent')))) {
        if ($roleid = create_role(get_string('roledemostudentname', 'block_demostudent'), 'demostudent', get_string('roledemostudentdescription', 'block_demostudent'), 'student')) {
            $newrole = new stdClass();
            $newrole->id = $roleid;
            // Set the capabilities to the archetype (student).
            // Caution: new capabilities un/set here can get clobbered by 'clonepermissionsfrom',
            // defined in access.php.
            reset_role_capabilities($roleid);
            // DemoStudent needs to see the DemoStudent block.
            $result = $result && assign_capability('block/demostudent:seedemostudentblock', CAP_ALLOW, $newrole->id, $systemcontext->id);
            // DemoStudent should be able to see hidden courses to facilitate testing.
            $result = $result && assign_capability('moodle/course:viewhiddencourses', CAP_ALLOW, $newrole->id, $systemcontext->id);
            // DemoStudent should NOT be able to add more demostudents!
            $result = $result && unassign_capability('block/demostudent:addinstance', $newrole->id);
            $systemcontext->mark_dirty();
            set_role_contextlevels($newrole->id, $contextlevels);
        } else {
            $result = false;
        }
    }
    return $result;
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:34,代码来源:install.php

示例2: test_reset_role_capabilities

 /**
  * Tests reset_role_capabilities function.
  */
 public function test_reset_role_capabilities()
 {
     global $DB;
     $this->resetAfterTest(true);
     $generator = $this->getDataGenerator();
     // Create test course and user, enrol one in the other.
     $course = $generator->create_course();
     $user = $generator->create_user();
     $roleid = $DB->get_field('role', 'id', array('shortname' => 'student'), MUST_EXIST);
     $generator->enrol_user($user->id, $course->id, $roleid);
     // Change student role so it DOES have 'mod/forum:addinstance'.
     $systemcontext = context_system::instance();
     assign_capability('mod/forum:addinstance', CAP_ALLOW, $roleid, $systemcontext->id);
     // Override course so it does NOT allow students 'mod/forum:viewdiscussion'.
     $coursecontext = context_course::instance($course->id);
     assign_capability('mod/forum:viewdiscussion', CAP_PREVENT, $roleid, $coursecontext->id);
     // Check expected capabilities so far.
     $this->assertTrue(has_capability('mod/forum:addinstance', $coursecontext, $user));
     $this->assertFalse(has_capability('mod/forum:viewdiscussion', $coursecontext, $user));
     // Oops, allowing student to add forums was a mistake, let's reset the role.
     reset_role_capabilities($roleid);
     // Check new expected capabilities - role capabilities should have been reset,
     // while the override at course level should remain.
     $this->assertFalse(has_capability('mod/forum:addinstance', $coursecontext, $user));
     $this->assertFalse(has_capability('mod/forum:viewdiscussion', $coursecontext, $user));
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:29,代码来源:accesslib_test.php

示例3: xmldb_main_upgrade


//.........这里部分代码省略.........
        upgrade_main_savepoint($result, 2007012101);
    }
    if ($result && $oldversion < 2007012400) {
        /// Rename field access on table mnet_sso_access_control to accessctrl
        $table = new XMLDBTable('mnet_sso_access_control');
        $field = new XMLDBField('access');
        $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'allow', 'mnet_host_id');
        /// Launch rename field accessctrl
        $result = $result && rename_field($table, $field, 'accessctrl');
        upgrade_main_savepoint($result, 2007012400);
    }
    if ($result && $oldversion < 2007012500) {
        execute_sql("DELETE FROM {$CFG->prefix}user WHERE username='changeme'", true);
        upgrade_main_savepoint($result, 2007012500);
    }
    if ($result && $oldversion < 2007020400) {
        /// Only for MySQL and PG, declare the user->ajax field as not null. MDL-8421.
        if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
            /// Changing nullability of field ajax on table user to not null
            $table = new XMLDBTable('user');
            $field = new XMLDBField('ajax');
            $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'htmleditor');
            /// Launch change of nullability for field ajax
            $result = $result && change_field_notnull($table, $field);
        }
        upgrade_main_savepoint($result, 2007020400);
    }
    if (!empty($CFG->rolesactive) && $result && $oldversion < 2007021401) {
        /// create default logged in user role if not present - upgrade rom 1.7.x
        if (empty($CFG->defaultuserroleid) or empty($CFG->guestroleid) or $CFG->defaultuserroleid == $CFG->guestroleid) {
            if (!get_records('role', 'shortname', 'user')) {
                $userroleid = create_role(addslashes(get_string('authenticateduser')), 'user', addslashes(get_string('authenticateduserdescription')), 'moodle/legacy:user');
                if ($userroleid) {
                    reset_role_capabilities($userroleid);
                    set_config('defaultuserroleid', $userroleid);
                }
            }
        }
        upgrade_main_savepoint($result, 2007021401);
    }
    if ($result && $oldversion < 2007021501) {
        /// delete removed setting from config
        unset_config('tabselectedtofront');
        upgrade_main_savepoint($result, 2007021501);
    }
    if ($result && $oldversion < 2007032200) {
        /// Define table role_sortorder to be created
        $table = new XMLDBTable('role_sortorder');
        /// Adding fields to table role_sortorder
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('sortoder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
        /// Adding keys to table role_sortorder
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
        $table->addKeyInfo('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
        $table->addKeyInfo('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
        /// Adding indexes to table role_sortorder
        $table->addIndexInfo('userid-roleid-contextid', XMLDB_INDEX_UNIQUE, array('userid', 'roleid', 'contextid'));
        /// Launch create table for role_sortorder
        $result = $result && create_table($table);
        upgrade_main_savepoint($result, 2007032200);
    }
    /// code to change lenghen tag field to 255, MDL-9095
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:67,代码来源:upgrade.php

示例4: get_string

                $warning = get_string('resetrolesurenolegacy', 'role', $a);
            } else {
                $warning = get_string('resetrolesure', 'role', $a);
            }
            $formcontinue = new single_button(new moodle_url('manage.php', $optionsyes), get_string('yes'));
            $formcancel = new single_button(new moodle_url('manage.php', $optionsno), get_string('no'), 'get');
            echo $OUTPUT->confirm($warning, $formcontinue, $formcancel);
            echo $OUTPUT->footer();
            die;
        }
        // Reset context levels for standard archetypes
        if ($roles[$roleid]->archetype) {
            set_role_contextlevels($roleid, get_default_contextlevels($roles[$roleid]->archetype));
        }
        //reset or delete the capabilities
        reset_role_capabilities($roleid);
        // Mark context dirty, log and redirect.
        mark_context_dirty($systemcontext->path);
        add_to_log(SITEID, 'role', 'reset', 'admin/roles/manage.php?action=reset&roleid=' . $roleid, $roles[$roleid]->localname, '', $USER->id);
        redirect($defineurl . '?action=view&roleid=' . $roleid);
        break;
}
/// Print the page header and tabs.
echo $OUTPUT->header();
$currenttab = 'manage';
include_once 'managetabs.php';
/// Initialise table.
$table = new html_table();
$table->colclasses = array('leftalign', 'leftalign', 'leftalign', 'leftalign');
$table->id = 'roles';
$table->attributes['class'] = 'admintable generaltable';
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:31,代码来源:manage.php

示例5: tao_reset_capabilities

/**
* same as tao_reassign_capabilities except removes existing custom capabilities.
*
* note: there are some safety checks to ensure only custom roles are affected.
*/
function tao_reset_capabilities($path = 'local')
{
    global $CFG;
    if (!get_site()) {
        // not finished installing, skip
        return true;
    }
    // look for a matrix of role/capability definitions and make sure we have them all
    $cappath = $CFG->dirroot . '/' . $path . '/capabilities.php';
    if (!file_exists($cappath)) {
        debugging("Local caps reassignment called with invalid path {$path}");
        return false;
    }
    require_once $cappath;
    $caps = get_custom_capabilities();
    if (!isset($caps)) {
        return true;
        // nothing to do.
    }
    $adminroles = get_admin_roles();
    foreach ($caps as $shortname => $caparray) {
        // get the roleid
        $role = get_record('role', 'shortname', $shortname);
        // don't mess with non-custom roles!
        if (!$role->custom == 1) {
            continue;
        }
        // extra safety: whatever we do - don't mess with the admin role!!!
        if (isset($adminroles[$role->id]) || $shortname == 'admin') {
            continue;
        }
        // reset capabilities on this role - this will reset to legacy role settings
        reset_role_capabilities($role->id);
    }
    // now reapply the custom capabilities
    return tao_reassign_capabilities($path);
}
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:42,代码来源:tao.php

示例6: xmldb_main_upgrade


//.........这里部分代码省略.........
        $field = new XMLDBField('lang');
        $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'en', 'country');
        /// Launch change of precision for field user->lang
        $result = $result && change_field_precision($table, $field);
    }
    if ($result && $oldversion < 2007012400) {
        /// Rename field access on table mnet_sso_access_control to accessctrl
        $table = new XMLDBTable('mnet_sso_access_control');
        $field = new XMLDBField('access');
        $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'allow', 'mnet_host_id');
        /// Launch rename field accessctrl
        $result = $result && rename_field($table, $field, 'accessctrl');
    }
    if ($result && $oldversion < 2007012500) {
        execute_sql("DELETE FROM {$CFG->prefix}user WHERE username='changeme'", true);
    }
    if ($result && $oldversion < 2007020400) {
        /// Only for MySQL and PG, declare the user->ajax field as not null. MDL-8421.
        if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
            /// Changing nullability of field ajax on table user to not null
            $table = new XMLDBTable('user');
            $field = new XMLDBField('ajax');
            $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'htmleditor');
            /// Launch change of nullability for field ajax
            $result = $result && change_field_notnull($table, $field);
        }
    }
    if (!empty($CFG->rolesactive) && $result && $oldversion < 2007021401) {
        /// create default logged in user role if not present - upgrade rom 1.7.x
        if (empty($CFG->defaultuserroleid) or empty($CFG->guestroleid) or $CFG->defaultuserroleid == $CFG->guestroleid) {
            if (!get_records('role', 'shortname', 'user')) {
                $userroleid = create_role(addslashes(get_string('authenticateduser')), 'user', addslashes(get_string('authenticateduserdescription')), 'moodle/legacy:user');
                if ($userroleid) {
                    reset_role_capabilities($userroleid);
                    set_config('defaultuserroleid', $userroleid);
                }
            }
        }
    }
    if ($result && $oldversion < 2007021501) {
        /// delete removed setting from config
        unset_config('tabselectedtofront');
    }
    /* Changes to the custom profile menu type - store values rather than indices.
       We could do all this with one tricky SQL statement but it's a one-off so no
       harm in using PHP loops */
    if ($result && $oldversion < 2007021503) {
        /// Get the menu fields
        if ($fields = get_records('user_info_field', 'datatype', 'menu')) {
            foreach ($fields as $field) {
                /// Get user data for the menu field
                if ($data = get_records('user_info_data', 'fieldid', $field->id)) {
                    /// Get the menu options
                    $options = explode("\n", $field->param1);
                    foreach ($data as $d) {
                        $key = array_search($d->data, $options);
                        /// If the data is an integer and is not one of the options,
                        /// set the respective option value
                        if (is_int($d->data) and ($key === NULL or $key === false) and isset($options[$d->data])) {
                            $d->data = $options[$d->data];
                            $result = $result && update_record('user_info_data', $d);
                        }
                    }
                }
            }
        }
开发者ID:veritech,项目名称:pare-project,代码行数:67,代码来源:upgrade.php


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