*/ #[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'roles')] protected Collection $users; /** @var Collection */ #[ OA\Property(type: "array", items: new OA\Items()), ORM\OneToMany(mappedBy: 'role', targetEntity: RolePermission::class) ] protected Collection $permissions; public function __construct() { $this->users = new ArrayCollection(); $this->permissions = new ArrayCollection(); } public function getName(): string { return $this->name; } public function setName(string $name): void { $this->name = $this->truncateString($name, 100); } /** * @return Collection */ public function getUsers(): Collection { return $this->users; } /** * @return Collection */ public function getPermissions(): Collection { return $this->permissions; } /** * @return mixed[] */ public function jsonSerialize(): array { $return = [ 'id' => $this->id, 'name' => $this->name, 'permissions' => [ 'global' => [], 'station' => [], ], ]; foreach ($this->permissions as $permission) { /** @var RolePermission $permission */ $station = $permission->getStation(); if (null !== $station) { $return['permissions']['station'][$station->getIdRequired()][] = $permission->getActionName(); } else { $return['permissions']['global'][] = $permission->getActionName(); } } return $return; } public function __toString(): string { return $this->name; } }