src/Entity/User.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Config\RightConfig;
  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={"username"}, message="There is already an account with this username")
  15.  * @UniqueEntity(fields={"messengerCode"}, message="This Messenger code is already used")
  16.  * @method string getUserIdentifier()
  17.  */
  18. class User implements UserInterfaceJsonSerializable
  19. {
  20.     /**
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     private $id;
  26.     /**
  27.      * @ORM\Column(type="string", length=180)
  28.      */
  29.     private $username;
  30.     /**
  31.      * @ORM\Column(type="json")
  32.      */
  33.     private $roles = [];
  34.     /**
  35.      * @var string The hashed password
  36.      * @ORM\Column(type="string", nullable=true)
  37.      */
  38.     private $password;
  39.     /**
  40.      * @ORM\Column(type="string", length=255, nullable=true)
  41.      */
  42.     private $civility;
  43.     /**
  44.      * @ORM\Column(type="string", length=255, nullable=true)
  45.      */
  46.     private $firstName;
  47.     /**
  48.      * @ORM\Column(type="string", length=255, nullable=true)
  49.      */
  50.     private $email;
  51.     /**
  52.      * @ORM\Column(type="date", nullable=true)
  53.      */
  54.     private ?\DateTimeInterface $birthDate null;
  55.     /**
  56.      * @ORM\Column(type="text", nullable=true)
  57.      */
  58.     private $description;
  59.     /**
  60.      * @ORM\Column(type="text", nullable=true)
  61.      */
  62.     private ?string $clientSearchNote null;
  63.     /**
  64.      * @ORM\Column(type="string", length=20, nullable=true)
  65.      */
  66.     private $phone;
  67.     /**
  68.      * @ORM\Column(type="string", length=30, nullable=true)
  69.      */
  70.     private $second_phone;
  71.     /**
  72.      * @ORM\Column(type="text", nullable=true)
  73.      */
  74.     private $adress;
  75.     /**
  76.      * @ORM\Column(type="string", length=100, nullable=true)
  77.      */
  78.     private $country;
  79.     /**
  80.      * @ORM\Column(type="string", length=100, nullable=true)
  81.      */
  82.     private $region;
  83.     /**
  84.      * @ORM\Column(type="string", length=255, nullable=true)
  85.      */
  86.     private $city;
  87.     /**
  88.      * @ORM\Column(type="string", length=255, nullable=true)
  89.      */
  90.     private $zip;
  91.     /**
  92.      * @ORM\Column(type="string", length=255, nullable=true)
  93.      */
  94.     private $type;
  95.     /**
  96.      * @ORM\Column(type="boolean")
  97.      */
  98.     private $isVerified false;
  99.     /**
  100.     * @ORM\OneToMany(targetEntity=Link::class, mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
  101.      */
  102.     private $links;
  103.     /**
  104.      * @ORM\Column(type="datetime")
  105.      */
  106.     private $createdAt;
  107.     /**
  108.      * @ORM\Column(type="boolean", options={"default": false})
  109.      */
  110.     private $isBlocked false;
  111.     /**
  112.      * @ORM\Column(type="datetime", nullable=true)
  113.      */
  114.     private $blockedAt;
  115.     /**
  116.      * @ORM\Column(type="datetime", nullable=true)
  117.      */
  118.     private $unblockedAt;
  119.     /**
  120.      * @ORM\Column(type="string", length=255, nullable=true)
  121.      */
  122.     private $blockReason;
  123.     /**
  124.      * @ORM\Column(type="json", nullable=true)
  125.      *
  126.      * Exemple de structure :
  127.      * {
  128.      *   "monday": [{"start": "09:00", "end": "12:00"}, {"start": "14:00", "end": "16:00"}],
  129.      *   "tuesday": [],
  130.      *   "wednesday": [{"start": "10:00", "end": "15:00"}],
  131.      *   ...
  132.      * }
  133.      */
  134.     private $blockedHours = [];
  135.     /**
  136.      * @ORM\OneToMany(targetEntity=Document::class, mappedBy="client")
  137.      */
  138.     private $documents;
  139.     /**
  140.      * @ORM\OneToMany(targetEntity=Document::class, mappedBy="user")
  141.      */
  142.     private $userDocuments;
  143.     /**
  144.      * @ORM\OneToMany(targetEntity=Address::class, mappedBy="user")
  145.      */
  146.     private $multiAddress;
  147.     /**
  148.      * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="user")
  149.      */
  150.     private $comments;
  151.     /**
  152.      * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="client")
  153.      */
  154.     private $notes;
  155.     /**
  156.      * @ORM\ManyToOne(targetEntity=Supplier::class, inversedBy="contacts")
  157.      */
  158.     private $supplier;
  159.     /**
  160.      * @ORM\OneToMany(targetEntity=Contact::class, mappedBy="linkedClient")
  161.      */
  162.     private $contacts;
  163.     /**
  164.      * @ORM\ManyToOne(targetEntity=Promotion::class, inversedBy="clients")
  165.      */
  166.     private $promotion;
  167.     /**
  168.      * @ORM\OneToMany(targetEntity=Activity::class, mappedBy="currentUser")
  169.      * @ORM\OrderBy({"createdAt" = "DESC"})
  170.      */
  171.     private $activities;
  172.     /**
  173.      * @ORM\ManyToMany(targetEntity=Produit::class, mappedBy="users")
  174.      */
  175.     private $produits;
  176.     /**
  177.      * @ORM\ManyToOne(targetEntity=GroupUser::class, inversedBy="users")
  178.      * @ORM\JoinColumn(nullable=true)
  179.      */
  180.     private $groupUser;
  181.     /**
  182.      * @ORM\ManyToMany(targetEntity=GroupUser::class, inversedBy="usersMultiGroups")
  183.      * @ORM\JoinTable(name="user_user_group",
  184.      *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")},
  185.      *      inverseJoinColumns={@ORM\JoinColumn(name="group_user_id", referencedColumnName="id", onDelete="CASCADE")}
  186.      * )
  187.      */
  188.     private $groupUsers;
  189.     /**
  190.      * @ORM\ManyToOne(targetEntity=UserPost::class)
  191.      * @ORM\JoinColumn(name="user_post_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  192.      */
  193.     private $userPost;
  194.    /**
  195.      * @ORM\ManyToOne(targetEntity=ClientType::class)
  196.      * @ORM\JoinColumn(name="client_type_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  197.      */
  198.     private $clientType;
  199.     /**
  200.      * @ORM\Column(type="boolean")
  201.      */
  202.     private $clientTypeLocked false;
  203.     /**
  204.      * @ORM\Column(type="boolean", options={"default": true})
  205.      */
  206.     private $internalMessengerSoundEnabled true;
  207.     /**
  208.      * @ORM\Column(type="boolean", options={"default": false})
  209.      */
  210.     private $internalMessengerBrowserNotificationsEnabled false;
  211.     /**
  212.      * @ORM\Column(type="string", length=10, nullable=true, unique=true)
  213.      */
  214.     private ?string $messengerCode null;
  215.     /**
  216.      * @ORM\ManyToMany(targetEntity=Warehouse::class, inversedBy="users")
  217.      * @ORM\JoinTable(name="user_warehouse")
  218.      */
  219.     private Collection $warehouses;
  220.     public function __construct()
  221.     {
  222.         $this->links = new ArrayCollection();
  223.         $this->documents = new ArrayCollection();
  224.         $this->userDocuments = new ArrayCollection();
  225.         $this->contacts = new ArrayCollection();
  226.         $this->multiAddress = new ArrayCollection();
  227.         $this->comments = new ArrayCollection();
  228.         $this->notes = new ArrayCollection();
  229.         $this->activities = new ArrayCollection();
  230.         $this->produits = new ArrayCollection();
  231.         $this->groupUsers = new ArrayCollection();
  232.         $this->warehouses = new ArrayCollection();
  233.         $this->zip="";
  234.     }
  235.     public function getId(): ?int
  236.     {
  237.         return $this->id;
  238.     }
  239.     public function getUsername(): ?string
  240.     {
  241.         return $this->username;
  242.     }
  243.     public function setUsername(string $username): self
  244.     {
  245.         $this->username $username;
  246.         return $this;
  247.     }
  248.     /**
  249.      * @see UserInterface
  250.      */
  251.     public function getRoles(): array
  252.     {
  253.         $roles $this->roles;
  254.         // guarantee every user at least has ROLE_USER
  255.         $roles[] = 'ROLE_USER';
  256.         return array_unique($roles);
  257.     }
  258.     public function setRoles(array $roles): self
  259.     {
  260.         $this->roles $roles;
  261.         return $this;
  262.     }
  263.     /**
  264.      * @see UserInterface
  265.      */
  266.     public function getPassword(): string
  267.     {
  268.         return (string) $this->password;
  269.     }
  270.     public function setPassword(string $password): self
  271.     {
  272.         $this->password $password;
  273.         return $this;
  274.     }
  275.     /**
  276.      * Returning a salt is only needed, if you are not using a modern
  277.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  278.      *
  279.      * @see UserInterface
  280.      */
  281.     public function getSalt(): ?string
  282.     {
  283.         return null;
  284.     }
  285.     /**
  286.      * @see UserInterface
  287.      */
  288.     public function eraseCredentials()
  289.     {
  290.         // If you store any temporary, sensitive data on the user, clear it here
  291.         // $this->plainPassword = null;
  292.     }
  293.     public function getCivility(): ?string
  294.     {
  295.         return $this->civility;
  296.     }
  297.     public function setCivility(string $civility): self
  298.     {
  299.         $this->civility $civility;
  300.         return $this;
  301.     }
  302.     public function getFirstName(): ?string
  303.     {
  304.         return $this->firstName;
  305.     }
  306.    public function setFirstName(?string $firstName): self
  307.     {
  308.         $this->firstName $firstName;
  309.         return $this;
  310.     }
  311.     public function getFullName(): ?string
  312.     {
  313.         return $this->firstName;
  314.     }
  315.     public function getEmail(): ?string
  316.     {
  317.         return $this->email;
  318.     }
  319.     public function setEmail(?string $email): self
  320.     {
  321.         $this->email $email;
  322.         return $this;
  323.     }
  324.     public function getBirthDate(): ?\DateTimeInterface
  325.     {
  326.         return $this->birthDate;
  327.     }
  328.     public function setBirthDate(?\DateTimeInterface $birthDate): self
  329.     {
  330.         $this->birthDate $birthDate;
  331.         return $this;
  332.     }
  333.     public function getDescription(): ?string
  334.     {
  335.         return $this->description;
  336.     }
  337.     public function setDescription(string $description): self
  338.     {
  339.         $this->description $description;
  340.         return $this;
  341.     }
  342.     public function getClientSearchNote(): ?string
  343.     {
  344.         return $this->clientSearchNote;
  345.     }
  346.     public function setClientSearchNote(?string $clientSearchNote): self
  347.     {
  348.         $clientSearchNote trim((string) $clientSearchNote);
  349.         $this->clientSearchNote $clientSearchNote !== '' $clientSearchNote null;
  350.         return $this;
  351.     }
  352.     public function getPhone(): ?string
  353.     {
  354.         return $this->phone;
  355.     }
  356.     public function setPhone(string $phone): self
  357.     {
  358.         $this->phone $phone;
  359.         return $this;
  360.     }
  361.     public function getSecondPhone(): ?string
  362.     {
  363.         return $this->second_phone;
  364.     }
  365.     public function setSecondPhone(?string $second_phone): self
  366.     {
  367.         $this->second_phone $second_phone;
  368.         return $this;
  369.     }
  370.     public function getAdress(): ?string
  371.     {
  372.         return $this->adress;
  373.     }
  374.      public function setAdress(?string $adress): self
  375.     {
  376.         $this->adress $adress ?? '';
  377.         return $this;
  378.     }
  379.     public function getCountry(): ?string
  380.     {
  381.         return $this->country;
  382.     }
  383.     public function setCountry(string $country): self
  384.     {
  385.         $this->country $country;
  386.         return $this;
  387.     }
  388.     public function getRegion(): ?string
  389.     {
  390.         return $this->region;
  391.     }
  392.     public function setRegion(?string $region): self
  393.     {
  394.         $this->region $region ?? '';
  395.         return $this;
  396.     }
  397.     public function getCity(): ?string
  398.     {
  399.         return $this->city;
  400.     }
  401.     public function setCity(?string $city): self
  402.     {
  403.         $this->city $city ?? '';
  404.         return $this;
  405.     }
  406.     public function getZip(): ?string
  407.     {
  408.         return $this->zip;
  409.     }
  410.     public function setZip(?string $zip): self
  411.     {
  412.         $this->zip $zip ?? '';
  413.         return $this;
  414.     }
  415.     public function getType(): ?string
  416.     {
  417.         return $this->type;
  418.     }
  419.     public function setType(string $type): self
  420.     {
  421.         $this->type $type;
  422.         return $this;
  423.     }
  424.     public function isVerified(): bool
  425.     {
  426.         return $this->isVerified;
  427.     }
  428.     public function setIsVerified(bool $isVerified): self
  429.     {
  430.         $this->isVerified $isVerified;
  431.         return $this;
  432.     }
  433.     /**
  434.      * @return Collection|Link[]
  435.      */
  436.     public function getLinks(): Collection
  437.     {
  438.         return $this->links;
  439.     }
  440.     public function addLink(Link $link): self
  441.     {
  442.         if( !$this->links->contains($link)) {
  443.             $this->links[] = $link;
  444.             $link->setUser($this);
  445.         }
  446.         return $this;
  447.     }
  448.     public function removeLink(Link $link): self
  449.     {
  450.         if( $this->links->removeElement($link)) {
  451.             // set the owning side to null (unless already changed)
  452.             if( $link->getUser() === $this) {
  453.                 $link->setUser(null);
  454.             }
  455.         }
  456.         return $this;
  457.     }
  458.     public function getCreatedAt(): ?\DateTimeInterface
  459.     {
  460.         return $this->createdAt;
  461.     }
  462.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  463.     {
  464.         $this->createdAt $createdAt;
  465.         return $this;
  466.     }
  467.     public function getBlockedHours(): ?array
  468.     {
  469.         return $this->blockedHours;
  470.     }
  471.     public function setBlockedHours(?array $blockedHours): self
  472.     {
  473.         $this->blockedHours $blockedHours;
  474.         return $this;
  475.     }
  476.     public function isBlocked(): bool
  477.     {
  478.         return (bool) $this->isBlocked || $this->isBlockedAt();
  479.     }
  480.     public function isAutoBlocked(): bool
  481.     {
  482.         return $this->isBlacklisted === true;
  483.     }
  484.     public function isManuallyBlocked(): bool
  485.     {
  486.         return $this->isBlocked === true;
  487.     }
  488.     public function canCreateCommande(): bool
  489.     {
  490.         return !$this->isManuallyBlocked();
  491.     }
  492.     // Nouvelle méthode avec tes paramètres (nom différent)
  493.     public function isBlockedAt( ?\DateTimeInterface $now null,?\DateTimeZone $tz null): bool {
  494.         $tz  $tz ?: new \DateTimeZone('Africa/Tunis');
  495.         $now $now ? (new \DateTimeImmutable($now->format('c')))->setTimezone($tz)
  496.                     : new \DateTimeImmutable('now'$tz);
  497.         // 1) Blocage permanent
  498.         if (!empty($this->isBlocked)) {
  499.             return true;
  500.         }
  501.         // 2) Blocage entre deux dates
  502.         $ba $this->blockedAt  instanceof \DateTimeInterface ? (new \DateTimeImmutable($this->blockedAt->format('c')))->setTimezone($tz) : null;
  503.         $ua $this->unblockedAt instanceof \DateTimeInterface ? (new \DateTimeImmutable($this->unblockedAt->format('c')))->setTimezone($tz) : null;
  504.         if ($ba) {
  505.             if ($ua) {
  506.                 if ($now >= $ba && $now $ua) return true;
  507.             } else {
  508.                 if ($now >= $ba) return true;
  509.             }
  510.         }
  511.         // 3) Plages horaires quotidiennes
  512.         if (empty($this->blockedHours) || !is_array($this->blockedHours)) {
  513.             return false;
  514.         }
  515.         $map = [
  516.             'monday'=>'mon','mon'=>'mon',
  517.             'tuesday'=>'tue','tue'=>'tue',
  518.             'wednesday'=>'wed','wed'=>'wed',
  519.             'thursday'=>'thu','thu'=>'thu',
  520.             'friday'=>'fri','fri'=>'fri',
  521.             'saturday'=>'sat','sat'=>'sat',
  522.             'sunday'=>'sun','sun'=>'sun',
  523.             '1'=>'mon','2'=>'tue','3'=>'wed','4'=>'thu','5'=>'fri','6'=>'sat','7'=>'sun','0'=>'sun',
  524.         ];
  525.         $key strtolower($now->format('D')); // mon..sun
  526.         $key $map[$key] ?? $key;
  527.         $ranges $this->blockedHours[$key] ?? [];
  528.         if (empty($ranges) || !is_array($ranges)) return false;
  529.         $toMin = static function (?string $hm): ?int {
  530.             if (!$hm || !preg_match('/^(\d{1,2}):(\d{2})$/'$hm$m)) return null;
  531.             return ((int)$m[1]) * 60 + (int)$m[2];
  532.         };
  533.         $nowMin = (int)$now->format('H') * 60 + (int)$now->format('i');
  534.         foreach ($ranges as $r) {
  535.             $start $toMin($r['start'] ?? null);
  536.             $end   $toMin($r['end']   ?? null);
  537.             if ($start === null && $end === null) continue;
  538.             if ($start !== null && $end !== null) {
  539.                 if ($start $end) {
  540.                     if ($nowMin >= $start && $nowMin $end) return true;
  541.                 } elseif ($start $end) {
  542.                     if ($nowMin >= $start || $nowMin $end) return true;
  543.                 } else {
  544.                     continue;
  545.                 }
  546.             }
  547.         }
  548.         return false;
  549.     }
  550.     public function getIsBlocked(): bool
  551.     {
  552.         return $this->isBlocked;
  553.     }
  554.     public function setIsBlocked(bool $blocked): self
  555.     {
  556.         $this->isBlocked $blocked;
  557.         return $this;
  558.     }
  559.     public function getBlockedAt(): ?\DateTimeInterface
  560.     {
  561.         return $this->blockedAt;
  562.     }
  563.     public function setBlockedAt(?\DateTimeInterface $date): self
  564.     {
  565.         $this->blockedAt $date;
  566.         return $this;
  567.     }
  568.     public function getUnblockedAt(): ?\DateTimeInterface
  569.     {
  570.         return $this->unblockedAt;
  571.     }
  572.     public function setUnblockedAt(?\DateTimeInterface $date): self
  573.     {
  574.         $this->unblockedAt $date;
  575.         return $this;
  576.     }
  577.     public function getBlockReason(): ?string
  578.     {
  579.         return $this->blockReason;
  580.     }
  581.     public function setBlockReason(?string $reason): self
  582.     {
  583.         $this->blockReason $reason;
  584.         return $this;
  585.     }
  586.     /**
  587.      * @return Collection|Document[]
  588.      */
  589.     public function getDocuments(): Collection
  590.     {
  591.         return $this->documents;
  592.     }
  593.     public function addDocument(Document $document): self
  594.     {
  595.         if( !$this->documents->contains($document)) {
  596.             $this->documents[] = $document;
  597.             $document->setClient($this);
  598.         }
  599.         return $this;
  600.     }
  601.     public function removeDocument(Document $document): self
  602.     {
  603.         if( $this->documents->removeElement($document)) {
  604.             // set the owning side to null (unless already changed)
  605.             if( $document->getClient() === $this) {
  606.                 $document->setClient(null);
  607.             }
  608.         }
  609.         return $this;
  610.     }
  611.     /**
  612.      * @return Collection|Document[]
  613.      */
  614.     public function getUserDocuments(): Collection
  615.     {
  616.         return $this->userDocuments;
  617.     }
  618.     public function addUserDocument(Document $userDocument): self
  619.     {
  620.         if( !$this->userDocuments->contains($userDocument)) {
  621.             $this->userDocuments[] = $userDocument;
  622.             $userDocument->setUser($this);
  623.         }
  624.         return $this;
  625.     }
  626.     public function removeUserDocument(Document $userDocument): self
  627.     {
  628.         if( $this->userDocuments->removeElement($userDocument)) {
  629.             // set the owning side to null (unless already changed)
  630.             if( $userDocument->getUser() === $this) {
  631.                 $userDocument->setUser(null);
  632.             }
  633.         }
  634.         return $this;
  635.     }
  636.     /**
  637.      * @return Collection|Address[]
  638.      */
  639.     public function getMultiAddress(): Collection
  640.     {
  641.         return $this->multiAddress;
  642.     }
  643.     public function addMultiAddress(Address $multiAddress): self
  644.     {
  645.         if( !$this->multiAddress->contains($multiAddress)) {
  646.             $this->multiAddress[] = $multiAddress;
  647.             $multiAddress->setUser($this);
  648.         }
  649.         return $this;
  650.     }
  651.     public function removeMultiAddress(Address $multiAddress): self
  652.     {
  653.         if( $this->multiAddress->removeElement($multiAddress)) {
  654.             // set the owning side to null (unless already changed)
  655.             if( $multiAddress->getUser() === $this) {
  656.                 $multiAddress->setUser(null);
  657.             }
  658.         }
  659.         return $this;
  660.     }
  661.     /**
  662.      * @return Collection|Comment[]
  663.      */
  664.     public function getComments(): Collection
  665.     {
  666.         return $this->comments;
  667.     }
  668.     public function addComment(Comment $comment): self
  669.     {
  670.         if( !$this->comments->contains($comment)) {
  671.             $this->comments[] = $comment;
  672.             $comment->setUser($this);
  673.         }
  674.         return $this;
  675.     }
  676.     public function removeComment(Comment $comment): self
  677.     {
  678.         if( $this->comments->removeElement($comment)) {
  679.             // set the owning side to null (unless already changed)
  680.             if( $comment->getUser() === $this) {
  681.                 $comment->setUser(null);
  682.             }
  683.         }
  684.         return $this;
  685.     }
  686.     /**
  687.      * @return Collection|Comment[]
  688.      */
  689.     public function getNotes(): Collection
  690.     {
  691.         return $this->notes;
  692.     }
  693.     public function addNote(Comment $note): self
  694.     {
  695.         if( !$this->notes->contains($note)) {
  696.             $this->notes[] = $note;
  697.             $note->setClient($this);
  698.         }
  699.         return $this;
  700.     }
  701.     public function removeNote(Comment $note): self
  702.     {
  703.         if( $this->notes->removeElement($note)) {
  704.             // set the owning side to null (unless already changed)
  705.             if( $note->getUser() === $this) {
  706.                 $note->setUser(null);
  707.             }
  708.         }
  709.         return $this;
  710.     }
  711.     public function getSupplier(): ?Supplier
  712.     {
  713.         return $this->supplier;
  714.     }
  715.     public function setSupplier(?Supplier $supplier): self
  716.     {
  717.         $this->supplier $supplier;
  718.         return $this;
  719.     }
  720.     /**
  721.      * @return Collection<int, Contact>
  722.      */
  723.     public function getContacts(): Collection
  724.     {
  725.         return $this->contacts;
  726.     }
  727.     public function addContact(Contact $contact): self
  728.     {
  729.         if (!$this->contacts->contains($contact)) {
  730.             $this->contacts[] = $contact;
  731.             $contact->setLinkedClient($this);
  732.         }
  733.         return $this;
  734.     }
  735.     public function removeContact(Contact $contact): self
  736.     {
  737.         if ($this->contacts->removeElement($contact)) {
  738.             if ($contact->getLinkedClient() === $this) {
  739.                 $contact->setLinkedClient(null);
  740.             }
  741.         }
  742.         return $this;
  743.     }
  744.     public function getPromotion(): ?Promotion
  745.     {
  746.         return $this->promotion;
  747.     }
  748.     public function setPromotion(?Promotion $promotion): self
  749.     {
  750.         $this->promotion $promotion;
  751.         return $this;
  752.     }
  753.     /**
  754.      * @return Collection|Activity[]
  755.      */
  756.     public function getActivities(): Collection
  757.     {
  758.         return $this->activities;
  759.     }
  760.     public function addActivity(Activity $activity): self
  761.     {
  762.         if( !$this->activities->contains($activity)) {
  763.             $this->activities[] = $activity;
  764.             $activity->setCurrentUser($this);
  765.         }
  766.         return $this;
  767.     }
  768.     public function removeActivity(Activity $activity): self
  769.     {
  770.         if( $this->activities->removeElement($activity)) {
  771.             // set the owning side to null (unless already changed)
  772.             if( $activity->getCurrentUser() === $this) {
  773.                 $activity->setCurrentUser(null);
  774.             }
  775.         }
  776.         return $this;
  777.     }
  778.     public function getGroupUser(): ?GroupUser
  779.     {
  780.         return $this->groupUser;
  781.     }
  782.     /**
  783.      * @return Collection|GroupUser[]
  784.      */
  785.     public function getGroupUsers(): Collection
  786.     {
  787.         return $this->groupUsers;
  788.     }
  789.     public function addGroupUser(GroupUser $groupUser): self
  790.     {
  791.         if (!$this->groupUsers->contains($groupUser)) {
  792.             $this->groupUsers[] = $groupUser;
  793.             $groupUser->addUsersMultiGroup($this);
  794.         }
  795.         return $this;
  796.     }
  797.     public function removeGroupUser(GroupUser $groupUser): self
  798.     {
  799.         if ($this->groupUsers->removeElement($groupUser)) {
  800.             $groupUser->removeUsersMultiGroup($this);
  801.             if ($this->groupUser && $this->isSameGroupUser($this->groupUser$groupUser)) {
  802.                 $this->groupUser $this->getFirstAssignedGroupUser();
  803.             }
  804.         }
  805.         return $this;
  806.     }
  807.     public function setGroupUsers(iterable $groupUsers): self
  808.     {
  809.         foreach ($this->groupUsers->toArray() as $existingGroupUser) {
  810.             $this->removeGroupUser($existingGroupUser);
  811.         }
  812.         foreach ($groupUsers as $groupUser) {
  813.             if ($groupUser instanceof GroupUser) {
  814.                 $this->addGroupUser($groupUser);
  815.             }
  816.         }
  817.         return $this;
  818.     }
  819.     /**
  820.      * @return GroupUser[]
  821.      */
  822.     public function getEffectiveGroupUsers(): array
  823.     {
  824.         $groups = [];
  825.         $seen = [];
  826.         $append = static function (?GroupUser $groupUser) use (&$groups, &$seen): void {
  827.             if (!$groupUser) {
  828.                 return;
  829.             }
  830.             $key $groupUser->getId() !== null
  831.                 'id:' $groupUser->getId()
  832.                 : 'obj:' spl_object_hash($groupUser);
  833.             if (isset($seen[$key])) {
  834.                 return;
  835.             }
  836.             $seen[$key] = true;
  837.             $groups[] = $groupUser;
  838.         };
  839.         $append($this->groupUser);
  840.         foreach ($this->groupUsers as $groupUser) {
  841.             $append($groupUser);
  842.         }
  843.         return $groups;
  844.     }
  845.     /**
  846.      * @return string[]
  847.      */
  848.     public function getEffectiveGroupUserNames(): array
  849.     {
  850.         $names = [];
  851.         foreach ($this->getEffectiveGroupUsers() as $groupUser) {
  852.             $name trim((string) $groupUser->getName());
  853.             if ($name !== '') {
  854.                 $names[] = $name;
  855.             }
  856.         }
  857.         return array_values(array_unique($names));
  858.     }
  859.     public function getEffectiveGroupUserLabel(): string
  860.     {
  861.         $names $this->getEffectiveGroupUserNames();
  862.         return $names !== [] ? implode(', '$names) : 'Sans groupe';
  863.     }
  864.     public function syncLegacyGroupUserIntoGroupUsers(): self
  865.     {
  866.         if ($this->groupUser instanceof GroupUser) {
  867.             $this->addGroupUser($this->groupUser);
  868.         }
  869.         return $this;
  870.     }
  871.     public function syncPrimaryGroupUserFromGroupUsers(): self
  872.     {
  873.         if ($this->groupUser instanceof GroupUser && !$this->hasAssignedGroupUser($this->groupUser)) {
  874.             $this->groupUser null;
  875.         }
  876.         if ($this->groupUser === null) {
  877.             $this->groupUser $this->getFirstAssignedGroupUser();
  878.         }
  879.         return $this;
  880.     }
  881.     public function getArrayRight(): array
  882.     {
  883.         if (in_array('ROLE_SUPER_ADMIN', (array) $this->getRoles(), true)) {
  884.             return RightConfig::allCodes();
  885.         }
  886.         $rights = [];
  887.         foreach ($this->getEffectiveGroupUsers() as $groupUser) {
  888.             foreach ($groupUser->getRights() as $right) {
  889.                 if ($right && method_exists($right'getCode')) {
  890.                     $rights[] = (string) $right->getCode();
  891.                 }
  892.             }
  893.         }
  894.         return array_values(array_unique(array_filter($rights)));
  895.     }
  896.     public function setGroupUser(?GroupUser $groupUser): self
  897.     {
  898.         $this->groupUser $groupUser;
  899.         if ($groupUser instanceof GroupUser) {
  900.             $this->addGroupUser($groupUser);
  901.         }
  902.         return $this;
  903.     }
  904.     public function getUserPost(): ?UserPost
  905.     {
  906.         return $this->userPost;
  907.     }
  908.     public function setUserPost(?UserPost $post): self
  909.     {
  910.         $this->userPost $post;
  911.         return $this;
  912.     }
  913.     public function __call($name$arguments)
  914.     {
  915.         // TODO: Implement @method string getUserIdentifier()
  916.     }
  917.     private function hasAssignedGroupUser(GroupUser $groupUser): bool
  918.     {
  919.         foreach ($this->groupUsers as $assignedGroupUser) {
  920.             if ($this->isSameGroupUser($assignedGroupUser$groupUser)) {
  921.                 return true;
  922.             }
  923.         }
  924.         return false;
  925.     }
  926.     private function getFirstAssignedGroupUser(): ?GroupUser
  927.     {
  928.         foreach ($this->groupUsers as $groupUser) {
  929.             if ($groupUser instanceof GroupUser) {
  930.                 return $groupUser;
  931.             }
  932.         }
  933.         return null;
  934.     }
  935.     private function isSameGroupUser(?GroupUser $left, ?GroupUser $right): bool
  936.     {
  937.         if (!$left || !$right) {
  938.             return false;
  939.         }
  940.         if ($left->getId() !== null && $right->getId() !== null) {
  941.             return $left->getId() === $right->getId();
  942.         }
  943.         return $left === $right;
  944.     }
  945.     #[\ReturnTypeWillChange]
  946.     public function jsonSerialize()
  947.     {
  948.         return array(
  949.             'adress' => $this->getAdress(),
  950.             'firstName' => $this->getFirstName(),
  951.             'username' => $this->getUsername(),
  952.             'email' => $this->getEmail(),
  953.             'birthDate' => $this->getBirthDate() ? $this->getBirthDate()->format('Y-m-d') : null,
  954.             'password' => '',
  955.             'newPassword' => '',
  956.             'confirmPassword' => ''
  957.         );
  958.     }
  959.     /**
  960.      * @return Collection|Produit[]
  961.      */
  962.     public function getProduits(): Collection
  963.     {
  964.         return $this->produits;
  965.     }
  966.     public function addProduit(Produit $produit): self
  967.     {
  968.         if( !$this->produits->contains($produit)) {
  969.             $this->produits[] = $produit;
  970.             $produit->addUser($this);
  971.         }
  972.         return $this;
  973.     }
  974.     public function removeProduit(Produit $produit): self
  975.     {
  976.         if( $this->produits->contains($produit)) {
  977.             $this->produits->removeElement($produit);
  978.             $produit->removeUser($this);
  979.         }
  980.         return $this;
  981.     }
  982.    public function getClientType(): ?ClientType
  983.     {
  984.         return $this->clientType;
  985.     }
  986.     public function setClientType(?ClientType $clientType): self
  987.     {
  988.         $this->clientType $clientType;
  989.         return $this;
  990.     }
  991.     public function isClientTypeLocked(): bool
  992.     {
  993.         return (bool) $this->clientTypeLocked;
  994.     }
  995.     public function setClientTypeLocked(bool $locked): self
  996.     {
  997.         $this->clientTypeLocked $locked;
  998.         return $this;
  999.     }
  1000.     public function getClientTypeCode(): ?string
  1001.     {
  1002.         return $this->clientType $this->clientType->getCode() : null;
  1003.     }
  1004.     public function isBlacklisted(): bool
  1005.     {
  1006.         return $this->getClientTypeCode() === 'BLACKLIST';
  1007.     }
  1008.     public function getInternalMessengerSoundEnabled(): bool
  1009.     {
  1010.         return (bool) $this->internalMessengerSoundEnabled;
  1011.     }
  1012.     public function setInternalMessengerSoundEnabled(bool $internalMessengerSoundEnabled): self
  1013.     {
  1014.         $this->internalMessengerSoundEnabled $internalMessengerSoundEnabled;
  1015.         return $this;
  1016.     }
  1017.     public function getInternalMessengerBrowserNotificationsEnabled(): bool
  1018.     {
  1019.         return (bool) $this->internalMessengerBrowserNotificationsEnabled;
  1020.     }
  1021.     public function setInternalMessengerBrowserNotificationsEnabled(bool $internalMessengerBrowserNotificationsEnabled): self
  1022.     {
  1023.         $this->internalMessengerBrowserNotificationsEnabled $internalMessengerBrowserNotificationsEnabled;
  1024.         return $this;
  1025.     }
  1026.     public function getMessengerCode(): ?string
  1027.     {
  1028.         return $this->messengerCode;
  1029.     }
  1030.     public function setMessengerCode(?string $messengerCode): self
  1031.     {
  1032.         $messengerCode trim((string) $messengerCode);
  1033.         $this->messengerCode $messengerCode !== '' $messengerCode null;
  1034.         return $this;
  1035.     }
  1036.     /**
  1037.      * @return Collection|Warehouse[]
  1038.      */
  1039.     public function getWarehouses(): Collection
  1040.     {
  1041.         return $this->warehouses;
  1042.     }
  1043.     public function addWarehouse(Warehouse $warehouse): self
  1044.     {
  1045.         if (!$this->warehouses->contains($warehouse)) {
  1046.             $this->warehouses->add($warehouse);
  1047.         }
  1048.         return $this;
  1049.     }
  1050.     public function removeWarehouse(Warehouse $warehouse): self
  1051.     {
  1052.         $this->warehouses->removeElement($warehouse);
  1053.         return $this;
  1054.     }
  1055. }