From 0613e04dea1f7cec8a76c3cf8cb472defd7630cb Mon Sep 17 00:00:00 2001 From: iszmais Date: Tue, 25 Jun 2024 18:44:42 +0200 Subject: [PATCH] Remove legacy table from DC Tables --- .../classes/DataRetrieval/Table.php | 168 ++++++++++++++++++ .../classes/Table/class.ilDclTableEditGUI.php | 46 +++++ .../classes/Table/class.ilDclTableListGUI.php | 120 +++---------- .../classes/class.ilObjDataCollection.php | 2 +- .../classes/class.ilObjDataCollectionGUI.php | 2 +- lang/ilias_de.lang | 7 +- lang/ilias_en.lang | 7 +- 7 files changed, 250 insertions(+), 102 deletions(-) create mode 100644 components/ILIAS/DataCollection/classes/DataRetrieval/Table.php diff --git a/components/ILIAS/DataCollection/classes/DataRetrieval/Table.php b/components/ILIAS/DataCollection/classes/DataRetrieval/Table.php new file mode 100644 index 000000000000..211aa4b14cb0 --- /dev/null +++ b/components/ILIAS/DataCollection/classes/DataRetrieval/Table.php @@ -0,0 +1,168 @@ +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 = []; + [$builder, $token] = $this->buildURL(ilDclTableEditGUI::class, 'edit'); + $actions[] = $this->dic->ui()->factory()->table()->action()->single( + $this->dic->language()->txt('settings'), + $builder, + $token + ); + + [$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): array + { + global $DIC; + $link = ILIAS_HTTP_PATH . '/' . $DIC->ctrl()->getLinkTargetByClass($class, $cmd); + $url_builder = new URLBuilder((new Factory())->uri($link)); + return $url_builder->acquireParameters(['i'], 'i'); + } + + public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int + { + return count($this->object->getTables()); + } +} diff --git a/components/ILIAS/DataCollection/classes/Table/class.ilDclTableEditGUI.php b/components/ILIAS/DataCollection/classes/Table/class.ilDclTableEditGUI.php index 022fbbaff7e5..eca60ae75b63 100755 --- a/components/ILIAS/DataCollection/classes/Table/class.ilDclTableEditGUI.php +++ b/components/ILIAS/DataCollection/classes/Table/class.ilDclTableEditGUI.php @@ -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(); diff --git a/components/ILIAS/DataCollection/classes/Table/class.ilDclTableListGUI.php b/components/ILIAS/DataCollection/classes/Table/class.ilDclTableListGUI.php index 7d11926a26ce..f65f594b3286 100755 --- a/components/ILIAS/DataCollection/classes/Table/class.ilDclTableListGUI.php +++ b/components/ILIAS/DataCollection/classes/Table/class.ilDclTableListGUI.php @@ -18,6 +18,10 @@ declare(strict_types=1); +use ILIAS\Data\URI; +use ILIAS\DataCollection\DataRetrieval\Table; +use ILIAS\UI\URLBuilder; + /** * @ilCtrl_Calls ilDclTableListGUI: ilDclFieldListGUI, ilDclFieldEditGUI, ilDclTableViewGUI, ilDclTableEditGUI */ @@ -35,10 +39,6 @@ class ilDclTableListGUI protected ilObjDataCollectionGUI $parent_obj; protected int $obj_id; - /** - * ilDclTableListGUI constructor. - * @param ilObjDataCollectionGUI $a_parent_obj - */ public function __construct(ilObjDataCollectionGUI $a_parent_obj) { global $DIC; @@ -77,9 +77,6 @@ public function getRefId(): int return $this->parent_obj->getRefId(); } - /** - * execute command - */ public function executeCommand(): void { global $DIC; @@ -105,7 +102,7 @@ public function executeCommand(): void 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 ) @@ -162,8 +159,23 @@ public function listTables(): void ); $this->toolbar->addStickyItem($add_new); - $table_gui = new ilDclTableListTableGUI($this); - $this->tpl->setContent($table_gui->getHTML()); + $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'), ''); + + list($builder, $token) = (new URLBuilder(new URI('http://none')))->acquireParameters(['i'], 'i'); + + $table = $this->ui_factory->table()->data( + $this->lng->txt('dcl_tables'), + [ + 'title' => $this->ui_factory->table()->column()->text( $this->lng->txt('title'))->withIsSortable(false), + 'default' => $this->ui_factory->table()->column()->boolean($this->lng->txt('default'), $checked, '')->withIsSortable(false), + 'visible' => $this->ui_factory->table()->column()->boolean($this->lng->txt('visible'), $checked, $unchecked)->withIsSortable(false), + 'comments' => $this->ui_factory->table()->column()->boolean($this->lng->txt('comments'), $checked, $unchecked)->withIsSortable(false), + ], + new Table($this->getDataCollectionObject()) + )->withActions([$this->ui_factory->table()->action()->single('', $builder, $token)]); + + $this->tpl->setContent($this->renderer->render($table->withRequest($this->http->request()))); } protected function setTabs(string $active): void @@ -187,94 +199,6 @@ protected function setTabs(string $active): void $this->tabs->activateTab($active); } - protected function save(): void - { - if ($this->http->wrapper()->post()->has("comments")) { - $comments = $this->http->wrapper()->post()->retrieve( - 'comments', - $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string()) - ); - } - if ($this->http->wrapper()->post()->has("visible")) { - $visible = $this->http->wrapper()->post()->retrieve( - 'visible', - $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string()) - ); - } - $orders = $this->http->wrapper()->post()->retrieve( - 'order', - $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string()) - ); - asort($orders); - $order = 10; - foreach (array_keys($orders) as $table_id) { - $table = ilDclCache::getTableCache($table_id); - $table->setOrder($order); - $table->setPublicCommentsEnabled(isset($comments[$table_id])); - $table->setIsVisible(isset($visible[$table_id])); - $table->doUpdate(); - $order += 10; - } - $this->ctrl->redirect($this); - } - - public function confirmDeleteTables(): void - { - //at least one table must exist - $has_dcl_table_ids = $this->http->wrapper()->post()->has('dcl_table_ids'); - if (!$has_dcl_table_ids) { - $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_delete_tables_no_selection'), true); - $this->ctrl->redirect($this, 'listTables'); - } - - $tables = $this->http->wrapper()->post()->retrieve( - 'dcl_table_ids', - $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()) - ); - $this->checkTablesLeft(count($tables)); - - $this->tabs->clearSubTabs(); - $conf = new ilConfirmationGUI(); - $conf->setFormAction($this->ctrl->getFormAction($this)); - $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->setConfirm($this->lng->txt('delete'), 'deleteTables'); - $conf->setCancel($this->lng->txt('cancel'), 'listTables'); - $this->tpl->setContent($conf->getHTML()); - } - - protected function deleteTables(): void - { - $has_dcl_table_ids = $this->http->wrapper()->post()->has('dcl_table_ids'); - if ($has_dcl_table_ids) { - $tables = $this->http->wrapper()->post()->retrieve( - 'dcl_table_ids', - $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()) - ); - foreach ($tables as $table_id) { - ilDclCache::getTableCache($table_id)->doDelete(); - } - } - $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tables_deleted'), true); - $this->ctrl->clearParameterByClass("ilobjdatacollectiongui", "table_id"); - $this->ctrl->redirect($this, 'listTables'); - } - - /** - * redirects if there are no tableviews left after deletion of {$delete_count} tableviews - * @param $delete_count number of tableviews to delete - */ - public function checkTablesLeft(int $delete_count): void - { - if ($delete_count >= count($this->getDataCollectionObject()->getTables())) { - $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_msg_tables_delete_all'), true); - $this->ctrl->redirect($this, 'listTables'); - } - } - protected function checkAccess(): bool { $ref_id = $this->parent_obj->getRefId(); diff --git a/components/ILIAS/DataCollection/classes/class.ilObjDataCollection.php b/components/ILIAS/DataCollection/classes/class.ilObjDataCollection.php index fb63cb5aaf68..5bcf0e3c210a 100755 --- a/components/ILIAS/DataCollection/classes/class.ilObjDataCollection.php +++ b/components/ILIAS/DataCollection/classes/class.ilObjDataCollection.php @@ -377,7 +377,7 @@ public static function _hasReadAccess(int $ref): bool public function getTables(): array { $query = "SELECT id FROM il_dcl_table WHERE obj_id = " . $this->db->quote($this->getId(), "integer") . - " ORDER BY -table_order DESC"; + " ORDER BY title ASC"; $set = $this->db->query($query); $tables = []; diff --git a/components/ILIAS/DataCollection/classes/class.ilObjDataCollectionGUI.php b/components/ILIAS/DataCollection/classes/class.ilObjDataCollectionGUI.php index e0914c0caa59..25dc19b56d38 100755 --- a/components/ILIAS/DataCollection/classes/class.ilObjDataCollectionGUI.php +++ b/components/ILIAS/DataCollection/classes/class.ilObjDataCollectionGUI.php @@ -264,7 +264,7 @@ protected function handleExport(bool $do_default = false) $this->tabs->setTabActive(self::TAB_EXPORT); $exp_gui = new ilDclExportGUI($this); $exporter = new ilDclContentExporter($this->object->getRefId(), $this->table_id); - $exp_gui->addFormat("xlsx", $this->lng->txt('dlc_xls_async_export'), $exporter, 'exportAsync'); + $exp_gui->addFormat("xlsx", $this->lng->txt('dcl_xls_async_export'), $exporter, 'exportAsync'); $exp_gui->addFormat("xml"); if ($do_default) { $exp_gui->listExportFiles(); diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang index a250cd0bc2be..283c1748f352 100755 --- a/lang/ilias_de.lang +++ b/lang/ilias_de.lang @@ -8823,10 +8823,15 @@ dcl#:#dcl_width#:#Breite dcl#:#dcl_wrong_input_type#:#Der eingegebene Text passt nicht zum Typ dieses Feldes (falscher Typ). dcl#:#dcl_wrong_length#:#Der eingegebene Text ist zu lang. dcl#:#dcl_wrong_regex#:#Der eingegebene Text passt nicht zur Spezifikation dieses Feldes (regulärer Ausdruck). -dcl#:#dlc_xls_async_export#:#Asynchroner XLSX-Export +dcl#:#dcl_xls_async_export#:#Asynchroner XLSX-Export +dcl#:#disable_comments#:#Kommentare deaktivieren +dcl#:#disable_visible#:#Sichtbarkeit deaktivieren +dcl#:#enable_comments#:#Kommentare aktivieren +dcl#:#enable_visible#:#Sichtbarkeit aktivieren dcl#:#entry_of#:#Eintrag %1$d von %2$d dcl#:#fieldtitle_allow_chars#:#Nicht Erlaubte Zeichen: %s dcl#:#fileupload_not_migrated#:#Die Datei wurde noch nicht migriert und kann deshalb nicht angezeigt werden. Bitte wenden Sie sich an Ihre Systemadministration. +dcl#:#set_as_default#:#Als Standard setzen didactic#:#activate_exclusive_template#:#Standard ausgrauen didactic#:#activate_exclusive_template_info#:#Die Standard-Vorlage wird überall dort ausgegraut, wo diese didaktische Vorlage aktiv ist. didactic#:#activate_local_didactic_template#:#Gültigkeitsbereich diff --git a/lang/ilias_en.lang b/lang/ilias_en.lang index 19c4d1881fc4..a378eab6663e 100755 --- a/lang/ilias_en.lang +++ b/lang/ilias_en.lang @@ -8817,10 +8817,15 @@ dcl#:#dcl_width#:#Width dcl#:#dcl_wrong_input_type#:#The value you entered does not match the specification (Wrong Type). dcl#:#dcl_wrong_length#:#The text you entered is to long. dcl#:#dcl_wrong_regex#:#The text you entered does not match the specification for this field (Regular Expression). -dcl#:#dlc_xls_async_export#:#Asynchronous XLSX-Export +dcl#:#dcl_xls_async_export#:#Asynchronous XLSX-Export +dcl#:#disable_comments#:#Disable comments +dcl#:#disable_visible#:#Disable visible +dcl#:#enable_comments#:#Enable comments +dcl#:#enable_visible#:#Enable visible dcl#:#entry_of#:#Entry %1$d of %2$d dcl#:#fieldtitle_allow_chars#:#Not allowed chars: %s dcl#:#fileupload_not_migrated#:#File has not yet been migration and cannot be displayed. Please contact your System-Administrator. +dcl#:#set_as_default#:#Set as default didactic#:#activate_exclusive_template#:#Grey Out Default didactic#:#activate_exclusive_template_info#:#The standard template won't be available wherever this template is active. didactic#:#activate_local_didactic_template#:#Scope of Application