|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @file |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace CultuurNet\UDB3\Offer\ReadModel\JSONLD; |
|
7
|
|
|
|
|
8
|
|
|
use CultureFeed_Cdb_Item_Base; |
|
9
|
|
|
use CultuurNet\UDB3\Cdb\DateTimeFactory; |
|
10
|
|
|
use stdClass; |
|
11
|
|
|
|
|
12
|
|
|
class CdbXMLItemBaseImporter |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param CultureFeed_Cdb_Item_Base $item |
|
16
|
|
|
* @param stdClass $jsonLD |
|
17
|
|
|
*/ |
|
18
|
|
|
public function importPublicationInfo( |
|
19
|
|
|
CultureFeed_Cdb_Item_Base $item, |
|
20
|
|
|
stdClass $jsonLD |
|
21
|
|
|
) { |
|
22
|
|
|
$jsonLD->creator = $item->getCreatedBy(); |
|
23
|
|
|
|
|
24
|
|
|
$itemCreationDate = $item->getCreationDate(); |
|
25
|
|
|
|
|
26
|
|
|
if (!empty($itemCreationDate)) { |
|
27
|
|
|
// format using ISO-8601 with time zone designator |
|
28
|
|
|
$creationDate = DateTimeFactory::dateTimeFromDateString( |
|
29
|
|
|
$itemCreationDate |
|
30
|
|
|
); |
|
31
|
|
|
|
|
32
|
|
|
$jsonLD->created = $creationDate->format('c'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$itemLastUpdatedDate = $item->getLastUpdated(); |
|
36
|
|
|
|
|
37
|
|
|
if (!empty($itemLastUpdatedDate)) { |
|
38
|
|
|
$lastUpdatedDate = DateTimeFactory::dateTimeFromDateString( |
|
39
|
|
|
$itemLastUpdatedDate |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$jsonLD->modified = $lastUpdatedDate->format('c'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$jsonLD->publisher = $item->getOwner(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param CultureFeed_Cdb_Item_Base $item |
|
50
|
|
|
* @param stdClass $jsonLD |
|
51
|
|
|
*/ |
|
52
|
|
|
public function importAvailable( |
|
53
|
|
|
\CultureFeed_Cdb_Item_Base $item, |
|
54
|
|
|
\stdClass $jsonLD |
|
55
|
|
|
) { |
|
56
|
|
|
$availableString = $item->getAvailableFrom(); |
|
57
|
|
|
if ($availableString) { |
|
58
|
|
|
$available = DateTimeFactory::dateTimeFromDateString( |
|
59
|
|
|
$availableString |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
$jsonLD->available = $available->format('c'); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param CultureFeed_Cdb_Item_Base $item |
|
68
|
|
|
* @param stdClass $jsonLD |
|
69
|
|
|
*/ |
|
70
|
|
|
public function importExternalId( |
|
71
|
|
|
\CultureFeed_Cdb_Item_Base $item, |
|
72
|
|
|
\stdClass $jsonLD |
|
73
|
|
|
) { |
|
74
|
|
|
$externalId = $item->getExternalId(); |
|
75
|
|
|
if (empty($externalId)) { |
|
76
|
|
|
return; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$externalIdIsCDB = (strpos($externalId, 'CDB:') === 0); |
|
80
|
|
|
|
|
81
|
|
|
if (!property_exists($jsonLD, 'sameAs')) { |
|
82
|
|
|
$jsonLD->sameAs = []; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if (!$externalIdIsCDB) { |
|
86
|
|
|
if (!in_array($externalId, $jsonLD->sameAs)) { |
|
87
|
|
|
array_push($jsonLD->sameAs, $externalId); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|