5 * @copyright CiviCRM LLC https://civicrm.org/licensing
7 * Generated from xml/schema/CRM/Core/Address.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:01b95dc4df972f40d718b61c77cd3b58)
13 * Database access object for the Address entity.
15 class CRM_Core_DAO_Address
extends CRM_Core_DAO
{
16 const EXT
= 'civicrm';
17 const TABLE_ADDED
= '1.1';
20 * Static instance to hold the table name.
24 public static $_tableName = 'civicrm_address';
27 * Icon associated with this entity.
31 public static $_icon = 'fa-map-marker';
34 * Should CiviCRM log any modifications to this table in the civicrm_log table.
38 public static $_log = TRUE;
55 * Which Location does this address belong to.
59 public $location_type_id;
62 * Is this the primary address.
69 * Is this the billing address.
76 * Concatenation of all routable street address components (prefix, street number, street name, suffix, unit
77 * number OR P.O. Box). Apps should be able to determine physical location with this data (for mapping, mail
82 public $street_address;
85 * Numeric portion of address number on the street, e.g. For 112A Main St, the street_number = 112.
89 public $street_number;
92 * Non-numeric portion of address number on the street, e.g. For 112A Main St, the street_number_suffix = A
96 public $street_number_suffix;
99 * Directional prefix, e.g. SE Main St, SE is the prefix.
103 public $street_number_predirectional;
106 * Actual street name, excluding St, Dr, Rd, Ave, e.g. For 112 Main St, the street_name = Main.
120 * Directional prefix, e.g. Main St S, S is the suffix.
124 public $street_number_postdirectional;
127 * Secondary unit designator, e.g. Apt 3 or Unit # 14, or Bldg 1200
134 * Supplemental Address Information, Line 1
138 public $supplemental_address_1;
141 * Supplemental Address Information, Line 2
145 public $supplemental_address_2;
148 * Supplemental Address Information, Line 3
152 public $supplemental_address_3;
155 * City, Town or Village Name.
162 * Which County does this address belong to.
169 * Which State_Province does this address belong to.
173 public $state_province_id;
176 * Store the suffix, like the +4 part in the USPS system.
180 public $postal_code_suffix;
183 * Store both US (zip5) AND international postal codes. App is responsible for country/region appropriate validation.
190 * USPS Bulk mailing code.
197 * Which Country does this address belong to.
218 * Is this a manually entered geo code
222 public $manual_geo_code;
225 * Timezone expressed as a UTC offset - e.g. United States CST would be written as "UTC-6".
246 public function __construct() {
247 $this->__table
= 'civicrm_address';
248 parent
::__construct();
252 * Returns localized title of this entity.
254 * @param bool $plural
255 * Whether to return the plural version of the title.
257 public static function getEntityTitle($plural = FALSE) {
258 return $plural ?
ts('Addresses') : ts('Address');
262 * Returns foreign keys and entity references.
265 * [CRM_Core_Reference_Interface]
267 public static function getReferenceColumns() {
268 if (!isset(Civi
::$statics[__CLASS__
]['links'])) {
269 Civi
::$statics[__CLASS__
]['links'] = static::createReferenceColumns(__CLASS__
);
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');
275 CRM_Core_DAO_AllCoreTables
::invoke(__CLASS__
, 'links_callback', Civi
::$statics[__CLASS__
]['links']);
277 return Civi
::$statics[__CLASS__
]['links'];
281 * Returns all the column names of this table
285 public static function &fields() {
286 if (!isset(Civi
::$statics[__CLASS__
]['fields'])) {
287 Civi
::$statics[__CLASS__
]['fields'] = [
290 'type' => CRM_Utils_Type
::T_INT
,
291 'title' => ts('Address ID'),
292 'description' => ts('Unique Address ID'),
294 'where' => 'civicrm_address.id',
296 'table_name' => 'civicrm_address',
297 'entity' => 'Address',
298 'bao' => 'CRM_Core_BAO_Address',
303 'name' => 'contact_id',
304 'type' => CRM_Utils_Type
::T_INT
,
305 'title' => ts('Contact ID'),
306 'description' => ts('FK to Contact ID'),
307 'where' => 'civicrm_address.contact_id',
308 'table_name' => 'civicrm_address',
309 'entity' => 'Address',
310 'bao' => 'CRM_Core_BAO_Address',
312 'FKClassName' => 'CRM_Contact_DAO_Contact',
315 'location_type_id' => [
316 'name' => 'location_type_id',
317 'type' => CRM_Utils_Type
::T_INT
,
318 'title' => ts('Address Location Type'),
319 'description' => ts('Which Location does this address belong to.'),
320 'where' => 'civicrm_address.location_type_id',
321 'table_name' => 'civicrm_address',
322 'entity' => 'Address',
323 'bao' => 'CRM_Core_BAO_Address',
328 'pseudoconstant' => [
329 'table' => 'civicrm_location_type',
331 'labelColumn' => 'display_name',
336 'name' => 'is_primary',
337 'type' => CRM_Utils_Type
::T_BOOLEAN
,
338 'title' => ts('Primary address'),
339 'description' => ts('Is this the primary address.'),
340 'where' => 'civicrm_address.is_primary',
342 'table_name' => 'civicrm_address',
343 'entity' => 'Address',
344 'bao' => 'CRM_Core_BAO_Address',
352 'name' => 'is_billing',
353 'type' => CRM_Utils_Type
::T_BOOLEAN
,
354 'title' => ts('Is Billing Address'),
355 'description' => ts('Is this the billing address.'),
356 'where' => 'civicrm_address.is_billing',
358 'table_name' => 'civicrm_address',
359 'entity' => 'Address',
360 'bao' => 'CRM_Core_BAO_Address',
363 'type' => 'CheckBox',
367 'street_address' => [
368 'name' => 'street_address',
369 'type' => CRM_Utils_Type
::T_STRING
,
370 'title' => ts('Street Address'),
371 'description' => ts('Concatenation of all routable street address components (prefix, street number, street name, suffix, unit
372 number OR P.O. Box). Apps should be able to determine physical location with this data (for mapping, mail
375 'size' => CRM_Utils_Type
::HUGE
,
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',
381 'table_name' => 'civicrm_address',
382 'entity' => 'Address',
383 'bao' => 'CRM_Core_BAO_Address',
391 'name' => 'street_number',
392 'type' => CRM_Utils_Type
::T_INT
,
393 'title' => ts('Street Number'),
394 'description' => ts('Numeric portion of address number on the street, e.g. For 112A Main St, the street_number = 112.'),
395 'where' => 'civicrm_address.street_number',
397 'table_name' => 'civicrm_address',
398 'entity' => 'Address',
399 'bao' => 'CRM_Core_BAO_Address',
406 'street_number_suffix' => [
407 'name' => 'street_number_suffix',
408 'type' => CRM_Utils_Type
::T_STRING
,
409 'title' => ts('Street Number Suffix'),
410 'description' => ts('Non-numeric portion of address number on the street, e.g. For 112A Main St, the street_number_suffix = A'),
412 'size' => CRM_Utils_Type
::EIGHT
,
413 'where' => 'civicrm_address.street_number_suffix',
415 'table_name' => 'civicrm_address',
416 'entity' => 'Address',
417 'bao' => 'CRM_Core_BAO_Address',
424 'street_number_predirectional' => [
425 'name' => 'street_number_predirectional',
426 'type' => CRM_Utils_Type
::T_STRING
,
427 'title' => ts('Street Direction Prefix'),
428 'description' => ts('Directional prefix, e.g. SE Main St, SE is the prefix.'),
430 'size' => CRM_Utils_Type
::EIGHT
,
431 'where' => 'civicrm_address.street_number_predirectional',
432 'table_name' => 'civicrm_address',
433 'entity' => 'Address',
434 'bao' => 'CRM_Core_BAO_Address',
442 'name' => 'street_name',
443 'type' => CRM_Utils_Type
::T_STRING
,
444 'title' => ts('Street Name'),
445 'description' => ts('Actual street name, excluding St, Dr, Rd, Ave, e.g. For 112 Main St, the street_name = Main.'),
447 'size' => CRM_Utils_Type
::BIG
,
448 'where' => 'civicrm_address.street_name',
450 'table_name' => 'civicrm_address',
451 'entity' => 'Address',
452 'bao' => 'CRM_Core_BAO_Address',
460 'name' => 'street_type',
461 'type' => CRM_Utils_Type
::T_STRING
,
462 'title' => ts('Street Type'),
463 'description' => ts('St, Rd, Dr, etc.'),
465 'size' => CRM_Utils_Type
::EIGHT
,
466 'where' => 'civicrm_address.street_type',
467 'table_name' => 'civicrm_address',
468 'entity' => 'Address',
469 'bao' => 'CRM_Core_BAO_Address',
476 'street_number_postdirectional' => [
477 'name' => 'street_number_postdirectional',
478 'type' => CRM_Utils_Type
::T_STRING
,
479 'title' => ts('Street Direction Suffix'),
480 'description' => ts('Directional prefix, e.g. Main St S, S is the suffix.'),
482 'size' => CRM_Utils_Type
::EIGHT
,
483 'where' => 'civicrm_address.street_number_postdirectional',
484 'table_name' => 'civicrm_address',
485 'entity' => 'Address',
486 'bao' => 'CRM_Core_BAO_Address',
494 'name' => 'street_unit',
495 'type' => CRM_Utils_Type
::T_STRING
,
496 'title' => ts('Street Unit'),
497 'description' => ts('Secondary unit designator, e.g. Apt 3 or Unit # 14, or Bldg 1200'),
499 'size' => CRM_Utils_Type
::TWELVE
,
500 'where' => 'civicrm_address.street_unit',
502 'table_name' => 'civicrm_address',
503 'entity' => 'Address',
504 'bao' => 'CRM_Core_BAO_Address',
511 'supplemental_address_1' => [
512 'name' => 'supplemental_address_1',
513 'type' => CRM_Utils_Type
::T_STRING
,
514 'title' => ts('Supplemental Address 1'),
515 'description' => ts('Supplemental Address Information, Line 1'),
517 'size' => CRM_Utils_Type
::HUGE
,
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',
523 'table_name' => 'civicrm_address',
524 'entity' => 'Address',
525 'bao' => 'CRM_Core_BAO_Address',
532 'supplemental_address_2' => [
533 'name' => 'supplemental_address_2',
534 'type' => CRM_Utils_Type
::T_STRING
,
535 'title' => ts('Supplemental Address 2'),
536 'description' => ts('Supplemental Address Information, Line 2'),
538 'size' => CRM_Utils_Type
::HUGE
,
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',
544 'table_name' => 'civicrm_address',
545 'entity' => 'Address',
546 'bao' => 'CRM_Core_BAO_Address',
553 'supplemental_address_3' => [
554 'name' => 'supplemental_address_3',
555 'type' => CRM_Utils_Type
::T_STRING
,
556 'title' => ts('Supplemental Address 3'),
557 'description' => ts('Supplemental Address Information, Line 3'),
559 'size' => CRM_Utils_Type
::HUGE
,
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',
565 'table_name' => 'civicrm_address',
566 'entity' => 'Address',
567 'bao' => 'CRM_Core_BAO_Address',
576 'type' => CRM_Utils_Type
::T_STRING
,
577 'title' => ts('City'),
578 'description' => ts('City, Town or Village Name.'),
580 'size' => CRM_Utils_Type
::BIG
,
582 'where' => 'civicrm_address.city',
583 'headerPattern' => '/city/i',
584 'dataPattern' => '/^[A-Za-z]+(\.?)(\s?[A-Za-z]+){0,2}$/',
586 'table_name' => 'civicrm_address',
587 'entity' => 'Address',
588 'bao' => 'CRM_Core_BAO_Address',
596 'name' => 'county_id',
597 'type' => CRM_Utils_Type
::T_INT
,
598 'title' => ts('County'),
599 'description' => ts('Which County does this address belong to.'),
600 'where' => 'civicrm_address.county_id',
601 'table_name' => 'civicrm_address',
602 'entity' => 'Address',
603 'bao' => 'CRM_Core_BAO_Address',
605 'FKClassName' => 'CRM_Core_DAO_County',
607 'type' => 'ChainSelect',
608 'controlField' => 'state_province_id',
610 'pseudoconstant' => [
611 'table' => 'civicrm_county',
613 'labelColumn' => 'name',
617 'state_province_id' => [
618 'name' => 'state_province_id',
619 'type' => CRM_Utils_Type
::T_INT
,
620 'title' => ts('State/Province'),
621 'description' => ts('Which State_Province does this address belong to.'),
622 'where' => 'civicrm_address.state_province_id',
623 'table_name' => 'civicrm_address',
624 'entity' => 'Address',
625 'bao' => 'CRM_Core_BAO_Address',
627 'localize_context' => 'province',
628 'FKClassName' => 'CRM_Core_DAO_StateProvince',
630 'type' => 'ChainSelect',
631 'controlField' => 'country_id',
633 'pseudoconstant' => [
634 'table' => 'civicrm_state_province',
636 'labelColumn' => 'name',
640 'postal_code_suffix' => [
641 'name' => 'postal_code_suffix',
642 'type' => CRM_Utils_Type
::T_STRING
,
643 'title' => ts('Postal Code Suffix'),
644 'description' => ts('Store the suffix, like the +4 part in the USPS system.'),
648 'where' => 'civicrm_address.postal_code_suffix',
649 'headerPattern' => '/p(ostal)\sc(ode)\ss(uffix)/i',
650 'dataPattern' => '/\d?\d{4}(-\d{4})?/',
652 'table_name' => 'civicrm_address',
653 'entity' => 'Address',
654 'bao' => 'CRM_Core_BAO_Address',
662 'name' => 'postal_code',
663 'type' => CRM_Utils_Type
::T_STRING
,
664 'title' => ts('Postal Code'),
665 'description' => ts('Store both US (zip5) AND international postal codes. App is responsible for country/region appropriate validation.'),
669 'where' => 'civicrm_address.postal_code',
670 'headerPattern' => '/postal|zip/i',
671 'dataPattern' => '/\d?\d{4}(-\d{4})?/',
673 'table_name' => 'civicrm_address',
674 'entity' => 'Address',
675 'bao' => 'CRM_Core_BAO_Address',
683 'name' => 'usps_adc',
684 'type' => CRM_Utils_Type
::T_STRING
,
685 'title' => ts('USPS Code'),
686 'description' => ts('USPS Bulk mailing code.'),
688 'size' => CRM_Utils_Type
::MEDIUM
,
689 'where' => 'civicrm_address.usps_adc',
690 'table_name' => 'civicrm_address',
691 'entity' => 'Address',
692 'bao' => 'CRM_Core_BAO_Address',
697 'name' => 'country_id',
698 'type' => CRM_Utils_Type
::T_INT
,
699 'title' => ts('Country'),
700 'description' => ts('Which Country does this address belong to.'),
701 'where' => 'civicrm_address.country_id',
702 'table_name' => 'civicrm_address',
703 'entity' => 'Address',
704 'bao' => 'CRM_Core_BAO_Address',
706 'localize_context' => 'country',
707 'FKClassName' => 'CRM_Core_DAO_Country',
711 'pseudoconstant' => [
712 'table' => 'civicrm_country',
714 'labelColumn' => 'name',
715 'nameColumn' => 'iso_code',
716 'abbrColumn' => 'iso_code',
721 'name' => 'geo_code_1',
722 'type' => CRM_Utils_Type
::T_FLOAT
,
723 'title' => ts('Latitude'),
724 'description' => ts('Latitude'),
726 'where' => 'civicrm_address.geo_code_1',
727 'headerPattern' => '/geo/i',
729 'table_name' => 'civicrm_address',
730 'entity' => 'Address',
731 'bao' => 'CRM_Core_BAO_Address',
739 'name' => 'geo_code_2',
740 'type' => CRM_Utils_Type
::T_FLOAT
,
741 'title' => ts('Longitude'),
742 'description' => ts('Longitude'),
744 'where' => 'civicrm_address.geo_code_2',
745 'headerPattern' => '/geo/i',
747 'table_name' => 'civicrm_address',
748 'entity' => 'Address',
749 'bao' => 'CRM_Core_BAO_Address',
756 'manual_geo_code' => [
757 'name' => 'manual_geo_code',
758 'type' => CRM_Utils_Type
::T_BOOLEAN
,
759 'title' => ts('Is Manually Geocoded'),
760 'description' => ts('Is this a manually entered geo code'),
761 'where' => 'civicrm_address.manual_geo_code',
764 'table_name' => 'civicrm_address',
765 'entity' => 'Address',
766 'bao' => 'CRM_Core_BAO_Address',
769 'type' => 'CheckBox',
774 'name' => 'timezone',
775 'type' => CRM_Utils_Type
::T_STRING
,
776 'title' => ts('Timezone'),
777 'description' => ts('Timezone expressed as a UTC offset - e.g. United States CST would be written as "UTC-6".'),
779 'size' => CRM_Utils_Type
::EIGHT
,
780 'where' => 'civicrm_address.timezone',
781 'table_name' => 'civicrm_address',
782 'entity' => 'Address',
783 'bao' => 'CRM_Core_BAO_Address',
792 'type' => CRM_Utils_Type
::T_STRING
,
793 'title' => ts('Address Name'),
795 'size' => CRM_Utils_Type
::HUGE
,
797 'where' => 'civicrm_address.name',
798 'headerPattern' => '/^location|(l(ocation\s)?name)$/i',
799 'dataPattern' => '/^\w+$/',
801 'table_name' => 'civicrm_address',
802 'entity' => 'Address',
803 'bao' => 'CRM_Core_BAO_Address',
811 'name' => 'master_id',
812 'type' => CRM_Utils_Type
::T_INT
,
813 'title' => ts('Master Address Belongs To'),
814 'description' => ts('FK to Address ID'),
816 'where' => 'civicrm_address.master_id',
818 'table_name' => 'civicrm_address',
819 'entity' => 'Address',
820 'bao' => 'CRM_Core_BAO_Address',
822 'FKClassName' => 'CRM_Core_DAO_Address',
826 CRM_Core_DAO_AllCoreTables
::invoke(__CLASS__
, 'fields_callback', Civi
::$statics[__CLASS__
]['fields']);
828 return Civi
::$statics[__CLASS__
]['fields'];
832 * Return a mapping from field-name to the corresponding key (as used in fields()).
835 * Array(string $name => string $uniqueName).
837 public static function &fieldKeys() {
838 if (!isset(Civi
::$statics[__CLASS__
]['fieldKeys'])) {
839 Civi
::$statics[__CLASS__
]['fieldKeys'] = array_flip(CRM_Utils_Array
::collect('name', self
::fields()));
841 return Civi
::$statics[__CLASS__
]['fieldKeys'];
845 * Returns the names of this table
849 public static function getTableName() {
850 return self
::$_tableName;
854 * Returns if this table needs to be logged
858 public function getLog() {
863 * Returns the list of fields that can be imported
865 * @param bool $prefix
869 public static function &import($prefix = FALSE) {
870 $r = CRM_Core_DAO_AllCoreTables
::getImports(__CLASS__
, 'address', $prefix, [
871 'CRM_Core_DAO_County',
872 'CRM_Core_DAO_StateProvince',
873 'CRM_Core_DAO_Country',
879 * Returns the list of fields that can be exported
881 * @param bool $prefix
885 public static function &export($prefix = FALSE) {
886 $r = CRM_Core_DAO_AllCoreTables
::getExports(__CLASS__
, 'address', $prefix, [
887 'CRM_Core_DAO_County',
888 'CRM_Core_DAO_StateProvince',
889 'CRM_Core_DAO_Country',
895 * Returns the list of indices
897 * @param bool $localize
901 public static function indices($localize = TRUE) {
903 'index_location_type' => [
904 'name' => 'index_location_type',
906 0 => 'location_type_id',
908 'localizable' => FALSE,
909 'sig' => 'civicrm_address::0::location_type_id',
911 'index_is_primary' => [
912 'name' => 'index_is_primary',
916 'localizable' => FALSE,
917 'sig' => 'civicrm_address::0::is_primary',
919 'index_is_billing' => [
920 'name' => 'index_is_billing',
924 'localizable' => FALSE,
925 'sig' => 'civicrm_address::0::is_billing',
927 'index_street_name' => [
928 'name' => 'index_street_name',
932 'localizable' => FALSE,
933 'sig' => 'civicrm_address::0::street_name',
936 'name' => 'index_city',
940 'localizable' => FALSE,
941 'sig' => 'civicrm_address::0::city',
943 'index_geo_code_1_geo_code_2' => [
944 'name' => 'index_geo_code_1_geo_code_2',
949 'localizable' => FALSE,
950 'sig' => 'civicrm_address::0::geo_code_1::geo_code_2',
953 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables
::multilingualize(__CLASS__
, $indices) : $indices;