3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
35 class CRM_Contact_BAO_Contact_Location
{
38 * function to get the display name, primary email, location type and location id of a contact
40 * @param int $id id of the contact
42 * @return array of display_name, email, location type and location id if found, or (null,null,null, null)
46 static function getEmailDetails($id, $isPrimary = TRUE, $locationTypeID = NULL) {
47 $primaryClause = NULL;
49 $primaryClause = " AND civicrm_email.is_primary = 1";
53 $locationClause = NULL;
54 if ($locationTypeID) {
55 $locationClause = " AND civicrm_email.location_type_id = $locationTypeID";
59 SELECT civicrm_contact.display_name,
61 civicrm_email.location_type_id,
64 LEFT JOIN civicrm_email ON ( civicrm_contact.id = civicrm_email.contact_id {$primaryClause} {$locationClause} )
65 WHERE civicrm_contact.id = %1";
67 $params = array(1 => array($id, 'Integer'));
68 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
70 return array($dao->display_name
, $dao->email
, $dao->location_type_id
, $dao->id
);
72 return array(NULL, NULL, NULL, NULL);
76 * function to get the sms number and display name of a contact
78 * @param int $id id of the contact
80 * @return array tuple of display_name and sms if found, or (null,null)
84 static function getPhoneDetails($id, $type = NULL) {
86 return array(NULL, NULL);
91 $cond = " AND civicrm_phone.phone_type_id = '$type'";
96 SELECT civicrm_contact.display_name, civicrm_phone.phone, civicrm_contact.do_not_sms
98 LEFT JOIN civicrm_phone ON ( civicrm_phone.contact_id = civicrm_contact.id )
99 WHERE civicrm_phone.is_primary = 1
101 AND civicrm_contact.id = %1";
103 $params = array(1 => array($id, 'Integer'));
104 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
106 return array($dao->display_name
, $dao->phone
, $dao->do_not_sms
);
108 return array(NULL, NULL, NULL);
112 * function to get the information to map a contact
114 * @param array $ids the list of ids for which we want map info
115 * $param int $locationTypeID
117 * @return null|string display name of the contact if found
121 static function &getMapInfo($ids, $locationTypeID = NULL, $imageUrlOnly = FALSE) {
122 $idString = ' ( ' . implode(',', $ids) . ' ) ';
124 SELECT civicrm_contact.id as contact_id,
125 civicrm_contact.contact_type as contact_type,
126 civicrm_contact.contact_sub_type as contact_sub_type,
127 civicrm_contact.display_name as display_name,
128 civicrm_address.street_address as street_address,
129 civicrm_address.supplemental_address_1 as supplemental_address_1,
130 civicrm_address.supplemental_address_2 as supplemental_address_2,
131 civicrm_address.city as city,
132 civicrm_address.postal_code as postal_code,
133 civicrm_address.postal_code_suffix as postal_code_suffix,
134 civicrm_address.geo_code_1 as latitude,
135 civicrm_address.geo_code_2 as longitude,
136 civicrm_state_province.abbreviation as state,
137 civicrm_country.name as country,
138 civicrm_location_type.name as location_type
140 LEFT JOIN civicrm_address ON civicrm_address.contact_id = civicrm_contact.id
141 LEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id
142 LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
143 LEFT JOIN civicrm_location_type ON civicrm_location_type.id = civicrm_address.location_type_id
144 WHERE civicrm_address.geo_code_1 IS NOT NULL
145 AND civicrm_address.geo_code_2 IS NOT NULL
146 AND civicrm_contact.id IN $idString ";
149 if (!$locationTypeID) {
150 $sql .= " AND civicrm_address.is_primary = 1";
153 $sql .= " AND civicrm_address.location_type_id = %1";
154 $params[1] = array($locationTypeID, 'Integer');
157 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
159 $locations = array();
160 $config = CRM_Core_Config
::singleton();
162 while ($dao->fetch()) {
164 $location['contactID'] = $dao->contact_id
;
165 $location['displayName'] = addslashes($dao->display_name
);
166 $location['city'] = $dao->city
;
167 $location['state'] = $dao->state
;
168 $location['postal_code'] = $dao->postal_code
;
169 $location['lat'] = $dao->latitude
;
170 $location['lng'] = $dao->longitude
;
171 $location['marker_class'] = $dao->contact_type
;
174 CRM_Utils_String
::append($address, '<br />',
176 $dao->street_address
,
177 $dao->supplemental_address_1
,
178 $dao->supplemental_address_2
,
182 CRM_Utils_String
::append($address, ', ',
183 array($dao->state
, $dao->postal_code
)
185 CRM_Utils_String
::append($address, '<br /> ',
188 $location['address'] = addslashes($address);
189 $location['displayAddress'] = str_replace('<br />', ', ', addslashes($address));
190 $location['url'] = CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $dao->contact_id
);
191 $location['location_type'] = $dao->location_type
;
192 $location['image'] = CRM_Contact_BAO_Contact_Utils
::getImage(isset($dao->contact_sub_type
) ?
193 $dao->contact_sub_type
: $dao->contact_type
, $imageUrlOnly, $dao->contact_id
195 $locations[] = $location;