|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* amadeus-ws-client |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright 2015 Amadeus Benelux NV |
|
6
|
|
|
* |
|
7
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
8
|
|
|
* you may not use this file except in compliance with the License. |
|
9
|
|
|
* You may obtain a copy of the License at |
|
10
|
|
|
* |
|
11
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
12
|
|
|
* |
|
13
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
14
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
15
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
16
|
|
|
* See the License for the specific language governing permissions and |
|
17
|
|
|
* limitations under the License. |
|
18
|
|
|
* |
|
19
|
|
|
* @package Amadeus |
|
20
|
|
|
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0 |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace Amadeus\Client\Struct\Pnr\AddMultiElements; |
|
24
|
|
|
|
|
25
|
|
|
use Amadeus\Client\RequestOptions\Pnr\Traveller as TravellerOptions; |
|
26
|
|
|
use Amadeus\Client\RequestOptions\Pnr\TravellerGroup as TravellerGroupOptions; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* TravellerInfo |
|
30
|
|
|
* |
|
31
|
|
|
* @package Amadeus\Client\Struct\Pnr\AddMultiElements |
|
32
|
|
|
* @author Dieter Devlieghere <[email protected]> |
|
33
|
|
|
*/ |
|
34
|
|
|
class TravellerInfo |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* @var ElementManagementPassenger |
|
38
|
|
|
*/ |
|
39
|
|
|
public $elementManagementPassenger; |
|
40
|
|
|
/** |
|
41
|
|
|
* Up to 2 PassengerData elements |
|
42
|
|
|
* |
|
43
|
|
|
* @var PassengerData[] |
|
44
|
|
|
*/ |
|
45
|
|
|
public $passengerData = []; |
|
46
|
|
|
/** |
|
47
|
|
|
* @todo expand this structure |
|
48
|
|
|
* @var array |
|
49
|
|
|
*/ |
|
50
|
|
|
public $enhancedPassengerData = []; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* TravellerInfo constructor. |
|
54
|
|
|
* |
|
55
|
|
|
* @param TravellerOptions|null $traveller |
|
56
|
|
|
* @param TravellerGroupOptions|null $travellerGroup |
|
57
|
|
|
*/ |
|
58
|
195 |
|
public function __construct($traveller = null, $travellerGroup = null) |
|
59
|
|
|
{ |
|
60
|
195 |
|
if ($traveller instanceof TravellerOptions) { |
|
61
|
190 |
|
$this->loadTraveller($traveller); |
|
62
|
87 |
|
} elseif ($travellerGroup instanceof TravellerGroupOptions) { |
|
63
|
10 |
|
$this->loadTravellerGroup($travellerGroup); |
|
64
|
4 |
|
} |
|
65
|
195 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param TravellerGroupOptions $group |
|
69
|
|
|
*/ |
|
70
|
10 |
|
protected function loadTravellerGroup($group) |
|
71
|
|
|
{ |
|
72
|
10 |
|
$this->elementManagementPassenger = new ElementManagementPassenger( |
|
73
|
6 |
|
ElementManagementPassenger::SEG_GROUPNAME |
|
74
|
4 |
|
); |
|
75
|
|
|
|
|
76
|
10 |
|
$this->passengerData[] = new PassengerData($group->name); |
|
77
|
|
|
|
|
78
|
10 |
|
$this->passengerData[0]->travellerInformation->traveller->quantity = $group->nrOfTravellers; |
|
79
|
10 |
|
$this->passengerData[0]->travellerInformation->traveller->qualifier = Traveller::QUAL_GROUP; |
|
80
|
10 |
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param TravellerOptions $traveller |
|
84
|
|
|
*/ |
|
85
|
190 |
|
protected function loadTraveller(TravellerOptions $traveller) |
|
86
|
|
|
{ |
|
87
|
190 |
|
$this->elementManagementPassenger = new ElementManagementPassenger( |
|
88
|
114 |
|
ElementManagementPassenger::SEG_NAME |
|
89
|
76 |
|
); |
|
90
|
|
|
|
|
91
|
190 |
|
$this->passengerData[] = new PassengerData($traveller->lastName); |
|
92
|
|
|
|
|
93
|
190 |
|
if (!is_null($traveller->number)) { |
|
|
|
|
|
|
94
|
185 |
|
$this->elementManagementPassenger->reference = new Reference( |
|
95
|
185 |
|
Reference::QUAL_PASSENGER, |
|
96
|
185 |
|
$traveller->number |
|
97
|
74 |
|
); |
|
98
|
74 |
|
} |
|
99
|
|
|
|
|
100
|
190 |
|
if ($traveller->firstName !== null || $traveller->travellerType !== null) { |
|
101
|
185 |
|
$this->passengerData[0]->travellerInformation->passenger[] = new Passenger( |
|
102
|
185 |
|
$traveller->firstName, |
|
103
|
185 |
|
$traveller->travellerType |
|
104
|
74 |
|
); |
|
105
|
74 |
|
} |
|
106
|
|
|
|
|
107
|
190 |
|
if ($traveller->withInfant === true || $traveller->infant !== null) { |
|
108
|
20 |
|
$this->addInfant($traveller); |
|
109
|
8 |
|
} |
|
110
|
|
|
|
|
111
|
190 |
|
if ($traveller->dateOfBirth instanceof \DateTime) { |
|
|
|
|
|
|
112
|
10 |
|
$this->passengerData[0]->dateOfBirth = new DateOfBirth( |
|
113
|
10 |
|
$this->formatDateOfBirth($traveller->dateOfBirth) |
|
114
|
4 |
|
); |
|
115
|
4 |
|
} |
|
116
|
190 |
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Add infant |
|
120
|
|
|
* |
|
121
|
|
|
* 3 scenario's: |
|
122
|
|
|
* - infant without additional information |
|
123
|
|
|
* - infant with only first name provided |
|
124
|
|
|
* - infant with first name, last name & date of birth provided. |
|
125
|
|
|
* |
|
126
|
|
|
* @param TravellerOptions $traveller |
|
127
|
|
|
*/ |
|
128
|
20 |
|
protected function addInfant($traveller) |
|
129
|
|
|
{ |
|
130
|
20 |
|
$this->passengerData[0]->travellerInformation->traveller->quantity = 2; |
|
131
|
|
|
|
|
132
|
20 |
|
if ($traveller->withInfant && is_null($traveller->infant)) { |
|
133
|
5 |
|
$this->makePassengerIfNeeded(); |
|
134
|
5 |
|
$this->passengerData[0]->travellerInformation->passenger[0]->infantIndicator = Passenger::INF_NOINFO; |
|
135
|
17 |
|
} elseif ($traveller->infant instanceof TravellerOptions) { |
|
|
|
|
|
|
136
|
15 |
|
if (empty($traveller->infant->lastName)) { |
|
137
|
10 |
|
$this->makePassengerIfNeeded(); |
|
138
|
10 |
|
$this->passengerData[0]->travellerInformation->passenger[0]->infantIndicator = Passenger::INF_GIVEN; |
|
139
|
|
|
|
|
140
|
10 |
|
$tmpInfantPassenger = new Passenger( |
|
141
|
10 |
|
$traveller->infant->firstName, |
|
142
|
6 |
|
Passenger::PASST_INFANT |
|
143
|
4 |
|
); |
|
144
|
|
|
|
|
145
|
10 |
|
$this->passengerData[0]->travellerInformation->passenger[] = $tmpInfantPassenger; |
|
146
|
4 |
|
} else { |
|
147
|
5 |
|
$this->makePassengerIfNeeded(); |
|
148
|
5 |
|
$this->passengerData[0]->travellerInformation->passenger[0]->infantIndicator = Passenger::INF_FULL; |
|
149
|
|
|
|
|
150
|
5 |
|
$tmpInfant = new PassengerData($traveller->infant->lastName); |
|
151
|
5 |
|
$tmpInfant->travellerInformation->passenger[] = new Passenger( |
|
152
|
5 |
|
$traveller->infant->firstName, |
|
153
|
3 |
|
Passenger::PASST_INFANT |
|
154
|
2 |
|
); |
|
155
|
|
|
|
|
156
|
5 |
|
if ($traveller->infant->dateOfBirth instanceof \DateTime) { |
|
|
|
|
|
|
157
|
5 |
|
$tmpInfant->dateOfBirth = new DateOfBirth( |
|
158
|
5 |
|
$this->formatDateOfBirth($traveller->infant->dateOfBirth) |
|
159
|
2 |
|
); |
|
160
|
2 |
|
} |
|
161
|
|
|
|
|
162
|
5 |
|
$this->passengerData[] = $tmpInfant; |
|
163
|
|
|
} |
|
164
|
6 |
|
} |
|
165
|
20 |
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* If there is no passenger node at |
|
169
|
|
|
* $travellerInfo->passengerData[0]->travellerInformation->passenger[0] |
|
170
|
|
|
* create one |
|
171
|
|
|
*/ |
|
172
|
20 |
|
protected function makePassengerIfNeeded() |
|
173
|
|
|
{ |
|
174
|
20 |
|
if (count($this->passengerData[0]->travellerInformation->passenger) < 1) { |
|
175
|
5 |
|
$this->passengerData[0]->travellerInformation->passenger[0] = new Passenger(null, null); |
|
176
|
2 |
|
} |
|
177
|
20 |
|
} |
|
178
|
|
|
|
|
179
|
20 |
|
protected function formatDateOfBirth(\DateTime $dateOfBirth) |
|
180
|
|
|
{ |
|
181
|
20 |
|
$day = (int) $dateOfBirth->format('d'); |
|
182
|
20 |
|
if ($day < 10) { |
|
183
|
15 |
|
$day = "0$day"; |
|
184
|
6 |
|
} |
|
185
|
|
|
|
|
186
|
20 |
|
$monthAndYear = strtoupper($dateOfBirth->format('My')); |
|
187
|
|
|
|
|
188
|
20 |
|
return $day . $monthAndYear; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|