$centerA, 'permissionsGroup' => array( * 'role' => 'CHILL_REPORT_SEE', 'scope' => $scopeA * ), * array( 'center' => $centerB, 'permissionsGroup' => array( * 'role' => 'CHILL_ACTIVITY_UPDATE', 'scope' => $scopeB * ) * ) * ``` * Scope must be an int. Scope created have this int as id, and the * int converted to string as name. * * @param array $permissions an array of permissions, with key 'center' for the center and key 'attrs' for an array of ['role' => (string), 'scope' => (int)] * * @throws LogicException if the trait is not set up * * @return User */ protected function prepareUser(array $permissions) { $user = new User(); foreach ($permissions as $permission) { $groupCenter = (new GroupCenter()) ->setCenter($permission['center']); $permissionGroup = new PermissionsGroup(); foreach ($permission['permissionsGroup'] as $pg) { $roleScope = (new RoleScope()) ->setRole($pg['role']) ->setScope($pg['scope']); $permissionGroup->addRoleScope($roleScope); } $groupCenter->setPermissionsGroup($permissionGroup); $user->addGroupCenter($groupCenter); } return $user; } }