Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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\AdvancedMetaData\Types\Group\ComplexOptions\Table;

use ILIAS\UI\Component\Table\DataRowBuilder;
use ILIAS\Data\Range;
use ILIAS\Data\Order;
use Generator;
use ilAdvancedMDFieldDefinitionGroupBased;
use ILIAS\UI\Component\Table\DataRetrieval as BaseDataRetrieval;

class DataRetrieval implements BaseDataRetrieval
{
public function __construct(
protected ilAdvancedMDFieldDefinitionGroupBased $definition
) {
}

public function getRows(
DataRowBuilder $row_builder,
array $visible_column_ids,
Range $range,
Order $order,
mixed $additional_viewcontrol_data,
mixed $filter_data,
mixed $additional_parameters
): Generator {
$data = [];
$options = $this->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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?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\AdvancedMetaData\Types\Group\ComplexOptions\Table;

use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Component\Table\Data as DataTable;
use ilLanguage;
use ILIAS\HTTP\Services as HTTP;
use ILIAS\UI\URLBuilder;
use ilAdvancedMDFieldDefinitionGroupBased;
use ilAdvancedMDSettingsGUI;
use ilCtrl;
use ILIAS\Data\URI;

/**
* @ilCtrl_Calls ilAdvancedMDSettingsGUI: ilPropertyFormGUI
*/
class TableBuilder
{
public function __construct(
protected DataRetrieval $data_retrieval,
protected ilLanguage $lng,
protected UIFactory $ui_factory,
protected HTTP $http,
protected ilCtrl $ctrl,
protected ilAdvancedMDFieldDefinitionGroupBased $definition
) {
}

public function get(): DataTable
{
$columns = [];
$columns['option'] = $this->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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <luetzenkirchen@leifos.com>
Expand Down Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = '')
{
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
Loading
Loading