function database_test_tablesort

7.x database_test.module database_test_tablesort()

Run a tablesort query and return the results.

This function does care about the page GET parameter, as set by the simpletest HTTP call.

1 string reference to 'database_test_tablesort'
database_test_menu in drupal-7.x/modules/simpletest/tests/database_test.module
Implements hook_menu().

File

drupal-7.x/modules/simpletest/tests/database_test.module, line 146

Code

function database_test_tablesort() {
  $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('TableSort')->orderByHeader($header);

  // We need all the results at once to check the sort.
  $tasks = $query->execute()->fetchAll();

  drupal_json_output(array(
    'tasks' => $tasks,
  ));
  exit;
}