public function Xml::addWhere in Views XML Backend 8
Adds a simple WHERE clause to the query.
The caller is responsible for ensuring that all fields are fully qualified (TABLE.FIELD) and that the table already exists in the query.
Parameters
$group: The WHERE group to add these to; groups are used to create AND/OR sections. Groups cannot be nested. Use 0 as the default group. If the group does not yet exist it will be created as an AND group.
$field: The name of the field to check.
$value: The value to test the field against. In most cases, this is a scalar. For more complex options, it is an array. The meaning of each element in the array is dependent on the $operator.
$operator: The comparison operator, such as =, <, or >=. It also accepts more complex options such as IN, LIKE, LIKE BINARY, or BETWEEN. Defaults to =. If $field is a string you have to use 'formula' here.
File
- src/
Plugin/ views/ query/ Xml.php, line 323 - Contains \Drupal\views_xml_backend\Plugin\views\query\Xml.
Class
- Xml
- Views query plugin for an XML query.
Namespace
Drupal\views_xml_backend\Plugin\views\queryCode
public function addWhere($group, $field, $value = NULL, $operator = NULL) {
if ($group && $operator === 'in') {
if (strpos($field, '.') !== FALSE) {
list(, $field) = explode('.', $field);
}
if (!isset($this->view->field[$field])) {
return;
}
$xpath = $this->view->field[$field]->options['xpath_selector'];
$values = [];
foreach ($value as $v) {
$v = Xpath::escapeXpathString($v);
$values[] = "{$xpath} = {$v}";
}
$this->filters[] = implode(' or ', $values);
}
}