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 Jun 27, 2024
1 parent 0c6c836 commit f1ff74c
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 137 deletions.
166 changes: 166 additions & 0 deletions components/ILIAS/DataCollection/classes/DataRetrieval/Table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\DataCollection\DataRetrieval;

use Generator;
use http\Url;
use ilDclFieldListGUI;
use ilDclTable;
use ilDclTableEditGUI;
use ilDclTableListGUI;
use ILIAS\Data\Factory;
use ILIAS\Data\Order;
use ILIAS\Data\Range;
use ILIAS\Data\URI;
use ILIAS\DI;
use ILIAS\DI\Container;
use ILIAS\UI\Component\Table\Action\Action;
use ILIAS\UI\Component\Table\DataRetrieval;
use ILIAS\UI\Component\Table\DataRowBuilder;
use ILIAS\UI\URLBuilder;
use ILIAS\UI\URLBuilderToken;
use ilObjDataCollection;
use ilObjDataCollectionGUI;

class Table implements DataRetrieval
{
private Container $dic;

public function __construct(protected readonly ilObjDataCollection $object)
{
global $DIC;
$this->dic = $DIC;
}

public function getRows(
DataRowBuilder $row_builder,
array $visible_column_ids,
Range $range,
Order $order,
?array $filter_data,
?array $additional_parameters
): Generator {
foreach ($this->object->getTables() as $table) {
$this->dic->ctrl()->setParameterByClass(ilDclFieldListGUI::class, 'table_id', $table->getId());
$row_builder = $row_builder->withSingleActions($this->getActions($table));
yield $row_builder->buildDataRow((string) $table->getId(), [
'title' => $this->dic->ui()->renderer()->render(
$this->dic->ui()->factory()->link()->standard(
$table->getTitle(),
$this->dic->ctrl()->getLinkTargetByClass(ilDclFieldListGUI::class, 'listFields')
)
),
'default' => $table->getOrder() === 10,
'visible' => $table->getIsVisible(),
'comments' => $table->getPublicCommentsEnabled()
]);
}
}

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

$actions = [];
$actions[] = $this->dic->ui()->factory()->table()->action()->single(
$this->dic->language()->txt('settings'),
$this->buildURL(ilDclTableEditGUI::class, 'edit'),
);
/*
[$builder, $token] = $this->buildURL(ilDclFieldListGUI::class, 'listFields');
$actions[] = $this->dic->ui()->factory()->table()->action()->single(
$this->dic->language()->txt('dcl_list_fields'),
$builder,
$token
);
[$builder, $token] = $this->buildURL(ilDclFieldListGUI::class, 'show');
$actions[] = $this->dic->ui()->factory()->table()->action()->single(
$this->dic->language()->txt('dcl_tableviews'),
$builder,
$token
);
[$builder, $token] = $this->buildURL(ilDclFieldListGUI::class, 'confirmDelete');
$actions[] = $this->dic->ui()->factory()->table()->action()->single(
$this->dic->language()->txt('delete'),
$builder,
$token
);
if ($table->getIsVisible()) {
[$builder, $token] = $this->buildURL(ilDclTableEditGUI::class, 'disableVisible');
$actions[] = $this->dic->ui()->factory()->table()->action()->single(
$this->dic->language()->txt('disable_visible'),
$builder,
$token
);
} else {
[$builder, $token] = $this->buildURL(ilDclTableEditGUI::class, 'enableVisible');
$actions[] = $this->dic->ui()->factory()->table()->action()->single(
$this->dic->language()->txt('enable_visible'),
$builder,
$token
);
}
if ($table->getPublicCommentsEnabled()) {
[$builder, $token] = $this->buildURL(ilDclTableEditGUI::class, 'disableComments');
$actions[] = $this->dic->ui()->factory()->table()->action()->single(
$this->dic->language()->txt('disable_comments'),
$builder,
$token
);
} else {
[$builder, $token] = $this->buildURL(ilDclTableEditGUI::class, 'enableComments');
$actions[] = $this->dic->ui()->factory()->table()->action()->single(
$this->dic->language()->txt('enable_comments'),
$builder,
$token
);
}
if ($table->getOrder() !== 10) {
[$builder, $token] = $this->buildURL(ilDclTableEditGUI::class, 'setAsDefault');
$actions[] = $this->dic->ui()->factory()->table()->action()->single(
$this->dic->language()->txt('set_as_default'),
$builder,
$token
);
}*/

return $actions;
}

