src/Entity/Agent.php line 144

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Reference\ReferenceCollaboratorState;
  5. use App\Repository\AgentRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use App\Controller\Agent\Agent\ActivateAgentController;
  10. use App\Controller\Manager\Agent\CreateAgentController;
  11. use App\Controller\Agent\Agent\DisableAgentController;
  12. use App\Controller\Agent\Agent\SuspendAgentController;
  13. use App\Controller\Agent\Agent\ArchiveAgentController;
  14. use App\Controller\Agent\Agent\AcceptTermsController;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Serializer\Annotation\SerializedName;
  18. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  19. use ApiPlatform\Core\Annotation\ApiFilter;
  20. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  21. use App\EventListener\AgentListener;
  22. /**
  23.  * @ApiResource(
  24.  *     security = "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  25.  *     normalizationContext = { "groups" = {"agent:read"}, "swagger_definition_name" = "Read" },
  26.  *     denormalizationContext = { "groups" = {"agent:write"}, "swagger_definition_name" = "Write" },
  27.  *     itemOperations={
  28.  *         "get",
  29.  *         "put" = {
  30.  *                  "denormalization_context" = { "groups" = {"profile:update"} },
  31.  *                  "security" = "is_granted('PROFILE_UPDATE', object)",
  32.  *              },
  33.  *         "activate_agent" = {
  34.  *              "denormalization_context"={"groups"={"agent:activate"}},
  35.  *              "access_control"="is_granted('ROLE_MANAGER')",
  36.  *              "method"="PATCH",
  37.  *              "path"="/agent/{id}/activate",
  38.  *              "controller"=ActivateAgentController::class,
  39.  *              "read"=true,
  40.  *              "write"=false,
  41.  *          },
  42.  *          "disable_agent" = {
  43.  *              "denormalization_context"={"groups"={"agent:disable"}},
  44.  *              "access_control"="is_granted('ROLE_MANAGER')",
  45.  *              "method"="PATCH",
  46.  *              "path"="/agent/{id}/disable",
  47.  *              "controller"=DisableAgentController::class,
  48.  *              "read"=true,
  49.  *              "write"=false,
  50.  *          },
  51.  *          "suspend_agent" = {
  52.  *              "denormalization_context"={"groups"={"agent:suspend"}},
  53.  *              "access_control"="is_granted('ROLE_MANAGER')",
  54.  *              "method"="PATCH",
  55.  *              "path"="/agent/{id}/suspend",
  56.  *              "controller"=SuspendAgentController::class,
  57.  *              "read"=true,
  58.  *              "write"=false,
  59.  *          },
  60.  *          "archive_agent" = {
  61.  *              "denormalization_context"={"groups"={"agent:archive"}},
  62.  *              "access_control"="is_granted('ROLE_MANAGER')",
  63.  *              "method"="PATCH",
  64.  *              "path"="/agent/{id}/archive",
  65.  *              "controller"=ArchiveAgentController::class,
  66.  *              "read"=true,
  67.  *              "write"=false,
  68.  *          }
  69.  *     },
  70.  *     collectionOperations = {
  71.  *          "get",
  72.  *          "post" = {
  73.  *                  "security"="is_granted('ROLE_MANAGER')",
  74.  *                  "controller"=CreateAgentController::class,
  75.  *          },
  76.  *          "accept_terms" = {
  77.  *              "method"="POST",
  78.  *              "access_control"="is_granted('ROLE_AGENT')",
  79.  *              "path"="/agent/accept_terms",
  80.  *              "controller"=AcceptTermsController::class,
  81.  *              "openapi_context"={
  82.  *                  "summary"="Accept terms",
  83.  *                  "description"="Accept terms"
  84.  *              }
  85.  *
  86.  *          },
  87.  *         "milkiya_agents"={
  88.  *              "security"="is_granted('PUBLIC_ACCESS')",
  89.  *              "access_control"="is_granted('PUBLIC_ACCESS')",
  90.  *              "normalization_context"={"groups"={"milkiya:read"}},
  91.  *              "method"="GET",
  92.  *              "path"="/internal/agents",
  93.  *              "pagination_enabled" = false,
  94.  *              "formats"={"json"}
  95.  *          },
  96.  *         "list_agent_light"={
  97.  *              "normalization_context"={"groups"={"agent:light"}},
  98.  *              "method"="GET",
  99.  *              "path"="/agents/light",
  100.  *              "pagination_enabled" = false
  101.  *          },
  102.  *     },
  103.  *     attributes={
  104.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  105.  *     }
  106.  * )
  107.  * @ApiFilter(SearchFilter::class, properties={
  108.  *     "roles",
  109.  *     "status.id": "exact"
  110.  * })
  111.  * @ApiFilter(BooleanFilter::class, properties={"isRecommender"})
  112.  * @ORM\Entity(repositoryClass=AgentRepository::class)
  113.  * @UniqueEntity(
  114.  *          fields={"cin" },
  115.  *          entityClass=Agent::class,
  116.  *          message="AbstractPeople with cin {{ value }} is already used."
  117.  * )
  118.  * @UniqueEntity(
  119.  *           fields={"email"},
  120.  *           entityClass=Agent::class,
  121.  *           message="AbstractPeople with email {{ value }} is already used."
  122.  *     )
  123.  * @UniqueEntity(
  124.  *           fields={"mainPhone"},
  125.  *           entityClass=Agent::class,
  126.  *           message="AbstractPeople with main phone {{ value }} is already used."
  127.  *     )
  128.  * @UniqueEntity(
  129.  *           fields={"email"},
  130.  *           entityClass=Agent::class,
  131.  *           message="AbstractPeople with email {{ value }} is already used."
  132.  * )
  133.  * @UniqueEntity(
  134.  *           fields={"professionalEmail"},
  135.  *           entityClass=Agent::class,
  136.  *           message="AbstractPeople with emailPro {{ value }} is already used."
  137.  * )
  138.  * @ORM\HasLifecycleCallbacks()
  139.  * @ORM\EntityListeners({AgentListener::class})
  140.  */
  141. class Agent extends AbstractCollaborator
  142. {
  143.     /**
  144.      * @ORM\ManyToOne(targetEntity=QualificationLevel::class, inversedBy="collaborators")
  145.      * @ORM\JoinColumn(nullable=true)
  146.      * @Groups({
  147.      *   "candidate:read",
  148.      *   "genealogy:read",
  149.      *   "abstract-collaborator:read",
  150.      *   "directory:collaborator:search",
  151.      *   "agent:read","siege:put","siege:write",
  152.      *   "milkiya:read"
  153.      * })
  154.      *
  155.      */
  156.     private ?QualificationLevel $qualificationLevel;
  157.     /**
  158.      * @ORM\OneToMany(targetEntity=Genealogy::class, mappedBy="collaborator")
  159.      */
  160.     private $genealogies;
  161.     /**
  162.      * @ORM\OneToMany(targetEntity=Property::class, mappedBy="collaborator")
  163.      */
  164.     private $properties;
  165.     /**
  166.      * @ORM\OneToMany(targetEntity=Candidate::class, mappedBy="sponsor")
  167.      */
  168.     private $candidates;
  169.     /**
  170.      * @ORM\OneToMany(targetEntity=Contact::class, mappedBy="collaborator")
  171.      */
  172.     private $contacts;
  173.     /**
  174.      * @ORM\OneToMany(targetEntity=Prescriber::class, mappedBy="collaborator")
  175.      */
  176.     private $prescribers;
  177.     /**
  178.      * @ORM\OneToMany(targetEntity=Property::class, mappedBy="prescriber")
  179.      */
  180.     private $prescriberProperties;
  181.     /**
  182.      * @ORM\OneToOne(targetEntity=Sector::class, cascade={"persist", "remove"})
  183.      *
  184.      * @Groups({
  185.      *
  186.      *   "directory:collaborator:search",
  187.      *   "siege:put",
  188.      *   "mandate:read",
  189.      *   "agent:read",
  190.      *   "siege:write"
  191.      * })
  192.      */
  193.     private ?Sector $sector null;
  194.     /**
  195.      * @ORM\ManyToOne(targetEntity=Manager::class, inversedBy="agents")
  196.      * @Groups({
  197.      *   "mandate:read",
  198.      *   "agent:read",
  199.      *   "siege:write"
  200.      * })
  201.      */
  202.     private ?Manager $manager;
  203.     /**
  204.      * @ORM\ManyToOne(targetEntity=ReferenceCollaboratorState::class, inversedBy="agents")
  205.      * @Groups({
  206.      *   "abstract-collaborator:read",
  207.      *   "agent:read","siege:put","siege:write"
  208.      *
  209.      * })
  210.      */
  211.     private ?ReferenceCollaboratorState $status;
  212.     /**
  213.      * @ORM\Column(type="string", length=255, nullable=true)
  214.      *
  215.      * @Groups({
  216.      *   "abstract-collaborator:read",
  217.      *   "directory:collaborator:search",
  218.      *   "agent:read","siege:put","siege:write"
  219.      * })
  220.      */
  221.     private ?string $cin;
  222.     /**
  223.      * @ORM\Column(type="boolean")
  224.      * @Groups({
  225.      *   "candidate:read",
  226.      *   "genealogy:read",
  227.      *   "abstract-collaborator:read",
  228.      *   "directory:collaborator:search",
  229.      *   "agent:read","siege:write"
  230.      * })
  231.      */
  232.     private bool $isRecommender false;
  233.     /**
  234.      * @ORM\OneToMany(targetEntity=Property::class, mappedBy="recommendation")
  235.      */
  236.     private $recommandations;
  237.     /**
  238.      * @ORM\ManyToOne(targetEntity=Agent::class)
  239.      * @Groups({
  240.      *   "abstract-collaborator:read",
  241.      *   "directory:collaborator:search",
  242.      *   "agent:read","siege:write"
  243.      * })
  244.      */
  245.     private ?Agent $sponsor;
  246.     /**
  247.      * @ORM\Column(type="string", length=100, nullable=true)
  248.      * @Groups({
  249.      *   "abstract-collaborator:read",
  250.      *   "directory:collaborator:search",
  251.      *   "agent:read","siege:put","siege:write"
  252.      * })
  253.      */
  254.     private $cnss;
  255.     /**
  256.      * @ORM\Column(type="string", length=100, nullable=true)
  257.      * @Groups({
  258.      *   "abstract-collaborator:read",
  259.      *   "directory:collaborator:search",
  260.      *   "agent:read","siege:put","siege:write"
  261.      * })
  262.      */
  263.     private $rc;
  264.     /**
  265.      * @ORM\Column(type="string", length=100, nullable=true)
  266.      * @Groups({
  267.      *   "abstract-collaborator:read",
  268.      *   "directory:collaborator:search",
  269.      *   "agent:read","siege:put","siege:write"
  270.      * })
  271.      */
  272.     private $professionalStatus;
  273.     /**
  274.      * @ORM\ManyToOne(targetEntity=Nationality::class)
  275.      * @Groups({
  276.      *   "abstract-collaborator:read",
  277.      *   "directory:collaborator:search",
  278.      *   "agent:read","siege:put","siege:write"
  279.      * })
  280.      */
  281.     private ?Nationality $nationality;
  282.     /**
  283.      * @ORM\Column(type="boolean", nullable=true)
  284.      * @Groups({
  285.      *   "abstract-collaborator:read",
  286.      *   "directory:collaborator:search",
  287.      *   "agent:read","siege:put", "siege:write"
  288.      * })
  289.      */
  290.     private $subjectToVAT;
  291.     /**
  292.      * @ORM\Column(type="date_immutable", nullable=true)
  293.      * @Groups({
  294.      *   "abstract-collaborator:read",
  295.      *   "directory:collaborator:search",
  296.      *   "agent:read","siege:put"
  297.      * })
  298.      */
  299.     private ?\DateTimeImmutable $createdQualifiqautionDate;
  300.     /**
  301.      * @ORM\Column(type="string", length=255, nullable=true)
  302.      *
  303.      * @Groups({
  304.      *   "abstract-collaborator:read",
  305.      *   "directory:collaborator:search",
  306.      *   "agent:read","siege:put","siege:write"
  307.      * })
  308.      */
  309.     private ?string $companyName;
  310.     /**
  311.      * @ORM\Column(type="string", length=255, nullable=true)
  312.      *
  313.      * @Groups({
  314.      *   "abstract-collaborator:read",
  315.      *   "directory:collaborator:search",
  316.      *   "agent:read","siege:put","siege:write"
  317.      * })
  318.      */
  319.     private ?string $commonCompanyIdentifier;
  320.     /**
  321.      * @ORM\OneToMany(targetEntity=IdentityVerificationImage::class, mappedBy="agent")
  322.      *
  323.      * @Groups({
  324.      *   "directory:collaborator:search",
  325.      *   "agent:read"
  326.      * })
  327.      */
  328.     private ?Collection $identityFiles null;
  329.     /**
  330.      * @ORM\OneToMany(targetEntity=AgentsOptions::class, mappedBy="agent")
  331.      *
  332.      * @Groups({
  333.      *   "abstract-collaborator:read",
  334.      *   "directory:collaborator:search",
  335.      *   "agent:read","siege:put","siege:write",
  336.      *   "milkiya:read", "agent:put", "contact:read"
  337.      * })
  338.      */
  339.     private ?Collection $agentOptions null;
  340.     public function __construct()
  341.     {
  342.         parent::__construct();
  343.         $this->genealogies = new ArrayCollection();
  344.         $this->properties = new ArrayCollection();
  345.         $this->candidates = new ArrayCollection();
  346.         $this->contacts = new ArrayCollection();
  347.         $this->prescribers = new ArrayCollection();
  348.         $this->prescriberProperties = new ArrayCollection();
  349.         $this->recommandations = new ArrayCollection();
  350.         $this->identityFiles = new ArrayCollection();
  351.         $this->agentOptions = new ArrayCollection();
  352.     }
  353.     public function getQualificationLevel(): ?QualificationLevel
  354.     {
  355.         return $this->qualificationLevel;
  356.     }
  357.     public function setQualificationLevel(?QualificationLevel $qualificationLevel): self
  358.     {
  359.         $this->qualificationLevel $qualificationLevel;
  360.         return $this;
  361.     }
  362.     /**
  363.      * @return Collection|Genealogy[]
  364.      */
  365.     public function getGenealogies(): Collection
  366.     {
  367.         return $this->genealogies;
  368.     }
  369.     public function addGenealogy(Genealogy $genealogy): self
  370.     {
  371.         if (!$this->genealogies->contains($genealogy)) {
  372.             $this->genealogies[] = $genealogy;
  373.             $genealogy->setCollaborator($this);
  374.         }
  375.         return $this;
  376.     }
  377.     public function removeGenealogy(Genealogy $genealogy): self
  378.     {
  379.         // set the owning side to null (unless already changed)
  380.         if ($this->genealogies->removeElement($genealogy) && $genealogy->getCollaborator() === $this) {
  381.             $genealogy->setCollaborator(null);
  382.         }
  383.         return $this;
  384.     }
  385.     /**
  386.      * @return Collection|Property[]
  387.      */
  388.     public function getProperties(): Collection
  389.     {
  390.         return $this->properties;
  391.     }
  392.     public function addProperty(Property $property): self
  393.     {
  394.         if (!$this->properties->contains($property)) {
  395.             $this->properties[] = $property;
  396.             $property->setCollaborator($this);
  397.         }
  398.         return $this;
  399.     }
  400.     public function removeProperty(Property $property): self
  401.     {
  402.         // set the owning side to null (unless already changed)
  403.         if ($this->properties->removeElement($property) && $property->getCollaborator() === $this) {
  404.             $property->setCollaborator(null);
  405.         }
  406.         return $this;
  407.     }
  408.     /**
  409.      * @return Collection|Candidate[]
  410.      */
  411.     public function getCandidates(): Collection
  412.     {
  413.         return $this->candidates;
  414.     }
  415.     public function addCandidate(Candidate $candidate): self
  416.     {
  417.         if (!$this->candidates->contains($candidate)) {
  418.             $this->candidates[] = $candidate;
  419.             $candidate->setSponsor($this);
  420.         }
  421.         return $this;
  422.     }
  423.     public function removeCandidate(Candidate $candidate): self
  424.     {
  425.         // set the owning side to null (unless already changed)
  426.         if ($this->candidates->removeElement($candidate) && $candidate->getSponsor() === $this) {
  427.             $candidate->setSponsor(null);
  428.         }
  429.         return $this;
  430.     }
  431.     /**
  432.      * @return Collection|Contact[]
  433.      */
  434.     public function getContacts(): Collection
  435.     {
  436.         return $this->contacts;
  437.     }
  438.     public function addContact(Contact $contact): self
  439.     {
  440.         if (!$this->contacts->contains($contact)) {
  441.             $this->contacts[] = $contact;
  442.             $contact->setCollaborator($this);
  443.         }
  444.         return $this;
  445.     }
  446.     public function removeContact(Contact $contact): self
  447.     {
  448.         // set the owning side to null (unless already changed)
  449.         if ($this->contacts->removeElement($contact) && $contact->getCollaborator() === $this) {
  450.             $contact->setCollaborator(null);
  451.         }
  452.         return $this;
  453.     }
  454.     /**
  455.      * @return Collection|Prescriber[]
  456.      */
  457.     public function getPrescribers(): Collection
  458.     {
  459.         return $this->prescribers;
  460.     }
  461.     public function addPrescriber(Prescriber $prescriber): self
  462.     {
  463.         if (!$this->prescribers->contains($prescriber)) {
  464.             $this->prescribers[] = $prescriber;
  465.             $prescriber->setCollaborator($this);
  466.         }
  467.         return $this;
  468.     }
  469.     public function removePrescriber(Prescriber $prescriber): self
  470.     {
  471.         // set the owning side to null (unless already changed)
  472.         if ($this->prescribers->removeElement($prescriber) && $prescriber->getCollaborator() === $this) {
  473.             $prescriber->setCollaborator(null);
  474.         }
  475.         return $this;
  476.     }
  477.     /**
  478.      * @return Collection|Property[]
  479.      */
  480.     public function getPrescriberProperties(): Collection
  481.     {
  482.         return $this->prescriberProperties;
  483.     }
  484.     public function addPrescriberProperty(Property $prescriberProperty): self
  485.     {
  486.         if (!$this->prescriberProperties->contains($prescriberProperty)) {
  487.             $this->prescriberProperties[] = $prescriberProperty;
  488.             $prescriberProperty->setPrescriber($this);
  489.         }
  490.         return $this;
  491.     }
  492.     public function removePrescriberProperty(Property $prescriberProperty): self
  493.     {
  494.         // set the owning side to null (unless already changed)
  495.         if (
  496.             $this->prescriberProperties->removeElement($prescriberProperty) &&
  497.             $prescriberProperty->getPrescriber() === $this
  498.         ) {
  499.             $prescriberProperty->setPrescriber(null);
  500.         }
  501.         return $this;
  502.     }
  503.     public function getSector(): ?Sector
  504.     {
  505.         return $this->sector;
  506.     }
  507.     public function setSector(?Sector $sector): self
  508.     {
  509.         $this->sector $sector;
  510.         return $this;
  511.     }
  512.     public function getManager(): ?Manager
  513.     {
  514.         return $this->manager;
  515.     }
  516.     public function setManager(?Manager $manager): self
  517.     {
  518.         $this->manager $manager;
  519.         return $this;
  520.     }
  521.     public function getStatus(): ?ReferenceCollaboratorState
  522.     {
  523.         return $this->status;
  524.     }
  525.     /**
  526.      * @SerializedName ("referenceCollaboratorState")
  527.      */
  528.     public function setStatus(?ReferenceCollaboratorState $status): self
  529.     {
  530.         $this->status $status;
  531.         return $this;
  532.     }
  533.     public function removeRecommandation(Recommandation $recommandation): self
  534.     {
  535.         // set the owning side to null (unless already changed)
  536.         if ($this->recommandations->removeElement($recommandation) && $recommandation->getAgent() === $this) {
  537.             $recommandation->setAgent(null);
  538.         }
  539.         return $this;
  540.     }
  541.     public function getCin(): ?string
  542.     {
  543.         return $this->cin;
  544.     }
  545.     public function setCin(?string $cin): self
  546.     {
  547.         $this->cin $cin;
  548.         return $this;
  549.     }
  550.     public function getIsRecommender(): ?bool
  551.     {
  552.         return $this->isRecommender;
  553.     }
  554.     public function setIsRecommender(bool $isRecommender): self
  555.     {
  556.         $this->isRecommender $isRecommender;
  557.         return $this;
  558.     }
  559.     /**
  560.      * @return Collection<int, Property>
  561.      */
  562.     public function getRecommandations(): Collection
  563.     {
  564.         return $this->recommandations;
  565.     }
  566.     public function addRecommandation(Property $recommandation): self
  567.     {
  568.         if (!$this->recommandations->contains($recommandation)) {
  569.             $this->recommandations[] = $recommandation;
  570.             $recommandation->setRecommendation($this);
  571.         }
  572.         return $this;
  573.     }
  574.     public function getSponsor(): ?self
  575.     {
  576.         return $this->sponsor;
  577.     }
  578.     public function setSponsor(?self $sponsor): self
  579.     {
  580.         $this->sponsor $sponsor;
  581.         return $this;
  582.     }
  583.     public function getCnss(): ?string
  584.     {
  585.         return $this->cnss;
  586.     }
  587.     public function setCnss(?string $cnss): self
  588.     {
  589.         $this->cnss $cnss;
  590.         return $this;
  591.     }
  592.     public function getRc(): ?string
  593.     {
  594.         return $this->rc;
  595.     }
  596.     public function setRc(?string $rc): self
  597.     {
  598.         $this->rc $rc;
  599.         return $this;
  600.     }
  601.     public function getProfessionalStatus(): ?string
  602.     {
  603.         return $this->professionalStatus;
  604.     }
  605.     public function setProfessionalStatus(?string $professionalStatus): self
  606.     {
  607.         $this->professionalStatus $professionalStatus;
  608.         return $this;
  609.     }
  610.     public function getNationality(): ?Nationality
  611.     {
  612.         return $this->nationality;
  613.     }
  614.     public function setNationality(?Nationality $nationality): self
  615.     {
  616.         $this->nationality $nationality;
  617.         return $this;
  618.     }
  619.     public function getSubjectToVAT(): ?bool
  620.     {
  621.         return $this->subjectToVAT;
  622.     }
  623.     public function setSubjectToVAT(?bool $subjectToVAT): self
  624.     {
  625.         $this->subjectToVAT $subjectToVAT;
  626.         return $this;
  627.     }
  628.     /**
  629.      * @return \DateTimeImmutable|null
  630.      */
  631.     public function getCreatedQualifiqautionDate(): ?\DateTimeImmutable
  632.     {
  633.         return $this->createdQualifiqautionDate;
  634.     }
  635.     /**
  636.      * @param \DateTimeImmutable|null $createdQualifiqautionDate
  637.      */
  638.     public function setCreatedQualifiqautionDate(?\DateTimeImmutable $createdQualifiqautionDate): self
  639.     {
  640.         $this->createdQualifiqautionDate $createdQualifiqautionDate;
  641.         return $this;
  642.     }
  643.     public function getCompanyName(): ?string
  644.     {
  645.         return $this->companyName;
  646.     }
  647.     public function setCompanyName(?string $companyName): self
  648.     {
  649.         $this->companyName $companyName;
  650.         return $this;
  651.     }
  652.     public function getCommonCompanyIdentifier(): ?string
  653.     {
  654.         return $this->commonCompanyIdentifier;
  655.     }
  656.     public function setCommonCompanyIdentifier(?string $commonCompanyIdentifier): self
  657.     {
  658.         $this->commonCompanyIdentifier $commonCompanyIdentifier;
  659.         return $this;
  660.     }
  661.     /**
  662.      * @return Collection<int, IdentityVerificationImage>
  663.      */
  664.     public function getIdentityFiles(): Collection
  665.     {
  666.         return $this->identityFiles;
  667.     }
  668.     public function addIdentityFile(IdentityVerificationImage $identityFile): self
  669.     {
  670.         if (!$this->identityFiles->contains($identityFile)) {
  671.             $this->identityFiles[] = $identityFile;
  672.             $identityFile->setAgent($this);
  673.         }
  674.         return $this;
  675.     }
  676.     public function removeIdentityFile(IdentityVerificationImage $identityFile): self
  677.     {
  678.         if ($this->identityFiles->removeElement($identityFile)) {
  679.             if ($identityFile->getAgent() === $this) {
  680.                 $identityFile->setAgent(null);
  681.             }
  682.         }
  683.         return $this;
  684.     }
  685.     /**
  686.      * @Groups({"milkiya:read"})
  687.      * @SerializedName("sector_city")
  688.      */
  689.     public function getMainCityName(): ?string
  690.     {
  691.         if (null === $sector $this->getSector()) {
  692.             return null;
  693.         }
  694.         return $sector->getMainCity() ? $sector->getMainCity()->getName() : null;
  695.     }
  696.     /**
  697.      * @Groups({"milkiya:read"})
  698.      * @SerializedName("sector")
  699.      */
  700.     public function getSectorInfo(): array
  701.     {
  702.         $citiesNeighborhoods = [];
  703.         if (null === $sector $this->getSector()) {
  704.             return $citiesNeighborhoods;
  705.         }
  706.         $cities $sector->getCities();
  707.         $neighborhoods $sector->getNeighborhoods();
  708.         foreach ($cities as $city) {
  709.             $neighborhoodList = [];
  710.             foreach ($city->getNeighborhoods() as $neighborhood) {
  711.                 if ($neighborhoods->contains($neighborhood)) {
  712.                     $neighborhoodList[] = [
  713.                         'id' => $neighborhood->getId(),
  714.                         'name' => $neighborhood->getName(),
  715.                         'latitude' => $neighborhood->getLatitude(),
  716.                         'longitude' => $neighborhood->getLongitude()
  717.                     ];
  718.                 }
  719.             }
  720.             $cityInfo = [
  721.                 'city' => [
  722.                     'id' => $city->getId(),
  723.                     'name' => $city->getName(),
  724.                     'country' => $city->getCountry()->getName()
  725.                 ],
  726.                 'neighborhoods' => $neighborhoodList,
  727.             ];
  728.              $citiesNeighborhoods[] = $cityInfo;
  729.         }
  730.         return $citiesNeighborhoods;
  731.     }
  732.         /**
  733.      * @return Collection<int, AgentsOptions>
  734.      */
  735.     public function getAgentOptions(): ?Collection
  736.     {
  737.         return $this->agentOptions;
  738.     }
  739.     public function addAgentOptions(AgentsOptions $agentOptions): self
  740.     {
  741.         if (!$this->agentOptions->contains($agentOptions)) {
  742.             $this->agentOptions[] = $agentOptions;
  743.             $agentOptions->setAgent($this);
  744.         }
  745.         return $this;
  746.     }
  747.     public function removeAgentOptions(AgentsOptions $agentOptions): self
  748.     {
  749.         if ($this->agentOptions->removeElement($agentOptions)) {
  750.             // set the owning side to null (unless already changed)
  751.             if ($agentOptions->getAgent() === $this) {
  752.                 $agentOptions->setAgent(null);
  753.             }
  754.         }
  755.         return $this;
  756.     }
  757. }