protected getInheritedPermissionsByUser ( string | integer $userId ) : |
||
$userId | string | integer | the user ID (see [[\yii\web\User::id]]) |
return | all inherited permissions that the user has. The array is indexed by the permission names. |
protected function getInheritedPermissionsByUser($userId)
{
$assignments = $this->getAssignments($userId);
$result = [];
foreach (array_keys($assignments) as $roleName) {
$this->getChildrenRecursive($roleName, $result);
}
if (empty($result)) {
return [];
}
$permissions = [];
foreach (array_keys($result) as $itemName) {
if (isset($this->items[$itemName]) && $this->items[$itemName] instanceof Permission) {
$permissions[$itemName] = $this->items[$itemName];
}
}
return $permissions;
}