Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Do your manual sorting after result set is retrieved
- # I'm using this on my API response which did not have a sorting possibility
- $orderings = $query->getOrderings();
- if (!empty($orderings) && $results && count($results) > 1) {
- usort($results, function ($a, $b) use ($orderings) {
- $t = array(TRUE => -1, FALSE => 1);
- $r = TRUE;
- $k = 1;
- foreach ($orderings as $key => $direction) {
- $k = (strtolower($direction) === 'asc') ? 1 : -1;
- $key = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($key);
- $r = ($a[$key] < $b[$key]);
- if ($a[$key] !== $b[$key]) {
- return $t[$r] * $k;
- }
- }
- return $t[$r] * $k;
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement