Merge pull request #19061 from christianwach/lab-core-2217
[civicrm-core.git] / CRM / Core / DAO / Address.php
CommitLineData
e501603b 1<?php
c3fc2621 2
e501603b
TO
3/**
4 * @package CRM
ca5cec67 5 * @copyright CiviCRM LLC https://civicrm.org/licensing
e501603b
TO
6 *
7 * Generated from xml/schema/CRM/Core/Address.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
d31fb4e3 9 * (GenCodeChecksum:44eb25ddfd0e9d87e213e2f80f80233d)
e501603b 10 */
c3fc2621 11
f41f0342 12/**
c3fc2621 13 * Database access object for the Address entity.
f41f0342 14 */
e501603b 15class CRM_Core_DAO_Address extends CRM_Core_DAO {
929a1c14
CW
16 const EXT = 'civicrm';
17 const TABLE_ADDED = '1.1';
c3fc2621 18
e501603b 19 /**
f41f0342 20 * Static instance to hold the table name.
e501603b
TO
21 *
22 * @var string
23 */
fa45b5b9 24 public static $_tableName = 'civicrm_address';
c3fc2621 25
449c4e6b
CW
26 /**
27 * Icon associated with this entity.
28 *
29 * @var string
30 */
31 public static $_icon = 'fa-map-marker';
32
e501603b 33 /**
f41f0342 34 * Should CiviCRM log any modifications to this table in the civicrm_log table.
e501603b 35 *
c3fc2621 36 * @var bool
e501603b 37 */
fa45b5b9 38 public static $_log = TRUE;
c3fc2621 39
e501603b
TO
40 /**
41 * Unique Address ID
42 *
e6ca0a57 43 * @var int
e501603b
TO
44 */
45 public $id;
c3fc2621 46
e501603b
TO
47 /**
48 * FK to Contact ID
49 *
e6ca0a57 50 * @var int
e501603b
TO
51 */
52 public $contact_id;
c3fc2621 53
e501603b
TO
54 /**
55 * Which Location does this address belong to.
56 *
e6ca0a57 57 * @var int
e501603b
TO
58 */
59 public $location_type_id;
c3fc2621 60
e501603b
TO
61 /**
62 * Is this the primary address.
63 *
e6ca0a57 64 * @var bool
e501603b
TO
65 */
66 public $is_primary;
c3fc2621 67
e501603b
TO
68 /**
69 * Is this the billing address.
70 *
e6ca0a57 71 * @var bool
e501603b
TO
72 */
73 public $is_billing;
c3fc2621 74
e501603b
TO
75 /**
76 * Concatenation of all routable street address components (prefix, street number, street name, suffix, unit
fb607354
SL
77 * number OR P.O. Box). Apps should be able to determine physical location with this data (for mapping, mail
78 * delivery, etc.).
e501603b
TO
79 *
80 * @var string
81 */
82 public $street_address;
c3fc2621 83
e501603b
TO
84 /**
85 * Numeric portion of address number on the street, e.g. For 112A Main St, the street_number = 112.
86 *
87 * @var int
88 */
89 public $street_number;
c3fc2621 90
e501603b
TO
91 /**
92 * Non-numeric portion of address number on the street, e.g. For 112A Main St, the street_number_suffix = A
93 *
94 * @var string
95 */
96 public $street_number_suffix;
c3fc2621 97
e501603b
TO
98 /**
99 * Directional prefix, e.g. SE Main St, SE is the prefix.
100 *
101 * @var string
102 */
103 public $street_number_predirectional;
c3fc2621 104
e501603b
TO
105 /**
106 * Actual street name, excluding St, Dr, Rd, Ave, e.g. For 112 Main St, the street_name = Main.
107 *
108 * @var string
109 */
110 public $street_name;
c3fc2621 111
e501603b
TO
112 /**
113 * St, Rd, Dr, etc.
114 *
115 * @var string
116 */
117 public $street_type;
c3fc2621 118
e501603b
TO
119 /**
120 * Directional prefix, e.g. Main St S, S is the suffix.
121 *
122 * @var string
123 */
124 public $street_number_postdirectional;
c3fc2621 125
e501603b
TO
126 /**
127 * Secondary unit designator, e.g. Apt 3 or Unit # 14, or Bldg 1200
128 *
129 * @var string
130 */
131 public $street_unit;
c3fc2621 132
e501603b
TO
133 /**
134 * Supplemental Address Information, Line 1
135 *
136 * @var string
137 */
138 public $supplemental_address_1;
c3fc2621 139
e501603b
TO
140 /**
141 * Supplemental Address Information, Line 2
142 *
143 * @var string
144 */
145 public $supplemental_address_2;
c3fc2621 146
e501603b
TO
147 /**
148 * Supplemental Address Information, Line 3
149 *
150 * @var string
151 */
152 public $supplemental_address_3;
c3fc2621 153
e501603b
TO
154 /**
155 * City, Town or Village Name.
156 *
157 * @var string
158 */
159 public $city;
c3fc2621 160
e501603b
TO
161 /**
162 * Which County does this address belong to.
163 *
e6ca0a57 164 * @var int
e501603b
TO
165 */
166 public $county_id;
c3fc2621 167
e501603b
TO
168 /**
169 * Which State_Province does this address belong to.
170 *
e6ca0a57 171 * @var int
e501603b
TO
172 */
173 public $state_province_id;
c3fc2621 174
e501603b
TO
175 /**
176 * Store the suffix, like the +4 part in the USPS system.
177 *
178 * @var string
179 */
180 public $postal_code_suffix;
c3fc2621 181
e501603b
TO
182 /**
183 * Store both US (zip5) AND international postal codes. App is responsible for country/region appropriate validation.
184 *
185 * @var string
186 */
187 public $postal_code;
c3fc2621 188
e501603b
TO
189 /**
190 * USPS Bulk mailing code.
191 *
192 * @var string
193 */
194 public $usps_adc;
c3fc2621 195
e501603b
TO
196 /**
197 * Which Country does this address belong to.
198 *
e6ca0a57 199 * @var int
e501603b
TO
200 */
201 public $country_id;
c3fc2621 202
e501603b
TO
203 /**
204 * Latitude
205 *
206 * @var float
207 */
208 public $geo_code_1;
c3fc2621 209
e501603b
TO
210 /**
211 * Longitude
212 *
213 * @var float
214 */
215 public $geo_code_2;
c3fc2621 216
e501603b
TO
217 /**
218 * Is this a manually entered geo code
219 *
e6ca0a57 220 * @var bool
e501603b
TO
221 */
222 public $manual_geo_code;
c3fc2621 223
e501603b
TO
224 /**
225 * Timezone expressed as a UTC offset - e.g. United States CST would be written as "UTC-6".
226 *
227 * @var string
228 */
229 public $timezone;
c3fc2621 230
e501603b 231 /**
e501603b
TO
232 * @var string
233 */
234 public $name;
c3fc2621 235
e501603b
TO
236 /**
237 * FK to Address ID
238 *
e6ca0a57 239 * @var int
e501603b
TO
240 */
241 public $master_id;
c3fc2621 242
e501603b 243 /**
f41f0342 244 * Class constructor.
e501603b 245 */
c3fc2621 246 public function __construct() {
e501603b
TO
247 $this->__table = 'civicrm_address';
248 parent::__construct();
249 }
c3fc2621 250
449c4e6b
CW
251 /**
252 * Returns localized title of this entity.
7b66c3b5
AH
253 *
254 * @param bool $plural
255 * Whether to return the plural version of the title.
449c4e6b 256 */
7b66c3b5
AH
257 public static function getEntityTitle($plural = FALSE) {
258 return $plural ? ts('Addresses') : ts('Address');
449c4e6b
CW
259 }
260
e501603b 261 /**
f41f0342 262 * Returns foreign keys and entity references.
e501603b
TO
263 *
264 * @return array
265 * [CRM_Core_Reference_Interface]
266 */
c3fc2621 267 public static function getReferenceColumns() {
346aaaba 268 if (!isset(Civi::$statics[__CLASS__]['links'])) {
fa45b5b9 269 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
c3fc2621
CW
270 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id', 'civicrm_contact', 'id');
271 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'county_id', 'civicrm_county', 'id');
272 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'state_province_id', 'civicrm_state_province', 'id');
273 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'country_id', 'civicrm_country', 'id');
274 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'master_id', 'civicrm_address', 'id');
346aaaba 275 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
e501603b 276 }
346aaaba 277 return Civi::$statics[__CLASS__]['links'];
e501603b 278 }
c3fc2621 279
e501603b
TO
280 /**
281 * Returns all the column names of this table
282 *
283 * @return array
284 */
c3fc2621 285 public static function &fields() {
346aaaba 286 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
c3fc2621 287 Civi::$statics[__CLASS__]['fields'] = [
7e18723f 288 'address_id' => [
e501603b
TO
289 'name' => 'id',
290 'type' => CRM_Utils_Type::T_INT,
c3fc2621 291 'title' => ts('Address ID'),
215b423e 292 'description' => ts('Unique Address ID'),
c3fc2621 293 'required' => TRUE,
a36434b9 294 'where' => 'civicrm_address.id',
7e18723f 295 'export' => TRUE,
522a26c9 296 'table_name' => 'civicrm_address',
297 'entity' => 'Address',
298 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 299 'localizable' => 0,
a9d0587b 300 'add' => '1.1',
c3fc2621
CW
301 ],
302 'contact_id' => [
e501603b
TO
303 'name' => 'contact_id',
304 'type' => CRM_Utils_Type::T_INT,
c3fc2621 305 'title' => ts('Contact ID'),
215b423e 306 'description' => ts('FK to Contact ID'),
a36434b9 307 'where' => 'civicrm_address.contact_id',
522a26c9 308 'table_name' => 'civicrm_address',
309 'entity' => 'Address',
310 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 311 'localizable' => 0,
e501603b 312 'FKClassName' => 'CRM_Contact_DAO_Contact',
a9d0587b 313 'add' => '2.0',
c3fc2621
CW
314 ],
315 'location_type_id' => [
e501603b
TO
316 'name' => 'location_type_id',
317 'type' => CRM_Utils_Type::T_INT,
c3fc2621 318 'title' => ts('Address Location Type'),
215b423e 319 'description' => ts('Which Location does this address belong to.'),
a36434b9 320 'where' => 'civicrm_address.location_type_id',
522a26c9 321 'table_name' => 'civicrm_address',
322 'entity' => 'Address',
323 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 324 'localizable' => 0,
c3fc2621 325 'html' => [
e501603b 326 'type' => 'Select',
c3fc2621
CW
327 ],
328 'pseudoconstant' => [
e501603b
TO
329 'table' => 'civicrm_location_type',
330 'keyColumn' => 'id',
331 'labelColumn' => 'display_name',
e6ca0a57 332 ],
a9d0587b 333 'add' => '2.0',
c3fc2621
CW
334 ],
335 'is_primary' => [
e501603b
TO
336 'name' => 'is_primary',
337 'type' => CRM_Utils_Type::T_BOOLEAN,
b6673dcd 338 'title' => ts('Primary address'),
215b423e 339 'description' => ts('Is this the primary address.'),
a36434b9 340 'where' => 'civicrm_address.is_primary',
45a83e42 341 'default' => '0',
522a26c9 342 'table_name' => 'civicrm_address',
343 'entity' => 'Address',
344 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 345 'localizable' => 0,
c3fc2621 346 'html' => [
b6673dcd 347 'type' => 'Radio',
c3fc2621 348 ],
a9d0587b 349 'add' => '2.0',
c3fc2621
CW
350 ],
351 'is_billing' => [
e501603b
TO
352 'name' => 'is_billing',
353 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621 354 'title' => ts('Is Billing Address'),
215b423e 355 'description' => ts('Is this the billing address.'),
a36434b9 356 'where' => 'civicrm_address.is_billing',
45a83e42 357 'default' => '0',
522a26c9 358 'table_name' => 'civicrm_address',
359 'entity' => 'Address',
360 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 361 'localizable' => 0,
c3fc2621 362 'html' => [
e501603b 363 'type' => 'CheckBox',
c3fc2621 364 ],
a9d0587b 365 'add' => '2.0',
c3fc2621
CW
366 ],
367 'street_address' => [
e501603b
TO
368 'name' => 'street_address',
369 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 370 'title' => ts('Street Address'),
215b423e 371 'description' => ts('Concatenation of all routable street address components (prefix, street number, street name, suffix, unit
e501603b 372 number OR P.O. Box). Apps should be able to determine physical location with this data (for mapping, mail
fb607354 373 delivery, etc.).'),
e501603b
TO
374 'maxlength' => 96,
375 'size' => CRM_Utils_Type::HUGE,
c3fc2621 376 'import' => TRUE,
e501603b
TO
377 'where' => 'civicrm_address.street_address',
378 'headerPattern' => '/(street|address)/i',
379 'dataPattern' => '/^(\d{1,5}( [0-9A-Za-z]+)+)$|^(P\.?O\.\? Box \d{1,5})$/i',
c3fc2621 380 'export' => TRUE,
522a26c9 381 'table_name' => 'civicrm_address',
382 'entity' => 'Address',
383 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 384 'localizable' => 0,
c3fc2621 385 'html' => [
e501603b 386 'type' => 'Text',
c3fc2621 387 ],
a9d0587b 388 'add' => '1.1',
c3fc2621
CW
389 ],
390 'street_number' => [
e501603b
TO
391 'name' => 'street_number',
392 'type' => CRM_Utils_Type::T_INT,
c3fc2621 393 'title' => ts('Street Number'),
215b423e 394 'description' => ts('Numeric portion of address number on the street, e.g. For 112A Main St, the street_number = 112.'),
e501603b 395 'where' => 'civicrm_address.street_number',
a36434b9 396 'export' => TRUE,
522a26c9 397 'table_name' => 'civicrm_address',
398 'entity' => 'Address',
399 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 400 'localizable' => 0,
c3fc2621 401 'html' => [
e501603b 402 'type' => 'Text',
c3fc2621 403 ],
a9d0587b 404 'add' => '1.1',
c3fc2621
CW
405 ],
406 'street_number_suffix' => [
e501603b
TO
407 'name' => 'street_number_suffix',
408 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 409 'title' => ts('Street Number Suffix'),
fb607354 410 'description' => ts('Non-numeric portion of address number on the street, e.g. For 112A Main St, the street_number_suffix = A'),
e501603b
TO
411 'maxlength' => 8,
412 'size' => CRM_Utils_Type::EIGHT,
e501603b 413 'where' => 'civicrm_address.street_number_suffix',
a36434b9 414 'export' => TRUE,
522a26c9 415 'table_name' => 'civicrm_address',
416 'entity' => 'Address',
417 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 418 'localizable' => 0,
c3fc2621 419 'html' => [
e501603b 420 'type' => 'Text',
c3fc2621 421 ],
a9d0587b 422 'add' => '1.1',
c3fc2621
CW
423 ],
424 'street_number_predirectional' => [
e501603b
TO
425 'name' => 'street_number_predirectional',
426 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 427 'title' => ts('Street Direction Prefix'),
215b423e 428 'description' => ts('Directional prefix, e.g. SE Main St, SE is the prefix.'),
e501603b
TO
429 'maxlength' => 8,
430 'size' => CRM_Utils_Type::EIGHT,
a36434b9 431 'where' => 'civicrm_address.street_number_predirectional',
522a26c9 432 'table_name' => 'civicrm_address',
433 'entity' => 'Address',
434 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 435 'localizable' => 0,
c3fc2621 436 'html' => [
e501603b 437 'type' => 'Text',
c3fc2621 438 ],
a9d0587b 439 'add' => '1.1',
c3fc2621
CW
440 ],
441 'street_name' => [
e501603b
TO
442 'name' => 'street_name',
443 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 444 'title' => ts('Street Name'),
215b423e 445 'description' => ts('Actual street name, excluding St, Dr, Rd, Ave, e.g. For 112 Main St, the street_name = Main.'),
e501603b
TO
446 'maxlength' => 64,
447 'size' => CRM_Utils_Type::BIG,
e501603b 448 'where' => 'civicrm_address.street_name',
a36434b9 449 'export' => TRUE,
522a26c9 450 'table_name' => 'civicrm_address',
451 'entity' => 'Address',
452 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 453 'localizable' => 0,
c3fc2621 454 'html' => [
e501603b 455 'type' => 'Text',
c3fc2621 456 ],
a9d0587b 457 'add' => '1.1',
c3fc2621
CW
458 ],
459 'street_type' => [
e501603b
TO
460 'name' => 'street_type',
461 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 462 'title' => ts('Street Type'),
215b423e 463 'description' => ts('St, Rd, Dr, etc.'),
e501603b
TO
464 'maxlength' => 8,
465 'size' => CRM_Utils_Type::EIGHT,
a36434b9 466 'where' => 'civicrm_address.street_type',
522a26c9 467 'table_name' => 'civicrm_address',
468 'entity' => 'Address',
469 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 470 'localizable' => 0,
c3fc2621 471 'html' => [
e501603b 472 'type' => 'Text',
c3fc2621 473 ],
a9d0587b 474 'add' => '1.1',
c3fc2621
CW
475 ],
476 'street_number_postdirectional' => [
e501603b
TO
477 'name' => 'street_number_postdirectional',
478 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 479 'title' => ts('Street Direction Suffix'),
215b423e 480 'description' => ts('Directional prefix, e.g. Main St S, S is the suffix.'),
e501603b
TO
481 'maxlength' => 8,
482 'size' => CRM_Utils_Type::EIGHT,
a36434b9 483 'where' => 'civicrm_address.street_number_postdirectional',
522a26c9 484 'table_name' => 'civicrm_address',
485 'entity' => 'Address',
486 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 487 'localizable' => 0,
c3fc2621 488 'html' => [
e501603b 489 'type' => 'Text',
c3fc2621 490 ],
a9d0587b 491 'add' => '1.1',
c3fc2621
CW
492 ],
493 'street_unit' => [
e501603b
TO
494 'name' => 'street_unit',
495 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 496 'title' => ts('Street Unit'),
215b423e 497 'description' => ts('Secondary unit designator, e.g. Apt 3 or Unit # 14, or Bldg 1200'),
e501603b
TO
498 'maxlength' => 16,
499 'size' => CRM_Utils_Type::TWELVE,
e501603b 500 'where' => 'civicrm_address.street_unit',
a36434b9 501 'export' => TRUE,
522a26c9 502 'table_name' => 'civicrm_address',
503 'entity' => 'Address',
504 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 505 'localizable' => 0,
c3fc2621 506 'html' => [
e501603b 507 'type' => 'Text',
c3fc2621 508 ],
a9d0587b 509 'add' => '1.1',
c3fc2621
CW
510 ],
511 'supplemental_address_1' => [
e501603b
TO
512 'name' => 'supplemental_address_1',
513 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 514 'title' => ts('Supplemental Address 1'),
215b423e 515 'description' => ts('Supplemental Address Information, Line 1'),
e501603b
TO
516 'maxlength' => 96,
517 'size' => CRM_Utils_Type::HUGE,
c3fc2621 518 'import' => TRUE,
e501603b
TO
519 'where' => 'civicrm_address.supplemental_address_1',
520 'headerPattern' => '/(supplemental(\s)?)?address(\s\d+)?/i',
521 'dataPattern' => '/unit|ap(ar)?t(ment)?\s(\d|\w)+/i',
c3fc2621 522 'export' => TRUE,
522a26c9 523 'table_name' => 'civicrm_address',
524 'entity' => 'Address',
525 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 526 'localizable' => 0,
c3fc2621 527 'html' => [
e501603b 528 'type' => 'Text',
c3fc2621 529 ],
a9d0587b 530 'add' => '1.1',
c3fc2621
CW
531 ],
532 'supplemental_address_2' => [
e501603b
TO
533 'name' => 'supplemental_address_2',
534 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 535 'title' => ts('Supplemental Address 2'),
215b423e 536 'description' => ts('Supplemental Address Information, Line 2'),
e501603b
TO
537 'maxlength' => 96,
538 'size' => CRM_Utils_Type::HUGE,
c3fc2621 539 'import' => TRUE,
e501603b
TO
540 'where' => 'civicrm_address.supplemental_address_2',
541 'headerPattern' => '/(supplemental(\s)?)?address(\s\d+)?/i',
542 'dataPattern' => '/unit|ap(ar)?t(ment)?\s(\d|\w)+/i',
c3fc2621 543 'export' => TRUE,
522a26c9 544 'table_name' => 'civicrm_address',
545 'entity' => 'Address',
546 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 547 'localizable' => 0,
c3fc2621 548 'html' => [
e501603b 549 'type' => 'Text',
c3fc2621 550 ],
a9d0587b 551 'add' => '1.1',
c3fc2621
CW
552 ],
553 'supplemental_address_3' => [
e501603b
TO
554 'name' => 'supplemental_address_3',
555 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 556 'title' => ts('Supplemental Address 3'),
215b423e 557 'description' => ts('Supplemental Address Information, Line 3'),
e501603b
TO
558 'maxlength' => 96,
559 'size' => CRM_Utils_Type::HUGE,
c3fc2621 560 'import' => TRUE,
207f62c6
AS
561 'where' => 'civicrm_address.supplemental_address_3',
562 'headerPattern' => '/(supplemental(\s)?)?address(\s\d+)?/i',
563 'dataPattern' => '/unit|ap(ar)?t(ment)?\s(\d|\w)+/i',
c3fc2621 564 'export' => TRUE,
522a26c9 565 'table_name' => 'civicrm_address',
566 'entity' => 'Address',
567 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 568 'localizable' => 0,
c3fc2621 569 'html' => [
e501603b 570 'type' => 'Text',
c3fc2621 571 ],
a9d0587b 572 'add' => '1.1',
c3fc2621
CW
573 ],
574 'city' => [
e501603b
TO
575 'name' => 'city',
576 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 577 'title' => ts('City'),
215b423e 578 'description' => ts('City, Town or Village Name.'),
e501603b
TO
579 'maxlength' => 64,
580 'size' => CRM_Utils_Type::BIG,
c3fc2621 581 'import' => TRUE,
e501603b
TO
582 'where' => 'civicrm_address.city',
583 'headerPattern' => '/city/i',
584 'dataPattern' => '/^[A-Za-z]+(\.?)(\s?[A-Za-z]+){0,2}$/',
c3fc2621 585 'export' => TRUE,
522a26c9 586 'table_name' => 'civicrm_address',
587 'entity' => 'Address',
588 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 589 'localizable' => 0,
c3fc2621 590 'html' => [
e501603b 591 'type' => 'Text',
c3fc2621 592 ],
a9d0587b 593 'add' => '1.1',
c3fc2621
CW
594 ],
595 'county_id' => [
e501603b
TO
596 'name' => 'county_id',
597 'type' => CRM_Utils_Type::T_INT,
c3fc2621 598 'title' => ts('County'),
215b423e 599 'description' => ts('Which County does this address belong to.'),
a36434b9 600 'where' => 'civicrm_address.county_id',
522a26c9 601 'table_name' => 'civicrm_address',
602 'entity' => 'Address',
603 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 604 'localizable' => 0,
e501603b 605 'FKClassName' => 'CRM_Core_DAO_County',
c3fc2621 606 'html' => [
e501603b 607 'type' => 'ChainSelect',
8ada2bfd 608 'controlField' => 'state_province_id',
c3fc2621
CW
609 ],
610 'pseudoconstant' => [
e501603b
TO
611 'table' => 'civicrm_county',
612 'keyColumn' => 'id',
613 'labelColumn' => 'name',
e6ca0a57 614 ],
a9d0587b 615 'add' => '1.1',
c3fc2621
CW
616 ],
617 'state_province_id' => [
e501603b
TO
618 'name' => 'state_province_id',
619 'type' => CRM_Utils_Type::T_INT,
c3fc2621 620 'title' => ts('State/Province'),
215b423e 621 'description' => ts('Which State_Province does this address belong to.'),
a36434b9 622 'where' => 'civicrm_address.state_province_id',
522a26c9 623 'table_name' => 'civicrm_address',
624 'entity' => 'Address',
625 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 626 'localizable' => 0,
65c86f7d 627 'localize_context' => 'province',
e501603b 628 'FKClassName' => 'CRM_Core_DAO_StateProvince',
c3fc2621 629 'html' => [
e501603b 630 'type' => 'ChainSelect',
8ada2bfd 631 'controlField' => 'country_id',
c3fc2621
CW
632 ],
633 'pseudoconstant' => [
e501603b
TO
634 'table' => 'civicrm_state_province',
635 'keyColumn' => 'id',
636 'labelColumn' => 'name',
e6ca0a57 637 ],
a9d0587b 638 'add' => '1.1',
c3fc2621
CW
639 ],
640 'postal_code_suffix' => [
e501603b
TO
641 'name' => 'postal_code_suffix',
642 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 643 'title' => ts('Postal Code Suffix'),
215b423e 644 'description' => ts('Store the suffix, like the +4 part in the USPS system.'),
e501603b
TO
645 'maxlength' => 12,
646 'size' => 3,
c3fc2621 647 'import' => TRUE,
e501603b
TO
648 'where' => 'civicrm_address.postal_code_suffix',
649 'headerPattern' => '/p(ostal)\sc(ode)\ss(uffix)/i',
650 'dataPattern' => '/\d?\d{4}(-\d{4})?/',
c3fc2621 651 'export' => TRUE,
522a26c9 652 'table_name' => 'civicrm_address',
653 'entity' => 'Address',
654 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 655 'localizable' => 0,
c3fc2621 656 'html' => [
e501603b 657 'type' => 'Text',
c3fc2621 658 ],
a9d0587b 659 'add' => '1.1',
c3fc2621
CW
660 ],
661 'postal_code' => [
e501603b
TO
662 'name' => 'postal_code',
663 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 664 'title' => ts('Postal Code'),
215b423e 665 'description' => ts('Store both US (zip5) AND international postal codes. App is responsible for country/region appropriate validation.'),
e501603b
TO
666 'maxlength' => 64,
667 'size' => 6,
c3fc2621 668 'import' => TRUE,
e501603b
TO
669 'where' => 'civicrm_address.postal_code',
670 'headerPattern' => '/postal|zip/i',
671 'dataPattern' => '/\d?\d{4}(-\d{4})?/',
c3fc2621 672 'export' => TRUE,
522a26c9 673 'table_name' => 'civicrm_address',
674 'entity' => 'Address',
675 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 676 'localizable' => 0,
c3fc2621 677 'html' => [
e501603b 678 'type' => 'Text',
c3fc2621 679 ],
a9d0587b 680 'add' => '1.1',
c3fc2621
CW
681 ],
682 'usps_adc' => [
e501603b
TO
683 'name' => 'usps_adc',
684 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 685 'title' => ts('USPS Code'),
215b423e 686 'description' => ts('USPS Bulk mailing code.'),
e501603b
TO
687 'maxlength' => 32,
688 'size' => CRM_Utils_Type::MEDIUM,
a36434b9 689 'where' => 'civicrm_address.usps_adc',
522a26c9 690 'table_name' => 'civicrm_address',
691 'entity' => 'Address',
692 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 693 'localizable' => 0,
a9d0587b 694 'add' => '1.1',
c3fc2621
CW
695 ],
696 'country_id' => [
e501603b
TO
697 'name' => 'country_id',
698 'type' => CRM_Utils_Type::T_INT,
c3fc2621 699 'title' => ts('Country'),
215b423e 700 'description' => ts('Which Country does this address belong to.'),
a36434b9 701 'where' => 'civicrm_address.country_id',
522a26c9 702 'table_name' => 'civicrm_address',
703 'entity' => 'Address',
704 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 705 'localizable' => 0,
65c86f7d 706 'localize_context' => 'country',
e501603b 707 'FKClassName' => 'CRM_Core_DAO_Country',
c3fc2621 708 'html' => [
e501603b 709 'type' => 'Select',
c3fc2621
CW
710 ],
711 'pseudoconstant' => [
e501603b
TO
712 'table' => 'civicrm_country',
713 'keyColumn' => 'id',
714 'labelColumn' => 'name',
715 'nameColumn' => 'iso_code',
a8fdb24e 716 'abbrColumn' => 'iso_code',
e6ca0a57 717 ],
a9d0587b 718 'add' => '1.1',
c3fc2621
CW
719 ],
720 'geo_code_1' => [
e501603b
TO
721 'name' => 'geo_code_1',
722 'type' => CRM_Utils_Type::T_FLOAT,
c3fc2621 723 'title' => ts('Latitude'),
215b423e 724 'description' => ts('Latitude'),
c3fc2621 725 'import' => TRUE,
e501603b
TO
726 'where' => 'civicrm_address.geo_code_1',
727 'headerPattern' => '/geo/i',
c3fc2621 728 'export' => TRUE,
522a26c9 729 'table_name' => 'civicrm_address',
730 'entity' => 'Address',
731 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 732 'localizable' => 0,
c3fc2621 733 'html' => [
e501603b 734 'type' => 'Text',
c3fc2621 735 ],
a9d0587b 736 'add' => '1.1',
c3fc2621
CW
737 ],
738 'geo_code_2' => [
e501603b
TO
739 'name' => 'geo_code_2',
740 'type' => CRM_Utils_Type::T_FLOAT,
c3fc2621 741 'title' => ts('Longitude'),
215b423e 742 'description' => ts('Longitude'),
c3fc2621 743 'import' => TRUE,
e501603b
TO
744 'where' => 'civicrm_address.geo_code_2',
745 'headerPattern' => '/geo/i',
c3fc2621 746 'export' => TRUE,
522a26c9 747 'table_name' => 'civicrm_address',
748 'entity' => 'Address',
749 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 750 'localizable' => 0,
c3fc2621 751 'html' => [
e501603b 752 'type' => 'Text',
c3fc2621 753 ],
a9d0587b 754 'add' => '1.1',
c3fc2621
CW
755 ],
756 'manual_geo_code' => [
e501603b
TO
757 'name' => 'manual_geo_code',
758 'type' => CRM_Utils_Type::T_BOOLEAN,
4fcfc078 759 'title' => ts('Is Manually Geocoded'),
215b423e 760 'description' => ts('Is this a manually entered geo code'),
a36434b9 761 'where' => 'civicrm_address.manual_geo_code',
4fcfc078 762 'export' => TRUE,
45a83e42 763 'default' => '0',
522a26c9 764 'table_name' => 'civicrm_address',
765 'entity' => 'Address',
766 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 767 'localizable' => 0,
c3fc2621 768 'html' => [
e501603b 769 'type' => 'CheckBox',
c3fc2621 770 ],
a9d0587b 771 'add' => '4.3',
c3fc2621
CW
772 ],
773 'timezone' => [
e501603b
TO
774 'name' => 'timezone',
775 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 776 'title' => ts('Timezone'),
215b423e 777 'description' => ts('Timezone expressed as a UTC offset - e.g. United States CST would be written as "UTC-6".'),
e501603b
TO
778 'maxlength' => 8,
779 'size' => CRM_Utils_Type::EIGHT,
a36434b9 780 'where' => 'civicrm_address.timezone',
522a26c9 781 'table_name' => 'civicrm_address',
782 'entity' => 'Address',
783 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 784 'localizable' => 0,
c3fc2621 785 'html' => [
e501603b 786 'type' => 'Text',
c3fc2621 787 ],
a9d0587b 788 'add' => '1.1',
c3fc2621
CW
789 ],
790 'address_name' => [
e501603b
TO
791 'name' => 'name',
792 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 793 'title' => ts('Address Name'),
e501603b
TO
794 'maxlength' => 255,
795 'size' => CRM_Utils_Type::HUGE,
c3fc2621 796 'import' => TRUE,
e501603b
TO
797 'where' => 'civicrm_address.name',
798 'headerPattern' => '/^location|(l(ocation\s)?name)$/i',
799 'dataPattern' => '/^\w+$/',
c3fc2621 800 'export' => TRUE,
522a26c9 801 'table_name' => 'civicrm_address',
802 'entity' => 'Address',
803 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 804 'localizable' => 0,
c3fc2621 805 'html' => [
e501603b 806 'type' => 'Text',
c3fc2621 807 ],
a9d0587b 808 'add' => '2.1',
c3fc2621
CW
809 ],
810 'master_id' => [
e501603b
TO
811 'name' => 'master_id',
812 'type' => CRM_Utils_Type::T_INT,
c3fc2621 813 'title' => ts('Master Address Belongs To'),
215b423e 814 'description' => ts('FK to Address ID'),
c3fc2621 815 'import' => TRUE,
e501603b 816 'where' => 'civicrm_address.master_id',
c3fc2621 817 'export' => TRUE,
522a26c9 818 'table_name' => 'civicrm_address',
819 'entity' => 'Address',
820 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 821 'localizable' => 0,
e501603b 822 'FKClassName' => 'CRM_Core_DAO_Address',
a9d0587b 823 'add' => '3.3',
c3fc2621
CW
824 ],
825 ];
346aaaba 826 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
e501603b 827 }
346aaaba 828 return Civi::$statics[__CLASS__]['fields'];
e501603b 829 }
c3fc2621 830
e501603b 831 /**
bd8e0b14 832 * Return a mapping from field-name to the corresponding key (as used in fields()).
e501603b
TO
833 *
834 * @return array
bd8e0b14 835 * Array(string $name => string $uniqueName).
e501603b 836 */
c3fc2621 837 public static function &fieldKeys() {
bd8e0b14
TO
838 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
839 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
e501603b 840 }
bd8e0b14 841 return Civi::$statics[__CLASS__]['fieldKeys'];
e501603b 842 }
c3fc2621 843
e501603b
TO
844 /**
845 * Returns the names of this table
846 *
847 * @return string
848 */
c3fc2621 849 public static function getTableName() {
e501603b
TO
850 return self::$_tableName;
851 }
c3fc2621 852
e501603b
TO
853 /**
854 * Returns if this table needs to be logged
855 *
c3fc2621 856 * @return bool
e501603b 857 */
c3fc2621 858 public function getLog() {
e501603b
TO
859 return self::$_log;
860 }
c3fc2621 861
e501603b
TO
862 /**
863 * Returns the list of fields that can be imported
864 *
865 * @param bool $prefix
866 *
867 * @return array
868 */
c3fc2621
CW
869 public static function &import($prefix = FALSE) {
870 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'address', $prefix, [
60808919
TO
871 'CRM_Core_DAO_County',
872 'CRM_Core_DAO_StateProvince',
873 'CRM_Core_DAO_Country',
c3fc2621 874 ]);
60808919 875 return $r;
e501603b 876 }
c3fc2621 877
e501603b
TO
878 /**
879 * Returns the list of fields that can be exported
880 *
881 * @param bool $prefix
882 *
883 * @return array
884 */
c3fc2621
CW
885 public static function &export($prefix = FALSE) {
886 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'address', $prefix, [
60808919
TO
887 'CRM_Core_DAO_County',
888 'CRM_Core_DAO_StateProvince',
889 'CRM_Core_DAO_Country',
c3fc2621 890 ]);
60808919 891 return $r;
e501603b 892 }
c3fc2621 893
e7a6b91a
AS
894 /**
895 * Returns the list of indices
c3fc2621
CW
896 *
897 * @param bool $localize
898 *
899 * @return array
e7a6b91a
AS
900 */
901 public static function indices($localize = TRUE) {
c3fc2621
CW
902 $indices = [
903 'index_location_type' => [
e7a6b91a 904 'name' => 'index_location_type',
c3fc2621 905 'field' => [
e7a6b91a 906 0 => 'location_type_id',
c3fc2621
CW
907 ],
908 'localizable' => FALSE,
e7a6b91a 909 'sig' => 'civicrm_address::0::location_type_id',
c3fc2621
CW
910 ],
911 'index_is_primary' => [
e7a6b91a 912 'name' => 'index_is_primary',
c3fc2621 913 'field' => [
e7a6b91a 914 0 => 'is_primary',
c3fc2621
CW
915 ],
916 'localizable' => FALSE,
e7a6b91a 917 'sig' => 'civicrm_address::0::is_primary',
c3fc2621
CW
918 ],
919 'index_is_billing' => [
e7a6b91a 920 'name' => 'index_is_billing',
c3fc2621 921 'field' => [
e7a6b91a 922 0 => 'is_billing',
c3fc2621
CW
923 ],
924 'localizable' => FALSE,
e7a6b91a 925 'sig' => 'civicrm_address::0::is_billing',
c3fc2621
CW
926 ],
927 'index_street_name' => [
e7a6b91a 928 'name' => 'index_street_name',
c3fc2621 929 'field' => [
e7a6b91a 930 0 => 'street_name',
c3fc2621
CW
931 ],
932 'localizable' => FALSE,
e7a6b91a 933 'sig' => 'civicrm_address::0::street_name',
c3fc2621
CW
934 ],
935 'index_city' => [
e7a6b91a 936 'name' => 'index_city',
c3fc2621 937 'field' => [
e7a6b91a 938 0 => 'city',
c3fc2621
CW
939 ],
940 'localizable' => FALSE,
e7a6b91a 941 'sig' => 'civicrm_address::0::city',
c3fc2621 942 ],
d56bfd0e
SL
943 'index_geo_code_1_geo_code_2' => [
944 'name' => 'index_geo_code_1_geo_code_2',
945 'field' => [
946 0 => 'geo_code_1',
947 1 => 'geo_code_2',
948 ],
949 'localizable' => FALSE,
950 'sig' => 'civicrm_address::0::geo_code_1::geo_code_2',
951 ],
c3fc2621 952 ];
e7a6b91a
AS
953 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
954 }
c3fc2621 955
e501603b 956}