src/Entity/User.php line 20

  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\HttpFoundation\File\File;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  12. #[ORM\Entity(repositoryClassUserRepository::class)]
  13. #[ORM\Table(name'`user`')]
  14. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  15. #[Vich\Uploadable]
  16. class User implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column]
  21.     private ?int $id null;
  22.     #[ORM\Column(length180uniquetrue)]
  23.     private ?string $email null;
  24.     #[ORM\Column]
  25.     private array $roles = [];
  26.     /**
  27.      * @var string The hashed password
  28.      */
  29.     #[ORM\Column]
  30.     private ?string $password null;
  31.     #[ORM\Column(type'boolean')]
  32.     private $isVerified false;
  33.     #[ORM\Column(length255)]
  34.     private ?string $name null;
  35.     #[ORM\Column(length255)]
  36.     private ?string $firstname null;
  37.     #[ORM\Column(length255)]
  38.     private ?string $phone null;
  39.     #[ORM\Column(length255nullabletrue)]
  40.     private ?string $image null;
  41.     #[Vich\UploadableField(mapping'users_images'fileNameProperty'image')]
  42.     private ?File $imageFile null;
  43.     #[ORM\ManyToOne(targetEntityself::class, cascade: ['remove'], inversedBy'users')]
  44.     #[ORM\JoinColumn(name'administrator_id'referencedColumnName'id'onDelete'CASCADE')]
  45.     private ?self $administrator null;
  46.     #[ORM\OneToMany(mappedBy'administrator'targetEntityself::class)]
  47.     private Collection $users;
  48.     #[ORM\ManyToMany(targetEntityProgram::class, mappedBy'collaborators')]
  49.     private Collection $programs;
  50.     #[ORM\OneToMany(mappedBy'adminUser'targetEntityClient::class)]
  51.     private Collection $clients;
  52.     #[ORM\OneToMany(mappedBy'adminUser'targetEntityCompany::class)]
  53.     private Collection $companies;
  54.     #[ORM\OneToMany(mappedBy'adminUser'targetEntityGroupe::class)]
  55.     private Collection $groupes;
  56.     #[ORM\OneToOne(mappedBy'userClient'targetEntityClient::class)]
  57.     private ?Client $client null;
  58.     #[ORM\Column]
  59.     private ?bool $isDisable null;
  60.     public function __construct()
  61.     {
  62.         $this->users = new ArrayCollection();
  63.         $this->programs = new ArrayCollection();
  64.         $this->clients = new ArrayCollection();
  65.         $this->companies = new ArrayCollection();
  66.         $this->groupes = new ArrayCollection();
  67.         $this->isDisable false;
  68.     }
  69.     /**
  70.      * @return string|null
  71.      */
  72.     public function getName(): ?string
  73.     {
  74.         return $this->name;
  75.     }
  76.     /**
  77.      * @param string|null $name
  78.      */
  79.     public function setName(?string $name): void
  80.     {
  81.         $this->name $name;
  82.     }
  83.     /**
  84.      * @return string|null
  85.      */
  86.     public function getFirstname(): ?string
  87.     {
  88.         return $this->firstname;
  89.     }
  90.     /**
  91.      * @param string|null $firstname
  92.      */
  93.     public function setFirstname(?string $firstname): void
  94.     {
  95.         $this->firstname $firstname;
  96.     }
  97.     /**
  98.      * @return string|null
  99.      */
  100.     public function getPhone(): ?string
  101.     {
  102.         return $this->phone;
  103.     }
  104.     /**
  105.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  106.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  107.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  108.      * must be able to accept an instance of 'CandidateFile' as the bundle will inject one here
  109.      * during Doctrine hydration.
  110.      *
  111.      * @param CandidateFile|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  112.      */
  113.     public function setImageFile(?File $imageFile null): void
  114.     {
  115.         $this->imageFile $imageFile;
  116.         if (null !== $imageFile) {
  117.             // It is required that at least one field changes if you are using doctrine
  118.             // otherwise the event listeners won't be called and the file is lost
  119.             $this->updatedAt = new \DateTimeImmutable();
  120.         }
  121.     }
  122.     public function getImageFile(): ?File
  123.     {
  124.         return $this->imageFile;
  125.     }
  126.     /**
  127.      * @param string|null $phone
  128.      */
  129.     public function setPhone(?string $phone): void
  130.     {
  131.         $this->phone $phone;
  132.     }
  133.     /**
  134.      * @return string|null
  135.      */
  136.     public function getImage(): ?string
  137.     {
  138.         return $this->image;
  139.     }
  140.     /**
  141.      * @param string|null $image
  142.      */
  143.     public function setImage(?string $image): void
  144.     {
  145.         $this->image $image;
  146.     }
  147.     public function getId(): ?int
  148.     {
  149.         return $this->id;
  150.     }
  151.     public function getEmail(): ?string
  152.     {
  153.         return $this->email;
  154.     }
  155.     public function setEmail(string $email): self
  156.     {
  157.         $this->email $email;
  158.         return $this;
  159.     }
  160.     /**
  161.      * A visual identifier that represents this user.
  162.      *
  163.      * @see UserInterface
  164.      */
  165.     public function getUserIdentifier(): string
  166.     {
  167.         return (string) $this->email;
  168.     }
  169.     /**
  170.      * @see UserInterface
  171.      */
  172.     public function getRoles(): array
  173.     {
  174.         $roles $this->roles;
  175.         // guarantee every user at least has ROLE_USER
  176.         $roles[] = 'ROLE_USER';
  177.         return array_unique($roles);
  178.     }
  179.     public function setRoles(array $roles): self
  180.     {
  181.         $this->roles $roles;
  182.         return $this;
  183.     }
  184.     /**
  185.      * @see PasswordAuthenticatedUserInterface
  186.      */
  187.     public function getPassword(): string
  188.     {
  189.         return $this->password;
  190.     }
  191.     public function setPassword(string $password): self
  192.     {
  193.         $this->password $password;
  194.         return $this;
  195.     }
  196.     /**
  197.      * @see UserInterface
  198.      */
  199.     public function eraseCredentials()
  200.     {
  201.         // If you store any temporary, sensitive data on the user, clear it here
  202.         // $this->plainPassword = null;
  203.     }
  204.     public function isVerified(): bool
  205.     {
  206.         return $this->isVerified;
  207.     }
  208.     public function setIsVerified(bool $isVerified): self
  209.     {
  210.         $this->isVerified $isVerified;
  211.         return $this;
  212.     }
  213.     public function getAdministrator(): ?self
  214.     {
  215.         return $this->administrator;
  216.     }
  217.     public function setAdministrator(?self $administrator): self
  218.     {
  219.         $this->administrator $administrator;
  220.         return $this;
  221.     }
  222.     /**
  223.      * @return Collection<int, self>
  224.      */
  225.     public function getUsers(): Collection
  226.     {
  227.         return $this->users;
  228.     }
  229.     public function addUser(self $user): self
  230.     {
  231.         if (!$this->users->contains($user)) {
  232.             $this->users->add($user);
  233.             $user->setAdministrator($this);
  234.         }
  235.         return $this;
  236.     }
  237.     public function removeUser(self $user): self
  238.     {
  239.         if ($this->users->removeElement($user)) {
  240.             // set the owning side to null (unless already changed)
  241.             if ($user->getAdministrator() === $this) {
  242.                 $user->setAdministrator(null);
  243.             }
  244.         }
  245.         return $this;
  246.     }
  247.     /**
  248.      * @return Collection<int, Program>
  249.      */
  250.     public function getPrograms(): Collection
  251.     {
  252.         return $this->programs;
  253.     }
  254.     public function addProgram(Program $program): self
  255.     {
  256.         if (!$this->programs->contains($program)) {
  257.             $this->programs->add($program);
  258.             $program->addCollaborator($this);
  259.         }
  260.         return $this;
  261.     }
  262.     public function removeProgram(Program $program): self
  263.     {
  264.         if ($this->programs->removeElement($program)) {
  265.             $program->removeCollaborator($this);
  266.         }
  267.         return $this;
  268.     }
  269.     /**
  270.      * @return Collection<int, Client>
  271.      */
  272.     public function getClients(): Collection
  273.     {
  274.         return $this->clients;
  275.     }
  276.     public function addClient(Client $client): self
  277.     {
  278.         if (!$this->clients->contains($client)) {
  279.             $this->clients->add($client);
  280.             $client->setAdminUser($this);
  281.         }
  282.         return $this;
  283.     }
  284.     public function removeClient(Client $client): self
  285.     {
  286.         if ($this->clients->removeElement($client)) {
  287.             // set the owning side to null (unless already changed)
  288.             if ($client->getAdminUser() === $this) {
  289.                 $client->setAdminUser(null);
  290.             }
  291.         }
  292.         return $this;
  293.     }
  294.     /**
  295.      * @return Collection<int, Company>
  296.      */
  297.     public function getCompanies(): Collection
  298.     {
  299.         return $this->companies;
  300.     }
  301.     public function addCompany(Company $company): self
  302.     {
  303.         if (!$this->companies->contains($company)) {
  304.             $this->companies->add($company);
  305.             $company->setAdminUser($this);
  306.         }
  307.         return $this;
  308.     }
  309.     public function removeCompany(Company $company): self
  310.     {
  311.         if ($this->companies->removeElement($company)) {
  312.             // set the owning side to null (unless already changed)
  313.             if ($company->getAdminUser() === $this) {
  314.                 $company->setAdminUser(null);
  315.             }
  316.         }
  317.         return $this;
  318.     }
  319.     /**
  320.      * @return Collection<int, Groupe>
  321.      */
  322.     public function getGroupes(): Collection
  323.     {
  324.         return $this->groupes;
  325.     }
  326.     public function addGroupe(Groupe $groupe): self
  327.     {
  328.         if (!$this->groupes->contains($groupe)) {
  329.             $this->groupes->add($groupe);
  330.             $groupe->setAdminUser($this);
  331.         }
  332.         return $this;
  333.     }
  334.     public function removeGroupe(Groupe $groupe): self
  335.     {
  336.         if ($this->groupes->removeElement($groupe)) {
  337.             // set the owning side to null (unless already changed)
  338.             if ($groupe->getAdminUser() === $this) {
  339.                 $groupe->setAdminUser(null);
  340.             }
  341.         }
  342.         return $this;
  343.     }
  344.     /**
  345.      * @return Client|null
  346.      */
  347.     public function getClient(): ?Client
  348.     {
  349.         return $this->client;
  350.     }
  351.     /**
  352.      * @param Client|null $client
  353.      */
  354.     public function setClient(?Client $client): void
  355.     {
  356.         $this->client $client;
  357.     }
  358.     public function isIsDisable(): ?bool
  359.     {
  360.         return $this->isDisable;
  361.     }
  362.     public function setIsDisable(bool $isDisable): self
  363.     {
  364.         $this->isDisable $isDisable;
  365.         return $this;
  366.     }
  367. }