public function canInRoles($permission, $requireAll = false)
{
if (is_array($permission)) {
foreach ($permission as $permName) {
$hasPerm = $this->can($permName);
if ($hasPerm && !$requireAll) {
return true;
} elseif (!$hasPerm && $requireAll) {
return false;
}
}
// If we've made it this far and $requireAll is FALSE, then NONE of the perms were found
// If we've made it this far and $requireAll is TRUE, then ALL of the perms were found.
// Return the value of $requireAll;
return $requireAll;
} else {
// Users of the 'admin' role cab do it all.
// TODO: Get 'admins' role name from config, and replace all occurrences.
if ($this->hasRole('admins')) {
return true;
} else {
foreach ($this->roles as $role) {
if ($role->enabled) {
// Validate against the Permission table
foreach ($role->perms as $perm) {
if ($perm->enabled && $perm->name == $permission) {
return true;
}
}
}
}
}
}
return false;
}