src/Entity/User.php line 17

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Yaml\Yaml;
  11. use Symfony\Component\HttpKernel\KernelInterface;
  12. #[ORM\Entity(repositoryClassUserRepository::class)]
  13. #[ORM\Table(name"user")]
  14. #[UniqueEntity(
  15.     fields: ['email'],
  16.     message'An account with this email already exists. Try logging in, or reset your password.'
  17. )]
  18. class User implements UserInterfacePasswordAuthenticatedUserInterface
  19. {
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column(type"integer")]
  23.     private ?int $id null;
  24.     #[ORM\Column(type"string"length180uniquetrue)]
  25.     private string $email;
  26.     #[ORM\Column(length255nullabletrue)]
  27.     private ?string $email2 null;
  28.     #[ORM\Column(type'string'length255nullabletrue)]
  29.     private ?string $email3 null;
  30.     #[ORM\Column(type'boolean'nullabletrue)]
  31.     private ?bool $emailVerified null;
  32.     #[ORM\ManyToMany(targetEntityRole::class, inversedBy'users')]
  33.     #[ORM\JoinTable(name'user_role')]
  34.     private Collection $roles;
  35.     #[ORM\Column(type'string')]
  36.     private string $password;
  37.     #[ORM\Column(type'string'length255nullabletrue)]
  38.     private ?string $salutation null;
  39.     #[ORM\Column(type'string'length255nullabletrue)]
  40.     private ?string $firstName null;
  41.     #[ORM\Column(type'string'length255nullabletrue)]
  42.     private ?string $lastName null;
  43.     #[ORM\Column(type'string'length255nullabletrue)]
  44.     private ?string $fullName null;
  45.     #[ORM\Column(type'string'length255nullabletrue)]
  46.     private ?string $mobile null;
  47.     #[ORM\Column(type'string'length255nullabletrue)]
  48.     private ?string $mobile2 null;
  49.     #[ORM\Column(type'string'length255nullabletrue)]
  50.     private ?string $plainPassword null;
  51.     #[ORM\OneToMany(targetEntityLog::class, mappedBy'user'orphanRemovaltrue)]
  52.     private Collection $logs;
  53.     #[ORM\Column(type'string'length255nullabletrue)]
  54.     private ?string $company null;
  55.     #[ORM\Column(type'date'nullabletrue)]
  56.     private ?\DateTimeInterface $birthday null;
  57.     #[ORM\Column(type'string'length255nullabletrue)]
  58.     private ?string $webPage null;
  59.     #[ORM\Column(type'text'nullabletrue)]
  60.     private ?string $notes null;
  61.     #[ORM\Column(type'string'length255nullabletrue)]
  62.     private ?string $jobTitle null;
  63.     #[ORM\Column(type'string'length255nullabletrue)]
  64.     private ?string $linkedIn null;
  65.     #[ORM\Column(type'string'length255nullabletrue)]
  66.     private ?string $businessPhone null;
  67.     #[ORM\Column(type'string'length255nullabletrue)]
  68.     private ?string $businessStreet null;
  69.     #[ORM\Column(type'string'length255nullabletrue)]
  70.     private ?string $businessCity null;
  71.     #[ORM\Column(type'string'length255nullabletrue)]
  72.     private ?string $businessPostalCode null;
  73.     #[ORM\Column(type'string'length255nullabletrue)]
  74.     private ?string $businessCountry null;
  75.     #[ORM\Column(type'string'length255nullabletrue)]
  76.     private ?string $homePhone null;
  77.     #[ORM\Column(type'string'length255nullabletrue)]
  78.     private ?string $homePhone2 null;
  79.     #[ORM\Column(type'string'length255nullabletrue)]
  80.     private ?string $homeStreet null;
  81.     #[ORM\Column(type'string'length255nullabletrue)]
  82.     private ?string $homeCity null;
  83.     #[ORM\Column(type'string'length255nullabletrue)]
  84.     private ?string $homePostalCode null;
  85.     #[ORM\Column(type'string'length255nullabletrue)]
  86.     private ?string $homeCountry null;
  87.     #[ORM\ManyToOne]
  88.     private ?Languages $defaultLanguage null;
  89.     #[ORM\Column(length255nullabletrue)]
  90.     private ?string $photo null;
  91.     #[ORM\ManyToOne(inversedBy'recipient')]
  92.     private ?ClientEmailsSent $clientEmailsSent null;
  93.     /**
  94.      * Inverse side of the ManyToMany with PhotoLocations::enabledUsers
  95.      */
  96.     #[ORM\ManyToMany(targetEntityPhotoLocations::class, mappedBy'enabledUsers')]
  97.     private Collection $photoLocations;
  98.     #[ORM\Column(length255nullabletrue)]
  99.     private ?string $autoLoginURL null;
  100.     #[ORM\Column(type"boolean"nullabletrueoptions: ["default" => false])]
  101.     private ?bool $pauseForBookmark null;
  102.     public function __construct()
  103.     {
  104.         $this->roles = new ArrayCollection();
  105.         $this->logs = new ArrayCollection();
  106.         $this->photoLocations = new ArrayCollection();
  107.     }
  108.     // ---------- ID ----------
  109.     public function getId(): ?int
  110.     {
  111.         return $this->id;
  112.     }
  113.     // ---------- Identity / Auth ----------
  114.     public function getUserIdentifier(): string
  115.     {
  116.         return $this->email ?? '';
  117.     }
  118.     public function getEmail(): ?string
  119.     {
  120.         return $this->email ?? '';
  121.     }
  122.     public function setEmail(string $email): self
  123.     {
  124.         // normalize for consistent uniqueness
  125.         $this->email mb_strtolower(trim($email));
  126.         return $this;
  127.     }
  128.     public function getUsername(): string
  129.     {
  130.         return (string) $this->email;
  131.     }
  132.     public function getPassword(): string
  133.     {
  134.         return $this->password;
  135.     }
  136.     public function setPassword(string $password): self
  137.     {
  138.         $this->password $password;
  139.         return $this;
  140.     }
  141.     public function getSalt(): ?string
  142.     {
  143.         return null;
  144.     }
  145.     public function eraseCredentials(): void
  146.     {
  147.         // clear temp sensitive data if any
  148.     }
  149.     // ---------- Roles ----------
  150.     public function addRole(Role $role): self
  151.     {
  152.         if (!$this->roles->contains($role)) {
  153.             $this->roles->add($role);
  154.         }
  155.         return $this;
  156.     }
  157.     public function removeRole(Role $role): self
  158.     {
  159.         $this->roles->removeElement($role);
  160.         return $this;
  161.     }
  162.     public function getRoles(): array
  163.     {
  164.         $roles $this->roles->toArray();
  165.         $roleStrings array_map(fn($r) => $r->getCode(), $roles);
  166.         $roleStrings[] = 'ROLE_USER';
  167.         return array_unique($roleStrings);
  168.     }
  169.     public function setRoleEntities(iterable $roles): self
  170.     {
  171.         $rolesArray is_array($roles) ? $roles iterator_to_array($roles);
  172.         foreach ($this->roles as $existingRole) {
  173.             if (!in_array($existingRole$rolesArraytrue)) {
  174.                 $this->roles->removeElement($existingRole);
  175.             }
  176.         }
  177.         foreach ($rolesArray as $role) {
  178.             if (!$this->roles->contains($role)) {
  179.                 $this->roles->add($role);
  180.             }
  181.         }
  182.         return $this;
  183.     }
  184.     public function getRoleEntities(): Collection
  185.     {
  186.         return $this->roles;
  187.     }
  188.     // ---------- Profile fields ----------
  189.     public function getSalutation(): ?string { return $this->salutation; }
  190.     public function setSalutation(?string $salutation): self $this->salutation $salutation; return $this; }
  191.     public function getFirstName(): ?string { return $this->firstName; }
  192.     public function setFirstName(?string $firstName): self $this->firstName $firstName; return $this; }
  193.     public function getLastName(): ?string { return $this->lastName; }
  194.     public function setLastName(?string $lastName): self $this->lastName $lastName; return $this; }
  195.     public function getFullName(): ?string
  196.     {
  197.         return $this->fullName ?? ($this->getFirstName() . ' ' $this->getLastName());
  198.     }
  199.     public function setFullName(?string $fullName): self $this->fullName $fullName; return $this; }
  200.     public function getMobile(): ?string { return $this->mobile; }
  201.     public function setMobile(?string $mobile): self $this->mobile $mobile; return $this; }
  202.     public function getMobile2(): ?string { return $this->mobile2; }
  203.     public function setMobile2(?string $mobile2): self $this->mobile2 $mobile2; return $this; }
  204.     public function getPlainPassword(): ?string { return $this->plainPassword; }
  205.     public function setPlainPassword(?string $plainPassword): self $this->plainPassword $plainPassword; return $this; }
  206.     // put near your other accessors
  207.     public function getEmail2(): ?string
  208.     {
  209.         return $this->email2;
  210.     }
  211.     public function setEmail2(?string $email2): self
  212.     {
  213.         $this->email2 $email2;
  214.         return $this;
  215.     }
  216.     public function getEmail3(): ?string
  217.     {
  218.         return $this->email3;
  219.     }
  220.     public function setEmail3(?string $email3): self
  221.     {
  222.         $this->email3 $email3;
  223.         return $this;
  224.     }
  225.     // ---------- Logs ----------
  226.     public function getLogs(): Collection { return $this->logs; }
  227.     public function addLog(Log $log): self
  228.     {
  229.         if (!$this->logs->contains($log)) {
  230.             $this->logs->add($log);
  231.             $log->setUser($this);
  232.         }
  233.         return $this;
  234.     }
  235.     public function removeLog(Log $log): self
  236.     {
  237.         if ($this->logs->removeElement($log)) {
  238.             if ($log->getUser() === $this) {
  239.                 $log->setUser(null);
  240.             }
  241.         }
  242.         return $this;
  243.     }
  244.     // ---------- Misc profile ----------
  245.     public function getCompany(): ?string { return $this->company; }
  246.     public function setCompany(?string $company): self $this->company $company; return $this; }
  247.     public function getBirthday(): ?\DateTimeInterface { return $this->birthday; }
  248.     public function setBirthday(?\DateTimeInterface $birthday): self $this->birthday $birthday; return $this; }
  249.     public function getWebPage(): ?string { return $this->webPage; }
  250.     public function setWebPage(?string $webPage): self $this->webPage $webPage; return $this; }
  251.     public function getNotes(): ?string { return $this->notes; }
  252.     public function setNotes(?string $notes): self $this->notes $notes; return $this; }
  253.     public function getJobTitle(): ?string { return $this->jobTitle; }
  254.     public function setJobTitle(?string $jobTitle): self $this->jobTitle $jobTitle; return $this; }
  255.     public function getLinkedIn(): ?string { return $this->linkedIn; }
  256.     public function setLinkedIn(?string $linkedIn): self $this->linkedIn $linkedIn; return $this; }
  257.     public function getBusinessPhone(): ?string { return $this->businessPhone; }
  258.     public function setBusinessPhone(?string $businessPhone): self $this->businessPhone $businessPhone; return $this; }
  259.     public function getBusinessStreet(): ?string { return $this->businessStreet; }
  260.     public function setBusinessStreet(?string $businessStreet): self $this->businessStreet $businessStreet; return $this; }
  261.     public function getBusinessCity(): ?string { return $this->businessCity; }
  262.     public function setBusinessCity(?string $businessCity): self $this->businessCity $businessCity; return $this; }
  263.     public function getBusinessPostalCode(): ?string { return $this->businessPostalCode; }
  264.     public function setBusinessPostalCode(?string $businessPostalCode): self $this->businessPostalCode $businessPostalCode; return $this; }
  265.     public function getBusinessCountry(): ?string { return $this->businessCountry; }
  266.     public function setBusinessCountry(?string $businessCountry): self $this->businessCountry $businessCountry; return $this; }
  267.     public function getHomePhone(): ?string { return $this->homePhone; }
  268.     public function setHomePhone(?string $homePhone): self $this->homePhone $homePhone; return $this; }
  269.     public function getHomePhone2(): ?string { return $this->homePhone2; }
  270.     public function setHomePhone2(?string $homePhone2): self $this->homePhone2 $homePhone2; return $this; }
  271.     public function getHomeStreet(): ?string { return $this->homeStreet; }
  272.     public function setHomeStreet(?string $homeStreet): self $this->homeStreet $homeStreet; return $this; }
  273.     public function getHomeCity(): ?string { return $this->homeCity; }
  274.     public function setHomeCity(?string $homeCity): self $this->homeCity $homeCity; return $this; }
  275.     public function getHomePostalCode(): ?string { return $this->homePostalCode; }
  276.     public function setHomePostalCode(?string $homePostalCode): self $this->homePostalCode $homePostalCode; return $this; }
  277.     public function getHomeCountry(): ?string { return $this->homeCountry; }
  278.     public function setHomeCountry(?string $homeCountry): self $this->homeCountry $homeCountry; return $this; }
  279.     // ---------- Photo Locations (inverse side) ----------
  280.     /** @return Collection<int, PhotoLocations> */
  281.     public function getPhotoLocations(): Collection
  282.     {
  283.         return $this->photoLocations;
  284.     }
  285.     public function addPhotoLocation(PhotoLocations $photoLocation): self
  286.     {
  287.         if (!$this->photoLocations->contains($photoLocation)) {
  288.             $this->photoLocations->add($photoLocation);
  289.             // sync owning side
  290.             $photoLocation->addEnabledUser($this);
  291.         }
  292.         return $this;
  293.     }
  294.     public function removePhotoLocation(PhotoLocations $photoLocation): self
  295.     {
  296.         if ($this->photoLocations->removeElement($photoLocation)) {
  297.             // sync owning side
  298.             $photoLocation->removeEnabledUser($this);
  299.         }
  300.         return $this;
  301.     }
  302.     // ---------- Misc ----------
  303.     public function getEmailVerified(): ?bool { return $this->emailVerified; }
  304.     public function setEmailVerified(?bool $emailVerified): self $this->emailVerified $emailVerified; return $this; }
  305.     public function getDefaultLanguage(): ?Languages { return $this->defaultLanguage; }
  306.     public function setDefaultLanguage(?Languages $defaultLanguage): static { $this->defaultLanguage $defaultLanguage; return $this; }
  307.     public function getPhoto(): ?string { return $this->photo; }
  308.     public function setPhoto(?string $photo): static { $this->photo $photo; return $this; }
  309.     public function getClientEmailsSent(): ?ClientEmailsSent { return $this->clientEmailsSent; }
  310.     public function setClientEmailsSent(?ClientEmailsSent $clientEmailsSent): static { $this->clientEmailsSent $clientEmailsSent; return $this; }
  311.     public static function getAvailableRoles(KernelInterface $kernel): array
  312.     {
  313.         $rolesFilePath $kernel->getProjectDir() . '/config/roles.yaml';
  314.         if (file_exists($rolesFilePath)) {
  315.             $rolesConfig Yaml::parseFile($rolesFilePath);
  316.             return $rolesConfig['roles'] ?? [];
  317.         }
  318.         return [];
  319.     }
  320.     public function hasRole(Role $role): bool
  321.     {
  322.         return $this->roles->contains($role);
  323.     }
  324.     public function getAutoLoginURL(): ?string { return $this->autoLoginURL; }
  325.     public function setAutoLoginURL(?string $autoLoginURL): static { $this->autoLoginURL $autoLoginURL; return $this; }
  326.     public function isPauseForBookmark(): bool { return (bool) $this->pauseForBookmark; }
  327.     public function setPauseForBookmark(bool $pause): self $this->pauseForBookmark $pause; return $this; }
  328. }