/
ParseQuery.php
1479 lines (1329 loc) · 43.3 KB
/
ParseQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Class ParseQuery | Parse/ParseQuery.php
*/
namespace Parse;
use Exception;
/**
* Class ParseQuery - Handles querying data from Parse.
*
* @author Fosco Marotto <fjm@fb.com>
* @package Parse
*/
class ParseQuery
{
/**
* Class name for data stored on Parse.
*
* @var string
*/
private $className;
/**
* Where constraints.
*
* @var array
*/
private $where = [];
/**
* Order By keys.
*
* @var array
*/
private $orderBy = [];
/**
* Include nested objects.
*
* @var array
*/
private $includes = [];
/**
* Exclude keys.
*
* @var array
*/
private $excludes = [];
/**
* Include certain keys only.
*
* @var array
*/
private $selectedKeys = [];
/**
* Skip from the beginning of the search results.
*
* @var int
*/
private $skip = 0;
/**
* Determines if the query is a count query or a results query.
*
* @var int
*/
private $count;
/**
* Limit of results, defaults to 100 when not explicitly set.
*
* @var int
*/
private $limit = -1;
/**
* The read preference for the main query.
*
* @var string
*/
private $readPreference;
/**
* The read preference for the queries to include pointers.
*
* @var string
*/
private $includeReadPreference;
/**
* The read preference for the sub queries.
*
* @var string
*/
private $subqueryReadPreference;
/**
* Create a Parse Query for a given Parse Class.
*
* @param mixed $className Class Name of data on Parse.
*/
public function __construct($className)
{
$this->className = $className;
}
/**
* Execute a query to retrieve a specific object.
*
* @param string $objectId Unique object id to retrieve.
* @param bool $useMasterKey If the query should use the master key
*
* @throws ParseException
*
* @return array|ParseObject Returns the selected object or an empty array
*/
public function get($objectId, $useMasterKey = false)
{
$this->equalTo('objectId', $objectId);
$result = $this->first($useMasterKey);
if (empty($result)) {
throw new ParseException('Object not found.', 101);
}
return $result;
}
/**
* Set a constraint for a field matching a given value.
*
* @param string $key Key to set up an equals constraint.
* @param mixed $value Value the key must equal.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function equalTo($key, $value)
{
$this->addCondition($key, '$eq', $value);
return $this;
}
/**
* Helper for condition queries.
*
* @param string $key The key to where constraints
* @param string $condition The condition name
* @param mixed $value The condition value, can be a string or an array of strings
*
* @throws Exception
*/
private function addCondition($key, $condition, $value)
{
if (!isset($this->where[$key])) {
$this->where[$key] = [];
}
$this->where[$key][$condition] = ParseClient::_encode($value, true);
}
/**
* Sets the conditions of this parse query from an array
*
* @param array $conditions Array of Conditions to set
* @throws ParseException
*/
public function _setConditions($conditions)
{
if (!is_array($conditions)) {
throw new ParseException("Conditions must be in an array");
}
// iterate over and add each condition
foreach ($conditions as $key => $entry) {
switch ($key) {
case 'where':
$this->where = $entry;
break;
case 'include':
$this->includes = explode(',', $entry);
break;
case 'excludeKeys':
$this->excludes = explode(',', $entry);
break;
case 'keys':
$this->selectedKeys = explode(',', $entry);
break;
case 'limit':
$this->limit = $entry;
break;
case 'readPreference':
$this->readPreference = $entry;
break;
case 'includeReadPreference':
$this->includeReadPreference = $entry;
break;
case 'subqueryReadPreference':
$this->subqueryReadPreference = $entry;
break;
// skip
case 'skip':
$this->skip = $entry;
break;
// orderBy
case 'order':
$this->orderBy = explode(',', $entry);
break;
// whether this query is for count or not
case 'count':
$this->count = $entry;
break;
default:
throw new ParseException("Unknown condition to set '{$key}''");
}
}
}
/**
* Add a constraint to the query that requires a particular key's value to
* be not equal to the provided value.
*
* @param string $key The key to check.
* @param mixed $value The value that must not be equalled.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function notEqualTo($key, $value)
{
$this->addCondition($key, '$ne', $value);
return $this;
}
/**
* Add a constraint to the query that requires a particular key's value to
* be less than the provided value.
*
* @param string $key The key to check.
* @param mixed $value The value that provides an Upper bound.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function lessThan($key, $value)
{
$this->addCondition($key, '$lt', $value);
return $this;
}
/**
* Add a constraint to the query that requires a particular key's value to
* be less than the provided relative time string.
*
* @param string $key The key to check
* @param string $relativeTime The relative time that provides an upper bound
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function lessThanRelativeTime($key, $relativeTime)
{
$this->lessThan($key, [
'$relativeTime' => $relativeTime
]);
return $this;
}
/**
* Add a constraint to the query that requires a particular key's value to
* be greater than the provided value.
*
* @param string $key The key to check.
* @param mixed $value The value that provides an Lower bound.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function greaterThan($key, $value)
{
$this->addCondition($key, '$gt', $value);
return $this;
}
/**
* Add a constraint to the query that requires a particular key's value to
* be greater than the provided relative time string.
*
* @param string $key The key to check
* @param string $relativeTime The relative time that provides a lower bound
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function greaterThanRelativeTime($key, $relativeTime)
{
$this->greaterThan($key, [
'$relativeTime' => $relativeTime
]);
return $this;
}
/**
* Add a constraint to the query that requires a particular key's value to
* be greater than or equal to the provided value.
*
* @param string $key The key to check.
* @param mixed $value The value that provides a lower bound.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function greaterThanOrEqualTo($key, $value)
{
$this->addCondition($key, '$gte', $value);
return $this;
}
/**
* Add a constraint to the query that requires a particular key's value to
* be greater than or equal to the provided relative time string.
*
* @param string $key The key to check.
* @param string $relativeTime The relative time that provides a lower bound
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function greaterThanOrEqualToRelativeTime($key, $relativeTime)
{
$this->greaterThanOrEqualTo($key, [
'$relativeTime' => $relativeTime
]);
return $this;
}
/**
* Add a constraint to the query that requires a particular key's value to
* be less than or equal to the provided value.
*
* @param string $key The key to check.
* @param mixed $value The value that provides an upper bound.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function lessThanOrEqualTo($key, $value)
{
$this->addCondition($key, '$lte', $value);
return $this;
}
/**
* Add a constraint to the query that requires a particular key's value to
* be less than or equal to the provided date string.
*
* @param string $key The key to check.
* @param string $relativeTime The relative time that provides an upper bound
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function lessThanOrEqualToRelativeTime($key, $relativeTime)
{
$this->lessThanOrEqualTo($key, [
'$relativeTime' => $relativeTime
]);
return $this;
}
/**
* Converts a string into a regex that matches it.
* Surrounding with \Q .. \E does this, we just need to escape \E's in
* the text separately.
*
* @param mixed $s The string or array being replaced.
*
* @return string Returns the string converted.
*/
private function quote($s)
{
return '\\Q'.str_replace('\\E', '\\E\\\\E\\Q', $s).'\\E';
}
/**
* Converts a string into a regex that matches it at the beginning
*
* @param mixed $s The string or array being replaced.
*
* @return string Returns the string converted.
*/
private function regexStartWith($s)
{
return '^' . $this->quote($s);
}
/**
* Add a constraint to the query that requires a particular key's value to
* start with the provided value.
*
* @param string $key The key to check.
* @param mixed $value The substring that the value must start with.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function startsWith($key, $value)
{
$this->addCondition($key, '$regex', $this->regexStartWith($value));
return $this;
}
/**
* Add a constraint to the query that requires a particular key's value to
* end with the provided value.
*
* @param string $key The key to check.
* @param mixed $value The substring that the value must end with.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function endsWith($key, $value)
{
$this->addCondition($key, '$regex', $this->quote($value).'$');
return $this;
}
/**
* Adds a constraint for finding string values that contain a provided
* string. This may be slow for large datasets.
*
* @param string $key The key to check.
* @param mixed $value The substring that the value must contain.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function contains($key, $value)
{
$this->addCondition($key, '$regex', $this->quote($value));
return $this;
}
/**
* Adds a constraint to the query that requires a particular key's value to
* be contained by the provided list of values. Get objects where all array elements match.
*
* @param string $key The key to check.
* @param mixed $value The values that will match.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function containedBy($key, $value)
{
$this->addCondition($key, '$containedBy', $value);
return $this;
}
/**
* Adds a constraint for finding string values that contain a provided
* string using Full Text Search
*
* @param string $key The key to check.
* @param mixed $value The substring that the value must contain.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function fullText($key, $value)
{
$this->addCondition(
$key,
'$text',
['$search' => ['$term' => $value]]
);
return $this;
}
/**
* Returns an associative array of the query constraints.
*
* @return array
*/
public function _getOptions()
{
$opts = [];
if (!empty($this->where)) {
$opts['where'] = $this->where;
}
if (count($this->includes)) {
$opts['include'] = implode(',', $this->includes);
}
if (count($this->excludes)) {
$opts['excludeKeys'] = implode(',', $this->excludes);
}
if (count($this->selectedKeys)) {
$opts['keys'] = implode(',', $this->selectedKeys);
}
if ($this->limit >= 0) {
$opts['limit'] = $this->limit;
}
if ($this->skip > 0) {
$opts['skip'] = $this->skip;
}
if ($this->orderBy) {
$opts['order'] = implode(',', $this->orderBy);
}
if ($this->count) {
$opts['count'] = $this->count;
}
if ($this->readPreference) {
$opts['readPreference'] = $this->readPreference;
}
if ($this->includeReadPreference) {
$opts['includeReadPreference'] = $this->includeReadPreference;
}
if ($this->subqueryReadPreference) {
$opts['subqueryReadPreference'] = $this->subqueryReadPreference;
}
return $opts;
}
/**
* Execute a query to get only the first result.
*
* @param bool $useMasterKey If the query should use the master key
* @param bool $decodeObjects If set to false, will return raw data instead of ParseObject instances
*
* @return array|ParseObject Returns the first object or an empty array
*/
public function first($useMasterKey = false, $decodeObjects = true)
{
$this->limit = 1;
$result = $this->find($useMasterKey, $decodeObjects);
if (count($result)) {
return $result[0];
} else {
return [];
}
}
/**
* Build query string from query constraints.
*
* @param array $queryOptions Associative array of the query constraints.
*
* @return string Query string.
*/
private function buildQueryString($queryOptions)
{
if (isset($queryOptions['where'])) {
$queryOptions['where'] = ParseClient::_encode($queryOptions['where'], true);
$queryOptions['where'] = json_encode($queryOptions['where']);
}
return http_build_query($queryOptions, '', '&');
}
/**
* Execute a count query and return the count.
*
* @param bool $useMasterKey If the query should use the master key
*
* @return int
*/
public function count($useMasterKey = false)
{
$sessionToken = null;
if (ParseUser::getCurrentUser()) {
$sessionToken = ParseUser::getCurrentUser()->getSessionToken();
}
$queryParams = $this->_getOptions();
$queryParams['limit'] = 0;
$queryParams['count'] = 1;
$queryString = $this->buildQueryString($queryParams);
$result = ParseClient::_request(
'GET',
'classes/'.$this->className.'?'.$queryString,
$sessionToken,
null,
$useMasterKey
);
return $result['count'];
}
/**
* The response will include the total number of objects satisfying this query,
* dispite limit / skip. Might be useful for pagination.
*
* Note: the results will be an object
* `results`: holding {ParseObject} array and `count`: integer holding total number
*
* @param bool $includeCount If response should include count, true by default.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function withCount($includeCount = true)
{
$this->count = (int)$includeCount;
return $this;
}
/**
* Execute a distinct query and return unique values.
*
* @param string $key field to find distinct values
*
* @return array
*/
public function distinct($key)
{
$sessionToken = null;
if ($user = ParseUser::getCurrentUser()) {
$sessionToken = $user->getSessionToken();
}
$opts = [];
if (!empty($this->where)) {
$opts['where'] = $this->where;
}
$opts['distinct'] = $key;
$queryString = $this->buildQueryString($opts);
$result = ParseClient::_request(
'GET',
'aggregate/'.$this->className.'?'.$queryString,
$sessionToken,
null,
true
);
return $result['results'];
}
/**
* Execute an aggregate query and returns aggregate results.
*
* @param array $pipeline stages to process query
*
* @return array
*/
public function aggregate($pipeline)
{
$sessionToken = null;
if ($user = ParseUser::getCurrentUser()) {
$sessionToken = $user->getSessionToken();
}
$stages = [];
foreach ($pipeline as $stage => $value) {
$stages[$stage] = json_encode($value);
}
$queryString = $this->buildQueryString($stages);
$result = ParseClient::_request(
'GET',
'aggregate/'.$this->className.'?'.$queryString,
$sessionToken,
null,
true
);
if (!isset($result['results'])) {
return [];
}
return $result['results'];
}
/**
* Execute a find query and return the results.
*
* @param bool $useMasterKey
* @param bool $decodeObjects If set to false, will return raw data instead of ParseObject instances
*
* @return ParseObject[]
*/
public function find($useMasterKey = false, $decodeObjects = true)
{
$sessionToken = null;
if (ParseUser::getCurrentUser()) {
$sessionToken = ParseUser::getCurrentUser()->getSessionToken();
}
$queryString = $this->buildQueryString($this->_getOptions());
$result = ParseClient::_request(
'GET',
'classes/'.$this->className.'?'.$queryString,
$sessionToken,
null,
$useMasterKey
);
$response = [];
if (isset($result['count'])) {
$response['count'] = $result['count'];
$response['results'] = $this->handleQueryResult($result, $decodeObjects);
return $response;
}
return $this->handleQueryResult($result, $decodeObjects);
}
/**
* Handles result from ParseClient::_request
*
* @param array $result Array of ParseObject raw data.
* @param bool $decodeObjects If set to false, will return raw data instead of ParseObject instances
*
* @return Array Array of ParseObjects or raw data.
*/
public function handleQueryResult($result, $decodeObjects)
{
if (!isset($result['results'])) {
return [];
}
if (!$decodeObjects) {
return $result['results'];
}
$output = [];
foreach ($result['results'] as $row) {
$obj = ParseObject::create($this->className, $row['objectId']);
$obj->_mergeAfterFetchWithSelectedKeys($row, $this->selectedKeys);
$output[] = $obj;
}
return $output;
}
/**
* Set the skip parameter as a query constraint.
*
* @param int $n Number of objects to skip from start of results.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function skip($n)
{
$this->skip = $n;
return $this;
}
/**
* Set the limit parameter as a query constraint.
*
* @param int $n Number of objects to return from the query.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function limit($n)
{
$this->limit = $n;
return $this;
}
/**
* Set the query orderBy to ascending for the given key(s). It overwrites the
* existing order criteria.
*
* @param mixed $key Key(s) to sort by, which is a string or an array of strings.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function ascending($key)
{
$this->orderBy = [];
return $this->addAscending($key);
}
/**
* Set the query orderBy to ascending for the given key(s). It can also add
* secondary sort descriptors without overwriting the existing order.
*
* @param mixed $key Key(s) to sort by, which is a string or an array of strings.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function addAscending($key)
{
if (is_array($key)) {
$this->orderBy = array_merge($this->orderBy, $key);
} else {
$this->orderBy[] = $key;
}
return $this;
}
/**
* Set the query orderBy to descending for a given key(s). It overwrites the
* existing order criteria.
*
* @param mixed $key Key(s) to sort by, which is a string or an array of strings.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function descending($key)
{
$this->orderBy = [];
return $this->addDescending($key);
}
/**
* Set the query orderBy to descending for a given key(s). It can also add
* secondary sort descriptors without overwriting the existing order.
*
* @param mixed $key Key(s) to sort by, which is a string or an array of strings.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function addDescending($key)
{
if (is_array($key)) {
$key = array_map(
function ($element) {
return '-'.$element;
},
$key
);
$this->orderBy = array_merge($this->orderBy, $key);
} else {
$this->orderBy[] = '-'.$key;
}
return $this;
}
/**
* Add a proximity based constraint for finding objects with key point
* values near the point given.
*
* @param string $key The key that the ParseGeoPoint is stored in.
* @param ParseGeoPoint $point The reference ParseGeoPoint that is used.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function near($key, $point)
{
$this->addCondition($key, '$nearSphere', $point);
return $this;
}
/**
* Add a proximity based constraint for finding objects with key point
* values near the point given and within the maximum distance given.
*
* @param string $key The key of the ParseGeoPoint
* @param ParseGeoPoint $point The ParseGeoPoint that is used.
* @param int $maxDistance Maximum distance (in radians)
* @param bool $sort Return objects sorted by distance
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function withinRadians($key, $point, $maxDistance, $sort = true)
{
if ($sort) {
$this->near($key, $point);
$this->addCondition($key, '$maxDistance', $maxDistance);
} else {
$this->addCondition(
$key,
'$geoWithin',
[
'$centerSphere' => [
[$point->getLongitude(), $point->getLatitude()],
$maxDistance
]
]
);
}
return $this;
}
/**
* Add a proximity based constraint for finding objects with key point
* values near the point given and within the maximum distance given.
* Radius of earth used is 3958.8 miles.
*
* @param string $key The key of the ParseGeoPoint
* @param ParseGeoPoint $point The ParseGeoPoint that is used.
* @param int $maxDistance Maximum distance (in miles)
* @param bool $sort Return objects sorted by distance
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function withinMiles($key, $point, $maxDistance, $sort = true)
{
return $this->withinRadians($key, $point, $maxDistance / 3958.8, $sort);
}
/**
* Add a proximity based constraint for finding objects with key point
* values near the point given and within the maximum distance given.
* Radius of earth used is 6371.0 kilometers.
*
* @param string $key The key of the ParseGeoPoint
* @param ParseGeoPoint $point The ParseGeoPoint that is used.
* @param int $maxDistance Maximum distance (in kilometers)
* @param bool $sort Return objects sorted by distance
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function withinKilometers($key, $point, $maxDistance, $sort = true)
{
return $this->withinRadians($key, $point, $maxDistance / 6371.0, $sort);
}
/**
* Add a constraint to the query that requires a particular key's
* coordinates be contained within a given rectangular geographic bounding
* box.
*
* @param string $key The key of the ParseGeoPoint
* @param ParseGeoPoint $southwest The lower-left corner of the box.
* @param ParseGeoPoint $northeast The upper-right corner of the box.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function withinGeoBox($key, $southwest, $northeast)
{
$this->addCondition(
$key,
'$within',
['$box' => [$southwest, $northeast]]
);
return $this;
}
/**
* Add a constraint to the query that requires a particular key's
* coordinates be contained within and on the bounds of a given polygon
* Supports closed and open (last point is connected to first) paths
*
* Polygon must have at least 3 points
*
* @param string $key The key of the ParseGeoPoint
* @param array $points Array of ParseGeoPoint
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function withinPolygon($key, $points)
{
$this->addCondition(
$key,
'$geoWithin',
['$polygon' => $points]
);
return $this;
}
/**
* Add a constraint to the query that requires a particular key's
* coordinates that contains a ParseGeoPoint
*
* @param string $key The key of the ParsePolygon
* @param ParseGeoPoint $point The point that will be contained.
*
* @return ParseQuery Returns this query, so you can chain this call.
*/
public function polygonContains($key, $point)
{
$this->addCondition(
$key,
'$geoIntersects',
['$point' => $point]
);
return $this;
}
/**
* Add a constraint to the query that requires a particular key's value to
* be contained in the provided list of values.
*
* @param string $key The key to check.
* @param array $values The values that will match.
*
* @return ParseQuery Returns the query, so you can chain this call.
*/
public function containedIn($key, $values)
{