-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathBoxGridView.class.php
More file actions
155 lines (143 loc) · 5.39 KB
/
BoxGridView.class.php
File metadata and controls
155 lines (143 loc) · 5.39 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
<?php
namespace wcf\system\gridView\admin;
use wcf\acp\form\BoxEditForm;
use wcf\data\box\Box;
use wcf\data\box\BoxList;
use wcf\data\DatabaseObjectList;
use wcf\event\gridView\admin\BoxGridViewInitialized;
use wcf\system\gridView\AbstractGridView;
use wcf\system\gridView\filter\BooleanFilter;
use wcf\system\gridView\filter\NumericFilter;
use wcf\system\gridView\filter\SelectFilter;
use wcf\system\gridView\filter\TextFilter;
use wcf\system\gridView\GridViewColumn;
use wcf\system\gridView\GridViewRowLink;
use wcf\system\gridView\renderer\ObjectIdColumnRenderer;
use wcf\system\interaction\admin\BoxInteractions;
use wcf\system\interaction\Divider;
use wcf\system\interaction\EditInteraction;
use wcf\system\interaction\ToggleInteraction;
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(new TextFilter())
->sortable(),
GridViewColumn::for('title')
->label('wcf.global.title')
->filter($this->getBoxContentFilter('title'))
->hidden(),
GridViewColumn::for('content')
->label('wcf.acp.box.content')
->filter($this->getBoxContentFilter('content'))
->hidden(),
GridViewColumn::for('boxType')
->label('wcf.acp.box.type')
->filter(
new SelectFilter(
\array_combine(
Box::$availableBoxTypes,
\array_map(
static fn(string $type) => 'wcf.acp.box.type.' . $type,
Box::$availableBoxTypes
)
)
)
)
->sortable(),
GridViewColumn::for('position')
->label('wcf.acp.box.position')
->filter(
new SelectFilter(
\array_combine(
Box::$availablePositions,
\array_map(
static fn(string $position) => 'wcf.acp.box.position.' . $position,
Box::$availablePositions
)
)
)
)
->sortable(),
GridViewColumn::for('showOrder')
->label('wcf.global.showOrder')
->filter(new NumericFilter())
->sortable(),
GridViewColumn::for('originIsSystem')
->label('wcf.acp.box.originIsNotSystem')
->filter(
new class extends BooleanFilter {
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $id, string $value): void
{
$columnName = $this->getDatabaseColumnName($list, $id);
$list->getConditionBuilder()->add("{$columnName} = ?", [0]);
}
}
)
->hidden(),
]);
$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));
}
private function getBoxContentFilter(string $databaseColumn): TextFilter
{
return new class($databaseColumn) extends TextFilter {
#[\Override]
public function applyFilter(DatabaseObjectList $list, string $id, string $value): void
{
$list->getConditionBuilder()->add(
"box.boxID IN (
SELECT boxID
FROM wcf1_box_content
WHERE {$this->databaseColumn} LIKE ?
)",
['%' . WCF::getDB()->escapeLikeValue($value) . '%']
);
}
};
}
#[\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);
}
}