-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathArticleGridView.class.php
More file actions
260 lines (242 loc) · 10.8 KB
/
ArticleGridView.class.php
File metadata and controls
260 lines (242 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
namespace wcf\system\gridView\admin;
use wcf\acp\form\ArticleEditForm;
use wcf\acp\form\UserEditForm;
use wcf\data\article\AccessibleArticleList;
use wcf\data\article\Article;
use wcf\data\article\ViewableArticle;
use wcf\data\category\CategoryNodeTree;
use wcf\data\DatabaseObject;
use wcf\data\DatabaseObjectList;
use wcf\event\gridView\admin\ArticleGridViewInitialized;
use wcf\system\gridView\AbstractGridView;
use wcf\system\gridView\GridViewColumn;
use wcf\system\gridView\GridViewRowLink;
use wcf\system\gridView\renderer\CategoryColumnRenderer;
use wcf\system\gridView\renderer\DefaultColumnRenderer;
use wcf\system\gridView\renderer\NumberColumnRenderer;
use wcf\system\gridView\renderer\ObjectIdColumnRenderer;
use wcf\system\gridView\renderer\TimeColumnRenderer;
use wcf\system\gridView\renderer\UserLinkColumnRenderer;
use wcf\system\interaction\admin\ArticleInteractions;
use wcf\system\interaction\bulk\admin\ArticleBulkInteractions;
use wcf\system\interaction\Divider;
use wcf\system\interaction\EditInteraction;
use wcf\system\view\filter\BooleanFilter;
use wcf\system\view\filter\CategoryFilter;
use wcf\system\view\filter\MultipleSelectFilter;
use wcf\system\view\filter\SelectFilter;
use wcf\system\view\filter\TextFilter;
use wcf\system\view\filter\TimeFilter;
use wcf\system\view\filter\UserFilter;
use wcf\system\WCF;
use wcf\util\StringUtil;
/**
* Grid view for the list of articles.
*
* @author Olaf Braun
* @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*
* @extends AbstractGridView<Article, AccessibleArticleList>
*/
final class ArticleGridView extends AbstractGridView
{
public function __construct()
{
$this->addColumns([
GridViewColumn::for('articleID')
->label('wcf.global.objectID')
->renderer(new ObjectIdColumnRenderer())
->sortable(),
GridViewColumn::for('teaserImage')
->label('wcf.acp.article.teaserImage')
->renderer([
new class extends DefaultColumnRenderer {
public function render(mixed $value, DatabaseObject $row): string
{
\assert($row instanceof ViewableArticle);
if ($row->getTeaserImage() !== null) {
return $row->getTeaserImage()->getElementTag(48);
}
return \sprintf(
'<img src="%simages/placeholderTiny.png" width="48" height="48" loading="lazy" alt="">',
WCF::getPath()
);
}
#[\Override]
public function getClasses(): string
{
return 'gridView__column--image';
}
}
]),
GridViewColumn::for('title')
->label('wcf.global.title')
->sortable(sortByDatabaseColumn: 'articleContent.title')
->filter(new class('title', 'wcf.global.title') extends TextFilter {
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $value): void
{
$list->getConditionBuilder()->add(
"article.articleID IN (
SELECT articleID
FROM wcf1_article_content
WHERE title LIKE ?
)",
['%' . WCF::getDB()->escapeLikeValue($value) . '%']
);
}
})
->renderer([
new class extends DefaultColumnRenderer {
public function render(mixed $value, DatabaseObject $row): string
{
\assert($row instanceof ViewableArticle);
$labels = '';
if ($row->hasLabels()) {
$labels = '<br><ul class="labelList">';
foreach ($row->getLabels() as $label) {
$labels .= '<li>' . $label->render() . '</li>';
}
$labels .= '</ul>';
}
$badges = '';
if ($row->isDeleted) {
$badges .= \sprintf(
'<span class="badge label red">%s</span>',
WCF::getLanguage()->get('wcf.message.status.deleted')
);
}
if ($row->publicationStatus === Article::UNPUBLISHED) {
if ($badges !== '') {
$badges .= ' ';
}
$badges .= \sprintf(
'<span class="badge">%s</span>',
WCF::getLanguage()->get('wcf.acp.article.publicationStatus.unpublished')
);
}
if ($row->publicationStatus === Article::DELAYED_PUBLICATION) {
$dateTime = \IntlDateFormatter::formatObject(
WCF::getUser()->getLocalDate($row->publicationDate),
[
\IntlDateFormatter::LONG,
\IntlDateFormatter::SHORT,
],
WCF::getLanguage()->getLocale()
);
if ($badges !== '') {
$badges .= ' ';
}
$badges .= \sprintf(
'<span class="badge" title="%s">%s</span>',
$dateTime,
WCF::getLanguage()->get('wcf.acp.article.publicationStatus.delayed')
);
}
// @phpstan-ignore property.notFound
$articleTitle = StringUtil::encodeHTML($row->title);
return \sprintf('%s %s%s', $badges, $articleTitle, $labels);
}
},
])
->titleColumn(),
GridViewColumn::for('userID')
->label('wcf.user.username')
->renderer(new UserLinkColumnRenderer(UserEditForm::class))
->sortable(sortByDatabaseColumn: 'username')
->filter(UserFilter::class),
GridViewColumn::for('categoryID')
->label('wcf.global.category')
->sortable()
->renderer(new CategoryColumnRenderer())
->filter(new CategoryFilter(
(new CategoryNodeTree('com.woltlab.wcf.article.category'))->getIterator(),
'categoryID',
'wcf.global.category'
)),
GridViewColumn::for('views')
->label('wcf.acp.article.views')
->renderer(new NumberColumnRenderer())
->sortable(),
GridViewColumn::for('time')
->label('wcf.acp.sessionLog.time')
->sortable()
->renderer(new TimeColumnRenderer())
->filter(TimeFilter::class),
]);
$this->addAvailableFilters([
new class('content', 'wcf.acp.article.content') extends TextFilter {
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $value): void
{
$list->getConditionBuilder()->add(
"article.articleID IN (
SELECT articleID
FROM wcf1_article_content
WHERE content LIKE ?
)",
['%' . WCF::getDB()->escapeLikeValue($value) . '%']
);
}
},
new MultipleSelectFilter(
[
0 => 'wcf.acp.article.publicationStatus.unpublished',
1 => 'wcf.acp.article.publicationStatus.published',
2 => 'wcf.acp.article.publicationStatus.delayed',
],
'publicationStatus',
'wcf.acp.article.publicationStatus'
),
new BooleanFilter('isDeleted', 'wcf.acp.article.isDeleted'),
]);
$provider = new ArticleInteractions();
$provider->addInteractions([
new Divider(),
new EditInteraction(ArticleEditForm::class)
]);
$this->setInteractionProvider($provider);
$this->setBulkInteractionProvider(new ArticleBulkInteractions());
$this->setDefaultSortField('time');
$this->setDefaultSortOrder('DESC');
$this->addRowLink(new GridViewRowLink(ArticleEditForm::class));
}
#[\Override]
public function isAccessible(): bool
{
return \MODULE_ARTICLE
&& (
WCF::getSession()->getPermission('admin.content.article.canManageArticle')
|| WCF::getSession()->getPermission('admin.content.article.canManageOwnArticles')
|| WCF::getSession()->getPermission('admin.content.article.canContributeArticle')
);
}
#[\Override]
protected function createObjectList(): AccessibleArticleList
{
$list = new AccessibleArticleList();
$join = ' LEFT JOIN wcf1_article_content articleContent
ON (
articleContent.articleID = article.articleID
AND (
articleContent.languageID IS NULL
OR articleContent.languageID = ' . WCF::getLanguage()->languageID . '
)
)';
$list->sqlJoins .= $join;
$list->sqlConditionJoins .= $join;
if (!empty($list->sqlSelects)) {
$list->sqlSelects .= ', ';
}
$list->sqlSelects .= "articleContent.title";
return $list;
}
#[\Override]
protected function getInitializedEvent(): ArticleGridViewInitialized
{
return new ArticleGridViewInitialized($this);
}
}