class QueryTest in Views (for Drupal 7) 8.3
Same name in this branch
- 8.3 lib/Drupal/views/Tests/Plugin/QueryTest.php \Drupal\views\Tests\Plugin\QueryTest
- 8.3 tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/query/QueryTest.php \Drupal\views_test_data\Plugin\views\query\QueryTest
Defines a query test plugin.
Plugin annotation
@Plugin(
id = "query_test",
title = @Translation("Query test")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\query\QueryPluginBase implements QueryInterface
- class \Drupal\views_test_data\Plugin\views\query\QueryTest
- class \Drupal\views\Plugin\views\query\QueryPluginBase implements QueryInterface
- class \Drupal\views\Plugin\views\PluginBase
Expanded class hierarchy of QueryTest
1 file declares its use of QueryTest
- QueryTest.php in lib/
Drupal/ views/ Tests/ Plugin/ QueryTest.php - Definition of Drupal\views\Tests\Plugin\QueryTest.
File
- tests/
views_test_data/ lib/ Drupal/ views_test_data/ Plugin/ views/ query/ QueryTest.php, line 24 - Definition of Drupal\views_test_data\Plugin\views\query\QueryTest.
Namespace
Drupal\views_test_data\Plugin\views\queryView source
class QueryTest extends QueryPluginBase {
protected $conditions = array();
protected $fields = array();
protected $allItems = array();
protected $orderBy = array();
/**
* Sets the allItems property.
*
* @param array $allItems
* An array of stdClasses.
*/
public function setAllItems($allItems) {
$this->allItems = $allItems;
}
public function add_where($group, $field, $value = NULL, $operator = NULL) {
$this->conditions[] = array(
'field' => $field,
'value' => $value,
'operator' => $operator,
);
}
public function add_field($table, $field, $alias = '', $params = array()) {
$this->fields[$field] = $field;
return $field;
}
public function add_orderby($table, $field = NULL, $order = 'ASC', $alias = '', $params = array()) {
$this->orderBy = array(
'field' => $field,
'order' => $order,
);
}
public function ensure_table($table, $relationship = NULL, JoinPluginBase $join = NULL) {
// There is no concept of joins.
}
/**
* Implements Drupal\views\Plugin\views\query\QueryPluginBase::build().
*
* @param Drupal\views\ViewExecutable $view
*/
public function build(ViewExecutable $view) {
$this->view = $view;
// @todo Support pagers for know, a php based one would probably match.
// @todo You could add a string representatin of the query.
$this->view->build_info['query'] = "";
$this->view->build_info['count_query'] = "";
}
/**
* Implements Drupal\views\Plugin\views\query\QueryPluginBase::execute().
*/
public function execute(ViewExecutable $view) {
$result = array();
foreach ($this->allItems as $element) {
// Run all conditions on the element, and add it to the result if they
// match.
$match = TRUE;
foreach ($this->conditions as $condition) {
$match &= $this
->match($element, $condition);
}
if ($match) {
// If the query explicit defines fields to use, filter all others out.
// Filter out fields
if ($this->fields) {
$element = array_intersect_key($element, $this->fields);
}
$result[] = (object) $element;
}
}
$this->view->result = $result;
}
/**
* Check a single condition for a single element.
*
* @param array $element
* The element which should be checked.
* @param array $condition
* An associative array containing:
* - field: The field to by, for example id.
* - value: The expected value of the element.
* - operator: The operator to compare the element value with the expected
* value.
*
* @return bool
* Returns whether the condition matches with the element.
*/
public function match($element, $condition) {
$value = $element[$condition['field']];
switch ($condition['operator']) {
case '=':
return $value == $condition['value'];
case 'IN':
return in_array($value, $condition['value']);
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
public | property | Plugins's definition | |
PluginBase:: |
public | property | The display object this plugin is for. | |
PluginBase:: |
public | property | Options for this plugin will be held here. | |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
protected | property | Denotes whether the plugin has an additional options form. | 8 |
PluginBase:: |
public | property | The top object of a view. | 1 |
PluginBase:: |
public | function | Provide a list of additional theme functions for the theme information page | |
PluginBase:: |
public | function | Provide a form to edit options for this plugin. | 14 |
PluginBase:: |
protected | function | Information about options for all kinds of purposes will be held here. @code 'option_name' => array( | 13 |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function | Clears a plugin. | 2 |
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Return the human readable name of the display. | |
PluginBase:: |
protected | function | ||
PluginBase:: |
public | function | Provide a full list of possible theme templates used by this style. | 1 |
PluginBase:: |
public | function | Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away. | |
PluginBase:: |
public | function | Returns the usesOptions property. | 8 |
PluginBase:: |
public | function | Validate that the plugin is correct and can be saved. | 4 |
PluginBase:: |
public | function |
Constructs a Plugin object. Overrides PluginBase:: |
2 |
QueryPluginBase:: |
property | A pager plugin that should be provided by the display. | ||
QueryPluginBase:: |
function | Add a signature to the query, if such a thing is feasible. | 1 | |
QueryPluginBase:: |
function | Let modules modify the query just prior to finalizing it. | 1 | |
QueryPluginBase:: |
function | Get aggregation info for group by queries. | 1 | |
QueryPluginBase:: |
public | function | Constructor; Create the basic query object and fill with default values. | 1 |
QueryPluginBase:: |
function | Loads all entities contained in the passed-in $results. . If the entity belongs to the base table, then it gets stored in $result->_entity. Otherwise, it gets stored in $result->_relationship_entities[$relationship_id]; | 1 | |
QueryPluginBase:: |
public | function |
Generate a query and a countquery from all of the information supplied
to the object. Overrides PluginBase:: |
1 |
QueryPluginBase:: |
function | Control how all WHERE and HAVING groups are put together. | ||
QueryPluginBase:: |
function | Set a LIMIT on the query, specifying a maximum number of results. | ||
QueryPluginBase:: |
function | Set an OFFSET on the query, specifying a number of results to skip | ||
QueryPluginBase:: |
function | Create a new grouping for the WHERE or HAVING clause. | ||
QueryPluginBase:: |
public | function |
Handle any special handling on the validate form. Overrides PluginBase:: |
1 |
QueryPluginBase:: |
public | function |
Returns the summary of the settings in the display. Overrides PluginBase:: |
|
QueryPluginBase:: |
public | function |
Validate the options form. Overrides PluginBase:: |
|
QueryTest:: |
protected | property | ||
QueryTest:: |
protected | property | ||
QueryTest:: |
protected | property | ||
QueryTest:: |
protected | property | ||
QueryTest:: |
public | function | ||
QueryTest:: |
public | function | ||
QueryTest:: |
public | function | ||
QueryTest:: |
public | function |
Implements Drupal\views\Plugin\views\query\QueryPluginBase::build(). Overrides QueryPluginBase:: |
|
QueryTest:: |
public | function | ||
QueryTest:: |
public | function |
Implements Drupal\views\Plugin\views\query\QueryPluginBase::execute(). Overrides QueryPluginBase:: |
|
QueryTest:: |
public | function | Check a single condition for a single element. | |
QueryTest:: |
public | function | Sets the allItems property. |