<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\NeighborhoodRepository;
use App\Controller\NeighborhoodPublicApiController;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
/**
* @ApiResource(
* security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* normalizationContext={"groups"={"neighborhood:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"neighborhood:write"}, "swagger_definition_name"="Write"},
* itemOperations={
* "get"
* },
* collectionOperations={
* "get",
* "milkiya_neighborhoods"={
* "security"="is_granted('PUBLIC_ACCESS')",
* "normalization_context"={"groups"={"milkiya:read"}},
* "method"="GET",
* "path"="/internal/neighborhoods",
* "pagination_enabled" = false
* },
* "milkiya_neighborhoods_by_city"={
* "security"="is_granted('PUBLIC_ACCESS')",
* "normalization_context"={"groups"={"milkiya:read"}},
* "method"="GET",
* "controller"= NeighborhoodPublicApiController::class,
* "path"="/internal/neighborhoods/{cityId}",
* "pagination_enabled" = false
* },
* },
* attributes={
* "pagination_enabled"=false,
* "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} },
* "order"={"name"}
* })
* @ApiFilter(SearchFilter::class, properties={
* "name":"ipartial"
* })
* @ORM\Entity(repositoryClass=NeighborhoodRepository::class)
*/
class Neighborhood
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({
* "directory:collaborator:search",
* "property:read",
* "neighborhood:read",
* "candidate:read",
* "agent:read",
* "city:read",
* "property-visit:read",
* "milkiya:read",
* "mandate:read"
* })
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=City::class, inversedBy="neighborhoods")
* @Groups({
* "milkiya:read"
* })
*/
private ?City $city;
/**
* @ORM\Column(type="string", length=150,nullable=true)
* @Groups({
* "directory:collaborator:search",
* "property:read",
* "neighborhood:read",
* "property-address:read",
* "candidate:read",
* "city:read",
* "property-visit:read",
* "siege:write",
* "milkiya:read",
* "mandate:read"
* })
*/
private ?string $name;
/**
* @ORM\OneToMany(targetEntity=PropertyAddress::class, mappedBy="neighborhood")
*/
private $propertyAddresses;
/**
* @ORM\Column(type="decimal", precision=20, scale=16, nullable=true)
*/
private $latitude;
/**
* @ORM\Column(type="decimal", precision=20, scale=16, nullable=true)
*/
private $longitude;
public function __construct()
{
$this->propertyAddresses = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCity(): ?City
{
return $this->city;
}
public function setCity(?City $city): self
{
$this->city = $city;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, PropertyAddress>
*/
public function getPropertyAddresses(): Collection
{
return $this->propertyAddresses;
}
public function addPropertyAddress(PropertyAddress $propertyAddress): self
{
if (!$this->propertyAddresses->contains($propertyAddress)) {
$this->propertyAddresses[] = $propertyAddress;
$propertyAddress->setNeighborhood($this);
}
return $this;
}
public function removePropertyAddress(PropertyAddress $propertyAddress): self
{
if (
$this->propertyAddresses->removeElement($propertyAddress) &&
$propertyAddress->getNeighborhood() === $this
) {
$propertyAddress->setNeighborhood(null);
}
return $this;
}
public function getLatitude(): ?string
{
return $this->latitude;
}
public function setLatitude(?string $latitude): self
{
$this->latitude = $latitude;
return $this;
}
public function getLongitude(): ?string
{
return $this->longitude;
}
public function setLongitude(string $longitude): self
{
$this->longitude = $longitude;
return $this;
}
}