mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
MDL-11143, adding a new setting "defaultfrontpageroleid" where you choose a role for all users on the front page
This commit is contained in:
parent
5dec234de7
commit
4e1fe7d109
@ -40,6 +40,17 @@ $ADMIN->add('frontpage', new admin_externalpage('frontpagebackup', get_string('f
|
||||
|
||||
$ADMIN->add('frontpage', new admin_externalpage('frontpagerestore', get_string('frontpagerestore', 'admin'), $CFG->wwwroot.'/files/index.php?id='.SITEID.'&wdir=/backupdata', 'moodle/site:restore', false, $frontpagecontext));
|
||||
|
||||
// front page default role
|
||||
$temp = new admin_settingpage('frontpagedefaultrole', get_string('frontpagedefaultrole', 'admin'), 'moodle/site:config', false, get_context_instance(CONTEXT_SYSTEM));
|
||||
$roleoptions = array(0=>'N/A'); // roles to choose from
|
||||
if ($roles = get_records('role')) {
|
||||
foreach ($roles as $role) {
|
||||
$roleoptions[$role->id] = $role->name;
|
||||
}
|
||||
}
|
||||
$temp->add(new admin_setting_configselect('defaultfrontpageroleid', get_string('frontpagedefaultrole', 'admin'), '', '', $roleoptions));
|
||||
$ADMIN->add('frontpage', $temp);
|
||||
|
||||
$ADMIN->add('frontpage', new admin_externalpage('sitefiles', get_string('sitefiles'), $CFG->wwwroot . '/files/index.php?id=' . SITEID, 'moodle/course:managefiles', false, $frontpagecontext));
|
||||
|
||||
?>
|
@ -242,6 +242,46 @@ function get_role_access($roleid, $accessdata=NULL) {
|
||||
return $accessdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the accessdata for role "sitewide"
|
||||
* (system down to course)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_default_frontpage_role_access($roleid, $accessdata=NULL) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
|
||||
$base = '/'. SYSCONTEXTID .'/'. $frontpagecontext->id;
|
||||
|
||||
//
|
||||
// Overrides for the role in any contexts related to the course
|
||||
//
|
||||
$sql = "SELECT ctx.path,
|
||||
rc.capability, rc.permission
|
||||
FROM {$CFG->prefix}context ctx
|
||||
JOIN {$CFG->prefix}role_capabilities rc
|
||||
ON rc.contextid=ctx.id
|
||||
WHERE rc.roleid = {$roleid}
|
||||
AND (ctx.id = ".SYSCONTEXTID." OR ctx.path LIKE '$base/%')
|
||||
ORDER BY ctx.depth, ctx.path";
|
||||
|
||||
if ($rs = get_recordset_sql($sql)) {
|
||||
if ($rs->RecordCount()) {
|
||||
while ($rd = rs_fetch_next_record($rs)) {
|
||||
$k = "{$rd->path}:{$roleid}";
|
||||
$accessdata['rdef'][$k][$rd->capability] = $rd->permission;
|
||||
}
|
||||
unset($rd);
|
||||
}
|
||||
rs_close($rs);
|
||||
}
|
||||
|
||||
return $accessdata;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the id for the not-logged-in role - or set it up if needed
|
||||
* @return bool
|
||||
@ -1514,7 +1554,19 @@ function load_user_accessdata($userid) {
|
||||
}
|
||||
$accessdata['dr'] = $CFG->defaultuserroleid;
|
||||
|
||||
$ACCESS[$userid] = $accessdata;
|
||||
//
|
||||
// provide "default frontpage role"
|
||||
//
|
||||
if ($CFG->defaultfrontpageroleid) {
|
||||
$base = '/'. SYSCONTEXTID .'/'. $frontpagecontext->id;
|
||||
$accessdata = get_default_frontpage_role_access($CFG->defaultfrongpageroleid, $accessdata);
|
||||
if (!isset($accessdata['ra'][$base])) {
|
||||
$accessdata['ra'][$base] = array($CFG->defaultfrongpageroleid);
|
||||
} else {
|
||||
array_push($accessdata['ra'][$base], $CFG->defaultfrongpageroleid);
|
||||
}
|
||||
}
|
||||
$ACCESS[$userid] = $accessdata;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1553,8 +1605,23 @@ function load_all_capabilities() {
|
||||
}
|
||||
$accessdata['dr'] = $CFG->defaultuserroleid;
|
||||
|
||||
$USER->access = $accessdata;
|
||||
$frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
|
||||
|
||||
//
|
||||
// provide "default frontpage role"
|
||||
//
|
||||
|
||||
if ($CFG->defaultfrontpageroleid) {
|
||||
$base = '/'. SYSCONTEXTID .'/'. $frontpagecontext->id;
|
||||
$accessdata = get_default_frontpage_role_access($CFG->defaultfrontpageroleid, $accessdata);
|
||||
if (!isset($accessdata['ra'][$base])) {
|
||||
$accessdata['ra'][$base] = array($CFG->defaultfrontpageroleid);
|
||||
} else {
|
||||
array_push($accessdata['ra'][$base], $CFG->defaultfrontpageroleid);
|
||||
}
|
||||
}
|
||||
$USER->access = $accessdata;
|
||||
|
||||
} else {
|
||||
if ($roleid = get_notloggedin_roleid()) {
|
||||
$USER->access = get_role_access($roleid);
|
||||
|
Loading…
x
Reference in New Issue
Block a user