Skip to content

Commit

Permalink
Remove legacy table from DC Tables
Browse files Browse the repository at this point in the history
  • Loading branch information
iszmais committed Jul 1, 2024
1 parent 8817428 commit c9854a7
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,15 @@ public function save(string $a_mode = "create"): void
$delete_by_owner = ($this->form->getInput('delete_perm_mode') == 'own');
$this->table->setDeleteByOwner($delete_by_owner);
}
$this->table->setViewOwnRecordsPerm((bool)$this->form->getInput('view_own_records_perm'));
$this->table->setExportEnabled((bool)$this->form->getInput("export_enabled"));
$this->table->setImportEnabled((bool)$this->form->getInput("import_enabled"));
$this->table->setViewOwnRecordsPerm((bool) $this->form->getInput('view_own_records_perm'));
$this->table->setExportEnabled((bool) $this->form->getInput("export_enabled"));
$this->table->setImportEnabled((bool) $this->form->getInput("import_enabled"));
$this->table->setDefaultSortField($this->form->getInput("default_sort_field"));
$this->table->setDefaultSortFieldOrder($this->form->getInput("default_sort_field_order"));
$this->table->setLimited((bool)$this->form->getInput("limited"));
$this->table->setLimited((bool) $this->form->getInput("limited"));
$this->table->setDescription($this->form->getInput('description'));
$this->table->setLimitStart((string)$this->form->getInput("limit_start"));
$this->table->setLimitEnd((string)$this->form->getInput("limit_end"));
$this->table->setLimitStart((string) $this->form->getInput("limit_start"));
$this->table->setLimitEnd((string) $this->form->getInput("limit_end"));
if ($a_mode == "update") {
$this->table->doUpdate();
$this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_msg_table_edited"), true);
Expand Down Expand Up @@ -408,6 +408,50 @@ public function delete(): void
$this->ctrl->redirectByClass("ildcltablelistgui", "listtables");
}

public function enableVisible(): void
{
$this->table->setIsVisible(true);
$this->table->doUpdate();
$this->ctrl->redirectByClass(ilDclTableListGUI::class, 'listTables');
}

public function disableVisible(): void
{
$this->table->setIsVisible(false);
$this->table->doUpdate();
$this->ctrl->redirectByClass(ilDclTableListGUI::class, 'listTables');
}

public function enableComments(): void
{
$this->table->setPublicCommentsEnabled(true);
$this->table->doUpdate();
$this->ctrl->redirectByClass(ilDclTableListGUI::class, 'listTables');
}

public function disableComments(): void
{
$this->table->setPublicCommentsEnabled(false);
$this->table->doUpdate();
$this->ctrl->redirectByClass(ilDclTableListGUI::class, 'listTables');
}

public function setAsDefault(): void
{
$object = ilObjectFactory::getInstanceByObjId($this->obj_id);
$order = 20;
foreach ($object->getTables() as $table) {
if ($table->getId() === $this->table->getId()) {
$table->setOrder(10);
} else {
$table->setOrder($order);
$order += 10;
}
$table->doUpdate();
}
$this->ctrl->redirectByClass(ilDclTableListGUI::class, 'listTables');
}

