115 lines
3.2 KiB
PHP
115 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\BusProNet\Model;
|
|
|
|
use Symfony\Component\Serializer\Attribute\Context;
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
|
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
|
|
|
class Travel
|
|
{
|
|
#[Groups(['api:list', 'api:single'])]
|
|
public ?int $id = null;
|
|
|
|
#[Groups(['api:list', 'api:single'])]
|
|
public ?string $code = null;
|
|
|
|
#[Groups(['api:list', 'api:single'])]
|
|
public ?string $label = null;
|
|
|
|
#[Groups(['api:list', 'api:single'])]
|
|
public ?int $hotelId = null;
|
|
|
|
#[Groups(['api:single'])]
|
|
public ?Hotel $hotel = null;
|
|
|
|
#[Groups(['api:list', 'api:single'])]
|
|
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
|
public ?\DateTimeImmutable $dateFrom = null;
|
|
|
|
#[Groups(['api:list', 'api:single'])]
|
|
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
|
public ?\DateTimeImmutable $dateTo = null;
|
|
|
|
#[Groups(['api:list', 'api:single'])]
|
|
public ?string $type = null;
|
|
|
|
#[Groups(['api:list', 'api:single'])]
|
|
public ?float $priceFrom = null;
|
|
|
|
#[Groups(['api:single'])]
|
|
public array $selectionGroups = [];
|
|
|
|
#[Groups(['api:single'])]
|
|
public array $additionalServices = [];
|
|
|
|
#[Groups(['api:single'])]
|
|
public bool $additionalServicesMutable = true;
|
|
|
|
#[Groups(['api:single'])]
|
|
public array $transportationServices = [];
|
|
|
|
#[Groups(['api:single'])]
|
|
public bool $transportationServicesMutable = true;
|
|
|
|
#[Groups(['api:single'])]
|
|
public array $pickups = [];
|
|
|
|
#[Groups(['api:single'])]
|
|
public bool $pickupsMutable = true;
|
|
|
|
#[Groups(['api:single'])]
|
|
public array $rooms = [];
|
|
|
|
#[Groups(['api:single'])]
|
|
public bool $roomsMutable = true;
|
|
|
|
#[Groups(['api:single'])]
|
|
public bool $participantDataMutable = true;
|
|
|
|
#[Groups(['api:single'])]
|
|
public bool $participantCountMutable = true;
|
|
|
|
public function getAdditionalServicesByGroup(mixed $group, bool $availableOnly = true): array
|
|
{
|
|
$group = (array) $group;
|
|
|
|
$services = array_filter($this->additionalServices, function (Service $service) use ($group, $availableOnly) {
|
|
return in_array($service->subType, $group) && (false === $availableOnly || $service->available > 0);
|
|
});
|
|
|
|
usort($services, function (Service $a, Service $b) {
|
|
return $a->label <=> $b->label;
|
|
});
|
|
|
|
return $services;
|
|
}
|
|
|
|
public function getTransportationServicesByDirection(string $direction, bool $availableOnly = true): array
|
|
{
|
|
$services = array_filter($this->transportationServices, function (Service $service) use ($direction, $availableOnly) {
|
|
return $direction === $service->direction
|
|
&& $service->price >= 0
|
|
&& (false === $availableOnly || $service->available > 0);
|
|
});
|
|
|
|
usort($services, function (Service $a, Service $b) {
|
|
return $a->subType <=> $b->subType;
|
|
});
|
|
|
|
return $services;
|
|
}
|
|
|
|
public function getIncludedServices(): array
|
|
{
|
|
$services = [];
|
|
|
|
foreach (CrmSelectionGroup::$includedServicesMapping as $id => $label) {
|
|
if (isset($this->selectionGroups[$id])) {
|
|
$services[] = $this->selectionGroups[$id];
|
|
}
|
|
}
|
|
|
|
return $services;
|
|
}
|
|
} |