Completed
Pull Request — master (#243)
by Luc
05:05 queued 10s
created

CdbXMLImporter::importCalendar()   C

Complexity

Conditions 11
Paths 40

Size

Total Lines 74
Code Lines 49

Duplication

Lines 12
Ratio 16.22 %

Importance

Changes 0
Metric Value
dl 12
loc 74
rs 5.5364
c 0
b 0
f 0
cc 11
eloc 49
nc 40
nop 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A CdbXMLImporter::importTypicalAgeRange() 0 7 2
A CdbXMLImporter::importPerformers() 0 14 4
A CdbXMLImporter::importLanguages() 0 12 3
B CdbXMLImporter::importSeeAlso() 0 21 7

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace CultuurNet\UDB3\Event\ReadModel\JSONLD;
4
5
use CultureFeed_Cdb_Data_File;
6
use CultureFeed_Cdb_Data_Keyword;
7
use CultuurNet\UDB3\CalendarFactory;
8
use CultuurNet\UDB3\Cdb\CdbId\EventCdbIdExtractorInterface;
9
use CultuurNet\UDB3\Cdb\PriceDescriptionParser;
10
use CultuurNet\UDB3\LabelImporter;
11
use CultuurNet\UDB3\Offer\ReadModel\JSONLD\CdbXMLItemBaseImporter;
12
use CultuurNet\UDB3\SluggerInterface;
13
use CultuurNet\UDB3\StringFilter\StringFilterInterface;
14
15
/**
16
 * Takes care of importing cultural events in the CdbXML format (UDB2)
17
 * into a UDB3 JSON-LD document.
18
 */
19
class CdbXMLImporter
20
{
21
    /**
22
     * @var CdbXMLItemBaseImporter
23
     */
24
    private $cdbXMLItemBaseImporter;
25
26
    /**
27
     * @var EventCdbIdExtractorInterface
28
     */
29
    private $cdbIdExtractor;
30
31
    /**
32
     * @var PriceDescriptionParser
33
     */
34
    private $priceDescriptionParser;
35
36
    /**
37
     * @param CdbXMLItemBaseImporter $dbXMLItemBaseImporter
38
     * @param EventCdbIdExtractorInterface $cdbIdExtractor
39
     * @param PriceDescriptionParser $priceDescriptionParser
40
     */
41
    public function __construct(
42
        CdbXMLItemBaseImporter $dbXMLItemBaseImporter,
43
        EventCdbIdExtractorInterface $cdbIdExtractor,
44
        PriceDescriptionParser $priceDescriptionParser
45
    ) {
46
        $this->cdbXMLItemBaseImporter = $dbXMLItemBaseImporter;
47
        $this->cdbIdExtractor = $cdbIdExtractor;
48
        $this->priceDescriptionParser = $priceDescriptionParser;
49
    }
50
51
    /**
52
     * @var StringFilterInterface[]
53
     */
54
    private $descriptionFilters = [];
55
56
    /**
57
     * Imports a UDB2 event into a UDB3 JSON-LD document.
58
     *
59
     * @param \stdClass $base
60
     *   The JSON-LD document to start from.
61
     * @param \CultureFeed_Cdb_Item_Event $event
62
     *   The cultural event data from UDB2 to import.
63
     * @param PlaceServiceInterface $placeManager
64
     *   The manager from which to retrieve the JSON-LD of a place.
65
     * @param OrganizerServiceInterface $organizerManager
66
     *   The manager from which to retrieve the JSON-LD of an organizer.
67
     * @param SluggerInterface $slugger
68
     *   The slugger that's used to generate a sameAs reference.
69
     *
70
     * @return \stdClass
71
     *   The document with the UDB2 event data merged in.
72
     */
73
    public function documentWithCdbXML(
74
        $base,
75
        \CultureFeed_Cdb_Item_Event $event,
76
        PlaceServiceInterface $placeManager,
77
        OrganizerServiceInterface $organizerManager,
78
        SluggerInterface $slugger
79
    ) {
80
        $jsonLD = clone $base;
81
82
        /** @var \CultureFeed_Cdb_Data_EventDetail $detail */
83
        $detail = null;
84
85
        /** @var \CultureFeed_Cdb_Data_EventDetail[] $details */
86
        $details = $event->getDetails();
87
88
        foreach ($details as $languageDetail) {
89
            $language = $languageDetail->getLanguage();
90
91
            // The first language detail found will be used to retrieve
92
            // properties from which in UDB3 are not any longer considered
93
            // to be language specific.
94
            if (!$detail) {
95
                $detail = $languageDetail;
96
            }
97
98
            $jsonLD->name[$language] = $languageDetail->getTitle();
99
100
            $this->importDescription($languageDetail, $jsonLD, $language);
101
        }
102
103
        $this->cdbXMLItemBaseImporter->importAvailable($event, $jsonLD);
104
105
        $this->importPicture($detail, $jsonLD);
106
107
        $labelImporter = new LabelImporter();
108
        $labelImporter->importLabels($event, $jsonLD);
109
110
        $jsonLD->calendarSummary = $detail->getCalendarSummary();
111
112
        $this->importLocation($event, $placeManager, $jsonLD);
113
114
        $this->importOrganizer($event, $organizerManager, $jsonLD);
115
116
        $this->importBookingInfo($event, $detail, $jsonLD);
117
118
        $this->importPriceInfo($detail, $jsonLD);
119
120
        $this->importTerms($event, $jsonLD);
121
122
        $this->cdbXMLItemBaseImporter->importPublicationInfo($event, $jsonLD);
123
124
        $calendarFactory = new CalendarFactory();
125
        $calendar = $calendarFactory->createFromCdbCalendar($event->getCalendar());
126
        $jsonLD = (object)array_merge((array)$jsonLD, $calendar->toJsonLd());
127
128
        $this->importTypicalAgeRange($event, $jsonLD);
129
130
        $this->importPerformers($detail, $jsonLD);
131
132
        $this->importLanguages($event, $jsonLD);
133
134
        $this->importUitInVlaanderenReference($event, $slugger, $jsonLD);
135
136
        $this->cdbXMLItemBaseImporter->importExternalId($event, $jsonLD);
137
138
        $this->importSeeAlso($event, $jsonLD);
139
140
        $this->importContactPoint($event, $jsonLD);
141
142
        $this->cdbXMLItemBaseImporter->importWorkflowStatus($event, $jsonLD);
143
144
        return $jsonLD;
145
    }
146
147
    /**
148
     * @param StringFilterInterface $filter
149
     */
150
    public function addDescriptionFilter(StringFilterInterface $filter)
151
    {
152
        $this->descriptionFilters[] = $filter;
153
    }
154
155
    /**
156
     * @param int $unixTime
157
     * @return \DateTime
158
     */
159
    private function dateFromUdb2UnixTime($unixTime)
160
    {
161
        $dateTime = new \DateTime(
162
            '@' . $unixTime,
163
            new \DateTimeZone('Europe/Brussels')
164
        );
165
166
        return $dateTime;
167
    }
168
169
    /**
170
     * @param \CultureFeed_Cdb_Data_EventDetail $languageDetail
171
     * @param \stdClass $jsonLD
172
     * @param string $language
173
     */
174
    private function importDescription($languageDetail, $jsonLD, $language)
175
    {
176
        $descriptions = [
177
            $languageDetail->getShortDescription(),
178
            $languageDetail->getLongDescription()
179
        ];
180
        $descriptions = array_filter($descriptions);
181
        $description = implode('<br/>', $descriptions);
182
183
        foreach ($this->descriptionFilters as $descriptionFilter) {
184
            $description = $descriptionFilter->filter($description);
185
        };
186
187
        $jsonLD->description[$language] = $description;
188
    }
189
190
    /**
191
     * @param \CultureFeed_Cdb_Data_EventDetail $detail
192
     * @param \stdClass $jsonLD
193
     *
194
     * This is based on code found in the culturefeed theme.
195
     * @see https://github.com/cultuurnet/culturefeed/blob/master/culturefeed_agenda/theme/theme.inc#L266-L284
196
     */
197 View Code Duplication
    private function importPicture($detail, $jsonLD)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
198
    {
199
        $mainPicture = null;
200
201
        // first check if there is a media file that is main and has the PHOTO media type
202
        $photos = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO);
203
        foreach ($photos as $photo) {
204
            if ($photo->isMain()) {
205
                $mainPicture = $photo;
206
            }
207
        }
208
209
        // the IMAGEWEB media type is deprecated but can still be used as a main image if there is no PHOTO
210
        if (empty($mainPicture)) {
211
            $images = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB);
212
            foreach ($images as $image) {
213
                if ($image->isMain()) {
214
                    $mainPicture = $image;
215
                }
216
            }
217
        }
218
219
        // if there is no explicit main image we just use the oldest picture of any type
220
        if (empty($mainPicture)) {
221
            $pictures = $detail->getMedia()->byMediaTypes(
222
                [
223
                    CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO,
224
                    CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB
225
                ]
226
            );
227
228
            $pictures->rewind();
229
            $mainPicture = count($pictures) > 0 ? $pictures->current() : null;
230
        }
231
232
        if ($mainPicture) {
233
            $jsonLD->image = $mainPicture->getHLink();
234
        }
235
    }
