src/Entity/User.php line 20

  1. <?php
  2. namespace App\Entity;
  3. use Cocur\Slugify\Slugify;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\UserRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  12. #[ORM\Entity(repositoryClassUserRepository::class)]
  13. #[ORM\Table(name'`user`')]
  14. #[ORM\HasLifecycleCallbacks]
  15. #[UniqueEntity(fields: ['email'], message'Il existe déjà un compte avec cette adresse e-mail')]
  16. class User implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column]
  21.     private ?int $id null;
  22.     #[ORM\Column(type'string'length:255)]
  23.     #[Assert\NotBlank(message"Veuillez renseigner ce champ")]
  24.     private $denomination;
  25.     #[ORM\Column(type'string'length255)]
  26.     private $contactEntreprise;
  27.     #[ORM\Column(type'string'length255)]
  28.     #[Assert\NotBlank(message"Veuillez renseigner un email valide")]
  29.     private $emailEntreprise;
  30.     #[ORM\Column(type'string'length255)]
  31.     #[Assert\NotBlank(message"Veuillez renseigner ce champ")]
  32.     private $nomPrenom;
  33.     #[ORM\Column(type'string'length255)]
  34.     private $contactInterlocuteur;
  35.     #[ORM\Column(type'string'length255)]
  36.     private $fonction;
  37.     #[ORM\Column(length180uniquetrue)]
  38.     private ?string $email null;
  39.     /**
  40.      * @var string The hashed password
  41.      */
  42.     #[ORM\Column]
  43.     private ?string $password null;
  44.     #[Assert\EqualTo(propertyPath:"password"message"Les deux mot de passes ne sont pas identiques")]
  45.     public $passwordConfirm;
  46.     #[ORM\Column(type'string'length255)]
  47.     private $slug;
  48.     #[ORM\Column]
  49.     private ?\DateTime $createdAt null;
  50.     #[ORM\Column(type'string'length255)]
  51.     private $adresse;
  52.     #[ORM\Column]
  53.     private ?bool $active null;
  54.     #[ORM\OneToMany(mappedBy'clientAssocie'targetEntityCe::class)]
  55.     private $userCes;
  56.     #[ORM\OneToMany(mappedBy'clientAssocie'targetEntityCv::class)]
  57.     private Collection $userCvs;
  58.     // #[ORM\OneToMany(mappedBy: 'clientAssocie', targetEntity: Cv::class)]
  59.     // private $cvs;
  60.     #[ORM\Column(type'json')]
  61.     private $roles = [];
  62.     #[ORM\ManyToOne(inversedBy'users')]
  63.     #[ORM\JoinColumn(nullablefalse)]
  64.     private ?TypeUser $typesUser null;
  65.     #[ORM\Column(type'boolean')]
  66.     private $isVerified false;
  67.     // #[ORM\ManyToOne(targetEntity: TypeUser::class, inversedBy: 'users')]
  68.     // #[ORM\JoinColumn(nullable: false)]
  69.     // private $typeUser;
  70.     public function __construct()
  71.     {
  72.         $this->userCes = new ArrayCollection();
  73.         //$this->cvs = new ArrayCollection();
  74.         //$this->userRoles = ArrayCollection();
  75.         $this->userCvs = new ArrayCollection();
  76.     }
  77.     /**
  78.      * Fonction permettant d'initialiser le slug de l'utilisateur
  79.      * @return void
  80.      */
  81.     #[ORM\PrePersist]
  82.     #[ORM\PreUpdate]
  83.     public function creationSlug()
  84.     {
  85.         if (empty($this->slug)) {
  86.             $slugify = new Slugify();
  87.             $this->slug $slugify->slugify($this->denomination);
  88.         }
  89.     }
  90.     /**
  91.      * Fonction permettant de calculer le prix en fonction de la durée du séjour et de mettre automatiquement
  92.      * Ã  jours la date de reservation
  93.      */
  94.     #[ORM\PrePersist]
  95.     public function prePersist()
  96.     {
  97.         if (empty($this->createdAt)) {
  98.             $this->createdAt = new \DateTime();
  99.         }
  100.     }
  101.     public function getId(): ?int
  102.     {
  103.         return $this->id;
  104.     }
  105.     public function getEmail(): ?string
  106.     {
  107.         return $this->email;
  108.     }
  109.     public function setEmail(string $email): self
  110.     {
  111.         $this->email $email;
  112.         return $this;
  113.     }
  114.     /**
  115.      * A visual identifier that represents this user.
  116.      *
  117.      * @see UserInterface
  118.      */
  119.     public function getUserIdentifier(): string
  120.     {
  121.         return (string) $this->email;
  122.     }
  123.     /**
  124.      * @see UserInterface
  125.      */
  126.     public function getRoles(): array
  127.     {
  128.         $roles $this->roles;
  129.         // if(empty($roles)){
  130.         //     // guarantee every user at least has ROLE_USER
  131.         //     $roles[] = 'ROLE_USER';
  132.         // }
  133.         return array_unique($roles);
  134.     }
  135.     public function hasRole($roles)
  136.     {
  137.         $user_role $this->getRoles();
  138.         if (!in_array($roles$user_role)) {
  139.             return false;
  140.         }
  141.         return true;
  142.     }
  143.     
  144.     public function setRoles(array $roles): self
  145.     {
  146.         $this->roles $roles;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @see PasswordAuthenticatedUserInterface
  151.      */
  152.     public function getPassword(): string
  153.     {
  154.         return $this->password;
  155.     }
  156.     public function setPassword(string $password): self
  157.     {
  158.         $this->password $password;
  159.         return $this;
  160.     }
  161.     /**
  162.      * @see UserInterface
  163.      */
  164.     public function eraseCredentials()
  165.     {
  166.         // If you store any temporary, sensitive data on the user, clear it here
  167.         // $this->plainPassword = null;
  168.     }
  169.     //Fonction permettant de retourner le nom d'utilisateur 
  170.     public function getUsername()
  171.     {
  172.         return $this->email;
  173.     }
  174.     // /**
  175.     //  * Get the value of typeUser
  176.     //  */ 
  177.     // public function getTypeUser()
  178.     // {
  179.     //     return $this->typeUser;
  180.     // }
  181.     // /**
  182.     //  * Set the value of typeUser
  183.     //  *
  184.     //  * @return  self
  185.     //  */ 
  186.     // public function setTypeUser($typeUser)
  187.     // {
  188.     //     $this->typeUser = $typeUser;
  189.     //     return $this;
  190.     // }
  191.     /**
  192.      * Get the value of adresse
  193.      */ 
  194.     public function getAdresse()
  195.     {
  196.         return $this->adresse;
  197.     }
  198.     /**
  199.      * Set the value of adresse
  200.      *
  201.      * @return  self
  202.      */ 
  203.     public function setAdresse($adresse)
  204.     {
  205.         $this->adresse $adresse;
  206.         return $this;
  207.     }
  208.     /**
  209.      * Get the value of active
  210.      */ 
  211.     public function getActive(): ?bool
  212.     {
  213.         return $this->active;
  214.     }
  215.     /**
  216.      * Set the value of active
  217.      *
  218.      * @return  self
  219.      */ 
  220.     public function setActive(bool $active): self
  221.     {
  222.         $this->active $active;
  223.         return $this;
  224.     }
  225.     /**
  226.      * Get the value of userCes
  227.      * @return Collection|Ce[]
  228.      */ 
  229.     public function getUserCes(): Collection
  230.     {
  231.         return $this->userCes;
  232.     }
  233.     /**
  234.      * Set the value of userCes
  235.      *
  236.      * @return  self
  237.      */
  238.     public function addUserCe(Ce $userCe): self
  239.     {
  240.         if (!$this->userCes->contains($userCe)) {
  241.             $this->userCes[] = $userCe;
  242.             $userCe->setClientAssocie($this);
  243.         }
  244.         return $this;
  245.     }
  246.     public function removeUserCe(Ce $userCe): self
  247.     {
  248.         if ($this->userCes->contains($userCe)) {
  249.             $this->userCes->removeElement($userCe);
  250.             // set the owning side to null (unless already changed)
  251.             if ($userCe->getClientAssocie() === $this) {
  252.                 $userCe->setClientAssocie(null);
  253.             }
  254.         }
  255.         return $this;
  256.     }
  257.     // /**
  258.     //  * @return Collection|Cv[]
  259.     //  */
  260.     // public function getCvs(): Collection
  261.     // {
  262.     //     return $this->cvs;
  263.     // }
  264.     // public function addCv(Cv $cv): self
  265.     // {
  266.     //     if (!$this->cvs->contains($cv)) {
  267.     //         $this->cvs[] = $cv;
  268.     //         $cv->setClientAssocie($this);
  269.     //     }
  270.     //     return $this;
  271.     // }
  272.     // public function removeCv(Cv $cv): self
  273.     // {
  274.     //     if ($this->cvs->contains($cv)) {
  275.     //         $this->cvs->removeElement($cv);
  276.     //         // set the owning side to null (unless already changed)
  277.     //         if ($cv->getClientAssocie() === $this) {
  278.     //             $cv->setClientAssocie(null);
  279.     //         }
  280.     //     }
  281.     //     return $this;
  282.     // }
  283.     /**
  284.      * Get the value of contactEntreprise
  285.      */ 
  286.     public function getContactEntreprise(): ?string
  287.     {
  288.         return $this->contactEntreprise;
  289.     }
  290.     /**
  291.      * Set the value of contactEntreprise
  292.      *
  293.      * @return  self
  294.      */ 
  295.     public function setContactEntreprise(string $contactEntreprise): self
  296.     {
  297.         $this->contactEntreprise $contactEntreprise;
  298.         return $this;
  299.     }
  300.     /**
  301.      * Get the value of emailEntreprise
  302.      */ 
  303.     public function getEmailEntreprise(): ?string
  304.     {
  305.         return $this->emailEntreprise;
  306.     }
  307.     /**
  308.      * Set the value of emailEntreprise
  309.      *
  310.      * @return  self
  311.      */ 
  312.     public function setEmailEntreprise(string $emailEntreprise): self
  313.     {
  314.         $this->emailEntreprise $emailEntreprise;
  315.         return $this;
  316.     }
  317.     /**
  318.      * Get the value of nomPrenom
  319.      */ 
  320.     public function getNomPrenom(): ?string
  321.     {
  322.         return $this->nomPrenom;
  323.     }
  324.     /**
  325.      * Set the value of nomPrenom
  326.      *
  327.      * @return  self
  328.      */ 
  329.     public function setNomPrenom(string $nomPrenom): self
  330.     {
  331.         $this->nomPrenom $nomPrenom;
  332.         return $this;
  333.     }
  334.     /**
  335.      * Get the value of contactInterlocuteur
  336.      */ 
  337.     public function getContactInterlocuteur(): ?string
  338.     {
  339.         return $this->contactInterlocuteur;
  340.     }
  341.     /**
  342.      * Set the value of contactInterlocuteur
  343.      *
  344.      * @return  self
  345.      */ 
  346.     public function setContactInterlocuteur(string $contactInterlocuteur): self
  347.     {
  348.         $this->contactInterlocuteur $contactInterlocuteur;
  349.         return $this;
  350.     }
  351.     /**
  352.      * Get the value of fonction
  353.      */ 
  354.     public function getFonction(): ?string
  355.     {
  356.         return $this->fonction;
  357.     }
  358.     /**
  359.      * Set the value of fonction
  360.      *
  361.      * @return  self
  362.      */ 
  363.     public function setFonction(string $fonction)
  364.     {
  365.         $this->fonction $fonction;
  366.         return $this;
  367.     }
  368.     /**
  369.      * Get the value of denomination
  370.      */ 
  371.     public function getDenomination()
  372.     {
  373.         return $this->denomination;
  374.     }
  375.     /**
  376.      * Set the value of denomination
  377.      *
  378.      * @return  self
  379.      */ 
  380.     public function setDenomination(string $denomination): self
  381.     {
  382.         $this->denomination $denomination;
  383.         return $this;
  384.     }
  385.     public function getSalt(): ?string
  386.     {
  387.         return null;
  388.     }
  389.     public function getCreatedAt(): ?\DateTimeInterface
  390.     {
  391.         return $this->createdAt;
  392.     }
  393.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  394.     {
  395.         $this->createdAt $createdAt;
  396.         return $this;
  397.     }
  398.     /**
  399.      * @return Collection<int, Cv>
  400.      */
  401.     public function getUserCvs(): Collection
  402.     {
  403.         return $this->userCvs;
  404.     }
  405.     public function addUserCv(Cv $userCv): self
  406.     {
  407.         if (!$this->userCvs->contains($userCv)) {
  408.             $this->userCvs->add($userCv);
  409.             $userCv->setClientAssocie($this);
  410.         }
  411.         return $this;
  412.     }
  413.     public function removeUserCv(Cv $userCv): self
  414.     {
  415.         if ($this->userCvs->removeElement($userCv)) {
  416.             // set the owning side to null (unless already changed)
  417.             if ($userCv->getClientAssocie() === $this) {
  418.                 $userCv->setClientAssocie(null);
  419.             }
  420.         }
  421.         return $this;
  422.     }
  423.     public function getTypesUser(): ?TypeUser
  424.     {
  425.         return $this->typesUser;
  426.     }
  427.     public function setTypesUser(?TypeUser $typesUser): self
  428.     {
  429.         $this->typesUser $typesUser;
  430.         return $this;
  431.     }
  432.     /**
  433.      * Get the value of slug
  434.      */ 
  435.     public function getSlug()
  436.     {
  437.         return $this->slug;
  438.     }
  439.     /**
  440.      * Set the value of slug
  441.      *
  442.      * @return  self
  443.      */ 
  444.     public function setSlug($slug)
  445.     {
  446.         $this->slug $slug;
  447.         return $this;
  448.     }
  449.     public function isVerified(): bool
  450.     {
  451.         return $this->isVerified;
  452.     }
  453.     public function setIsVerified(bool $isVerified): self
  454.     {
  455.         $this->isVerified $isVerified;
  456.         return $this;
  457.     }
  458. }