src/Entity/User.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\Post;
  4. use ApiPlatform\Metadata\GetCollection;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Patch;
  7. use ApiPlatform\Metadata\Put;
  8. use ApiPlatform\Metadata\Get;
  9. use ApiPlatform\Metadata\ApiResource;
  10. use App\Repository\UserRepository;
  11. use DateTimeInterface;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  16. use Symfony\Component\Security\Core\User\UserInterface;
  17. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. #[ApiResource(operations: [new Get(), new Put(security'is_granted(\'ROLE_SUPER_ADMIN\')'securityMessage'Accès Interdit'), new Patch(security'is_granted(\'ROLE_SUPER_ADMIN\')'securityMessage'Accès Interdit'), new Delete(security'is_granted(\'ROLE_SUPER_ADMIN\')'securityMessage'Accès Interdit'), new GetCollection(), new Post(security'is_granted(\'ROLE_SUPER_ADMIN\')'securityMessage'Accès Interdit')])]
  20. #[ORM\Entity(repositoryClassUserRepository::class)]
  21. #[UniqueEntity(fields: ['email'], errorPath'email'message'Cet email est déjà utilisé. Veuillez vous connecter.')]
  22. class User implements UserInterfacePasswordAuthenticatedUserInterface
  23. {
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column(type'integer')]
  27.     private $id;
  28.     #[ORM\Column(type'string'length180uniquetruenullabletrue)]
  29.     #[Assert\Regex(pattern'/^\S+@\S+\.\S+$/'message'Le champ "Email" doit être une adresse email valide.')]
  30.     private ?string $email null;
  31.     #[ORM\Column(type'json')]
  32.     private array $roles = ['ROLE_USER'];
  33.     /**
  34.      * @var string The hashed password
  35.      */
  36.     #[ORM\Column(type'string'nullabletrue)]
  37.     #[Assert\Regex(pattern'/^(?=.{6,}$)(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*?\W).*$/'message'Votre mot de passe doit contenir au moins 8 caractères dont une majuscule, un chiffre et un caractère spécial')]
  38.     private ?string $password null;
  39.     #[ORM\Column(type'string'length50nullabletrue)]
  40.     private ?string $name null;
  41.     #[ORM\Column(type'string'length100nullabletrue)]
  42.     private ?string $lastName null;
  43.     #[Assert\Regex(pattern'/^(\+\d{2}|\d{2})?\s?\d{2}(\s?\d{2}){3}$/'message'Le numéro de téléphone n\'est pas valide.')]
  44.     #[ORM\Column(type'string'length20nullabletrue)]
  45.     private ?string $phone null;
  46.     #[ORM\Column(type'date'nullabletrue)]
  47.     #[Assert\LessThanOrEqual(value'-15 years'message"Vous devez être agé d'au moins 15 ans.")]
  48.     private ?DateTimeInterface $birthDate null;
  49.     #[ORM\Column(type'text'nullabletrue)]
  50.     private ?string $address null;
  51.     #[ORM\Column(type'string'length255nullabletrue)]
  52.     private ?string $additionalAddress null;
  53.     #[ORM\Column(type'string'length100nullabletrue)]
  54.     private ?string $city null;
  55.     #[ORM\Column(type'string'length5nullabletrue)]
  56.     #[Assert\Regex(pattern'/^(?:[0-8]\d|9[0-8])\d{3}$/'message'Le code postal n\'est pas valide.')]
  57.     private ?string $postalCode null;
  58.     #[ORM\Column(type'boolean'nullabletrue)]
  59.     private ?bool $isAccept null;
  60.     #[ORM\Column(type'boolean'nullabletrue)]
  61.     private ?bool $isActivated null;
  62.     #[ORM\Column(type'string'length255nullabletrue)]
  63.     private ?string $smsToken null;
  64.     #[ORM\JoinTable(name'entity_admin')]
  65.     #[ORM\ManyToMany(targetEntityEntity::class, mappedBy'admins')]
  66.     private Collection $entitiesAdmins;
  67.     #[ORM\ManyToMany(targetEntityProfile::class, inversedBy'users')]
  68.     private Collection $profiles;
  69.     #[ORM\Column(type'string'length255nullabletrue)]
  70.     private ?string $picture null;
  71.     #[ORM\ManyToOne(targetEntityEntity::class, cascade: ['persist'])]
  72.     #[ORM\JoinColumn(name'selected_entity_id'referencedColumnName'id'onDelete'SET NULL')]
  73.     private ?Entity $selectedEntity null;
  74.     #[ORM\OneToMany(targetEntityUserEntity::class, mappedBy'user'orphanRemovaltruecascade: ['persist'])]
  75.     private Collection $userEntities;
  76.     #[ORM\OneToMany(targetEntityAnswer::class, mappedBy'author')]
  77.     private Collection $answers;
  78.     #[ORM\OneToMany(targetEntitySavedNotification::class, mappedBy'user'orphanRemovaltrue)]
  79.     private Collection $notifications;
  80.     #[ORM\OneToMany(targetEntityComment::class, mappedBy'author'orphanRemovaltrue)]
  81.     private array|Collection $comments;
  82.     #[ORM\OneToOne(targetEntityDevice::class, cascade: ['persist''remove'])]
  83.     private ?Device $device null;
  84.     #[ORM\Column(type'date')]
  85.     private \DateTime $createdDate;
  86.     #[ORM\OneToMany(targetEntityLike::class, mappedBy'author'orphanRemovaltrue)]
  87.     private Collection $likes;
  88.     #[ORM\OneToOne(targetEntityNotifParams::class, mappedBy'user'cascade: ['persist''remove'])]
  89.     private NotifParams $notifParams;
  90.     #[ORM\Column(type'string'length255nullabletrue)]
  91.     private ?string $resetToken null;
  92.     /**
  93.      * @var ArrayCollection
  94.      */
  95.     private Collection $entities;
  96.     /**
  97.      * @var string
  98.      */
  99.     private string $emailVerif;
  100.     #[ORM\Column(type'integer'nullabletrue)]
  101.     #[Assert\Length(min14max14minMessage'Numéro invalide'maxMessage'Numéro invalide'exactMessage'Numéro invalide')]
  102.     private ?int $numberGU null;
  103.     #[ORM\OneToMany(targetEntityUserConnexion::class, mappedBy'user'cascade: ['remove'])]
  104.     private Collection $userConnexions;
  105.     #[ORM\OneToMany(targetEntityLog::class, mappedBy'user'cascade: ['remove'])]
  106.     private Collection $logs;
  107.     #[ORM\ManyToMany(targetEntityTerritory::class, mappedBy'admins')]
  108.     private Collection $adminTerritories;
  109.     #[ORM\ManyToMany(targetEntityTerritory::class, mappedBy'members')]
  110.     private Collection $territories;
  111.     public function __construct()
  112.     {
  113.         $this->profiles = new ArrayCollection();
  114.         $this->answers = new ArrayCollection();
  115.         $this->notifications = new ArrayCollection();
  116.         $this->userEntities = new ArrayCollection();
  117.         $this->entitiesAdmins = new ArrayCollection();
  118.         $this->createdDate = new \DateTime();
  119.         $this->likes = new ArrayCollection();
  120.         $this->entities = new ArrayCollection();
  121.         $this->notifParams = new NotifParams();
  122.         $this->notifParams->setUser($this);
  123.         $this->userConnexions = new ArrayCollection();
  124.         $this->logs = new ArrayCollection();
  125.         $this->adminTerritories = new ArrayCollection();
  126.         $this->territories = new ArrayCollection();
  127.     }
  128.     public function getId() : ?int
  129.     {
  130.         return $this->id;
  131.     }
  132.     public function getEmail() : ?string
  133.     {
  134.         return $this->email;
  135.     }
  136.     public function setEmail(?string $email) : self
  137.     {
  138.         $this->email $email;
  139.         return $this;
  140.     }
  141.     /**
  142.      * A visual identifier that represents this user.
  143.      *
  144.      * @see UserInterface
  145.      */
  146.     public function getUsername() : string
  147.     {
  148.         return (string) $this->email;
  149.     }
  150.     /**
  151.      * @see UserInterface
  152.      */
  153.     public function getRoles() : array
  154.     {
  155.         $roles $this->roles;
  156.         // guarantee every user at least has ROLE_USER
  157.         //$roles[] = 'ROLE_USER';
  158.         return array_unique($roles);
  159.     }
  160.     public function setRoles(array $roles) : self
  161.     {
  162.         $this->roles $roles;
  163.         return $this;
  164.     }
  165.     public function addRole(string $role) : self
  166.     {
  167.         if (!array_search($role$this->roles)){
  168.             $this->roles[] = $role;
  169.         }
  170.         return $this;
  171.     }
  172.     public function removeRole(string $role) : self
  173.     {
  174.         $index array_search($role$this->roles);
  175.         if ($index){
  176.             array_splice($this->roles$index1);
  177.         }
  178.         return $this;
  179.     }
  180.     public function toggleRole(string $role) : self
  181.     {
  182.         $index array_search($role$this->roles);
  183.         if ($index){
  184.             array_splice($this->roles$index1);
  185.         } else {
  186.             $this->roles[] = $role;
  187.         }
  188.         return $this;
  189.     }
  190.     /**
  191.      * @see UserInterface
  192.      */
  193.     public function getPassword() : ?string
  194.     {
  195.         return (string) $this->password;
  196.     }
  197.     public function setPassword(?string $password) : self
  198.     {
  199.         $this->password $password;
  200.         return $this;
  201.     }
  202.     /**
  203.      * Returning a salt is only needed, if you are not using a modern
  204.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  205.      *
  206.      * @see UserInterface
  207.      */
  208.     public function getSalt() : ?string
  209.     {
  210.         return null;
  211.     }
  212.     /**
  213.      * @see UserInterface
  214.      */
  215.     public function eraseCredentials()
  216.     {
  217.         // If you store any temporary, sensitive data on the user, clear it here
  218.         // $this->plainPassword = null;
  219.     }
  220.     public function getName() : ?string
  221.     {
  222.         return $this->name;
  223.     }
  224.     public function setName(?string $name) : self
  225.     {
  226.         $this->name $name;
  227.         return $this;
  228.     }
  229.     public function getLastName() : ?string
  230.     {
  231.         return $this->lastName;
  232.     }
  233.     public function setLastName(?string $lastName) : self
  234.     {
  235.         $this->lastName $lastName;
  236.         return $this;
  237.     }
  238.     public function getPhone() : ?string
  239.     {
  240.         return $this->phone;
  241.     }
  242.     public function setPhone(?string $phone) : self
  243.     {
  244.         $this->phone $phone;
  245.         return $this;
  246.     }
  247.     public function getBirthDate() : ?DateTimeInterface
  248.     {
  249.         return $this->birthDate;
  250.     }
  251.     public function setBirthDate(?DateTimeInterface $birthDate) : self
  252.     {
  253.         $this->birthDate $birthDate;
  254.         return $this;
  255.     }
  256.     public function getAddress() : ?string
  257.     {
  258.         return $this->address;
  259.     }
  260.     public function setAddress(?string $address) : self
  261.     {
  262.         $this->address $address;
  263.         return $this;
  264.     }
  265.     public function getAdditionalAddress() : ?string
  266.     {
  267.         return $this->additionalAddress;
  268.     }
  269.     public function setAdditionalAddress(?string $additionalAddress) : self
  270.     {
  271.         $this->additionalAddress $additionalAddress;
  272.         return $this;
  273.     }
  274.     public function getCity() : ?string
  275.     {
  276.         return $this->city;
  277.     }
  278.     public function setCity(?string $city) : self
  279.     {
  280.         $this->city $city;
  281.         return $this;
  282.     }
  283.     public function getPostalCode() : ?string
  284.     {
  285.         return $this->postalCode;
  286.     }
  287.     public function setPostalCode(?string $postalCode) : self
  288.     {
  289.         $this->postalCode $postalCode;
  290.         return $this;
  291.     }
  292.     public function getIsAccept() : ?bool
  293.     {
  294.         return $this->isAccept;
  295.     }
  296.     public function setIsAccept(bool $isAccept) : self
  297.     {
  298.         $this->isAccept $isAccept;
  299.         return $this;
  300.     }
  301.     public function getIsActivated() : ?bool
  302.     {
  303.         return $this->isActivated;
  304.     }
  305.     public function setIsActivated(bool $isActivated) : self
  306.     {
  307.         $this->isActivated $isActivated;
  308.         return $this;
  309.     }
  310.     public function getSmsToken() : ?string
  311.     {
  312.         return $this->smsToken;
  313.     }
  314.     public function setSmsToken(?string $smsToken) : self
  315.     {
  316.         $this->smsToken $smsToken;
  317.         return $this;
  318.     }
  319.     /**
  320.      * @return Collection|Entity[]
  321.      */
  322.     public function getEntitiesAdmins() : ?Collection
  323.     {
  324.         return $this->entitiesAdmins;
  325.     }
  326.     public function addEntityAdmins(Entity $entity) : self
  327.     {
  328.         if (!$this->entitiesAdmins->contains($entity)) {
  329.             $this->entitiesAdmins[] = $entity;
  330.             $entity->addAdmin($this);
  331.         }
  332.         return $this;
  333.     }
  334.     public function removeEntityAdmins(Entity $entity) : self
  335.     {
  336.         if ($this->entitiesAdmins->removeElement($entity)) {
  337.             $entity->removeAdmin($this);
  338.         }
  339.         return $this;
  340.     }
  341.     /**
  342.      * @return Collection|Profile[]
  343.      */
  344.     public function getProfiles() : Collection
  345.     {
  346.         return $this->profiles;
  347.     }
  348.     public function addProfile(Profile $profile) : self
  349.     {
  350.         if (!$this->profiles->contains($profile)) {
  351.             $this->profiles[] = $profile;
  352.         }
  353.         return $this;
  354.     }
  355.     public function setProfiles(array $profiles) : self
  356.     {
  357.         $this->profiles[] = $profiles;
  358.         return $this;
  359.     }
  360.     public function removeProfile(Profile $profile) : self
  361.     {
  362.         $this->profiles->removeElement($profile);
  363.         return $this;
  364.     }
  365.     public function getPicture() : ?string
  366.     {
  367.         return $this->picture;
  368.     }
  369.     public function setPicture(?string $picture) : self
  370.     {
  371.         $this->picture $picture;
  372.         return $this;
  373.     }
  374.     public function getSelectedEntity() : ?Entity
  375.     {
  376.         return $this->selectedEntity;
  377.     }
  378.     public function setSelectedEntity(?Entity $selectedEntity) : self
  379.     {
  380.         $this->selectedEntity $selectedEntity;
  381.         return $this;
  382.     }
  383.     /**
  384.      * @return Collection|UserEntity[]
  385.      */
  386.     public function getUserEntities() : Collection
  387.     {
  388.         return $this->userEntities;
  389.     }
  390.     public function addUserEntity(UserEntity $userEntity) : self
  391.     {
  392.         if (!$this->userEntities->contains($userEntity)) {
  393.             $this->userEntities[] = $userEntity;
  394.             $userEntity->setUser($this);
  395.         }
  396.         return $this;
  397.     }
  398.     public function removeUserEntity(UserEntity $userEntity) : self
  399.     {
  400.         if ($this->userEntities->removeElement($userEntity)) {
  401.             // set the owning side to null (unless already changed)
  402.             if ($userEntity->getUser() === $this) {
  403.                 $userEntity->setUser(null);
  404.             }
  405.         }
  406.         return $this;
  407.     }
  408.     public function removeAllUserEntity() : self
  409.     {
  410.         foreach ($this->userEntities as $userEntity) {
  411.             if ($this->userEntities->removeElement($userEntity)) {
  412.                 // set the owning side to null (unless already changed)
  413.                 if ($userEntity->getUser() === $this) {
  414.                     $userEntity->setUser(null);
  415.                 }
  416.             }
  417.         }
  418.         return $this;
  419.     }
  420.     public function getAnswers() : Collection
  421.     {
  422.         return $this->answers;
  423.     }
  424.     public function addAnswer(Answer $answer) : self
  425.     {
  426.         if (!$this->answers->contains($answer)) {
  427.             $this->answers[] = $answer;
  428.             $answer->setAuthor($this);
  429.         }
  430.         return $this;
  431.     }
  432.     public function removeAnswer(Answer $answer) : self
  433.     {
  434.         if ($this->answers->removeElement($answer)) {
  435.             // set the owning side to null (unless already changed)
  436.             if ($answer->getAuthor() === $this) {
  437.                 $answer->setAuthor(null);
  438.             }
  439.         }
  440.         return $this;
  441.     }
  442.     public function getNotifications() : Collection
  443.     {
  444.         return $this->notifications;
  445.     }
  446.     public function addNotification(SavedNotification $notification) : self
  447.     {
  448.         if (!$this->notifications->contains($notification)) {
  449.             $this->notifications[] = $notification;
  450.             $notification->setUser($this);
  451.         }
  452.         return $this;
  453.     }
  454.     public function removeNotification(SavedNotification $notification) : self
  455.     {
  456.         if ($this->notifications->removeElement($notification)) {
  457.             // set the owning side to null (unless already changed)
  458.             if ($notification->getUser() === $this) {
  459.                 $notification->setUser(null);
  460.             }
  461.         }
  462.         return $this;
  463.     }
  464.     public function getDevice() : ?Device
  465.     {
  466.         return $this->device;
  467.     }
  468.     public function setDevice(?Device $device) : self
  469.     {
  470.         $this->device $device;
  471.         return $this;
  472.     }
  473.     public function isUSerAcceptedInEntity($idEntity)
  474.     {
  475.         foreach ($this->getUserEntities() as $userEntity) {
  476.             if ($idEntity == $userEntity->getEntity()->getId()) {
  477.                 return $userEntity->getIsAccepted();
  478.             }
  479.         }
  480.         return false;
  481.     }
  482.     public function getCreatedDate() : ?\DateTimeInterface
  483.     {
  484.         return $this->createdDate;
  485.     }
  486.     public function setCreatedDate(\DateTimeInterface $createdDate) : self
  487.     {
  488.         $this->createdDate $createdDate;
  489.         return $this;
  490.     }
  491.     /**
  492.      * @return Collection|Like[]
  493.      */
  494.     public function getLikes() : Collection
  495.     {
  496.         return $this->likes;
  497.     }
  498.     public function addLike(Like $like) : self
  499.     {
  500.         if (!$this->likes->contains($like)) {
  501.             $this->likes[] = $like;
  502.             $like->setAuthor($this);
  503.         }
  504.         return $this;
  505.     }
  506.     public function removeLike(Like $like) : self
  507.     {
  508.         if ($this->likes->removeElement($like)) {
  509.             // set the owning side to null (unless already changed)
  510.             if ($like->getAuthor() === $this) {
  511.                 $like->setAuthor(null);
  512.             }
  513.         }
  514.         return $this;
  515.     }
  516.     public function getNotifParams() : ?NotifParams
  517.     {
  518.         return $this->notifParams;
  519.     }
  520.     public function setNotifParams(NotifParams $notifParams) : self
  521.     {
  522.         // set the owning side of the relation if necessary
  523.         if ($notifParams->getUser() !== $this) {
  524.             $notifParams->setUser($this);
  525.         }
  526.         $this->notifParams $notifParams;
  527.         return $this;
  528.     }
  529.     public function getResetToken() : ?string
  530.     {
  531.         return $this->resetToken;
  532.     }
  533.     public function setResetToken(?string $resetToken) : self
  534.     {
  535.         $this->resetToken $resetToken;
  536.         return $this;
  537.     }
  538.     /**
  539.      * @return Collection|Comment[]
  540.      */
  541.     public function getComments() : Collection
  542.     {
  543.         return $this->comments;
  544.     }
  545.     public function addComments(Comment $comment) : self
  546.     {
  547.         if (!$this->comments->contains($comment)) {
  548.             $this->comments[] = $comment;
  549.             $comment->setAuthor($this);
  550.         }
  551.         return $this;
  552.     }
  553.     public function removeComments(Comment $comment) : self
  554.     {
  555.         if ($this->comments->removeElement($comment)) {
  556.             // set the owning side to null (unless already changed)
  557.             if ($comment->getAuthor() === $this) {
  558.                 $comment->setAuthor(null);
  559.             }
  560.         }
  561.         return $this;
  562.     }
  563.     public function setEntities(ArrayCollection $arrayCollection) : User
  564.     {
  565.         $this->entities $arrayCollection;
  566.         return $this;
  567.     }
  568.     /**
  569.      * @return Collection|Entity[]
  570.      */
  571.     public function getEntities() : ?Collection
  572.     {
  573.         return $this->entities;
  574.     }
  575.     public function addEntities(Entity $entities) : User
  576.     {
  577.         $this->entities[] = $entities;
  578.         return $this;
  579.     }
  580.     public function getEmailVerif() : ?string
  581.     {
  582.         return $this->emailVerif;
  583.     }
  584.     public function setEmailVerif(?string $emailVerif) : self
  585.     {
  586.         $this->emailVerif $emailVerif;
  587.         return $this;
  588.     }
  589.     public function getNumberGU() : ?int
  590.     {
  591.         return $this->numberGU;
  592.     }
  593.     public function setNumberGU(?int $numberGU) : self
  594.     {
  595.         $this->numberGU $numberGU;
  596.         return $this;
  597.     }
  598.     public function getFormUserAnswers() : ?FormUserAnswers
  599.     {
  600.         return $this->formUserAnswers;
  601.     }
  602.     public function setFormUserAnswers(?FormUserAnswers $formUserAnswers) : self
  603.     {
  604.         $this->formUserAnswers $formUserAnswers;
  605.         return $this;
  606.     }
  607.     /**
  608.      * @return Collection|Log[]
  609.      */
  610.     public function getLogs() : Collection
  611.     {
  612.         return $this->logs;
  613.     }
  614.     public function addLog(Log $log) : self
  615.     {
  616.         if (!$this->logs->contains($log)) {
  617.             $this->logs[] = $log;
  618.             $log->setUser($this);
  619.         }
  620.         return $this;
  621.     }
  622.     public function removeLog(Log $log) : self
  623.     {
  624.         if ($this->logs->removeElement($log)) {
  625.             // set the owning side to null (unless already changed)
  626.             if ($log->getUser() === $this) {
  627.                 $log->setUser(null);
  628.             }
  629.         }
  630.         return $this;
  631.     }
  632.     public function getUserConnexions() : Collection
  633.     {
  634.         return $this->userConnexions;
  635.     }
  636.     public function addUserConnexion(UserConnexion $userConnexion) : self
  637.     {
  638.         if (!$this->userConnexions->contains($userConnexion)) {
  639.             $this->userConnexions[] = $userConnexion;
  640.             $userConnexion->setUser($this);
  641.         }
  642.         return $this;
  643.     }
  644.     public function removeUserConnexion(UserConnexion $userConnexion) : self
  645.     {
  646.         if ($this->userConnexions->removeElement($userConnexion)) {
  647.             // set the owning side to null (unless already changed)
  648.             if ($userConnexion->getUser() === $this) {
  649.                 $userConnexion->setUser(null);
  650.             }
  651.         }
  652.         return $this;
  653.     }
  654.     public function getUserIdentifier() : string
  655.     {
  656.         return (string) $this->email;
  657.     }
  658.     /**
  659.      * @return Collection<int, Territory>
  660.      */
  661.     public function getAdminTerritories(): Collection
  662.     {
  663.         return $this->adminTerritories;
  664.     }
  665.     public function addAdminTerritory(Territory $adminTerritory): self
  666.     {
  667.         if (!$this->adminTerritories->contains($adminTerritory)) {
  668.             $this->adminTerritories->add($adminTerritory);
  669.             $adminTerritory->addAdmin($this);
  670.         }
  671.         return $this;
  672.     }
  673.     public function removeAdminTerritory(Territory $adminTerritory): self
  674.     {
  675.         if ($this->adminTerritories->removeElement($adminTerritory)) {
  676.             $adminTerritory->removeAdmin($this);
  677.         }
  678.         return $this;
  679.     }
  680.     /**
  681.      * @return Collection<int, Territory>
  682.      */
  683.     public function getTerritories(): Collection
  684.     {
  685.         return $this->territories;
  686.     }
  687.     public function addTerritory(Territory $territory): self
  688.     {
  689.         if (!$this->territories->contains($territory)) {
  690.             $this->territories->add($territory);
  691.             $territory->addMember($this);
  692.         }
  693.         return $this;
  694.     }
  695.     public function removeTerritory(Territory $territory): self
  696.     {
  697.         if ($this->territories->removeElement($territory)) {
  698.             $territory->removeMember($this);
  699.         }
  700.         return $this;
  701.     }
  702. }