236
237
    /**
238
     * @param \CultureFeed_Cdb_Item_Event $event
239
     * @param PlaceServiceInterface $placeManager
240
     * @param \stdClass $jsonLD
241
     */
242
    private function importLocation(\CultureFeed_Cdb_Item_Event $event, PlaceServiceInterface $placeManager, $jsonLD)
243
    {
244
        $location = array();
245
        $location['@type'] = 'Place';
246
247
        $location_id = $this->cdbIdExtractor->getRelatedPlaceCdbId($event);
248
249
        if ($location_id) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $location_id of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
250
            $location += (array)$placeManager->placeJSONLD($location_id);
251
        } else {
252
            $location_cdb = $event->getLocation();
253
            $location['name']['nl'] = $location_cdb->getLabel();
254
            $address = $location_cdb->getAddress()->getPhysicalAddress();
255
            if ($address) {
256
                $location['address'] = array(
257
                    'addressCountry' => $address->getCountry(),
258
                    'addressLocality' => $address->getCity(),
259
                    'postalCode' => $address->getZip(),
260
                    'streetAddress' =>
261
                        $address->getStreet() . ' ' . $address->getHouseNumber(
262
                        ),
263
                );
264
            }
265
        }
266
        $jsonLD->location = $location;
267
    }
268
269
    /**
270
     * @param \CultureFeed_Cdb_Item_Event $event
271
     * @param OrganizerServiceInterface $organizerManager
272
     * @param \stdClass $jsonLD
273
     */
