3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
33 class CRM_Contact_BAO_Contact_Location
{
36 * Get the display name, primary email, location type and location id of a contact.
41 * @param bool $isPrimary
42 * @param int $locationTypeID
45 * Array of display_name, email, location type and location id if found, or (null,null,null, null)
47 public static function getEmailDetails($id, $isPrimary = TRUE, $locationTypeID = NULL) {
49 'location_type_id' => $locationTypeID,
51 'return' => array('contact_id.display_name', 'email', 'location_type_id', 'id'),
54 $params['is_primary'] = 1;
56 $emails = civicrm_api3('Email', 'get', $params);
58 if ($emails['count'] > 0) {
59 $email = reset($emails['values']);
60 return array($email['contact_id.display_name'], $email['email'], $email['location_type_id'], $email['id']);
62 return array(NULL, NULL, NULL, NULL);
66 * @deprecated Not used anywhere, use the Phone API instead
67 * Get the sms number and display name of a contact.
75 * tuple of display_name and sms if found, or (null,null)
77 public static function getPhoneDetails($id, $type = NULL) {
78 CRM_Core_Error
::deprecatedFunctionWarning('Phone.get API instead');
80 return array(NULL, NULL);
85 $cond = " AND civicrm_phone.phone_type_id = '$type'";
89 SELECT civicrm_contact.display_name, civicrm_phone.phone, civicrm_contact.do_not_sms
91 LEFT JOIN civicrm_phone ON ( civicrm_phone.contact_id = civicrm_contact.id )
92 WHERE civicrm_phone.is_primary = 1
94 AND civicrm_contact.id = %1";
96 $params = array(1 => array($id, 'Integer'));
97 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
99 return array($dao->display_name
, $dao->phone
, $dao->do_not_sms
);
101 return array(NULL, NULL, NULL);
105 * Get the information to map a contact.
108 * The list of ids for which we want map info.
109 * $param int $locationTypeID
111 * @param int $locationTypeID
112 * @param bool $imageUrlOnly
114 * @return null|string
115 * display name of the contact if found
117 public static function &getMapInfo($ids, $locationTypeID = NULL, $imageUrlOnly = FALSE) {
118 $idString = ' ( ' . implode(',', $ids) . ' ) ';
120 SELECT civicrm_contact.id as contact_id,
121 civicrm_contact.contact_type as contact_type,
122 civicrm_contact.contact_sub_type as contact_sub_type,
123 civicrm_contact.display_name as display_name,
124 civicrm_address.street_address as street_address,
125 civicrm_address.supplemental_address_1 as supplemental_address_1,
126 civicrm_address.supplemental_address_2 as supplemental_address_2,
127 civicrm_address.supplemental_address_3 as supplemental_address_3,
128 civicrm_address.city as city,
129 civicrm_address.postal_code as postal_code,
130 civicrm_address.postal_code_suffix as postal_code_suffix,
131 civicrm_address.geo_code_1 as latitude,
132 civicrm_address.geo_code_2 as longitude,
133 civicrm_state_province.abbreviation as state,
134 civicrm_country.name as country,
135 civicrm_location_type.name as location_type
137 LEFT JOIN civicrm_address ON civicrm_address.contact_id = civicrm_contact.id
138 LEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id
139 LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
140 LEFT JOIN civicrm_location_type ON civicrm_location_type.id = civicrm_address.location_type_id
141 WHERE civicrm_address.geo_code_1 IS NOT NULL
142 AND civicrm_address.geo_code_2 IS NOT NULL
143 AND civicrm_contact.id IN $idString ";
146 if (!$locationTypeID) {
147 $sql .= " AND civicrm_address.is_primary = 1";
150 $sql .= " AND civicrm_address.location_type_id = %1";
151 $params[1] = array($locationTypeID, 'Integer');
154 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
156 $locations = array();
157 $config = CRM_Core_Config
::singleton();
159 while ($dao->fetch()) {
161 $location['contactID'] = $dao->contact_id
;
162 $location['displayName'] = addslashes($dao->display_name
);
163 $location['city'] = $dao->city
;
164 $location['state'] = $dao->state
;
165 $location['postal_code'] = $dao->postal_code
;
166 $location['lat'] = $dao->latitude
;
167 $location['lng'] = $dao->longitude
;
168 $location['marker_class'] = $dao->contact_type
;
171 CRM_Utils_String
::append($address, '<br />',
173 $dao->street_address
,
174 $dao->supplemental_address_1
,
175 $dao->supplemental_address_2
,
176 $dao->supplemental_address_3
,
180 CRM_Utils_String
::append($address, ', ',
181 array($dao->state
, $dao->postal_code
)
183 CRM_Utils_String
::append($address, '<br /> ',
186 $location['address'] = addslashes($address);
187 $location['displayAddress'] = str_replace('<br />', ', ', addslashes($address));
188 $location['url'] = CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $dao->contact_id
);
189 $location['location_type'] = $dao->location_type
;
190 $location['image'] = CRM_Contact_BAO_Contact_Utils
::getImage(isset($dao->contact_sub_type
) ?
$dao->contact_sub_type
: $dao->contact_type
, $imageUrlOnly, $dao->contact_id
192 $locations[] = $location;