|
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\PriceXplorer; |
|
24
|
|
|
|
|
25
|
|
|
use Amadeus\Client\RequestOptions\PriceXplorerExtremeSearchOptions; |
|
26
|
|
|
use Amadeus\Client\Struct\BaseWsMessage; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* ExtremeSearch |
|
30
|
|
|
* |
|
31
|
|
|
* @package Amadeus\Client\Struct\PriceXplorer |
|
32
|
|
|
* @author Dieter Devlieghere <[email protected]> |
|
33
|
|
|
*/ |
|
34
|
|
|
class ExtremeSearch extends BaseWsMessage |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* Itinerary information group |
|
38
|
|
|
* |
|
39
|
|
|
* @var ItineraryGrp[] |
|
40
|
|
|
*/ |
|
41
|
|
|
public $itineraryGrp = []; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Budget info |
|
45
|
|
|
* |
|
46
|
|
|
* @var Budget |
|
47
|
|
|
*/ |
|
48
|
|
|
public $budget; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Departure dates ranges |
|
52
|
|
|
* |
|
53
|
|
|
* @var TravelDates |
|
54
|
|
|
*/ |
|
55
|
|
|
public $travelDates; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Stay duration and flexibility |
|
59
|
|
|
* |
|
60
|
|
|
* @var StayDuration |
|
61
|
|
|
*/ |
|
62
|
|
|
public $stayDuration; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Attribute Information |
|
66
|
|
|
* |
|
67
|
|
|
* @var AttributeInfo[] |
|
68
|
|
|
*/ |
|
69
|
|
|
public $attributeInfo = []; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Option description : Price result distribution, ... |
|
73
|
|
|
* |
|
74
|
|
|
* @var SelectionDetailsGroup[] |
|
75
|
|
|
*/ |
|
76
|
|
|
public $selectionDetailsGroup = []; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* List of departure days |
|
80
|
|
|
* |
|
81
|
|
|
* @var DepartureDays[] |
|
82
|
|
|
*/ |
|
83
|
|
|
public $departureDays = []; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Airline information |
|
87
|
|
|
* |
|
88
|
|
|
* @var AirlineInfo[] |
|
89
|
|
|
*/ |
|
90
|
|
|
public $airlineInfo = []; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* List of Office Id Details |
|
94
|
|
|
* |
|
95
|
|
|
* @var OfficeIdInfo[] |
|
96
|
|
|
*/ |
|
97
|
|
|
public $officeIdInfo = []; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Construct PriceXplorer_ExtremeSearch Request message |
|
101
|
|
|
* |
|
102
|
|
|
* @param PriceXplorerExtremeSearchOptions $params |
|
103
|
|
|
*/ |
|
104
|
|
|
public function __construct(PriceXplorerExtremeSearchOptions $params) |
|
105
|
|
|
{ |
|
106
|
|
|
$this->itineraryGrp[] = new ItineraryGrp($params->origin); |
|
107
|
|
|
|
|
108
|
|
|
$this->loadDepartureDateLimits($params); |
|
109
|
|
|
|
|
110
|
|
|
if ($params->searchOffice !== null) { |
|
111
|
|
|
$this->officeIdInfo[] = new OfficeIdInfo($params->searchOffice); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
$this->loadBudget($params->maxBudget, $params->minBudget, $params->currency); |
|
115
|
|
|
|
|
116
|
|
|
$this->loadDestinations($params); |
|
117
|
|
|
|
|
118
|
|
|
if (!empty($params->destinationCountries)) { |
|
119
|
|
|
$this->loadDestinationCountries($params->destinationCountries); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$this->loadDepartureDaysOutIn($params); |
|
123
|
|
|
|
|
124
|
|
|
$this->loadStayDuration($params->stayDurationDays, $params->stayDurationFlexibilityDays); |
|
125
|
|
|
|
|
126
|
|
|
$this->loadCheapestQualifiers($params->returnCheapestNonStop, $params->returnCheapestOverall); |
|
127
|
|
|
|
|
128
|
|
|
$this->loadResultAggregation($params->resultAggregationOption); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param int|null $maxBudget |
|
133
|
|
|
* @param int|null $minBudget |
|
134
|
|
|
* @param string|null $currency |
|
135
|
|
|
*/ |
|
136
|
|
|
protected function loadBudget($maxBudget, $minBudget, $currency) |
|
137
|
|
|
{ |
|
138
|
|
|
if (($maxBudget !== null || $minBudget !== null) && $currency !== null) { |
|
139
|
|
|
$this->budget = new Budget( |
|
140
|
|
|
$maxBudget, |
|
141
|
|
|
$minBudget, |
|
142
|
|
|
$currency |
|
143
|
|
|
); |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param array $destinationCountries |
|
149
|
|
|
*/ |
|
150
|
|
|
protected function loadDestinationCountries($destinationCountries) |
|
151
|
|
|
{ |
|
152
|
|
|
foreach ($destinationCountries as $destinationCountry) { |
|
153
|
|
|
$tmpGrp = new ItineraryGrp(); |
|
154
|
|
|
|
|
155
|
|
|
$tmpGrp->locationInfo = new LocationInfo(LocationInfo::LOC_COUNTRY); |
|
156
|
|
|
|
|
157
|
|
|
$tmpGrp->locationInfo->locationDescription = new LocationIdentificationType(); |
|
158
|
|
|
$tmpGrp->locationInfo->locationDescription->qualifier = LocationIdentificationType::QUAL_DESTINATION; |
|
159
|
|
|
$tmpGrp->locationInfo->locationDescription->code = $destinationCountry; |
|
160
|
|
|
|
|
161
|
|
|
$this->itineraryGrp[] = $tmpGrp; |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @param int|null $stayDuration |
|
167
|
|
|
* @param int|null $flexibility |
|
168
|
|
|
*/ |
|
169
|
|
|
protected function loadStayDuration($stayDuration, $flexibility) |
|
170
|
|
|
{ |
|
171
|
|
|
if ($stayDuration !== null) { |
|
172
|
|
|
$this->stayDuration = new StayDuration($stayDuration); |
|
173
|
|
|
|
|
174
|
|
|
if ($flexibility !== null) { |
|
175
|
|
|
$this->stayDuration->flexibilityInfo = new FlexibilityInfo($flexibility); |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @param bool $cheapestNonStop |
|
182
|
|
|
* @param bool $cheapestOverall |
|
183
|
|
|
*/ |
|
184
|
|
|
protected function loadCheapestQualifiers($cheapestNonStop, $cheapestOverall) |
|
185
|
|
|
{ |
|
186
|
|
|
if ($cheapestNonStop || $cheapestOverall) { |
|
187
|
|
|
|
|
188
|
|
|
$tmpSelDet = new SelectionDetailsGroup(); |
|
189
|
|
|
|
|
190
|
|
|
$tmpSelDet->selectionDetailsInfo = new SelectionDetailsInfo(); |
|
191
|
|
|
$tmpSelDet->selectionDetailsInfo->selectionDetails[] = new SelectionDetails( |
|
192
|
|
|
SelectionDetails::OPT_PRICE_RESULT_DISTRIBUTION |
|
193
|
|
|
); |
|
194
|
|
|
|
|
195
|
|
|
$tmpSelDet->nbOfUnitsInfo = new NbOfUnitsInfo(); |
|
196
|
|
|
|
|
197
|
|
|
if ($cheapestNonStop) { |
|
198
|
|
|
$tmpSelDet->nbOfUnitsInfo->quantityDetails[] = new NumberOfUnitDetailsType( |
|
199
|
|
|
null, |
|
200
|
|
|
NumberOfUnitDetailsType::QUAL_CHEAPEST_NONSTOP |
|
201
|
|
|
); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
if ($cheapestOverall) { |
|
205
|
|
|
$tmpSelDet->nbOfUnitsInfo->quantityDetails[] = new NumberOfUnitDetailsType( |
|
206
|
|
|
null, |
|
207
|
|
|
NumberOfUnitDetailsType::QUAL_CHEAPEST_OVERALL |
|
208
|
|
|
); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
$this->selectionDetailsGroup[] = $tmpSelDet; |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* @param string $resultAggregationOption |
|
217
|
|
|
*/ |
|
218
|
|
|
protected function loadResultAggregation($resultAggregationOption) |
|
219
|
|
|
{ |
|
220
|
|
|
if ($resultAggregationOption !== null) { |
|
221
|
|
|
$groupTypes = $this->makeAggregationGroupTypes($resultAggregationOption); |
|
222
|
|
|
|
|
223
|
|
|
$tmpAttrInfo = new AttributeInfo( |
|
224
|
|
|
AttributeInfo::FUNC_GROUPING, |
|
225
|
|
|
$groupTypes |
|
226
|
|
|
); |
|
227
|
|
|
|
|
228
|
|
|
$this->attributeInfo[] = $tmpAttrInfo; |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* @param string $groupTypeString |
|
234
|
|
|
* @return array |
|
235
|
|
|
*/ |
|
236
|
|
|
protected function makeAggregationGroupTypes($groupTypeString) |
|
237
|
|
|
{ |
|
238
|
|
|
$result = []; |
|
239
|
|
|
|
|
240
|
|
|
switch($groupTypeString) { |
|
241
|
|
|
case PriceXplorerExtremeSearchOptions::AGGR_DEST: |
|
242
|
|
|
$result[] = AttributeDetails::TYPE_DESTINATION; |
|
243
|
|
|
break; |
|
244
|
|
|
case PriceXplorerExtremeSearchOptions::AGGR_COUNTRY: |
|
245
|
|
|
$result[] = AttributeDetails::TYPE_COUNTRY; |
|
246
|
|
|
break; |
|
247
|
|
|
case PriceXplorerExtremeSearchOptions::AGGR_DEST_WEEK: |
|
248
|
|
|
$result[] = AttributeDetails::TYPE_DESTINATION; |
|
249
|
|
|
$result[] = AttributeDetails::TYPE_WEEK; |
|
250
|
|
|
break; |
|
251
|
|
View Code Duplication |
case PriceXplorerExtremeSearchOptions::AGGR_DEST_WEEK_DEPART: |
|
|
|
|
|
|
252
|
|
|
$result[] = AttributeDetails::TYPE_DESTINATION; |
|
253
|
|
|
$result[] = AttributeDetails::TYPE_WEEK; |
|
254
|
|
|
$result[] = AttributeDetails::TYPE_DEPARTURE_DAY; |
|
255
|
|
|
break; |
|
256
|
|
View Code Duplication |
case PriceXplorerExtremeSearchOptions::AGGR_DEST_WEEK_DEPART_STAY: |
|
|
|
|
|
|
257
|
|
|
$result[] = AttributeDetails::TYPE_DESTINATION; |
|
258
|
|
|
$result[] = AttributeDetails::TYPE_WEEK; |
|
259
|
|
|
$result[] = AttributeDetails::TYPE_DEPARTURE_DAY; |
|
260
|
|
|
$result[] = AttributeDetails::TYPE_STAY_DURATION; |
|
261
|
|
|
break; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
return $result; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* @param PriceXplorerExtremeSearchOptions $params |
|
269
|
|
|
* |
|
270
|
|
|
*/ |
|
271
|
|
|
protected function loadDepartureDateLimits(PriceXplorerExtremeSearchOptions $params) |
|
272
|
|
|
{ |
|
273
|
|
|
if ($params->earliestDepartureDate instanceof \DateTime || $params->latestDepartureDate instanceof \DateTime) { |
|
274
|
|
|
$this->travelDates = new TravelDates($params->earliestDepartureDate, $params->latestDepartureDate); |
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* @param PriceXplorerExtremeSearchOptions $params |
|
280
|
|
|
* |
|
281
|
|
|
*/ |
|
282
|
|
|
protected function loadDestinations(PriceXplorerExtremeSearchOptions $params) |
|
283
|
|
|
{ |
|
284
|
|
|
if (!empty($params->destinations)) { |
|
285
|
|
|
foreach ($params->destinations as $destination) { |
|
286
|
|
|
$this->itineraryGrp[] = new ItineraryGrp(null, $destination); |
|
287
|
|
|
} |
|
288
|
|
|
} |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
/** |
|
292
|
|
|
* @param PriceXplorerExtremeSearchOptions $params |
|
293
|
|
|
* |
|
294
|
|
|
*/ |
|
295
|
|
|
protected function loadDepartureDaysOutIn(PriceXplorerExtremeSearchOptions $params) |
|
296
|
|
|
{ |
|
297
|
|
|
if (!empty($params->departureDaysInbound)) { |
|
298
|
|
|
$this->departureDays[] = new DepartureDays($params->departureDaysInbound, SelectionDetails::OPT_INBOUND_DEP_DAYS); |
|
|
|
|
|
|
299
|
|
|
} |
|
300
|
|
|
if (!empty($params->departureDaysOutbound)) { |
|
301
|
|
|
$this->departureDays[] = new DepartureDays( |
|
302
|
|
|
$params->departureDaysOutbound, |
|
303
|
|
|
SelectionDetails::OPT_OUTBOUND_DEP_DAYS |
|
304
|
|
|
); |
|
305
|
|
|
} |
|
306
|
|
|
} |
|
307
|
|
|
} |
|
308
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.