本文整理汇总了PHP中get_role_contextlevels函数的典型用法代码示例。如果您正苦于以下问题:PHP get_role_contextlevels函数的具体用法?PHP get_role_contextlevels怎么用?PHP get_role_contextlevels使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_role_contextlevels函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_export_xml
/**
* Generate role export xml file.
*
* @param $roleid
* @return string
*/
public static function get_export_xml($roleid)
{
global $DB;
$role = $DB->get_record('role', array('id' => $roleid), '*', MUST_EXIST);
$dom = new DOMDocument('1.0', 'UTF-8');
$top = $dom->createElement('role');
$dom->appendChild($top);
$top->appendChild($dom->createElement('shortname', $role->shortname));
$top->appendChild($dom->createElement('name', htmlspecialchars($role->name, ENT_COMPAT | ENT_HTML401, 'UTF-8')));
$top->appendChild($dom->createElement('description', htmlspecialchars($role->description, ENT_COMPAT | ENT_HTML401, 'UTF-8')));
$top->appendChild($dom->createElement('archetype', $role->archetype));
$contextlevels = $dom->createElement('contextlevels');
$top->appendChild($contextlevels);
foreach (get_role_contextlevels($roleid) as $level) {
$name = context_helper::get_class_for_level($level);
$name = preg_replace('/^context_/', '', $name);
$contextlevels->appendChild($dom->createElement('level', $name));
}
foreach (array('assign', 'override', 'switch') as $type) {
$allows = $dom->createElement('allow' . $type);
$top->appendChild($allows);
$records = $DB->get_records('role_allow_' . $type, array('roleid' => $roleid), "allow{$type} ASC");
foreach ($records as $record) {
if (!($ar = $DB->get_record('role', array('id' => $record->{'allow' . $type})))) {
continue;
}
$allows->appendChild($dom->createElement('shortname', $ar->shortname));
}
}
$permissions = $dom->createElement('permissions');
$top->appendChild($permissions);
$capabilities = $DB->get_records_sql_menu("SELECT capability, permission\n FROM {role_capabilities}\n WHERE contextid = :syscontext AND roleid = :roleid\n ORDER BY capability ASC", array('syscontext' => context_system::instance()->id, 'roleid' => $roleid));
$allcapabilities = $DB->get_records('capabilities', array(), 'name ASC');
foreach ($allcapabilities as $cap) {
if (!isset($capabilities[$cap->name])) {
$permissions->appendChild($dom->createElement('inherit', $cap->name));
}
}
foreach ($capabilities as $capability => $permission) {
if ($permission == CAP_ALLOW) {
$permissions->appendChild($dom->createElement('allow', $capability));
}
}
foreach ($capabilities as $capability => $permission) {
if ($permission == CAP_PREVENT) {
$permissions->appendChild($dom->createElement('prevent', $capability));
}
}
foreach ($capabilities as $capability => $permission) {
if ($permission == CAP_PROHIBIT) {
$permissions->appendChild($dom->createElement('prohibit', $capability));
}
}
return $dom->saveXML();
}
示例2: test_xml
public function test_xml()
{
global $DB;
$roles = $DB->get_records('role');
foreach ($roles as $role) {
$xml = core_role_preset::get_export_xml($role->id);
$this->assertTrue(core_role_preset::is_valid_preset($xml));
$info = core_role_preset::parse_preset($xml);
$this->assertSame($role->shortname, $info['shortname']);
$this->assertSame($role->name, $info['name']);
$this->assertSame($role->description, $info['description']);
$this->assertSame($role->archetype, $info['archetype']);
$contextlevels = get_role_contextlevels($role->id);
$this->assertEquals(array_values($contextlevels), array_values($info['contextlevels']));
foreach (array('assign', 'override', 'switch') as $type) {
$records = $DB->get_records('role_allow_' . $type, array('roleid' => $role->id), "allow{$type} ASC");
$allows = array();
foreach ($records as $record) {
if ($record->{'allow' . $type} == $role->id) {
array_unshift($allows, -1);
}
$allows[] = $record->{'allow' . $type};
}
$this->assertEquals($allows, $info['allow' . $type], "{$type} {$role->shortname} does not match");
}
$capabilities = $DB->get_records_sql("SELECT *\n FROM {role_capabilities}\n WHERE contextid = :syscontext AND roleid = :roleid\n ORDER BY capability ASC", array('syscontext' => context_system::instance()->id, 'roleid' => $role->id));
foreach ($capabilities as $cap) {
$this->assertEquals($cap->permission, $info['permissions'][$cap->capability]);
unset($info['permissions'][$cap->capability]);
}
// The remainders should be only inherits.
foreach ($info['permissions'] as $capability => $permission) {
if ($permission == CAP_INHERIT) {
continue;
}
$this->fail('only CAP_INHERIT expected');
}
}
}
示例3: 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();
}
示例4: load_current_permissions
protected function load_current_permissions()
{
global $DB;
if ($this->roleid) {
if (!($this->role = $DB->get_record('role', array('id' => $this->roleid)))) {
throw new moodle_exception('invalidroleid');
}
$contextlevels = get_role_contextlevels($this->roleid);
// Put the contextlevels in the array keys, as well as the values.
if (!empty($contextlevels)) {
$this->contextlevels = array_combine($contextlevels, $contextlevels);
} else {
$this->contextlevels = array();
}
} else {
$this->role = new stdClass();
$this->role->name = '';
$this->role->shortname = '';
$this->role->description = '';
$this->role->archetype = '';
$this->contextlevels = array();
}
parent::load_current_permissions();
}
示例5: get_system_roles
function get_system_roles()
{
global $CFG, $DB, $PAGE;
$roles = $DB->get_records_sql("SELECT id, name, shortname\n FROM {$CFG->prefix}role");
$rolenames = role_fix_names($roles, NULL, ROLENAME_BOTH, true);
$data = array();
foreach ($roles as $role) {
// Only return roles assignables in course context
$contextlevels = get_role_contextlevels($role->id);
if (!in_array(CONTEXT_SYSTEM, $contextlevels)) {
continue;
}
$r['id'] = $role->id;
$r['name'] = $rolenames[$role->id];
$data[] = $r;
}
return $data;
}
示例6: create_role
/**
* Creates a new role in the system.
*
* You can fill $record with the role 'name',
* 'shortname', 'description' and 'archetype'.
*
* If an archetype is specified it's capabilities,
* context where the role can be assigned and
* all other properties are copied from the archetype;
* if no archetype is specified it will create an
* empty role.
*
* @param array|stdClass $record
* @return int The new role id
*/
public function create_role($record=null) {
global $DB;
$this->rolecount++;
$i = $this->rolecount;
$record = (array)$record;
if (empty($record['shortname'])) {
$record['shortname'] = 'role-' . $i;
}
if (empty($record['name'])) {
$record['name'] = 'Test role ' . $i;
}
if (empty($record['description'])) {
$record['description'] = 'Test role ' . $i . ' description';
}
if (empty($record['archetype'])) {
$record['archetype'] = '';
} else {
$archetypes = get_role_archetypes();
if (empty($archetypes[$record['archetype']])) {
throw new coding_exception('\'role\' requires the field \'archetype\' to specify a ' .
'valid archetype shortname (editingteacher, student...)');
}
}
// Creates the role.
if (!$newroleid = create_role($record['name'], $record['shortname'], $record['description'], $record['archetype'])) {
throw new coding_exception('There was an error creating \'' . $record['shortname'] . '\' role');
}
// If no archetype was specified we allow it to be added to all contexts,
// otherwise we allow it in the archetype contexts.
if (!$record['archetype']) {
$contextlevels = array_keys(context_helper::get_all_levels());
} else {
// Copying from the archetype default rol.
$archetyperoleid = $DB->get_field(
'role',
'id',
array('shortname' => $record['archetype'], 'archetype' => $record['archetype'])
);
$contextlevels = get_role_contextlevels($archetyperoleid);
}
set_role_contextlevels($newroleid, $contextlevels);
if ($record['archetype']) {
// We copy all the roles the archetype can assign, override and switch to.
if ($record['archetype']) {
$types = array('assign', 'override', 'switch');
foreach ($types as $type) {
$rolestocopy = get_default_role_archetype_allows($type, $record['archetype']);
foreach ($rolestocopy as $tocopy) {
$functionname = 'allow_' . $type;
$functionname($newroleid, $tocopy);
}
}
}
// Copying the archetype capabilities.
$sourcerole = $DB->get_record('role', array('id' => $archetyperoleid));
role_cap_duplicate($sourcerole, $newroleid);
}
return $newroleid;
}
示例7: force_duplicate
/**
* Call this after the table has been initialised,
* this resets everything to that role.
*
* @param int $roleid role id or 0 for no role
* @param array $options array with following keys:
* 'name', 'shortname', 'description', 'permissions', 'archetype',
* 'contextlevels', 'allowassign', 'allowoverride', 'allowswitch'
*/
public function force_duplicate($roleid, array $options)
{
global $DB;
if ($roleid == 0) {
// This means reset to nothing == remove everything.
if ($options['shortname']) {
$this->role->shortname = '';
}
if ($options['name']) {
$this->role->name = '';
}
if ($options['description']) {
$this->role->description = '';
}
if ($options['archetype']) {
$this->role->archetype = '';
}
if ($options['contextlevels']) {
$this->contextlevels = array();
}
if ($options['allowassign']) {
$this->allowassign = array();
}
if ($options['allowoverride']) {
$this->allowoverride = array();
}
if ($options['allowswitch']) {
$this->allowswitch = array();
}
if ($options['permissions']) {
foreach ($this->capabilities as $capid => $cap) {
$this->permissions[$cap->name] = CAP_INHERIT;
}
}
return;
}
$role = $DB->get_record('role', array('id' => $roleid), '*', MUST_EXIST);
if ($options['shortname']) {
$this->role->shortname = $role->shortname;
}
if ($options['name']) {
$this->role->name = $role->name;
}
if ($options['description']) {
$this->role->description = $role->description;
}
if ($options['archetype']) {
$this->role->archetype = $role->archetype;
}
if ($options['contextlevels']) {
$this->contextlevels = array();
$levels = get_role_contextlevels($roleid);
foreach ($levels as $cl) {
$this->contextlevels[$cl] = $cl;
}
}
if ($options['allowassign']) {
$this->allowassign = array_keys($this->get_allow_roles_list('assign', $roleid));
}
if ($options['allowoverride']) {
$this->allowoverride = array_keys($this->get_allow_roles_list('override', $roleid));
}
if ($options['allowswitch']) {
$this->allowswitch = array_keys($this->get_allow_roles_list('switch', $roleid));
}
if ($options['permissions']) {
$this->permissions = $DB->get_records_menu('role_capabilities', array('roleid' => $roleid, 'contextid' => context_system::instance()->id), '', 'capability,permission');
foreach ($this->capabilities as $capid => $cap) {
if (!isset($this->permissions[$cap->name])) {
$this->permissions[$cap->name] = CAP_INHERIT;
}
}
}
}
示例8: xmldb_local_iomad_upgrade
//.........这里部分代码省略.........
$table->add_field('groupid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
// Adding keys to table company_course_groups.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
// Conditionally launch create table for company_course_groups.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Define table company_shared_courses to be created.
$table = new xmldb_table('company_shared_courses');
// Adding fields to table company_shared_courses.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('companyid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
// Adding keys to table company_shared_courses.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
// Conditionally launch create table for company_shared_courses.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Iomad savepoint reached.
upgrade_plugin_savepoint(true, 2012012500, 'local', 'iomad');
}
if ($oldversion < 2012051500) {
// Change the role permissions for company and create the department manager role.
$systemcontext = context_system::instance();
// Create the Company Manager role.
if (!($companymanager = $DB->get_record('role', array('shortname' => 'companymanager')))) {
$companymanagerid = create_role('Company Manager', 'companymanager', '(Iomad) Manages individual companies - can upload users etc.');
} else {
$companymanagerid = $companymanager->id;
}
// If not done already, allow assignment at system context.
$levels = get_role_contextlevels($companymanagerid);
if (empty($levels)) {
$level = null;
$level->roleid = $companymanagerid;
$level->contextlevel = CONTEXT_SYSTEM;
$DB->insert_record('role_context_levels', $level);
}
// Create new Company Department Manager role.
if (!($companydepartmentmanager = $DB->get_record('role', array('shortname' => 'companydepartmentmanager')))) {
$companydepartmentmanagerid = create_role('Company Department Manager', 'companydepartmentmanager', '(Iomad) Manages departments within companies - can upload users etc.');
} else {
$companydepartmentmanagerid = $companydepartmentmanager->id;
}
// If not done already, allow assignment at system context.
$levels = get_role_contextlevels($companydepartmentmanagerid);
if (empty($levels)) {
$level = null;
$level->roleid = $companydepartmentmanagerid;
$level->contextlevel = CONTEXT_SYSTEM;
$DB->insert_record('role_context_levels', $level);
}
$companydepartmentmanagercaps = array('block/iomad_reports:view', 'block/iomad_online_users:viewlist', 'block/iomad_link:view', 'block/iomad_company_admin:view_licenses', 'block/iomad_company_admin:view', 'block/iomad_company_admin:user_upload', 'block/iomad_company_admin:user_create', 'block/iomad_company_admin:editusers', 'block/iomad_company_admin:edit_departments', 'block/iomad_company_admin:company_view', 'block/iomad_company_admin:company_course_users', 'block/iomad_company_admin:assign_department_manager', 'block/iomad_company_admin:company_manager', 'block/iomad_company_admin:allocate_licenses', 'local/iomad_dashboard:view');
if ($DB->get_records('role_capabilities', array('roleid' => $companydepartmentmanagerid))) {
$DB->delete_records('role_capabilities', array('roleid' => $companydepartmentmanagerid));
}
foreach ($companydepartmentmanagercaps as $cap) {
assign_capability($cap, CAP_ALLOW, $companydepartmentmanagerid, $systemcontext->id);
}
$companymanagercaps = array('block/iomad_company_admin:assign_company_manager', 'block/iomad_company_admin:assign_department_manager', 'block/iomad_online_users:viewlist', 'block/iomad_link:view', 'block/iomad_company_admin:view_licenses', 'block/iomad_company_admin:view', 'block/iomad_company_admin:user_upload', 'block/iomad_company_admin:user_create', 'block/iomad_company_admin:editusers', 'block/iomad_company_admin:edit_departments', 'block/iomad_company_admin:company_view', 'block/iomad_company_admin:company_course_users', 'block/iomad_company_admin:assign_department_manager', 'block/iomad_company_admin:allocate_licenses', 'block/iomad_company_admin:assign_company_manager', 'block/iomad_company_admin:classrooms', 'block/iomad_company_admin:classrooms_delete', 'block/iomad_company_admin:classrooms_edit', 'block/iomad_company_admin:company_edit', 'block/iomad_company_admin:company_course_unenrol', 'block/iomad_company_admin:company_manager', 'block/iomad_company_admin:company_user_profiles', 'block/iomad_company_admin:createcourse', 'local/iomad_dashboard:view');
if ($DB->get_records('role_capabilities', array('roleid' => $companymanagerid))) {
$DB->delete_records('role_capabilities', array('roleid' => $companymanagerid));
}
foreach ($companymanagercaps as $cap) {
示例9: load_current_permissions
protected function load_current_permissions()
{
if ($this->roleid) {
if (!($this->role = get_record('role', 'id', $this->roleid))) {
print_error('invalidroleid');
}
$this->role->legacytype = get_legacy_type($this->roleid);
$contextlevels = get_role_contextlevels($this->roleid);
// Put the contextlevels in the array keys, as well as the values.
if (!empty($contextlevels)) {
$this->contextlevels = array_combine($contextlevels, $contextlevels);
} else {
$this->contextlevels = array();
}
} else {
$this->role = new stdClass();
$this->role->name = '';
$this->role->shortname = '';
$this->role->description = '';
$this->role->legacytype = '';
$this->contextlevels = array();
}
parent::load_current_permissions();
}
示例10: backup_general_info
//.........这里部分代码省略.........
}
//The user in backup
if ($preferences->backup_users == 1) {
fwrite($bf, full_tag("USERS", 3, false, "course"));
} else {
if ($preferences->backup_users == 0) {
fwrite($bf, full_tag("USERS", 3, false, "all"));
} else {
fwrite($bf, full_tag("USERS", 3, false, "none"));
}
}
//The logs in backup
if ($preferences->backup_logs == 1) {
fwrite($bf, full_tag("LOGS", 3, false, "true"));
} else {
fwrite($bf, full_tag("LOGS", 3, false, "false"));
}
//The user files
if ($preferences->backup_user_files == 1) {
fwrite($bf, full_tag("USERFILES", 3, false, "true"));
} else {
fwrite($bf, full_tag("USERFILES", 3, false, "false"));
}
//The course files
if ($preferences->backup_course_files == 1) {
fwrite($bf, full_tag("COURSEFILES", 3, false, "true"));
} else {
fwrite($bf, full_tag("COURSEFILES", 3, false, "false"));
}
//The site files
if ($preferences->backup_site_files == 1) {
fwrite($bf, full_tag("SITEFILES", 3, false, "true"));
} else {
fwrite($bf, full_tag("SITEFILES", 3, false, "false"));
}
//The gradebook histories
if (empty($CFG->disablegradehistory) && $preferences->backup_gradebook_history == 1) {
fwrite($bf, full_tag("GRADEBOOKHISTORIES", 3, false, "true"));
} else {
fwrite($bf, full_tag("GRADEBOOKHISTORIES", 3, false, "false"));
}
//The messages in backup
if ($preferences->backup_messages == 1 && $preferences->backup_course == SITEID) {
fwrite($bf, full_tag("MESSAGES", 3, false, "true"));
} else {
fwrite($bf, full_tag("MESSAGES", 3, false, "false"));
}
//The blogs in backup
if ($preferences->backup_blogs == 1 && $preferences->backup_course == SITEID) {
fwrite($bf, full_tag("BLOGS", 3, false, "true"));
} else {
fwrite($bf, full_tag("BLOGS", 3, false, "false"));
}
//The mode of writing the block data
fwrite($bf, full_tag('BLOCKFORMAT', 3, false, 'instances'));
fwrite($bf, end_tag("DETAILS", 2, true));
$status = fwrite($bf, end_tag("INFO", 1, true));
///Roles stuff goes in here
fwrite($bf, start_tag('ROLES', 1, true));
$roles = backup_fetch_roles($preferences);
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
$coursecontext = get_context_instance(CONTEXT_COURSE, $preferences->backup_course);
foreach ($roles as $role) {
fwrite($bf, start_tag('ROLE', 2, true));
fwrite($bf, full_tag('ID', 3, false, $role->id));
fwrite($bf, full_tag('NAME', 3, false, $role->name));
fwrite($bf, full_tag('SHORTNAME', 3, false, $role->shortname));
/// Calculate $role name in course
$nameincourse = role_get_name($role, $coursecontext);
if ($nameincourse != $role->name) {
fwrite($bf, full_tag('NAMEINCOURSE', 3, false, $nameincourse));
}
/// List of context level where this role can be assigned.
fwrite($bf, start_tag('CONTEXTLEVELS', 3, true));
$contextlevels = get_role_contextlevels($role->id);
foreach ($contextlevels as $cl) {
fwrite($bf, full_tag('CONTEXTLEVEL', 4, false, $cl));
}
fwrite($bf, end_tag('CONTEXTLEVELS', 3, true));
/// find and write all default capabilities
fwrite($bf, start_tag('CAPABILITIES', 3, true));
// pull out all default (site context) capabilities
if ($capabilities = role_context_capabilities($role->id, $sitecontext)) {
foreach ($capabilities as $capability => $value) {
fwrite($bf, start_tag('CAPABILITY', 4, true));
fwrite($bf, full_tag('NAME', 5, false, $capability));
fwrite($bf, full_tag('PERMISSION', 5, false, $value));
// use this to pull out the other info (timemodified and modifierid)
$cap = $DB->get_record_sql("SELECT *\n FROM {role_capabilities}\n WHERE capability = ?\n AND contextid = ?\n AND roleid = ?", array($capability, $sitecontext->id, $role->id));
fwrite($bf, full_tag("TIMEMODIFIED", 5, false, $cap->timemodified));
fwrite($bf, full_tag("MODIFIERID", 5, false, $cap->modifierid));
fwrite($bf, end_tag('CAPABILITY', 4, true));
}
}
fwrite($bf, end_tag('CAPABILITIES', 3, true));
fwrite($bf, end_tag('ROLE', 2, true));
}
fwrite($bf, end_tag('ROLES', 1, true));
return $status;
}
示例11: get_roles
function get_roles()
{
global $CFG, $DB, $PAGE;
$roles = $DB->get_records_sql("SELECT id, name, shortname\n FROM {$CFG->prefix}role");
$data = array();
foreach ($roles as $role) {
// Only return roles assignables in course context
$contextlevels = get_role_contextlevels($role->id);
if (!in_array(CONTEXT_COURSE, $contextlevels)) {
continue;
}
$r['id'] = $role->id;
$r['name'] = $role->name;
$r['name'] = get_string($role->shortname);
$data[] = $r;
}
return $data;
}
示例12: xmldb_local_iomad_install
function xmldb_local_iomad_install()
{
global $CFG, $DB;
$systemcontext = context_system::instance();
// Create new Company Manager role.
if (!($companymanager = $DB->get_record('role', array('shortname' => 'companymanager')))) {
$companymanagerid = create_role('Company Manager', 'companymanager', '(Iomad) Manages individual companies - can upload users etc.');
} else {
$companymanagerid = $companymanager->id;
}
// If not done already, allow assignment at system context.
$levels = get_role_contextlevels($companymanagerid);
if (empty($levels)) {
$level = new stdClass();
$level->roleid = $companymanagerid;
$level->contextlevel = CONTEXT_SYSTEM;
$DB->insert_record('role_context_levels', $level);
}
// Create new Company Department Manager role.
if (!($companydepartmentmanager = $DB->get_record('role', array('shortname' => 'companydepartmentmanager')))) {
$companydepartmentmanagerid = create_role('Company Department Manager', 'companydepartmentmanager', 'Iomad Manages departments within companies - can upload users etc.');
} else {
$companydepartmentmanagerid = $companydepartmentmanager->id;
}
// If not done already, allow assignment at system context.
$levels = get_role_contextlevels($companydepartmentmanagerid);
if (empty($levels)) {
$level = new stdclass();
$level->roleid = $companydepartmentmanagerid;
$level->contextlevel = CONTEXT_SYSTEM;
$DB->insert_record('role_context_levels', $level);
}
// Create new Client Administrator role.
if (!($clientadministrator = $DB->get_record('role', array('shortname' => 'clientadministrator')))) {
$clientadministratorid = create_role('Client Administrator', 'clientadministrator', '(Iomad) Manages site - can create new companies and add managers etc.');
} else {
$clientadministratorid = $clientadministrator->id;
}
// If not done already, allow assignment at system context.
$levels = get_role_contextlevels($clientadministratorid);
if (empty($levels)) {
$level = new stdclass();
$level->roleid = $clientadministratorid;
$level->contextlevel = CONTEXT_SYSTEM;
$DB->insert_record('role_context_levels', $level);
}
// Create new Client Course Editor role.
if (!($companycourseeditor = $DB->get_record('role', array('shortname' => 'companycourseeditor')))) {
$companycourseeditorid = create_role('Client Course Editor', 'companycourseeditor', 'Iomad Client Course Editor - can edit course content; add, delete, modify etc..');
} else {
$companycourseeditorid = $companycourseeditor->id;
}
// If not done already, allow assignment at system context.
$levels = get_role_contextlevels($companycourseeditorid);
if (empty($levels)) {
$level = new stdclass();
$level->roleid = $companycourseeditorid;
$level->contextlevel = CONTEXT_SYSTEM;
$DB->insert_record('role_context_levels', $level);
}
// Create new Client Course Access role.
if (!($companycoursenoneditor = $DB->get_record('role', array('shortname' => 'companycoursenoneditor')))) {
$companycoursenoneditorid = create_role('Client Course Access', 'companycoursenoneditor', 'Iomad Client Course Access - similar to the non-editing teacher role for client admin');
} else {
$companycoursenoneditorid = $companycoursenoneditor->id;
}
// If not done already, allow assignment at system context.
$levels = get_role_contextlevels($clientadministratorid);
if (empty($levels)) {
$level = null;
$level->roleid = $clientadministratorid;
$level->contextlevel = CONTEXT_SYSTEM;
$DB->insert_record('role_context_levels', $level);
}
// Add capabilities to above.
$clientadministratorcaps = array('local/iomad_dashboard:view', 'block/iomad_company_admin:assign_company_manager', 'block/iomad_company_admin:assign_department_manager', 'block/iomad_company_admin:company_add', 'block/iomad_company_admin:company_course_users', 'block/iomad_company_admin:company_delete', 'block/iomad_company_admin:company_edit', 'block/iomad_company_admin:company_manager', 'block/iomad_company_admin:company_user', 'block/iomad_company_admin:createcourse', 'block/iomad_company_admin:user_create', 'block/iomad_company_admin:user_upload', 'block/iomad_company_admin:view', 'block/iomad_company_admin:restrict_capabilities', 'block/iomad_link:view', 'block/iomad_online_users:viewlist', 'block/iomad_reports:view', 'local/report_attendance:view', 'local/report_completion:view', 'local/report_users:view', 'local/report_scorm_overview:view');
foreach ($clientadministratorcaps as $cap) {
assign_capability($cap, CAP_ALLOW, $clientadministratorid, $systemcontext->id);
}
$companydepartmentmanagercaps = array('block/iomad_report:view', 'local/iomad_dashboard:view', 'block/iomad_online_users:viewlist', 'block/iomad_link:view', 'block/iomad_company_admin:view_licenses', 'block/iomad_company_admin:view', 'block/iomad_company_admin:user_upload', 'block/iomad_company_admin:user_create', 'block/iomad_company_admin:editusers', 'block/iomad_company_admin:edit_departments', 'block/iomad_company_admin:company_view', 'block/iomad_company_admin:company_course_users', 'block/iomad_company_admin:assign_department_manager', 'block/iomad_company_admin:allocate_licenses', 'block/iomad_reports:view', 'local/report_attendance:view', 'local/report_completion:view', 'local/report_users:view', 'local/report_scorm_overview:view');
foreach ($companydepartmentmanagercaps as $cap) {
assign_capability($cap, CAP_ALLOW, $companydepartmentmanagerid, $systemcontext->id);
}
$companymanagercaps = array('local/iomad_dashboard:view', 'block/iomad_online_users:viewlist', 'block/iomad_link:view', 'block/iomad_company_admin:view_licenses', 'block/iomad_company_admin:view', 'block/iomad_company_admin:user_upload', 'block/iomad_company_admin:user_create', 'block/iomad_company_admin:editusers', 'block/iomad_company_admin:edit_departments', 'block/iomad_company_admin:company_view', 'block/iomad_company_admin:company_course_users', 'block/iomad_company_admin:assign_department_manager', 'block/iomad_company_admin:allocate_licenses', 'block/iomad_company_admin:assign_company_manager', 'block/iomad_company_admin:classrooms', 'block/iomad_company_admin:classrooms_add', 'block/iomad_company_admin:classrooms_delete', 'block/iomad_company_admin:classrooms_edit', 'block/iomad_company_admin:company_edit', 'block/iomad_company_admin:company_course_unenrol', 'block/iomad_company_admin:company_manager', 'block/iomad_company_admin:company_user_profiles', 'block/iomad_company_admin:createcourse', 'block/iomad_reports:view', 'local/report_attendance:view', 'local/report_completion:view', 'local/report_users:view', 'local/report_scorm_overview:view');
$companycoursenoneditorcaps = array('block/side_bar_block:viewblock', 'gradereport/grader:view', 'gradereport/user:view', 'mod/assignment:view', 'mod/book:read', 'mod/certificate:manage', 'mod/certificate:view', 'mod/choice:readresponses', 'mod/feedback:view', 'mod/forum:addquestion', 'mod/forum:createattachment', 'mod/forum:deleteownpost', 'mod/forum:replypost', 'mod/forum:startdiscussion', 'mod/forum:viewdiscussion', 'mod/forum:viewqandawithoutposting', 'mod/page:view', 'mod/quiz:attempt', 'mod/quiz:view', 'mod/resource:view', 'mod/survey:participate', 'mod/trainingevent:add`', 'mod/trainingevent:grade', 'mod/trainingevent:viewattendees', 'moodle/block:view', 'moodle/grade:viewall', 'moodle/site:viewfullnames', 'moodle/site:viewuseridentity');
$companycourseeditorcaps = array('block/side_bar_block:editblock', 'block/side_bar_block:viewblock', 'booktool/importhtml:import', 'booktool/print:print', 'enrol/authorize:manage', 'enrol/license:manage', 'enrol/license:unenrol', 'enrol/manual:enrol', 'enrol/manual:unenrol', 'gradereport/grader:view', 'gradereport/overview:view', 'gradereport/user:view', 'mod/assignment:exportownsubmission', 'mod/assignment:grade', 'mod/assignment:view', 'mod/book:edit', 'mod/book:read', 'mod/book:viewhiddenchapters', 'mod/certificate:manage', 'mod/certificate:view', 'mod/choice:choose', 'mod/choice:deleteresponses', 'mod/choice:downloadresponses', 'mod/choice:readresponses', 'mod/trainingevent:add`', 'mod/trainingevent:grade', 'mod/trainingevent:invite', 'mod/trainingevent:viewattendees', 'mod/forum:addnews', 'mod/forum:addquestion', 'mod/forum:createattachment', 'mod/forum:deleteanypost', 'mod/forum:deleteownpost', 'mod/forum:editanypost', 'mod/forum:exportdiscussion', 'mod/forum:exportownpost', 'mod/forum:exportpost', 'mod/forum:managesubscriptions', 'mod/forum:movediscussions', 'mod/forum:postwithoutthrottling', 'mod/forum:rate', 'mod/forum:replynews', 'mod/forum:replypost', 'mod/forum:splitdiscussions', 'mod/forum:startdiscussion', 'mod/forum:viewallratings', 'mod/forum:viewanyrating', 'mod/forum:viewdiscussion', 'mod/forum:viewhiddentimedposts', 'mod/forum:viewqandawithoutposting', 'mod/forum:viewrating', 'mod/forum:viewsubscribers', 'mod/page:view', 'mod/resource:view', 'mod/scorm:deleteresponses', 'mod/scorm:savetrack', 'mod/scorm:viewreport', 'mod/scorm:viewscores', 'mod/url:view', 'moodle/block:edit', 'moodle/block:view', 'moodle/calendar:manageentries', 'moodle/calendar:managegroupentries', 'moodle/calendar:manageownentries', 'moodle/course:activityvisibility', 'moodle/course:changefullname', 'moodle/course:changesummary', 'moodle/course:manageactivities', 'moodle/course:managefiles', 'moodle/course:managegroups', 'moodle/course:markcomplete', 'moodle/course:reset', 'moodle/course:sectionvisibility', 'moodle/course:setcurrentsection', 'moodle/course:update', 'moodle/course:viewhiddenactivities', 'moodle/course:viewhiddensections', 'moodle/course:viewparticipants', 'moodle/grade:edit', 'moodle/grade:hide', 'moodle/grade:lock', 'moodle/grade:manage', 'moodle/grade:managegradingforms', 'moodle/grade:manageletters', 'moodle/grade:manageoutcomes', 'moodle/grade:unlock', 'moodle/grade:viewall', 'moodle/grade:viewhidden', 'moodle/notes:manage', 'moodle/notes:view', 'moodle/rating:rate', 'moodle/rating:view', 'moodle/rating:viewall', 'moodle/rating:viewany', 'moodle/role:switchroles', 'moodle/site:accessallgroups', 'moodle/site:manageblocks', 'moodle/site:trustcontent', 'moodle/site:viewfullnames', 'moodle/site:viewreports', 'moodle/site:viewuseridentity', 'moodle/user:viewdetails', 'report/courseoverview:view', 'report/log:view', 'report/log:viewtoday', 'report/loglive:view', 'report/outline:view', 'report/participation:view', 'report/progress:view');
foreach ($companymanagercaps as $cap) {
assign_capability($cap, CAP_ALLOW, $companymanagerid, $systemcontext->id);
}
foreach ($companycourseeditorcaps as $rolecapability) {
// Assign_capability will update rather than insert if capability exists.
assign_capability($rolecapability, CAP_ALLOW, $companycourseeditorid, $systemcontext->id);
}
foreach ($companycoursenoneditorcaps as $rolecapability) {
// Assign_capability will update rather than insert if capability exists.
assign_capability($rolecapability, CAP_ALLOW, $companycoursenoneditorid, $systemcontext->id);
}
// Create custom user field for company (if not already existing).
if (!$DB->get_record('user_info_field', array('shortname' => 'company'))) {
$field = new stdClass();
//.........这里部分代码省略.........