Skip to content

Commit

Permalink
Badges: Bugfixes after testing (#8786)
Browse files Browse the repository at this point in the history
* Fixed multi action delete

* Fixed permissions

* Code style fixes

* Fixed comments
  • Loading branch information
gvollbach committed Jan 6, 2025
1 parent 92dc8d4 commit 036086a
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 100 deletions.
19 changes: 19 additions & 0 deletions components/ILIAS/Badge/classes/class.ilBadgeGUIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
class ilBadgeGUIRequest
{
private const ACTION_PARAMETER_TOKEN = 'tid_id';
private const ACTION_PARAMETER_TOKEN_ID = 'id';

protected HTTP\Services $http;
protected Refinery\Factory $refinery;
Expand Down Expand Up @@ -186,6 +187,24 @@ public function getMultiActionBadgeIdsFromUrl(): array
return $tmpl_ids;
}

/**
* @return list<string>
*/
public function getMultiActionBadgeIdsFromPost(): array
{
$tmpl_ids = [];
$query = $this->http->wrapper()->post();
if ($query->has(self::ACTION_PARAMETER_TOKEN_ID)) {
$tmpl_ids = $query->retrieve(
self::ACTION_PARAMETER_TOKEN_ID,
$this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string())
);
}

return $tmpl_ids;
}


public function getBadgeId(): int
{
return $this->int("bid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);
Expand All @@ -35,7 +34,6 @@
use Generator;
use ILIAS\UI\Component\Table\DataRetrieval;
use ILIAS\UI\URLBuilderToken;
use ILIAS\DI\Container;
use ILIAS\Filesystem\Stream\Streams;

class ilBadgeImageTemplateTableGUI
Expand All @@ -48,7 +46,7 @@ class ilBadgeImageTemplateTableGUI
private readonly ilLanguage $lng;
private readonly ilGlobalTemplateInterface $tpl;

public function __construct()
public function __construct(protected bool $has_write = false)
{
global $DIC;
$this->lng = $DIC->language();
Expand Down Expand Up @@ -191,19 +189,24 @@ private function getActions(
URLBuilderToken $row_id_token
): array {
$f = $this->factory;
return [
'badge_image_template_edit' => $f->table()->action()->single(
$this->lng->txt('edit'),
$url_builder->withParameter($action_parameter_token, 'badge_image_template_editImageTemplate'),
$row_id_token
),
'badge_image_template_delete' =>
$f->table()->action()->standard(
$this->lng->txt('delete'),
$url_builder->withParameter($action_parameter_token, 'badge_image_template_delete'),
if ($this->has_write) {
return [
'badge_image_template_edit' => $f->table()->action()->single(
$this->lng->txt('edit'),
$url_builder->withParameter($action_parameter_token, 'badge_image_template_editImageTemplate'),
$row_id_token
)
];
),
'badge_image_template_delete' =>
$f->table()->action()->standard(
$this->lng->txt('delete'),
$url_builder->withParameter($action_parameter_token, 'badge_image_template_delete'),
$row_id_token
)
];
} else {
return [];
}

}

public function renderTable(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

use ILIAS\Badge\ilBadgeImage;
Expand Down Expand Up @@ -292,7 +291,7 @@ protected function listBadges(): void
}
}

$table = new ilBadgeTableGUI($this->parent_obj_id, $this->parent_obj_type);
$table = new ilBadgeTableGUI($this->parent_obj_id, $this->parent_obj_type, $this->hasWrite());
$table->renderTable();
}

Expand Down Expand Up @@ -658,8 +657,6 @@ protected function deleteBadges(): void
$this->tpl->setOnScreenMessage('failure', $lng->txt('badge_select_one'), true);
}



$ilCtrl->redirect($this, 'listBadges');
}

