3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class provides the functionality to map
38 * the address for group of
41 class CRM_Contact_Form_Task_Map
extends CRM_Contact_Form_Task
{
44 * Are we operating in "single mode", i.e. mapping address to one
49 protected $_single = FALSE;
52 * build all the data structures needed to build the form
57 function preProcess() {
58 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive',
61 $lid = CRM_Utils_Request
::retrieve('lid', 'Positive',
64 $eid = CRM_Utils_Request
::retrieve('eid', 'Positive',
67 $profileGID = CRM_Utils_Request
::retrieve('profileGID', 'Integer',
70 $this->assign('profileGID', $profileGID);
71 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
76 $this->_single
= TRUE;
78 // this does a check and ensures that the user has permission on this profile
80 $profileIDs = CRM_Profile_Page_Listings
::getProfileContact($profileGID);
81 if (!in_array($cid, $profileIDs)) {
82 CRM_Core_Error
::fatal();
86 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
87 $urlParams = 'force=1';
88 if (CRM_Utils_Rule
::qfKey($qfKey)) {
89 $urlParams .= "&qfKey=$qfKey";
91 $session = CRM_Core_Session
::singleton();
92 $urlString = "civicrm/contact/search/$context";
93 if ($context == 'search') {
94 $urlString = 'civicrm/contact/search';
96 $url = CRM_Utils_System
::url($urlString, $urlParams);
97 $session->replaceUserContext($url);
106 $ids = CRM_Profile_Page_Listings
::getProfileContact($profileGID);
109 parent
::preProcess();
110 $ids = $this->_contactIds
;
113 self
::createMapXML($ids, $lid, $this, TRUE, $type);
114 $this->assign('single', $this->_single
);
124 public function buildQuickForm() {
125 $this->addButtons(array(
128 'name' => ts('Done'),
136 * process the form after the input has been submitted and validated
142 public function postProcess() {}
146 * assign smarty variables to the template that will be used by google api to plot the contacts
148 * @param array $contactIds list of contact ids that we need to plot
149 * @param int $locationId location_id
151 * @return string the location of the file we have created
154 static function createMapXML($ids, $locationId, &$page, $addBreadCrumb, $type = 'Contact') {
155 $config = CRM_Core_Config
::singleton();
157 CRM_Utils_System
::setTitle(ts('Map Location(s)'));
158 $page->assign('query', 'CiviCRM Search Query');
159 $page->assign('mapProvider', $config->mapProvider
);
160 $page->assign('mapKey', urlencode($config->mapAPIKey
));
161 if ($type == 'Contact') {
162 $imageUrlOnly = FALSE;
164 // google needs image url, CRM-6564
165 if ($config->mapProvider
== 'Google' ||
$config->mapProvider
== 'OpenStreetMaps') {
166 $imageUrlOnly = TRUE;
168 $locations = CRM_Contact_BAO_Contact_Location
::getMapInfo($ids, $locationId, $imageUrlOnly);
171 $locations = CRM_Event_BAO_Event
::getMapInfo($ids);
174 if (empty($locations)) {
175 CRM_Core_Error
::statusBounce(ts('This address does not contain latitude/longitude information and cannot be mapped.'));
178 if ($addBreadCrumb) {
179 $session = CRM_Core_Session
::singleton();
180 $redirect = $session->readUserContext();
181 if ($type == 'Contact') {
182 $bcTitle = ts('Contact');
185 $bcTitle = ts('Event Info');
186 $action = CRM_Utils_Request
::retrieve('action', 'String',
190 $args = 'reset=1&action=preview&id=';
193 $args = 'reset=1&id=';
195 $session->pushUserContext(CRM_Utils_System
::url('civicrm/event/info', "{$args}{$ids}"));
197 CRM_Utils_System
::appendBreadCrumb($bcTitle, $redirect);
200 $page->assign_by_ref('locations', $locations);
202 // only issue a javascript warning if we know we will not
203 // mess the poor user with too many warnings
204 if (count($locations) <= 3) {
205 $page->assign('geoCodeWarn', TRUE);
208 $page->assign('geoCodeWarn', FALSE);
211 $sumLat = $sumLng = 0;
212 $maxLat = $maxLng = -400;
213 $minLat = $minLng = +
400;
214 foreach ($locations as $location) {
215 $sumLat +
= $location['lat'];
216 $sumLng +
= $location['lng'];
218 if ($location['lat'] > $maxLat) {
219 $maxLat = $location['lat'];
221 if ($location['lat'] < $minLat) {
222 $minLat = $location['lat'];
225 if ($location['lng'] > $maxLng) {
226 $maxLng = $location['lng'];
228 if ($location['lng'] < $minLng) {
229 $minLng = $location['lng'];
234 'lat' => (float ) $sumLat / count($locations),
235 'lng' => (float ) $sumLng / count($locations),
238 'lat' => (float )($maxLat - $minLat),
239 'lng' => (float )($maxLng - $minLng),
241 $page->assign_by_ref('center', $center);
242 $page->assign_by_ref('span', $span);