<?php
namespace Slivki\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\PersistentCollection;
class GeoLocation extends AbstractGeoLocationBase implements \JsonSerializable
{
public const SRID = 4326;
public const DEFAULT_LOCATION = [53.911724, 27.557008];
public const TYPE = 0;
protected $offers;
protected $pickupPointPartnerID;
protected $pickupPointBelTransSatDepotID;
protected $pickupPointSchedule;
protected $giftCertificate;
protected $active;
protected int $offerId;
protected ?string $bepaidCredentials;
private ?PersistentCollection $additionalDiscounts;
protected Collection $beautyMasters;
public function __construct()
{
parent::__construct();
$this->active = true;
$this->bepaidCredentials = null;
$this->beautyMasters = new ArrayCollection();
}
public function getOffers() {
return $this->offers;
}
public function firstOffer(): Offer
{
return $this->offers->first();
}
public function setOffer($offers) {
$this->offer = $offers;
}
public function getPickupPointPartnerID() {
return $this->pickupPointPartnerID;
}
public function setPickupPointPartnerID($pickupPointPartnerID) {
$this->pickupPointPartnerID = $pickupPointPartnerID;
}
public function getPickupPointBelTransSatDepotID() {
return $this->pickupPointBelTransSatDepotID;
}
public function setPickupPointBelTransSatDepotID($pickupPointBelTransSatDepotID) {
$this->pickupPointBelTransSatDepotID = $pickupPointBelTransSatDepotID;
}
public function getPickupPointSchedule() {
return $this->pickupPointSchedule;
}
public function setPickupPointSchedule($pickupPointSchedule) {
$this->pickupPointSchedule = $pickupPointSchedule;
}
public function getPickupPointScheduleParsed() {
if (!$this->pickupPointSchedule || !(json_decode($this->pickupPointSchedule))) {
return null;
}
$schedule = [];
foreach (json_decode($this->pickupPointSchedule) as $item) {
if ($item == '') {
$schedule[] = [];
} else {
$daySchedule = [];
foreach (explode(',', $item) as $schedulePeriod) {
$schedulePeriodExploded = explode('-', $schedulePeriod);
$timeFrom = \DateTime::createFromFormat("H:i", $schedulePeriodExploded[0]);
$timeTo = \DateTime::createFromFormat("H:i", $schedulePeriodExploded[1]);
while ($timeFrom <= $timeTo) {
$daySchedule[] = $timeFrom->format('H:i');
$timeFrom->modify('+30 minutes');
}
}
$schedule[] = $daySchedule;
}
}
return $schedule;
}
public function jsonSerialize(): array
{
$serialized = parent::jsonSerialize();
$serialized['pickupPointPartnerID'] = $this->pickupPointPartnerID;
$serialized['pickupPointSchedule'] = $this->pickupPointSchedule;
$serialized['pickupPointBelTransSatDepotID'] = $this->pickupPointBelTransSatDepotID;
$serialized['bepaidCredentials'] = $this->bepaidCredentials;
return $serialized;
}
public static function fromJSON($data): self
{
$location = parent::fromJSON($data);
if (isset($data->pickupPointPartnerID)) {
$location->setPickupPointPartnerID($data->pickupPointPartnerID);
$location->setPickupPointSchedule($data->pickupPointSchedule);
}
if (isset($data->pickupPointBelTransSatDepotID)) {
$location->setPickupPointBelTransSatDepotID($data->pickupPointBelTransSatDepotID);
}
if (isset($data->bepaidCredentials)) {
$location->setBepaidCredentials($data->bepaidCredentials);
}
return $location;
}
public function getGiftCertificate() {
return $this->giftCertificate;
}
public function setGiftCertificate($giftCertificate) {
$this->giftCertificate = $giftCertificate;
}
public function isActive() {
return $this->active;
}
public function setActive($active) {
$this->active = $active;
}
public function getOfferId(): int
{
return $this->offerId;
}
public function setOfferId(int $offerId): void
{
$this->offerId = $offerId;
}
public function getBepaidCredentials(): ?string
{
return $this->bepaidCredentials;
}
public function setBepaidCredentials(?string $bepaidCredentials): void
{
$this->bepaidCredentials = $bepaidCredentials;
}
public function getBeautyMasters(): Collection
{
return $this->beautyMasters;
}
}