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