-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathAddressQuery.php
More file actions
1056 lines (981 loc) · 29.4 KB
/
AddressQuery.php
File metadata and controls
1056 lines (981 loc) · 29.4 KB
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
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\elements\db;
use Craft;
use craft\db\QueryAbortedException;
use craft\db\Table;
use craft\elements\Address;
use craft\helpers\Db;
use yii\db\Expression;
/**
* AddressQuery represents a SELECT SQL statement for categories in a way that is independent of DBMS.
*
* @template TKey of array-key
* @template TElement of Address
* @extends ElementQuery<TKey,TElement>
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 4.0.0
* @doc-path addresses.md
* @replace {element} address
* @replace {elements} addresses
* @replace {twig-method} craft.addresses()
* @replace {myElement} myAddress
* @replace {element-class} \craft\elements\Address
*/
class AddressQuery extends ElementQuery implements NestedElementQueryInterface
{
use NestedElementQueryTrait {
cacheTags as nestedTraitCacheTags;
}
/**
* @var mixed The address countryCode(s) that the resulting address must be in.
* ---
* ```php
* // fetch addresses that are located in AU
* $addresses = \craft\elements\Address::find()
* ->countryCode('AU')
* ->all();
* ```
* ```twig
* {# fetch addresses that are located in AU #}
* {% set addresses = craft.addresses()
* .countryCode('AU')
* .all() %}
* ```
* @used-by countryCode()
* @since 5.0.0
*/
public mixed $countryCode = null;
/**
* @var mixed Narrows the query results based on the administrative areas the addresses belongs to.
* ---
* ```php
* // fetch addresses that are located in Western Australia
* $addresses = \craft\elements\Address::find()
* ->administrativeArea('WA')
* ->all();
* ```
* ```twig
* {# fetch addresses that are located in Western Australia #}
* {% set addresses = craft.addresses()
* .administrativeArea('WA')
* .all() %}
* ```
* @used-by administrativeArea()
* @since 5.0.0
*/
public mixed $administrativeArea = null;
/**
* @var string|null Narrows the query results based on the locality the addresses belong to.
* ---
* ```php
* // fetch addresses by locality
* $addresses = \craft\elements\Address::find()
* ->locality('Perth')
* ->all();
* ```
* ```twig
* {# fetch addresses by locality #}
* {% set addresses = craft.addresses()
* .locality('Perth')
* .all() %}
* ```
* @used-by locality()
* @since 5.0.0
*/
public ?string $locality = null;
/**
* @var string|null Narrows the query results based on the dependent locality the addresses belong to.
* ---
* ```php
* // fetch addresses by dependent locality
* $addresses = \craft\elements\Address::find()
* ->dependentLocality('Darlington')
* ->all();
* ```
* ```twig
* {# fetch addresses by dependent locality #}
* {% set addresses = craft.addresses()
* .dependentLocality('Darlington')
* .all() %}
* ```
* @used-by dependentLocality()
* @since 5.0.0
*/
public ?string $dependentLocality = null;
/**
* @var string|null Narrows the query results based on the postal code the addresses belong to.
* ---
* ```php
* // fetch addresses by postal code
* $addresses = \craft\elements\Address::find()
* ->postalCode('10001')
* ->all();
* ```
* ```twig
* {# fetch addresses by postal code #}
* {% set addresses = craft.addresses()
* .postalCode('10001')
* .all() %}
* ```
* @used-by postalCode()
* @since 5.0.0
*/
public ?string $postalCode = null;
/**
* @var string|null Narrows the query results based on the sorting code the addresses have.
* ---
* ```php
* // fetch addresses by sorting code
* $addresses = \craft\elements\Address::find()
* ->sortingCode('ABCD')
* ->all();
* ```
* ```twig
* {# fetch addresses by sorting code #}
* {% set addresses = craft.addresses()
* .sortingCode('ABCD')
* .all() %}
* ```
* @used-by sortingCode()
* @since 5.0.0
*/
public ?string $sortingCode = null;
/**
* @var string|null Narrows the query results based on the organization the addresses have.
* ---
* ```php
* // fetch addresses by organization
* $addresses = \craft\elements\Address::find()
* ->organization('Pixel & Tonic')
* ->all();
* ```
* ```twig
* {# fetch addresses by organization #}
* {% set addresses = craft.addresses()
* .organization('Pixel & Tonic')
* .all() %}
* ```
* @used-by organization()
* @since 5.0.0
*/
public ?string $organization = null;
/**
* @var string|null Narrows the query results based on the tax ID the addresses have.
* ---
* ```php
* // fetch addresses by organization tax ID
* $addresses = \craft\elements\Address::find()
* ->organizationTaxId('123-456-789')
* ->all();
* ```
* ```twig
* {# fetch addresses by organization tax ID #}
* {% set addresses = craft.addresses()
* .organizationTaxId('123-456-789')
* .all() %}
* ```
* @used-by organizationTaxId()
* @since 5.0.0
*/
public ?string $organizationTaxId = null;
/**
* @var string|null Narrows the query results based on the first address line the addresses have.
* ---
* ```php
* // fetch addresses by address line 1
* $addresses = \craft\elements\Address::find()
* ->addressLine1('23 Craft st')
* ->all();
* ```
* ```twig
* {# fetch addresses by address line 1 #}
* {% set addresses = craft.addresses()
* .addressLine1('23 Craft st')
* .all() %}
* ```
* @used-by addressLine1()
* @since 5.0.0
*/
public ?string $addressLine1 = null;
/**
* @var string|null Narrows the query results based on the second address line the addresses have.
* ---
* ```php
* // fetch addresses by address line 2
* $addresses = \craft\elements\Address::find()
* ->addressLine2('Apt 5B')
* ->all();
* ```
* ```twig
* {# fetch addresses by address line 2 #}
* {% set addresses = craft.addresses()
* .addressLine2('Apt 5B')
* .all() %}
* ```
* @used-by addressLine2()
* @since 5.0.0
*/
public ?string $addressLine2 = null;
/**
* @var string|null Narrows the query results based on the third address line the addresses have.
* ---
* ```php
* // fetch addresses by address line 3
* $addresses = \craft\elements\Address::find()
* ->addressLine3('Suite 212')
* ->all();
* ```
* ```twig
* {# fetch addresses by address line 3 #}
* {% set addresses = craft.addresses()
* .addressLine3('Suite 212')
* .all() %}
* ```
* @used-by addressLine3()
* @since 5.0.0
*/
public ?string $addressLine3 = null;
/**
* @var string|null Narrows the query results based on the full name the addresses have.
* ---
* ```php
* // fetch addresses by full name
* $addresses = \craft\elements\Address::find()
* ->fullName('John Doe')
* ->all();
* ```
* ```twig
* {# fetch addresses by full name #}
* {% set addresses = craft.addresses()
* .fullName('John Doe')
* .all() %}
* ```
* @used-by fullName()
* @since 5.0.0
*/
public ?string $fullName = null;
/**
* @var string|null Narrows the query results based on the first name the addresses have.
* ---
* ```php
* // fetch addresses by first name
* $addresses = \craft\elements\Address::find()
* ->firstName('Doe')
* ->all();
* ```
* ```twig
* {# fetch addresses by first name #}
* {% set addresses = craft.addresses()
* .firstName('Doe')
* .all() %}
* ```
* @used-by firstName()
* @since 5.0.0
*/
public ?string $firstName = null;
/**
* @var string|null Narrows the query results based on the last name the addresses have.
* ---
* ```php
* // fetch addresses by last name
* $addresses = \craft\elements\Address::find()
* ->lastName('Doe')
* ->all();
* ```
* ```twig
* {# fetch addresses by last name #}
* {% set addresses = craft.addresses()
* .lastName('Doe')
* .all() %}
* ```
* @used-by lastName()
* @since 5.0.0
*/
public ?string $lastName = null;
/**
* @var null|array Narrows the query results based on the distance to a set of coordinates.
* ---
* ```php
* // Fetch addresses by distance to the given coordinates
* $addresses = \craft\elements\Address::find()
* ->distanceTo(['latitude' => 44.0473,'longitude' => -121.3338])
* ->all();
* ```
* ```twig
* {# Fetch addresses by distance to the given coordinates #}
* {% set addresses = craft.addresses()
* .distanceTo({ latitude: 44.0473, longitude: -121.3338 })
* .all() %}
* ```
*
* @used-by distanceTo()
*/
public ?array $distanceTo = null;
/**
* Narrows the query results based on the country the addresses belong to.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'AU'` | with a countryCode of `AU`.
* | `'not US'` | not in a countryCode of `US`.
* | `['AU', 'US']` | in a countryCode of `AU` or `US`.
* | `['not', 'AU', 'US']` | not in a countryCode of `AU` or `US`.
*
* ---
*
* ```twig
* {# Fetch Australian addresses #}
* {% set {elements-var} = {twig-method}
* .countryCode('AU')
* .all() %}
* ```
*
* ```php
* // Fetch Australian addresses
* ${elements-var} = {php-method}
* ->countryCode('AU')
* ->all();
* ```
*
* @param string|string[]|null $value The property value
* @return static self reference
* @uses $countryCode
*/
public function countryCode(array|string|null $value): static
{
$this->countryCode = $value;
return $this;
}
/**
* Narrows the query results based on the administrative areas the addresses belongs to.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'WA'` | with a administrative area of `WA`.
* | `'not WA'` | not in a administrative area of `WA`.
* | `['WA', 'SA']` | in a administrative area of `WA` or `SA`.
* | `['not', 'WA', 'SA']` | not in a administrative area of `WA` or `SA`.
*
* ---
*
* ```twig
* {# Fetch addresses in Western Australia #}
* {% set {elements-var} = {twig-method}
* .administrativeArea('WA')
* .all() %}
* ```
*
* ```php
* // Fetch addresses in Western Australia
* ${elements-var} = {php-method}
* ->administrativeArea('WA')
* ->all();
* ```
*
* @param string|string[]|null $value The property value
* @return static self reference
* @uses $administrativeArea
* @since 5.0.0
*/
public function administrativeArea(array|string|null $value): static
{
$this->administrativeArea = $value;
return $this;
}
/**
* Narrows the query results based on the locality the addresses belong to.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'Perth'` | with a locality of `Perth`.
* | `'*Perth*'` | with a locality containing `Perth`.
* | `'Ner*'` | with a locality beginning with `Per`.
*
* ---
*
* ```twig
* {# Fetch addresses in Perth #}
* {% set {elements-var} = {twig-method}
* .locality('Perth')
* .all() %}
* ```
*
* ```php
* // Fetch addresses in Perth
* ${elements-var} = {php-method}
* ->locality('Perth')
* ->all();
* ```
*
* @param string|null $value The property value
* @return static self reference
* @uses $locality
* @since 5.0.0
*/
public function locality(?string $value): static
{
$this->locality = $value;
return $this;
}
/**
* Narrows the query results based on the dependent locality the addresses belong to.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'Darlington'` | with a dependentLocality of `Darlington`.
* | `'*Darling*'` | with a dependentLocality containing `Darling`.
* | `'Dar*'` | with a dependentLocality beginning with `Dar`.
*
* ---
*
* ```twig
* {# Fetch addresses in Darlington #}
* {% set {elements-var} = {twig-method}
* .dependentLocality('Darlington')
* .all() %}
* ```
*
* ```php
* // Fetch addresses in Darlington
* ${elements-var} = {php-method}
* ->dependentLocality('Darlington')
* ->all();
* ```
*
* @param string|null $value The property value
* @return static self reference
* @uses $dependentLocality
* @since 5.0.0
*/
public function dependentLocality(?string $value): static
{
$this->dependentLocality = $value;
return $this;
}
/**
* Narrows the query results based on the postal code the addresses belong to.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'10001'` | with a postalCode of `10001`.
* | `'*001*'` | with a postalCode containing `001`.
* | `'100*'` | with a postalCode beginning with `100`.
*
* ---
*
* ```twig
* {# Fetch addresses with postal code 10001 #}
* {% set {elements-var} = {twig-method}
* .postalCode('10001')
* .all() %}
* ```
*
* ```php
* // Fetch addresses with postal code 10001
* ${elements-var} = {php-method}
* ->postalCode('10001')
* ->all();
* ```
*
* @param string|null $value The property value
* @return static self reference
* @uses $postalCode
* @since 5.0.0
*/
public function postalCode(?string $value): static
{
$this->postalCode = $value;
return $this;
}
/**
* Narrows the query results based on the sorting code the addresses have.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'ABCD'` | with a sortingCode of `ABCD`.
* | `'*BC*'` | with a sortingCode containing `BC`.
* | `'AB*'` | with a sortingCode beginning with `AB`.
*
* ---
*
* ```twig
* {# Fetch addresses with sorting code ABCD #}
* {% set {elements-var} = {twig-method}
* .sortingCode('ABCD')
* .all() %}
* ```
*
* ```php
* // Fetch addresses with sorting code ABCD
* ${elements-var} = {php-method}
* ->sortingCode('ABCD')
* ->all();
* ```
*
* @param string|null $value The property value
* @return static self reference
* @uses $sortingCode
* @since 5.0.0
*/
public function sortingCode(?string $value): static
{
$this->sortingCode = $value;
return $this;
}
/**
* Narrows the query results based on the organization the addresses have.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'Pixel & Tonic'` | with an organization of `Pixel & Tonic`.
* | `'*Pixel*'` | with an organization containing `Pixel`.
* | `'Pixel*'` | with an organization beginning with `Pixel`.
*
* ---
*
* ```twig
* {# Fetch addresses for Pixel & Tonic #}
* {% set {elements-var} = {twig-method}
* .organization('Pixel & Tonic')
* .all() %}
* ```
*
* ```php
* // Fetch addresses for Pixel & Tonic
* ${elements-var} = {php-method}
* ->organization('Pixel & Tonic')
* ->all();
* ```
*
* @param string|null $value The property value
* @return static self reference
* @uses $organization
* @since 5.0.0
*/
public function organization(?string $value): static
{
$this->organization = $value;
return $this;
}
/**
* Narrows the query results based on the tax ID the addresses have.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'123-456-789'` | with an organizationTaxId of `123-456-789`.
* | `'*456*'` | with an organizationTaxId containing `456`.
* | `'123*'` | with an organizationTaxId beginning with `123`.
*
* ---
*
* ```twig
* {# Fetch addresses with tax ID 123-456-789 #}
* {% set {elements-var} = {twig-method}
* .organizationTaxId('123-456-789')
* .all() %}
* ```
*
* ```php
* // Fetch addresses with tax ID 123-456-789
* ${elements-var} = {php-method}
* ->organizationTaxId('123-456-789')
* ->all();
* ```
*
* @param string $value The property value
* @return static self reference
* @uses $organizationTaxId
* @since 5.0.0
*/
public function organizationTaxId(string $value): static
{
$this->organizationTaxId = $value;
return $this;
}
/**
* Narrows the query results based on the first address line the addresses have.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'23 Craft st'` | with a addressLine1 of `23 Craft st`.
* | `'*23*'` | with a addressLine1 containing `23`.
* | `'23*'` | with a addressLine1 beginning with `23`.
*
* ---
*
* ```twig
* {# Fetch addresses at 23 Craft st #}
* {% set {elements-var} = {twig-method}
* .addressLine1('23 Craft st')
* .all() %}
* ```
*
* ```php
* // Fetch addresses at 23 Craft st
* ${elements-var} = {php-method}
* ->addressLine1('23 Craft st')
* ->all();
* ```
*
* @param string|null $value The property value
* @return static self reference
* @uses $addressLine1
* @since 5.0.0
*/
public function addressLine1(?string $value): static
{
$this->addressLine1 = $value;
return $this;
}
/**
* Narrows the query results based on the second address line the addresses have.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'Apt 5B'` | with an addressLine2 of `Apt 5B`.
* | `'*5B*'` | with an addressLine2 containing `5B`.
* | `'5B*'` | with an addressLine2 beginning with `5B`.
*
* ---
*
* ```twig
* {# Fetch addresses at Apt 5B #}
* {% set {elements-var} = {twig-method}
* .addressLine2('Apt 5B')
* .all() %}
* ```
*
* ```php
* // Fetch addresses at Apt 5B
* ${elements-var} = {php-method}
* ->addressLine2('Apt 5B')
* ->all();
* ```
*
* @param string|null $value The property value
* @return static self reference
* @uses $addressLine2
* @since 5.0.0
*/
public function addressLine2(?string $value): static
{
$this->addressLine2 = $value;
return $this;
}
/**
* Narrows the query results based on the third address line the addresses have.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'Suite 212'` | with an addressLine3 of `Suite 212`.
* | `'*Suite*'` | with an addressLine3 containing `Suite`.
* | `'Suite*'` | with an addressLine3 beginning with `Suite`.
*
* ---
*
* ```twig
* {# Fetch addresses at Suite 212 #}
* {% set {elements-var} = {twig-method}
* .addressLine3('Suite 212')
* .all() %}
* ```
*
* ```php
* // Fetch addresses at Suite 212
* ${elements-var} = {php-method}
* ->addressLine3('Suite 212')
* ->all();
* ```
*
* @param string|null $value The property value
* @return static self reference
* @uses $addressLine3
* @since 5.0.0
*/
public function addressLine3(?string $value): static
{
$this->addressLine3 = $value;
return $this;
}
/**
* Narrows the query results based on the full name the addresses have.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'John Doe'` | with a fullName of `John Doe`.
* | `'*Doe*'` | with a fullName containing `Doe`.
* | `'John*'` | with a fullName beginning with `John`.
*
* ---
*
* ```twig
* {# Fetch addresses for John Doe #}
* {% set {elements-var} = {twig-method}
* .fullName('John Doe')
* .all() %}
* ```
*
* ```php
* // Fetch addresses for John Doe
* ${elements-var} = {php-method}
* ->fullName('John Doe')
* ->all();
* ```
*
* @param string|null $value The property value
* @return static self reference
* @uses $fullName
* @since 5.0.0
*/
public function fullName(?string $value): static
{
$this->fullName = $value;
return $this;
}
/**
* Narrows the query results based on the first name the addresses have.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'John'` | with a firstName of `John`.
* | `'*Joh*'` | with a firstName containing `Joh`.
* | `'Joh*'` | with a firstName beginning with `Joh`.
*
* ---
*
* ```twig
* {# Fetch addresses with first name John #}
* {% set {elements-var} = {twig-method}
* .firstName('John')
* .all() %}
* ```
*
* ```php
* // Fetch addresses with first name John
* ${elements-var} = {php-method}
* ->firstName('John')
* ->all();
* ```
*
* @param string|null $value The property value
* @return static self reference
* @uses $firstName
* @since 5.0.0
*/
public function firstName(?string $value): static
{
$this->firstName = $value;
return $this;
}
/**
* Narrows the query results based on the last name the addresses have.
*
* Possible values include:
*
* | Value | Fetches addresses…
* | - | -
* | `'Doe'` | with a lastName of `Doe`.
* | `'*Do*'` | with a lastName containing `Do`.
* | `'Do*'` | with a lastName beginning with `Do`.
*
* ---
*
* ```twig
* {# Fetch addresses with last name Doe #}
* {% set {elements-var} = {twig-method}
* .lastName('Doe')
* .all() %}
* ```
*
* ```php
* // Fetch addresses with last name Doe
* ${elements-var} = {php-method}
* ->lastName('Doe')
* ->all();
* ```
*
* @param string|null $value The property value
* @return static self reference
* @uses $lastName
* @since 5.0.0
*/
public function lastName(?string $value): static
{
$this->lastName = $value;
return $this;
}
/**
* Calculate the distance of the address to a given set of coordinates, and
* optionally narrows the query results by minimum or maximum distance.
* Excludes addresses without valid coordinates.
*
* The coordinates should be provided as an associative array with the following keys:
*
* | Key | Value
* | - | -
* | `latitude` | Required, the latitude of the point to measure distance to.
* | `longitude` | Required, the longitude of the point to measure distance to.
* | `min` | Minimum distance in meters to narrow results by.
* | `max` | Maximum distance in meters to narrow results by.
*
* @return static self reference
*
* @uses $distanceTo
*/
public function distanceTo(array $coordinates): static
{
$this->distanceTo = $coordinates;
return $this;
}
/**
* @inheritdoc
*/
protected function beforePrepare(): bool
{
if (!parent::beforePrepare()) {
return false;
}
$this->joinElementTable(Table::ADDRESSES);
$this->query->addSelect([
'addresses.id',
'addresses.fieldId',
'addresses.primaryOwnerId',
'addresses.countryCode',
'addresses.administrativeArea',
'addresses.locality',
'addresses.dependentLocality',
'addresses.postalCode',
'addresses.sortingCode',
'addresses.addressLine1',
'addresses.addressLine2',
'addresses.addressLine3',
'addresses.organization',
'addresses.organizationTaxId',
'addresses.fullName',
'addresses.firstName',
'addresses.lastName',
'addresses.latitude',
'addresses.longitude',
]);
$this->normalizeNestedElementParams();
// Only join the elements_owners table if fieldId is specified
if (!empty($this->fieldId) && (!empty($this->ownerId) || !empty($this->primaryOwnerId))) {
$this->applyNestedElementParams('addresses.fieldId', 'addresses.primaryOwnerId');
} elseif (isset($this->primaryOwnerId) || isset($this->ownerId)) {
// User addresses don't get rows in the elements_owners table
if (!$this->primaryOwnerId && !$this->ownerId) {
throw new QueryAbortedException();
}
$this->subQuery->andWhere(['addresses.primaryOwnerId' => $this->primaryOwnerId ?? $this->ownerId]);
}
if ($this->countryCode) {
$this->subQuery->andWhere(Db::parseParam('addresses.countryCode', $this->countryCode));
}
if ($this->administrativeArea) {
$this->subQuery->andWhere(Db::parseParam('addresses.administrativeArea', $this->administrativeArea));
}
if ($this->locality) {
$this->subQuery->andWhere(Db::parseParam('addresses.locality', $this->locality));
}
if ($this->dependentLocality) {
$this->subQuery->andWhere(Db::parseParam('addresses.dependentLocality', $this->dependentLocality));
}
if ($this->postalCode) {
$this->subQuery->andWhere(Db::parseParam('addresses.postalCode', $this->postalCode));
}
if ($this->sortingCode) {
$this->subQuery->andWhere(Db::parseParam('addresses.sortingCode', $this->sortingCode));
}
if ($this->organization) {
$this->subQuery->andWhere(Db::parseParam('addresses.organization', $this->organization));
}
if ($this->organizationTaxId) {
$this->subQuery->andWhere(Db::parseParam('addresses.organizationTaxId', $this->organizationTaxId));
}
if ($this->addressLine1) {
$this->subQuery->andWhere(Db::parseParam('addresses.addressLine1', $this->addressLine1));
}
if ($this->addressLine2) {
$this->subQuery->andWhere(Db::parseParam('addresses.addressLine2', $this->addressLine2));
}
if ($this->addressLine3) {
$this->subQuery->andWhere(Db::parseParam('addresses.addressLine3', $this->addressLine3));
}