-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathBoxGridView.class.php
More file actions
172 lines (162 loc) · 6.11 KB
/
BoxGridView.class.php
File metadata and controls
172 lines (162 loc) · 6.11 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
<?php
namespace wcf\system\gridView\admin;
use wcf\acp\form\BoxEditForm;
use wcf\data\box\Box;
use wcf\data\box\BoxList;
use wcf\data\DatabaseObject;
use wcf\data\DatabaseObjectList;
use wcf\event\gridView\admin\BoxGridViewInitialized;
use wcf\system\gridView\AbstractGridView;
use wcf\system\gridView\GridViewColumn;
use wcf\system\gridView\GridViewRowLink;
use wcf\system\gridView\renderer\NumberColumnRenderer;
use wcf\system\gridView\renderer\ObjectIdColumnRenderer;
use wcf\system\gridView\renderer\PhraseColumnRenderer;
use wcf\system\interaction\admin\BoxInteractions;
use wcf\system\interaction\Divider;
use wcf\system\interaction\EditInteraction;
use wcf\system\interaction\ToggleInteraction;
use wcf\system\view\filter\BooleanFilter;
use wcf\system\view\filter\IntegerFilter;
use wcf\system\view\filter\SelectFilter;
use wcf\system\view\filter\TextFilter;
use wcf\system\WCF;
/**
* Grid view for the list of boxes.
*
* @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<Box, BoxList>
*/
final class BoxGridView extends AbstractGridView
{
public function __construct()
{
$this->addColumns([
GridViewColumn::for('boxID')
->label('wcf.global.objectID')
->renderer(new ObjectIdColumnRenderer())
->sortable(),
GridViewColumn::for('name')
->label('wcf.global.name')
->titleColumn()
->filter(TextFilter::class)
->sortable(),
GridViewColumn::for('boxType')
->label('wcf.acp.box.type')
->renderer(new class extends PhraseColumnRenderer {
#[\Override]
public function render(mixed $value, DatabaseObject $row): string
{
return parent::render('wcf.acp.box.type.' . $value, $row);
}
})
->filter(
new SelectFilter(
\array_combine(
Box::$availableBoxTypes,
\array_map(
static fn(string $type) => 'wcf.acp.box.type.' . $type,
Box::$availableBoxTypes
)
),
'boxType',
'wcf.acp.box.type'
)
)
->sortable(),
GridViewColumn::for('position')
->label('wcf.acp.box.position')
->renderer(new class extends PhraseColumnRenderer {
#[\Override]
public function render(mixed $value, DatabaseObject $row): string
{
return parent::render('wcf.acp.box.position.' . $value, $row);
}
})
->filter(
new SelectFilter(
\array_combine(
Box::$availablePositions,
\array_map(
static fn(string $position) => 'wcf.acp.box.position.' . $position,
Box::$availablePositions
)
),
'position',
'wcf.acp.box.position'
)
)
->sortable(),
GridViewColumn::for('showOrder')
->label('wcf.global.showOrder')
->renderer(new NumberColumnRenderer())
->filter(IntegerFilter::class)
->sortable(),
]);
$this->addAvailableFilters([
new class('title', 'wcf.global.title') extends TextFilter {
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $value): void
{
$list->getConditionBuilder()->add(
"box.boxID IN (
SELECT boxID
FROM wcf1_box_content
WHERE title LIKE ?
)",
['%' . WCF::getDB()->escapeLikeValue($value) . '%']
);
}
},
new class('content', 'wcf.acp.box.content') extends TextFilter {
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $value): void
{
$list->getConditionBuilder()->add(
"box.boxID IN (
SELECT boxID
FROM wcf1_box_content
WHERE content LIKE ?
)",
['%' . WCF::getDB()->escapeLikeValue($value) . '%']
);
}
},
new BooleanFilter('originIsNotSystem', 'wcf.acp.box.originIsNotSystem', 'originIsSystem', true),
]);
$provider = new BoxInteractions();
$provider->addInteractions([
new Divider(),
new EditInteraction(BoxEditForm::class)
]);
$this->setInteractionProvider($provider);
$this->addQuickInteraction(new ToggleInteraction(
'enable',
'core/boxes/%s/enable',
'core/boxes/%s/disable'
));
$this->setDefaultSortField('name');
$this->addRowLink(new GridViewRowLink(BoxEditForm::class));
}
#[\Override]
public function isAccessible(): bool
{
return WCF::getSession()->getPermission('admin.content.cms.canManageBox');
}
#[\Override]
protected function createObjectList(): BoxList
{
$boxList = new BoxList();
$boxList->getConditionBuilder()->add('box.boxType <> ?', ['menu']);
return $boxList;
}
#[\Override]
protected function getInitializedEvent(): BoxGridViewInitialized
{
return new BoxGridViewInitialized($this);
}
}