Expand Down
75 changes: 39 additions & 36 deletions components/ILIAS/Badge/classes/class.ilBadgeTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);
Expand All @@ -34,7 +33,6 @@
use Generator;
use ILIAS\UI\Component\Table\DataRetrieval;
use ILIAS\UI\URLBuilderToken;
use ILIAS\DI\Container;
use ilBadge;
use ilBadgeAuto;
use ILIAS\Filesystem\Stream\Streams;
Expand All @@ -52,7 +50,7 @@ class ilBadgeTableGUI
private readonly ilLanguage $lng;
private readonly ilGlobalTemplateInterface $tpl;

public function __construct(int $parent_obj_id, string $parent_obj_type)
public function __construct(int $parent_obj_id, string $parent_obj_type, protected bool $has_write = false)
{
global $DIC;

Expand Down Expand Up @@ -193,10 +191,10 @@ public function getRows(
foreach ($records as $record) {
$row_id = (string) $record['id'];
yield $row_builder->buildDataRow($row_id, $record)
->withDisabledAction(
'award_revoke_badge',
!$record['manual'] || !$record['active']
);
->withDisabledAction(
'award_revoke_badge',
!$record['manual'] || !$record['active']
);
}
}

Expand Down Expand Up @@ -269,37 +267,42 @@ private function getActions(
): array {
$f = $this->factory;

return [
'badge_table_activate' =>
$f->table()->action()->multi(
$this->lng->txt('activate'),
$url_builder->withParameter($action_parameter_token, 'badge_table_activate'),
if ($this->has_write) {
return [
'badge_table_activate' =>
$f->table()->action()->multi(
$this->lng->txt('activate'),
$url_builder->withParameter($action_parameter_token, 'badge_table_activate'),
$row_id_token
),
'badge_table_deactivate' =>
$f->table()->action()->multi(
$this->lng->txt('deactivate'),
$url_builder->withParameter($action_parameter_token, 'badge_table_deactivate'),
$row_id_token
),
'badge_table_edit' => $f->table()->action()->single(
$this->lng->txt('edit'),
$url_builder->withParameter($action_parameter_token, 'badge_table_edit'),
$row_id_token
),
'badge_table_deactivate' =>
$f->table()->action()->multi(
$this->lng->txt('deactivate'),
$url_builder->withParameter($action_parameter_token, 'badge_table_deactivate'),
$row_id_token
),
'badge_table_edit' => $f->table()->action()->single(
$this->lng->txt('edit'),
$url_builder->withParameter($action_parameter_token, 'badge_table_edit'),
$row_id_token
),
'badge_table_delete' =>
$f->table()->action()->standard(
$this->lng->txt('delete'),
$url_builder->withParameter($action_parameter_token, 'badge_table_delete'),
$row_id_token
),
'award_revoke_badge' =>
$f->table()->action()->single(
$this->lng->txt('badge_award_revoke'),
$url_builder->withParameter($action_parameter_token, 'award_revoke_badge'),
$row_id_token
)
];
'badge_table_delete' =>
$f->table()->action()->standard(
$this->lng->txt('delete'),
$url_builder->withParameter($action_parameter_token, 'badge_table_delete'),
$row_id_token
),
'award_revoke_badge' =>
$f->table()->action()->single(
$this->lng->txt('badge_award_revoke'),
$url_builder->withParameter($action_parameter_token, 'award_revoke_badge'),
$row_id_token
)
];
} else {
return [];
}

}

public function renderTable(): void
Expand Down
31 changes: 18 additions & 13 deletions components/ILIAS/Badge/classes/class.ilBadgeTypesTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ilBadgeTypesTableGUI
private readonly ilLanguage $lng;
private readonly ilGlobalTemplateInterface $tpl;

public function __construct()
public function __construct(protected bool $a_has_write = false)
{
global $DIC;

Expand Down Expand Up @@ -170,19 +170,24 @@ private function getActions(
URLBuilderToken $row_id_token
): array {
$f = $this->factory;
return [
'badge_type_activate' => $f->table()->action()->multi(
$this->lng->txt('activate'),
$url_builder->withParameter($action_parameter_token, 'badge_type_activate'),
$row_id_token
),
'badge_type_deactivate' =>
$f->table()->action()->multi(
$this->lng->txt('deactivate'),
$url_builder->withParameter($action_parameter_token, 'badge_type_deactivate'),
if ($this->a_has_write) {
return [
'badge_type_activate' => $f->table()->action()->multi(
$this->lng->txt('activate'),
$url_builder->withParameter($action_parameter_token, 'badge_type_activate'),
$row_id_token
)
];
),
'badge_type_deactivate' =>
$f->table()->action()->multi(
$this->lng->txt('deactivate'),
$url_builder->withParameter($action_parameter_token, 'badge_type_deactivate'),
$row_id_token
)
];
} else {
return [];
}

}

public function renderTable(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public function executeCommand(): void
} elseif ($table_action === 'badge_image_template_delete') {
$this->confirmDeleteImageTemplates();
$render_default = false;
} elseif ($table_action === 'obj_badge_delete') {
$this->confirmDeleteObjectBadges();
$render_default = false;
}

if ($render_default) {
Expand Down Expand Up @@ -257,7 +260,7 @@ protected function listTypes(): void
$this->assertActive();
$this->tabs_gui->setTabActive('types');

$tpl = new ilBadgeTypesTableGUI();
$tpl = new ilBadgeTypesTableGUI($this->access->checkAccess("write", "", $this->object->getRefId()));
$tpl->renderTable();
}

Expand Down Expand Up @@ -341,7 +344,7 @@ protected function listImageTemplates(): void
);
}

$template_table = new ilBadgeImageTemplateTableGUI();
$template_table = new ilBadgeImageTemplateTableGUI($this->access->checkAccess("write", "", $this->object->getRefId()));
$template_table->renderTable();
}