private function buildURL(string $class, string $cmd): URLBuilder
{
$link = ILIAS_HTTP_PATH . '/' . $this->dic->ctrl()->getLinkTargetByClass($class, $cmd);
return new URLBuilder((new Factory())->uri($link));
}

public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
{
return count($this->object->getTables());
}
}
30 changes: 15 additions & 15 deletions components/ILIAS/DataCollection/classes/Table/class.ilDclTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,27 @@ public function doRead(): void
if (null !== $rec["title"]) {
$this->setTitle($rec["title"]);
}
$this->setAddPerm((bool)$rec["add_perm"]);
$this->setEditPerm((bool)$rec["edit_perm"]);
$this->setDeletePerm((bool)$rec["delete_perm"]);
$this->setEditByOwner((bool)$rec["edit_by_owner"]);
$this->setAddPerm((bool) $rec["add_perm"]);
$this->setEditPerm((bool) $rec["edit_perm"]);
$this->setDeletePerm((bool) $rec["delete_perm"]);
$this->setEditByOwner((bool) $rec["edit_by_owner"]);
if (null !== $rec["export_enabled"]) {
$this->setExportEnabled((bool) $rec["export_enabled"]);
}
$this->setImportEnabled((bool)$rec["import_enabled"]);
$this->setLimited((bool)$rec["limited"]);
$this->setLimitStart((string)$rec["limit_start"]);
$this->setLimitEnd((string)$rec["limit_end"]);
$this->setIsVisible((bool)$rec["is_visible"]);
$this->setImportEnabled((bool) $rec["import_enabled"]);
$this->setLimited((bool) $rec["limited"]);
$this->setLimitStart((string) $rec["limit_start"]);
$this->setLimitEnd((string) $rec["limit_end"]);
$this->setIsVisible((bool) $rec["is_visible"]);
if (null !== $rec['description']) {
$this->setDescription($rec['description']);
}
$this->setDefaultSortField((string)$rec['default_sort_field_id']);
$this->setDefaultSortField((string) $rec['default_sort_field_id']);
$this->setDefaultSortFieldOrder($rec['default_sort_field_order']);
$this->setPublicCommentsEnabled((bool)$rec['public_comments']);
$this->setViewOwnRecordsPerm((bool)$rec['view_own_records_perm']);
$this->setDeleteByOwner((bool)$rec['delete_by_owner']);
$this->setSaveConfirmation((bool)$rec['save_confirmation']);
$this->setPublicCommentsEnabled((bool) $rec['public_comments']);
$this->setViewOwnRecordsPerm((bool) $rec['view_own_records_perm']);
$this->setDeleteByOwner((bool) $rec['delete_by_owner']);
$this->setSaveConfirmation((bool) $rec['save_confirmation']);
if (null !== $rec['table_order']) {
$this->setOrder($rec['table_order']);
}
Expand Down Expand Up @@ -1067,7 +1067,7 @@ public function cloneStructure(ilDclTable $original): void
}
}

$this->setDefaultSortField((string)$default_sort_field);
$this->setDefaultSortField((string) $default_sort_field);
$this->doUpdate();

// Clone Records with recordfields
Expand Down
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,52 @@ public function delete(): void
$this->ctrl->redirectByClass("ildcltablelistgui", "listtables");
}



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

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

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

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

public function setAsDefault()
{
$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
Loading

0 comments on commit f1ff74c

Please sign in to comment.