94 lines
2.5 KiB
PHP
94 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\BusProNet\Model;
|
|
|
|
use Symfony\Component\Serializer\Attribute\Context;
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
|
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
|
|
|
/**
|
|
* Represents a pickup location with timing and pricing information.
|
|
*
|
|
* This class handles pickup point data including location details, scheduled times,
|
|
* pricing, and participant mapping. It provides serialization groups for API
|
|
* responses and booking management.
|
|
*/
|
|
class Pickup
|
|
{
|
|
#[Groups(['api:list'])]
|
|
public ?int $id = null;
|
|
|
|
#[Groups(['api:list'])]
|
|
public ?string $code = null;
|
|
|
|
#[Groups(['api:list'])]
|
|
public ?string $city = null;
|
|
|
|
#[Groups(['api:list'])]
|
|
public ?string $postalCode = null;
|
|
|
|
#[Groups(['api:list'])]
|
|
public ?string $street = null;
|
|
|
|
#[Groups(['api:single'])]
|
|
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i'])]
|
|
public ?\DateTimeImmutable $time = null;
|
|
|
|
#[Groups(['api:single'])]
|
|
public ?float $price = null;
|
|
|
|
#[Groups(['api:booking'])]
|
|
public array $mapping = [];
|
|
|
|
/**
|
|
* Gets the formatted label for the pickup location without pricing.
|
|
*
|
|
* Creates user-friendly labels following the pattern:
|
|
* - Primary format: "City (Street)" if street is available
|
|
* - Fallback format: "City" if no street information
|
|
*
|
|
* @return string The formatted pickup location label
|
|
*/
|
|
public function getLabel(): string
|
|
{
|
|
$label = $this->city ?? '';
|
|
|
|
if (null !== $this->street && '' !== trim($this->street)) {
|
|
$label .= ' ('.$this->street.')';
|
|
}
|
|
|
|
return $label;
|
|
}
|
|
|
|
/**
|
|
* Gets the formatted label with pricing information.
|
|
*
|
|
* Formats the pickup label with price display:
|
|
* - Zero/null price: Just the label without price suffix
|
|
* - Positive price: "Label (€X,XX)" as surcharge
|
|
* - Negative price: "Label (-X,XX€ Rabatt)" as discount
|
|
*
|
|
* @return string The formatted pickup label with pricing
|
|
*/
|
|
public function getLabelWithPrice(): string
|
|
{
|
|
$label = $this->getLabel();
|
|
|
|
if (null === $this->price) {
|
|
return $label;
|
|
}
|
|
|
|
if (0.0 === $this->price) {
|
|
return sprintf('%s (inkl.)', $label);
|
|
}
|
|
|
|
if ($this->price < 0) {
|
|
return sprintf('%s (-%s€ Rabatt)', $label, number_format(abs($this->price), 2, ',', '.'));
|
|
}
|
|
|
|
return sprintf('%s (€%s)', $label, number_format($this->price, 2, ',', '.'));
|
|
}
|
|
}
|