127 lines
3.9 KiB
PHP
127 lines
3.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\BusProNet\Model;
|
|
|
|
use App\BusProNet\Constants;
|
|
use Symfony\Component\Serializer\Attribute\Context;
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
|
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
|
|
|
/**
|
|
* Represents a room configuration with capacity, pricing, and availability information.
|
|
*
|
|
* This class handles room data including category, board options, capacity limits,
|
|
* pricing structure, and participant mapping. It provides serialization groups
|
|
* for different API contexts and booking management.
|
|
*/
|
|
class Room
|
|
{
|
|
public const SELECTION_TYPE_BY_PAX = 'by_pax';
|
|
public const SELECTION_TYPE_BY_ROOM = 'by_room';
|
|
|
|
/**
|
|
* Room code suffix by which the office marks a room as deliberately sold on request.
|
|
*/
|
|
public const ON_REQUEST_CODE_SUFFIX = 'Anf';
|
|
|
|
/**
|
|
* Whether a room with this status, availability and code is offered for new bookings.
|
|
*
|
|
* 'Frei' rooms with rooms left. A room on request ('Anfrage') would turn the booking into
|
|
* an inquiry, so it is treated as sold out, unless isOnRequestByCode() says the office
|
|
* sells it that way on purpose. Static and taking the raw values so the product export
|
|
* and the chatbot, which hold rooms as arrays, apply the same rule.
|
|
*/
|
|
public static function isBookableState(?string $status, ?int $available, ?string $code): bool
|
|
{
|
|
if (($available ?? 0) <= 0) {
|
|
return false;
|
|
}
|
|
|
|
return Constants::STATUS_AVAILABLE === $status
|
|
|| (Constants::STATUS_ON_REQUEST === $status && self::isOnRequestByCode($code));
|
|
}
|
|
|
|
/**
|
|
* Whether the room code carries the on-request suffix (case-sensitive, e.g. `6erSDAnf`).
|
|
*/
|
|
public static function isOnRequestByCode(?string $code): bool
|
|
{
|
|
return null !== $code && str_ends_with($code, self::ON_REQUEST_CODE_SUFFIX);
|
|
}
|
|
|
|
#[Groups(['api:list', 'api:single', 'snapshot'])]
|
|
public ?int $id = null;
|
|
|
|
#[Groups(['api:list', 'api:single', 'snapshot'])]
|
|
public ?string $category = null;
|
|
|
|
#[Groups(['api:list', 'api:single', 'snapshot'])]
|
|
public ?int $boardId = null;
|
|
|
|
#[Groups(['api:list', 'api:single', 'snapshot'])]
|
|
public ?string $code = null;
|
|
|
|
#[Groups(['api:list', 'api:single', 'snapshot'])]
|
|
public ?string $label = null;
|
|
|
|
#[Groups(['booking'])]
|
|
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
|
public ?\DateTimeImmutable $dateFrom = null;
|
|
|
|
#[Groups(['booking'])]
|
|
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
|
public ?\DateTimeImmutable $dateTo = null;
|
|
|
|
#[Groups(['booking'])]
|
|
public ?int $totalCount = null;
|
|
|
|
#[Groups(['api:list', 'api:single', 'snapshot'])]
|
|
public ?int $minPax = null;
|
|
|
|
#[Groups(['api:list', 'api:single', 'snapshot'])]
|
|
public ?int $maxPax = null;
|
|
|
|
#[Groups(['api:list', 'api:single', 'snapshot'])]
|
|
public ?int $nights = null;
|
|
|
|
#[Groups(['api:list', 'api:single', 'snapshot'])]
|
|
public ?string $status = null;
|
|
|
|
#[Groups(['api:list', 'api:single', 'snapshot'])]
|
|
public ?int $available = null;
|
|
|
|
#[Groups(['booking'])]
|
|
public ?string $board = null;
|
|
|
|
/** @var list<int> */
|
|
#[Groups(['booking'])]
|
|
public array $mapping = [];
|
|
|
|
#[Groups(['api:list', 'api:single', 'snapshot'])]
|
|
public ?float $price = null;
|
|
|
|
#[Groups(['booking'])]
|
|
public ?float $totalPrice = null;
|
|
|
|
/** @var array<int, float|null> */
|
|
#[Groups(['booking'])]
|
|
public array $individualPrice = [];
|
|
|
|
/**
|
|
* Determines the selection type of the room based on its label.
|
|
*
|
|
* @return string Either self::SELECTION_TYPE_BY_PAX or self::SELECTION_TYPE_BY_ROOM
|
|
*/
|
|
public function getSelectionType(): string
|
|
{
|
|
if (1 === preg_match('/bett/i', $this->label)) {
|
|
return self::SELECTION_TYPE_BY_PAX;
|
|
}
|
|
|
|
return self::SELECTION_TYPE_BY_ROOM;
|
|
}
|
|
}
|