src/Entity/RouteLap.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Eg\Osm\Parking;
  4. use App\Entity\Eg\Osm\Zone;
  5. use App\Repository\RouteLapRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\Entity(repositoryClass: RouteLapRepository::class)]
  10. #[ORM\Table(name: 'route_laps')]
  11. #[ORM\Index(name: 'route_laps_start_date', columns: ['start_time'])]
  12. #[ORM\Index(name: 'route_laps_inspector_id', columns: ['inspector_id'])]
  13. #[ORM\Index(name: 'lasttime_idx', columns: ['last_time'])]
  14. #[ORM\Index(columns: ['parking_id'])]
  15. class RouteLap
  16. {
  17.     /**
  18.      * @var int
  19.      */
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue(strategy: 'IDENTITY')]
  22.     #[ORM\Column(type: 'integer')]
  23.     private $id;
  24.     /**
  25.      * @var \DateTimeInterface
  26.      */
  27.     #[ORM\Column(name: 'start_time', type: 'datetimetz_milliseconds')]
  28.     private $startTime;
  29.     /**
  30.      * @var \DateTimeInterface|null
  31.      */
  32.     #[ORM\Column(name: 'last_time', type: 'datetimetz_milliseconds', nullable: true)]
  33.     private $lastTime = null;
  34.     /**
  35.      * @var int
  36.      */
  37.     #[ORM\Column(name: 'inspector_id', type: 'integer', nullable: false)]
  38.     private $inspectorId;
  39.     /**
  40.      * @var int|null
  41.      */
  42.     #[ORM\Column(name: 'total_places', type: 'smallint', nullable: true)]
  43.     private $totalPlaces;
  44.     /**
  45.      * @var int|null
  46.      */
  47.     #[ORM\Column(name: 'occupied_places', type: 'smallint', nullable: true)]
  48.     private $occupiedPlaces;
  49.     /**
  50.      * @var int|null
  51.      */
  52.     #[ORM\Column(name: 'occupancy_state', type: 'smallint', nullable: true)]
  53.     private $occupancyState;
  54.     /**
  55.      * @var \DateTimeInterface|null
  56.      */
  57.     #[ORM\Column(name: 'last_occupancy_change', type: 'datetimetz_milliseconds', nullable: true)]
  58.     private $lastOccupancyChange;
  59.     /**
  60.      * @var int|null
  61.      */
  62.     #[ORM\Column(name: 'unpaid_places', type: 'smallint', nullable: true)]
  63.     private $unpaidPlaces;
  64.     /**
  65.      * @var int|null
  66.      */
  67.     #[ORM\Column(name: 'payment_state', type: 'smallint', nullable: true)]
  68.     private $paymentState;
  69.     /**
  70.      * @var \DateTimeInterface|null
  71.      */
  72.     #[ORM\Column(name: 'last_payment_change', type: 'datetimetz_milliseconds', nullable: true)]
  73.     private $lastPaymentChange;
  74.     /**
  75.      * @var Parking
  76.      */
  77.     #[ORM\ManyToOne(targetEntity: Parking::class)]
  78.     #[ORM\JoinColumn(name: 'parking_id', referencedColumnName: 'id')]
  79.     private $parking;
  80.     /**
  81.      * Typ przejazdu:
  82.      *  0 - przejazd samotny
  83.      *  1 - przejazd pierwszego samochodu z pary
  84.      *  2 - przejazd drugiego samochodu z pary
  85.      */
  86.     #[ORM\Column(type: 'smallint', nullable: true)]
  87.     private $lapType;
  88.     #[ORM\Column(type: 'string', length: 255, nullable: true)]
  89.     private $deviceUID;
  90.     #[ORM\OneToMany(targetEntity: RequestLog::class, mappedBy: 'routeLap')]
  91.     private $requestLogs;
  92.     #[ORM\Column(type: 'boolean', nullable: true)]
  93.     private $drivingType;
  94.     #[ORM\Column(type: 'boolean', options: ['default' => false])]
  95.     private $inParkingDirection = false;
  96.     public function __construct()
  97.     {
  98.         $this->requestLogs = new ArrayCollection();
  99.     }
  100.     /**
  101.      * Metoda do zwracania kluczowych informacji o pojedynczym przejeździe
  102.      */
  103.     public function getLapData(): iterable
  104.     {
  105.         return [
  106.             'parking' => $this->getParking() ? $this->getParking()->getName() : 'Brak parkingu',
  107.             'lapDate' => $this->getStartTime() ? $this->getStartTime()->format('d.m.Y') : 'Brak daty przejazdu',
  108.             'startTime' => $this->getStartTime() ? $this->getStartTime()->format('H:i:s') : 'Brak czasu rozpoczęcia przejazdu',
  109.             'endTime' => $this->getLastTime() ? $this->getLastTime()->format('H:i:s') : 'Brak czasu zakończenia przejazdu',
  110.             'numberOfRequests' => $this->getRequestLogs() ? count($this->getRequestLogs()) : 0,
  111.             'drivingType' => $this->getDrivingTypeTranslated()
  112.         ];
  113.     }
  114.     /**
  115.      * Metoda do wyciągania informacji na temat pojedynczych odczytów wykonanych podczas danego przejazdu
  116.      */
  117.     public function getLapLogsData(): iterable
  118.     {
  119.         $logs = [];
  120.         foreach ($this->getRequestLogs() as $log) {
  121.             // Dane całego loga
  122.             $logs[] = $log->getBasicLogData();
  123.         }
  124.         return $logs;
  125.     }
  126.     public function getId(): ?int
  127.     {
  128.         return $this->id;
  129.     }
  130.     public function getStartTime(): ?\DateTimeInterface
  131.     {
  132.         return $this->startTime;
  133.     }
  134.     public function setStartTime(\DateTimeInterface $startTime): self
  135.     {
  136.         $this->startTime = $startTime;
  137.         return $this;
  138.     }
  139.     public function getLastTime(): ?\DateTimeInterface
  140.     {
  141.         return $this->lastTime;
  142.     }
  143.     public function setLastTime(?\DateTimeInterface $lastTime): self
  144.     {
  145.         $this->lastTime = $lastTime;
  146.         return $this;
  147.     }
  148.     public function getInspectorId(): ?int
  149.     {
  150.         return $this->inspectorId;
  151.     }
  152.     public function setInspectorId(int $inspectorId): self
  153.     {
  154.         $this->inspectorId = $inspectorId;
  155.         return $this;
  156.     }
  157.     public function getTotalPlaces(): ?int
  158.     {
  159.         return $this->totalPlaces;
  160.     }
  161.     public function setTotalPlaces(?int $totalPlaces): self
  162.     {
  163.         $this->totalPlaces = $totalPlaces;
  164.         return $this;
  165.     }
  166.     public function getOccupiedPlaces(): ?int
  167.     {
  168.         return $this->occupiedPlaces;
  169.     }
  170.     public function setOccupiedPlaces(?int $occupiedPlaces): self
  171.     {
  172.         $this->occupiedPlaces = $occupiedPlaces;
  173.         return $this;
  174.     }
  175.     public function getOccupancyState(): ?int
  176.     {
  177.         return $this->occupancyState;
  178.     }
  179.     public function setOccupancyState(?int $occupancyState): self
  180.     {
  181.         $this->occupancyState = $occupancyState;
  182.         return $this;
  183.     }
  184.     public function getLastOccupancyChange(): ?\DateTimeInterface
  185.     {
  186.         return $this->lastOccupancyChange;
  187.     }
  188.     public function setLastOccupancyChange(?\DateTimeInterface $lastOccupancyChange): self
  189.     {
  190.         $this->lastOccupancyChange = $lastOccupancyChange;
  191.         return $this;
  192.     }
  193.     public function getUnpaidPlaces(): ?int
  194.     {
  195.         return $this->unpaidPlaces;
  196.     }
  197.     public function setUnpaidPlaces(?int $unpaidPlaces): self
  198.     {
  199.         $this->unpaidPlaces = $unpaidPlaces;
  200.         return $this;
  201.     }
  202.     public function getPaymentState(): ?int
  203.     {
  204.         return $this->paymentState;
  205.     }
  206.     public function setPaymentState(?int $paymentState): self
  207.     {
  208.         $this->paymentState = $paymentState;
  209.         return $this;
  210.     }
  211.     public function getLastPaymentChange(): ?\DateTimeInterface
  212.     {
  213.         return $this->lastPaymentChange;
  214.     }
  215.     public function setLastPaymentChange(?\DateTimeInterface $lastPaymentChange): self
  216.     {
  217.         $this->lastPaymentChange = $lastPaymentChange;
  218.         return $this;
  219.     }
  220.     public function getParking(): ?Parking
  221.     {
  222.         return $this->parking;
  223.     }
  224.     public function setParking(?Parking $parking): self
  225.     {
  226.         $this->parking = $parking;
  227.         return $this;
  228.     }
  229.     public function getLapType(): ?int
  230.     {
  231.         return $this->lapType;
  232.     }
  233.     public function setLapType(?int $lapType): self
  234.     {
  235.         $this->lapType = $lapType;
  236.         return $this;
  237.     }
  238.     public function getDeviceUID(): ?string
  239.     {
  240.         return $this->deviceUID;
  241.     }
  242.     public function setDeviceUID(?string $deviceUID): self
  243.     {
  244.         $this->deviceUID = $deviceUID;
  245.         return $this;
  246.     }
  247.     public function getRequestLogs(): Collection
  248.     {
  249.         return $this->requestLogs;
  250.     }
  251.     public function addRequestLog(RequestLog $requestLog): self
  252.     {
  253.         if (!$this->requestLogs->contains($requestLog)) {
  254.             $this->requestLogs[] = $requestLog;
  255.             $requestLog->setRouteLap($this);
  256.         }
  257.         return $this;
  258.     }
  259.     public function removeRequestLog(RequestLog $requestLog): self
  260.     {
  261.         if ($this->requestLogs->removeElement($requestLog)) {
  262.             // set the owning side to null (unless already changed)
  263.             if ($requestLog->getRouteLap() === $this) {
  264.                 $requestLog->setRouteLap(null);
  265.             }
  266.         }
  267.         return $this;
  268.     }
  269.     public function getParkingZone(): ?Zone
  270.     {
  271.         return $this->getParking() ? $this->getParking()->getZone() : null;
  272.     }
  273.     public function getParkingStreet(): ?string
  274.     {
  275.         if ($this->getParking() && $streets = $this->getParking()->getDataAggregators()) {
  276.             return $streets[0]->getName();
  277.         }
  278.         return null;
  279.     }
  280.     public function getDrivingType(): ?bool
  281.     {
  282.         return $this->drivingType;
  283.     }
  284.     public function setDrivingType(?bool $drivingType): self
  285.     {
  286.         $this->drivingType = $drivingType;
  287.         return $this;
  288.     }
  289.     public function getDrivingTypeTranslated(): ?string
  290.     {
  291.         if ($this->getDrivingType()) {
  292.             return 'Pojazd lider/samodzielny przejazd';
  293.         }
  294.         return 'Pojazd podążający';
  295.     }
  296.     public function isInParkingDirection(): ?bool
  297.     {
  298.         return $this->inParkingDirection;
  299.     }
  300.     public function setInParkingDirection(bool $inParkingDirection): self
  301.     {
  302.         $this->inParkingDirection = $inParkingDirection;
  303.         return $this;
  304.     }
  305. }