3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
56 public function preProcess() {
57 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive',
60 $lid = CRM_Utils_Request
::retrieve('lid', 'Positive',
63 $eid = CRM_Utils_Request
::retrieve('eid', 'Positive',
66 $profileGID = CRM_Utils_Request
::retrieve('profileGID', 'Integer',
69 $this->assign('profileGID', $profileGID);
70 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
75 $this->_single
= TRUE;
77 // this does a check and ensures that the user has permission on this profile
79 $profileIDs = CRM_Profile_Page_Listings
::getProfileContact($profileGID);
80 if (!in_array($cid, $profileIDs)) {
81 CRM_Core_Error
::fatal();
85 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
86 $urlParams = 'force=1';
87 if (CRM_Utils_Rule
::qfKey($qfKey)) {
88 $urlParams .= "&qfKey=$qfKey";
90 $session = CRM_Core_Session
::singleton();
91 $urlString = "civicrm/contact/search/$context";
92 if ($context == 'search') {
93 $urlString = 'civicrm/contact/search';
95 $url = CRM_Utils_System
::url($urlString, $urlParams);
96 $session->replaceUserContext($url);
105 $ids = CRM_Profile_Page_Listings
::getProfileContact($profileGID);
108 parent
::preProcess();
109 $ids = $this->_contactIds
;
112 self
::createMapXML($ids, $lid, $this, TRUE, $type);
113 $this->assign('single', $this->_single
);
117 * Build the form object
122 public function buildQuickForm() {
123 $this->addButtons(array(
126 'name' => ts('Done'),
134 * Process the form after the input has been submitted and validated
139 public function postProcess() {}
142 * Assign smarty variables to the template that will be used by google api to plot the contacts
145 * @param int $locationId location_id
147 * @param $addBreadCrumb
148 * @param string $type
150 * @return string the location of the file we have created
152 public static function createMapXML($ids, $locationId, &$page, $addBreadCrumb, $type = 'Contact') {
153 $config = CRM_Core_Config
::singleton();
155 CRM_Utils_System
::setTitle(ts('Map Location(s)'));
156 $page->assign('query', 'CiviCRM Search Query');
157 $page->assign('mapProvider', $config->mapProvider
);
158 $page->assign('mapKey', urlencode($config->mapAPIKey
));
159 if ($type == 'Contact') {
160 $imageUrlOnly = FALSE;
162 // google needs image url, CRM-6564
163 if ($config->mapProvider
== 'Google' ||
$config->mapProvider
== 'OpenStreetMaps') {
164 $imageUrlOnly = TRUE;
166 $locations = CRM_Contact_BAO_Contact_Location
::getMapInfo($ids, $locationId, $imageUrlOnly);
169 $locations = CRM_Event_BAO_Event
::getMapInfo($ids);
172 if (empty($locations)) {
173 CRM_Core_Error
::statusBounce(ts('This address does not contain latitude/longitude information and cannot be mapped.'));
176 if ($addBreadCrumb) {
177 $session = CRM_Core_Session
::singleton();
178 $redirect = $session->readUserContext();
179 if ($type == 'Contact') {
180 $bcTitle = ts('Contact');
183 $bcTitle = ts('Event Info');
184 $action = CRM_Utils_Request
::retrieve('action', 'String',
188 $args = 'reset=1&action=preview&id=';
191 $args = 'reset=1&id=';
193 $session->pushUserContext(CRM_Utils_System
::url('civicrm/event/info', "{$args}{$ids}"));
195 CRM_Utils_System
::appendBreadCrumb($bcTitle, $redirect);
198 $page->assign_by_ref('locations', $locations);
200 // only issue a javascript warning if we know we will not
201 // mess the poor user with too many warnings
202 if (count($locations) <= 3) {
203 $page->assign('geoCodeWarn', TRUE);
206 $page->assign('geoCodeWarn', FALSE);
209 $sumLat = $sumLng = 0;
210 $maxLat = $maxLng = -400;
211 $minLat = $minLng = +
400;
212 foreach ($locations as $location) {
213 $sumLat +
= $location['lat'];
214 $sumLng +
= $location['lng'];
216 if ($location['lat'] > $maxLat) {
217 $maxLat = $location['lat'];
219 if ($location['lat'] < $minLat) {
220 $minLat = $location['lat'];
223 if ($location['lng'] > $maxLng) {
224 $maxLng = $location['lng'];
226 if ($location['lng'] < $minLng) {
227 $minLng = $location['lng'];
232 'lat' => (float ) $sumLat / count($locations),
233 'lng' => (float ) $sumLng / count($locations),
236 'lat' => (float )($maxLat - $minLat),
237 'lng' => (float )($maxLng - $minLng),
239 $page->assign_by_ref('center', $center);
240 $page->assign_by_ref('span', $span);