274
    private function importOrganizer(
275
        \CultureFeed_Cdb_Item_Event $event,
276
        OrganizerServiceInterface $organizerManager,
277
        $jsonLD
278
    ) {
279
        $organizer = null;
280
        $organizer_id = $this->cdbIdExtractor->getRelatedOrganizerCdbId($event);
281
        $organizer_cdb = $event->getOrganiser();
282
        $contact_info_cdb = $event->getContactInfo();
283
284
        if ($organizer_id) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $organizer_id of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
285
            $organizer = (array)$organizerManager->organizerJSONLD($organizer_id);
286
        } elseif ($organizer_cdb && $contact_info_cdb) {
287
            $organizer = array();
288
            $organizer['name'] = $organizer_cdb->getLabel();
289
290
            $emails_cdb = $contact_info_cdb->getMails();
291
            if (count($emails_cdb) > 0) {
292
                $organizer['email'] = array();
293
                foreach ($emails_cdb as $email) {
294
                    $organizer['email'][] = $email->getMailAddress();
295
                }
296
            }
297
298
            $phones_cdb = $contact_info_cdb->getPhones();
299
            if (count($phones_cdb) > 0) {
300
                $organizer['phone'] = array();
301
                foreach ($phones_cdb as $phone) {
302
                    $organizer['phone'][] = $phone->getNumber();
303
                }
304
            }
305
        }
