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. use App\Entity\Role;
  12. #[ORM\Entity(repositoryClassUserRepository::class)]
  13. #[ORM\Table(name"user")]
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column(type"integer")]
  19.     private $id;
  20.     #[ORM\Column(type"string"length180uniquetrue)]
  21.     private string $email;
  22.     #[ORM\Column(length255nullabletrue)]
  23.     private ?string $email2 null;
  24.     #[ORM\Column(type'string'length255nullabletrue)]
  25.     private ?string $email3 null;
  26.     #[ORM\Column(type'boolean'nullabletrue)]
  27.     private ?bool $emailVerified null;
  28. //    /**
  29. //     * @ORM\Column(type="json")
  30. //     */
  31. //    #[ORM\Column(type: 'json')]
  32. //    private array $roles = [];
  33.     #[ORM\ManyToMany(targetEntityRole::class, inversedBy'users')]
  34.     #[ORM\JoinTable(name'user_role')]
  35.     private Collection $roles;
  36.     #[ORM\Column(type'string')]
  37.     private string $password;
  38.     #[ORM\Column(type'string'length255nullabletrue)]
  39.     private ?string $salutation null;
  40.     #[ORM\Column(type'string'length255nullabletrue)]
  41.     private ?string $firstName null;
  42.     #[ORM\Column(type'string'length255nullabletrue)]
  43.     private ?string $lastName null;
  44.     #[ORM\Column(type'string'length255nullabletrue)]
  45.     private ?string $fullName null;
  46.     #[ORM\Column(type'string'length255nullabletrue)]
  47.     private ?string $mobile null;
  48.     #[ORM\Column(type'string'length255nullabletrue)]
  49.     private ?string $mobile2 null;
  50.     #[ORM\Column(type'string'length255nullabletrue)]
  51.     private ?string $plainPassword null;
  52.     #[ORM\OneToMany(targetEntityLog::class, mappedBy'user'orphanRemovaltrue)]
  53.     private $logs;
  54.     #[ORM\Column(type'string'length255nullabletrue)]
  55.     private ?string $company null;
  56.     #[ORM\Column(type'date'nullabletrue)]
  57.     private ?\DateTimeInterface $birthday null;
  58.     #[ORM\Column(type'string'length255nullabletrue)]
  59.     private ?string $webPage null;
  60.     #[ORM\Column(type'text'nullabletrue)]
  61.     private ?string $notes null;
  62.     #[ORM\Column(type'string'length255nullabletrue)]
  63.     private ?string $jobTitle null;
  64.     #[ORM\Column(type'string'length255nullabletrue)]
  65.     private ?string $linkedIn null;
  66.     #[ORM\Column(type'string'length255nullabletrue)]
  67.     private ?string $businessPhone null;
  68.     #[ORM\Column(type'string'length255nullabletrue)]
  69.     private ?string $businessStreet null;
  70.     #[ORM\Column(type'string'length255nullabletrue)]
  71.     private ?string $businessCity null;
  72.     #[ORM\Column(type'string'length255nullabletrue)]
  73.     private ?string $businessPostalCode null;
  74.     #[ORM\Column(type'string'length255nullabletrue)]
  75.     private ?string $businessCountry null;
  76.     #[ORM\Column(type'string'length255nullabletrue)]
  77.     private ?string $homePhone null;
  78.     #[ORM\Column(type'string'length255nullabletrue)]
  79.     private ?string $homePhone2 null;
  80.     #[ORM\Column(type'string'length255nullabletrue)]
  81.     private ?string $homeStreet null;
  82.     #[ORM\Column(type'string'length255nullabletrue)]
  83.     private ?string $homeCity null;
  84.     #[ORM\Column(type'string'length255nullabletrue)]
  85.     private ?string $homePostalCode null;
  86.     #[ORM\Column(type'string'length255nullabletrue)]
  87.     private ?string $homeCountry null;
  88.     #[ORM\ManyToMany(targetEntityUser::class, inversedBy'photoLocations')]
  89.     #[ORM\JoinTable(name'photo_locations_users')]
  90.     private Collection $enabledUsers;
  91.     #[ORM\ManyToOne]
  92.     private ?Languages $defaultLanguage null;
  93.     #[ORM\Column(length255nullabletrue)]
  94.     private ?string $photo null;
  95.     #[ORM\ManyToOne(inversedBy'recipient')]
  96.     private ?ClientEmailsSent $clientEmailsSent null;
  97.     public function __construct()
  98.     {
  99.         $this->roles = new ArrayCollection();
  100.         $this->logs = new ArrayCollection();
  101.         $this->enabledUsers = new ArrayCollection();
  102.     }
  103.     public function getEnabledUsers(): Collection
  104.     {
  105.         return $this->enabledUsers;
  106.     }
  107.     public function addEnabledUser(User $user): self
  108.     {
  109.         if (!$this->enabledUsers->contains($user)) {
  110.             $this->enabledUsers->add($user);
  111.         }
  112.         return $this;
  113.     }
  114.     public function removeEnabledUser(User $user): self
  115.     {
  116.         $this->enabledUsers->removeElement($user);
  117.         return $this;
  118.     }
  119.     public function getId(): ?int
  120.     {
  121.         return $this->id;
  122.     }
  123.     public function getSalutation(): ?string
  124.     {
  125.         return $this->salutation;
  126.     }
  127.     public function setSalutation(?string $salutation): self
  128.     {
  129.         $this->salutation $salutation;
  130.         return $this;
  131.     }
  132.     public function getFirstName(): ?string
  133.     {
  134.         return $this->firstName;
  135.     }
  136.     public function setFirstName(?string $firstName): self
  137.     {
  138.         $this->firstName $firstName;
  139.         return $this;
  140.     }
  141.     public function getLastName(): ?string
  142.     {
  143.         return $this->lastName;
  144.     }
  145.     public function setLastName(?string $LastName): self
  146.     {
  147.         $this->lastName $LastName;
  148.         return $this;
  149.     }
  150.     public function getUserIdentifier(): string
  151.     {
  152.         // Typically, the identifier is the user's email or username
  153.         return $this->email ?? '';
  154.     }
  155.     public function getEmail(): ?string
  156.     {
  157.         return $this->email ?? '';
  158.     }
  159.     public function setEmail(string $email): self
  160.     {
  161.         $this->email $email ?? '';
  162.         return $this;
  163.     }
  164.     public function getEmail2(): ?string
  165.     {
  166.         return $this->email2;
  167.     }
  168.     public function setEmail2(?string $email2): static
  169.     {
  170.         $this->email2 $email2;
  171.         return $this;
  172.     }
  173.     public function getEmail3(): ?string
  174.     {
  175.         return $this->email3;
  176.     }
  177.     public function setEmail3(?string $email3): self
  178.     {
  179.         $this->email3 $email3;
  180.         return $this;
  181.     }
  182.     public function getUsername(): string
  183.     {
  184.         return (string)$this->email;
  185.     }
  186. //    public function getRoles(): array
  187. //    {
  188. //        $roles = $this->roles;
  189. //        $roles[] = 'ROLE_USER';
  190. //        return array_unique($roles);
  191. //    }
  192.     public function addRole(Role $role): self
  193.     {
  194.         if (!$this->roles->contains($role)) {
  195.             $this->roles[] = $role;
  196.         }
  197.         return $this;
  198.     }
  199.     public function getRoles(): array
  200.     {
  201.         $roleCodes = [];
  202.         // Add roles from Role entities (if you're using them)
  203.         foreach ($this->roles as $role) {
  204.             $roleCodes[] = $role->getCode();  // e.g., "ROLE_ADMIN"
  205.         }
  206.         // Always guarantee ROLE_USER
  207.         $roleCodes[] = 'ROLE_USER';
  208.         // Remove duplicates and return
  209.         return array_unique($roleCodes);
  210.     }
  211.     public function setRoles(iterable $roles): self
  212.     {
  213.         $this->roles = new ArrayCollection();
  214.         foreach ($roles as $role) {
  215.             if ($role instanceof Role) {
  216.                 $this->roles->add($role);
  217.             }
  218.         }
  219.         return $this;
  220.     }
  221.     public function getRoleEntities(): Collection
  222.     {
  223.         return $this->roles;
  224.     }
  225.     public function setRoleEntities(Collection $roles): self
  226.     {
  227.         $this->roles $roles;
  228.         return $this;
  229.     }
  230.     public function getPassword(): string
  231.     {
  232.         return $this->password;
  233.     }
  234.     public function setPassword(string $password): self
  235.     {
  236.         $this->password $password;
  237.         return $this;
  238.     }
  239.     public function getSalt(): ?string
  240.     {
  241.         return null;
  242.     }
  243.     public function eraseCredentials()
  244.     {
  245.         // Clear any temporary, sensitive data here
  246.     }
  247.     public function getFullName(): ?string
  248.     {
  249.         if ($this->fullName === null) {
  250.             return $this->getFirstName() . " " $this->getLastName();
  251.         }
  252.         return $this->fullName;
  253.     }
  254.     public function setFullName(?string $fullName): self
  255.     {
  256.         $this->fullName $fullName;
  257.         return $this;
  258.     }
  259.     public function getMobile(): ?string
  260.     {
  261.         return $this->mobile;
  262.     }
  263.     public function setMobile(?string $mobile): self
  264.     {
  265.         $this->mobile $mobile;
  266.         return $this;
  267.     }
  268.     public function getMobile2(): ?string
  269.     {
  270.         return $this->mobile2;
  271.     }
  272.     public function setMobile2(?string $mobile2): self
  273.     {
  274.         $this->mobile2 $mobile2;
  275.         return $this;
  276.     }
  277.     public function getPlainPassword(): ?string
  278.     {
  279.         return $this->plainPassword;
  280.     }
  281.     public function setPlainPassword(?string $plainPassword): self
  282.     {
  283.         $this->plainPassword $plainPassword;
  284.         return $this;
  285.     }
  286.     public function getLogs(): Collection
  287.     {
  288.         return $this->logs;
  289.     }
  290.     public function addLog(Log $log): self
  291.     {
  292.         if (!$this->logs->contains($log)) {
  293.             $this->logs[] = $log;
  294.             $log->setUser($this);
  295.         }
  296.         return $this;
  297.     }
  298.     public function removeLog(Log $log): self
  299.     {
  300.         if ($this->logs->removeElement($log)) {
  301.             if ($log->getUser() === $this) {
  302.                 $log->setUser(null);
  303.             }
  304.         }
  305.         return $this;
  306.     }
  307.     public function getCompany(): ?string
  308.     {
  309.         return $this->company;
  310.     }
  311.     public function setCompany(?string $company): self
  312.     {
  313.         $this->company $company;
  314.         return $this;
  315.     }
  316.     public function getBusinessPhone(): ?string
  317.     {
  318.         return $this->businessPhone;
  319.     }
  320.     public function setBusinessPhone(?string $businessPhone): self
  321.     {
  322.         $this->businessPhone $businessPhone;
  323.         return $this;
  324.     }
  325.     public function getHomePhone(): ?string
  326.     {
  327.         return $this->homePhone;
  328.     }
  329.     public function setHomePhone(?string $homePhone): self
  330.     {
  331.         $this->homePhone $homePhone;
  332.         return $this;
  333.     }
  334.     public function getHomePhone2(): ?string
  335.     {
  336.         return $this->homePhone2;
  337.     }
  338.     public function setHomePhone2(?string $homePhone2): self
  339.     {
  340.         $this->homePhone2 $homePhone2;
  341.         return $this;
  342.     }
  343.     public function getBirthday(): ?\DateTimeInterface
  344.     {
  345.         return $this->birthday;
  346.     }
  347.     public function setBirthday(?\DateTimeInterface $birthday): self
  348.     {
  349.         $this->birthday $birthday;
  350.         return $this;
  351.     }
  352.     public function getWebPage(): ?string
  353.     {
  354.         return $this->webPage;
  355.     }
  356.     public function setWebPage(?string $webPage): self
  357.     {
  358.         $this->webPage $webPage;
  359.         return $this;
  360.     }
  361.     public function getNotes(): ?string
  362.     {
  363.         return $this->notes;
  364.     }
  365.     public function setNotes(?string $notes): self
  366.     {
  367.         $this->notes $notes;
  368.         return $this;
  369.     }
  370.     public function getJobTitle(): ?string
  371.     {
  372.         return $this->jobTitle;
  373.     }
  374.     public function setJobTitle(?string $jobTitle): self
  375.     {
  376.         $this->jobTitle $jobTitle;
  377.         return $this;
  378.     }
  379.     public function getLinkedIn(): ?string
  380.     {
  381.         return $this->linkedIn;
  382.     }
  383.     public function setLinkedIn(?string $linkedIn): self
  384.     {
  385.         $this->linkedIn $linkedIn;
  386.         return $this;
  387.     }
  388.     public function getBusinessStreet(): ?string
  389.     {
  390.         return $this->businessStreet;
  391.     }
  392.     public function setBusinessStreet(?string $businessStreet): self
  393.     {
  394.         $this->businessStreet $businessStreet;
  395.         return $this;
  396.     }
  397.     public function getBusinessCity(): ?string
  398.     {
  399.         return $this->businessCity;
  400.     }
  401.     public function setBusinessCity(?string $businessCity): self
  402.     {
  403.         $this->businessCity $businessCity;
  404.         return $this;
  405.     }
  406.     public function getBusinessPostalCode(): ?string
  407.     {
  408.         return $this->businessPostalCode;
  409.     }
  410.     public function setBusinessPostalCode(?string $businessPostalCode): self
  411.     {
  412.         $this->businessPostalCode $businessPostalCode;
  413.         return $this;
  414.     }
  415.     public function getBusinessCountry(): ?string
  416.     {
  417.         return $this->businessCountry;
  418.     }
  419.     public function setBusinessCountry(?string $businessCountry): self
  420.     {
  421.         $this->businessCountry $businessCountry;
  422.         return $this;
  423.     }
  424.     public function getHomeStreet(): ?string
  425.     {
  426.         return $this->homeStreet;
  427.     }
  428.     public function setHomeStreet(?string $homeStreet): self
  429.     {
  430.         $this->homeStreet $homeStreet;
  431.         return $this;
  432.     }
  433.     public function getHomeCity(): ?string
  434.     {
  435.         return $this->homeCity;
  436.     }
  437.     public function setHomeCity(?string $homeCity): self
  438.     {
  439.         $this->homeCity $homeCity;
  440.         return $this;
  441.     }
  442.     public function getHomePostalCode(): ?string
  443.     {
  444.         return $this->homePostalCode;
  445.     }
  446.     public function setHomePostalCode(?string $homePostalCode): self
  447.     {
  448.         $this->homePostalCode $homePostalCode;
  449.         return $this;
  450.     }
  451.     public function getHomeCountry(): ?string
  452.     {
  453.         return $this->homeCountry;
  454.     }
  455.     public function setHomeCountry(?string $homeCountry): self
  456.     {
  457.         $this->homeCountry $homeCountry;
  458.         return $this;
  459.     }
  460.     /**
  461.      * @return Collection|PhotoLocations[]
  462.      */
  463.     public function getPhotoLocations(): Collection
  464.     {
  465.         return $this->photoLocations;
  466.     }
  467.     public function addPhotoLocation(PhotoLocations $photoLocation): self
  468.     {
  469.         if (!$this->photoLocations->contains($photoLocation)) {
  470.             $this->photoLocations[] = $photoLocation;
  471.             $photoLocation->setEnabledUsers($this);
  472.         }
  473.         return $this;
  474.     }
  475.     public function removePhotoLocation(PhotoLocations $photoLocation): self
  476.     {
  477.         if ($this->photoLocations->removeElement($photoLocation)) {
  478.             // set the owning side to null (unless already changed)
  479.             if ($photoLocation->getEnabledUsers() === $this) {
  480.                 $photoLocation->setEnabledUsers(null);
  481.             }
  482.         }
  483.         return $this;
  484.     }
  485.     public function getEmailVerified(): ?bool
  486.     {
  487.         return $this->emailVerified;
  488.     }
  489.     public function setEmailVerified(?bool $emailVerified): self
  490.     {
  491.         $this->emailVerified $emailVerified;
  492.         return $this;
  493.     }
  494.     public function getDefaultLanguage(): ?Languages
  495.     {
  496.         return $this->defaultLanguage;
  497.     }
  498.     public function setDefaultLanguage(?Languages $defaultLanguage): static
  499.     {
  500.         $this->defaultLanguage $defaultLanguage;
  501.         return $this;
  502.     }
  503.     public function getPhoto(): ?string
  504.     {
  505.         return $this->photo;
  506.     }
  507.     public function setPhoto(?string $photo): static
  508.     {
  509.         $this->photo $photo;
  510.         return $this;
  511.     }
  512.     public function getClientEmailsSent(): ?ClientEmailsSent
  513.     {
  514.         return $this->clientEmailsSent;
  515.     }
  516.     public function setClientEmailsSent(?ClientEmailsSent $clientEmailsSent): static
  517.     {
  518.         $this->clientEmailsSent $clientEmailsSent;
  519.         return $this;
  520.     }
  521. //    private array $roles = [];
  522. //
  523.     public static function getAvailableRoles(KernelInterface $kernel): array
  524.     {
  525.         // Construct the path to your roles.yaml file
  526.         $rolesFilePath $kernel->getProjectDir() . '/config/roles.yaml';
  527.         dd($rolesFilePath);
  528.         // Check if the file exists and parse it
  529.         if (file_exists($rolesFilePath)) {
  530.             $rolesConfig Yaml::parseFile($rolesFilePath);
  531.             return $rolesConfig['roles'] ?? [];
  532.         }
  533.         return [];
  534.     }
  535. //
  536. //    public function getRoles(): array
  537. //    {
  538. //        return $this->roles;
  539. //    }
  540. //
  541. //    public function setRoles(array $roles): void
  542. //    {
  543. //        $availableRoles = self::getAvailableRoles();
  544. //        $this->roles = array_filter($roles, fn($role) => isset($availableRoles[$role]));
  545. //    }
  546. }