Expand Down Expand Up @@ -651,7 +654,7 @@ protected function listObjectBadges(): void
$this->assertActive();
$this->tabs_gui->setTabActive('obj_badges');

$tbl = new ilObjectBadgeTableGUI($this);
$tbl = new ilObjectBadgeTableGUI($this, $this->access->checkAccess("write", "", $this->object->getRefId()));
$tbl->renderTable();
}

Expand Down Expand Up @@ -720,7 +723,7 @@ protected function confirmDeleteObjectBadges(): void
$tpl = $this->tpl;
$ilTabs = $this->tabs;

$badge_ids = $this->getObjectBadgesFromMultiAction();
$badge_ids = $this->badge_request->getMultiActionBadgeIdsFromUrl();

$ilTabs->clearTargets();
$ilTabs->setBackTarget(
Expand All @@ -734,11 +737,21 @@ protected function confirmDeleteObjectBadges(): void
$confirmation_gui->setCancel($lng->txt('cancel'), 'listObjectBadges');
$confirmation_gui->setConfirm($lng->txt('delete'), 'deleteObjectBadges');

if ($badge_ids === ['ALL_OBJECTS']) {
$badge_ids = [];
$filter = [
'type' => '',
'title' => '',
'object' => ''
];
foreach (ilBadge::getObjectInstances($filter) as $badge_item) {
$badge_ids[] = $badge_item['id'];
}
}
foreach ($badge_ids as $badge_id) {
$badge = new ilBadge($badge_id);
$parent = $badge->getParentMeta();

// :TODO: container presentation
$container = '(' . $parent['type'] . '/' .
$parent['id'] . ') ' .
$parent['title'];
Expand All @@ -763,7 +776,7 @@ protected function deleteObjectBadges(): void
$ilCtrl = $this->ctrl;
$lng = $this->lng;

$badge_ids = $this->getObjectBadgesFromMultiAction();
$badge_ids = $this->badge_request->getMultiActionBadgeIdsFromPost();

foreach ($badge_ids as $badge_id) {
$badge = new ilBadge($badge_id);
Expand Down
Loading

0 comments on commit 036086a

Please sign in to comment.