Runs a tablesort query with a second order_by after and returns the results.
This function does care about the page GET parameter, as set by the simpletest HTTP call.
function database_test_tablesort_first() {
$header = array(
'tid' => array(
'data' => t('Task ID'),
'field' => 'tid',
'sort' => 'desc',
),
'pid' => array(
'data' => t('Person ID'),
'field' => 'pid',
),
'task' => array(
'data' => t('Task'),
'field' => 'task',
),
'priority' => array(
'data' => t('Priority'),
'field' => 'priority',
),
);
$query = db_select('test_task', 't');
$query
->fields('t', array(
'tid',
'pid',
'task',
'priority',
));
$query = $query
->extend('Drupal\\Core\\Database\\Query\\TableSortExtender')
->orderByHeader($header)
->orderBy('priority');
// We need all the results at once to check the sort.
$tasks = $query
->execute()
->fetchAll();
return new JsonResponse(array(
'tasks' => $tasks,
));
}