Total Complexity | 17 |
Total Lines | 81 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | trait PublisherLogicTrait |
||
19 | { |
||
20 | /** |
||
21 | * todo extract Infra getcont form file + inject |
||
22 | */ |
||
23 | protected function importConfigAndData(): void |
||
24 | { |
||
25 | // todo REFAC DataObject[] |
||
26 | $this->config = Yaml::parseFile(self::CONFIG_PRESSE); |
||
1 ignored issue
–
show
|
|||
27 | $skipFromFile = file( |
||
28 | self::SKIP_DOMAIN_FILENAME, |
||
1 ignored issue
–
show
|
|||
29 | FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES |
||
30 | ); |
||
31 | $this->skip_domain = $skipFromFile ?: []; |
||
1 ignored issue
–
show
|
|||
32 | |||
33 | $this->publisherData['newspaper'] = json_decode(file_get_contents(self::CONFIG_NEWSPAPER_JSON), true, 512, JSON_THROW_ON_ERROR); |
||
2 ignored issues
–
show
|
|||
34 | $this->publisherData['scientific domain'] = json_decode( |
||
35 | file_get_contents(self::CONFIG_SCIENTIFIC_JSON), |
||
1 ignored issue
–
show
|
|||
36 | true, |
||
37 | 512, |
||
38 | JSON_THROW_ON_ERROR |
||
39 | ); |
||
40 | $this->publisherData['scientific wiki'] = json_decode( |
||
41 | file_get_contents(self::CONFIG_SCIENTIFIC_WIKI_JSON), |
||
1 ignored issue
–
show
|
|||
42 | true, |
||
43 | 512, |
||
44 | JSON_THROW_ON_ERROR |
||
45 | ); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * TODO rename/move Postprocess data site/périodique |
||
50 | * Logique : remplacement titre périodique ou nom du site |
||
51 | * |
||
52 | * @param array $mapData |
||
53 | * @param $template |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | protected function replaceSitenameByConfig(array $mapData, $template): array |
||
58 | { |
||
59 | // from wikidata URL of newspapers |
||
60 | if (!empty($this->publisherData['newspaper'][$this->registrableDomain])) { |
||
61 | $frwiki = $this->publisherData['newspaper'][$this->registrableDomain]['frwiki']; |
||
62 | $label = $this->publisherData['newspaper'][$this->registrableDomain]['fr']; |
||
63 | if (isset($mapData['site']) || $template instanceof LienWebTemplate) { |
||
64 | $mapData['site'] = WikiTextUtil::wikilink($label, $frwiki); |
||
65 | } |
||
66 | if (isset($mapData['périodique']) || $template instanceof ArticleTemplate) { |
||
67 | $mapData['périodique'] = WikiTextUtil::wikilink($label, $frwiki); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | // from wikidata of scientific journals |
||
72 | if (isset($mapData['périodique']) && isset($this->publisherData['scientific wiki'][$mapData['périodique']])) { |
||
73 | $mapData['périodique'] = WikiTextUtil::wikilink( |
||
74 | $mapData['périodique'], |
||
75 | $this->publisherData['scientific wiki'][$mapData['périodique']] |
||
76 | ); |
||
77 | } |
||
78 | |||
79 | // from YAML config |
||
80 | if (!empty($this->config[$this->registrableDomain]['site']) && $template instanceof LienWebTemplate) { |
||
81 | $mapData['site'] = $this->config[$this->registrableDomain]['site']; |
||
82 | } |
||
83 | if (!empty($this->config[$this->registrableDomain]['périodique']) |
||
84 | && (!empty($mapData['périodique']) |
||
85 | || $template instanceof OuvrageTemplate) |
||
86 | ) { |
||
87 | $mapData['périodique'] = $this->config[$this->registrableDomain]['périodique']; |
||
88 | } |
||
89 | |||
90 | return $mapData; |
||
91 | } |
||
92 | |||
93 | protected function isScientificDomain(): bool |
||
99 | } |
||
100 | } |