Skip to content

Commit

Permalink
dc fix filters and sortation (ILIAS-eLearning#8717)
Browse files Browse the repository at this point in the history
  • Loading branch information
iszmais authored Dec 12, 2024
1 parent dd936be commit 24e1b5d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ilDclRecordListGUI
protected ilTabsGUI $tabs;
protected ILIAS\HTTP\Services $http;
protected ILIAS\Refinery\Factory $refinery;
protected bool $filter_changed = false;

private function init(
ilDataCollectionOutboundsAdapter $adapter
Expand Down Expand Up @@ -324,7 +325,8 @@ protected function applyFilter(): void
$table->initFilter();
$table->resetOffset();
$table->writeFilterToSession();
$this->ctrl->redirect($this, self::CMD_LIST_RECORDS);
$this->filter_changed = true;
$this->listRecords();
}

/**
Expand All @@ -336,7 +338,8 @@ protected function resetFilter(): void
$table->initFilter();
$table->resetOffset();
$table->resetFilter();
$this->ctrl->redirect($this, self::CMD_LIST_RECORDS);
$this->filter_changed = true;
$this->listRecords();
}

/**
Expand Down Expand Up @@ -528,24 +531,13 @@ protected function getRecordListTableGUI(bool $use_tableview_filter): ilDclRecor
$list->setExternalSorting(true);
$list->determineOffsetAndOrder();

$limit = $list->getLimit();
$offset = $list->getOffset();

$num_records = count($table_obj->getPartialRecords(
(string) $this->getRefId(),
$list->getOrderField(),
$list->getOrderDirection(),
$limit,
$offset,
$list->getFilter()
));

// Fix no data found on new filter application when on a site other than the first
if ($num_records === 0) {
if ($this->filter_changed) {
$list->resetOffset();
$offset = 0;
}

$limit = $list->getLimit();
$offset = $list->getOffset();

$data = $table_obj->getPartialRecords(
(string) $this->getRefId(),
$list->getOrderField(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,14 @@ private function setOptions(string $link_name): array
*/
private function loadSession(): void
{
// We need the default sorting etc. to dertermine on which position we currently are, thus we instantiate the table gui.
$list = new ilDclRecordListTableGUI(
new ilDclRecordListGUI($this->dcl_gui_object, $this->table->getId(), $this->tableview_id),
"listRecords",
$this->table,
$this->tableview_id
);
//we then partially load the records. note that this also fills up session data.
$list->initFilter();
$list->determineOffsetAndOrder();
$this->table->getPartialRecords(
$this->table->getId(),
$list->getOrderField(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function doRead(): void
}

$this->setTableId((int) $rec["table_id"]);
$this->loadTable();
if (null !== $rec["create_date"]) {
$this->setCreateDate(new ilDateTime($rec["create_date"], IL_CAL_DATETIME));
}
Expand Down
10 changes: 10 additions & 0 deletions Modules/DataCollection/classes/Table/class.ilDclTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,16 @@ public function getPartialRecords(
$total_record_ids = $sort_query_object->applyCustomSorting($sort_field, $total_record_ids, $direction);
}

if ($sort === 'n_comments') {
global $DIC;
$comments_nr = [];
foreach ($total_record_ids as $id) {
$comments_nr[$id] = $DIC->notes()->domain()->getNrOfCommentsForContext($DIC->notes()->data()->context($this->getObjId(), $id, 'dcl'));
}
uasort($comments_nr, static fn ($a, $b) => ($direction === 'asc' ? 1 : -1) * ($a <=> $b));
$total_record_ids = array_keys($comments_nr);
}

// Now slice the array to load only the needed records in memory
$record_ids = array_slice($total_record_ids, $offset, $limit);

Expand Down

0 comments on commit 24e1b5d

Please sign in to comment.