Skip to content

Commit 2c72b38

Browse files
authored
Merge pull request #347 from ethercreative/v4-dev
V4 dev
2 parents 31657b0 + c4ff2dd commit 2c72b38

5 files changed

Lines changed: 16 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.0.2 - 2022-06-08
2+
### Fixed
3+
- Misc fixes via @davidwebca & @jamesedmonston
4+
15
## 4.0.1 - 2022-05-18
26
### Fixed
37
- Fix Geo Location Token only allowing string (Fixes #343)

src/integrations/graphql/MapType.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ public static function getQueryInputDefinitions (): array
103103

104104
public static function getType (): Type
105105
{
106-
if ($type = GqlEntityRegistry::getEntity(static::class))
106+
if ($type = GqlEntityRegistry::getEntity(static::getName()))
107107
return $type;
108108

109109
return GqlEntityRegistry::createEntity(
110-
static::class,
110+
static::getName(),
111111
new ObjectType([
112112
'name' => static::getName(),
113113
'fields' => static::class . '::getFieldDefinitions',
@@ -117,7 +117,7 @@ public static function getType (): Type
117117

118118
public static function getInputType (): InputType
119119
{
120-
$name = static::class . 'Input';
120+
$name = static::getName() . 'Input';
121121

122122
if ($type = GqlEntityRegistry::getEntity($name))
123123
return $type;
@@ -133,7 +133,7 @@ public static function getInputType (): InputType
133133

134134
public static function getQueryType (): InputType
135135
{
136-
$name = static::class . 'Query';
136+
$name = static::getName() . 'Query';
137137

138138
if ($type = GqlEntityRegistry::getEntity($name))
139139
return $type;
@@ -149,7 +149,7 @@ public static function getQueryType (): InputType
149149

150150
public static function getCoordsType (): InputType
151151
{
152-
$name = static::class . 'Coords';
152+
$name = static::getName() . 'Coords';
153153

154154
if ($type = GqlEntityRegistry::getEntity($name))
155155
return $type;
@@ -174,7 +174,7 @@ public static function getCoordsType (): InputType
174174

175175
public static function getUnitType (): EnumType
176176
{
177-
$name = static::class . 'Unit';
177+
$name = static::getName() . 'Unit';
178178

179179
if ($type = GqlEntityRegistry::getEntity($name))
180180
return $type;

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)