306
307
        if (!is_null($organizer)) {
308
            $organizer['@type'] = 'Organizer';
309
            $jsonLD->organizer = $organizer;
310
        }
311
    }
312
313
    /**
314
     * @param \CultureFeed_Cdb_Data_EventDetail $detail
315
     * @param \stdClass $jsonLD
316
     */
317
    private function importPriceInfo(
318
        \CultureFeed_Cdb_Data_EventDetail $detail,
319
        $jsonLD
320
    ) {
321
        $prices = array();
322
323
        $price = $detail->getPrice();
324
325
        if ($price) {
326
            $description = $price->getDescription();
327
328
            if ($description) {
329
                $prices = $this->priceDescriptionParser->parse($description);
330
            }
331
332
            // If price description was not interpretable, fall back to
333
            // price title and value.
334
            if (empty($prices) && $price->getValue() !== null) {
335
                $prices['Basistarief'] = floatval($price->getValue());
336
            }
337
        }
338
339
        if (!empty($prices)) {
340
            $priceInfo = array();
341
342
            /** @var \CultureFeed_Cdb_Data_Price $price */
343
            foreach ($prices as $title => $value) {
344
                $priceInfoItem = array(
345
                    'name' => $title,
346
                    'priceCurrency' => 'EUR',
347
                    'price' => $value,
348
                );
349
350
                $priceInfoItem['category'] = 'tariff';
351
352
                if ($priceInfoItem['name'] === 'Basistarief') {
353
                    $priceInfoItem['category'] = 'base';
354
                }
355
356
                $priceInfo[] = $priceInfoItem;
357
            }
358
359
            if (!empty($priceInfo)) {
360
                $jsonLD->priceInfo = $priceInfo;
361
            }
362
        }
363
    }
364
365
    /**
366
     * @param \CultureFeed_Cdb_Data_EventDetail $detail
367
     * @param \stdClass $jsonLD
368
     */
369
    private function importBookingInfo(
370
        \CultureFeed_Cdb_Item_Event $event,
371
        \CultureFeed_Cdb_Data_EventDetail $detail,
372
        $jsonLD
373
    ) {
374
        $bookingInfo = array();
375
376
        $price = $detail->getPrice();
377
        if ($price) {
378
            if ($price->getDescription()) {
379
                $bookingInfo['description'] = $price->getDescription();
380
            }
381
            if ($price->getTitle()) {
382
                $bookingInfo['name'] = $price->getTitle();
383
            }
384
            if ($price->getValue() !== null) {
385
                $bookingInfo['priceCurrency'] = 'EUR';
386
                $bookingInfo['price'] = floatval($price->getValue());
387
            }
388
            if ($bookingPeriod = $event->getBookingPeriod()) {
389
                $startDate = $this->dateFromUdb2UnixTime($bookingPeriod->getDateFrom());
390
                $endDate = $this->dateFromUdb2UnixTime($bookingPeriod->getDateTill());
391
392
                $bookingInfo['availabilityStarts'] = $startDate->format('c');
393
                $bookingInfo['availabilityEnds'] = $endDate->format('c');
394
            }
395
        }
396
397
        // Add reservation contact data.
398
        $contactInfo = $event->getContactInfo();
399
        if ($contactInfo) {
400
            foreach ($contactInfo->getUrls() as $url) {
401
                if ($url->isForReservations()) {
402
                    $bookingInfo['url'] = $url->getUrl();
403
                    break;
404
                }
405
            }
406
407
            if (array_key_exists('url', $bookingInfo)) {
408
                $bookingInfo['urlLabel'] = 'Reserveer plaatsen';
409
            }
410
411
            foreach ($contactInfo->getPhones() as $phone) {
412
                if ($phone->isForReservations()) {
413
                    $bookingInfo['phone'] = $phone->getNumber();
414
                    break;
415
                }
416
            }
417
418
            foreach ($contactInfo->getMails() as $mail) {
419
                if ($mail->isForReservations()) {
420
                    $bookingInfo['email'] = $mail->getMailAddress();
421
                    break;
422
                }
423
            }
424
        }
425
426
        if (!empty($bookingInfo)) {
427
            $jsonLD->bookingInfo = $bookingInfo;
428
        }
429
    }
