class TableSortExtender in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Database/Query/TableSortExtender.php \Drupal\Core\Database\Query\TableSortExtender
Query extender class for tablesort queries.
Hierarchy
- class \Drupal\Core\Database\Query\SelectExtender implements SelectInterface
- class \Drupal\Core\Database\Query\TableSortExtender
Expanded class hierarchy of TableSortExtender
File
- core/
lib/ Drupal/ Core/ Database/ Query/ TableSortExtender.php, line 15 - Contains \Drupal\Core\Database\Query\TableSortExtender.
Namespace
Drupal\Core\Database\QueryView source
class TableSortExtender extends SelectExtender {
/**
* The array of fields that can be sorted by.
*/
protected $header = array();
public function __construct(SelectInterface $query, Connection $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.
*
* @param array $header
* Table header array.
*
* @return \Drupal\Core\Database\Query\SelectInterface
* The called object.
*
* @see table.html.twig
*/
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;
}
/**
* Initialize 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.
*
* @return
* The current sort direction ("asc" or "desc").
*
* @see tablesort_get_sort()
*/
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.
*
* @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.
*
* @see tablesort_get_order()
*/
protected function order() {
return tablesort_get_order($this->header);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SelectExtender:: |
protected | property | The connection object on which to run this query. | |
SelectExtender:: |
protected | property | The placeholder counter. | |
SelectExtender:: |
protected | property | The Select query object we are extending/decorating. | |
SelectExtender:: |
protected | property | A unique identifier for this query object. | |
SelectExtender:: |
public | function |
Adds an expression to the list of "fields" to be SELECTed. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Adds a field to the list to be SELECTed. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Join against another table in the database. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Adds additional metadata to the query. Overrides AlterableInterface:: |
|
SelectExtender:: |
public | function |
Adds a tag to a query. Overrides AlterableInterface:: |
|
SelectExtender:: |
public | function |
Creates a new group of conditions ANDed together. Overrides ConditionInterface:: |
|
SelectExtender:: |
public | function |
Gets a complete list of all values to insert into the prepared statement. Overrides ConditionInterface:: |
|
SelectExtender:: |
public | function |
Compiles the saved conditions for later retrieval. Overrides ConditionInterface:: |
|
SelectExtender:: |
public | function |
Check whether a condition has been previously compiled. Overrides ConditionInterface:: |
|
SelectExtender:: |
public | function |
Helper function: builds the most common conditional clauses. Overrides ConditionInterface:: |
|
SelectExtender:: |
public | function |
Creates an object holding a group of conditions. Overrides ConditionInterface:: |
|
SelectExtender:: |
public | function |
Gets a complete list of all conditions in this conditional clause. Overrides ConditionInterface:: |
1 |
SelectExtender:: |
public | function |
Get the equivalent COUNT query of this query as a new query object. Overrides SelectInterface:: |
1 |
SelectExtender:: |
public | function |
Sets this query to be DISTINCT. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Escapes a field name string. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Escapes characters that work as wildcard characters in a LIKE pattern. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Runs the query against the database. Overrides SelectInterface:: |
2 |
SelectExtender:: |
public | function |
Sets a condition that the specified subquery returns values. Overrides ConditionInterface:: |
|
SelectExtender:: |
public | function |
Enhance this object by wrapping it in an extender object. Overrides ExtendableInterface:: |
|
SelectExtender:: |
public | function |
Add multiple fields from the same table to be SELECTed. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Add FOR UPDATE to the query. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Compiles and returns an associative array of the arguments for this prepared statement. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Returns a reference to the expressions array for this query. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Returns a reference to the fields array for this query. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Returns a reference to the group-by array for this query. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Retrieves a given piece of metadata. Overrides AlterableInterface:: |
|
SelectExtender:: |
public | function |
Returns a reference to the order by array for this query. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Returns a reference to the tables array for this query. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Returns a reference to the union queries for this query. This include
queries for UNION, UNION ALL, and UNION DISTINCT. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Groups the result set by the specified field. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Determines if a given query has all specified tags. Overrides AlterableInterface:: |
|
SelectExtender:: |
public | function |
Determines if a given query has any specified tag. Overrides AlterableInterface:: |
|
SelectExtender:: |
public | function |
Determines if a given query has a given tag. Overrides AlterableInterface:: |
|
SelectExtender:: |
public | function |
Adds an arbitrary HAVING clause to the query. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Gets a list of all values to insert into the HAVING clause. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Compiles the HAVING clause for later retrieval. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Helper function to build most common HAVING conditional clauses. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Gets a list of all conditions in the HAVING clause. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Sets a HAVING condition that the specified subquery returns values. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Sets a condition in the HAVING clause that the specified field be NOT NULL. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Sets a condition in the HAVING clause that the specified field be NULL. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Sets a HAVING condition that the specified subquery returns no values. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Inner Join against another table in the database. Overrides SelectInterface:: |
|
SelectExtender:: |
function |
Sets a condition that the specified field be NOT NULL. Overrides ConditionInterface:: |
||
SelectExtender:: |
function |
Sets a condition that the specified field be NULL. Overrides ConditionInterface:: |
||
SelectExtender:: |
public | function |
Indicates if preExecute() has already been called on that object. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Default Join against another table in the database. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Left Outer Join against another table in the database. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Returns the next placeholder ID for the query. Overrides PlaceholderInterface:: |
|
SelectExtender:: |
public | function |
Sets a condition that the specified subquery returns no values. Overrides ConditionInterface:: |
|
SelectExtender:: |
public | function |
Creates a new group of conditions ORed together. Overrides ConditionInterface:: |
|
SelectExtender:: |
public | function |
Orders the result set by a given field. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Orders the result set by a random value. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Generic preparation and validation for a SELECT query. Overrides SelectInterface:: |
1 |
SelectExtender:: |
public | function |
Restricts a query to a given range in the result set. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Right Outer Join against another table in the database. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Add another Select query to UNION to this one. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Returns a unique identifier for this object. Overrides PlaceholderInterface:: |
|
SelectExtender:: |
public | function |
Adds an arbitrary WHERE clause to the query. Overrides ConditionInterface:: |
|
SelectExtender:: |
public | function | Magic override for undefined methods. | |
SelectExtender:: |
public | function |
Clone magic method. Overrides SelectInterface:: |
|
SelectExtender:: |
public | function |
Returns a string representation of how the query will be executed in SQL. Overrides SelectInterface:: |
|
TableSortExtender:: |
protected | property | The array of fields that can be sorted by. | |
TableSortExtender:: |
protected | function | Compose a URL query parameter array to append to table sorting requests. | |
TableSortExtender:: |
protected | function | Determine the current sort direction. | |
TableSortExtender:: |
protected | function | Initialize the table sort context. | |
TableSortExtender:: |
protected | function | Determine the current sort criterion. | |
TableSortExtender:: |
public | function | Order the query based on a header array. | |
TableSortExtender:: |
public | function |
Overrides SelectExtender:: |