src/Entity/User.php line 28
<?php/** @author Guerby Duval <info@tranzaksyon.com>* @link https://tranzaksyon.com* @copyright You are not allowed to remove this author "Guerby Duval <info@tranzaksyon.com>", the link "https://tranzaksyon.com" neither this copyright.*/namespace App\Entity;use App\Interfaces\OwnerCompanyInterface;use App\Repository\UserRepository;use App\RoleUtils;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;use Symfony\Component\Security\Core\User\UserInterface;use Symfony\Component\Serializer\Annotation\Groups;use Symfony\Component\Validator\Constraints\Count;use Symfony\Component\Validator\Constraints\Email;use Symfony\Component\Validator\Constraints\Length;use Symfony\Component\Validator\Constraints\NotBlank;#[ORM\Entity(repositoryClass: UserRepository::class)]#[UniqueEntity('email')]#[UniqueEntity('username')]class User implements UserInterface, PasswordAuthenticatedUserInterface, OwnerCompanyInterface{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]#[Groups(['user_out'])]private ?int $id = null;#[ORM\Column(length: 180, unique: true)]#[NotBlank]#[Groups(['user_out'])]private ?string $username = null;#[ORM\Column]#[NotBlank(groups: ['employee-create'])]#[Count(min: 1, groups: ['employee-create'])]#[Groups(['user_out'])]private array $roles = [];/*** @var string The hashed password*/#[ORM\Column]#[NotBlank(groups: ["new-user"])]#[Length(min: 8, groups: ["new-user"])]private ?string $password = null;#[ORM\Column(length: 80, unique: true)]#[Email]#[NotBlank]#[Groups(['user_out'])]private ?string $email = null;#[ORM\Column(length: 100)]#[NotBlank]#[Groups(['user_out'])]private ?string $name = null;#[ORM\Column(length: 100)]#[NotBlank]#[Groups(['user_out'])]private ?string $lastname = null;#[ORM\OneToMany(mappedBy: 'user', targetEntity: SriInfo::class, orphanRemoval: true)]private Collection $sriInfos;#[ORM\OneToMany(mappedBy: 'user', targetEntity: Invoice::class)]private Collection $invoices;#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'disabledUsers')]#[ORM\JoinColumn(onDelete: 'SET NULL')]private ?self $disabledBy = null;#[ORM\OneToMany(mappedBy: 'disabledBy', targetEntity: self::class)]private Collection $disabledUsers;#[ORM\OneToMany(mappedBy: 'disabledBy', targetEntity: SriInfo::class)]private Collection $disableCompanies;#[ORM\Column(length: 2000, nullable: true)]private ?string $resetPasswordKey = null;#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Company::class, orphanRemoval: true)]private Collection $companies;public function __construct(){$this->sriInfos = new ArrayCollection();$this->invoices = new ArrayCollection();$this->disabledUsers = new ArrayCollection();$this->disableCompanies = new ArrayCollection();$this->companies = new ArrayCollection();}public function getId(): ?int{return $this->id;}public function getUsername(): ?string{return $this->username;}public function setUsername(string $username): self{$this->username = $username;return $this;}/*** A visual identifier that represents this user.** @see UserInterface*/public function getUserIdentifier(): string{return (string)$this->username;}/*** @see UserInterface*/public function getRoles(): array{$roles = $this->roles;// guarantee every user at least has ROLE_USER$roles[] = 'ROLE_USER';return array_unique($roles);}public function setRoles(array $roles): self{$this->roles = $roles;return $this;}/*** @see PasswordAuthenticatedUserInterface*/public function getPassword(): string{return $this->password;}public function setPassword(string $password): self{$this->password = $password;return $this;}/*** @see UserInterface*/public function eraseCredentials(){// If you store any temporary, sensitive data on the user, clear it here// $this->plainPassword = null;}public function getEmail(): ?string{return $this->email;}public function setEmail(string $email): self{$this->email = $email;return $this;}public function getName(): ?string{return $this->name;}public function setName(string $name): self{$this->name = $name;return $this;}public function getLastname(): ?string{return $this->lastname;}public function setLastname(string $lastname): self{$this->lastname = $lastname;return $this;}public function canonicalRoles(){return RoleUtils::canonicalizeRoles($this->getRoles());}/*** @return Collection<int, SriInfo>*/public function getSriInfos(): Collection{return $this->sriInfos;}public function addSriInfo(SriInfo $sriInfo): self{if (!$this->sriInfos->contains($sriInfo)) {$this->sriInfos->add($sriInfo);$sriInfo->setUser($this);}return $this;}public function removeSriInfo(SriInfo $sriInfo): self{if ($this->sriInfos->removeElement($sriInfo)) {// set the owning side to null (unless already changed)if ($sriInfo->getUser() === $this) {$sriInfo->setUser(null);}}return $this;}/*** @return Collection<int, Invoice>*/public function getInvoices(): Collection{return $this->invoices;}public function addInvoice(Invoice $invoice): self{if (!$this->invoices->contains($invoice)) {$this->invoices->add($invoice);$invoice->setUser($this);}return $this;}public function removeInvoice(Invoice $invoice): self{if ($this->invoices->removeElement($invoice)) {// set the owning side to null (unless already changed)if ($invoice->getUser() === $this) {$invoice->setUser(null);}}return $this;}public function getDisabledBy(): ?self{return $this->disabledBy;}public function setDisabledBy(?self $disabledBy): self{$this->disabledBy = $disabledBy;return $this;}/*** @return Collection<int, self>*/public function getDisabledUsers(): Collection{return $this->disabledUsers;}public function addDisabledUser(self $disabledUser): self{if (!$this->disabledUsers->contains($disabledUser)) {$this->disabledUsers->add($disabledUser);$disabledUser->setDisabledBy($this);}return $this;}public function removeDisabledUser(self $disabledUser): self{if ($this->disabledUsers->removeElement($disabledUser)) {// set the owning side to null (unless already changed)if ($disabledUser->getDisabledBy() === $this) {$disabledUser->setDisabledBy(null);}}return $this;}/*** @return Collection<int, SriInfo>*/public function getDisableCompanies(): Collection{return $this->disableCompanies;}public function addDisableCompany(SriInfo $disableCompany): self{if (!$this->disableCompanies->contains($disableCompany)) {$this->disableCompanies->add($disableCompany);$disableCompany->setDisabledBy($this);}return $this;}public function removeDisableCompany(SriInfo $disableCompany): self{if ($this->disableCompanies->removeElement($disableCompany)) {// set the owning side to null (unless already changed)if ($disableCompany->getDisabledBy() === $this) {$disableCompany->setDisabledBy(null);}}return $this;}public function getResetPasswordKey(): ?string{return $this->resetPasswordKey;}public function setResetPasswordKey(?string $resetPasswordKey): self{$this->resetPasswordKey = $resetPasswordKey;return $this;}public function getSriInfo(): ?SriInfo{if ($this->sriInfos->count() === 0) {return null;}return $this->sriInfos[0];}/*** @return Collection<int, Company>*/public function getCompanies(): Collection{return $this->companies;}public function addCompany(Company $company): static{if (!$this->companies->contains($company)) {$this->companies->add($company);$company->setOwner($this);}return $this;}public function removeCompany(Company $company): static{if ($this->companies->removeElement($company)) {// set the owning side to null (unless already changed)if ($company->getOwner() === $this) {$company->setOwner(null);}}return $this;}}