src/Entity/Sector.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\SectorRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. /**
  10.  * @ApiResource(
  11.  *     security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  12.  *     normalizationContext={"groups"={"sector:read"}, "swagger_definition_name"="Read"},
  13.  *     denormalizationContext={"groups"={"sector:write"}, "swagger_definition_name"="Write","skip_null_values" = true},
  14.  *     itemOperations={
  15.  *          "get"
  16.  *     },
  17.  *     collectionOperations={
  18.  *           "get"
  19.  *     },
  20.  *     attributes={
  21.  *          "pagination_items_per_page"=10,
  22.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  23.  *     }
  24.  * )
  25.  * @ORM\Entity(repositoryClass=SectorRepository::class)
  26.  */
  27. class Sector
  28. {
  29.     /**
  30.      * @ORM\Id
  31.      * @ORM\GeneratedValue
  32.      * @ORM\Column(type="integer")
  33.      *
  34.      * @Groups({
  35.      *   "directory:collaborator:search",
  36.      *   "agent:read",
  37.      *   "sector:read",
  38.      *   "mandate:read",
  39.      *   "milkiya:read"
  40.      * })
  41.      */
  42.     private $id;
  43.     /**
  44.      * @ORM\OneToMany(targetEntity=Agent::class, mappedBy="sector")
  45.      */
  46.     private $collaborators;
  47.     /**
  48.      * @ORM\OneToMany(targetEntity=Candidate::class, mappedBy="sector")
  49.      */
  50.     private $candidates;
  51.     /**
  52.      * @ORM\ManyToMany(targetEntity=City::class, cascade={"persist"})
  53.      * @Groups({
  54.      *   "directory:collaborator:search",
  55.      *   "siege:put","siege:write",
  56.      *   "candidate:read","candidate:write","candidate:put",
  57.      *   "sector:read",
  58.      *   "mandate:read",
  59.      *   "agent:read",
  60.      * })
  61.      */
  62.     private $cities;
  63.     /**
  64.      * @ORM\ManyToMany(targetEntity=Neighborhood::class, cascade={"persist"})
  65.      *  @Groups({
  66.      *   "directory:collaborator:search",
  67.      *   "siege:put","siege:write",
  68.      *   "candidate:read","candidate:write","candidate:put",
  69.      *   "agent:read",
  70.      *   "mandate:read"
  71.      * })
  72.      */
  73.     private $neighborhoods;
  74.     /**
  75.      * @ORM\ManyToOne(targetEntity=City::class)
  76.      * @Groups({
  77.      *   "directory:collaborator:search",
  78.      *   "siege:put","siege:write",
  79.      *   "candidate:read","candidate:write","candidate:put",
  80.      *   "agent:read",
  81.      *   "mandate:read",
  82.      * })
  83.      */
  84.     private ?City $mainCity null;
  85.     public function getId(): ?int
  86.     {
  87.         return $this->id;
  88.     }
  89.     public function __construct()
  90.     {
  91.         $this->collaborators = new ArrayCollection();
  92.         $this->candidates = new ArrayCollection();
  93.         $this->cities = new ArrayCollection();
  94.         $this->neighborhoods = new ArrayCollection();
  95.     }
  96.     /**
  97.      * @return Collection|Agent[]
  98.      */
  99.     public function getCollaborators(): Collection
  100.     {
  101.         return $this->collaborators;
  102.     }
  103.     public function addCollaborator(Agent $collaborator): self
  104.     {
  105.         if (!$this->collaborators->contains($collaborator)) {
  106.             $this->collaborators[] = $collaborator;
  107.             $collaborator->setSector($this);
  108.         }
  109.         return $this;
  110.     }
  111.     public function removeCollaborator(Agent $collaborator): self
  112.     {
  113.         if ($this->collaborators->removeElement($collaborator)) {
  114.             // set the owning side to null (unless already changed)
  115.             if ($collaborator->getSector() === $this) {
  116.                 $collaborator->setSector(null);
  117.             }
  118.         }
  119.         return $this;
  120.     }
  121.     /**
  122.      * @return Collection|Candidate[]
  123.      */
  124.     public function getCandidates(): Collection
  125.     {
  126.         return $this->candidates;
  127.     }
  128.     public function addCandidate(Candidate $candidate): self
  129.     {
  130.         if (!$this->candidates->contains($candidate)) {
  131.             $this->candidates[] = $candidate;
  132.             $candidate->setSector($this);
  133.         }
  134.         return $this;
  135.     }
  136.     public function removeCandidate(Candidate $candidate): self
  137.     {
  138.         // set the owning side to null (unless already changed)
  139.         if ($this->candidates->removeElement($candidate) && $candidate->getSector() === $this) {
  140.             $candidate->setSector(null);
  141.         }
  142.         return $this;
  143.     }
  144.     /**
  145.      * @return Collection<int, City>
  146.      */
  147.     public function getCities(): Collection
  148.     {
  149.         return $this->cities;
  150.     }
  151.     public function addCity(City $city): self
  152.     {
  153.         if (!$this->cities->contains($city)) {
  154.             $this->cities[] = $city;
  155.         }
  156.         return $this;
  157.     }
  158.     public function removeCity(City $city): self
  159.     {
  160.         $this->cities->removeElement($city);
  161.         return $this;
  162.     }
  163.     /**
  164.      * @return Collection<int, Neighborhood>
  165.      */
  166.     public function getNeighborhoods(): Collection
  167.     {
  168.         return $this->neighborhoods;
  169.     }
  170.     public function addNeighborhood(Neighborhood $neighborhood): self
  171.     {
  172.         if (!$this->neighborhoods->contains($neighborhood)) {
  173.             $this->neighborhoods[] = $neighborhood;
  174.         }
  175.         return $this;
  176.     }
  177.     public function removeNeighborhood(Neighborhood $neighborhood): self
  178.     {
  179.         $this->neighborhoods->removeElement($neighborhood);
  180.         return $this;
  181.     }
  182.     public function getMainCity(): ?City
  183.     {
  184.         return $this->mainCity;
  185.     }
  186.     public function setMainCity(?City $mainCity): self
  187.     {
  188.         $this->mainCity $mainCity;
  189.         return $this;
  190.     }
  191. }