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

PHP set_role_contextlevels函数代码示例

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

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



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

示例1: xmldb_block_roomscheduler_upgrade

/**
 *
 * @since 2.0
 * @package blocks
 * @copyright 2011 Dustin Durand
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function xmldb_block_roomscheduler_upgrade($oldversion)
{
    global $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2011150301) {
        $timenow = time();
        $sysctx = get_context_instance(CONTEXT_SYSTEM);
        /// Fully setup the Elluminate Moderator role.
        if (!($mrole = $DB->get_record('role', array('shortname' => 'roomschedulermanager')))) {
            if ($rid = create_role(get_string('roomschedulermanager', 'block_roomscheduler'), 'roomschedulemanager', get_string('roomschedulermanagerdescription', 'block_roomscheduler'))) {
                $mrole = $DB->get_record('role', array('id' => $rid));
                assign_capability('block/roomscheduler:manage', CAP_ALLOW, $mrole->id, $sysctx->id);
                set_role_contextlevels($mrole->id, array(CONTEXT_SYSTEM));
            } else {
                $mrole = $DB->get_record('role', array('shortname' => 'roomschedulermanager'));
                set_role_contextlevels($mrole->id, array(CONTEXT_SYSTEM));
            }
        }
        upgrade_block_savepoint(true, 2011150301, 'roomscheduler');
    }
    if ($oldversion < 2011140315) {
        // Define field reservable to be added to roomscheduler_rooms
        $table = new xmldb_table('roomscheduler_rooms');
        $field = new xmldb_field('reservable', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'active');
        // Conditionally launch add field reservable
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_block_savepoint(true, 2011140315, 'roomscheduler');
    }
    return true;
}
开发者ID:nadavkav,项目名称:Moodle2-Hebrew-plugins,代码行数:39,代码来源:upgrade.php


示例2: xmldb_block_demostudent_install

/**
 * @package block
 * @subpackage demostudent
 * @author Dominik Royko [email protected]
 */
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


