Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Core/Search/Legacy/Content/Common/Gateway/SortClauseHandler/MapLocationDistance.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler;
8
9 use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
10 use eZ\Publish\Core\Persistence\Database\SelectQuery;
11 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
12 use PDO;
13
17 class MapLocationDistance extends Field
18 {
26 public function accept(SortClause $sortClause)
27 {
28 return $sortClause instanceof SortClause\MapLocationDistance;
29 }
30
43 public function applySelect(SelectQuery $query, SortClause $sortClause, $number)
44 {
46 $target = $sortClause->targetData;
47 $externalTable = $this->getSortTableName($number, 'ezgmaplocation');
48
49 /*
50 * Note: this formula is precise only for short distances.
51 */
52 $longitudeCorrectionByLatitude = cos(deg2rad($target->latitude)) ** 2;
53 $distanceExpression = $query->expr->add(
54 $query->expr->mul(
55 $query->expr->sub(
56 $this->dbHandler->quoteColumn('latitude', $externalTable),
57 $query->bindValue($target->latitude)
58 ),
59 $query->expr->sub(
60 $this->dbHandler->quoteColumn('latitude', $externalTable),
61 $query->bindValue($target->latitude)
62 )
63 ),
64 $query->expr->mul(
65 $query->expr->sub(
66 $this->dbHandler->quoteColumn('longitude', $externalTable),
67 $query->bindValue($target->longitude)
68 ),
69 $query->expr->sub(
70 $this->dbHandler->quoteColumn('longitude', $externalTable),
71 $query->bindValue($target->longitude)
72 ),
73 $query->bindValue($longitudeCorrectionByLatitude)
74 )
75 );
76
77 $query->select(
78 $query->alias(
79 $distanceExpression,
80 $column1 = $this->getSortColumnName($number)
81 )
82 );
83
84 return [$column1];
85 }
86
95 public function applyJoin(
96 SelectQuery $query,
97 SortClause $sortClause,
98 $number,
99 array $languageSettings
100 ) {
102 $fieldTarget = $sortClause->targetData;
103 $fieldMap = $this->contentTypeHandler->getSearchableFieldMap();
104
105 if (!isset($fieldMap[$fieldTarget->typeIdentifier][$fieldTarget->fieldIdentifier]['field_definition_id'])) {
106 throw new InvalidArgumentException(
107 '$sortClause->targetData',
108 'No searchable fields found for the given sort clause target ' .
109 "'{$fieldTarget->fieldIdentifier}' on '{$fieldTarget->typeIdentifier}'."
110 );
111 }
112
113 $fieldDefinitionId = $fieldMap[$fieldTarget->typeIdentifier][$fieldTarget->fieldIdentifier]['field_definition_id'];
114 $table = $this->getSortTableName($number);
115 $externalTable = $this->getSortTableName($number, 'ezgmaplocation');
116
117 $query
118 ->leftJoin(
119 $query->alias(
120 $this->dbHandler->quoteTable('ezcontentobject_attribute'),
121 $this->dbHandler->quoteIdentifier($table)
122 ),
123 $query->expr->lAnd(
124 $query->expr->eq(
125 $query->bindValue($fieldDefinitionId, null, PDO::PARAM_INT),
126 $this->dbHandler->quoteColumn('contentclassattribute_id', $table)
127 ),
128 $query->expr->eq(
129 $this->dbHandler->quoteColumn('contentobject_id', $table),
130 $this->dbHandler->quoteColumn('id', 'ezcontentobject')
131 ),
132 $query->expr->eq(
133 $this->dbHandler->quoteColumn('version', $table),
134 $this->dbHandler->quoteColumn('current_version', 'ezcontentobject')
135 ),
136 $this->getFieldCondition($query, $languageSettings, $table)
137 )
138 )
139 ->leftJoin(
140 $query->alias(
141 $this->dbHandler->quoteTable('ezgmaplocation'),
142 $this->dbHandler->quoteIdentifier($externalTable)
143 ),
144 $query->expr->lAnd(
145 $query->expr->eq(
146 $this->dbHandler->quoteColumn('contentobject_version', $externalTable),
147 $this->dbHandler->quoteColumn('version', $table)
148 ),
149 $query->expr->eq(
150 $this->dbHandler->quoteColumn('contentobject_attribute_id', $externalTable),
151 $this->dbHandler->quoteColumn('id', $table)
152 )
153 )
154 );
155 }
156 }
eZ\Publish\API\Repository\Values\Content\Query\SortClause\Field
Sets sort direction on a field value for a content query.
Definition: API/Repository/Values/Content/Query/SortClause/Field.php:26
eZ\Publish\API\Repository\Values\Content\Query\SortClause\MapLocationDistance
Sets sort direction on the MapLocation distance for a content query.
Definition: API/Repository/Values/Content/Query/SortClause/MapLocationDistance.php:18
eZ\Publish\API\Repository\Values\Content\Query\SortClause
This class is the base for SortClause classes, used to set sorting of content queries.
Definition: Content/Query/SortClause.php:16
eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
Invalid Argument Type Exception implementation.
Definition: Core/Base/Exceptions/InvalidArgumentException.php:20
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler\Field\applySelect
applySelect(SelectQuery $query, SortClause $sortClause, $number)
Apply selects to the query.
Definition: Core/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php:80
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler\MapLocationDistance\accept
accept(SortClause $sortClause)
Check if this sort clause handler accepts to handle the given sort clause.
Definition: Core/Search/Legacy/Content/Common/Gateway/SortClauseHandler/MapLocationDistance.php:26
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler\getSortTableName
getSortTableName($number, $externalTableName=null)
Returns the sort table name.
Definition: SortClauseHandler.php:96
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler\applyJoin
applyJoin(SelectQuery $query, SortClause $sortClause, $number, array $languageSettings)
Applies joins to the query.
Definition: SortClauseHandler.php:68
eZ\Publish\Core\Persistence\Database\Query\bindValue
bindValue($value, $placeHolder=null, $type=PDO::PARAM_STR)
Binds the value $value to the specified variable name $placeHolder.
eZ\Publish\Core\Persistence\Database\SelectQuery
Definition: SelectQuery.php:16
eZ\Publish\Core\Persistence\Database\SelectQuery\leftJoin
leftJoin()
Returns the SQL for a left join or prepares $fromString for a left join.
eZ\Publish\Core\Persistence\Database\SelectQuery\alias
alias($name, $alias)
Returns SQL to create an alias.
eZ\Publish\Core\Persistence\Database\SelectQuery\select
select()
Opens the query and selects which columns you want to return with the query.
eZ\Publish\API\Repository\Values\Content\Query\SortClause
Definition: API/Repository/Values/Content/Query/SortClause/ContentId.php:7
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler
Definition: Core/Search/Legacy/Content/Common/Gateway/SortClauseHandler/ContentId.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.