config = $aircraftConfig;
}
/**
* Fetch seat availability from API
*/
public function fetchSeatAvailability(string $flightNumber): array
{
$url = $this->apiEndpoint . „/flights/“ . urlencode($flightNumber) . „/seats“;
$response = file_get_contents($url);
if (!$response) {
return [];
}
return json_decode($response, true);
}
/**
* Render Seat Map as HTML
*/
public function render(array $availability): string
{
$html = „
foreach ($this->config[‚rows‘] as $rowNumber => $seats) {
$html .= „
foreach ($seats as $seat) {
$seatId = $rowNumber . $seat;
$status = $availability[$seatId] ?? ‚unknown‘;
$cssClass = „seat status-{$status}“;
$html .= „„;
}
$html .= „
„;
}
$html .= „
„;
return $html;
}
/**
* Example seat configuration for Airbus A320
*/
public static function getDefaultA320Config(): array
{
return [
‚rows‘ => [
1 => [‚A‘, ‚B‘, ‚C‘, ‚D‘, ‚E‘, ‚F‘],
2 => [‚A‘, ‚B‘, ‚C‘, ‚D‘, ‚E‘, ‚F‘],
3 => [‚A‘, ‚B‘, ‚C‘, ‚D‘, ‚E‘, ‚F‘],
// … Add more rows as needed
]
];
}
}
// Example usage:
$seatMap = new SeatMap(SeatMap::getDefaultA320Config());
$availability = $seatMap->fetchSeatAvailability(„LH1234“);
echo $seatMap->render($availability);