1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TK\API\Helper; |
5
|
|
|
|
6
|
|
|
class GetTimetableHelper |
7
|
|
|
{ |
8
|
|
|
public $responseData; |
9
|
|
|
|
10
|
|
|
public function __construct(array $responseData) |
11
|
|
|
{ |
12
|
|
|
$this->responseData = $responseData; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public function getFlightExtraInfo() : array |
16
|
|
|
{ |
17
|
|
|
$extraOTAAirScheduleRS = $this->responseData['extendedOTAAirScheduleRS']['extraOTAAirScheduleRS']; |
18
|
|
|
$flightExtraInfo = $this |
19
|
|
|
->getFlightExtraInfoData($extraOTAAirScheduleRS['extraOTAAirScheduleRSListType']['flightExtraInfo']); |
20
|
|
|
return [ |
21
|
|
|
'totalDuration' => DurationConverter::toMinute($flightExtraInfo['totalDuration']), |
22
|
|
|
'flightDuration' => DurationConverter::toMinute($flightExtraInfo['flightDuration']), |
23
|
|
|
'transferDuration' => DurationConverter::toMinute($flightExtraInfo['transferDuration']), |
24
|
|
|
'durationType' => 'minute' |
25
|
|
|
]; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
private function getFlightExtraInfoData($flightExtraInfo) : array |
29
|
|
|
{ |
30
|
|
|
if (array_key_exists('totalDuration', $flightExtraInfo)) { |
31
|
|
|
return $flightExtraInfo; |
32
|
|
|
} |
33
|
|
|
return $flightExtraInfo[0]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getOriginDestinationOptions() : array |
37
|
|
|
{ |
38
|
|
|
$airScheduleRS = $this->responseData['extendedOTAAirScheduleRS']['OTA_AirScheduleRS']; |
39
|
|
|
if (array_key_exists('FlightSegment', $airScheduleRS['OriginDestinationOptions']['OriginDestinationOption'])) { |
40
|
|
|
return [$airScheduleRS['OriginDestinationOptions']['OriginDestinationOption']]; |
41
|
|
|
} |
42
|
|
|
return $airScheduleRS['OriginDestinationOptions']['OriginDestinationOption']; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getOperationAirline(array $originDestinationOption) : array |
46
|
|
|
{ |
47
|
|
|
return $originDestinationOption['FlightSegment']['OperatingAirline']; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getFlightDetails(array $originDestinationOption) : array |
51
|
|
|
{ |
52
|
|
|
$flightExtraInfo = $this->getFlightExtraInfo(); |
53
|
|
|
return [ |
54
|
|
|
'ScheduleValidStartDate' => $originDestinationOption['FlightSegment']['ScheduleValidStartDate'], |
55
|
|
|
'ScheduleValidEndDate' => $originDestinationOption['FlightSegment']['ScheduleValidEndDate'], |
56
|
|
|
'DepartureAirport' => $originDestinationOption['FlightSegment']['DepartureAirport']['LocationCode'], |
57
|
|
|
'ArrivalAirport' => $originDestinationOption['FlightSegment']['ArrivalAirport']['LocationCode'], |
58
|
|
|
'OperationTime' => $originDestinationOption['FlightSegment']['DaysOfOperation']['OperationSchedule'] |
59
|
|
|
['OperationTimes']['OperationTime']['Text'], |
60
|
|
|
'DepartureDateTime' => $originDestinationOption['FlightSegment']['DepartureDateTime'], |
61
|
|
|
'ArrivalDateTime' => $originDestinationOption['FlightSegment']['ArrivalDateTime'], |
62
|
|
|
'FlightNumber' => $originDestinationOption['FlightSegment']['FlightNumber'], |
63
|
|
|
'AirlineCode' => $originDestinationOption['FlightSegment']['OperatingAirline']['Code'], |
64
|
|
|
'JourneyDuration' => DurationConverter::toMinute( |
65
|
|
|
$originDestinationOption['FlightSegment']['JourneyDuration'], |
66
|
|
|
DurationConverter::FORMAT_SHORT |
67
|
|
|
), |
68
|
|
|
'TotalDuration' => $flightExtraInfo['totalDuration'], |
69
|
|
|
'FlightDuration' => $flightExtraInfo['flightDuration'], |
70
|
|
|
'TransferDuration' => $flightExtraInfo['transferDuration'], |
71
|
|
|
'DurationType' => 'minute' |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|