diff --git a/components/ILIAS/AdvancedMetaData/classes/Types/Group/ComplexOptions/Table/DataRetrieval.php b/components/ILIAS/AdvancedMetaData/classes/Types/Group/ComplexOptions/Table/DataRetrieval.php new file mode 100644 index 000000000000..9765c4547fed --- /dev/null +++ b/components/ILIAS/AdvancedMetaData/classes/Types/Group/ComplexOptions/Table/DataRetrieval.php @@ -0,0 +1,79 @@ +definition->getOptions(); + foreach ($options as $option) { + $item = ["option" => (string) $option]; + $this->definition->exportOptionToTableGUI($option, $item); + $data[md5((string) $option)] = $item; + } + + $order_field = array_keys($order->get())[0] ?? 'option'; + $order_direction = $order->get()[$order_field] ?? Order::ASC; + + uasort($data, function ($a, $b) use ($order_field) { + return strnatcasecmp((string) ($a[$order_field] ?? ''), (string) ($b[$order_field] ?? '')); + }); + + if ($order_direction === Order::DESC) { + $data = array_reverse($data, true); + } + + $data = array_slice($data, $range->getStart(), $range->getLength(), true); + + foreach ($data as $id => $datum) { + yield $row_builder->buildDataRow($id, $datum); + } + } + + public function getTotalRowCount( + mixed $additional_viewcontrol_data, + mixed $filter_data, + mixed $additional_parameters + ): int { + return count($this->definition->getOptions()); + } +} diff --git a/components/ILIAS/AdvancedMetaData/classes/Types/Group/ComplexOptions/Table/TableBuilder.php b/components/ILIAS/AdvancedMetaData/classes/Types/Group/ComplexOptions/Table/TableBuilder.php new file mode 100644 index 000000000000..8cc873f9ecbd --- /dev/null +++ b/components/ILIAS/AdvancedMetaData/classes/Types/Group/ComplexOptions/Table/TableBuilder.php @@ -0,0 +1,88 @@ +ui_factory->table()->column()->text( + $this->lng->txt('option') + )->withIsSortable(true); + + foreach ($this->definition->getTitles() as $element => $title) { + $columns[$element] = $this->ui_factory->table()->column()->text( + $title + )->withIsSortable(true); + } + + $actions = []; + list($url_builder, $id_token) = $this->getTableActionURLBuilder(); + + $actions['edit'] = $this->ui_factory->table()->action()->single( + $this->lng->txt('edit'), + $url_builder, + $id_token + ); + + return $this->ui_factory->table()->data( + $this->data_retrieval, + $this->definition->getTitle(), + $columns + )->withActions($actions)->withRequest($this->http->request()) + ->withId('advanced_metadata_address_field_options_table'); + } + + public function getTableActionURLBuilder(): array + { + $link = ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass( + ilAdvancedMDSettingsGUI::class, + 'editComplexOption' + ); + $url_builder = new URLBuilder(new URI($link)); + + return $url_builder->acquireParameters(['advmd'], 'oid_table'); + } +} diff --git a/components/ILIAS/AdvancedMetaData/classes/Types/class.ilAdvancedMDFieldDefinitionGroupBased.php b/components/ILIAS/AdvancedMetaData/classes/Types/class.ilAdvancedMDFieldDefinitionGroupBased.php index 7a7965dd97dc..49e795c713c8 100755 --- a/components/ILIAS/AdvancedMetaData/classes/Types/class.ilAdvancedMDFieldDefinitionGroupBased.php +++ b/components/ILIAS/AdvancedMetaData/classes/Types/class.ilAdvancedMDFieldDefinitionGroupBased.php @@ -18,6 +18,11 @@ declare(strict_types=1); +use ILIAS\AdvancedMetaData\Types\Group\ComplexOptions\Table\DataRetrieval as ComplexOptionsDataRetrieval; +use ILIAS\AdvancedMetaData\Types\Group\ComplexOptions\Table\TableBuilder as ComplexOptionsTableBuilder; +use ILIAS\UI\Component\Component; +use ILIAS\UI\Component\Table\Data as DataTable; + /** * AMD field type address * @author Jörg Lützenkirchen @@ -191,13 +196,20 @@ protected function getADTForOption(string $a_option): ilADT return $adt; } - /** - * @inheritdoc - */ - public function getComplexOptionsOverview(object $a_parent_gui, string $a_parent_cmd): ?string + + public function getComplexOptionsOverview(): ?DataTable { - $tbl = new ilAdvancedMDFieldDefinitionGroupTableGUI($a_parent_gui, $a_parent_cmd, $this); - return $tbl->getHTML(); + $data_retrieval = new ComplexOptionsDataRetrieval($this); + $table_builder = new ComplexOptionsTableBuilder( + $data_retrieval, + $this->lng, + $this->ui_factory, + $this->http, + $this->ctrl, + $this + ); + + return $table_builder->get(); } public function exportOptionToTableGUI($a_option, array &$a_item): void diff --git a/components/ILIAS/AdvancedMetaData/classes/Types/class.ilAdvancedMDFieldDefinitionGroupTableGUI.php b/components/ILIAS/AdvancedMetaData/classes/Types/class.ilAdvancedMDFieldDefinitionGroupTableGUI.php deleted file mode 100755 index d0430a7f4acc..000000000000 --- a/components/ILIAS/AdvancedMetaData/classes/Types/class.ilAdvancedMDFieldDefinitionGroupTableGUI.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @version $Id$ - * @ingroup ServicesAdvancedMetaData - */ -class ilAdvancedMDFieldDefinitionGroupTableGUI extends ilTable2GUI -{ - protected ilAdvancedMDFieldDefinition $def; - - public function __construct($a_parent_obj, $a_parent_cmd, ilAdvancedMDFieldDefinition $a_def) - { - $this->def = $a_def; - - parent::__construct($a_parent_obj, $a_parent_cmd); - - $this->addColumn($this->lng->txt("option"), "option"); - - foreach ($this->def->getTitles() as $element => $title) { - $this->addColumn($title, $element); - } - - $this->addColumn($this->lng->txt("action"), ""); - - $this->setFormAction($this->ctrl->getFormAction($a_parent_obj)); - $this->setRowTemplate("tpl.edit_complex_row.html", "components/ILIAS/AdvancedMetaData"); - $this->setDefaultOrderField("option"); - $this->initItems($a_def); - } - - protected function initItems(ilAdvancedMDFieldDefinition $a_def): void - { - $data = array(); - - foreach ($a_def->getOptions() as $option) { - $item = array("option" => $option); - - $a_def->exportOptionToTableGUI($option, $item); - - $data[] = $item; - } - - $this->setData($data); - } - - protected function fillRow(array $a_set): void - { - $this->tpl->setVariable("OPTION", $a_set["option"]); - - $this->tpl->setCurrentBlock("field_bl"); - foreach (array_keys($this->def->getTitles()) as $element) { - $this->tpl->setVariable("FIELD", trim($a_set[$element])); - $this->tpl->parseCurrentBlock(); - } - - // action - $this->ctrl->setParameter($this->getParentObject(), "oid", md5($a_set["option"])); - $url = $this->ctrl->getLinkTarget($this->getParentObject(), "editComplexOption"); - $this->ctrl->setParameter($this->getParentObject(), "oid", ""); - - $this->tpl->setVariable("ACTION_URL", $url); - $this->tpl->setVariable("ACTION_TXT", $this->lng->txt("edit")); - } -} diff --git a/components/ILIAS/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php b/components/ILIAS/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php index 9e00e4a979ba..f82b7765179e 100755 --- a/components/ILIAS/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php +++ b/components/ILIAS/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php @@ -25,6 +25,10 @@ use ILIAS\AdvancedMetaData\Data\FieldDefinition\GenericData\GenericData; use ILIAS\AdvancedMetaData\Data\FieldDefinition\GenericData\GenericDataImplementation; use ILIAS\AdvancedMetaData\Repository\FieldDefinition\GenericData\DatabaseGatewayImplementation; +use ILIAS\UI\Factory as UIFactory; +use ILIAS\UI\Renderer as UIRenderer; +use ILIAS\UI\Component\Component; +use ILIAS\UI\Component\Table\Data as DataTable; /** * AMD field abstract base class @@ -74,6 +78,9 @@ abstract class ilAdvancedMDFieldDefinition protected ilLogger $logger; protected GlobalHttpState $http; protected RefineryFactory $refinery; + protected UIFactory $ui_factory; + protected UIRenderer $ui_renderer; + protected ilCtrl $ctrl; public function __construct(GenericData $generic_data, string $language = '') { @@ -83,6 +90,9 @@ public function __construct(GenericData $generic_data, string $language = '') $this->language = $DIC->language()->getLangKey(); $this->refinery = $DIC->refinery(); $this->http = $DIC->http(); + $this->ui_factory = $DIC->ui()->factory(); + $this->ui_renderer = $DIC->ui()->renderer(); + $this->ctrl = $DIC->ctrl(); if ($language) { @@ -1036,11 +1046,9 @@ public function hasComplexOptions(): bool } /** - * @param object $a_parent_gui - * @param string $parent_cmd * @return null */ - public function getComplexOptionsOverview(object $a_parent_gui, string $parent_cmd): ?string + public function getComplexOptionsOverview(): ?DataTable { return null; } diff --git a/components/ILIAS/AdvancedMetaData/classes/class.ilAdvancedMDSettingsGUI.php b/components/ILIAS/AdvancedMetaData/classes/class.ilAdvancedMDSettingsGUI.php index 20b4df7c6d8d..890362731cde 100755 --- a/components/ILIAS/AdvancedMetaData/classes/class.ilAdvancedMDSettingsGUI.php +++ b/components/ILIAS/AdvancedMetaData/classes/class.ilAdvancedMDSettingsGUI.php @@ -204,12 +204,28 @@ protected function getFieldTypeFromPost(): ?int protected function getOidFromQuery(): ?string { - if ($this->http->wrapper()->query()->has('oid')) { + $name = 'advmd_oid'; + if ($this->http->wrapper()->query()->has($name)) { return $this->http->wrapper()->query()->retrieve( - 'oid', + $name, $this->refinery->kindlyTo()->string() ); } + + return null; + } + + protected function getOidFromTable(): ?string + { + $name = 'advmd_oid_table'; + if ($this->http->wrapper()->query()->has($name)) { + $oids = $this->http->wrapper()->query()->retrieve( + $name, + $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()) + ); + return (string) ($oids[0] ?? ''); + } + return null; } @@ -1251,9 +1267,12 @@ public function editField(?ilPropertyFormGUI $a_form = null): void $this->showLanguageSwitch($this->record->getRecordId(), 'editField'); $a_form = $this->initFieldForm($field_definition); } - $table = null; + $table = ''; if ($field_definition->hasComplexOptions()) { - $table = $field_definition->getComplexOptionsOverview($this, "editField"); + $table_obj = $field_definition->getComplexOptionsOverview(); + if ($table_obj !== null) { + $table = $this->ui_renderer->render($table_obj); + } } $this->tpl->setContent($a_form->getHTML() . $table); } @@ -1992,23 +2011,26 @@ public function editComplexOption(?ilPropertyFormGUI $a_form = null): void } if (!$a_form) { - $a_form = $this->initComplexOptionForm($field_definition); + $oid = $this->getOidFromTable(); + $a_form = $this->initComplexOptionForm($field_definition, $oid); } $this->tpl->setContent($a_form->getHTML()); } - protected function initComplexOptionForm(ilAdvancedMDFieldDefinition $a_def): ilPropertyFormGUI + protected function initComplexOptionForm(ilAdvancedMDFieldDefinition $a_def, string $oid): ilPropertyFormGUI { $this->ctrl->saveParameter($this, "record_id"); $this->ctrl->saveParameter($this, "field_id"); - $this->ctrl->saveParameter($this, "oid"); + + if ($oid !== null) { + $this->ctrl->setParameter($this, "advmd_oid", $oid); + } $form = new ilPropertyFormGUI(); $form->setTitle($this->lng->txt("md_adv_edit_complex_option")); $form->setFormAction($this->ctrl->getFormAction($this, "updateComplexOption")); - $oid = $this->getOidFromQuery(); $a_def->initOptionForm($form, $oid); $form->addCommandButton("updateComplexOption", $this->lng->txt("save")); @@ -2024,7 +2046,7 @@ public function updateComplexOption(): void $oid = $this->getOidFromQuery(); if ($field_definition->hasComplexOptions()) { - $form = $this->initComplexOptionForm($field_definition); + $form = $this->initComplexOptionForm($field_definition, $oid); if ($form->checkInput() && $field_definition->updateComplexOption($form, $oid)) { $field_definition->update(); diff --git a/components/ILIAS/AdvancedMetaData/templates/default/tpl.edit_complex_row.html b/components/ILIAS/AdvancedMetaData/templates/default/tpl.edit_complex_row.html deleted file mode 100755 index a16d813e330e..000000000000 --- a/components/ILIAS/AdvancedMetaData/templates/default/tpl.edit_complex_row.html +++ /dev/null @@ -1,13 +0,0 @@ - - - {OPTION} - - - - {FIELD} - - - - {ACTION_TXT} - - \ No newline at end of file