<?php
namespace App\Entity\Eg\Osm;
use App\Entity\Eg\ParkingMeter;
use App\Entity\GeoParkingShape;
use App\Entity\ParkingDates;
use App\Repository\ParkingRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
#[ORM\Table(name: 'eg_osm_parkings')]
#[ORM\Entity(repositoryClass: ParkingRepository::class)]
#[Gedmo\SoftDeleteable]
#[ORM\Index(name: 'geomshape_idx', columns: ['geomshape'])]
#[ORM\Index(name: 'lastoccupancychange_idx', columns: ['last_occupancy_change'])]
#[ORM\Index(name: 'idx_1b3a46dc9f2c3fab', columns: ['zone_id'])]
#[ORM\Index(name: 'vendorsystem_idx', columns: ['vendor_system'])]
#[ORM\Index(name: 'unpaidplaces_idx', columns: ['unpaid_places'])]
#[ORM\Index(name: 'lastpaymentchange_idx', columns: ['last_payment_change'])]
#[ORM\Index(name: 'idx_1b3a46dc4ba67449', columns: ['parking_type_id'])]
#[ORM\Index(name: 'occupiedplaces_idx', columns: ['occupied_places'])]
#[ORM\Index(name: 'vendorid_idx', columns: ['vendor_id'])]
#[ORM\Index(name: 'IDX_1B3A46DC62939AB5', columns: ['stop_type_id'])]
#[ORM\Index(name: 'IDX_1B3A46DC18B7791E', columns: ['parking_side_id'])]
class Parking
{
use SoftDeleteableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(name: 'aux_vendor_id', type: 'string', length: 255, nullable: true)]
private ?string $auxVendorId = null;
#[ORM\Column(name: 'callback', type: 'string', length: 255, nullable: true)]
private ?string $callback = null;
/**
* @var string|null
*/
#[ORM\Column(name: 'address', type: 'string', length: 255, nullable: true)]
private $address;
/**
* @var bool|null
*/
#[ORM\Column(name: 'owned', type: 'boolean', nullable: true)]
private $owned;
/**
* @var bool|null
*/
#[ORM\Column(name: 'managed', type: 'boolean', nullable: true)]
private $managed;
/**
* @var bool|null
*/
#[ORM\Column(name: 'payment_possible', type: 'boolean', nullable: true)]
private $paymentPossible;
/**
* @var string|null
*/
#[ORM\Column(name: 'osm_ids', type: 'text', nullable: true)]
private $osmIds;
/**
* @var string
*/
#[ORM\Column(name: 'custom_shape', type: 'text')]
private $customShape;
/**
* @var int|null
*/
#[ORM\Column(name: 'total_places', type: 'smallint', nullable: true)]
private $totalPlaces;
/**
* @var int|null
*/
#[ORM\Column(name: 'occupied_places', type: 'smallint', nullable: true)]
private $occupiedPlaces;
/**
* @var \DateTime|null
*/
#[ORM\Column(name: 'last_occupancy_change', type: 'datetimetz', nullable: true)]
private $lastOccupancyChange;
/**
* @var int|null
*/
#[ORM\Column(name: 'unpaid_places', type: 'smallint', nullable: true)]
private $unpaidPlaces;
/**
* @var \DateTime|null
*/
#[ORM\Column(name: 'last_payment_change', type: 'datetimetz', nullable: true)]
private $lastPaymentChange;
/**
* @var string|null
*/
#[ORM\Column(name: 'geomshape', type: 'geography', nullable: true, options: ['srid' => 4326])]
private $geomshape;
/**
* @var string|null
*/
#[ORM\Column(name: 'ushape', type: 'geography', nullable: true, options: ['srid' => 4326])]
private $ushape;
#[ORM\Column(name: 'ushape_ctl', type: 'text', nullable: true)]
private ?string $ushapeCtl = null;
/**
* @var int|null
*/
#[ORM\Column(name: 'gps_snap_radius', type: 'smallint', nullable: true, options: ['default' => 5])]
private $gpsSnapRadius = 5;
#[ORM\Column(name: 'bufferedshape', type: 'text', nullable: true)]
private ?string $bufferedshape = null;
/**
* @var string
*/
#[ORM\Column(name: 'vendor_system', type: 'string', length: 30)]
private $vendorSystem;
/**
* @var string
*/
#[ORM\Column(name: 'vendor_entity', type: 'string', length: 30)]
private $vendorEntity;
/**
* @var string
*/
#[ORM\Column(name: 'vendor_id', type: 'string', length: 255)]
private $vendorId;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'last_refreshed_at', type: 'datetimetz')]
private $lastRefreshedAt;
/**
* @var string
*/
#[ORM\Column(name: 'name', type: 'string', length: 255)]
private $name;
/**
* @var bool
*/
#[ORM\Column(name: 'configured', type: 'boolean')]
private $configured;
#[ORM\Column(name: 'color', type: 'string', length: 7, nullable: true)]
private ?string $color = null;
#[ORM\Column(name: 'enabled', type: 'boolean', nullable: true)]
private ?bool $enabled = null;
#[ORM\Column(name: 'position_lon', type: 'float', precision: 10, scale: 0, nullable: true)]
private ?float $positionLon = null;
#[ORM\Column(name: 'position_lat', type: 'float', precision: 10, scale: 0, nullable: true)]
private ?float $positionLat = null;
#[ORM\Column(name: 'shape', type: 'text', nullable: true)]
private ?string $shape = null;
#[ORM\Column(name: 'bufferedshape2', type: 'text', nullable: true)]
private ?string $bufferedshape2 = null;
#[ORM\Column(name: 'geombufferedshape2', type: 'geography', nullable: true, options: ['srid' => 4326])]
private ?string $geombufferedshape2 = null;
#[ORM\Column(name: 'speed', type: 'integer', nullable: true)]
private ?int $speed = null;
#[ORM\ManyToOne(inversedBy: 'parkings')]
private ?ParkingType $parkingType = null;
#[ORM\ManyToOne(targetEntity: StopType::class)]
private ?StopType $stopType = null;
#[ORM\ManyToOne(targetEntity: ParkingSide::class)]
private ?ParkingSide $parkingSide = null;
#[ORM\ManyToOne(targetEntity: Zone::class, inversedBy: 'parkings')]
private ?Zone $zone = null;
/**
* @var Collection
*/
#[ORM\JoinTable(name: 'eg_osm_parkings_data_agregators_join')]
#[ORM\JoinColumn(name: 'parking_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'data_agregator_id', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: DataAggregator::class, inversedBy: 'parking')]
private $dataAggregators;
/**
* @var Collection
*/
#[ORM\JoinTable(name: 'eg_osm_parking_cameras_join')]
#[ORM\JoinColumn(name: 'parking_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'cameras_id', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: Camera::class, inversedBy: 'parking')]
private $cameras;
/**
* @var Collection
*/
#[ORM\JoinTable(name: 'eg_osm_parking_parkingmeter_join')]
#[ORM\JoinColumn(name: 'parking_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'parking_meter_id', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: ParkingMeter::class, inversedBy: 'parking')]
private $parkingMeter;
#[ORM\OneToMany(targetEntity: GeoParkingShape::class, mappedBy: 'parking')]
private $parkingShapes;
#[ORM\Column(name: 'parking_direction', type: 'float', precision: 10, scale: 0, nullable: true)]
private ?float $parkingDirection = null;
#[ORM\OneToOne(targetEntity: ParkingCarDrawingDetails::class, inversedBy: 'parking', cascade: ['persist', 'remove'])]
private $carDrawingDetails;
#[ORM\OneToMany(targetEntity: ParkingDates::class, mappedBy: 'parkingi')]
private $parkingDates;
public function __construct()
{
$this->dataAggregators = new ArrayCollection();
$this->cameras = new ArrayCollection();
$this->parkingMeter = new ArrayCollection();
$this->parkingShapes = new ArrayCollection();
$this->parkingDates = new ArrayCollection();
}
public function __toString(): string
{
return $this->name ?: 'NIEPOPRAWNIE SKONSTRUOWANY PARKING';
}
public function getId(): ?int
{
return $this->id;
}
public function getAuxVendorId(): ?string
{
return $this->auxVendorId;
}
public function setAuxVendorId(?string $auxVendorId): self
{
$this->auxVendorId = $auxVendorId;
return $this;
}
public function getCallback(): ?string
{
return $this->callback;
}
public function setCallback(?string $callback): self
{
$this->callback = $callback;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getOwned(): ?bool
{
return $this->owned;
}
public function setOwned(?bool $owned): self
{
$this->owned = $owned;
return $this;
}
public function getManaged(): ?bool
{
return $this->managed;
}
public function setManaged(?bool $managed): self
{
$this->managed = $managed;
return $this;
}
public function getPaymentPossible(): ?bool
{
return $this->paymentPossible;
}
public function setPaymentPossible(?bool $paymentPossible): self
{
$this->paymentPossible = $paymentPossible;
return $this;
}
public function getOsmIds(): ?string
{
return $this->osmIds;
}
public function setOsmIds(?string $osmIds): self
{
$this->osmIds = $osmIds;
return $this;
}
public function getCustomShape(): ?string
{
return $this->customShape;
}
public function setCustomShape(string $customShape): self
{
$this->customShape = $customShape;
return $this;
}
public function getTotalPlaces(): ?int
{
return $this->totalPlaces;
}
public function setTotalPlaces(?int $totalPlaces): self
{
$this->totalPlaces = $totalPlaces;
return $this;
}
public function getOccupiedPlaces(): ?int
{
return $this->occupiedPlaces;
}
public function setOccupiedPlaces(?int $occupiedPlaces): self
{
$this->occupiedPlaces = $occupiedPlaces;
return $this;
}
public function getLastOccupancyChange(): ?\DateTimeInterface
{
return $this->lastOccupancyChange;
}
public function setLastOccupancyChange(?\DateTimeInterface $lastOccupancyChange): self
{
$this->lastOccupancyChange = $lastOccupancyChange;
return $this;
}
public function getUnpaidPlaces(): ?int
{
return $this->unpaidPlaces;
}
public function setUnpaidPlaces(?int $unpaidPlaces): self
{
$this->unpaidPlaces = $unpaidPlaces;
return $this;
}
public function getLastPaymentChange(): ?\DateTimeInterface
{
return $this->lastPaymentChange;
}
public function setLastPaymentChange(?\DateTimeInterface $lastPaymentChange): self
{
$this->lastPaymentChange = $lastPaymentChange;
return $this;
}
public function getGeomshape()
{
return $this->geomshape;
}
public function setGeomshape($geomshape): self
{
$this->geomshape = $geomshape;
return $this;
}
public function getUshape()
{
return $this->ushape;
}
public function setUshape($ushape): self
{
$this->ushape = $ushape;
return $this;
}
public function getUshapeCtl(): ?string
{
return $this->ushapeCtl;
}
public function setUshapeCtl(?string $ushapeCtl): self
{
$this->ushapeCtl = $ushapeCtl;
return $this;
}
public function getGpsSnapRadius(): ?int
{
return $this->gpsSnapRadius;
}
public function setGpsSnapRadius(?int $gpsSnapRadius): self
{
$this->gpsSnapRadius = $gpsSnapRadius;
return $this;
}
public function getBufferedshape(): ?string
{
return $this->bufferedshape;
}
public function setBufferedshape(?string $bufferedshape): self
{
$this->bufferedshape = $bufferedshape;
return $this;
}
public function getVendorSystem(): ?string
{
return $this->vendorSystem;
}
public function setVendorSystem(string $vendorSystem): self
{
$this->vendorSystem = $vendorSystem;
return $this;
}
public function getVendorEntity(): ?string
{
return $this->vendorEntity;
}
public function setVendorEntity(string $vendorEntity): self
{
$this->vendorEntity = $vendorEntity;
return $this;
}
public function getVendorId(): ?string
{
return $this->vendorId;
}
public function setVendorId(string $vendorId): self
{
$this->vendorId = $vendorId;
return $this;
}
public function getLastRefreshedAt(): ?\DateTimeInterface
{
return $this->lastRefreshedAt;
}
public function setLastRefreshedAt(\DateTimeInterface $lastRefreshedAt): self
{
$this->lastRefreshedAt = $lastRefreshedAt;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getConfigured(): ?bool
{
return $this->configured;
}
public function setConfigured(bool $configured): self
{
$this->configured = $configured;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function setColor(?string $color): self
{
$this->color = $color;
return $this;
}
public function getEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(?bool $enabled): self
{
$this->enabled = $enabled;
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 getShape(): ?string
{
return $this->shape;
}
public function setShape(?string $shape): self
{
$this->shape = $shape;
return $this;
}
public function getBufferedshape2(): ?string
{
return $this->bufferedshape2;
}
public function setBufferedshape2(?string $bufferedshape2): self
{
$this->bufferedshape2 = $bufferedshape2;
return $this;
}
public function getGeombufferedshape2()
{
return $this->geombufferedshape2;
}
public function setGeombufferedshape2($geombufferedshape2): self
{
$this->geombufferedshape2 = $geombufferedshape2;
return $this;
}
public function getSpeed(): ?int
{
return $this->speed;
}
public function setSpeed(?int $speed): self
{
$this->speed = $speed;
return $this;
}
public function getParkingType(): ?ParkingType
{
return $this->parkingType;
}
public function setParkingType(?ParkingType $parkingType): static
{
$this->parkingType = $parkingType;
return $this;
}
public function getStopType(): ?StopType
{
return $this->stopType;
}
public function setStopType(?StopType $stopType): self
{
$this->stopType = $stopType;
return $this;
}
public function getParkingSide(): ?ParkingSide
{
return $this->parkingSide;
}
public function setParkingSide(?ParkingSide $parkingSide): self
{
$this->parkingSide = $parkingSide;
return $this;
}
public function getZone(): ?Zone
{
return $this->zone;
}
public function setZone(?Zone $zone): self
{
$this->zone = $zone;
return $this;
}
/**
* @return Collection<int, DataAggregator>
*/
public function getDataAggregators(): ?Collection
{
return $this->dataAggregators;
}
public function addDataAggregators(DataAggregator $dataAggregators): self
{
if (!$this->dataAggregators->contains($dataAggregators)) {
$this->dataAggregators[] = $dataAggregators;
}
return $this;
}
public function removeDataAggregators(DataAggregator $dataAggregators): self
{
$this->dataAggregators->removeElement($dataAggregators);
return $this;
}
/**
* @return Collection<int, Camera>
*/
public function getCameras(): Collection
{
return $this->cameras;
}
public function addCamera(Camera $camera): self
{
if (!$this->cameras->contains($camera)) {
$this->cameras[] = $camera;
}
return $this;
}
public function removeCamera(Camera $camera): self
{
$this->cameras->removeElement($camera);
return $this;
}
/**
* @return Collection<int, ParkingMeter>
*/
public function getParkingMeter(): Collection
{
return $this->parkingMeter;
}
public function addParkingMeter(ParkingMeter $parkingMeter): self
{
if (!$this->parkingMeter->contains($parkingMeter)) {
$this->parkingMeter[] = $parkingMeter;
}
return $this;
}
public function removeParkingMeter(ParkingMeter $parkingMeter): self
{
$this->parkingMeter->removeElement($parkingMeter);
return $this;
}
/**
* @return Collection<int, GeoParkingShape>
*/
public function getParkingShapes(): Collection
{
return $this->parkingShapes;
}
public function addParkingShape(GeoParkingShape $parkingShape): self
{
if (!$this->parkingShapes->contains($parkingShape)) {
$this->parkingShapes[] = $parkingShape;
$parkingShape->setParking($this);
}
return $this;
}
public function calculateCenterPoint($locations)
{
$totalLat = 0;
$totalLon = 0;
foreach ($locations as $location) {
$totalLat += $location[0];
$totalLon += $location[1];
}
$totalPoints = count($locations);
$centerLat = $totalLat / $totalPoints;
$centerLon = $totalLon / $totalPoints;
return [$centerLat, $centerLon];
}
public function calculateCenterPointOfParking()
{
$points = [];
$geometry = json_decode($this->getBufferedshape(), true);
if ($geometry['type'] === 'MultiPolygon') {
foreach ($geometry['coordinates'] as $polygon) {
foreach ($polygon as $ring) {
foreach ($ring as $point) {
$points[] = $point;
}
}
}
} elseif ($geometry['type'] === 'Polygon') {
foreach ($geometry['coordinates'] as $ring) {
foreach ($ring as $point) {
$points[] = $point;
}
}
} else {
return null;
}
return $this->calculateCenterPoint($points);
}
public function removeParkingShape(GeoParkingShape $parkingShape): self
{
if ($this->parkingShapes->removeElement($parkingShape)) {
// set the owning side to null (unless already changed)
if ($parkingShape->getParking() === $this) {
$parkingShape->setParking(null);
}
}
return $this;
}
public function getParkingDirection(): ?float
{
return $this->parkingDirection;
}
public function setParkingDirection(?float $parkingDirection): self
{
$this->parkingDirection = $parkingDirection;
return $this;
}
public function getCarDrawingDetails(): ?ParkingCarDrawingDetails
{
return $this->carDrawingDetails;
}
public function setCarDrawingDetails(?ParkingCarDrawingDetails $carDrawingDetails): self
{
$this->carDrawingDetails = $carDrawingDetails;
return $this;
}
/**
* @return Collection<int, ParkingDates>
*/
public function getParkingDates(): Collection
{
return $this->parkingDates;
}
}