Skip to content

Commit ccb212f

Browse files
authored
Merge pull request ILIAS-eLearning#11257 from surlabs/ilias11_LTI_M47263_2
[FIX] LTI: Provider table alphabetical ordering for derived columns
2 parents 3408c9e + ec2b445 commit ccb212f

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

components/ILIAS/LTIConsumer/classes/class.ilLTIConsumerProviderTableGUI.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,20 @@ protected function applyOrdering(array $records, Order $order, ?Range $range = n
151151
fn($ret, $key, $value) => [$key, $value]
152152
);
153153

154-
usort($records, static function (array $left, array $right) use ($order_field): int {
155-
$left_val = $left[$order_field] ?? '';
156-
$right_val = $right[$order_field] ?? '';
157-
return ilStr::strCmp($left_val, $right_val);
154+
$order_field = (string) $order_field;
155+
$sortable_records = array_map(function (array $record) use ($order_field): array {
156+
return [
157+
'sort_key' => $this->getSortableValue($record, $order_field),
158+
'record' => $record,
159+
];
160+
}, $records);
161+
162+
usort($sortable_records, static function (array $left, array $right): int {
163+
return ilStr::strCmp($left['sort_key'], $right['sort_key']);
158164
});
159165

166+
$records = array_column($sortable_records, 'record');
167+
160168
if ($order_direction === Order::DESC) {
161169
$records = array_reverse($records);
162170
}
@@ -168,6 +176,20 @@ protected function applyOrdering(array $records, Order $order, ?Range $range = n
168176
return $records;
169177
}
170178

179+
protected function getSortableValue(array $record, string $order_field): string
180+
{
181+
return match ($order_field) {
182+
'category' => $this->getCategoryTranslation((string) ($record['category'] ?? '')),
183+
'outcome' => $this->getHasOutcomeFormatted((bool) ($record['outcome'] ?? false)),
184+
'internal' => $this->getIsInternalFormatted(!(bool) ($record['external'] ?? false)),
185+
'with_key' => $this->getIsWithKeyFormatted(!(bool) ($record['provider_key_customizable'] ?? false)),
186+
'availability' => $this->getAvailabilityLabel($record),
187+
'own_provider' => $this->getOwnProviderLabel($record),
188+
'provider_creator' => $this->getProviderCreatorLabel($record),
189+
default => (string) ($record[$order_field] ?? ''),
190+
};
191+
}
192+
171193
/**
172194
* @throws ilCtrlException
173195
*/

0 commit comments

Comments
 (0)