Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | class CRM_Contact_BAO_Contact_Location { | |
34 | ||
35 | /** | |
67d19299 | 36 | * Get the display name, primary email, location type and location id of a contact. |
6a488035 | 37 | * |
77c5b619 TO |
38 | * @param int $id |
39 | * Id of the contact. | |
77b97be7 EM |
40 | * |
41 | * @param bool $isPrimary | |
100fef9d | 42 | * @param int $locationTypeID |
6a488035 | 43 | * |
a6c01b45 | 44 | * @return array |
16b10e64 | 45 | * Array of display_name, email, location type and location id if found, or (null,null,null, null) |
6a488035 | 46 | */ |
00be9182 | 47 | public static function getEmailDetails($id, $isPrimary = TRUE, $locationTypeID = NULL) { |
beac1417 MW |
48 | $params = array( |
49 | 'location_type_id' => $locationTypeID, | |
50 | 'contact_id' => $id, | |
51 | 'return' => array('contact_id.display_name', 'email', 'location_type_id', 'id'), | |
52 | ); | |
6a488035 | 53 | if ($isPrimary) { |
beac1417 | 54 | $params['is_primary'] = 1; |
6a488035 | 55 | } |
beac1417 | 56 | $emails = civicrm_api3('Email', 'get', $params); |
6a488035 | 57 | |
beac1417 MW |
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']); | |
6a488035 TO |
61 | } |
62 | return array(NULL, NULL, NULL, NULL); | |
63 | } | |
64 | ||
65 | /** | |
c9184ed3 | 66 | * @deprecated Not used anywhere, use the Phone API instead |
fe482240 | 67 | * Get the sms number and display name of a contact. |
6a488035 | 68 | * |
77c5b619 TO |
69 | * @param int $id |
70 | * Id of the contact. | |
6c8f6e67 EM |
71 | * |
72 | * @param null $type | |
6a488035 | 73 | * |
a6c01b45 CW |
74 | * @return array |
75 | * tuple of display_name and sms if found, or (null,null) | |
6a488035 | 76 | */ |
00be9182 | 77 | public static function getPhoneDetails($id, $type = NULL) { |
496320c3 | 78 | CRM_Core_Error::deprecatedFunctionWarning('Phone.get API instead'); |
6a488035 TO |
79 | if (!$id) { |
80 | return array(NULL, NULL); | |
81 | } | |
82 | ||
83 | $cond = NULL; | |
84 | if ($type) { | |
85 | $cond = " AND civicrm_phone.phone_type_id = '$type'"; | |
86 | } | |
87 | ||
6a488035 TO |
88 | $sql = " |
89 | SELECT civicrm_contact.display_name, civicrm_phone.phone, civicrm_contact.do_not_sms | |
90 | FROM civicrm_contact | |
91 | LEFT JOIN civicrm_phone ON ( civicrm_phone.contact_id = civicrm_contact.id ) | |
92 | WHERE civicrm_phone.is_primary = 1 | |
93 | $cond | |
94 | AND civicrm_contact.id = %1"; | |
95 | ||
96 | $params = array(1 => array($id, 'Integer')); | |
97 | $dao = CRM_Core_DAO::executeQuery($sql, $params); | |
98 | if ($dao->fetch()) { | |
99 | return array($dao->display_name, $dao->phone, $dao->do_not_sms); | |
100 | } | |
101 | return array(NULL, NULL, NULL); | |
102 | } | |
103 | ||
104 | /** | |
fe482240 | 105 | * Get the information to map a contact. |
6a488035 | 106 | * |
77c5b619 TO |
107 | * @param array $ids |
108 | * The list of ids for which we want map info. | |
6a488035 TO |
109 | * $param int $locationTypeID |
110 | * | |
100fef9d | 111 | * @param int $locationTypeID |
da6b46f4 EM |
112 | * @param bool $imageUrlOnly |
113 | * | |
72b3a70c CW |
114 | * @return null|string |
115 | * display name of the contact if found | |
6a488035 | 116 | */ |
00be9182 | 117 | public static function &getMapInfo($ids, $locationTypeID = NULL, $imageUrlOnly = FALSE) { |
6a488035 TO |
118 | $idString = ' ( ' . implode(',', $ids) . ' ) '; |
119 | $sql = " | |
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, | |
207f62c6 | 127 | civicrm_address.supplemental_address_3 as supplemental_address_3, |
6a488035 TO |
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 | |
136 | FROM civicrm_contact | |
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 | |
8ef12e64 | 141 | WHERE civicrm_address.geo_code_1 IS NOT NULL |
142 | AND civicrm_address.geo_code_2 IS NOT NULL | |
6a488035 TO |
143 | AND civicrm_contact.id IN $idString "; |
144 | ||
145 | $params = array(); | |
146 | if (!$locationTypeID) { | |
147 | $sql .= " AND civicrm_address.is_primary = 1"; | |
148 | } | |
149 | else { | |
150 | $sql .= " AND civicrm_address.location_type_id = %1"; | |
151 | $params[1] = array($locationTypeID, 'Integer'); | |
152 | } | |
153 | ||
154 | $dao = CRM_Core_DAO::executeQuery($sql, $params); | |
155 | ||
156 | $locations = array(); | |
157 | $config = CRM_Core_Config::singleton(); | |
158 | ||
159 | while ($dao->fetch()) { | |
160 | $location = array(); | |
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; | |
169 | $address = ''; | |
170 | ||
171 | CRM_Utils_String::append($address, '<br />', | |
172 | array( | |
173 | $dao->street_address, | |
174 | $dao->supplemental_address_1, | |
175 | $dao->supplemental_address_2, | |
207f62c6 | 176 | $dao->supplemental_address_3, |
6a488035 TO |
177 | $dao->city, |
178 | ) | |
179 | ); | |
180 | CRM_Utils_String::append($address, ', ', | |
181 | array($dao->state, $dao->postal_code) | |
182 | ); | |
183 | CRM_Utils_String::append($address, '<br /> ', | |
184 | array($dao->country) | |
185 | ); | |
186 | $location['address'] = addslashes($address); | |
d40be285 | 187 | $location['displayAddress'] = str_replace('<br />', ', ', addslashes($address)); |
6a488035 TO |
188 | $location['url'] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $dao->contact_id); |
189 | $location['location_type'] = $dao->location_type; | |
28a04ea9 | 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 |
6a488035 TO |
191 | ); |
192 | $locations[] = $location; | |
193 | } | |
194 | return $locations; | |
195 | } | |
96025800 | 196 | |
6a488035 | 197 | } |