Skip to content

Commit

Permalink
refactor: Tidy applyOrder method
Browse files Browse the repository at this point in the history
  • Loading branch information
garett-at-liquidlight committed Sep 1, 2024
1 parent ce96919 commit 805236b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Classes/Controller/DatatableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,16 @@ public function applyOrder(QueryBuilder $query, array $params)
$columnCount = count($this->headers);

foreach ($orders as $order) {

// Prepare the directions
$dir = strtoupper($order['dir'] ?? 'ASC');

if (!in_array($dir, ['ASC', 'DESC'], true)) {
continue;
}

// Prepare the column index
$column = $order['column'] ?? false;
$dir = $order['dir'] ?? 'ASC';

if (!is_numeric($column)) {
continue;
Expand All @@ -368,17 +376,11 @@ public function applyOrder(QueryBuilder $query, array $params)

if (!is_int($column)) {
continue;
}

if (0 > $column || $column >= $columnCount) {
continue;
}

if (!in_array(strtoupper($dir), ['ASC', 'DESC'], true)) {
} elseif (0 > $column || $column >= $columnCount) {
continue;
}

// SQL order by columns are 1-base
// Note: SQL order by column index is 1-base
$query->getConcreteQueryBuilder()->addOrderBy($column + 1, $dir);
}

Expand Down

0 comments on commit 805236b

Please sign in to comment.