|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WebHemi. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 7.1 |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com) |
|
8
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
|
9
|
|
|
* |
|
10
|
|
|
* @link http://www.gixx-web.com |
|
11
|
|
|
*/ |
|
12
|
|
|
declare(strict_types = 1); |
|
13
|
|
|
|
|
14
|
|
|
namespace WebHemi\Middleware\Action\Website; |
|
15
|
|
|
|
|
16
|
|
|
use WebHemi\Data\Entity; |
|
17
|
|
|
use WebHemi\Data\Storage; |
|
18
|
|
|
use WebHemi\Data\StorageInterface; |
|
19
|
|
|
use WebHemi\Data\Traits\StorageInjectorTrait; |
|
20
|
|
|
use WebHemi\Environment\ServiceInterface as EnvironmentInterface; |
|
21
|
|
|
use WebHemi\Middleware\Action\AbstractMiddlewareAction; |
|
22
|
|
|
use WebHemi\Router\ProxyInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class IndexAction. |
|
26
|
|
|
* |
|
27
|
|
|
* @method Storage\ApplicationStorage getApplicationStorage() |
|
28
|
|
|
* @method Storage\Filesystem\FilesystemCategoryStorage getFilesystemCategoryStorage() |
|
29
|
|
|
* @method Storage\Filesystem\FilesystemDirectoryStorage getFilesystemDirectoryStorage() |
|
30
|
|
|
* @method Storage\Filesystem\FilesystemDocumentStorage getFilesystemDocumentStorage() |
|
31
|
|
|
* @method Storage\Filesystem\FilesystemStorage getFilesystemStorage() |
|
32
|
|
|
* @method Storage\Filesystem\FilesystemTagStorage getFilesystemTagStorage() |
|
33
|
|
|
* @method Storage\User\UserStorage getUserStorage() |
|
34
|
|
|
* @method Storage\User\UserMetaStorage getUserMetaStorage() |
|
35
|
|
|
*/ |
|
36
|
|
|
class IndexAction extends AbstractMiddlewareAction |
|
37
|
|
|
{ |
|
38
|
|
|
/** @var EnvironmentInterface */ |
|
39
|
|
|
protected $environmentManager; |
|
40
|
|
|
|
|
41
|
|
|
use StorageInjectorTrait; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* IndexAction constructor. |
|
45
|
|
|
* |
|
46
|
|
|
* @param EnvironmentInterface $environmentManager |
|
47
|
|
|
* @param StorageInterface[] ...$dataStorages |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct(EnvironmentInterface $environmentManager, StorageInterface ...$dataStorages) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->environmentManager = $environmentManager; |
|
52
|
|
|
$this->addStorageInstances($dataStorages); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Gets template map name or template file path. |
|
57
|
|
|
* |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getTemplateName() : string |
|
61
|
|
|
{ |
|
62
|
|
|
return 'website-index'; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Gets template data. |
|
67
|
|
|
* |
|
68
|
|
|
* @return array |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getTemplateData() : array |
|
71
|
|
|
{ |
|
72
|
|
|
$blogPosts = []; |
|
73
|
|
|
|
|
74
|
|
|
/** @var Entity\ApplicationEntity $applicationEntity */ |
|
75
|
|
|
$applicationEntity = $this->getApplicationStorage() |
|
76
|
|
|
->getApplicationByName($this->environmentManager->getSelectedApplication()); |
|
77
|
|
|
|
|
78
|
|
|
/** @var Entity\Filesystem\FilesystemEntity[] $publications */ |
|
79
|
|
|
$publications = $this->getFilesystemStorage() |
|
80
|
|
|
->getPublishedDocuments($applicationEntity->getApplicationId()); |
|
81
|
|
|
|
|
82
|
|
|
/** @var Entity\Filesystem\FilesystemEntity $filesystemEntity */ |
|
83
|
|
|
foreach ($publications as $filesystemEntity) { |
|
84
|
|
|
$blogPosts[] = $this->getBlobPostData($applicationEntity, $filesystemEntity); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return [ |
|
88
|
|
|
'activeMenu' => '', |
|
89
|
|
|
'application' => $this->getApplicationData($applicationEntity), |
|
90
|
|
|
'blogPosts' => $blogPosts, |
|
91
|
|
|
]; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Gets application data to render. |
|
96
|
|
|
* |
|
97
|
|
|
* @param Entity\ApplicationEntity $applicationEntity |
|
98
|
|
|
* @return array |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function getApplicationData(Entity\ApplicationEntity $applicationEntity) : array |
|
101
|
|
|
{ |
|
102
|
|
|
return [ |
|
103
|
|
|
'name' => $applicationEntity->getName(), |
|
104
|
|
|
'title' => $applicationEntity->getTitle(), |
|
105
|
|
|
'introduction' => $applicationEntity->getIntroduction(), |
|
106
|
|
|
'subject' => $applicationEntity->getSubject(), |
|
107
|
|
|
'description' => $applicationEntity->getDescription(), |
|
108
|
|
|
'keywords' => $applicationEntity->getKeywords(), |
|
109
|
|
|
'coptright' => $applicationEntity->getCopyright() |
|
110
|
|
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Collets the blog post data |
|
115
|
|
|
* |
|
116
|
|
|
* @param Entity\ApplicationEntity $applicationEntity |
|
117
|
|
|
* @param Entity\Filesystem\FilesystemEntity $filesystemEntity |
|
118
|
|
|
* @return array |
|
119
|
|
|
*/ |
|
120
|
|
|
protected function getBlobPostData( |
|
121
|
|
|
Entity\ApplicationEntity $applicationEntity, |
|
122
|
|
|
Entity\Filesystem\FilesystemEntity $filesystemEntity |
|
123
|
|
|
) : array { |
|
124
|
|
|
/** @var Entity\Filesystem\FilesystemDocumentEntity $documentEntity */ |
|
125
|
|
|
$documentEntity = $this->getFilesystemDocumentStorage() |
|
126
|
|
|
->getFilesystemDocumentById($filesystemEntity->getDocumentId()); |
|
127
|
|
|
|
|
128
|
|
|
$documentMeta = $this->getFilesystemStorage() |
|
129
|
|
|
->getPublicationMeta($filesystemEntity->getFilesystemId()); |
|
130
|
|
|
|
|
131
|
|
|
$author = $this->getPublicationAuthor( |
|
132
|
|
|
$documentEntity->getAuthorId(), |
|
133
|
|
|
$applicationEntity->getApplicationId() |
|
134
|
|
|
); |
|
135
|
|
|
|
|
136
|
|
|
return [ |
|
137
|
|
|
'author' => $author, |
|
138
|
|
|
'tags' => $this->getPublicationTags( |
|
139
|
|
|
$applicationEntity->getApplicationId(), |
|
140
|
|
|
$filesystemEntity->getFilesystemId() |
|
141
|
|
|
), |
|
142
|
|
|
'category' => $this->getPublicationCategory( |
|
143
|
|
|
$applicationEntity->getApplicationId(), |
|
144
|
|
|
$filesystemEntity->getCategoryId() |
|
145
|
|
|
), |
|
146
|
|
|
'path' => $this->getPublicationPath($filesystemEntity), |
|
147
|
|
|
'title' => $filesystemEntity->getTitle(), |
|
148
|
|
|
'summary' => $filesystemEntity->getDescription(), |
|
149
|
|
|
'contentLead' => $documentEntity->getContentLead(), |
|
150
|
|
|
'contentBody' => $documentEntity->getContentBody(), |
|
151
|
|
|
'publishedAt' => $filesystemEntity->getDatePublished(), |
|
152
|
|
|
'meta' => $documentMeta, |
|
153
|
|
|
]; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Gets author information for a filesystem record. |
|
158
|
|
|
* |
|
159
|
|
|
* @param int $userId |
|
160
|
|
|
* @param int $applicationId |
|
161
|
|
|
* @return array |
|
162
|
|
|
*/ |
|
163
|
|
View Code Duplication |
protected function getPublicationAuthor(int $userId, int $applicationId) : array |
|
|
|
|
|
|
164
|
|
|
{ |
|
165
|
|
|
/** @var Entity\User\UserEntity $user */ |
|
166
|
|
|
$user = $this->getUserStorage() |
|
167
|
|
|
->getUserById($userId); |
|
168
|
|
|
|
|
169
|
|
|
/** @var array $userMeta */ |
|
170
|
|
|
$userMeta = $this->getUserMetaStorage() |
|
171
|
|
|
->getUserMetaArrayForUserId($userId); |
|
172
|
|
|
|
|
173
|
|
|
/** @var array $userDirectoryData */ |
|
174
|
|
|
$userDirectoryData = $this->getFilesystemDirectoryStorage() |
|
175
|
|
|
->getDirectoryDataByApplicationAndProxy($applicationId, ProxyInterface::LIST_USER); |
|
176
|
|
|
|
|
177
|
|
|
return [ |
|
178
|
|
|
'userId' => $userId, |
|
179
|
|
|
'username' => $user->getUserName(), |
|
180
|
|
|
'url' => $userDirectoryData['uri'].'/'.$user->getUserName(), |
|
181
|
|
|
'meta' => $userMeta, |
|
182
|
|
|
]; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Generates the content path. |
|
187
|
|
|
* |
|
188
|
|
|
* @param Entity\Filesystem\FilesystemEntity $filesystemEntity |
|
189
|
|
|
* @return string |
|
190
|
|
|
*/ |
|
191
|
|
|
protected function getPublicationPath(Entity\Filesystem\FilesystemEntity $filesystemEntity) : string |
|
192
|
|
|
{ |
|
193
|
|
|
$path = $filesystemEntity->getPath().'/'.$filesystemEntity->getBaseName(); |
|
194
|
|
|
|
|
195
|
|
|
while (strpos($path, '//') !== false) { |
|
196
|
|
|
$path = str_replace('//', '/', $path); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
return ltrim($path, '/'); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Collects all the tags for a filesystem record. |
|
204
|
|
|
* |
|
205
|
|
|
* @param int $applicationId |
|
206
|
|
|
* @param int $filesystemId |
|
207
|
|
|
* @return array |
|
208
|
|
|
*/ |
|
209
|
|
|
protected function getPublicationTags(int $applicationId, int $filesystemId) : array |
|
210
|
|
|
{ |
|
211
|
|
|
$tags = []; |
|
212
|
|
|
/** @var Entity\Filesystem\FilesystemTagEntity[] $tagEntities */ |
|
213
|
|
|
$tagEntities = $this->getFilesystemTagStorage() |
|
214
|
|
|
->getFilesystemTagsByFilesystem($filesystemId); |
|
215
|
|
|
|
|
216
|
|
|
if (!empty($tagEntities)) { |
|
217
|
|
|
/** @var array $categoryDirectoryData */ |
|
218
|
|
|
$categoryDirectoryData = $this->getFilesystemDirectoryStorage() |
|
219
|
|
|
->getDirectoryDataByApplicationAndProxy($applicationId, ProxyInterface::LIST_TAG); |
|
220
|
|
|
|
|
221
|
|
|
/** @var Entity\Filesystem\FilesystemTagEntity $tagEntity */ |
|
222
|
|
|
foreach ($tagEntities as $tagEntity) { |
|
223
|
|
|
$tags[] = [ |
|
224
|
|
|
'url' => $categoryDirectoryData['uri'].'/'.$tagEntity->getName(), |
|
225
|
|
|
'name' => $tagEntity->getName(), |
|
226
|
|
|
'title' => $tagEntity->getTitle() |
|
227
|
|
|
]; |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
return $tags; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Gets the category for a filesystem record. |
|
236
|
|
|
* |
|
237
|
|
|
* @param int $applicationId |
|
238
|
|
|
* @param int $categoryId |
|
239
|
|
|
* @return array |
|
240
|
|
|
*/ |
|
241
|
|
View Code Duplication |
protected function getPublicationCategory(int $applicationId, int $categoryId) : array |
|
|
|
|
|
|
242
|
|
|
{ |
|
243
|
|
|
/** @var Entity\Filesystem\FilesystemCategoryEntity $categoryEntity */ |
|
244
|
|
|
$categoryEntity = $this->getFilesystemCategoryStorage() |
|
245
|
|
|
->getFilesystemCategoryById($categoryId); |
|
246
|
|
|
|
|
247
|
|
|
/** @var array $categoryDirectoryData */ |
|
248
|
|
|
$categoryDirectoryData = $this->getFilesystemDirectoryStorage() |
|
249
|
|
|
->getDirectoryDataByApplicationAndProxy($applicationId, ProxyInterface::LIST_CATEGORY); |
|
250
|
|
|
|
|
251
|
|
|
$category = [ |
|
252
|
|
|
'url' => $categoryDirectoryData['uri'].'/'.$categoryEntity->getName(), |
|
253
|
|
|
'name' => $categoryEntity->getName(), |
|
254
|
|
|
'title' => $categoryEntity->getTitle() |
|
255
|
|
|
]; |
|
256
|
|
|
return $category; |
|
257
|
|
|
} |
|
258
|
|
|
} |
|
259
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: