MDL-68402 accesslib: fix coding style of loops

This commit is contained in:
Tim Hunt 2020-05-06 09:14:49 +01:00
parent 1736c59925
commit 1ed243c2fe

View File

@ -776,7 +776,7 @@ function has_capability_in_accessdata($capability, context $context, array &$acc
// Build $paths as a list of current + all parent "paths" with order bottom-to-top
$path = $context->path;
$paths = array($path);
while($path = rtrim($path, '0123456789')) {
while ($path = rtrim($path, '0123456789')) {
$path = rtrim($path, '/');
if ($path === '') {
break;
@ -1106,7 +1106,7 @@ function remove_temp_course_roles(context_course $coursecontext) {
$ras = $DB->get_records_sql($sql, array('contextid'=>$coursecontext->id, 'userid'=>$USER->id));
$USER->access['ra'][$coursecontext->path] = array();
foreach($ras as $r) {
foreach ($ras as $r) {
$USER->access['ra'][$coursecontext->path][(int)$r->id] = (int)$r->id;
}
}
@ -1663,7 +1663,7 @@ function role_unassign_all(array $params, $subcontexts = false, $includemanual =
}
$ras = $DB->get_records('role_assignments', $params);
foreach($ras as $ra) {
foreach ($ras as $ra) {
$DB->delete_records('role_assignments', array('id'=>$ra->id));
if ($context = context::instance_by_id($ra->contextid, IGNORE_MISSING)) {
// Role assignments have changed, so mark user as dirty.
@ -1697,10 +1697,10 @@ function role_unassign_all(array $params, $subcontexts = false, $includemanual =
if ($context) {
$contexts = $context->get_child_contexts();
$mparams = $params;
foreach($contexts as $context) {
foreach ($contexts as $context) {
$mparams['contextid'] = $context->id;
$ras = $DB->get_records('role_assignments', $mparams);
foreach($ras as $ra) {
foreach ($ras as $ra) {
$DB->delete_records('role_assignments', array('id'=>$ra->id));
// Role assignments have changed, so mark user as dirty.
mark_user_dirty($ra->userid);
@ -1978,7 +1978,7 @@ function can_access_course(stdClass $course, $user = null, $withcapability = '',
// if not enrolled try to gain temporary guest access
$instances = $DB->get_records('enrol', array('courseid'=>$course->id, 'status'=>ENROL_INSTANCE_ENABLED), 'sortorder, id ASC');
$enrols = enrol_get_plugins(true);
foreach($instances as $instance) {
foreach ($instances as $instance) {
if (!isset($enrols[$instance->enrol])) {
continue;
}
@ -2067,7 +2067,7 @@ function get_default_capabilities($archetype) {
$alldefs = array_merge($alldefs, load_capability_def($cap['component']));
}
}
foreach($alldefs as $name=>$def) {
foreach ($alldefs as $name=>$def) {
// Use array 'archetypes if available. Only if not specified, use 'legacy'.
if (isset($def['archetypes'])) {
if (isset($def['archetypes'][$archetype])) {
@ -2188,7 +2188,7 @@ function reset_role_capabilities($roleid) {
$DB->delete_records('role_capabilities',
array('roleid' => $roleid, 'contextid' => $systemcontext->id));
foreach($defaultcaps as $cap=>$permission) {
foreach ($defaultcaps as $cap=>$permission) {
assign_capability($cap, $permission, $roleid, $systemcontext->id);
}
@ -2215,7 +2215,7 @@ function update_capabilities($component = 'moodle') {
$storedcaps = array();
$filecaps = load_capability_def($component);
foreach($filecaps as $capname=>$unused) {
foreach ($filecaps as $capname=>$unused) {
if (!preg_match('|^[a-z]+/[a-z_0-9]+:[a-z_0-9]+$|', $capname)) {
debugging("Coding problem: Invalid capability name '$capname', use 'clonepermissionsfrom' field for migration.");
}
@ -2345,7 +2345,7 @@ function capabilities_cleanup($component, $newcapdef = null) {
// Delete from roles.
if ($roles = get_roles_with_capability($cachedcap->name)) {
foreach($roles as $role) {
foreach ($roles as $role) {
if (!unassign_capability($cachedcap->name, $role->id)) {
print_error('cannotunassigncap', 'error', '', (object)array('cap'=>$cachedcap->name, 'role'=>$role->name));
}
@ -3496,7 +3496,7 @@ function get_with_capability_join(context $context, $capability, $useridcolumn)
if (empty($defs[$cap][$path])) {
continue;
}
foreach($defs[$cap][$path] as $roleid => $perm) {
foreach ($defs[$cap][$path] as $roleid => $perm) {
if ($perm == CAP_PROHIBIT) {
$access[$cap][$roleid] = CAP_PROHIBIT;
continue;
@ -4105,7 +4105,7 @@ function get_user_capability_course($capability, $userid = null, $doanything = t
$fieldlist = '';
if ($fieldsexceptid) {
$fields = array_map('trim', explode(',', $fieldsexceptid));
foreach($fields as $field) {
foreach ($fields as $field) {
// Context fields have a different alias.
if (strpos($field, 'ctx') === 0) {
switch($field) {
@ -4128,7 +4128,7 @@ function get_user_capability_course($capability, $userid = null, $doanything = t
if ($orderby) {
$fields = explode(',', $orderby);
$orderby = '';
foreach($fields as $field) {
foreach ($fields as $field) {
if ($orderby) {
$orderby .= ',';
}
@ -4618,7 +4618,7 @@ function get_roles_with_cap_in_context($context, $capability) {
$forbidden = array();
$needed = array();
foreach($capdefs as $def) {
foreach ($capdefs as $def) {
if (isset($forbidden[$def->roleid])) {
continue;
}
@ -4638,7 +4638,7 @@ function get_roles_with_cap_in_context($context, $capability) {
unset($capdefs);
// remove all those roles not allowing
foreach($needed as $key=>$value) {
foreach ($needed as $key=>$value) {
if (!$value) {
unset($needed[$key]);
} else {
@ -4660,7 +4660,7 @@ function get_roles_with_cap_in_context($context, $capability) {
function get_roles_with_caps_in_context($context, $capabilities) {
$neededarr = array();
$forbiddenarr = array();
foreach($capabilities as $caprequired) {
foreach ($capabilities as $caprequired) {
list($neededarr[], $forbiddenarr[]) = get_roles_with_cap_in_context($context, $caprequired);
}
@ -4774,7 +4774,7 @@ function role_change_permission($roleid, $context, $capname, $permission) {
ORDER BY ctx.depth DESC";
if ($existing = $DB->get_records_sql($sql, $params)) {
foreach($existing as $e) {
foreach ($existing as $e) {
if ($e->permission == CAP_PROHIBIT) {
// prohibit can not be overridden, no point in changing anything
return;
@ -4931,7 +4931,7 @@ abstract class context extends stdClass implements IteratorAggregate {
if (self::$cache_count >= CONTEXT_CACHE_MAX_SIZE) {
$i = 0;
foreach(self::$cache_contextsbyid as $ctx) {
foreach (self::$cache_contextsbyid as $ctx) {
$i++;
if ($i <= 100) {
// we want to keep the first contexts to be loaded on this page, hopefully they will be needed again later