src/Entity/Neighborhood.php line 51

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\NeighborhoodRepository;
  6. use App\Controller\NeighborhoodPublicApiController;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  12. /**
  13.  * @ApiResource(
  14.  *     security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  15.  *     normalizationContext={"groups"={"neighborhood:read"}, "swagger_definition_name"="Read"},
  16.  *     denormalizationContext={"groups"={"neighborhood:write"}, "swagger_definition_name"="Write"},
  17.  *     itemOperations={
  18.  *          "get"
  19.  *     },
  20.  *     collectionOperations={
  21.  *           "get",
  22.  *           "milkiya_neighborhoods"={
  23.  *              "security"="is_granted('PUBLIC_ACCESS')",
  24.  *              "normalization_context"={"groups"={"milkiya:read"}},
  25.  *              "method"="GET",
  26.  *              "path"="/internal/neighborhoods",
  27.  *              "pagination_enabled" = false
  28.  *           },
  29.  *           "milkiya_neighborhoods_by_city"={
  30.  *              "security"="is_granted('PUBLIC_ACCESS')",
  31.  *              "normalization_context"={"groups"={"milkiya:read"}},
  32.  *              "method"="GET",
  33.  *              "controller"= NeighborhoodPublicApiController::class,
  34.  *              "path"="/internal/neighborhoods/{cityId}",
  35.  *              "pagination_enabled" = false
  36.  *           },
  37.  *     },
  38.  *     attributes={
  39.  *          "pagination_enabled"=false,
  40.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} },
  41.  *          "order"={"name"}
  42.  *     })
  43.  * @ApiFilter(SearchFilter::class, properties={
  44.  *     "name":"ipartial"
  45.  * })
  46.  * @ORM\Entity(repositoryClass=NeighborhoodRepository::class)
  47.  */
  48. class Neighborhood
  49. {
  50.     /**
  51.      * @ORM\Id
  52.      * @ORM\GeneratedValue
  53.      * @ORM\Column(type="integer")
  54.      * @Groups({
  55.      *    "directory:collaborator:search",
  56.      *    "property:read",
  57.      *    "neighborhood:read",
  58.      *    "candidate:read",
  59.      *    "agent:read",
  60.      *    "city:read",
  61.      *    "property-visit:read",
  62.      *    "milkiya:read",
  63.      *     "mandate:read"
  64.      * })
  65.      */
  66.     private $id;
  67.     /**
  68.      * @ORM\ManyToOne(targetEntity=City::class, inversedBy="neighborhoods")
  69.      * @Groups({
  70.      *    "milkiya:read"
  71.      * })
  72.      */
  73.     private ?City $city;
  74.     /**
  75.      * @ORM\Column(type="string", length=150,nullable=true)
  76.      * @Groups({
  77.      *    "directory:collaborator:search",
  78.      *    "property:read",
  79.      *    "neighborhood:read",
  80.      *    "property-address:read",
  81.      *    "candidate:read",
  82.      *    "city:read",
  83.      *    "property-visit:read",
  84.      *    "siege:write",
  85.      *    "milkiya:read",
  86.      *     "mandate:read"
  87.      * })
  88.      */
  89.     private ?string $name;
  90.     /**
  91.      * @ORM\OneToMany(targetEntity=PropertyAddress::class, mappedBy="neighborhood")
  92.      */
  93.     private $propertyAddresses;
  94.     /**
  95.      * @ORM\Column(type="decimal", precision=20, scale=16, nullable=true)
  96.      */
  97.     private $latitude;
  98.     /**
  99.      * @ORM\Column(type="decimal", precision=20, scale=16, nullable=true)
  100.      */
  101.     private $longitude;
  102.     public function __construct()
  103.     {
  104.         $this->propertyAddresses = new ArrayCollection();
  105.     }
  106.     public function getId(): ?int
  107.     {
  108.         return $this->id;
  109.     }
  110.     public function getCity(): ?City
  111.     {
  112.         return $this->city;
  113.     }
  114.     public function setCity(?City $city): self
  115.     {
  116.         $this->city $city;
  117.         return $this;
  118.     }
  119.     public function getName(): ?string
  120.     {
  121.         return $this->name;
  122.     }
  123.     public function setName(string $name): self
  124.     {
  125.         $this->name $name;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @return Collection<int, PropertyAddress>
  130.      */
  131.     public function getPropertyAddresses(): Collection
  132.     {
  133.         return $this->propertyAddresses;
  134.     }
  135.     public function addPropertyAddress(PropertyAddress $propertyAddress): self
  136.     {
  137.         if (!$this->propertyAddresses->contains($propertyAddress)) {
  138.             $this->propertyAddresses[] = $propertyAddress;
  139.             $propertyAddress->setNeighborhood($this);
  140.         }
  141.         return $this;
  142.     }
  143.     public function removePropertyAddress(PropertyAddress $propertyAddress): self
  144.     {
  145.         if (
  146.             $this->propertyAddresses->removeElement($propertyAddress) &&
  147.             $propertyAddress->getNeighborhood() === $this
  148.         ) {
  149.             $propertyAddress->setNeighborhood(null);
  150.         }
  151.         return $this;
  152.     }
  153.     public function getLatitude(): ?string
  154.     {
  155.         return $this->latitude;
  156.     }
  157.     public function setLatitude(?string $latitude): self
  158.     {
  159.         $this->latitude $latitude;
  160.         return $this;
  161.     }
  162.     public function getLongitude(): ?string
  163.     {
  164.         return $this->longitude;
  165.     }
  166.     public function setLongitude(string $longitude): self
  167.     {
  168.         $this->longitude $longitude;
  169.         return $this;
  170.     }
  171. }