class TableSort in Drupal 7
Query extender class for tablesort queries.
Hierarchy
- class \SelectQueryExtender implements SelectQueryInterface
- class \TableSort
Expanded class hierarchy of TableSort
16 string references to 'TableSort'
- comment_admin_overview in modules/
comment/ comment.admin.inc - Form builder for the comment overview administration form.
- database_test_theme_tablesort in modules/
simpletest/ tests/ database_test.module - Output a form without setting a header sort.
- dblog_overview in modules/
dblog/ dblog.admin.inc - Page callback: Displays a listing of database log messages.
- dblog_top in modules/
dblog/ dblog.admin.inc - Page callback: Shows the most frequent log messages of a given event type.
- forum_get_topics in modules/
forum/ forum.module - Gets all the topics in a forum.
File
- includes/
tablesort.inc, line 15 - Functions to aid in the creation of sortable tables.
View source
class TableSort extends SelectQueryExtender {
/**
* The array of fields that can be sorted by.
*
* @var array
*/
protected $header = array();
public function __construct(SelectQueryInterface $query, DatabaseConnection $connection) {
parent::__construct($query, $connection);
// Add convenience tag to mark that this is an extended query. We have to
// do this in the constructor to ensure that it is set before preExecute()
// gets called.
$this
->addTag('tablesort');
}
/**
* Order the query based on a header array.
*
* @see theme_table()
* @param $header
* Table header array.
* @return SelectQueryInterface
* The called object.
*/
public function orderByHeader(array $header) {
$this->header = $header;
$ts = $this
->init();
if (!empty($ts['sql'])) {
// Based on code from db_escape_table(), but this can also contain a dot.
$field = preg_replace('/[^A-Za-z0-9_.]+/', '', $ts['sql']);
// orderBy() will ensure that only ASC/DESC values are accepted, so we
// don't need to sanitize that here.
$this
->orderBy($field, $ts['sort']);
}
return $this;
}
/**
* Initializes the table sort context.
*/
protected function init() {
$ts = $this
->order();
$ts['sort'] = $this
->getSort();
$ts['query'] = $this
->getQueryParameters();
return $ts;
}
/**
* Determine the current sort direction.
*
* @param $headers
* An array of column headers in the format described in theme_table().
* @return
* The current sort direction ("asc" or "desc").
*/
protected function getSort() {
return tablesort_get_sort($this->header);
}
/**
* Compose a URL query parameter array to append to table sorting requests.
*
* @return
* A URL query parameter array that consists of all components of the current
* page request except for those pertaining to table sorting.
*
* @see tablesort_get_query_parameters()
*/
protected function getQueryParameters() {
return tablesort_get_query_parameters();
}
/**
* Determine the current sort criterion.
*
* @param $headers
* An array of column headers in the format described in theme_table().
* @return
* An associative array describing the criterion, containing the keys:
* - "name": The localized title of the table column.
* - "sql": The name of the database field to sort on.
*/
protected function order() {
return tablesort_get_order($this->header);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SelectQueryExtender:: |
protected | property | The connection object on which to run this query. | |
SelectQueryExtender:: |
protected | property | The placeholder counter. | |
SelectQueryExtender:: |
protected | property | The SelectQuery object we are extending/decorating. | |
SelectQueryExtender:: |
protected | property | A unique identifier for this query object. | |
SelectQueryExtender:: |
public | function |
Adds an expression to the list of "fields" to be SELECTed. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Adds a field to the list to be SELECTed. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Join against another table in the database. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Adds additional metadata to the query. Overrides QueryAlterableInterface:: |
|
SelectQueryExtender:: |
public | function |
Adds a tag to a query. Overrides QueryAlterableInterface:: |
|
SelectQueryExtender:: |
public | function |
Gets a complete list of all values to insert into the prepared statement. Overrides QueryConditionInterface:: |
|
SelectQueryExtender:: |
public | function |
Compiles the saved conditions for later retrieval. Overrides QueryConditionInterface:: |
|
SelectQueryExtender:: |
public | function |
Check whether a condition has been previously compiled. Overrides QueryConditionInterface:: |
|
SelectQueryExtender:: |
public | function |
Helper function: builds the most common conditional clauses. Overrides QueryConditionInterface:: |
|
SelectQueryExtender:: |
public | function |
Gets a complete list of all conditions in this conditional clause. Overrides QueryConditionInterface:: |
|
SelectQueryExtender:: |
public | function |
Get the equivalent COUNT query of this query as a new query object. Overrides SelectQueryInterface:: |
1 |
SelectQueryExtender:: |
public | function |
Sets this query to be DISTINCT. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function | 2 | |
SelectQueryExtender:: |
public | function |
Sets a condition that the specified subquery returns values. Overrides QueryConditionInterface:: |
|
SelectQueryExtender:: |
public | function |
Enhance this object by wrapping it in an extender object. Overrides QueryExtendableInterface:: |
|
SelectQueryExtender:: |
public | function |
Add multiple fields from the same table to be SELECTed. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Add FOR UPDATE to the query. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Compiles and returns an associative array of the arguments for this prepared statement. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Returns a reference to the expressions array for this query. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Returns a reference to the fields array for this query. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Returns a reference to the group-by array for this query. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Retrieves a given piece of metadata. Overrides QueryAlterableInterface:: |
|
SelectQueryExtender:: |
public | function |
Returns a reference to the order by array for this query. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Returns a reference to the tables array for this query. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Returns a reference to the union queries for this query. This include
queries for UNION, UNION ALL, and UNION DISTINCT. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Groups the result set by the specified field. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Determines if a given query has all specified tags. Overrides QueryAlterableInterface:: |
|
SelectQueryExtender:: |
public | function |
Determines if a given query has any specified tag. Overrides QueryAlterableInterface:: |
|
SelectQueryExtender:: |
public | function |
Determines if a given query has a given tag. Overrides QueryAlterableInterface:: |
|
SelectQueryExtender:: |
public | function | ||
SelectQueryExtender:: |
public | function | ||
SelectQueryExtender:: |
public | function | ||
SelectQueryExtender:: |
public | function |
Helper function to build most common HAVING conditional clauses. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function | ||
SelectQueryExtender:: |
public | function |
Inner Join against another table in the database. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
function |
Sets a condition that the specified field be NOT NULL. Overrides QueryConditionInterface:: |
||
SelectQueryExtender:: |
function |
Sets a condition that the specified field be NULL. Overrides QueryConditionInterface:: |
||
SelectQueryExtender:: |
public | function |
Indicates if preExecute() has already been called on that object. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Default Join against another table in the database. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Left Outer Join against another table in the database. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Implements QueryPlaceholderInterface::nextPlaceholder(). Overrides QueryPlaceholderInterface:: |
|
SelectQueryExtender:: |
public | function |
Sets a condition that the specified subquery returns no values. Overrides QueryConditionInterface:: |
|
SelectQueryExtender:: |
public | function |
Orders the result set by a given field. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Orders the result set by a random value. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Generic preparation and validation for a SELECT query. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Restricts a query to a given range in the result set. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Right Outer Join against another table in the database. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Add another Select query to UNION to this one. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function |
Implements QueryPlaceholderInterface::uniqueIdentifier(). Overrides QueryPlaceholderInterface:: |
|
SelectQueryExtender:: |
public | function |
Adds an arbitrary WHERE clause to the query. Overrides QueryConditionInterface:: |
|
SelectQueryExtender:: |
public | function | Magic override for undefined methods. | |
SelectQueryExtender:: |
public | function |
Clone magic method. Overrides SelectQueryInterface:: |
|
SelectQueryExtender:: |
public | function | ||
TableSort:: |
protected | property | The array of fields that can be sorted by. | |
TableSort:: |
protected | function | Compose a URL query parameter array to append to table sorting requests. | |
TableSort:: |
protected | function | Determine the current sort direction. | |
TableSort:: |
protected | function | Initializes the table sort context. | |
TableSort:: |
protected | function | Determine the current sort criterion. | |
TableSort:: |
public | function | Order the query based on a header array. | |
TableSort:: |
public | function |
Overrides SelectQueryExtender:: |