1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Event\ReadModel\JSONLD; |
4
|
|
|
|
5
|
|
|
use CultuurNet\UDB3\ReadModel\ConfigurableJsonDocumentLanguageAnalyzer; |
6
|
|
|
use CultuurNet\UDB3\ReadModel\JsonDocument; |
7
|
|
|
|
8
|
|
|
class EventJsonDocumentLanguageAnalyzer extends ConfigurableJsonDocumentLanguageAnalyzer |
9
|
|
|
{ |
10
|
|
|
public function __construct() |
11
|
|
|
{ |
12
|
|
|
parent::__construct( |
13
|
|
|
[ |
14
|
|
|
'name', |
15
|
|
|
'description', |
16
|
|
|
'bookingInfo.urlLabel', |
17
|
|
|
] |
18
|
|
|
); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @todo Remove when full replay is done. |
23
|
|
|
* @replay_i18n |
24
|
|
|
* @see https://jira.uitdatabank.be/browse/III-2201 |
25
|
|
|
* |
26
|
|
|
* @param JsonDocument $jsonDocument |
27
|
|
|
* @return \CultuurNet\UDB3\Language[] |
28
|
|
|
*/ |
29
|
|
|
public function determineAvailableLanguages(JsonDocument $jsonDocument) |
30
|
|
|
{ |
31
|
|
|
$jsonDocument = $this->polyFillMultilingualFields($jsonDocument); |
32
|
|
|
return parent::determineAvailableLanguages($jsonDocument); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @todo Remove when full replay is done. |
37
|
|
|
* @replay_i18n |
38
|
|
|
* @see https://jira.uitdatabank.be/browse/III-2201 |
39
|
|
|
* |
40
|
|
|
* @param JsonDocument $jsonDocument |
41
|
|
|
* @return \CultuurNet\UDB3\Language[] |
42
|
|
|
*/ |
43
|
|
|
public function determineCompletedLanguages(JsonDocument $jsonDocument) |
44
|
|
|
{ |
45
|
|
|
$jsonDocument = $this->polyFillMultilingualFields($jsonDocument); |
46
|
|
|
return parent::determineCompletedLanguages($jsonDocument); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @todo Remove when full replay is done. |
51
|
|
|
* @replay_i18n |
52
|
|
|
* @see https://jira.uitdatabank.be/browse/III-2201 |
53
|
|
|
* |
54
|
|
|
* @param JsonDocument $jsonDocument |
55
|
|
|
* @return JsonDocument |
56
|
|
|
*/ |
57
|
|
|
private function polyFillMultilingualFields(JsonDocument $jsonDocument) |
58
|
|
|
{ |
59
|
|
|
$body = $jsonDocument->getBody(); |
60
|
|
|
$mainLanguage = isset($body->mainLanguage) ? $body->mainLanguage : 'nl'; |
61
|
|
|
|
62
|
|
View Code Duplication |
if (isset($body->bookingInfo->urlLabel) && is_string($body->bookingInfo->urlLabel)) { |
|
|
|
|
63
|
|
|
$body->bookingInfo->urlLabel = (object) [ |
64
|
|
|
$mainLanguage => $body->bookingInfo->urlLabel, |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $jsonDocument->withBody($body); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
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.