src/Entity/City.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiSubresource;
  5. use App\Repository\CityRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use ApiPlatform\Core\Annotation\ApiResource;
  11. use ApiPlatform\Core\Annotation\ApiProperty;
  12. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  13. /**
  14.  * @ApiResource(
  15.  *     security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  16.  *     normalizationContext={"groups"={"city:read"}, "swagger_definition_name"="Read"},
  17.  *     denormalizationContext={"groups"={"city:write"}, "swagger_definition_name"="Write"},
  18.  *     itemOperations={
  19.  *          "get"
  20.  *     },
  21.  *     collectionOperations={
  22.  *           "get"
  23.  *     },
  24.  *     attributes={
  25.  *          "pagination_enabled"=false,
  26.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} },
  27.  *          "order"={"rank", "name"}
  28.  *     }
  29.  * )
  30.  * @ApiFilter(SearchFilter::class, properties={
  31.  *     "name":"ipartial",
  32.  *     "id":"exact",
  33.  * })
  34.  * @ORM\Entity(repositoryClass=CityRepository::class)
  35.  * @ORM\HasLifecycleCallbacks()
  36.  */
  37. class City
  38. {
  39.     /**
  40.      * @ORM\Id
  41.      * @ORM\GeneratedValue
  42.      * @ORM\Column(type="integer")
  43.      *
  44.      * @Groups({
  45.      *    "directory:collaborator:search",
  46.      *    "directory:people:search",
  47.      *    "city:read",
  48.      *    "contact:read",
  49.      *    "candidate:read",
  50.      *    "property:read",
  51.      *    "mandate:read",
  52.      *    "sector:read",
  53.      *    "prescriber:read",
  54.      *    "agent:read",
  55.      *    "transaction-item:read",
  56.      *    "mandate:read",
  57.      *    "property-visit:read",
  58.      *    "milkiya:read",
  59.      *    "business-indication:item:read",
  60.      *    "read:matching"
  61.      *
  62.      * })
  63.      */
  64.     private $id;
  65.     /**
  66.      * @ORM\Column(type="string", length=255)
  67.      *
  68.      * @Groups({
  69.      *    "directory:collaborator:search",
  70.      *    "directory:people:search",
  71.      *    "candidate:read",
  72.      *    "city:read",
  73.      *    "contact:read",
  74.      *    "property:read",
  75.      *    "mandate:read",
  76.      *    "sector:read",
  77.      *    "prescriber:read",
  78.      *    "recommandation:read",
  79.      *    "agent:read",
  80.      *    "transaction-item:read",
  81.      *    "mandate:read",
  82.      *    "property-visit:read",
  83.      *    "milkiya:read",
  84.      *    "business-indication:item:read",
  85.      *    "read:matching"
  86.      * })
  87.      */
  88.     private ?string $name;
  89.     /**
  90.      * @ORM\OneToMany(targetEntity=Address::class, mappedBy="city", orphanRemoval=true)
  91.      */
  92.     private $addresses;
  93.     /**
  94.      * @ORM\OneToMany(targetEntity=PropertyAddress::class, mappedBy="city")
  95.      */
  96.     private $propertyAddresses;
  97.     /**
  98.      * @ORM\ManyToOne(targetEntity=Country::class, inversedBy="cities")
  99.      * @Groups({
  100.      *    "city:read",
  101.      *    "agent:read"
  102.      * })
  103.      * @ORM\JoinColumn(nullable=false)
  104.      * @ApiProperty(readableLink=true)
  105.      */
  106.     private ?Country $country;
  107.     /**
  108.      * @ORM\Column(type="decimal", precision=20, scale=16, nullable=true)
  109.      */
  110.     private $latitude;
  111.     /**
  112.      * @ORM\Column(type="decimal", precision=20, scale=16, nullable=true)
  113.      */
  114.     private $longitude;
  115.     /**
  116.      * @Groups({
  117.      *    "city:read",
  118.      *    "contact:read",
  119.      *    "candidate:read",
  120.      *    "agent:read",
  121.      *    "abstract-collaborator:read",
  122.      * })
  123.      * @ORM\OneToMany(targetEntity=Neighborhood::class, mappedBy="city")
  124.      * @ApiSubresource()
  125.      */
  126.     private $neighborhoods;
  127.     /**
  128.      * @ORM\Column(type="integer", nullable=true)
  129.      */
  130.     private ?int $rank;
  131.     public function __construct()
  132.     {
  133.         $this->addresses = new ArrayCollection();
  134.         $this->propertyAddresses = new ArrayCollection();
  135.         $this->neighborhoods = new ArrayCollection();
  136.     }
  137.     public function getId(): ?int
  138.     {
  139.         return $this->id;
  140.     }
  141.     /**
  142.      * @param mixed $id
  143.      */
  144.     public function setId($id): self
  145.     {
  146.         $this->id $id;
  147.         return $this;
  148.     }
  149.     public function getName(): ?string
  150.     {
  151.         return $this->name;
  152.     }
  153.     public function setName(string $name): self
  154.     {
  155.         $this->name $name;
  156.         return $this;
  157.     }
  158.     /**
  159.      * @return Collection|Address[]
  160.      */
  161.     public function getAddresses(): Collection
  162.     {
  163.         return $this->addresses;
  164.     }
  165.     public function addAddress(Address $address): self
  166.     {
  167.         if (!$this->addresses->contains($address)) {
  168.             $this->addresses[] = $address;
  169.             $address->setCity($this);
  170.         }
  171.         return $this;
  172.     }
  173.     public function removeAddress(Address $address): self
  174.     {
  175.         // set the owning side to null (unless already changed)
  176.         if ($this->addresses->removeElement($address) && $address->getCity() === $this) {
  177.             $address->setCity(null);
  178.         }
  179.         return $this;
  180.     }
  181.     /**
  182.      * @return Collection|PropertyAddress[]
  183.      */
  184.     public function getPropertyAddresses(): Collection
  185.     {
  186.         return $this->propertyAddresses;
  187.     }
  188.     public function addPropertyAddress(PropertyAddress $propertyAddress): self
  189.     {
  190.         if (!$this->propertyAddresses->contains($propertyAddress)) {
  191.             $this->propertyAddresses[] = $propertyAddress;
  192.             $propertyAddress->setCity($this);
  193.         }
  194.         return $this;
  195.     }
  196.     public function removePropertyAddress(PropertyAddress $propertyAddress): self
  197.     {
  198.         // set the owning side to null (unless already changed)
  199.         if ($this->propertyAddresses->removeElement($propertyAddress) && $propertyAddress->getCity() === $this) {
  200.             $propertyAddress->setCity(null);
  201.         }
  202.         return $this;
  203.     }
  204.     public function getCountry(): ?Country
  205.     {
  206.         return $this->country;
  207.     }
  208.     public function setCountry(?Country $country): self
  209.     {
  210.         $this->country $country;
  211.         return $this;
  212.     }
  213.     public function getLatitude(): ?string
  214.     {
  215.         return $this->latitude;
  216.     }
  217.     public function setLatitude(?string $latitude): self
  218.     {
  219.         $this->latitude $latitude;
  220.         return $this;
  221.     }
  222.     public function getLongitude(): ?string
  223.     {
  224.         return $this->longitude;
  225.     }
  226.     public function setLongitude(string $longitude): self
  227.     {
  228.         $this->longitude $longitude;
  229.         return $this;
  230.     }
  231.     /**
  232.      * @return Collection<int, Neighborhood>
  233.      */
  234.     public function getNeighborhoods(): Collection
  235.     {
  236.         return $this->neighborhoods;
  237.     }
  238.     public function addNeighborhood(Neighborhood $neighborhood): self
  239.     {
  240.         if (!$this->neighborhoods->contains($neighborhood)) {
  241.             $this->neighborhoods[] = $neighborhood;
  242.             $neighborhood->setCity($this);
  243.         }
  244.         return $this;
  245.     }
  246.     public function removeNeighborhood(Neighborhood $neighborhood): self
  247.     {
  248.         // set the owning side to null (unless already changed)
  249.         if ($this->neighborhoods->removeElement($neighborhood) && $neighborhood->getCity() === $this) {
  250.             $neighborhood->setCity(null);
  251.         }
  252.         return $this;
  253.     }
  254.     public function getRank(): ?int
  255.     {
  256.         return $this->rank;
  257.     }
  258.     public function setRank(?int $rank): self
  259.     {
  260.         $this->rank $rank;
  261.         return $this;
  262.     }
  263. }