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