Skip to content

Commit

Permalink
Make gridRenderSort() more robust xibosignage/xibo#2311
Browse files Browse the repository at this point in the history
  • Loading branch information
dasgarner committed Sep 7, 2020
1 parent e6c1129 commit e218c4d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/Controller/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,21 +379,28 @@ protected function gridRenderFilter($extraFilter = [])
/**
* Set the sort order
* @return array
* @throws \Xibo\Exception\ConfigurationException
*/
protected function gridRenderSort()
{
$app = $this->getApp();

$columns = $app->request()->get('columns');

if ($columns == null || !is_array($columns))
if ($columns === null || !is_array($columns) || count($columns) <= 0) {
return null;
}

$order = array_map(function ($element) use ($columns) {
return ((isset($columns[$element['column']]['name']) && $columns[$element['column']]['name'] != '') ? '`' . $columns[$element['column']]['name'] . '`' : '`' . $columns[$element['column']]['data'] . '`') . (($element['dir'] == 'desc') ? ' DESC' : '');
}, $app->request()->get('order', array()));
$order = $app->request()->get('order');
if ($order === null || !is_array($order) || count($order) <= 0) {
return null;
}

return $order;
return array_map(function ($element) use ($columns) {
return ((isset($columns[$element['column']]['name']) && $columns[$element['column']]['name'] != '')
? '`' . $columns[$element['column']]['name'] . '`'
: '`' . $columns[$element['column']]['data'] . '`')
. (($element['dir'] == 'desc') ? ' DESC' : '');
}, $order);
}

/**
Expand Down

0 comments on commit e218c4d

Please sign in to comment.