"lib/git@gitlab.studip.de:tleilax/studip.git" did not exist on "9b6fd20728aef64a3ce1bbf38b13948d3ac1994a"
Newer
Older
use Courseware\BlockTypes\BlockType;
use Courseware\ContainerTypes\ContainerType;
/**
* @SuppressWarnings(PHPMD.CamelCaseClassName)
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
* @SuppressWarnings(PHPMD.StaticAccess)
*/
class Admin_CoursewareController extends AuthenticatedController
{
/**
* @SuppressWarnings(PHPMD.Superglobals)
*/
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
$GLOBALS['perm']->check('root');
PageLayout::setTitle(_('Coursewareverwaltung'));
Navigation::activateItem('/admin/locations/courseware');
}
public function index_action()
{
$this->setSidebar();
}
public function block_types_action()
{
PageLayout::addStyleSheet('courseware.css');
$views = Sidebar::get()->addWidget(new ViewsWidget());
$views->addLink(_('Templates'), $this->indexURL());
$views->addLink(_('Block-Typen'), $this->block_typesURL())->setActive(true);
$views->addLink(_('Container-Typen'), $this->container_typesURL());
$this->blockTypes = BlockType::getBlockTypes();
usort($this->blockTypes, function ($blockTypeA, $blockTypeB) {
return $blockTypeA::getTitle() <=> $blockTypeB::getTitle();
});
}
public function bulk_block_types_action()
{
CSRFProtection::verifyUnsafeRequest();
switch (Request::quoted('bulk_action')) {
case 'activate':
return $this->activate_block_types_action();
case 'deactivate':
return $this->deactivate_block_types_action();
}
PageLayout::postInfo(_("Keine Aktion ausgewählt."));
$this->redirect($this->action_url('block_types'));
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
}
/**
*/
public function activate_block_types_action()
{
CSRFProtection::verifyUnsafeRequest();
$requestedBlockTypes = $this->validateBlockTypes();
$changed = array_sum(
array_map(function ($blockType) {
return $blockType::activate() ? 1 : 0;
}, $requestedBlockTypes)
);
PageLayout::postSuccess(
sprintf(
ngettext('Block-Typ erfolgreich aktiviert.', '%d Block-Typen erfolgreich aktiviert.', $changed),
$changed
)
);
$this->redirect($this->action_url('block_types'));
}
/**
*/
public function deactivate_block_types_action()
{
CSRFProtection::verifyUnsafeRequest();
$requestedBlockTypes = $this->validateBlockTypes();
$changed = array_sum(
array_map(function ($blockType) {
return $blockType::deactivate() ? 1 : 0;
}, $requestedBlockTypes)
);
PageLayout::postSuccess(
sprintf(
ngettext('Block-Typ erfolgreich deaktiviert.', '%d Block-Typen erfolgreich deaktiviert.', $changed),
$changed
)
);
$this->redirect($this->action_url('block_types'));
}
private function validateBlockTypes(): iterable
{
$requestedBlockTypes = Request::getArray('block_types');
$diff = array_diff($requestedBlockTypes, BlockType::getBlockTypes());
if (count($diff)) {
throw new Trails_Exception(400);
}
return $requestedBlockTypes;
}
public function container_types_action()
{
PageLayout::addStyleSheet('courseware.css');
$views = Sidebar::get()->addWidget(new ViewsWidget());
$views->addLink(_('Templates'), $this->indexURL());
$views->addLink(_('Block-Typen'), $this->block_typesURL());
$views->addLink(_('Container-Typen'), $this->container_typesURL())->setActive(true);
$this->containerTypes = ContainerType::getContainerTypes();
usort($this->containerTypes, function ($containerTypeA, $containerTypeB) {
return $containerTypeA::getTitle() <=> $containerTypeB::getTitle();
});
}
public function bulk_container_types_action()
{
CSRFProtection::verifyUnsafeRequest();
switch (Request::quoted('bulk_action')) {
case 'activate':
return $this->activate_container_types_action();
case 'deactivate':
return $this->deactivate_container_types_action();
}
PageLayout::postInfo(_("Keine Aktion ausgewählt."));
$this->redirect($this->action_url('container_types'));
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
}
/**
*/
public function activate_container_types_action()
{
CSRFProtection::verifyUnsafeRequest();
$requestedContainerTypes = $this->validateContainerTypes();
$changed = array_sum(
array_map(function ($containerType) {
return $containerType::activate() ? 1 : 0;
}, $requestedContainerTypes)
);
PageLayout::postSuccess(
sprintf(
ngettext('Container-Typ erfolgreich aktiviert.', '%d Container-Typen erfolgreich aktiviert.', $changed),
$changed
)
);
$this->redirect($this->action_url('container_types'));
}
/**
*/
public function deactivate_container_types_action()
{
CSRFProtection::verifyUnsafeRequest();
$requestedContainerTypes = $this->validateContainerTypes();
$changed = array_sum(
array_map(function ($containerType) {
return $containerType::deactivate() ? 1 : 0;
}, $requestedContainerTypes)
);
PageLayout::postSuccess(
sprintf(
ngettext('Container-Typ erfolgreich deaktiviert.', '%d Container-Typen erfolgreich deaktiviert.', $changed),
$changed
)
);
$this->redirect($this->action_url('container_types'));
}
private function validateContainerTypes(): iterable
{
$requestedContainerTypes = Request::getArray('container_types');
$diff = array_diff($requestedContainerTypes, ContainerType::getContainerTypes());
if (count($diff)) {
throw new Trails_Exception(400);
}
return $requestedContainerTypes;
}
private function setSidebar()
{
$sidebar = Sidebar::Get();
$views = new TemplateWidget(
_('Ansichten'),
$this->get_template_factory()->open('admin/courseware/admin_view_widget')
);
$sidebar->addWidget($views)->addLayoutCSSClass('courseware-admin-view-widget');
$views = new TemplateWidget(
_('Aktionen'),
$this->get_template_factory()->open('admin/courseware/admin_action_widget')
);
$sidebar->addWidget($views)->addLayoutCSSClass('courseware-admin-action-widget');
}