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


PHP create_role函数代码示例

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


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

示例1: test_mymoodleredirectreturnsfalseforadmin

 /**
  * Validate that redirection from My Moodle does not happen for admins
  */
 public function test_mymoodleredirectreturnsfalseforadmin()
 {
     global $CFG, $USER, $DB;
     require_once $CFG->dirroot . '/user/lib.php';
     // Make sure we're not a guest.
     set_config('siteguest', '');
     // Obtain the system context.
     $syscontext = context_system::instance();
     // Set up the current user global.
     $user = new stdClass();
     $user->username = "testuser";
     $userid = user_create_user($user);
     $USER = $DB->get_record('user', array('id' => $userid));
     // Enable functionaltiy.
     pm_set_config('mymoodle_redirect', 1);
     elis::$config = new elis_config();
     // Give the admin sufficient permissions.
     $roleid = create_role('adminrole', 'adminrole', 'adminrole');
     assign_capability('moodle/site:config', CAP_ALLOW, $roleid, $syscontext->id);
     role_assign($roleid, $USER->id, $syscontext->id);
     // Validate that redirection does not happen for admins.
     $result = pm_mymoodle_redirect();
     // Clear out cached permissions data so we don't affect other tests.
     accesslib_clear_all_caches(true);
     $this->assertFalse($result);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:29,代码来源:programsettings_test.php

示例2: test_coursepermissions

 /**
  * Test for correct assignment of course permissions
  */
 public function test_coursepermissions()
 {
     global $DB, $CFG, $USER;
     accesslib_clear_all_caches(true);
     set_config('siteguest', '');
     set_config('siteadmins', '');
     $this->assertFalse($this->has_program_create_capability());
     $this->assertFalse($this->has_associate_and_manage_capability());
     $this->assertFalse($this->has_program_view_capability());
     $syscontext = context_system::instance();
     $assigninguser = new user(array('idnumber' => 'testuserid', 'username' => 'testuser', 'firstname' => 'testuser', 'lastname' => 'testuser', 'email' => 'testuser@testuserdomain.com', 'country' => 'CA'));
     $assigninguser->save();
     $roleid = create_role('userrole', 'userrole', 'userrole');
     $usr = $DB->get_record('user', array('username' => 'testuser'));
     $this->setUser($usr);
     $USER = $usr;
     assign_capability('local/elisprogram:associate', CAP_ALLOW, $roleid, $syscontext->id);
     assign_capability('local/elisprogram:manage', CAP_ALLOW, $roleid, $syscontext->id);
     assign_capability('local/elisprogram:program_create', CAP_ALLOW, $roleid, $syscontext->id);
     assign_capability('local/elisprogram:program_enrol', CAP_ALLOW, $roleid, $syscontext->id);
     assign_capability('local/elisprogram:program_view', CAP_ALLOW, $roleid, $syscontext->id);
     role_assign($roleid, $usr->id, $syscontext->id);
     $this->assertTrue($this->has_program_create_capability());
     $this->assertTrue($this->has_associate_and_manage_capability());
     $this->assertTrue($this->has_program_view_capability());
     $this->setUser(null);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:30,代码来源:permissions_test.php

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

示例4: fixture_moodleenrol

 /**
  * Set up all data needed for testing.
  * @param array $userids List of moodle user ids to test with.
  * @param array $itemgrades List of grade item grades to test with.
  */
 public function fixture_moodleenrol($userids, $itemgrades)
 {
     global $DB;
     // Import CSV data.
     $dataset = $this->createCsvDataSet(array(course::TABLE => elispm::file('tests/fixtures/pmcourse.csv'), pmclass::TABLE => elispm::file('tests/fixtures/pmclass.csv'), 'user' => elispm::file('tests/fixtures/mdluser.csv'), user::TABLE => elispm::file('tests/fixtures/pmuser.csv'), usermoodle::TABLE => elispm::file('tests/fixtures/user_moodle.csv'), coursecompletion::TABLE => elispm::file('tests/fixtures/course_completion.csv')));
     $this->loadDataSet($dataset);
     // Create course.
     $course = $this->getDataGenerator()->create_course();
     // Link with ELIS class.
     $DB->insert_record(classmoodlecourse::TABLE, (object) array('classid' => 100, 'moodlecourseid' => $course->id));
     // Create grade items.
     $items = array(array('courseid' => $course->id, 'idnumber' => 'required', 'itemtype' => 'manual'), array('courseid' => $course->id, 'idnumber' => 'notrequired', 'itemtype' => 'manual'), array('courseid' => $course->id, 'idnumber' => 'course', 'itemtype' => 'course'));
     foreach ($items as $item) {
         $DB->insert_record('grade_items', (object) $item);
     }
     // Set up our test role.
     $roleid = create_role('gradedrole', 'gradedrole', 'gradedrole');
     set_config('gradebookroles', $roleid);
     // Create all of our test enrolments.
     foreach ($userids as $userid) {
         $this->getDataGenerator()->enrol_user($userid, $course->id, $roleid);
     }
     // Assign item grades.
     foreach ($itemgrades as $itemgrade) {
         $DB->insert_record('grade_grades', (object) $itemgrade);
     }
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:32,代码来源:pmupdatestudentprogress_test.php

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

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

示例7: create_roles

 /**
  * Creates the two roles required to test default role association. The first role contains the 'view' and
  * 'create' permissions for the entity and the second contains the 'view' and 'edit' capabilities for the entity.
  *
  * @param string $entity The name of the entity being created.
  * @return array An array containg the role for the creator / editor role
  */
 private function create_roles($entity)
 {
     $syscontext = context_system::instance();
     $role1 = create_role($entity . '_creator', $entity . '_creator', $entity . '_creator');
     assign_capability('local/elisprogram:' . $entity . '_view', CAP_ALLOW, $role1, $syscontext->id);
     assign_capability('local/elisprogram:' . $entity . '_create', CAP_ALLOW, $role1, $syscontext->id);
     $role2 = create_role($entity . '_editor', $entity . '_editor', $entity . '_editor');
     assign_capability('local/elisprogram:' . $entity . '_view', CAP_ALLOW, $role2, $syscontext->id);
     assign_capability('local/elisprogram:' . $entity . '_create', CAP_ALLOW, $role2, $syscontext->id);
     return array($role1, $role2);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:18,代码来源:pmentities_test.php

示例8: setUp

 /**
  * Setup function- we will create a course and add an assign instance to it.
  */
 protected function setUp()
 {
     global $DB;
     $this->resetAfterTest(true);
     // Create some users.
     $this->cohort = $this->getDataGenerator()->create_cohort();
     $this->userassignto = $this->getDataGenerator()->create_user();
     $this->userassignover = $this->getDataGenerator()->create_user();
     $this->roleid = create_role('Sausage Roll', 'sausageroll', 'mmmm');
     cohort_add_member($this->cohort->id, $this->userassignover->id);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:14,代码来源:api_test.php

示例9: createRoleWithCapabilities

 /**
  * Cria um papel no MOODLE conforme os padrões.
  * 
  * É sugerido que com esta função seja usado um dos papeis como Arquétipo:
  * <lu>
  * <li>manager
  * <li>coursecreator
  * <li>editingteacher
  * <li>teacher
  * <li>student
  * </lu> 
  * 
  *  
  * O Array de habilidades (capabilities) deve ser formado da seguinte forma
  * $caps = array(
  * 		array('name'=>'moodle/site:sendmessage',  'perm'=CAP_PREVENT),
  *      array('name'=>'moodle/restore:rolldates', 'perm'=CAP_INHERIT),
  *      array('name'=>'moodle/site:manageblocks', 'perm'=CAP_PROHIBIT),
  *      array('name'=>'mod/data:viewallratings',  'perm'=CAP_ALLOW),
  *      
  * );
  * Como pode ser visto 'name'aponta para o nome da habilidade e
  * 'perm' indica a permissão que será data da seguinte forma:
  * <lu>
  * <li>CAP_PREVENT<br/>
  *     Evita esta habilidade
  * <li>CAP_INHERIT<br/>
  *     Erda esta habilidade do Arquétipo informado.
  * <li>CAP_PROHIBIT<br/>
  *     Proibe esta Habilidade
  * <li>CAP_ALLOW<br/>
  *     Permite ter esta habilidade.
  * </lu>
  * 
  * @param string $name
  * @param string $shortname
  * @param String $description
  * @param string $archtype
  * @param array $capabilities
  */
 public static function createRoleWithCapabilities($name, $shortname, $description, $archtype, $capabilities = NULL)
 {
     global $DB, $CFG;
     require_once "{$CFG->dirlib}/accesslib.php";
     $roleid = create_role($name, $shortname, $description, $archetype = '');
     if (empty($capabilities)) {
         foreach ($capabilities as $cap) {
             assign_capability($cap[name], $cap[perm], $roleid, 1);
         }
     }
 }
开发者ID:LMSeXT,项目名称:local_samoodlelib,代码行数:51,代码来源:lib.php

示例10: after_install

 function after_install()
 {
     //currently after install we should require upgrade.php to run
     //test to see if this works!!
     $openrole = get_record("role", "shortname", "openlearner");
     if (empty($openrole)) {
         $roleid = create_role('Open Learner', 'openlearner', 'Open Learners have more privileges than a guest but less than a student. Custom role for OpenShare modification.');
         assign_capability("gradereport/user:view", 1, $roleid, 1);
         assign_capability("mod/assignment:submit", -1, $roleid, 1);
         assign_capability("mod/assignment:view", 1, $roleid, 1);
         assign_capability("mod/chat:chat", -1, $roleid, 1);
         assign_capability("mod/chat:readlog", -1, $roleid, 1);
         assign_capability("mod/choice:choose", 1, $roleid, 1);
         assign_capability("mod/data:comment", -1, $roleid, 1);
         assign_capability("mod/data:viewentry", 1, $roleid, 1);
         assign_capability("mod/data:writeentry", -1, $roleid, 1);
         assign_capability("mod/forum:createattachment", -1, $roleid, 1);
         assign_capability("mod/forum:deleteownpost", 1, $roleid, 1);
         assign_capability("mod/forum:initialsubscriptions", 1, $roleid, 1);
         assign_capability("mod/forum:replypost", 1, $roleid, 1);
         assign_capability("mod/forum:startdiscussion", 1, $roleid, 1);
         assign_capability("mod/forum:throttlingapplies", 1, $roleid, 1);
         assign_capability("mod/forum:viewdiscussion", 1, $roleid, 1);
         assign_capability("mod/forum:viewrating", 1, $roleid, 1);
         assign_capability("mod/glossary:comment", 1, $roleid, 1);
         assign_capability("mod/glossary:write", 1, $roleid, 1);
         assign_capability("mod/hotpot:attempt", 1, $roleid, 1);
         assign_capability("mod/lams:participate", 1, $roleid, 1);
         assign_capability("mod/quiz:attempt", 1, $roleid, 1);
         assign_capability("mod/quiz:view", 1, $roleid, 1);
         assign_capability("mod/scorm:savetrack", 1, $roleid, 1);
         assign_capability("mod/scorm:skipview", 1, $roleid, 1);
         assign_capability("mod/scorm:viewscores", 1, $roleid, 1);
         assign_capability("mod/survey:participate", 1, $roleid, 1);
         assign_capability("mod/wiki:participate", 1, $roleid, 1);
         assign_capability("mod/workshop:participate", -1, $roleid, 1);
         assign_capability("moodle/block:view", 1, $roleid, 1);
         assign_capability("moodle/blog:view", -1, $roleid, 1);
         assign_capability("moodle/calendar:manageownentries", 1, $roleid, 1);
         assign_capability("moodle/course:useremail", 1, $roleid, 1);
         assign_capability("moodle/course:view", 1, $roleid, 1);
         assign_capability("moodle/course:viewparticipants", -1, $roleid, 1);
         assign_capability("moodle/course:viewscales", 1, $roleid, 1);
         assign_capability("moodle/grade:view", 1, $roleid, 1);
         assign_capability("moodle/legacy:student", 1, $roleid, 1);
         assign_capability("moodle/site:viewparticipants", -1, $roleid, 1);
         assign_capability("moodle/user:changeownpassword", 1, $roleid, 1);
         assign_capability("moodle/user:editownprofile", 1, $roleid, 1);
         assign_capability("moodle/user:readuserblogs", -1, $roleid, 1);
         assign_capability("moodle/user:readuserposts", -1, $roleid, 1);
         assign_capability("moodle/user:viewdetails", -1, $roleid, 1);
     }
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:53,代码来源:block_openshare.php

示例11: 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 = 'testELIS4093@example.com';
     $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

示例12: execute

 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . DIRECTORY_SEPARATOR . "accesslib.php";
     $options = $this->expandedOptions;
     $arguments = $this->arguments;
     //don't create if already exists
     $role = $DB->get_record('role', array('shortname' => $arguments[0]));
     if ($role) {
         echo "Role '" . $arguments[0] . "' already exists!\n";
         exit(0);
     }
     $newroleid = create_role($options['name'], $arguments[0], $options['description'], $options['archetype']);
     echo "{$newroleid}\n";
 }
开发者ID:dariogs,项目名称:moosh,代码行数:15,代码来源:RoleCreate.php

示例13: get_user_objects

 /**
  * Returns a user object and its assigned new role.
  *
  * @param testing_data_generator $generator
  * @param $contextid
  * @return array The user object and the role ID
  */
 protected function get_user_objects(testing_data_generator $generator, $contextid)
 {
     global $USER;
     if (empty($USER->id)) {
         $user = $generator->create_user();
         $this->setUser($user);
     }
     $roleid = create_role('Test role', 'testrole', 'Test role description');
     if (!is_array($contextid)) {
         $contextid = array($contextid);
     }
     foreach ($contextid as $cid) {
         $assignid = role_assign($roleid, $user->id, $cid);
     }
     return array($user, $roleid);
 }
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:23,代码来源:management_helper_test.php

示例14: assignUserCapability

 /**
  * Assign a capability to $USER
  * The function creates a student $USER if $USER->id is empty
  *
  * @param string $capability capability name
  * @param int $contextid
  * @param int $roleid
  * @return int the role id - mainly returned for creation, so calling function can reuse it
  */
 public static function assignUserCapability($capability, $contextid, $roleid = null)
 {
     global $USER;
     // Create a new student $USER if $USER doesn't exist
     if (empty($USER->id)) {
         $user = self::getDataGenerator()->create_user();
         self::setUser($user);
     }
     if (empty($roleid)) {
         $roleid = create_role('Dummy role', 'dummyrole', 'dummy role description');
     }
     assign_capability($capability, CAP_ALLOW, $roleid, $contextid);
     role_assign($roleid, $USER->id, $contextid);
     accesslib_clear_all_caches_for_unit_testing();
     return $roleid;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:25,代码来源:helpers.php

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


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