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


PHP get_default_contextlevels函数代码示例

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


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

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

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

示例3: force_archetype

 /**
  * Change the role definition to match given archetype.
  *
  * @param string $archetype
  * @param array $options array with following keys:
  *      'name', 'shortname', 'description', 'permissions', 'archetype',
  *      'contextlevels', 'allowassign', 'allowoverride', 'allowswitch'
  */
 public function force_archetype($archetype, array $options)
 {
     $archetypes = get_role_archetypes();
     if (!isset($archetypes[$archetype])) {
         throw new coding_exception('Unknown archetype: ' . $archetype);
     }
     if ($options['shortname']) {
         $this->role->shortname = '';
     }
     if ($options['name']) {
         $this->role->name = '';
     }
     if ($options['description']) {
         $this->role->description = '';
     }
     if ($options['archetype']) {
         $this->role->archetype = $archetype;
     }
     if ($options['contextlevels']) {
         $this->contextlevels = array();
         $defaults = get_default_contextlevels($archetype);
         foreach ($defaults as $cl) {
             $this->contextlevels[$cl] = $cl;
         }
     }
     if ($options['allowassign']) {
         $this->allowassign = get_default_role_archetype_allows('assign', $archetype);
     }
     if ($options['allowoverride']) {
         $this->allowoverride = get_default_role_archetype_allows('override', $archetype);
     }
     if ($options['allowswitch']) {
         $this->allowswitch = get_default_role_archetype_allows('switch', $archetype);
     }
     if ($options['permissions']) {
         $defaultpermissions = get_default_capabilities($archetype);
         foreach ($this->permissions as $k => $v) {
             if (isset($defaultpermissions[$k])) {
                 $this->permissions[$k] = $defaultpermissions[$k];
                 continue;
             }
             $this->permissions[$k] = CAP_INHERIT;
         }
     }
 }
开发者ID:Gavinthisisit,项目名称:Moodle,代码行数:53,代码来源:define_role_table_advanced.php

示例4: get_string

            $a->shortname = $roles[$roleid]->shortname;
            $a->legacytype = $roles[$roleid]->archetype;
            if (empty($a->legacytype)) {
                $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();
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:31,代码来源:manage.php

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

示例6: xmldb_main_install


//.........这里部分代码省略.........
    /// Create guest record - do not assign any role, guest user get's the default guest role automatically on the fly
    $guest = new stdClass();
    $guest->auth = 'manual';
    $guest->username = 'guest';
    $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);
    /// 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);
    /// Install the roles system.
    $managerrole = create_role(get_string('manager', 'role'), 'manager', get_string('managerdescription', 'role'), 'manager');
    $coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator', get_string('coursecreatorsdescription'), 'coursecreator');
    $editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher', get_string('defaultcourseteacherdescription'), 'editingteacher');
    $noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher', get_string('noneditingteacherdescription'), 'teacher');
    $studentrole = create_role(get_string('defaultcoursestudent'), 'student', get_string('defaultcoursestudentdescription'), 'student');
    $guestrole = create_role(get_string('guest'), 'guest', get_string('guestdescription'), 'guest');
    $userrole = create_role(get_string('authenticateduser'), 'user', get_string('authenticateduserdescription'), 'user');
    $frontpagerole = create_role(get_string('frontpageuser', 'role'), 'frontpage', get_string('frontpageuserdescription', 'role'), 'frontpage');
    /// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
    update_capabilities('moodle');
    /// Default allow assign
    $defaultallowassigns = array(array($managerrole, $managerrole), array($managerrole, $coursecreatorrole), array($managerrole, $editteacherrole), array($managerrole, $noneditteacherrole), array($managerrole, $studentrole), array($editteacherrole, $noneditteacherrole), array($editteacherrole, $studentrole));
    foreach ($defaultallowassigns as $allow) {
        list($fromroleid, $toroleid) = $allow;
        allow_assign($fromroleid, $toroleid);
    }
    /// Default allow override
    $defaultallowoverrides = array(array($managerrole, $managerrole), array($managerrole, $coursecreatorrole), array($managerrole, $editteacherrole), array($managerrole, $noneditteacherrole), array($managerrole, $studentrole), array($managerrole, $guestrole), array($managerrole, $userrole), array($managerrole, $frontpagerole), array($editteacherrole, $noneditteacherrole), array($editteacherrole, $studentrole), array($editteacherrole, $guestrole));
    foreach ($defaultallowoverrides as $allow) {
        list($fromroleid, $toroleid) = $allow;
        allow_override($fromroleid, $toroleid);
        // There is a rant about this in MDL-15841.
    }
    /// Default allow switch.
    $defaultallowswitch = array(array($managerrole, $editteacherrole), array($managerrole, $noneditteacherrole), array($managerrole, $studentrole), array($managerrole, $guestrole), array($editteacherrole, $noneditteacherrole), array($editteacherrole, $studentrole), array($editteacherrole, $guestrole), array($noneditteacherrole, $studentrole), array($noneditteacherrole, $guestrole));
    foreach ($defaultallowswitch as $allow) {
        list($fromroleid, $toroleid) = $allow;
        allow_switch($fromroleid, $toroleid);
    }
    /// 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 themes
    set_config('themerev', 1);
    // Install licenses
    require_once $CFG->libdir . '/licenselib.php';
    license_manager::install_licenses();
    /// Add two lines of data into this new table
    $mypage = new stdClass();
    $mypage->userid = NULL;
    $mypage->name = '__default';
    $mypage->private = 0;
    $mypage->sortorder = 0;
    if (!$DB->record_exists('my_pages', array('userid' => NULL, 'private' => 0))) {
        $DB->insert_record('my_pages', $mypage);
    }
    $mypage->private = 1;
    if (!$DB->record_exists('my_pages', array('userid' => NULL, 'private' => 1))) {
        $DB->insert_record('my_pages', $mypage);
    }
}
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:101,代码来源:install.php

