src/Entity/User.php line 740

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Doctrine\Type\ClientType;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use JsonSerializable;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  * @ORM\Table(name="`users`")
  14.  * @UniqueEntity(fields={"usermane"}, message="There is already an account with this usermane")
  15.  * @method string getUserIdentifier()
  16.  */
  17. class User implements UserInterfaceJsonSerializable
  18. {
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=180)
  27.      */
  28.     private $usermane;
  29.     /**
  30.      * @ORM\Column(type="json")
  31.      */
  32.     private $roles = [];
  33.     /**
  34.      * @var string The hashed password
  35.      * @ORM\Column(type="string", nullable=true)
  36.      */
  37.     private $password;
  38.     /**
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      */
  41.     private $civility;
  42.     /**
  43.      * @ORM\Column(type="string", length=255, nullable=true)
  44.      */
  45.     private $firstName;
  46.     /**
  47.      * @ORM\Column(type="string", length=255, nullable=true)
  48.      */
  49.     private $LastName;
  50.     /**
  51.      * @ORM\Column(type="string", length=255, nullable=true)
  52.      */
  53.     private $email;
  54.     /**
  55.      * @ORM\Column(type="text", nullable=true)
  56.      */
  57.     private $description;
  58.     /**
  59.      * @ORM\Column(type="string", length=255, nullable=true)
  60.      */
  61.     private $phone;
  62.     /**
  63.      * @ORM\Column(type="string", length=255, nullable=true)
  64.      */
  65.     private $second_phone;
  66.     /**
  67.      * @ORM\Column(type="text", nullable=true)
  68.      */
  69.     private $adress;
  70.     /**
  71.      * @ORM\Column(type="text", nullable=true)
  72.      */
  73.     private $second_adress;
  74.     /**
  75.      * @ORM\Column(type="string", length=255, nullable=true)
  76.      */
  77.     private $country;
  78.     /**
  79.      * @ORM\Column(type="string", length=255, nullable=true)
  80.      */
  81.     private $region;
  82.     /**
  83.      * @ORM\Column(type="string", length=255, nullable=true)
  84.      */
  85.     private $city;
  86.     /**
  87.      * @ORM\Column(type="string", length=255, nullable=true)
  88.      */
  89.     private $tariff_category;
  90.     /**
  91.      * @ORM\Column(type="string", length=255, nullable=true)
  92.      */
  93.     private $zip;
  94.     /**
  95.      * @ORM\Column(type="string", length=255, nullable=true)
  96.      */
  97.     private $type;
  98.     /**
  99.      * @ORM\Column(type="boolean")
  100.      */
  101.     private $isVerified false;
  102.     /**
  103.      * @ORM\OneToMany(targetEntity=Link::class, mappedBy="user",cascade={"persist"})
  104.      */
  105.     private $links;
  106.     /**
  107.      * @ORM\Column(type="datetime")
  108.      */
  109.     private $createdAt;
  110.     /**
  111.      * @ORM\OneToMany(targetEntity=Document::class, mappedBy="client")
  112.      */
  113.     private $documents;
  114.     /**
  115.      * @ORM\OneToMany(targetEntity=Document::class, mappedBy="user")
  116.      */
  117.     private $userDocuments;
  118.     /**
  119.      * @ORM\OneToMany(targetEntity=Address::class, mappedBy="user")
  120.      */
  121.     private $multiAddress;
  122.     /**
  123.      * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="user")
  124.      */
  125.     private $comments;
  126.     /**
  127.      * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="client")
  128.      */
  129.     private $notes;
  130.     /**
  131.      * @ORM\ManyToOne(targetEntity=Supplier::class, inversedBy="contacts")
  132.      */
  133.     private $supplier;
  134.     /**
  135.      * @ORM\ManyToOne(targetEntity=Promotion::class, inversedBy="clients")
  136.      */
  137.     private $promotion;
  138.     /**
  139.      * @ORM\OneToMany(targetEntity=Activity::class, mappedBy="currentUser")
  140.      * @ORM\OrderBy({"ceratedAt" = "DESC"})
  141.      */
  142.     private $activities;
  143.     /**
  144.      * @ORM\ManyToMany(targetEntity=Produit::class, mappedBy="users")
  145.      */
  146.     private $produits;
  147.     /**
  148.      * @ORM\ManyToOne(targetEntity=GroupUser::class, inversedBy="users")
  149.      */
  150.     private $groupUser;
  151.     /**
  152.      * @ORM\Column(type="client_type", length=255)
  153.      */
  154.     private $clientType='Nouveau client';
  155.     public function __construct()
  156.     {
  157.         $this->links = new ArrayCollection();
  158.         $this->documents = new ArrayCollection();
  159.         $this->userDocuments = new ArrayCollection();
  160.         $this->multiAddress = new ArrayCollection();
  161.         $this->comments = new ArrayCollection();
  162.         $this->notes = new ArrayCollection();
  163.         $this->activities = new ArrayCollection();
  164.         $this->produits = new ArrayCollection();
  165.         $this->zip="";
  166.     }
  167.     public function getId(): ?int
  168.     {
  169.         return $this->id;
  170.     }
  171.     public function getUsermane(): ?string
  172.     {
  173.         return $this->usermane;
  174.     }
  175.     public function setUsermane(string $usermane): self
  176.     {
  177.         $this->usermane $usermane;
  178.         return $this;
  179.     }
  180.     /**
  181.      * A visual identifier that represents this user.
  182.      *
  183.      * @see UserInterface
  184.      */
  185.     public function getUsername(): string
  186.     {
  187.         return (string) $this->usermane;
  188.     }
  189.     /**
  190.      * @see UserInterface
  191.      */
  192.     public function getRoles(): array
  193.     {
  194.         $roles $this->roles;
  195.         // guarantee every user at least has ROLE_USER
  196.         $roles[] = 'ROLE_USER';
  197.         return array_unique($roles);
  198.     }
  199.     public function setRoles(array $roles): self
  200.     {
  201.         $this->roles $roles;
  202.         return $this;
  203.     }
  204.     /**
  205.      * @see UserInterface
  206.      */
  207.     public function getPassword(): string
  208.     {
  209.         return (string) $this->password;
  210.     }
  211.     public function setPassword(string $password): self
  212.     {
  213.         $this->password $password;
  214.         return $this;
  215.     }
  216.     /**
  217.      * Returning a salt is only needed, if you are not using a modern
  218.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  219.      *
  220.      * @see UserInterface
  221.      */
  222.     public function getSalt(): ?string
  223.     {
  224.         return null;
  225.     }
  226.     /**
  227.      * @see UserInterface
  228.      */
  229.     public function eraseCredentials()
  230.     {
  231.         // If you store any temporary, sensitive data on the user, clear it here
  232.         // $this->plainPassword = null;
  233.     }
  234.     public function getCivility(): ?string
  235.     {
  236.         return $this->civility;
  237.     }
  238.     public function setCivility(string $civility): self
  239.     {
  240.         $this->civility $civility;
  241.         return $this;
  242.     }
  243.     public function getFirstName(): ?string
  244.     {
  245.         return $this->firstName;
  246.     }
  247.     public function setFirstName(string $firstName): self
  248.     {
  249.         $this->firstName $firstName;
  250.         return $this;
  251.     }
  252.     public function getLastName(): ?string
  253.     {
  254.         return $this->LastName;
  255.     }
  256.     public function setLastName(string $LastName): self
  257.     {
  258.         $this->LastName $LastName;
  259.         return $this;
  260.     }
  261.     public function getFullName(): ?string
  262.     {
  263.         return $this->firstName .' '.$this->LastName;
  264.     }
  265.     public function getEmail(): ?string
  266.     {
  267.         return $this->email;
  268.     }
  269.     public function setEmail(string $email): self
  270.     {
  271.         $this->email $email;
  272.         return $this;
  273.     }
  274.     public function getDescription(): ?string
  275.     {
  276.         return $this->description;
  277.     }
  278.     public function setDescription(string $description): self
  279.     {
  280.         $this->description $description;
  281.         return $this;
  282.     }
  283.     public function getPhone(): ?string
  284.     {
  285.         return $this->phone;
  286.     }
  287.     public function setPhone(string $phone): self
  288.     {
  289.         $this->phone $phone;
  290.         return $this;
  291.     }
  292.     public function getSecondPhone(): ?string
  293.     {
  294.         return $this->second_phone;
  295.     }
  296.     public function setSecondPhone(?string $second_phone): self
  297.     {
  298.         $this->second_phone $second_phone;
  299.         return $this;
  300.     }
  301.     public function getAdress(): ?string
  302.     {
  303.         return $this->adress;
  304.     }
  305.     public function setAdress(string $adress): self
  306.     {
  307.         $this->adress $adress;
  308.         return $this;
  309.     }
  310.     public function getSecondAdress(): ?string
  311.     {
  312.         return $this->second_adress;
  313.     }
  314.     public function setSecondAdress(?string $second_adress): self
  315.     {
  316.         $this->second_adress $second_adress;
  317.         return $this;
  318.     }
  319.     public function getCountry(): ?string
  320.     {
  321.         return $this->country;
  322.     }
  323.     public function setCountry(string $country): self
  324.     {
  325.         $this->country $country;
  326.         return $this;
  327.     }
  328.     public function getRegion(): ?string
  329.     {
  330.         return $this->region;
  331.     }
  332.     public function setRegion(string $region): self
  333.     {
  334.         $this->region $region;
  335.         return $this;
  336.     }
  337.     public function getCity(): ?string
  338.     {
  339.         return $this->city;
  340.     }
  341.     public function setCity(string $city): self
  342.     {
  343.         $this->city $city;
  344.         return $this;
  345.     }
  346.     public function getTariffCategory(): ?string
  347.     {
  348.         return $this->tariff_category;
  349.     }
  350.     public function setTariffCategory(?string $tariff_category): self
  351.     {
  352.         $this->tariff_category $tariff_category;
  353.         return $this;
  354.     }
  355.     public function getZip(): ?string
  356.     {
  357.         return $this->zip;
  358.     }
  359.     public function setZip(string $zip): self
  360.     {
  361.         $this->zip $zip;
  362.         return $this;
  363.     }
  364.     public function getType(): ?string
  365.     {
  366.         return $this->type;
  367.     }
  368.     public function setType(string $type): self
  369.     {
  370.         $this->type $type;
  371.         return $this;
  372.     }
  373.     public function isVerified(): bool
  374.     {
  375.         return $this->isVerified;
  376.     }
  377.     public function setIsVerified(bool $isVerified): self
  378.     {
  379.         $this->isVerified $isVerified;
  380.         return $this;
  381.     }
  382.     /**
  383.      * @return Collection|Link[]
  384.      */
  385.     public function getLinks(): Collection
  386.     {
  387.         return $this->links;
  388.     }
  389.     public function addLink(Link $link): self
  390.     {
  391.         if( !$this->links->contains($link)) {
  392.             $this->links[] = $link;
  393.             $link->setUser($this);
  394.         }
  395.         return $this;
  396.     }
  397.     public function removeLink(Link $link): self
  398.     {
  399.         if( $this->links->removeElement($link)) {
  400.             // set the owning side to null (unless already changed)
  401.             if( $link->getUser() === $this) {
  402.                 $link->setUser(null);
  403.             }
  404.         }
  405.         return $this;
  406.     }
  407.     public function getCreatedAt(): ?\DateTimeInterface
  408.     {
  409.         return $this->createdAt;
  410.     }
  411.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  412.     {
  413.         $this->createdAt $createdAt;
  414.         return $this;
  415.     }
  416.     /**
  417.      * @return Collection|Document[]
  418.      */
  419.     public function getDocuments(): Collection
  420.     {
  421.         return $this->documents;
  422.     }
  423.     public function addDocument(Document $document): self
  424.     {
  425.         if( !$this->documents->contains($document)) {
  426.             $this->documents[] = $document;
  427.             $document->setClient($this);
  428.         }
  429.         return $this;
  430.     }
  431.     public function removeDocument(Document $document): self
  432.     {
  433.         if( $this->documents->removeElement($document)) {
  434.             // set the owning side to null (unless already changed)
  435.             if( $document->getClient() === $this) {
  436.                 $document->setClient(null);
  437.             }
  438.         }
  439.         return $this;
  440.     }
  441.     /**
  442.      * @return Collection|Document[]
  443.      */
  444.     public function getUserDocuments(): Collection
  445.     {
  446.         return $this->userDocuments;
  447.     }
  448.     public function addUserDocument(Document $userDocument): self
  449.     {
  450.         if( !$this->userDocuments->contains($userDocument)) {
  451.             $this->userDocuments[] = $userDocument;
  452.             $userDocument->setUser($this);
  453.         }
  454.         return $this;
  455.     }
  456.     public function removeUserDocument(Document $userDocument): self
  457.     {
  458.         if( $this->userDocuments->removeElement($userDocument)) {
  459.             // set the owning side to null (unless already changed)
  460.             if( $userDocument->getUser() === $this) {
  461.                 $userDocument->setUser(null);
  462.             }
  463.         }
  464.         return $this;
  465.     }
  466.     /**
  467.      * @return Collection|Address[]
  468.      */
  469.     public function getMultiAddress(): Collection
  470.     {
  471.         return $this->multiAddress;
  472.     }
  473.     public function addMultiAddress(Address $multiAddress): self
  474.     {
  475.         if( !$this->multiAddress->contains($multiAddress)) {
  476.             $this->multiAddress[] = $multiAddress;
  477.             $multiAddress->setUser($this);
  478.         }
  479.         return $this;
  480.     }
  481.     public function removeMultiAddress(Address $multiAddress): self
  482.     {
  483.         if( $this->multiAddress->removeElement($multiAddress)) {
  484.             // set the owning side to null (unless already changed)
  485.             if( $multiAddress->getUser() === $this) {
  486.                 $multiAddress->setUser(null);
  487.             }
  488.         }
  489.         return $this;
  490.     }
  491.     /**
  492.      * @return Collection|Comment[]
  493.      */
  494.     public function getComments(): Collection
  495.     {
  496.         return $this->comments;
  497.     }
  498.     public function addComment(Comment $comment): self
  499.     {
  500.         if( !$this->comments->contains($comment)) {
  501.             $this->comments[] = $comment;
  502.             $comment->setUser($this);
  503.         }
  504.         return $this;
  505.     }
  506.     public function removeComment(Comment $comment): self
  507.     {
  508.         if( $this->comments->removeElement($comment)) {
  509.             // set the owning side to null (unless already changed)
  510.             if( $comment->getUser() === $this) {
  511.                 $comment->setUser(null);
  512.             }
  513.         }
  514.         return $this;
  515.     }
  516.     /**
  517.      * @return Collection|Comment[]
  518.      */
  519.     public function getNotes(): Collection
  520.     {
  521.         return $this->notes;
  522.     }
  523.     public function addNote(Comment $note): self
  524.     {
  525.         if( !$this->notes->contains($note)) {
  526.             $this->notes[] = $note;
  527.             $note->setClient($this);
  528.         }
  529.         return $this;
  530.     }
  531.     public function removeNote(Comment $note): self
  532.     {
  533.         if( $this->notes->removeElement($note)) {
  534.             // set the owning side to null (unless already changed)
  535.             if( $note->getUser() === $this) {
  536.                 $note->setUser(null);
  537.             }
  538.         }
  539.         return $this;
  540.     }
  541.     public function getSupplier(): ?Supplier
  542.     {
  543.         return $this->supplier;
  544.     }
  545.     public function setSupplier(?Supplier $supplier): self
  546.     {
  547.         $this->supplier $supplier;
  548.         return $this;
  549.     }
  550.     public function getPromotion(): ?Promotion
  551.     {
  552.         return $this->promotion;
  553.     }
  554.     public function setPromotion(?Promotion $promotion): self
  555.     {
  556.         $this->promotion $promotion;
  557.         return $this;
  558.     }
  559.     /**
  560.      * @return Collection|Activity[]
  561.      */
  562.     public function getActivities(): Collection
  563.     {
  564.         return $this->activities;
  565.     }
  566.     public function addActivity(Activity $activity): self
  567.     {
  568.         if( !$this->activities->contains($activity)) {
  569.             $this->activities[] = $activity;
  570.             $activity->setCurrentUser($this);
  571.         }
  572.         return $this;
  573.     }
  574.     public function removeActivity(Activity $activity): self
  575.     {
  576.         if( $this->activities->removeElement($activity)) {
  577.             // set the owning side to null (unless already changed)
  578.             if( $activity->getCurrentUser() === $this) {
  579.                 $activity->setCurrentUser(null);
  580.             }
  581.         }
  582.         return $this;
  583.     }
  584.     public function getGroupUser(): ?GroupUser
  585.     {
  586.         return $this->groupUser;
  587.     }
  588.     public function setGroupUser(?GroupUser $groupUser): self
  589.     {
  590.         $this->groupUser $groupUser;
  591.         return $this;
  592.     }
  593.     public function __call($name$arguments)
  594.     {
  595.         // TODO: Implement @method string getUserIdentifier()
  596.     }
  597.     public function jsonSerialize()
  598.     {
  599.         return array(
  600.             'adress' => $this->getAdress(),
  601.             'second_adress' => $this->getSecondAdress(),
  602.             'firstName' => $this->getFirstName(),
  603.             'lastName' => $this->getLastName(),
  604.             'username' => $this->getUsermane(),
  605.             'email' => $this->getEmail(),
  606.             'password' => '',
  607.             'newPassword' => '',
  608.             'confirmPassword' => ''
  609.         );
  610.     }
  611.     /**
  612.      * @return Collection|Produit[]
  613.      */
  614.     public function getProduits(): Collection
  615.     {
  616.         return $this->produits;
  617.     }
  618.     public function addProduit(Produit $produit): self
  619.     {
  620.         if( !$this->produits->contains($produit)) {
  621.             $this->produits[] = $produit;
  622.             $produit->addUser($this);
  623.         }
  624.         return $this;
  625.     }
  626.     public function removeProduit(Produit $produit): self
  627.     {
  628.         if( $this->produits->contains($produit)) {
  629.             $this->produits->removeElement($produit);
  630.             $produit->removeUser($this);
  631.         }
  632.         return $this;
  633.     }
  634.     public function getClientType(): ?string
  635.     {
  636.         return $this->clientType;
  637.     }
  638.     public function setClientType(string $clientType): self
  639.     {
  640.         // Validate if the provided value is one of the valid ENUM values
  641.         if (!in_array($clientTypeClientType::getValidValues(), true)) {
  642.             throw new \InvalidArgumentException("Invalid client type: $clientType");
  643.         }
  644.         $this->clientType $clientType;
  645.         return $this;
  646.     }
  647. }