Skip to content

Commit

Permalink
[FIX] 0043177: Failed test: Sorting fields in the detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
chfsx committed Jan 28, 2025
1 parent 91aebaa commit 85660f6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
17 changes: 16 additions & 1 deletion components/ILIAS/Bibliographic/classes/Field/DataRetrieval.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
use ILIAS\Data\Order;
use ILIAS\Data\Range;
use ILIAS\UI\Component\Table as I;
use ILIAS\UI\Component\Table\OrderingRowBuilder;

/**
* Class DataRetrieval
*
*/
class DataRetrieval implements I\DataRetrieval
class DataRetrieval implements I\OrderingBinding
{
private \ilLanguage $lng;

Expand All @@ -38,6 +39,20 @@ public function __construct(
}

public function getRows(
OrderingRowBuilder $row_builder,
array $visible_column_ids
): \Generator {
$records = $this->getRecords(new Order('position', 'ASC'));
foreach ($records as $idx => $record) {
$row_id = (string) $record['id'];
$field = $this->facade->fieldFactory()->findById($record['id']);
$record['data_type'] = $this->facade->translationFactory()->translate($field);
$record['is_standard_field'] = $field->isStandardField() ? $this->lng->txt('standard') : $this->lng->txt('custom');
yield $row_builder->buildOrderingRow($row_id, $record);
}
}

public function getRows22(
I\DataRowBuilder $row_builder,
array $visible_column_ids,
Range $range,
Expand Down
13 changes: 11 additions & 2 deletions components/ILIAS/Bibliographic/classes/Field/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Table
private \ilLanguage $lng;
private URLBuilder $url_builder;
private URLBuilderToken $id_token;
private \ILIAS\UI\Component\Table\Ordering $table;

protected array $components = [];

Expand All @@ -61,10 +62,13 @@ public function __construct(
$facade
);

$this->components[] = $this->ui_factory->table()->data(
$this->components[] = $this->table = $this->ui_factory->table()->ordering(
$this->lng->txt('filter'),
$columns,
$data_retrieval
$data_retrieval,
new URI(
ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTarget($this->calling_gui, \ilBiblAdminFieldGUI::CMD_SAVE_ORDERING)
)
)->withActions($actions)->withRequest(
$DIC->http()->request()
);
Expand Down Expand Up @@ -134,6 +138,11 @@ public function getHTML(): string
return $this->ui_renderer->render($this->components);
}

public function getOrdering(): array
{
return $this->table->getData();
}

public function getUrlBuilder(): URLBuilder
{
return $this->url_builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
abstract class ilBiblAdminFieldGUI
{
public const CMD_INIT_DEFAULT_FIELDS_AND_SORTING = 'initDefaultFieldsAndSorting';
public const SUBTAB_RIS = 'subtab_ris';
public const SUBTAB_BIBTEX = 'subtab_bibtex';
public const FIELD_IDENTIFIER = 'field_id';
Expand All @@ -34,6 +33,7 @@ abstract class ilBiblAdminFieldGUI
public const CMD_CANCEL = 'cancel';
public const CMD_EDIT = 'edit';
public const CMD_UPDATE = 'update';
public const CMD_SAVE_ORDERING = 'saveOrdering';
public const CMD_APPLY_FILTER = 'applyFilter';
public const CMD_RESET_FILTER = 'resetFilter';
public const CMD_SAVE = 'save';
Expand Down Expand Up @@ -101,6 +101,7 @@ protected function performCommand(): void
case self::CMD_EDIT:
case self::CMD_UPDATE:
case self::CMD_SAVE:
case self::CMD_SAVE_ORDERING:
case self::CMD_APPLY_FILTER:
case self::CMD_RESET_FILTER:
if ($this->checkPermissionBoolAndReturn('write')) {
Expand All @@ -110,6 +111,18 @@ protected function performCommand(): void
}
}

protected function saveOrdering(): void
{
foreach ($this->table->getOrdering() as $position => $field_id) {
$field = $this->facade->fieldFactory()->findById($field_id);
$field->setPosition($position);
$field->store();
}

$this->main_tpl->setOnScreenMessage('success', $this->lng->txt('changes_successfully_saved'));
$this->ctrl->redirect($this, self::CMD_STANDARD);
}

protected function getFieldIdFromRequest(): int
{
$query_params = $this->http->request()->getQueryParams(); // aka $_GET
Expand Down Expand Up @@ -178,20 +191,8 @@ protected function setSubTabs(): void

protected function save(): void
{
// I currently did not find a way to use the wrapper here
$positions = $this->http->request()->getParsedBody()['position'];

foreach ($positions as $set) {
$field_id = (int) key($set);
$position = (int) current($set);

$ilBiblField = $this->facade->fieldFactory()->findById($field_id);
$ilBiblField->setPosition($position);
$ilBiblField->store();
}

$this->main_tpl->setOnScreenMessage('success', $this->lng->txt('changes_successfully_saved'));
$this->ctrl->redirect($this, self::CMD_STANDARD);
$this->saveOrdering();
;
}

protected function applyFilter(): void
Expand Down

0 comments on commit 85660f6

Please sign in to comment.