示例7: 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';
    $mnet_app->sso_land_url = '/auth/xmlrpc/land.php';
    $mnet_app->sso_jump_url = '/auth/xmlrpc/jump.php';
    $DB->insert_record('mnet_application', $mnet_app);
    /// insert log entries - replaces statements section in install.xml
    update_log_display_entry('user', 'view', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('course', 'user report', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('course', 'view', 'course', 'fullname');
    update_log_display_entry('course', 'update', 'course', 'fullname');
    update_log_display_entry('course', 'enrol', 'course', 'fullname');
    update_log_display_entry('course', 'unenrol', 'course', 'fullname');
    update_log_display_entry('course', 'report log', 'course', 'fullname');
    update_log_display_entry('course', 'report live', 'course', 'fullname');
    update_log_display_entry('course', 'report outline', 'course', 'fullname');
    update_log_display_entry('course', 'report participation', 'course', 'fullname');
    update_log_display_entry('course', 'report stats', 'course', 'fullname');
    update_log_display_entry('message', 'write', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('message', 'read', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('message', 'add contact', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('message', 'remove contact', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('message', 'block contact', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('message', 'unblock contact', 'user', 'CONCAT(firstname,\' \',lastname)');
    update_log_display_entry('group', 'view', 'groups', 'name');
    /// Create guest record
    $guest = new object();
    $guest->auth = 'manual';
    $guest->username = 'guest';
    $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);
    /// Now create admin user
    $admin = new object();
    $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);
    /// Install the roles system.
    $adminrole = create_role(get_string('administrator'), 'admin', get_string('administratordescription'), 'moodle/legacy:admin');
    $coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator', get_string('coursecreatorsdescription'), 'moodle/legacy:coursecreator');
    $editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher', get_string('defaultcourseteacherdescription'), 'moodle/legacy:editingteacher');
    $noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher', get_string('noneditingteacherdescription'), 'moodle/legacy:teacher');
    $studentrole = create_role(get_string('defaultcoursestudent'), 'student', get_string('defaultcoursestudentdescription'), 'moodle/legacy:student');
    $guestrole = create_role(get_string('guest'), 'guest', get_string('guestdescription'), 'moodle/legacy:guest');
    $userrole = create_role(get_string('authenticateduser'), 'user', get_string('authenticateduserdescription'), 'moodle/legacy:user');
    /// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
    assign_capability('moodle/site:doanything', CAP_ALLOW, $adminrole, $syscontext->id);
    update_capabilities('moodle');
    /// assign default roles
    role_assign($guestrole, $guest->id, 0, $syscontext->id);
    role_assign($adminrole, $admin->id, 0, $syscontext->id);
    /// Default allow assign/override/switch.
    $defaultallows = array($coursecreatorrole => $noneditteacherrole, $coursecreatorrole => $editteacherrole, $coursecreatorrole => $studentrole, $coursecreatorrole => $guestrole, $editteacherrole => $noneditteacherrole, $editteacherrole => $studentrole, $editteacherrole => $guestrole);
    foreach ($defaultallows as $fromroleid => $toroleid) {
        allow_assign($fromroleid, $toroleid);
        allow_override($fromroleid, $toroleid);
        // There is a rant about this in MDL-15841.
        allow_switch($fromroleid, $toroleid);
    }
    allow_switch($noneditteacherrole, $studentrole);
    /// Set up the context levels where you can assign each role.
    set_role_contextlevels($adminrole, get_default_contextlevels('admin'));
    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'));
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:101,代码来源:install.php

示例8: xmldb_main_upgrade


//.........这里部分代码省略.........
    if ($result && $oldversion < 2008101300) {
        if (!get_config(NULL, 'statsruntimedays')) {
            set_config('statsruntimedays', '31');
        }
        /// Main savepoint reached
        upgrade_main_savepoint($result, 2008101300);
    }
    /// New table for storing which roles can be assigned in which contexts.
    if ($result && $oldversion < 2008110601) {
        /// Define table role_context_levels to be created
        $table = new xmldb_table('role_context_levels');
        /// Adding fields to table role_context_levels
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        /// Adding keys to table role_context_levels
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->add_key('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid'));
        $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
        /// Conditionally launch create table for role_context_levels
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        /// Main savepoint reached
        upgrade_main_savepoint($result, 2008110601);
    }
    /// Now populate the role_context_levels table with the defaults that match
    /// moodle_install_roles, and any other combinations that exist in this system.
    if ($result && $oldversion < 2008110602) {
        $roleids = $DB->get_records_menu('role', array(), '', 'shortname,id');
        /// Defaults, should match moodle_install_roles.
        $rolecontextlevels = array();
        if (isset($roleids['admin'])) {
            $rolecontextlevels[$roleids['admin']] = get_default_contextlevels('admin');
        }
        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;
                }
            }
        }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:67,代码来源:upgrade.php

示例9: upgrade_to_new_roles_ui

function upgrade_to_new_roles_ui()
{
    global $CFG;
    /// New table for storing which roles can be assigned in which contexts.
    /// Define table role_context_levels to be created
    $table = new XMLDBTable('role_context_levels');
    /// Adding fields to table role_context_levels
    $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
    $table->addFieldInfo('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
    $table->addFieldInfo('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
    /// Adding keys to table role_context_levels
    $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
    $table->addKeyInfo('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid'));
    $table->addKeyInfo('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
    /// Conditionally launch create table for role_context_levels
    if (!table_exists($table)) {
        create_table($table);
    }
    /// Now populate the role_context_levels table with the defaults that match
    /// moodle_install_roles, and any other combinations that exist in this system.
    $roleids = get_records_menu('role', '', '', '', 'shortname,id');
    /// Defaults, should match moodle_install_roles.
    $rolecontextlevels = array();
    if (isset($roleids['admin'])) {
        $rolecontextlevels[$roleids['admin']] = get_default_contextlevels('admin');
    }
    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 = 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) {
        $rcl = (object) $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);
    }
    /// Remove any role overrides for moodle/site:doanything, or any permissions
    /// for it in a role without legacy:admin.
    $systemcontext = get_context_instance(CONTEXT_SYSTEM);
    // Remove all overrides.
    delete_records_select('role_capabilities', "capability = 'moodle/site:doanything'\n        AND contextid <> {$systemcontext->id}");
    $roletest = '';
    // Get the ids of all the roles that are moodle/legacy:admin.
    if ($adminroleids = get_records_select_menu('role_capabilities', "capability = 'moodle/legacy:admin' AND permission = 1 AND contextid = {$systemcontext->id}", '', 'id, roleid')) {
        $roletest = 'IN ( ' . implode(',', $adminroleids) . ')';
    } else {
        $adminroleids = array();
    }
    delete_records_select('role_capabilities', "roleid NOT {$roletest}\n        AND capability = 'moodle/site:doanything'AND contextid = {$systemcontext->id}");
    set_field_select('role_capabilities', 'permission', 1, "roleid {$roletest} AND capability = 'moodle/site:doanything' AND contextid = {$systemcontext->id}");
    // And for any admin-y roles where moodle/site:doanything is not set, set it.
    $doanythingroleids = get_records_select_menu('role_capabilities', "capability = 'moodle/site:doanything' AND permission = 1 AND 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();
            insert_record('role_capabilities', $rc);
        }
    }
    set_config('roles_ui_backport_upgraded', 1);
}
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:91,代码来源:newui.php

示例10: moodle_install_roles


//.........这里部分代码省略.........
            while ($coursecreator = rs_fetch_next_record($rs)) {
                role_assign($coursecreatorrole, $coursecreator->userid, 0, $systemcontext->id);
                $progresscount++;
                print_progress($progresscount, $totalcount, 5, 1, 'Processing role assignments');
            }
            rs_close($rs);
        }
    }
    /// Upgrade editting teachers and non-editting teachers.
    if (in_array($CFG->prefix . 'user_teachers', $dbtables)) {
        if ($rs = get_recordset('user_teachers')) {
            while ($teacher = rs_fetch_next_record($rs)) {
                // removed code here to ignore site level assignments
                // since the contexts are separated now
                // populate the user_lastaccess table
                $access = new object();
                $access->timeaccess = $teacher->timeaccess;
                $access->userid = $teacher->userid;
                $access->courseid = $teacher->course;
                insert_record('user_lastaccess', $access);
                // assign the default student role
                $coursecontext = get_context_instance(CONTEXT_COURSE, $teacher->course);
                // needs cache
                // hidden teacher
                if ($teacher->authority == 0) {
                    $hiddenteacher = 1;
                } else {
                    $hiddenteacher = 0;
                }
                if ($teacher->editall) {
                    // editting teacher
                    role_assign($editteacherrole, $teacher->userid, 0, $coursecontext->id, $teacher->timestart, $teacher->timeend, $hiddenteacher, $teacher->enrol, $teacher->timemodified);
                } else {
                    role_assign($noneditteacherrole, $teacher->userid, 0, $coursecontext->id, $teacher->timestart, $teacher->timeend, $hiddenteacher, $teacher->enrol, $teacher->timemodified);
                }
                $progresscount++;
                print_progress($progresscount, $totalcount, 5, 1, 'Processing role assignments');
            }
            rs_close($rs);
        }
    }
    /// Upgrade students.
    if (in_array($CFG->prefix . 'user_students', $dbtables)) {
        if ($rs = get_recordset('user_students')) {
            while ($student = rs_fetch_next_record($rs)) {
                // populate the user_lastaccess table
                $access = new object();
                $access->timeaccess = $student->timeaccess;
                $access->userid = $student->userid;
                $access->courseid = $student->course;
                insert_record('user_lastaccess', $access);
                // assign the default student role
                $coursecontext = get_context_instance(CONTEXT_COURSE, $student->course);
                role_assign($studentrole, $student->userid, 0, $coursecontext->id, $student->timestart, $student->timeend, 0, $student->enrol, $student->time);
                $progresscount++;
                print_progress($progresscount, $totalcount, 5, 1, 'Processing role assignments');
            }
            rs_close($rs);
        }
    }
    /// Upgrade guest (only 1 entry).
    if ($guestuser = get_record('user', 'username', 'guest')) {
        role_assign($guestrole, $guestuser->id, 0, $systemcontext->id);
    }
    print_progress($totalcount, $totalcount, 5, 1, 'Processing role assignments');
    /// Insert the correct records for legacy roles
    allow_assign($adminrole, $adminrole);
    allow_assign($adminrole, $coursecreatorrole);
    allow_assign($adminrole, $noneditteacherrole);
    allow_assign($adminrole, $editteacherrole);
    allow_assign($adminrole, $studentrole);
    allow_assign($adminrole, $guestrole);
    allow_assign($coursecreatorrole, $noneditteacherrole);
    allow_assign($coursecreatorrole, $editteacherrole);
    allow_assign($coursecreatorrole, $studentrole);
    allow_assign($coursecreatorrole, $guestrole);
    allow_assign($editteacherrole, $noneditteacherrole);
    allow_assign($editteacherrole, $studentrole);
    allow_assign($editteacherrole, $guestrole);
    /// Set up default allow override matrix
    allow_override($adminrole, $adminrole);
    allow_override($adminrole, $coursecreatorrole);
    allow_override($adminrole, $noneditteacherrole);
    allow_override($adminrole, $editteacherrole);
    allow_override($adminrole, $studentrole);
    allow_override($adminrole, $guestrole);
    allow_override($adminrole, $userrole);
    //See MDL-15841
    //allow_override($editteacherrole, $noneditteacherrole);
    //allow_override($editteacherrole, $studentrole);
    //allow_override($editteacherrole, $guestrole);
    /// Set up the context levels where you can assign each role.
    set_role_contextlevels($adminrole, get_default_contextlevels('admin'));
    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'));
}
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:101,代码来源:accesslib.php