430
431
    /**
432
     * @param \CultureFeed_Cdb_Item_Event $event
433
     * @param \stdClass $jsonLD
434
     */
435
    private function importContactPoint(
436
        \CultureFeed_Cdb_Item_Event $event,
437
        \stdClass $jsonLD
438
    ) {
439
        $contactInfo = $event->getContactInfo();
440
441
        $notForReservations = function ($item) {
442
            /** @var \CultureFeed_Cdb_Data_Url|\CultureFeed_Cdb_Data_Phone|\CultureFeed_Cdb_Data_Mail $item */
443
            return !$item->isForReservations();
444
        };
445
446
        if ($contactInfo) {
447
            $contactPoint = array();
448
449
            $emails = array_filter($contactInfo->getMails(), $notForReservations);
450
451 View Code Duplication
            if (!empty($emails)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
452
                $contactPoint['email'] = array_map(
453
                    function (\CultureFeed_Cdb_Data_Mail $email) {
454
                        return $email->getMailAddress();
455
                    },
456
                    $emails
457
                );
458
                $contactPoint['email'] = array_values($contactPoint['email']);
459
            }
460
461
            $phones = array_filter($contactInfo->getPhones(), $notForReservations);
462
463 View Code Duplication
            if (!empty($phones)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
464
                $contactPoint['phone'] = array_map(
465
                    function (\CultureFeed_Cdb_Data_phone $phone) {
466
                        return $phone->getNumber();
467
                    },
468
                    $phones
469
                );
470
                $contactPoint['phone'] = array_values($contactPoint['phone']);
471
            }
472
473
            $urls = array_filter($contactInfo->getUrls(), $notForReservations);
474
475 View Code Duplication
            if (!empty($urls)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
476
                $contactPoint['url'] = array_map(
477
                    function (\CultureFeed_Cdb_Data_Url $url) {
478
                        return $url->getUrl();
479
                    },
480
                    $urls
481
                );
482
                $contactPoint['url'] = array_values($contactPoint['url']);
483
            }
484
485
            array_filter($contactPoint);
486
            if (!empty($contactPoint)) {
487
                $jsonLD->contactPoint = $contactPoint;
488
            }
489
        }
490
    }
491
492
    /**
493
     * @param \CultureFeed_Cdb_Item_Event $event
494
     * @param \stdClass $jsonLD
495
     */
496
    private function importTerms(\CultureFeed_Cdb_Item_Event $event, $jsonLD)
497
    {
498
        $themeBlacklist = [
499
            'Thema onbepaald',
500
            'Meerder kunstvormen',
501
            'Meerdere filmgenres'
502
        ];
503
        $categories = array();
504 View Code Duplication
        foreach ($event->getCategories() as $category) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
505
            /* @var \Culturefeed_Cdb_Data_Category $category */
506
            if ($category && !in_array($category->getName(), $themeBlacklist)) {
507
                $categories[] = array(
508
                    'label' => $category->getName(),
509
                    'domain' => $category->getType(),
510
                    'id' => $category->getId(),
511
                );
512
            }
513
        }
514
        $jsonLD->terms = $categories;
515
    }
516
517
    /**
518
     * @param \CultureFeed_Cdb_Item_Event $event
519
     * @param \stdClass $jsonLD
520
     */
