ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
trait.RetrievalBase.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Repository;
22
25
26trait RetrievalBase
27{
28 protected function applyOrder(array $data, ?Order $order = null): array
29 {
30 if ($order !== null) {
31 $order_field = array_keys($order->get())[0];
32 $order_direction = $order->get()[$order_field];
33
34 if (count(array_column($data, $order_field)) === 0) {
35 return $data;
36 }
37 array_multisort(
38 array_column($data, $order_field),
39 $order_direction === 'ASC' ? SORT_ASC : SORT_DESC,
40 $this->isFieldNumeric($order_field) ? SORT_NUMERIC : SORT_STRING,
41 $data
42 );
43 }
44 return $data;
45 }
46
47 protected function applyRange(array $data, ?Range $range = null): array
48 {
49 if ($range !== null) {
50 $offset = $range->getStart();
51 $limit = $range->getLength();
52 $data = array_slice($data, $offset, $limit);
53 }
54 return $data;
55 }
56}
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29