protected function checkAccess(): bool
{
$ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

declare(strict_types=1);

use ILIAS\UI\Component\Button\Shy;

/**
* @ilCtrl_Calls ilDclTableListGUI: ilDclFieldListGUI, ilDclFieldEditGUI, ilDclTableViewGUI, ilDclTableEditGUI
*/
Expand All @@ -33,12 +35,7 @@ class ilDclTableListGUI
protected ILIAS\HTTP\Services $http;
protected ILIAS\Refinery\Factory $refinery;
protected ilObjDataCollectionGUI $parent_obj;
protected int $obj_id;

/**
* ilDclTableListGUI constructor.
* @param ilObjDataCollectionGUI $a_parent_obj
*/
public function __construct(ilObjDataCollectionGUI $a_parent_obj)
{
global $DIC;
Expand All @@ -54,12 +51,6 @@ public function __construct(ilObjDataCollectionGUI $a_parent_obj)
$this->renderer = $DIC->ui()->renderer();

$this->parent_obj = $a_parent_obj;
$this->obj_id = 0;
if ($a_parent_obj->getRefId() >= 0) {
$this->obj_id = ilObject::_lookupObjectId($a_parent_obj->getRefId());
}



if (!$this->checkAccess()) {
$main_tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
Expand Down Expand Up @@ -87,25 +78,21 @@ public function executeCommand(): void

$next_class = $this->ctrl->getNextClass($this);

/*
* see https://www.ilias.de/mantis/view.php?id=22775
*/
$ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());

$tableHelper = new ilDclTableHelper(
$this->obj_id,
$this->getObjId(),
$ref_id,
$DIC->rbac()->review(),
$DIC->user(),
$DIC->database()
);
// send a warning if there are roles with rbac read access on the data collection but without read access on any standard view
$role_titles = $tableHelper->getRoleTitlesWithoutReadRightOnAnyStandardView();

if (count($role_titles) > 0) {
$this->tpl->setOnScreenMessage(
'info',
$DIC->language()->txt('dcl_rbac_roles_without_read_access_on_any_standard_view') . " " . implode(
$this->lng->txt('dcl_rbac_roles_without_read_access_on_any_standard_view') . " " . implode(
", ",
$role_titles
)
Expand Down Expand Up @@ -162,8 +149,109 @@ public function listTables(): void
);
$this->toolbar->addStickyItem($add_new);

$table_gui = new ilDclTableListTableGUI($this);
$this->tpl->setContent($table_gui->getHTML());
$this->tpl->setContent(
$this->renderer->render(
$this->ui_factory->panel()->standard(
$this->lng->txt('dcl_tables'),
$this->getItems()
)
)
);
}

protected function getItems(): array
{
$items = [];
foreach ($this->parent_obj->getDataCollectionObject()->getTables() as $table) {

$this->ctrl->setParameterByClass(ilObjDataCollectionGUI::class, 'table_id', $table->getId());
$checked = $this->ui_factory->symbol()->icon()->custom(ilUtil::getImagePath('standard/icon_checked.svg'), '');
$unchecked = $this->ui_factory->symbol()->icon()->custom(ilUtil::getImagePath('standard/icon_unchecked.svg'), '');
$item = $this->ui_factory->item()->standard(
$this->ui_factory->link()->standard(
$table->getTitle(),
$this->ctrl->getLinkTargetByClass(ilDclFieldListGUI::class, 'listFields')
)
)
->withProperties([
$this->lng->txt('visible') => $table->getIsVisible() ? $checked : $unchecked,
$this->lng->txt('comments') => $table->getPublicCommentsEnabled() ? $checked : $unchecked
])
->withActions(
$this->ui_factory->dropdown()->standard(
$this->getActions($table)
)
);

if ($table->getOrder() === 10) {
$item = $item->withDescription($this->lng->txt('default'));
}
$items[] = $item;
}
return $items;
}


/**
* @return Shy[]
*/
protected function getActions(ilDclTable $table): array
{
$this->ctrl->setParameterByClass(ilObjDataCollectionGUI::class, 'table_id', $table->getId());

$actions = [];
$actions[] = $this->ui_factory->button()->shy(
$this->lng->txt('settings'),
$this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'edit'),
);

$actions[] = $this->ui_factory->button()->shy(
$this->lng->txt('dcl_list_fields'),
$this->ctrl->getLinkTargetByClass(ilDclFieldListGUI::class, 'listFields')
);

$actions[] = $this->ui_factory->button()->shy(
$this->lng->txt('dcl_tableviews'),
$this->ctrl->getLinkTargetByClass(ilDclFieldListGUI::class, 'show')
);

$actions[] = $this->ui_factory->button()->shy(
$this->lng->txt('delete'),
$this->ctrl->getLinkTargetByClass(ilDclFieldListGUI::class, 'confirmDelete')
);

if ($table->getIsVisible()) {
$actions[] = $this->ui_factory->button()->shy(
$this->lng->txt('disable_visible'),
$this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'disableVisible')
);
} else {
$actions[] = $this->ui_factory->button()->shy(
$this->lng->txt('enable_visible'),
$this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'enableVisible')
);
}

if ($table->getPublicCommentsEnabled()) {
$actions[] = $this->ui_factory->button()->shy(
$this->lng->txt('disable_comments'),
$this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'disableComments')
);
} else {
$actions[] = $this->ui_factory->button()->shy(
$this->lng->txt('enable_comments'),
$this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'enableComments')
);
}

if ($table->getOrder() !== 10) {
$actions[] = $this->ui_factory->button()->shy(
$this->lng->txt('set_as_default'),
$this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'setAsDefault')
);
}

return $actions;
}

protected function setTabs(string $active): void
Expand Down Expand Up @@ -239,7 +327,7 @@ public function confirmDeleteTables(): void
$conf->setHeaderText($this->lng->txt('dcl_tables_confirm_delete'));

foreach ($tables as $table_id) {
$conf->addItem('dcl_table_ids[]', (string)$table_id, ilDclCache::getTableCache($table_id)->getTitle());
$conf->addItem('dcl_table_ids[]', (string) $table_id, ilDclCache::getTableCache($table_id)->getTitle());
}
$conf->setConfirm($this->lng->txt('delete'), 'deleteTables');
$conf->setCancel($this->lng->txt('cancel'), 'listTables');
Expand Down
Loading

0 comments on commit c9854a7

Please sign in to comment.