-
Notifications
You must be signed in to change notification settings - Fork 0
/
CollectTouristObjects.php
327 lines (281 loc) · 11.6 KB
/
CollectTouristObjects.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php
require 'CIG_Importer.php';
class CollectTouristObjects {
private function get_category_mappings() {
return array(
'gospodarka i nauka ekologia' => 'C030',
'gospodarka i nauka ekonomia' => 'C030',
'gospodarka i nauka konferencja' => 'C030',
'gospodarka i nauka targi' => 'C030',
'gospodarka i nauka technika' => 'C030',
'inne inne' => 'C030',
'inne kulinarna' => 'C027',
'inne zdrowie' => 'C027',
'kultura dla dzieci' => 'C025',
'kultura edukacja' => 'C025',
'kultura film' => 'C025',
'kultura fotografia' => 'C025',
'kultura historia' => 'C025',
'kultura inne' => 'C025',
'kultura jubileusz' => 'C025',
'kultura kabaret' => 'C025',
'kultura koncert' => 'C028',
'kultura on-line' => 'C025', // imprezy kulturalne
'koncert on-line' => 'C028', // koncerty
'rozrywka on-line' => 'C030', // inne wydarzenia
'inne on-line' => 'C030', // inne wydarzenia
'teatr on-line' => 'C025', // imprezy kulturalne
'gospodarka i nauka on-line' => 'C030', // inne wydarzenia
'sport on-line' => 'C026', // imprezy sportowe
'wystawa on-line' => 'C029', // wystawy
'film on-line' => 'C025', // imprezy kulturalne
'dla dzieci on-line' => 'C025', // imprezy kulturalne
'warsztaty on-line' => 'C025', // imprezy kulturalne
'kultura konkurs' => 'C025',
'kultura literatura' => 'C025',
'kultura ludowa' => 'C024',
'kultura malarstwo' => 'C025',
'kultura muzyka' => 'C025',
'kultura opera' => 'C025',
'kultura religia' => 'C025',
'kultura rozrywka' => 'C025',
'kultura spotkanie' => 'C025',
'kultura taniec' => 'C025',
'kultura teatr' => 'C025',
'kultura warsztaty' => 'C025',
'kultura wernisaż' => 'C029',
'kultura widowisko' => 'C025',
'kultura wykład' => 'C025',
'kultura wystawa' => 'C029',
'motoryzacja inne' => 'C026',
'motoryzacja rajd' => 'C026',
'motoryzacja wyścigi' => 'C026',
'sport badminton' => 'C026',
'sport biegi' => 'C026',
'sport dla dzieci' => 'C026',
'sport gry planszowe' => 'C026',
'sport hokej' => 'C026',
'sport inne' => 'C026',
'sport kajaki' => 'C026',
'sport karciane' => 'C026',
'sport kolarstwo' => 'C026',
'sport koszykówka' => 'C026',
'sport lekkoatletyka' => 'C026',
'sport łyżwiarstwo' => 'C026',
'sport narty' => 'C026',
'sport niepełnosprawni' => 'C026',
'sport piłka nożna' => 'C026',
'sport piłka ręczna' => 'C026',
'sport piłka siatkowa' => 'C026',
'sport pływanie' => 'C026',
'sport samolotowy' => 'C026',
'sport snowboard' => 'C026',
'sport strzelectwo sportowe' => 'C026',
'sport szachy' => 'C026',
'sport sztuki walki' => 'C026',
'sport tenis' => 'C026',
'sport tenis stołowy' => 'C026',
'sport turystyka i rekreacja' => 'C026',
'sport żeglarstwo' => 'C026',
);
}
private function decode_restrictions($search_condidtions) {
$allForDistributionChannel = false;
$searchAttributeAnd = array();
$searchCategoryAnd = array();
$objectIdentifier = array();
$date_from = null;
$date_to = null;
$sc = $search_condidtions;
if (property_exists($sc, 'allForDistributionChannel')) {
$allForDistributionChannel = $sc->allForDistributionChannel;
}
if ($allForDistributionChannel === false) {
if (property_exists($sc, 'searchAttributeAnd')) {
if (property_exists($sc->searchAttributeAnd, 'attributeValue')) {
if (false === is_array($sc->searchAttributeAnd->attributeValue)) {
$sc->searchAttributeAnd->attributeValue = array($sc->searchAttributeAnd->attributeValue);
}
foreach ($sc->searchAttributeAnd->attributeValue as $attribute) {
$searchAttributeAnd[$attribute->attributeCode] = $attribute->valueToSearch;
}
}
}
if (property_exists($sc, 'searchCategoryAnd')) {
if (property_exists($sc->searchCategoryAnd, 'categoryCode')) {
if (false === is_array($sc->searchCategoryAnd->categoryCode)) {
$sc->searchCategoryAnd->categoryCode = array($sc->searchCategoryAnd->categoryCode);
}
$searchCategoryAnd = $sc->searchCategoryAnd->categoryCode;
}
}
if (property_exists($sc, 'objectIdentifier')) {
if (property_exists($sc->objectIdentifier, 'identifierRIT')) {
if (false === is_array($sc->objectIdentifier->identifierRIT)) {
$objectIdentifier = array($sc->objectIdentifier->identifierRIT);
} else {
$objectIdentifier = $sc->objectIdentifier->identifierRIT;
}
} else if (property_exists($sc->objectIdentifier, 'identifierSZ')) {
if (false === is_array($sc->objectIdentifier->identifierSZ)) {
$ids = array($sc->objectIdentifier->identifierSZ);
} else {
$ids = $sc->objectIdentifier->identifierSZ;
}
foreach ($ids as $id) {
if (false === property_exists($id, 'artificialIdentifier')) {
$id->artificialIdentifier = null;
}
if (false === property_exists($id, 'databaseTable')) {
$id->databaseTable = null;
}
if (false === property_exists($id, 'concatenationOfField')) {
$id->concatenationOfField = null;
}
$objectIdentifier[] = array(
'type' => $id->identifierType,
'id' => $id->artificialIdentifier,
'table' => $id->databaseTable,
'concat'=> $id->concatenationOfField,
);
}
}
}
if (property_exists($sc, 'lastModifiedRange')) {
if (property_exists($sc->lastModifiedRange, 'dateFrom')) {
$date_from = $sc->lastModifiedRange->dateFrom;
}
if (property_exists($sc->lastModifiedRange, 'dateTo')) {
$date_to = $sc->lastModifiedRange->dateTo;
}
}
}
$restrictions = array(
'ids' => $objectIdentifier,
'attributes' => $searchAttributeAnd,
'categories' => $searchCategoryAnd,
'date_from' => $date_from,
'date_to' => $date_to,
);
return $restrictions;
}
public function searchTouristObjects($request) {
$sc = $request->searchCondition;
$restrictions = $this->decode_restrictions($sc);
$language = $sc->language;
$importer = new CIG_Importer();
$xml = $importer->get_xml();
$happenings = new SimpleXMLElement($xml);
$response = new \stdClass;
$response->status = 'OK';
$response->info = '';
$response->touristObject = array();
$count = 0;
$category_mappings = $this->get_category_mappings();
foreach ($happenings as $happening) {
if ($happening['deleted'] == '1') {
continue;
}
if (empty($restrictions['ids']) === false && in_array($happening['happeningId'], $restrictions['ids']) === false) {
continue;
}
if ($restrictions['date_from'] !== null && strtotime($happening['modified']) < strtotime($restrictions['date_from'])) {
continue;
}
if ($restrictions['date_to'] !== null && strtotime($happening['modified']) > strtotime($restrictions['date_to'])) {
continue;
}
$touristObject = new \stdClass;
$touristObject->touristObjectIdentifierRIT = new \stdClass;
$touristObject->touristObjectIdentifierRIT->identifierRIT = $happening['happeningId'];
$touristObject->touristObjectIdentifierRIT->lastModified = date("Y-d-m", strtotime($happening['modified']));
$touristObject->categories = array();
$codes = array();
foreach ($category_mappings as $coigdzie_category => $rit_category) {
if ($happening->category == $coigdzie_category) {
$codes[] = $rit_category;
}
}
if (count($codes) === 0) {
die('Unknown category ' . $happening->category);
}
foreach ($codes as $code) {
$category = new \stdClass;
$category->code = $code;
$touristObject->categories[] = $category;
}
if (empty($restrictions['categories']) === false && empty(array_intersect(array_merge($codes, ['C005']), $restrictions['categories'])) === true) {
continue;
}
$touristObject->attributes = array();
$attributes = array();
$attributes['A001'] = $happening->name;
$attributes['A004'] = '<p>' . nl2br($happening->description) . '</p>';
$attributes['A009'] = strtoupper($happening->venue->venueVoivodeship);
$attributes['A010'] = $happening->venue->venueDistrict;
$attributes['A011'] = $happening->venue->venueCommune;
$attributes['A012'] = $happening->venue->venueLocality;
$attributes['A014'] = $happening->venue->venueStreet;
$attributes['A015'] = $happening->venue->venueHouseNo;
$attributes['A017'] = $happening->venue->venuePostCode;
$attributes['A018'] = $happening->venue->venueGeom->lat . ',' . $happening->venue->venueGeom->lon;
$attributes['A065'] = $happening->happeningUrl;
if ($happening->price != '-1') {
$attributes['A069'] = $happening->price;
}
$attributes['A105'] = $happening->startDate;
$attributes['A106'] = $happening->endDate;
if ($happening->venue->venueAttributes->carParkAvailable == '1') {
$attributes['A129'] = 'parking';
}
if ($happening->venue->venueAttributes->disabledAccess == '1') {
$attributes['A130'] = 'Udogodnienia dla niepełnosprawnych';
}
//if ($happening->venue->venueAttributes->foodAndDrinkAvailable == '1') {
// brak odpowiednika w RIT
//}
if (isset($happening->organizer)) {
$attributes['A024'] = $happening->organizer->organizerName;
$attributes['A025'] = strtoupper($happening->organizer->organizerVoivodeship);
$attributes['A026'] = $happening->organizer->organizerDistrict;
$attributes['A027'] = $happening->organizer->organizerCommune;
$attributes['A028'] = $happening->organizer->organizerLocality;
$attributes['A030'] = $happening->organizer->organizerStreet;
$attributes['A031'] = $happening->organizer->organizerHouseNo;
$attributes['A033'] = $happening->organizer->organizerPostCode;
$attributes['A034'] = $happening->organizer->organizerTelephone;
$attributes['A039'] = $happening->organizer->organizerEmail;
}
foreach ($attributes as $code => $values) {
$attribute = new \stdClass;
$attribute->code = $code;
$attribute->attrVals = new \stdClass;
$attribute->attrVals->language = $language;
$attribute->attrVals->value = explode('|', $values);
$touristObject->attributes[] = $attribute;
}
$touristObject->binaryDocuments = new \stdClass;
$touristObject->binaryDocuments->documentURL = array();
$images = array();
if (isset($happening->imageUrl)) {
$images[] = $happening->imageUrl;
}
if (isset($happening->venue->venueImageUrl)) {
$images[] = $happening->venue->venueImageUrl;
}
foreach ($images as $image) {
$documentURL = new \stdClass;
$documentURL->fileType = 'image';
$documentURL->URL = $happening->imageUrl;
$documentURL->fileName = basename($documentURL->URL);
$touristObject->binaryDocuments->documentURL[] = $documentURL;
}
$response->touristObject[] = $touristObject;
$count++;
}
$response->info = 'Znaleziono '. $count .' obiektów';
return $response;
}
}
$webservice = 'CollectTouristObjects';
require 'server.php';