示例11: xmldb_core_install

function xmldb_core_install() {
    global $CFG, $DB, $SITE;

    // switch to new default theme 
    set_config('theme', 'standard');

    $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
    $systemcontext = context_system::instance();
    // add coursetype and icon fields to course table

    $table = new xmldb_table('course');

    $field = new xmldb_field('coursetype');
    if (!$dbman->field_exists($table, $field)) {
        $field->set_attributes(XMLDB_TYPE_INTEGER, '4', null, null, null, null, null);
        $dbman->add_field($table, $field);
    }

    $field = new xmldb_field('icon');
    if (!$dbman->field_exists($table, $field)) {
        $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $dbman->add_field($table, $field);
    }

    // rename the moodle 'manager' fullname to "Site Manager" to make it
    // distinct from the "Staff Manager"
    if ($managerroleid = $DB->get_field('role', 'id', array('shortname' => 'manager', 'name' => get_string('manager', 'role')))) {
        $todb = new stdClass();
        $todb->id = $managerroleid;
        $todb->name = get_string('sitemanager', 'local_core');
        $DB->update_record('role', $todb);
    }

    // Create roles.
    $manager             = $DB->get_record('role', array('shortname' => 'manager'));
    $managerrole         = $manager->id;
    $staffmanagerrole    = create_role('', 'staffmanager', '', 'staffmanager');
    $assessorrole        = create_role('', 'assessor', '', 'assessor');
    $regionalmanagerrole = create_role('', 'regionalmanager', '');
    $regionaltrainerrole = create_role('', 'regionaltrainer', '');

    $defaultallowassigns = array(
        array($managerrole, $staffmanagerrole),
        array($managerrole, $assessorrole),
        array($managerrole, $regionalmanagerrole),
        array($managerrole, $regionaltrainerrole)
    );
    foreach ($defaultallowassigns as $allow) {
        list($fromroleid, $toroleid) = $allow;
        allow_assign($fromroleid, $toroleid);
    }

    $defaultallowoverrides = array(
        array($managerrole, $staffmanagerrole),
        array($managerrole, $assessorrole),
        array($managerrole, $regionalmanagerrole),
        array($managerrole, $regionaltrainerrole)
    );
    foreach ($defaultallowoverrides as $allow) {
        list($fromroleid, $toroleid) = $allow;
        allow_override($fromroleid, $toroleid); // There is a rant about this in MDL-15841.
    }

    $defaultallowswitch = array(
        array($managerrole, $staffmanagerrole),
    );
    foreach ($defaultallowswitch as $allow) {
        list($fromroleid, $toroleid) = $allow;
        allow_switch($fromroleid, $toroleid);
    }

    set_role_contextlevels($staffmanagerrole,   get_default_contextlevels('staffmanager'));
    assign_capability('moodle/user:viewdetails', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true);
    assign_capability('moodle/user:viewuseractivitiesreport', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true);
    assign_capability('moodle/cohort:view', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true);
    assign_capability('moodle/comment:view', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true);
    assign_capability('moodle/comment:delete', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true);
    assign_capability('moodle/comment:post', CAP_ALLOW, $staffmanagerrole, $systemcontext->id, true);
    $systemcontext->mark_dirty();
    set_role_contextlevels($assessorrole,       get_default_contextlevels('teacher'));

    $role_to_modify = array(
        'editingteacher' => 'editingtrainer',
        'teacher' => 'trainer',
        'student' => 'learner'
    );

    $DB->update_record('role', array('id' => $assessorrole, 'archetype' => 'assessor'));
    assign_capability('moodle/user:editownprofile', CAP_ALLOW, $assessorrole, $systemcontext->id, true);
    assign_capability('moodle/user:editownprofile', CAP_ALLOW, $regionalmanagerrole, $systemcontext->id, true);
    assign_capability('moodle/user:editownprofile', CAP_ALLOW, $regionaltrainerrole, $systemcontext->id, true);

    foreach ($role_to_modify as $old => $new) {
        if ($old_role = $DB->get_record('role', array('shortname' => $old))) {
            $new_role = new stdClass();
            $new_role->id = $old_role->id;
            $new_role->name = '';
            $new_role->description = '';

            $DB->update_record('role', $new_role);
//.........这里部分代码省略.........
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:101,代码来源:install.php


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