|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Offer\ReadModel\JSONLD; |
|
4
|
|
|
|
|
5
|
|
|
use CultureFeed_Cdb_Item_Base; |
|
6
|
|
|
use CultuurNet\UDB3\Cdb\DateTimeFactory; |
|
7
|
|
|
use CultuurNet\UDB3\Offer\WorkflowStatus; |
|
8
|
|
|
|
|
9
|
|
|
class CdbXMLItemBaseImporter |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @param CultureFeed_Cdb_Item_Base $item |
|
13
|
|
|
* @param \stdClass $jsonLD |
|
14
|
|
|
*/ |
|
15
|
|
|
public function importPublicationInfo( |
|
16
|
|
|
CultureFeed_Cdb_Item_Base $item, |
|
17
|
|
|
\stdClass $jsonLD |
|
18
|
|
|
) { |
|
19
|
|
|
$jsonLD->creator = $item->getCreatedBy(); |
|
20
|
|
|
|
|
21
|
|
|
$itemCreationDate = $item->getCreationDate(); |
|
22
|
|
|
|
|
23
|
|
|
if (!empty($itemCreationDate)) { |
|
24
|
|
|
// format using ISO-8601 with time zone designator |
|
25
|
|
|
$creationDate = DateTimeFactory::dateTimeFromDateString( |
|
26
|
|
|
$itemCreationDate |
|
27
|
|
|
); |
|
28
|
|
|
|
|
29
|
|
|
$jsonLD->created = $creationDate->format('c'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$itemLastUpdatedDate = $item->getLastUpdated(); |
|
33
|
|
|
|
|
34
|
|
|
if (!empty($itemLastUpdatedDate)) { |
|
35
|
|
|
$lastUpdatedDate = DateTimeFactory::dateTimeFromDateString( |
|
36
|
|
|
$itemLastUpdatedDate |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
$jsonLD->modified = $lastUpdatedDate->format('c'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$jsonLD->publisher = $item->getOwner(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param CultureFeed_Cdb_Item_Base $item |
|
47
|
|
|
* @param \stdClass $jsonLD |
|
48
|
|
|
*/ |
|
49
|
|
|
public function importAvailable( |
|
50
|
|
|
\CultureFeed_Cdb_Item_Base $item, |
|
51
|
|
|
\stdClass $jsonLD |
|
52
|
|
|
) { |
|
53
|
|
|
$availableFromString = $item->getAvailableFrom(); |
|
54
|
|
|
if ($availableFromString) { |
|
55
|
|
|
$jsonLD->availableFrom = $this->formatAvailableString( |
|
56
|
|
|
$availableFromString |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$availableToString = $item->getAvailableTo(); |
|
61
|
|
|
if ($availableToString) { |
|
62
|
|
|
$jsonLD->availableTo = $this->formatAvailableString( |
|
63
|
|
|
$availableToString |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param string $availableString |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
|
|
private function formatAvailableString($availableString) |
|
73
|
|
|
{ |
|
74
|
|
|
$available = DateTimeFactory::dateTimeFromDateString( |
|
75
|
|
|
$availableString |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
return $available->format('c'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param CultureFeed_Cdb_Item_Base $item |
|
83
|
|
|
* @param \stdClass $jsonLD |
|
84
|
|
|
*/ |
|
85
|
|
|
public function importExternalId( |
|
86
|
|
|
\CultureFeed_Cdb_Item_Base $item, |
|
87
|
|
|
\stdClass $jsonLD |
|
88
|
|
|
) { |
|
89
|
|
|
$externalId = $item->getExternalId(); |
|
90
|
|
|
if (empty($externalId)) { |
|
91
|
|
|
return; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$externalIdIsCDB = (strpos($externalId, 'CDB:') === 0); |
|
95
|
|
|
|
|
96
|
|
|
if (!property_exists($jsonLD, 'sameAs')) { |
|
97
|
|
|
$jsonLD->sameAs = []; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if (!$externalIdIsCDB) { |
|
101
|
|
|
if (!in_array($externalId, $jsonLD->sameAs)) { |
|
102
|
|
|
array_push($jsonLD->sameAs, $externalId); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param CultureFeed_Cdb_Item_Base $item |
|
109
|
|
|
* @param \stdClass $jsonLD |
|
110
|
|
|
*/ |
|
111
|
|
|
public function importWorkflowStatus( |
|
112
|
|
|
CultureFeed_Cdb_Item_Base $item, |
|
113
|
|
|
\stdClass $jsonLD |
|
114
|
|
|
) { |
|
115
|
|
|
$wfStatus = $item->getWfStatus(); |
|
116
|
|
|
|
|
117
|
|
|
$workflowStatus = $wfStatus ? WorkflowStatus::fromNative($wfStatus) : WorkflowStatus::READY_FOR_VALIDATION(); |
|
118
|
|
|
|
|
119
|
|
|
$jsonLD->workflowStatus = $workflowStatus->getName(); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|