public function GeolocationContains::buildJoin in Geolocation Field 8.3
Builds the SQL for the join this object represents.
When possible, try to use table alias instead of table names.
Parameters
$select_query: An select query object.
$table: The base table to join.
\Drupal\views\Plugin\views\query\QueryPluginBase $view_query: The source views query.
Overrides JoinPluginBase::buildJoin
File
- modules/
geolocation_geometry/ src/ Plugin/ views/ join/ GeolocationContains.php, line 20
Class
- GeolocationContains
- Geometry joins.
Namespace
Drupal\geolocation_geometry\Plugin\views\joinCode
public function buildJoin($select_query, $table, $view_query) {
/** @var \Drupal\Core\Database\Query\Select $select_query */
$geometry_field = $table['alias'] . '.' . $this->field . '_geometry';
$latitude_field = $this->leftTable . '.' . $this->leftField . '_lat';
$longitude_field = $this->leftTable . '.' . $this->leftField . '_lng';
$condition = "ST_Contains(" . $geometry_field . ", ST_PointFromText(CONCAT('POINT(', " . $longitude_field . ", ' ', " . $latitude_field . ", ')'), 4326))";
$select_query
->addJoin($this->type, $this->table, $table['alias'], $condition);
}