Merge pull request #22496 from civicrm/5.46
[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
70c5cd97 9 * (GenCodeChecksum:40a96138e8081eaba0460889f49cc1cf)
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,
2cbbebe8
A
300 'html' => [
301 'type' => 'Number',
302 ],
1fe423d6 303 'readonly' => TRUE,
a9d0587b 304 'add' => '1.1',
c3fc2621
CW
305 ],
306 'contact_id' => [
e501603b
TO
307 'name' => 'contact_id',
308 'type' => CRM_Utils_Type::T_INT,
c3fc2621 309 'title' => ts('Contact ID'),
215b423e 310 'description' => ts('FK to Contact ID'),
a36434b9 311 'where' => 'civicrm_address.contact_id',
522a26c9 312 'table_name' => 'civicrm_address',
313 'entity' => 'Address',
314 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 315 'localizable' => 0,
e501603b 316 'FKClassName' => 'CRM_Contact_DAO_Contact',
2cbbebe8
A
317 'html' => [
318 'label' => ts("Contact"),
319 ],
a9d0587b 320 'add' => '2.0',
c3fc2621
CW
321 ],
322 'location_type_id' => [
e501603b
TO
323 'name' => 'location_type_id',
324 'type' => CRM_Utils_Type::T_INT,
c3fc2621 325 'title' => ts('Address Location Type'),
215b423e 326 'description' => ts('Which Location does this address belong to.'),
a36434b9 327 'where' => 'civicrm_address.location_type_id',
522a26c9 328 'table_name' => 'civicrm_address',
329 'entity' => 'Address',
330 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 331 'localizable' => 0,
c3fc2621 332 'html' => [
e501603b 333 'type' => 'Select',
c3fc2621
CW
334 ],
335 'pseudoconstant' => [
e501603b
TO
336 'table' => 'civicrm_location_type',
337 'keyColumn' => 'id',
338 'labelColumn' => 'display_name',
e6ca0a57 339 ],
a9d0587b 340 'add' => '2.0',
c3fc2621
CW
341 ],
342 'is_primary' => [
e501603b
TO
343 'name' => 'is_primary',
344 'type' => CRM_Utils_Type::T_BOOLEAN,
b6673dcd 345 'title' => ts('Primary address'),
215b423e 346 'description' => ts('Is this the primary address.'),
a36434b9 347 'where' => 'civicrm_address.is_primary',
45a83e42 348 'default' => '0',
522a26c9 349 'table_name' => 'civicrm_address',
350 'entity' => 'Address',
351 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 352 'localizable' => 0,
c3fc2621 353 'html' => [
b6673dcd 354 'type' => 'Radio',
c3fc2621 355 ],
a9d0587b 356 'add' => '2.0',
c3fc2621
CW
357 ],
358 'is_billing' => [
e501603b
TO
359 'name' => 'is_billing',
360 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621 361 'title' => ts('Is Billing Address'),
215b423e 362 'description' => ts('Is this the billing address.'),
a36434b9 363 'where' => 'civicrm_address.is_billing',
45a83e42 364 'default' => '0',
522a26c9 365 'table_name' => 'civicrm_address',
366 'entity' => 'Address',
367 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 368 'localizable' => 0,
c3fc2621 369 'html' => [
e501603b 370 'type' => 'CheckBox',
c3fc2621 371 ],
a9d0587b 372 'add' => '2.0',
c3fc2621
CW
373 ],
374 'street_address' => [
e501603b
TO
375 'name' => 'street_address',
376 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 377 'title' => ts('Street Address'),
215b423e 378 'description' => ts('Concatenation of all routable street address components (prefix, street number, street name, suffix, unit
e501603b 379 number OR P.O. Box). Apps should be able to determine physical location with this data (for mapping, mail
fb607354 380 delivery, etc.).'),
e501603b
TO
381 'maxlength' => 96,
382 'size' => CRM_Utils_Type::HUGE,
c3fc2621 383 'import' => TRUE,
e501603b
TO
384 'where' => 'civicrm_address.street_address',
385 'headerPattern' => '/(street|address)/i',
386 'dataPattern' => '/^(\d{1,5}( [0-9A-Za-z]+)+)$|^(P\.?O\.\? Box \d{1,5})$/i',
c3fc2621 387 'export' => TRUE,
522a26c9 388 'table_name' => 'civicrm_address',
389 'entity' => 'Address',
390 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 391 'localizable' => 0,
c3fc2621 392 'html' => [
e501603b 393 'type' => 'Text',
c3fc2621 394 ],
a9d0587b 395 'add' => '1.1',
c3fc2621
CW
396 ],
397 'street_number' => [
e501603b
TO
398 'name' => 'street_number',
399 'type' => CRM_Utils_Type::T_INT,
c3fc2621 400 'title' => ts('Street Number'),
215b423e 401 'description' => ts('Numeric portion of address number on the street, e.g. For 112A Main St, the street_number = 112.'),
e501603b 402 'where' => 'civicrm_address.street_number',
a36434b9 403 'export' => TRUE,
522a26c9 404 'table_name' => 'civicrm_address',
405 'entity' => 'Address',
406 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 407 'localizable' => 0,
c3fc2621 408 'html' => [
e501603b 409 'type' => 'Text',
c3fc2621 410 ],
a9d0587b 411 'add' => '1.1',
c3fc2621
CW
412 ],
413 'street_number_suffix' => [
e501603b
TO
414 'name' => 'street_number_suffix',
415 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 416 'title' => ts('Street Number Suffix'),
fb607354 417 'description' => ts('Non-numeric portion of address number on the street, e.g. For 112A Main St, the street_number_suffix = A'),
e501603b
TO
418 'maxlength' => 8,
419 'size' => CRM_Utils_Type::EIGHT,
e501603b 420 'where' => 'civicrm_address.street_number_suffix',
a36434b9 421 'export' => TRUE,
522a26c9 422 'table_name' => 'civicrm_address',
423 'entity' => 'Address',
424 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 425 'localizable' => 0,
c3fc2621 426 'html' => [
e501603b 427 'type' => 'Text',
c3fc2621 428 ],
a9d0587b 429 'add' => '1.1',
c3fc2621
CW
430 ],
431 'street_number_predirectional' => [
e501603b
TO
432 'name' => 'street_number_predirectional',
433 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 434 'title' => ts('Street Direction Prefix'),
215b423e 435 'description' => ts('Directional prefix, e.g. SE Main St, SE is the prefix.'),
e501603b
TO
436 'maxlength' => 8,
437 'size' => CRM_Utils_Type::EIGHT,
a36434b9 438 'where' => 'civicrm_address.street_number_predirectional',
522a26c9 439 'table_name' => 'civicrm_address',
440 'entity' => 'Address',
441 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 442 'localizable' => 0,
c3fc2621 443 'html' => [
e501603b 444 'type' => 'Text',
c3fc2621 445 ],
a9d0587b 446 'add' => '1.1',
c3fc2621
CW
447 ],
448 'street_name' => [
e501603b
TO
449 'name' => 'street_name',
450 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 451 'title' => ts('Street Name'),
215b423e 452 'description' => ts('Actual street name, excluding St, Dr, Rd, Ave, e.g. For 112 Main St, the street_name = Main.'),
e501603b
TO
453 'maxlength' => 64,
454 'size' => CRM_Utils_Type::BIG,
e501603b 455 'where' => 'civicrm_address.street_name',
a36434b9 456 'export' => TRUE,
522a26c9 457 'table_name' => 'civicrm_address',
458 'entity' => 'Address',
459 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 460 'localizable' => 0,
c3fc2621 461 'html' => [
e501603b 462 'type' => 'Text',
c3fc2621 463 ],
a9d0587b 464 'add' => '1.1',
c3fc2621
CW
465 ],
466 'street_type' => [
e501603b
TO
467 'name' => 'street_type',
468 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 469 'title' => ts('Street Type'),
215b423e 470 'description' => ts('St, Rd, Dr, etc.'),
e501603b
TO
471 'maxlength' => 8,
472 'size' => CRM_Utils_Type::EIGHT,
a36434b9 473 'where' => 'civicrm_address.street_type',
522a26c9 474 'table_name' => 'civicrm_address',
475 'entity' => 'Address',
476 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 477 'localizable' => 0,
c3fc2621 478 'html' => [
e501603b 479 'type' => 'Text',
c3fc2621 480 ],
a9d0587b 481 'add' => '1.1',
c3fc2621
CW
482 ],
483 'street_number_postdirectional' => [
e501603b
TO
484 'name' => 'street_number_postdirectional',
485 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 486 'title' => ts('Street Direction Suffix'),
215b423e 487 'description' => ts('Directional prefix, e.g. Main St S, S is the suffix.'),
e501603b
TO
488 'maxlength' => 8,
489 'size' => CRM_Utils_Type::EIGHT,
a36434b9 490 'where' => 'civicrm_address.street_number_postdirectional',
522a26c9 491 'table_name' => 'civicrm_address',
492 'entity' => 'Address',
493 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 494 'localizable' => 0,
c3fc2621 495 'html' => [
e501603b 496 'type' => 'Text',
c3fc2621 497 ],
a9d0587b 498 'add' => '1.1',
c3fc2621
CW
499 ],
500 'street_unit' => [
e501603b
TO
501 'name' => 'street_unit',
502 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 503 'title' => ts('Street Unit'),
215b423e 504 'description' => ts('Secondary unit designator, e.g. Apt 3 or Unit # 14, or Bldg 1200'),
e501603b
TO
505 'maxlength' => 16,
506 'size' => CRM_Utils_Type::TWELVE,
e501603b 507 'where' => 'civicrm_address.street_unit',
a36434b9 508 'export' => TRUE,
522a26c9 509 'table_name' => 'civicrm_address',
510 'entity' => 'Address',
511 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 512 'localizable' => 0,
c3fc2621 513 'html' => [
e501603b 514 'type' => 'Text',
c3fc2621 515 ],
a9d0587b 516 'add' => '1.1',
c3fc2621
CW
517 ],
518 'supplemental_address_1' => [
e501603b
TO
519 'name' => 'supplemental_address_1',
520 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 521 'title' => ts('Supplemental Address 1'),
215b423e 522 'description' => ts('Supplemental Address Information, Line 1'),
e501603b
TO
523 'maxlength' => 96,
524 'size' => CRM_Utils_Type::HUGE,
c3fc2621 525 'import' => TRUE,
e501603b
TO
526 'where' => 'civicrm_address.supplemental_address_1',
527 'headerPattern' => '/(supplemental(\s)?)?address(\s\d+)?/i',
528 'dataPattern' => '/unit|ap(ar)?t(ment)?\s(\d|\w)+/i',
c3fc2621 529 'export' => TRUE,
522a26c9 530 'table_name' => 'civicrm_address',
531 'entity' => 'Address',
532 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 533 'localizable' => 0,
c3fc2621 534 'html' => [
e501603b 535 'type' => 'Text',
c3fc2621 536 ],
a9d0587b 537 'add' => '1.1',
c3fc2621
CW
538 ],
539 'supplemental_address_2' => [
e501603b
TO
540 'name' => 'supplemental_address_2',
541 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 542 'title' => ts('Supplemental Address 2'),
215b423e 543 'description' => ts('Supplemental Address Information, Line 2'),
e501603b
TO
544 'maxlength' => 96,
545 'size' => CRM_Utils_Type::HUGE,
c3fc2621 546 'import' => TRUE,
e501603b
TO
547 'where' => 'civicrm_address.supplemental_address_2',
548 'headerPattern' => '/(supplemental(\s)?)?address(\s\d+)?/i',
549 'dataPattern' => '/unit|ap(ar)?t(ment)?\s(\d|\w)+/i',
c3fc2621 550 'export' => TRUE,
522a26c9 551 'table_name' => 'civicrm_address',
552 'entity' => 'Address',
553 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 554 'localizable' => 0,
c3fc2621 555 'html' => [
e501603b 556 'type' => 'Text',
c3fc2621 557 ],
a9d0587b 558 'add' => '1.1',
c3fc2621
CW
559 ],
560 'supplemental_address_3' => [
e501603b
TO
561 'name' => 'supplemental_address_3',
562 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 563 'title' => ts('Supplemental Address 3'),
215b423e 564 'description' => ts('Supplemental Address Information, Line 3'),
e501603b
TO
565 'maxlength' => 96,
566 'size' => CRM_Utils_Type::HUGE,
c3fc2621 567 'import' => TRUE,
207f62c6
AS
568 'where' => 'civicrm_address.supplemental_address_3',
569 'headerPattern' => '/(supplemental(\s)?)?address(\s\d+)?/i',
570 'dataPattern' => '/unit|ap(ar)?t(ment)?\s(\d|\w)+/i',
c3fc2621 571 'export' => TRUE,
522a26c9 572 'table_name' => 'civicrm_address',
573 'entity' => 'Address',
574 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 575 'localizable' => 0,
c3fc2621 576 'html' => [
e501603b 577 'type' => 'Text',
c3fc2621 578 ],
a9d0587b 579 'add' => '1.1',
c3fc2621
CW
580 ],
581 'city' => [
e501603b
TO
582 'name' => 'city',
583 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 584 'title' => ts('City'),
215b423e 585 'description' => ts('City, Town or Village Name.'),
e501603b
TO
586 'maxlength' => 64,
587 'size' => CRM_Utils_Type::BIG,
c3fc2621 588 'import' => TRUE,
e501603b
TO
589 'where' => 'civicrm_address.city',
590 'headerPattern' => '/city/i',
591 'dataPattern' => '/^[A-Za-z]+(\.?)(\s?[A-Za-z]+){0,2}$/',
c3fc2621 592 'export' => TRUE,
522a26c9 593 'table_name' => 'civicrm_address',
594 'entity' => 'Address',
595 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 596 'localizable' => 0,
c3fc2621 597 'html' => [
e501603b 598 'type' => 'Text',
c3fc2621 599 ],
a9d0587b 600 'add' => '1.1',
c3fc2621
CW
601 ],
602 'county_id' => [
e501603b
TO
603 'name' => 'county_id',
604 'type' => CRM_Utils_Type::T_INT,
2cbbebe8 605 'title' => ts('County ID'),
215b423e 606 'description' => ts('Which County does this address belong to.'),
a36434b9 607 'where' => 'civicrm_address.county_id',
522a26c9 608 'table_name' => 'civicrm_address',
609 'entity' => 'Address',
610 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 611 'localizable' => 0,
e501603b 612 'FKClassName' => 'CRM_Core_DAO_County',
c3fc2621 613 'html' => [
e501603b 614 'type' => 'ChainSelect',
2cbbebe8 615 'label' => ts("County"),
8ada2bfd 616 'controlField' => 'state_province_id',
c3fc2621
CW
617 ],
618 'pseudoconstant' => [
e501603b
TO
619 'table' => 'civicrm_county',
620 'keyColumn' => 'id',
621 'labelColumn' => 'name',
70c5cd97 622 'abbrColumn' => 'abbreviation',
e6ca0a57 623 ],
a9d0587b 624 'add' => '1.1',
c3fc2621
CW
625 ],
626 'state_province_id' => [
e501603b
TO
627 'name' => 'state_province_id',
628 'type' => CRM_Utils_Type::T_INT,
2cbbebe8 629 'title' => ts('State/Province ID'),
215b423e 630 'description' => ts('Which State_Province does this address belong to.'),
a36434b9 631 'where' => 'civicrm_address.state_province_id',
522a26c9 632 'table_name' => 'civicrm_address',
633 'entity' => 'Address',
634 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 635 'localizable' => 0,
65c86f7d 636 'localize_context' => 'province',
e501603b 637 'FKClassName' => 'CRM_Core_DAO_StateProvince',
c3fc2621 638 'html' => [
e501603b 639 'type' => 'ChainSelect',
2cbbebe8 640 'label' => ts("State/Province"),
8ada2bfd 641 'controlField' => 'country_id',
c3fc2621
CW
642 ],
643 'pseudoconstant' => [
e501603b
TO
644 'table' => 'civicrm_state_province',
645 'keyColumn' => 'id',
646 'labelColumn' => 'name',
70c5cd97 647 'abbrColumn' => 'abbreviation',
e6ca0a57 648 ],
a9d0587b 649 'add' => '1.1',
c3fc2621
CW
650 ],
651 'postal_code_suffix' => [
e501603b
TO
652 'name' => 'postal_code_suffix',
653 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 654 'title' => ts('Postal Code Suffix'),
215b423e 655 'description' => ts('Store the suffix, like the +4 part in the USPS system.'),
e501603b
TO
656 'maxlength' => 12,
657 'size' => 3,
c3fc2621 658 'import' => TRUE,
e501603b
TO
659 'where' => 'civicrm_address.postal_code_suffix',
660 'headerPattern' => '/p(ostal)\sc(ode)\ss(uffix)/i',
661 'dataPattern' => '/\d?\d{4}(-\d{4})?/',
c3fc2621 662 'export' => TRUE,
522a26c9 663 'table_name' => 'civicrm_address',
664 'entity' => 'Address',
665 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 666 'localizable' => 0,
c3fc2621 667 'html' => [
e501603b 668 'type' => 'Text',
c3fc2621 669 ],
a9d0587b 670 'add' => '1.1',
c3fc2621
CW
671 ],
672 'postal_code' => [
e501603b
TO
673 'name' => 'postal_code',
674 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 675 'title' => ts('Postal Code'),
215b423e 676 'description' => ts('Store both US (zip5) AND international postal codes. App is responsible for country/region appropriate validation.'),
e501603b
TO
677 'maxlength' => 64,
678 'size' => 6,
c3fc2621 679 'import' => TRUE,
e501603b
TO
680 'where' => 'civicrm_address.postal_code',
681 'headerPattern' => '/postal|zip/i',
682 'dataPattern' => '/\d?\d{4}(-\d{4})?/',
c3fc2621 683 'export' => TRUE,
522a26c9 684 'table_name' => 'civicrm_address',
685 'entity' => 'Address',
686 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 687 'localizable' => 0,
c3fc2621 688 'html' => [
e501603b 689 'type' => 'Text',
c3fc2621 690 ],
a9d0587b 691 'add' => '1.1',
c3fc2621
CW
692 ],
693 'usps_adc' => [
e501603b
TO
694 'name' => 'usps_adc',
695 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 696 'title' => ts('USPS Code'),
215b423e 697 'description' => ts('USPS Bulk mailing code.'),
e501603b
TO
698 'maxlength' => 32,
699 'size' => CRM_Utils_Type::MEDIUM,
a36434b9 700 'where' => 'civicrm_address.usps_adc',
522a26c9 701 'table_name' => 'civicrm_address',
702 'entity' => 'Address',
703 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 704 'localizable' => 0,
a9d0587b 705 'add' => '1.1',
c3fc2621
CW
706 ],
707 'country_id' => [
e501603b
TO
708 'name' => 'country_id',
709 'type' => CRM_Utils_Type::T_INT,
2cbbebe8 710 'title' => ts('Country ID'),
215b423e 711 'description' => ts('Which Country does this address belong to.'),
a36434b9 712 'where' => 'civicrm_address.country_id',
522a26c9 713 'table_name' => 'civicrm_address',
714 'entity' => 'Address',
715 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 716 'localizable' => 0,
65c86f7d 717 'localize_context' => 'country',
e501603b 718 'FKClassName' => 'CRM_Core_DAO_Country',
c3fc2621 719 'html' => [
e501603b 720 'type' => 'Select',
2cbbebe8 721 'label' => ts("Country"),
c3fc2621
CW
722 ],
723 'pseudoconstant' => [
e501603b
TO
724 'table' => 'civicrm_country',
725 'keyColumn' => 'id',
726 'labelColumn' => 'name',
727 'nameColumn' => 'iso_code',
a8fdb24e 728 'abbrColumn' => 'iso_code',
e6ca0a57 729 ],
a9d0587b 730 'add' => '1.1',
c3fc2621
CW
731 ],
732 'geo_code_1' => [
e501603b
TO
733 'name' => 'geo_code_1',
734 'type' => CRM_Utils_Type::T_FLOAT,
c3fc2621 735 'title' => ts('Latitude'),
215b423e 736 'description' => ts('Latitude'),
c3fc2621 737 'import' => TRUE,
e501603b
TO
738 'where' => 'civicrm_address.geo_code_1',
739 'headerPattern' => '/geo/i',
c3fc2621 740 'export' => TRUE,
522a26c9 741 'table_name' => 'civicrm_address',
742 'entity' => 'Address',
743 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 744 'localizable' => 0,
c3fc2621 745 'html' => [
e501603b 746 'type' => 'Text',
c3fc2621 747 ],
a9d0587b 748 'add' => '1.1',
c3fc2621
CW
749 ],
750 'geo_code_2' => [
e501603b
TO
751 'name' => 'geo_code_2',
752 'type' => CRM_Utils_Type::T_FLOAT,
c3fc2621 753 'title' => ts('Longitude'),
215b423e 754 'description' => ts('Longitude'),
c3fc2621 755 'import' => TRUE,
e501603b
TO
756 'where' => 'civicrm_address.geo_code_2',
757 'headerPattern' => '/geo/i',
c3fc2621 758 'export' => TRUE,
522a26c9 759 'table_name' => 'civicrm_address',
760 'entity' => 'Address',
761 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 762 'localizable' => 0,
c3fc2621 763 'html' => [
e501603b 764 'type' => 'Text',
c3fc2621 765 ],
a9d0587b 766 'add' => '1.1',
c3fc2621
CW
767 ],
768 'manual_geo_code' => [
e501603b
TO
769 'name' => 'manual_geo_code',
770 'type' => CRM_Utils_Type::T_BOOLEAN,
4fcfc078 771 'title' => ts('Is Manually Geocoded'),
215b423e 772 'description' => ts('Is this a manually entered geo code'),
a36434b9 773 'where' => 'civicrm_address.manual_geo_code',
4fcfc078 774 'export' => TRUE,
45a83e42 775 'default' => '0',
522a26c9 776 'table_name' => 'civicrm_address',
777 'entity' => 'Address',
778 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 779 'localizable' => 0,
c3fc2621 780 'html' => [
e501603b 781 'type' => 'CheckBox',
c3fc2621 782 ],
a9d0587b 783 'add' => '4.3',
c3fc2621
CW
784 ],
785 'timezone' => [
e501603b
TO
786 'name' => 'timezone',
787 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 788 'title' => ts('Timezone'),
215b423e 789 'description' => ts('Timezone expressed as a UTC offset - e.g. United States CST would be written as "UTC-6".'),
e501603b
TO
790 'maxlength' => 8,
791 'size' => CRM_Utils_Type::EIGHT,
a36434b9 792 'where' => 'civicrm_address.timezone',
522a26c9 793 'table_name' => 'civicrm_address',
794 'entity' => 'Address',
795 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 796 'localizable' => 0,
c3fc2621 797 'html' => [
e501603b 798 'type' => 'Text',
c3fc2621 799 ],
a9d0587b 800 'add' => '1.1',
c3fc2621
CW
801 ],
802 'address_name' => [
e501603b
TO
803 'name' => 'name',
804 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 805 'title' => ts('Address Name'),
e501603b
TO
806 'maxlength' => 255,
807 'size' => CRM_Utils_Type::HUGE,
c3fc2621 808 'import' => TRUE,
e501603b
TO
809 'where' => 'civicrm_address.name',
810 'headerPattern' => '/^location|(l(ocation\s)?name)$/i',
811 'dataPattern' => '/^\w+$/',
c3fc2621 812 'export' => TRUE,
522a26c9 813 'table_name' => 'civicrm_address',
814 'entity' => 'Address',
815 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 816 'localizable' => 0,
c3fc2621 817 'html' => [
e501603b 818 'type' => 'Text',
c3fc2621 819 ],
a9d0587b 820 'add' => '2.1',
c3fc2621
CW
821 ],
822 'master_id' => [
e501603b
TO
823 'name' => 'master_id',
824 'type' => CRM_Utils_Type::T_INT,
2cbbebe8 825 'title' => ts('Master Address ID'),
215b423e 826 'description' => ts('FK to Address ID'),
c3fc2621 827 'import' => TRUE,
e501603b 828 'where' => 'civicrm_address.master_id',
c3fc2621 829 'export' => TRUE,
522a26c9 830 'table_name' => 'civicrm_address',
831 'entity' => 'Address',
832 'bao' => 'CRM_Core_BAO_Address',
6a7e5e5d 833 'localizable' => 0,
e501603b 834 'FKClassName' => 'CRM_Core_DAO_Address',
2cbbebe8
A
835 'html' => [
836 'label' => ts("Master Address Belongs To"),
837 ],
a9d0587b 838 'add' => '3.3',
c3fc2621
CW
839 ],
840 ];
346aaaba 841 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
e501603b 842 }
346aaaba 843 return Civi::$statics[__CLASS__]['fields'];
e501603b 844 }
c3fc2621 845
e501603b 846 /**
bd8e0b14 847 * Return a mapping from field-name to the corresponding key (as used in fields()).
e501603b
TO
848 *
849 * @return array
bd8e0b14 850 * Array(string $name => string $uniqueName).
e501603b 851 */
c3fc2621 852 public static function &fieldKeys() {
bd8e0b14
TO
853 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
854 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
e501603b 855 }
bd8e0b14 856 return Civi::$statics[__CLASS__]['fieldKeys'];
e501603b 857 }
c3fc2621 858
e501603b
TO
859 /**
860 * Returns the names of this table
861 *
862 * @return string
863 */
c3fc2621 864 public static function getTableName() {
e501603b
TO
865 return self::$_tableName;
866 }
c3fc2621 867
e501603b
TO
868 /**
869 * Returns if this table needs to be logged
870 *
c3fc2621 871 * @return bool
e501603b 872 */
c3fc2621 873 public function getLog() {
e501603b
TO
874 return self::$_log;
875 }
c3fc2621 876
e501603b
TO
877 /**
878 * Returns the list of fields that can be imported
879 *
880 * @param bool $prefix
881 *
882 * @return array
883 */
c3fc2621
CW
884 public static function &import($prefix = FALSE) {
885 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'address', $prefix, [
60808919
TO
886 'CRM_Core_DAO_County',
887 'CRM_Core_DAO_StateProvince',
888 'CRM_Core_DAO_Country',
c3fc2621 889 ]);
60808919 890 return $r;
e501603b 891 }
c3fc2621 892
e501603b
TO
893 /**
894 * Returns the list of fields that can be exported
895 *
896 * @param bool $prefix
897 *
898 * @return array
899 */
c3fc2621
CW
900 public static function &export($prefix = FALSE) {
901 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'address', $prefix, [
60808919
TO
902 'CRM_Core_DAO_County',
903 'CRM_Core_DAO_StateProvince',
904 'CRM_Core_DAO_Country',
c3fc2621 905 ]);
60808919 906 return $r;
e501603b 907 }
c3fc2621 908
e7a6b91a
AS
909 /**
910 * Returns the list of indices
c3fc2621
CW
911 *
912 * @param bool $localize
913 *
914 * @return array
e7a6b91a
AS
915 */
916 public static function indices($localize = TRUE) {
c3fc2621
CW
917 $indices = [
918 'index_location_type' => [
e7a6b91a 919 'name' => 'index_location_type',
c3fc2621 920 'field' => [
e7a6b91a 921 0 => 'location_type_id',
c3fc2621
CW
922 ],
923 'localizable' => FALSE,
e7a6b91a 924 'sig' => 'civicrm_address::0::location_type_id',
c3fc2621
CW
925 ],
926 'index_is_primary' => [
e7a6b91a 927 'name' => 'index_is_primary',
c3fc2621 928 'field' => [
e7a6b91a 929 0 => 'is_primary',
c3fc2621
CW
930 ],
931 'localizable' => FALSE,
e7a6b91a 932 'sig' => 'civicrm_address::0::is_primary',
c3fc2621
CW
933 ],
934 'index_is_billing' => [
e7a6b91a 935 'name' => 'index_is_billing',
c3fc2621 936 'field' => [
e7a6b91a 937 0 => 'is_billing',
c3fc2621
CW
938 ],
939 'localizable' => FALSE,
e7a6b91a 940 'sig' => 'civicrm_address::0::is_billing',
c3fc2621
CW
941 ],
942 'index_street_name' => [
e7a6b91a 943 'name' => 'index_street_name',
c3fc2621 944 'field' => [
e7a6b91a 945 0 => 'street_name',
c3fc2621
CW
946 ],
947 'localizable' => FALSE,
e7a6b91a 948 'sig' => 'civicrm_address::0::street_name',
c3fc2621
CW
949 ],
950 'index_city' => [
e7a6b91a 951 'name' => 'index_city',
c3fc2621 952 'field' => [
e7a6b91a 953 0 => 'city',
c3fc2621
CW
954 ],
955 'localizable' => FALSE,
e7a6b91a 956 'sig' => 'civicrm_address::0::city',
c3fc2621 957 ],
d56bfd0e
SL
958 'index_geo_code_1_geo_code_2' => [
959 'name' => 'index_geo_code_1_geo_code_2',
960 'field' => [
961 0 => 'geo_code_1',
962 1 => 'geo_code_2',
963 ],
964 'localizable' => FALSE,
965 'sig' => 'civicrm_address::0::geo_code_1::geo_code_2',
966 ],
c3fc2621 967 ];
e7a6b91a
AS
968 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
969 }
c3fc2621 970
e501603b 971}