示例3: create_test_role

 /**
  * Create a test role
  *
  * @param string $name The role's display name
  * @param string $shortname The role's shortname
  * @param string $description The role's description
  * @param array $contexts The contexts at which the role should be assignable (defaults to course.
  * @return int The created role's id
  */
 private static function create_test_role($name = 'coursename', $shortname = 'courseshortname', $description = 'coursedescription', $contexts = null)
 {
     if ($contexts === null) {
         // Use default of course context.
         $contexts = array(CONTEXT_COURSE);
     }
     $roleid = create_role($name, $shortname, $description);
     set_role_contextlevels($roleid, $contexts);
     return $roleid;
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:19,代码来源:version1_enrolment_import_test.php


示例4: test_block_elisadmin_load_menu_children_course

 /**
  * Test block_elisadmin_load_menu_children_course function.
  */
 public function test_block_elisadmin_load_menu_children_course()
 {
     global $DB, $USER;
     accesslib_clear_all_caches(true);
     // Create test user - ensure the returned user is NOT a site admin. if they are, our capability restrictions won't work.
     $testuser = new user();
     $testuser->username = 'testELIS4093';
     $testuser->idnumber = 'testELIS4093';
     $testuser->firstname = 'testELIS4093';
     $testuser->lastname = 'testELIS4093';
     $testuser->email = '[email protected]';
     $testuser->country = 'CA';
     $testuser->save();
     $testmuser = $testuser->get_moodleuser();
     // Create role with cap: 'local/elisprogram:class_view'.
     $testrole = new stdClass();
     $testrole->name = 'ELIS Class View';
     $testrole->shortname = '_test_ELIS_4093';
     $testrole->description = 'ELIS Class View';
     $testrole->archetype = '';
     $testrole->id = create_role($testrole->name, $testrole->shortname, $testrole->description, $testrole->archetype);
     // Ensure our new role is assignable to ELIS class contexts.
     set_role_contextlevels($testrole->id, array(CONTEXT_ELIS_CLASS));
     // Ensure the role has our required capability assigned.
     $sitecontext = context_system::instance();
     assign_capability('local/elisprogram:class_view', CAP_ALLOW, $testrole->id, $sitecontext->id, true);
     $sitecontext->mark_dirty();
     // Create ELIS Course Description.
     $testcrs = new course(array('name' => 'CD-ELIS-4093', 'idnumber' => 'CDELIS4093', 'syllabus' => ''));
     $testcrs->save();
     $testcrs->load();
     // Create three(3) Class Instances for Course Descrption.
     $testcls1 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.1'));
     $testcls1->save();
     $testcls1->load();
     $testcls2 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.2'));
     $testcls2->save();
     $testcls2->load();
     $testcls3 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.3'));
     $testcls3->save();
     $testcls3->load();
     // Assign testuser new role in one Class Instance.
     $context = \local_elisprogram\context\pmclass::instance($testcls2->id);
     role_assign($testrole->id, $testmuser->id, $context->id);
     // Switch to testuser.
     $USER = $testmuser;
     $this->setUser($testmuser);
     $items = block_elisadmin_load_menu_children_course($testcrs->id, 0, 0, 5, '');
     $this->assertEquals(1, count($items));
     $this->assertTrue($items[0]->name == 'pmclass_2');
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:54,代码来源:block_elisadmin_test.php


示例5: xmldb_block_roomscheduler_install

function xmldb_block_roomscheduler_install()
{
    global $DB;
    $timenow = time();
    $sysctx = get_context_instance(CONTEXT_SYSTEM);
    /// Fully setup the Elluminate Moderator role.
    if (!($mrole = $DB->get_record('role', array('shortname' => 'roomschedulermanager')))) {
        if ($rid = create_role(get_string('roomschedulermanager', 'block_roomscheduler'), 'roomschedulemanager', get_string('roomschedulermanagerdescription', 'block_roomscheduler'))) {
            $mrole = $DB->get_record('role', array('id' => $rid));
            assign_capability('block/roomscheduler:manage', CAP_ALLOW, $mrole->id, $sysctx->id);
            //Only assignable at system level
            set_role_contextlevels($mrole->id, array(CONTEXT_SYSTEM));
        } else {
            $mrole = $DB->get_record('role', array('shortname' => 'roomschedulermanager'));
            set_role_contextlevels($mrole->id, array(CONTEXT_SYSTEM));
        }
    }
}
开发者ID:nadavkav,项目名称:Moodle2-Hebrew-plugins,代码行数:18,代码来源:install.php


示例6: xmldb_enrol_category_install

function xmldb_enrol_category_install()
{
    global $CFG, $DB;
    if (!$DB->record_exists_select('role_assignments', "contextid IN (SELECT id FROM {context} WHERE contextlevel = ?)", array(CONTEXT_COURSECAT))) {
        // fresh install or nobody used category enrol
        return;
    }
    // existing sites need a way to keep category role enrols, but we do not want to encourage that on new sites
    // extremely ugly hack, the sync depends on the capabilities so we unfortunately force update of caps here
    // note: this is not officially supported and should not be copied elsewhere! :-(
    update_capabilities('enrol_category');
    $syscontext = get_context_instance(CONTEXT_SYSTEM);
    $archetypes = array('student', 'teacher', 'editingteacher');
    $enableplugin = false;
    foreach ($archetypes as $archetype) {
        $roles = get_archetype_roles($archetype);
        foreach ($roles as $role) {
            if (!$DB->record_exists_select('role_assignments', "roleid = ? AND contextid IN (SELECT id FROM {context} WHERE contextlevel = ?)", array($role->id, CONTEXT_COURSECAT))) {
                continue;
            }
            assign_capability('enrol/category:synchronised', CAP_ALLOW, $role->id, $syscontext->id, true);
            $levels = get_role_contextlevels($role->id);
            $levels[] = CONTEXT_COURSECAT;
            set_role_contextlevels($role->id, $levels);
            $enableplugin = true;
        }
    }
    if (!$enableplugin) {
        return;
    }
    // enable this plugin
    $enabledplugins = explode(',', $CFG->enrol_plugins_enabled);
    $enabledplugins[] = 'category';
    $enabledplugins = array_unique($enabledplugins);
    set_config('enrol_plugins_enabled', implode(',', $enabledplugins));
    // brute force course resync, this may take a while
    require_once "{$CFG->dirroot}/enrol/category/locallib.php";
    enrol_category_sync_full();
}
开发者ID:vuchannguyen,项目名称:web,代码行数:39,代码来源:install.php


示例7: xmldb_adobeconnect_install

/**
 * @package mod
 * @subpackage adobeconnect
 * @author Akinsaya Delamarre ([email protected])
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function xmldb_adobeconnect_install()
{
    global $DB;
    // The commented out code is waiting for a fix for MDL-25709
    $result = true;
    $timenow = time();
    $sysctx = get_context_instance(CONTEXT_SYSTEM);
    $mrole = new stdClass();
    $levels = array(CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_MODULE);
    $param = array('shortname' => 'coursecreator');
    $coursecreatorrid = $DB->get_record('role', $param);
    $param = array('shortname' => 'editingteacher');
    $editingteacherrid = $DB->get_record('role', $param);
    $param = array('shortname' => 'teacher');
    $teacherrid = $DB->get_record('role', $param);
    /// Fully setup the Adobe Connect Presenter role.
    $param = array('shortname' => 'adobeconnectpresenter');
    if (!($mrole = $DB->get_record('role', $param))) {
        if ($rid = create_role(get_string('adobeconnectpresenter', 'adobeconnect'), 'adobeconnectpresenter', get_string('adobeconnectpresenterdescription', 'adobeconnect'), 'adobeconnectpresenter')) {
            $mrole->id = $rid;
            $result = assign_capability('mod/adobeconnect:meetingpresenter', CAP_ALLOW, $mrole->id, $sysctx->id);
            set_role_contextlevels($mrole->id, $levels);
        } else {
            $result = false;
        }
    }
    $param = array('allowassign' => $mrole->id, 'roleid' => $coursecreatorrid->id);
    if (!$DB->get_record('role_allow_assign', $param)) {
        $result = allow_assign($coursecreatorrid->id, $mrole->id);
    }
    $param = array('allowassign' => $mrole->id, 'roleid' => $editingteacherrid->id);
    if (!$DB->get_record('role_allow_assign', $param)) {
        $result = allow_assign($editingteacherrid->id, $mrole->id);
    }
    $param = array('allowassign' => $mrole->id, 'roleid' => $teacherrid->id);
    if (!$DB->get_record('role_allow_assign', $param)) {
        $result = allow_assign($teacherrid->id, $mrole->id);
    }
    /// Fully setup the Adobe Connect Participant role.
    $param = array('shortname' => 'adobeconnectparticipant');
    if (!($mrole = $DB->get_record('role', $param))) {
        if ($rid = create_role(get_string('adobeconnectparticipant', 'adobeconnect'), 'adobeconnectparticipant', get_string('adobeconnectparticipantdescription', 'adobeconnect'), 'adobeconnectparticipant')) {
            $mrole->id = $rid;
            $result = assign_capability('mod/adobeconnect:meetingparticipant', CAP_ALLOW, $mrole->id, $sysctx->id);
            set_role_contextlevels($mrole->id, $levels);
        } else {
            $result = false;
        }
    }
    $param = array('allowassign' => $mrole->id, 'roleid' => $coursecreatorrid->id);
    if (!$DB->get_record('role_allow_assign', $param)) {
        $result = allow_assign($coursecreatorrid->id, $mrole->id);
    }
    $param = array('allowassign' => $mrole->id, 'roleid' => $editingteacherrid->id);
    if (!$DB->get_record('role_allow_assign', $param)) {
        $result = allow_assign($editingteacherrid->id, $mrole->id);
    }
    $param = array('allowassign' => $mrole->id, 'roleid' => $teacherrid->id);
    if (!$DB->get_record('role_allow_assign', $param)) {
        $result = allow_assign($teacherrid->id, $mrole->id);
    }
    /// Fully setup the Adobe Connect Host role.
    $param = array('shortname' => 'adobeconnecthost');
    if (!($mrole = $DB->get_record('role', $param))) {
        if ($rid = create_role(get_string('adobeconnecthost', 'adobeconnect'), 'adobeconnecthost', get_string('adobeconnecthostdescription', 'adobeconnect'), 'adobeconnecthost')) {
            $mrole->id = $rid;
            $result = assign_capability('mod/adobeconnect:meetinghost', CAP_ALLOW, $mrole->id, $sysctx->id);
            set_role_contextlevels($mrole->id, $levels);
        } else {
            $result = false;
        }
    }
    $param = array('allowassign' => $mrole->id, 'roleid' => $coursecreatorrid->id);
    if (!$DB->get_record('role_allow_assign', $param)) {
        $result = allow_assign($coursecreatorrid->id, $mrole->id);
    }
    $param = array('allowassign' => $mrole->id, 'roleid' => $editingteacherrid->id);
    if (!$DB->get_record('role_allow_assign', $param)) {
        $result = allow_assign($editingteacherrid->id, $mrole->id);
    }
    $param = array('allowassign' => $mrole->id, 'roleid' => $teacherrid->id);
    if (!$DB->get_record('role_allow_assign', $param)) {
        $result = allow_assign($teacherrid->id, $mrole->id);
    }
    return $result;
}
开发者ID:number33,项目名称:moodle-mod_adobeconnect,代码行数:92,代码来源:install.php


示例8: create_test_role

 /**
  * Creates a test role, assignable at all necessary context levels
  *
  * @param string $fullname The new role's fullname
  * @param string $shortname The new role's shortname
  * @param string $description The new role's description
  * @return int The database record id of the created course
  */
 private function create_test_role($fullname = 'rlipfullname', $shortname = 'rlipshortname', $description = 'rlipdescription')
 {
     // Create the role.
     $roleid = create_role($fullname, $shortname, $description);
     // Make it assignable at all necessary contexts.
     $contexts = array(CONTEXT_COURSE, CONTEXT_COURSECAT, CONTEXT_USER, CONTEXT_SYSTEM);
     set_role_contextlevels($roleid, $contexts);
     return $roleid;
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:17,代码来源:version1elis_filesystem_logging_test.php


示例9: test_version1createorupdatedoesnotcreateenrolmentfromupdateaction

 /**
  * Validate that when the "create or update" flag is enabled, update
  * actions can not create enrolments
  */
 public function test_version1createorupdatedoesnotcreateenrolmentfromupdateaction()
 {
     global $DB;
     // Set up initial conditions.
     set_config('createorupdate', 1, 'dhimport_version1');
     // Initial data setup.
     $userid = $this->create_test_user();
     $courseid = $this->create_test_course();
     $context = context_course::instance($courseid);
     $roleid = create_role('rlipname', 'rlipshortname', 'rlipdescription');
     set_role_contextlevels($roleid, array(CONTEXT_COURSE));
     // Validate that updates are not converted to creates for enrolments.
     $importdata = array('entity' => 'enrolment', 'action' => 'update', 'username' => 'rlipusername', 'context' => 'course', 'instance' => 'rlipshortname', 'role' => 'rlipshortname');
     $this->run_core_enrolment_import($importdata);
     $this->assertEquals($DB->count_records('role_assignments'), 0);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:20,代码来源:version1_createorupdate_test.php


示例10: test_pm_get_select_roles

 /**
  * Method to test function /local/elisprogram/lib/lib.php::pm_get_select_roles_for_contexts()
  * part of ELIS-8341
  * @param array $testroles array of role 'objects' to create
  * @param array $passedcontexts  array of contexts to pass to function under  test
  * @param array $expectedresults associative array of selectable roles: roleshortname => rolename
  * @uses $DB
  * @dataProvider pm_get_select_roles_data_provider
  */
 public function test_pm_get_select_roles($testroles, $passedcontexts, $expectedresults)
 {
     global $DB;
     $id2shortname = array();
     // Create specified roles.
     foreach ($testroles as $testrole) {
         $roleid = create_role($testrole['name'], $testrole['shortname'], 'Default role description');
         // Assign role capabilities.
         foreach ($testrole['caps'] as $cap => $perm) {
             assign_capability($cap, $perm, $roleid, 1, true);
         }
         // Create assignable contexts array & assign.
         $contexts = array();
         foreach ($testrole['contexts'] as $contextlevel) {
             $contexts[$contextlevel] = $contextlevel;
         }
         set_role_contextlevels($roleid, $contexts);
         // Save roleid for later conversion.
         $id2shortname[$roleid] = $testrole['shortname'];
     }
     // Call test function.
     $results = array();
     pm_get_select_roles_for_contexts($results, $passedcontexts);
     // Convert roleid to roleshortname to validate.
     foreach ($results as $id => $name) {
         if (isset($id2shortname[$id])) {
             $results[$id2shortname[$id]] = $name;
         }
         unset($results[$id]);
     }
     $this->assertEquals($expectedresults, $results);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:41,代码来源:roles_test.php


示例11: xmldb_main_upgrade


//.........这里部分代码省略.........
        if (isset($roleids['coursecreator'])) {
            $rolecontextlevels[$roleids['coursecreator']] = get_default_contextlevels('coursecreator');
        }
        if (isset($roleids['editingteacher'])) {
            $rolecontextlevels[$roleids['editingteacher']] = get_default_contextlevels('editingteacher');
        }
        if (isset($roleids['teacher'])) {
            $rolecontextlevels[$roleids['teacher']] = get_default_contextlevels('teacher');
        }
        if (isset($roleids['student'])) {
            $rolecontextlevels[$roleids['student']] = get_default_contextlevels('student');
        }
        if (isset($roleids['guest'])) {
            $rolecontextlevels[$roleids['guest']] = get_default_contextlevels('guest');
        }
        if (isset($roleids['user'])) {
            $rolecontextlevels[$roleids['user']] = get_default_contextlevels('user');
        }
        /// See what other role assignments are in this database, extend the allowed
        /// lists to allow them too.
        $existingrolecontextlevels = $DB->get_recordset_sql('SELECT DISTINCT ra.roleid, con.contextlevel FROM
                {role_assignments} ra JOIN {context} con ON ra.contextid = con.id');
        foreach ($existingrolecontextlevels as $rcl) {
            if (!isset($rolecontextlevels[$rcl->roleid])) {
                $rolecontextlevels[$rcl->roleid] = array($rcl->contextlevel);
            } else {
                if (!in_array($rcl->contextlevel, $rolecontextlevels[$rcl->roleid])) {
                    $rolecontextlevels[$rcl->roleid][] = $rcl->contextlevel;
                }
            }
        }
        /// Put the data into the database.
        foreach ($rolecontextlevels as $roleid => $contextlevels) {
            set_role_contextlevels($roleid, $contextlevels);
        }
        /// Main savepoint reached
        upgrade_main_savepoint($result, 2008110602);
    }
    /// Remove any role overrides for moodle/site:doanything, or any permissions
    /// for it in a role without legacy:admin.
    if ($result && $oldversion < 2008110603) {
        $systemcontext = get_context_instance(CONTEXT_SYSTEM);
        // Remove all overrides.
        $DB->delete_records_select('role_capabilities', 'capability = ? AND contextid <> ?', array('moodle/site:doanything', $systemcontext->id));
        // Get the ids of all the roles that are moodle/legacy:admin.
        $adminroleids = $DB->get_records_menu('role_capabilities', array('capability' => 'moodle/legacy:admin', 'permission' => 1, 'contextid' => $systemcontext->id), '', 'id, roleid');
        // Remove moodle/site:doanything from all other roles.
        list($notroletest, $params) = $DB->get_in_or_equal($adminroleids, SQL_PARAMS_QM, '', false);
        $DB->delete_records_select('role_capabilities', "roleid {$notroletest} AND capability = ? AND contextid = ?", array_merge($params, array('moodle/site:doanything', $systemcontext->id)));
        // Ensure that for all admin-y roles, the permission for moodle/site:doanything is 1
        list($isroletest, $params) = $DB->get_in_or_equal($adminroleids);
        $DB->set_field_select('role_capabilities', 'permission', 1, "roleid {$isroletest} AND capability = ? AND contextid = ?", array_merge($params, array('moodle/site:doanything', $systemcontext->id)));
        // And for any admin-y roles where moodle/site:doanything is not set, set it.
        $doanythingroleids = $DB->get_records_menu('role_capabilities', array('capability' => 'moodle/site:doanything', 'permission' => 1, 'contextid' => $systemcontext->id), '', 'id, roleid');
        foreach ($adminroleids as $roleid) {
            if (!in_array($roleid, $doanythingroleids)) {
                $rc = new stdClass();
                $rc->contextid = $systemcontext->id;
                $rc->roleid = $roleid;
                $rc->capability = 'moodle/site:doanything';
                $rc->permission = 1;
                $rc->timemodified = time();
                $DB->insert_record('role_capabilities', $rc);
            }
        }
        /// Main savepoint reached
开发者ID:ajv,项目名称:Offline-Caching,代码行数:67,代码来源:upgrade.php


示例12: array

$user = $DB->get_record('user', array('username' => 'testtete'));
if (!$user) {
    $user = new stdClass();
    $user->username = 'testtete';
    $user->firstname = 'Web';
    $user->lastname = 'Service';
    $user->password = 'test';
    $dg = new testing_data_generator();
    $user = $dg->create_user($user);
}
// Create a role for Web Services with all permissions.
if (!($roleid = $DB->get_field('role', 'id', array('shortname' => 'testtete')))) {
    $roleid = create_role('Web Service', 'testtete', 'MDK: All permissions given by default.', '');
}
$context = context_system::instance();
set_role_contextlevels($roleid, array($context->contextlevel));
role_assign($roleid, $user->id, $context->id);
if (method_exists($context, 'get_capabilities')) {
    $capabilities = $context->get_capabilities();
} else {
    $capabilities = fetch_context_capabilities($context);
}
foreach ($capabilities as $capability) {
    assign_capability($capability->name, CAP_ALLOW, $roleid, $context->id, true);
}
$context->mark_dirty();
// Create a new service with all functions for the user.
$webservicemanager = new webservice();
if (!($service = $DB->get_record('external_services', array('shortname' => 'mdk_all')))) {
    $service = new stdClass();
    $service->name = 'MDK: All functions';
开发者ID:junpataleta,项目名称:mdk,代码行数:31,代码来源:webservices.php


示例13: save_changes

 public function save_changes()
 {
     global $DB;
     if (!$this->roleid) {
         // Creating role
         $this->role->id = create_role($this->role->name, $this->role->shortname, $this->role->description, $this->role->archetype);
         $this->roleid = $this->role->id;
         // Needed to make the parent::save_changes(); call work.
     } else {
         // Updating role
         $DB->update_record('role', $this->role);
     }
     // Assignable contexts.
     set_role_contextlevels($this->role->id, $this->contextlevels);
     // Permissions.
     parent::save_changes();
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:17,代码来源:lib.php


示例14: tao_reset_custom_roles


//.........这里部分代码省略.........
function tao_reset_custom_roles($path = 'local')
{
    global $CFG;
    if (!get_site()) {
        // not finished installing, skip
        return true;
    }
    // get latest role definition from roles file
    $rolespath = $CFG->dirroot . '/' . $path . '/roles.php';
    if (!file_exists($rolespath)) {
        debugging("Local caps reassignment called with invalid path {$path}");
        return false;
    }
    require_once $rolespath;
    if (!isset($customroles)) {
        return true;
        // nothing to do.
    }
    $undeletableroles = array();
    $undeletableroles[$CFG->notloggedinroleid] = 1;
    $undeletableroles[$CFG->guestroleid] = 1;
    $undeletableroles[$CFG->defaultuserroleid] = 1;
    $undeletableroles[$CFG->defaultcourseroleid] = 1;
    // If there is only one admin role, add that to $undeletableroles too.
    $adminroles = get_admin_roles();
    if (count($adminroles) == 1) {
        $undeletableroles[reset($adminroles)->id] = 1;
    }
    // get recordset of existing custom roles
    $sql = "SELECT id, name, shortname, description, sortorder, custom\n              FROM {$CFG->prefix}role\n              WHERE custom IS NOT NULL";
    $roles = get_records_sql($sql);
    // remove custom roles that are not in the latest definition
    foreach ($roles as $role) {
        // check whether this role is in the latest definition
        if (array_key_exists($role->shortname, $customroles)) {
            continue;
        }
        // extra safety: check undeletable roles
        if (isset($undeletableroles[$role->id])) {
            continue;
        }
        delete_role($role->id);
    }
    // hack to avoid sortorder unique constraint
    execute_sql("UPDATE {$CFG->prefix}role SET sortorder = (sortorder+1000) WHERE custom IS NOT NULL");
    // set sortorder to current highest value
    $sortorder = get_field_sql("SELECT " . sql_max('sortorder') . " FROM {$CFG->prefix}role WHERE custom IS NULL");
    // now loop through the new settings
    foreach ($customroles as $shortname => $role) {
        $sortorder++;
        // get the roleid
        $roleid = get_field('role', 'id', 'shortname', $shortname);
        // if exists then make updates
        if (!empty($roleid)) {
            // only update fields that have been set
            if (isset($role['name'])) {
                set_field('role', 'name', $role['name'], 'shortname', $shortname);
            }
            if (isset($role['description'])) {
                set_field('role', 'description', $role['description'], 'shortname', $shortname);
            }
            // reset sortorder
            set_field('role', 'sortorder', $sortorder, 'shortname', $shortname);
            // else create record
        } else {
            $newrole = new stdclass();
            $newrole->name = $role['name'];
            $newrole->shortname = $shortname;
            $newrole->description = $role['description'];
            $newrole->sortorder = $sortorder;
            $newrole->custom = 1;
            $roleid = insert_record('role', $newrole);
        }
        // remove any previously set legacy roles
        $legacyroles = get_legacy_roles();
        foreach ($legacyroles as $ltype => $lcap) {
            unassign_capability($lcap, $roleid);
        }
        // reset legacy role
        if (isset($role['legacy'])) {
            $legacycap = $legacyroles[$role['legacy']];
            $context = get_context_instance(CONTEXT_SYSTEM);
            assign_capability($legacycap, CAP_ALLOW, $roleid, $context->id);
        }
        // update the context settings
        set_role_contextlevels($roleid, $role['context']);
        //  e.g. array(CONTEXT_SYSTEM, CONTEXT_COURSECAT)
        // set allow assigns
        if (is_array($role['canassign'])) {
            // delete existing
            delete_records('role_allow_assign', 'allowassign', $roleid);
            foreach ($role['canassign'] as $canassign) {
                $canassignid = get_field('role', 'id', 'shortname', $canassign);
                allow_assign($canassignid, $roleid);
            }
        }
    }
    // reset custom capabilities to keep up with changes
    return tao_reset_capabilities();
}
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:101,代码来源:tao.php


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


示例16: test_version1enrolmentcreateanddeleteignoreemptyvalues

 /**
  * Validates that the version 1 update ignores empty values and does not
  * blank out fields for enrolments
  */
 public function test_version1enrolmentcreateanddeleteignoreemptyvalues()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->dirroot . '/user/lib.php';
     require_once $CFG->dirroot . '/lib/enrollib.php';
     set_config('createorupdate', 0, 'dhimport_version1');
     set_config('gradebookroles', '');
     set_config('defaultenrol', 1, 'enrol_manual');
     set_config('status', ENROL_INSTANCE_ENABLED, 'enrol_manual');
     // Create category.
     $category = new stdClass();
     $category->name = 'rlipcategory';
     $category->id = $DB->insert_record('course_categories', $category);
     // Create course.
     $course = new stdClass();
     $course->shortname = 'rlipshortname';
     $course->fullname = 'rlipfullname';
     $course->category = $category->id;
     $course = create_course($course);
     // Create user.
     $user = new stdClass();
     $user->username = 'rlipusername';
     $user->mnethostid = $CFG->mnet_localhost_id;
     $user->idnumber = 'rlipidnumber';
     $user->email = '[email protected]';
     $user->password = 'Password!0';
     $user->idnumber = 'rlipidnumber';
     $user->id = user_create_user($user);
     set_config('siteguest', 99999);
     // Create role.
     $context = context_course::instance($course->id);
     $roleid = create_role('rliprole', 'rliprole', 'rliprole');
     set_role_contextlevels($roleid, array(CONTEXT_COURSE));
     $syscontext = context_system::instance();
     assign_capability('moodle/course:view', CAP_ALLOW, $roleid, $syscontext->id);
     // Create an enrolment.
     $data = array(array('entity' => 'enrolment', 'action' => 'create', 'username' => 'rlipusername', 'email' => '', 'idnumber' => '', 'context' => 'course', 'instance' => 'rlipshortname', 'role' => 'rliprole'));
     $provider = new rlipimport_version1_importprovider_emptyenrolment($data);
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1', $provider);
     $importplugin->run();
     $this->assert_record_exists('role_assignments', array('userid' => $user->id, 'contextid' => $context->id, 'roleid' => $roleid));
     // Delete an enrolment.
     $data[0]['action'] = 'delete';
     $provider = new rlipimport_version1_importprovider_emptyenrolment($data);
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1', $provider);
     $importplugin->run();
     // Validation.
     $exists = $DB->record_exists('role_assignments', array('userid' => $user->id, 'contextid' => $context->id, 'roleid' => $roleid));
     $this->assertFalse($exists);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:55,代码来源:version1_empty_value_updates_test.php


示例17: get_legacy_type

            $a->name = $roles[$roleid]->name;
            $a->shortname = $roles[$roleid]->shortname;
            $a->legacytype = get_legacy_type($roleid);
            if (empty($a->legacytype)) {
                $warning = get_string('resetrolesurenolegacy', 'role', $a);
            } else {
                $warning = get_string('resetrolesure', 'role', $a);
            }
            notice_yesno($warning, 'manage.php', 'manage.php', $optionsyes, $optionsno, 'post', 'get');
            admin_externalpage_print_footer();
            die;
        }
        // Do the reset.
        $legacytype = get_legacy_type($roleid);
        if ($legacytype) {
            set_role_contextlevels($roleid, get_default_contextlevels($legacytype));
        }
        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&amp;roleid=' . $roleid);
        break;
}
/// Print the page header and tabs.
admin_externalpage_print_header();
$currenttab = 'manage';
include_once 'managetabs.php';
/// Initialise table.
$table = new object();
$table->tablealign = 'center';
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:31,代码来源:manage.php


示例18: xmldb_main_install


//.........这里部分代码省略.........
        $mnethost->ip_address = $_SERVER['SERVER_ADDR'];
    }
    $mnetid = $DB->insert_record('mnet_host', $mnethost);
    set_config('mnet_localhost_id', $mnetid);
    // Initial insert of mnet applications info
    $mnet_app = new object();
    $mnet_app->name = 'moodle';
    $mnet_app->display_name = 'Moodle';
    $mnet_app->xmlrpc_server_url = '/mnet/xmlrpc/server.php';
    $mnet_app->sso_land_url = '/auth/mnet/land.php';
    $mnet_app->sso_jump_url = '/auth/mnet/land.php';
    $DB->insert_record('mnet_application', $mnet_app);
    $mnet_app = new object();
    $mnet_app->name = 'mahara';
    $mnet_app->display_name = 'Mahara';
    $mnet_app->xmlrpc_server_url = '/api/xmlrpc/server.php'; 

鲜花

握手

雷人

路过

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

请发表评论

全部评论

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