<?php
namespace App\Entity\Eg\Osm;
use App\Entity\Eg\Admin\User;
use App\Entity\Eg\Traits\ColorTrait;
use App\Entity\Eg\Traits\ShapeTrait;
use App\Repository\Eg\Osm\CityRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
#[ORM\Table(name: 'eg_osm_cities')]
#[ORM\Entity(repositoryClass: CityRepository::class)]
#[Gedmo\SoftDeleteable]
#[ORM\HasLifecycleCallbacks]
class City
{
use ColorTrait;
use ShapeTrait; // TODO: shape dla miast nie jest uzywany, do wywalenia - spr jeszcze piotrek/mateusz i z bazy sie wywali oni tez dostosuja swoje
// uzywa go tylko strefa i parking
// tak samo kolumna default_parking - czy musi byc dla organizacji skoro też miasta to mają?
use SoftDeleteableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\Column(type: Types::INTEGER)]
private ?int $id = null;
#[ORM\Column(name: 'extent', type: Types::STRING, length: 255, nullable: true)]
private ?string $extent = null;
#[ORM\Column(name: 'name', type: Types::STRING, length: 255)]
private string $name;
#[ORM\Column(name: 'position_lon', type: Types::FLOAT, precision: 10, scale: 0, nullable: true)]
private ?float $positionLon = null;
#[ORM\Column(name: 'position_lat', type: Types::FLOAT, precision: 10, scale: 0, nullable: true)]
private ?float $positionLat = null;
#[ORM\Column(name: 'cpa_hash', type: Types::STRING, length: 5, nullable: true)]
private ?string $cpaHash = null;
#[ORM\ManyToOne(inversedBy: 'cities')]
private ?ParkingType $defaultParkingType = null;
/** @var Collection<int, User> */
#[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'cities')]
#[ORM\JoinTable(name: 'eg_osm_user_city_join')]
private Collection $users;
/** @var Collection<int, Organization> */
#[ORM\ManyToMany(targetEntity: Organization::class, mappedBy: 'cities')]
#[ORM\JoinTable(name: 'eg_osm_organizations_cities_join')]
private Collection $organizations;
/** @var Collection<int, Zone> */
#[ORM\OneToMany(mappedBy: 'city', targetEntity: Zone::class)]
private Collection $zones;
public function __construct()
{
$this->users = new ArrayCollection();
$this->organizations = new ArrayCollection();
$this->zones = new ArrayCollection();
$this->setColor('#90ffa0');
}
public function __toString(): string
{
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getExtent(): ?string
{
return $this->extent;
}
public function setExtent(?string $extent): self
{
$this->extent = $extent;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPositionLon(): ?float
{
return $this->positionLon;
}
public function setPositionLon(?float $positionLon): self
{
$this->positionLon = $positionLon;
return $this;
}
public function getPositionLat(): ?float
{
return $this->positionLat;
}
public function setPositionLat(?float $positionLat): self
{
$this->positionLat = $positionLat;
return $this;
}
public function getCpaHash(): ?string
{
return $this->cpaHash;
}
public function setCpaHash(?string $cpaHash): self
{
$this->cpaHash = $cpaHash;
return $this;
}
public function getDefaultParkingType(): ?ParkingType
{
return $this->defaultParkingType;
}
public function setDefaultParkingType(?ParkingType $defaultParkingType): static
{
$this->defaultParkingType = $defaultParkingType;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
/**
* @return Collection<int, Organization>
*/
public function getOrganizations(): Collection
{
return $this->organizations;
}
public function addOrganization(Organization $organization): self
{
if (!$this->organizations->contains($organization)) {
$this->organizations[] = $organization;
$organization->addCity($this);
}
return $this;
}
public function removeOrganization(Organization $organization): self
{
if ($this->organizations->removeElement($organization)) {
$organization->removeCity($this);
}
return $this;
}
/**
* @return Collection<int, Zone>
*/
public function getZones(): Collection
{
return $this->zones;
}
public function addZone(Zone $zone): static
{
if (!$this->zones->contains($zone)) {
$this->zones->add($zone);
$zone->setCity($this);
}
return $this;
}
public function removeZone(Zone $zone): static
{
if ($this->zones->removeElement($zone)) {
// set the owning side to null (unless already changed)
if ($zone->getCity() === $this) {
$zone->setCity(null);
}
}
return $this;
}
}