The user roles */ #[ORM\Column] private array $roles = []; /** * @var string The hashed password */ #[ORM\Column] private ?string $password = null; /** * @var Collection */ #[ORM\ManyToMany(targetEntity: UserGroup::class, mappedBy: 'users')] private Collection $userGroups; /** * @var Collection */ #[ORM\ManyToMany(targetEntity: OrganizationalUnit::class, inversedBy: 'users')] private Collection $allowedOrganizationalUnits; private ?string $currentPassword = null; private ?string $newPassword = null; private ?string $repeatNewPassword = null; public function __construct() { parent::__construct(); $this->userGroups = new ArrayCollection(); $this->allowedOrganizationalUnits = new ArrayCollection(); } public function getUsername(): ?string { return $this->username; } public function setUsername(string $username): static { $this->username = $username; return $this; } /** * A visual identifier that represents this user. * * @see UserInterface */ public function getUserIdentifier(): string { return (string) $this->username; } /** * @see UserInterface * * @return list */ public function getRoles(): array { $roles = $this->roles; if (!array_search(self::ROLE_USER, $roles, true)){ $roles[] = self::ROLE_USER; } foreach ($this->getUserGroups() as $userGroup) { if ($userGroup->isEnabled()){ $roles = array_merge($roles, $userGroup->getPermissions()); } } return array_merge(array_unique($roles)); } /** * @param list $roles */ public function setRoles(array $roles): static { $this->roles = $roles; return $this; } /** * @see PasswordAuthenticatedUserInterface */ public function getPassword(): string { return $this->password; } public function setPassword(string $password): static { $this->password = $password; return $this; } /** * @see UserInterface */ public function eraseCredentials(): void { // If you store any temporary, sensitive data on the user, clear it here // $this->plainPassword = null; } /** * @return Collection */ public function getUserGroups(): Collection { return $this->userGroups; } public function setUserGroups(array $userGroup): static { $this->userGroups->clear(); foreach ($userGroup as $group){ $this->addUserGroup($group); } return $this; } public function addUserGroup(UserGroup $userGroup): static { if (!$this->userGroups->contains($userGroup)) { $this->userGroups->add($userGroup); $userGroup->addUser($this); } return $this; } public function removeUserGroup(UserGroup $userGroup): static { if ($this->userGroups->removeElement($userGroup)) { $userGroup->removeUser($this); } return $this; } /** * @return Collection */ public function getAllowedOrganizationalUnits(): Collection { return $this->allowedOrganizationalUnits; } public function setAllowedOrganizationalUnits(array $allowedOrganizationalUnits): static { $this->allowedOrganizationalUnits->clear(); foreach ($allowedOrganizationalUnits as $allowedOrganizationalUnit){ $this->addAllowedOrganizationalUnit($allowedOrganizationalUnit); } return $this; } public function addAllowedOrganizationalUnit(OrganizationalUnit $allowedOrganizationalUnit): static { if (!$this->allowedOrganizationalUnits->contains($allowedOrganizationalUnit)) { $this->allowedOrganizationalUnits->add($allowedOrganizationalUnit); } return $this; } public function removeAllowedOrganizationalUnit(OrganizationalUnit $allowedOrganizationalUnit): static { $this->allowedOrganizationalUnits->removeElement($allowedOrganizationalUnit); return $this; } public function getCurrentPassword(): ?string { return $this->currentPassword; } public function setCurrentPassword(?string $currentPassword): static { $this->currentPassword = $currentPassword; return $this; } public function getNewPassword(): ?string { return $this->newPassword; } public function setNewPassword(?string $newPassword): static { $this->newPassword = $newPassword; return $this; } public function getRepeatNewPassword(): ?string { return $this->repeatNewPassword; } public function setRepeatNewPassword(?string $repeatNewPassword): static { $this->repeatNewPassword = $repeatNewPassword; return $this; } }