Skip to content

Commit 8b5ff0c

Browse files
authored
Merge pull request #342 from davidwebca/v4-dev
Fixes for Craft 4
2 parents b0e1428 + 68d443c commit 8b5ff0c

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

src/models/UserLocation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function distance (array $to, string $unit = 'km'): float|int
6060
// Coordinates
6161
$to = GeoService::normalizeLocation($to);
6262

63-
if ($to === null)
63+
if (empty($to))
6464
throw new InvalidConfigException('Invalid target lat/lng');
6565

6666
$targetLat = $to['lat'];

src/services/GeoService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ public static function normalizeLocation (mixed $location, string $country = nul
678678
else if ($location instanceof Map)
679679
$location = ['lat' => $location->lat, 'lng' => $location->lng];
680680
else if (!is_array($location) || !isset($location['lat'], $location['lng']))
681-
$location = null;
681+
$location = [];
682682

683683
return $location;
684684
}

src/services/MapService.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,9 @@ public function getDistance (Map $map): float|int|null
165165
*/
166166
public function modifyElementsQuery (ElementQueryInterface $query, mixed $value, MapField $field)
167167
{
168-
if (empty($value))
168+
if (is_null($value))
169169
return;
170170

171-
172171
// Work-around for Craft built-in GraphQL not supporting custom
173172
// arguments for fields:
174173

@@ -318,7 +317,7 @@ private function _searchLocation (ElementQuery $query, mixed $value, string $tab
318317
$location = GeoService::normalizeLocation($location, $country);
319318

320319
// If we don't have a location, reduce the search radius to 0
321-
if ($location === null)
320+
if (empty($location))
322321
{
323322
$location = ['lat' => 0, 'lng' => 0];
324323
$radius = 0;
@@ -398,13 +397,13 @@ private function _searchLocation (ElementQuery $query, mixed $value, string $tab
398397
* @param ElementQuery $query
399398
* @param bool $search
400399
*/
401-
private function _replaceOrderBy (ElementQuery $query, bool $search = false)
400+
private function _replaceOrderBy (ElementQuery $query, string $search = "")
402401
{
403402
$nextOrder = [];
404403

405404
foreach ((array) $query->orderBy as $order => $sort)
406405
{
407-
if ($order === 'distance' && $search) $nextOrder[$search] = $sort;
406+
if ($order === 'distance' && !empty($search)) $nextOrder[$search] = $sort;
408407
elseif ($order !== 'distance') $nextOrder[$order] = $sort;
409408
}
410409

0 commit comments

Comments
 (0)