src/Entity/User.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use App\Traits\TimestampableTrait;
  5. use DateTime;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  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. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. use Symfony\Component\HttpFoundation\File\File;
  14. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  15. /**
  16.  * @ORM\Entity(repositoryClass=UserRepository::class)
  17.  * @UniqueEntity(fields={"email"}, message="Cette adresse e-mail est déjà utilisée à un autre compte !")
  18.  * @Vich\Uploadable
  19.  */
  20. class User implements UserInterface, \Serializable, PasswordAuthenticatedUserInterface
  21. {
  22.     use TimestampableTrait;
  23.     /**
  24.      * @ORM\Id
  25.      * @ORM\GeneratedValue
  26.      * @ORM\Column(type="integer")
  27.      */
  28.     protected $id;
  29.     /**
  30.      * @ORM\Column(type="string", length=180, unique=true)
  31.      * @Assert\Email(message="Votre adresse e-mail n'est pas correct !")
  32.      */
  33.     protected $email;
  34.     /**
  35.      * @ORM\Column(type="json")
  36.      */
  37.     protected $roles = [];
  38.     /**
  39.      * @var string The hashed password
  40.      * @ORM\Column(type="string")
  41.      * @Assert\Length(min=8, minMessage="Un mot de passe doit contenir au moins 8 caractères ! ")
  42.      */
  43.     protected $password;
  44.     /**
  45.      * @ORM\Column(type="boolean")
  46.      */
  47.     protected $isVerified = false;
  48.     /**
  49.      * @ORM\Column(type="boolean")
  50.      */
  51.     protected $isConnected = false;
  52.     /**
  53.      * @ORM\Column(type="string", length=255, nullable=true)
  54.      */
  55.     protected $lastName;
  56.     /**
  57.      * @ORM\Column(type="string", length=255, nullable=true)
  58.      */
  59.     protected $firstName;
  60.     /**
  61.      * @ORM\OneToOne(targetEntity=Company::class, inversedBy="user", cascade={"persist", "remove"})
  62.      */
  63.     private $company;
  64.     /**
  65.      * @ORM\Column(type="string", length=255, nullable=true)
  66.      */
  67.     private $image;
  68.     /**
  69.      * @Vich\UploadableField(mapping="images_user", fileNameProperty="image")
  70.      * @var File | null
  71.      */
  72.     private $imageFile;
  73.     /**
  74.      * @ORM\Column(type="string", length=20, nullable=true)
  75.      */
  76.     private $phone;
  77.     /**
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private $address;
  81.     /**
  82.      * @ORM\Column(type="string", length=255, nullable=true)
  83.      */
  84.     private $profession;
  85.     /**
  86.      * @ORM\Column(type="string", length=255, nullable=true)
  87.      */
  88.     private $companyname;
  89.     /**
  90.      * @ORM\Column(type="date", nullable=true)
  91.      */
  92.     private $birthday;
  93.     /**
  94.      * @ORM\Column(type="string", length=255, nullable=true)
  95.      */
  96.     private $nationality;
  97.     /**
  98.      * @ORM\Column(type="string", length=255, nullable=true)
  99.      */
  100.     private $gender;
  101.     /**
  102.      * @ORM\Column(type="string", length=255, nullable=true)
  103.      */
  104.     private $currency;
  105.     /**
  106.      * @ORM\Column(type="json", length=255, nullable=true)
  107.      */
  108.     private $languages = [];
  109.     /**
  110.      * @ORM\OneToMany(targetEntity=Abonnement::class, mappedBy="prestataireid", cascade={"persist", "remove"})
  111.      */
  112.     private $abonnements;
  113.     /**
  114.      * @ORM\OneToMany(targetEntity=Avis::class, mappedBy="user")
  115.      */
  116.     private $avis;
  117.     /**
  118.      * @ORM\OneToMany(targetEntity=Reclamationpresta::class, mappedBy="user")
  119.      */
  120.     private $reclamationprestas;
  121.     /**
  122.      * @ORM\OneToMany(targetEntity=Annonce::class, mappedBy="prestataireid")
  123.      */
  124.     private $annonces;
  125.     /**
  126.      * @ORM\OneToMany(targetEntity=InfoLog::class, mappedBy="user")
  127.      */
  128.     private $infologs;
  129.     /**
  130.      * @ORM\OneToMany(targetEntity=Publication::class, mappedBy="author")
  131.      */
  132.     private $publications;
  133.     /**
  134.      * @ORM\OneToMany(targetEntity=ReclamationCustomer::class, mappedBy="user")
  135.      */
  136.     private $reclamationCustomers;
  137.     public function __construct()
  138.     {
  139.         $this->annonces = new ArrayCollection();
  140.         $this->abonnements = new ArrayCollection();
  141.         $this->avis = new ArrayCollection();
  142.         $this->reclamationprestas = new ArrayCollection();
  143.         $this->infologs = new ArrayCollection();
  144.         $this->publications = new ArrayCollection();
  145.         $this->reclamationCustomers = new ArrayCollection();
  146.     }
  147.     public function preUpdate()
  148.     {
  149.         $this->lastName = ucwords(strtolower($this->lastName));
  150.         $this->firstName = ucwords(strtolower($this->firstName));
  151.         $this->email = strtolower($this->email);
  152.     }
  153.     public function getId(): ?int
  154.     {
  155.         return $this->id;
  156.     }
  157.     public function getEmail(): ?string
  158.     {
  159.         return $this->email;
  160.     }
  161.     public function setEmail(string $email): self
  162.     {
  163.         $this->email = $email;
  164.         return $this;
  165.     }
  166.     /**
  167.      * A visual identifier that represents this user.
  168.      *
  169.      * @see UserInterface
  170.      */
  171.     public function getUserIdentifier(): string
  172.     {
  173.         return (string) $this->email;
  174.     }
  175.     public function getRoles(): ?array
  176.     {
  177.         return $this->roles;
  178.     }
  179.     public function setRoles(array $roles): self
  180.     {
  181.         $this->roles = $roles;
  182.         return $this;
  183.     }
  184.     public function addRole($role)
  185.     {
  186.         $role = strtoupper($role);
  187.         $roles = $this->getRoles();
  188.         if ($role === '') {
  189.             return $this;
  190.         }
  191.         if (!in_array($role, $roles, true)) {
  192.             $this->roles[] = $role;
  193.         }
  194.         return $this;
  195.     }
  196.     public function hasRole($role)
  197.     {
  198.         if (in_array($role, $this->roles)) {
  199.             return true;
  200.         }
  201.         return false;
  202.     }
  203.     public function removeRole($role)
  204.     {
  205.         if ($this->hasRole($role)) {
  206.             unset($this->roles[array_search($role, $this->roles)]);
  207.         }
  208.         return $this;
  209.     }
  210.     public function getPassword(): ?string
  211.     {
  212.         return $this->password;
  213.     }
  214.     public function setPassword(string $password): self
  215.     {
  216.         $this->password = $password;
  217.         return $this;
  218.     }
  219.     /**
  220.      * @return bool
  221.      */
  222.     public function getIsVerified(): ?bool
  223.     {
  224.         return $this->isVerified;
  225.     }
  226.     /**
  227.      * @param bool $isVerified
  228.      */
  229.     public function setIsVerified(bool $isVerified): self
  230.     {
  231.         $this->isVerified = $isVerified;
  232.         return $this;
  233.     }
  234.     /**
  235.      * @return bool
  236.      */
  237.     public function getIsConnected(): ?bool
  238.     {
  239.         return $this->isConnected;
  240.     }
  241.     /**
  242.      * @param bool $isConnected
  243.      */
  244.     public function setIsConnected(bool $isConnected): self
  245.     {
  246.         $this->isConnected = $isConnected;
  247.         return $this;
  248.     }
  249.     public function getLastName(): ?string
  250.     {
  251.         return $this->lastName;
  252.     }
  253.     public function setLastName(string $lastName): self
  254.     {
  255.         $this->lastName = $lastName;
  256.         return $this;
  257.     }
  258.     public function getFirstName(): ?string
  259.     {
  260.         return $this->firstName;
  261.     }
  262.     public function setFirstName(string $firstName): self
  263.     {
  264.         $this->firstName = $firstName;
  265.         return $this;
  266.     }
  267.     public function getSalt()
  268.     {
  269.         return null;
  270.     }
  271.     /**
  272.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  273.      */
  274.     public function getUsername()
  275.     {
  276.         return (string) $this->email;
  277.     }
  278.     
  279.     /**
  280.      * @see UserInterface
  281.      */
  282.     public function eraseCredentials()
  283.     {
  284.         // If you store any temporary, sensitive data on the user, clear it here
  285.         // $this->plainPassword = null;
  286.     }
  287.     public function serialize()
  288.     {
  289.         return serialize(array(
  290.             $this->id,
  291.             $this->email,
  292.             $this->password,
  293.         ));
  294.     }
  295.     public function unserialize($serialized)
  296.     {
  297.         list(
  298.             $this->id,
  299.             $this->email,
  300.             $this->password,
  301.         ) = unserialize($serialized);
  302.     }
  303.     public function getCompany(): ?Company
  304.     {
  305.         return $this->company;
  306.     }
  307.     public function setCompany(?Company $company): self
  308.     {
  309.         $this->company = $company;
  310.         return $this;
  311.     }
  312.     public function getImage(): ?string
  313.     {
  314.         return $this->image;
  315.     }
  316.     public function setImage(?string $image): self
  317.     {
  318.         $this->image = $image;
  319.         return $this;
  320.     }
  321.     public function setImageFile(File $image = null)
  322.     {
  323.         $this->imageFile = $image;
  324.         if ($image) {
  325.             $this->updatedAt = new \DateTime('now');
  326.         }
  327.     }
  328.     public function getImageFile()
  329.     {
  330.         return $this->imageFile;
  331.     }
  332.     public function getPhone(): ?string
  333.     {
  334.         return $this->phone;
  335.     }
  336.     public function setPhone(?string $phone): self
  337.     {
  338.         $this->phone = $phone;
  339.         return $this;
  340.     }
  341.     public function getAddress(): ?string
  342.     {
  343.         return $this->address;
  344.     }
  345.     public function setAddress(?string $address): self
  346.     {
  347.         $this->address = $address;
  348.         return $this;
  349.     }
  350.     public function getProfession(): ?string
  351.     {
  352.         return $this->profession;
  353.     }
  354.     public function setProfession(?string $profession): self
  355.     {
  356.         $this->profession = $profession;
  357.         return $this;
  358.     }
  359.     public function getCompanyname(): ?string
  360.     {
  361.         return $this->companyname;
  362.     }
  363.     public function setCompanyname(?string $companyname): self
  364.     {
  365.         $this->companyname = $companyname;
  366.         return $this;
  367.     }
  368.     public function getNationality(): ?string
  369.     {
  370.         return $this->nationality;
  371.     }
  372.     public function setNationality(?string $nationality): self
  373.     {
  374.         $this->nationality = $nationality;
  375.         return $this;
  376.     }
  377.     public function getGender(): ?string
  378.     {
  379.         return $this->gender;
  380.     }
  381.     public function setGender(?string $gender): self
  382.     {
  383.         $this->gender = $gender;
  384.         return $this;
  385.     }
  386.     public function getBirthday(): ?\DateTimeInterface
  387.     {
  388.         return $this->birthday;
  389.     }
  390.     public function setBirthday(?\DateTimeInterface $birthday): self
  391.     {
  392.         $this->birthday = $birthday;
  393.         return $this;
  394.     }
  395.     public function getCurrency(): ?string
  396.     {
  397.         return $this->currency;
  398.     }
  399.     public function setCurrency(?string $currency): self
  400.     {
  401.         $this->currency = $currency;
  402.         return $this;
  403.     }
  404.     public function getLanguages(): ?array
  405.     {
  406.         return $this->languages;
  407.     }
  408.     public function setLanguages(?array $languages): self
  409.     {
  410.         $this->languages = $languages;
  411.         return $this;
  412.     }
  413.     /**
  414.      * @return Collection<int, Abonnement>
  415.      */
  416.     public function getAbonnements(): Collection
  417.     {
  418.         return $this->abonnements;
  419.     }
  420.     public function addAbonnement(Abonnement $abonnement): self
  421.     {
  422.         if (!$this->abonnements->contains($abonnement)) {
  423.             $this->abonnements[] = $abonnement;
  424.             $abonnement->setPrestataireid($this);
  425.         }
  426.         return $this;
  427.     }
  428.     public function removeAbonnement(Abonnement $abonnement): self
  429.     {
  430.         if ($this->abonnements->removeElement($abonnement)) {
  431.             // set the owning side to null (unless already changed)
  432.             if ($abonnement->getPrestataireid() === $this) {
  433.                 $abonnement->setPrestataireid(null);
  434.             }
  435.         }
  436.         return $this;
  437.     }
  438.     /**
  439.      * @return Collection<int, Avis>
  440.      */
  441.     public function getAvis(): Collection
  442.     {
  443.         return $this->avis;
  444.     }
  445.     public function addAvi(Avis $avi): self
  446.     {
  447.         if (!$this->avis->contains($avi)) {
  448.             $this->avis[] = $avi;
  449.             $avi->setUser($this);
  450.         }
  451.         return $this;
  452.     }
  453.     public function removeAvi(Avis $avi): self
  454.     {
  455.         if ($this->avis->removeElement($avi)) {
  456.             // set the owning side to null (unless already changed)
  457.             if ($avi->getUser() === $this) {
  458.                 $avi->setUser(null);
  459.             }
  460.         }
  461.         return $this;
  462.     }
  463.     /**
  464.      * @return Collection<int, Reclamationpresta>
  465.      */
  466.     public function getReclamationprestas(): Collection
  467.     {
  468.         return $this->reclamationprestas;
  469.     }
  470.     public function addReclamationpresta(Reclamationpresta $reclamationpresta): self
  471.     {
  472.         if (!$this->reclamationprestas->contains($reclamationpresta)) {
  473.             $this->reclamationprestas[] = $reclamationpresta;
  474.             $reclamationpresta->setUser($this);
  475.         }
  476.         return $this;
  477.     }
  478.     public function removeReclamationpresta(Reclamationpresta $reclamationpresta): self
  479.     {
  480.         if ($this->reclamationprestas->removeElement($reclamationpresta)) {
  481.             // set the owning side to null (unless already changed)
  482.             if ($reclamationpresta->getUser() === $this) {
  483.                 $reclamationpresta->setUser(null);
  484.             }
  485.         }
  486.         return $this;
  487.     }
  488.     /**
  489.      * @return Collection<int, Infolog>
  490.      */
  491.     public function getInfologs(): Collection
  492.     {
  493.         return $this->infologs;
  494.     }
  495.     public function addInfolog(Infolog $infolog): self
  496.     {
  497.         if (!$this->infologs->contains($infolog)) {
  498.             $this->infologs->add($infolog);
  499.             $infolog->setUser($this);
  500.         }
  501.         return $this;
  502.     }
  503.     public function removeInfolog(Infolog $infolog): self
  504.     {
  505.         if ($this->infologs->removeElement($infolog)) {
  506.             // set the owning side to null (unless already changed)
  507.             if ($infolog->getUser() === $this) {
  508.                 $infolog->setUser(null);
  509.             }
  510.         }
  511.         return $this;
  512.     }
  513.     /**
  514.      * @return Collection<int, Publication>
  515.      */
  516.     public function getPublications(): Collection
  517.     {
  518.         return $this->publications;
  519.     }
  520.     public function addPublication(Publication $publication): self
  521.     {
  522.         if (!$this->publications->contains($publication)) {
  523.             $this->publications[] = $publication;
  524.             $publication->setAuthor($this);
  525.         }
  526.         return $this;
  527.     }
  528.     public function removePublication(Publication $publication): self
  529.     {
  530.         if ($this->publications->removeElement($publication)) {
  531.             // set the owning side to null (unless already changed)
  532.             if ($publication->getAuthor() === $this) {
  533.                 $publication->setAuthor(null);
  534.             }
  535.         }
  536.         return $this;
  537.     }
  538.     /**
  539.      * @return Collection<int, ReclamationCustomer>
  540.      */
  541.     public function getReclamationCustomers(): Collection
  542.     {
  543.         return $this->reclamationCustomers;
  544.     }
  545.     public function addReclamationCustomer(ReclamationCustomer $reclamationCustomer): self
  546.     {
  547.         if (!$this->reclamationCustomers->contains($reclamationCustomer)) {
  548.             $this->reclamationCustomers[] = $reclamationCustomer;
  549.             $reclamationCustomer->setUser($this);
  550.         }
  551.         return $this;
  552.     }
  553.     public function removeReclamationCustomer(ReclamationCustomer $reclamationCustomer): self
  554.     {
  555.         if ($this->reclamationCustomers->removeElement($reclamationCustomer)) {
  556.             // set the owning side to null (unless already changed)
  557.             if ($reclamationCustomer->getUser() === $this) {
  558.                 $reclamationCustomer->setUser(null);
  559.             }
  560.         }
  561.         return $this;
  562.     }
  563. }