521
    private function importTypicalAgeRange(\CultureFeed_Cdb_Item_Event $event, $jsonLD)
522
    {
523
        $ageFrom = $event->getAgeFrom();
524
        if ($ageFrom) {
525
            $jsonLD->typicalAgeRange = "{$ageFrom}-";
526
        }
527
    }
528
529
    /**
530
     * @param \CultureFeed_Cdb_Data_EventDetail $detail
531
     * @param \stdClass $jsonLD
532
     */
533
    private function importPerformers(\CultureFeed_Cdb_Data_EventDetail $detail, $jsonLD)
534
    {
535
        /** @var \CultureFeed_Cdb_Data_Performer $performer */
536
        $performers = $detail->getPerformers();
537
        if ($performers) {
538
            foreach ($performers as $performer) {
539
                if ($performer->getLabel()) {
540
                    $performerData = new \stdClass();
541
                    $performerData->name = $performer->getLabel();
542
                    $jsonLD->performer[] = $performerData;
543
                }
544
            }
545
        }
546
    }
547
548
    /**
549
     * @param \CultureFeed_Cdb_Item_Event $event
550
     * @param \stdClass $jsonLD
551
     */
552
    private function importLanguages(\CultureFeed_Cdb_Item_Event $event, $jsonLD)
553
    {
554
        /** @var \CultureFeed_Cdb_Data_Language $udb2Language */
555
        $languages = $event->getLanguages();
556
        if ($languages) {
557
            $jsonLD->language = [];
558
            foreach ($languages as $udb2Language) {
559
                $jsonLD->language[] = $udb2Language->getLanguage();
560
            }
561
            $jsonLD->language = array_unique($jsonLD->language);
562
        }
563
    }
564
565
    /**
566
     * @param \CultureFeed_Cdb_Item_Event $event
567
     * @param \stdClass $jsonLD
568
     */
569
    private function importSeeAlso(
570
        \CultureFeed_Cdb_Item_Event $event,
571
        \stdClass $jsonLD
572
    ) {
573
        if (!property_exists($jsonLD, 'seeAlso')) {
574
            $jsonLD->seeAlso = [];
575
        }
576
577
        // Add contact info url, if it's not for reservations.
578
        if ($contactInfo = $event->getContactInfo()) {
579
            /** @var \CultureFeed_Cdb_Data_Url[] $contactUrls */
580
            $contactUrls = $contactInfo->getUrls();
581
            if (is_array($contactUrls) && count($contactUrls) > 0) {
582
                foreach ($contactUrls as $contactUrl) {
583
                    if (!$contactUrl->isForReservations()) {
584
                        $jsonLD->seeAlso[] = $contactUrl->getUrl();
585
                    }
586
                }
587
            }
588
        }
589
    }
590
591
    /**
592
     * @param \CultureFeed_Cdb_Item_Event $event
593
     * @param SluggerInterface $slugger
594
     * @param \stdClass $jsonLD
595
     */
596
    private function importUitInVlaanderenReference(
597
        \CultureFeed_Cdb_Item_Event $event,
598
        SluggerInterface $slugger,
599
        $jsonLD
600
    ) {
601
602
        // Some events seem to not have a Dutch name, even though this is
603
        // required. If there's no Dutch name, we just leave the slug empty as
604
        // that seems to be the behaviour on http://m.uitinvlaanderen.be
605
        if (isset($jsonLD->name['nl'])) {
606
            $name = $jsonLD->name['nl'];
607
            $slug = $slugger->slug($name);
608
        } else {
609
            $slug = '';
610
        }
611
612
        $reference = 'http://www.uitinvlaanderen.be/agenda/e/' . $slug . '/' . $event->getCdbId();
613
614
615
        if (!property_exists($jsonLD, 'sameAs')) {
616
            $jsonLD->sameAs = [];
617
        }
618
619
        if (!in_array($reference, $jsonLD->sameAs)) {
620
            array_push($jsonLD->sameAs, $reference);
621
        }
622
    }
623
}
624