Skip to content
Snippets Groups Projects
Commit 374e1180 authored by Marcus Eibrink-Lunzenauer's avatar Marcus Eibrink-Lunzenauer
Browse files

Apply Jan's code review suggestions

parent 035288dc
No related branches found
No related tags found
No related merge requests found
Pipeline #28349 failed
......@@ -37,23 +37,24 @@ class Admin_CoursewareController extends AuthenticatedController
$this->blockTypes = BlockType::getBlockTypes();
usort($this->blockTypes, function ($blockTypeA, $blockTypeB) {
return $blockTypeA::getTitle() <=> $blockTypeB::getTitle();
});
usort(
$this->blockTypes,
fn ($blockTypeA, $blockTypeB) => $blockTypeA::getTitle() <=> $blockTypeB::getTitle()
);
}
public function bulk_block_types_action()
{
CSRFProtection::verifyUnsafeRequest();
switch (Request::quoted('bulk_action')) {
switch (Request::option('bulk_action')) {
case 'activate':
return $this->activate_block_types_action();
case 'deactivate':
return $this->deactivate_block_types_action();
}
PageLayout::postInfo(_("Keine Aktion ausgewählt."));
PageLayout::postInfo(_('Keine Aktion ausgewählt.'));
$this->redirect($this->action_url('block_types'));
}
......@@ -65,9 +66,10 @@ class Admin_CoursewareController extends AuthenticatedController
$requestedBlockTypes = $this->validateBlockTypes();
$changed = array_sum(
array_map(function ($blockType) {
return $blockType::activate() ? 1 : 0;
}, $requestedBlockTypes)
array_map(
fn ($blockType) => $blockType::activate() ? 1 : 0,
$requestedBlockTypes)
)
);
PageLayout::postSuccess(
......@@ -87,9 +89,10 @@ class Admin_CoursewareController extends AuthenticatedController
$requestedBlockTypes = $this->validateBlockTypes();
$changed = array_sum(
array_map(function ($blockType) {
return $blockType::deactivate() ? 1 : 0;
}, $requestedBlockTypes)
array_map(
fn ($blockType) => $blockType::deactivate() ? 1 : 0,
$requestedBlockTypes
)
);
PageLayout::postSuccess(
......@@ -105,8 +108,8 @@ class Admin_CoursewareController extends AuthenticatedController
{
$requestedBlockTypes = Request::getArray('block_types');
$diff = array_diff($requestedBlockTypes, BlockType::getBlockTypes());
if (count($diff)) {
throw new Trails_Exception(400);
if (count($diff) > 0) {
throw new Trails\Exception(400);
}
return $requestedBlockTypes;
......@@ -123,9 +126,10 @@ class Admin_CoursewareController extends AuthenticatedController
$this->containerTypes = ContainerType::getContainerTypes();
usort($this->containerTypes, function ($containerTypeA, $containerTypeB) {
return $containerTypeA::getTitle() <=> $containerTypeB::getTitle();
});
usort(
$this->containerTypes,
fn ($containerTypeA, $containerTypeB) => $containerTypeA::getTitle() <=> $containerTypeB::getTitle(),
);
}
public function bulk_container_types_action()
......@@ -139,7 +143,7 @@ class Admin_CoursewareController extends AuthenticatedController
return $this->deactivate_container_types_action();
}
PageLayout::postInfo(_("Keine Aktion ausgewählt."));
PageLayout::postInfo(_('Keine Aktion ausgewählt.'));
$this->redirect($this->action_url('container_types'));
}
......@@ -151,9 +155,10 @@ class Admin_CoursewareController extends AuthenticatedController
$requestedContainerTypes = $this->validateContainerTypes();
$changed = array_sum(
array_map(function ($containerType) {
return $containerType::activate() ? 1 : 0;
}, $requestedContainerTypes)
array_map(
fn ($containerType) => $containerType::activate() ? 1 : 0,
$requestedContainerTypes
)
);
PageLayout::postSuccess(
......@@ -173,9 +178,10 @@ class Admin_CoursewareController extends AuthenticatedController
$requestedContainerTypes = $this->validateContainerTypes();
$changed = array_sum(
array_map(function ($containerType) {
return $containerType::deactivate() ? 1 : 0;
}, $requestedContainerTypes)
array_map(
fn ($containerType) => $containerType::deactivate() ? 1 : 0,
$requestedContainerTypes
)
);
PageLayout::postSuccess(
......@@ -192,7 +198,7 @@ class Admin_CoursewareController extends AuthenticatedController
$requestedContainerTypes = Request::getArray('container_types');
$diff = array_diff($requestedContainerTypes, ContainerType::getContainerTypes());
if (count($diff)) {
throw new Trails_Exception(400);
throw new Trails\Exception(400);
}
return $requestedContainerTypes;
......
......@@ -29,12 +29,12 @@
</tr>
</thead>
<tbody>
<? foreach ($blockTypes as $blockType) { ?>
<? foreach ($blockTypes as $blockType): ?>
<? $isActivated = $blockType::isActivated(); ?>
<tr class="<?= $isActivated ? 'activated' : '' ?>">
<td>
<label>
<span class="sr-only"><? printf(_('Blocktyp "%s" auswählen'), $blockType::getTitle()) ?></span>
<span class="sr-only"><? printf(_('Blocktyp "%s" auswählen'), htmlReady($blockType::getTitle())) ?></span>
<input type="checkbox" name="block_types[]" value="<?= htmlReady($blockType) ?>" />
</label>
</td>
......@@ -57,21 +57,32 @@
->setContext(sprintf(_('Courseware-Blocktyp "%s"'), $blockType::getTitle()))
->setRenderingMode(ActionMenu::RENDERING_MODE_MENU)
->condition($isActivated)
->addButton('deactivate_block_type', _('Deaktivieren'), Icon::create('remove'), [
'formaction' => URLHelper::getURL(
'dispatch.php/admin/courseware/deactivate_block_types',
['block_types' => [$blockType]]
),
])
->addButton(
'deactivate_block_type',
_('Deaktivieren'),
Icon::create('remove'),
[
'formaction' => URLHelper::getURL(
'dispatch.php/admin/courseware/deactivate_block_types',
['block_types' => [$blockType]]
),
]
)
->condition(!$isActivated)
->addButton('activate_block_type', _('Aktivieren'), Icon::create('add'), [
'formaction' => URLHelper::getURL('dispatch.php/admin/courseware/activate_block_types', [
'block_types' => [$blockType],
]),
]) ?>
->addButton(
'activate_block_type',
_('Aktivieren'),
Icon::create('add'),
[
'formaction' => URLHelper::getURL(
'dispatch.php/admin/courseware/activate_block_types',
['block_types' => [$blockType]]
),
]
) ?>
</td>
</tr>
<? } ?>
<? endforeach; ?>
</tbody>
</table>
</form>
......@@ -29,12 +29,12 @@
</tr>
</thead>
<tbody>
<? foreach ($containerTypes as $containerType) { ?>
<? foreach ($containerTypes as $containerType): ?>
<? $isActivated = $containerType::isActivated(); ?>
<tr class="<?= $isActivated ? 'activated' : '' ?>">
<td>
<label>
<span class="sr-only"><? printf(_('Containertyp "%s" auswählen'), $containerType::getTitle()) ?></span>
<span class="sr-only"><? printf(_('Containertyp "%s" auswählen'), htmlReady($containerType::getTitle())) ?></span>
<input type="checkbox" name="container_types[]" value="<?= htmlReady($containerType) ?>" />
</label>
</td>
......@@ -57,21 +57,32 @@
->setContext(sprintf(_('Courseware-Containertyp "%s"'), $containerType::getTitle()))
->setRenderingMode(ActionMenu::RENDERING_MODE_MENU)
->condition($isActivated)
->addButton('deactivate_container_type', _('Deaktivieren'), Icon::create('remove'), [
'formaction' => URLHelper::getURL(
'dispatch.php/admin/courseware/deactivate_container_types',
['container_types' => [$containerType]]
),
])
->addButton(
'deactivate_container_type',
_('Deaktivieren'),
Icon::create('remove'),
[
'formaction' => URLHelper::getURL(
'dispatch.php/admin/courseware/deactivate_container_types',
['container_types' => [$containerType]]
),
]
)
->condition(!$isActivated)
->addButton('activate_container_type', _('Aktivieren'), Icon::create('add'), [
'formaction' => URLHelper::getURL('dispatch.php/admin/courseware/activate_container_types', [
'container_types' => [$containerType],
]),
]) ?>
->addButton(
'activate_container_type',
_('Aktivieren'),
Icon::create('add'),
[
'formaction' => URLHelper::getURL(
'dispatch.php/admin/courseware/activate_container_types',
['container_types' => [$containerType]]
),
]
) ?>
</td>
</tr>
<? } ?>
<? endforeach; ?>
</tbody>
</table>
</form>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment