コード例 #1
0
 /**
  * This function is called when action is browse
  *
  * return null
  * @access public
  */
 function browse()
 {
     // get the primary city, state and zip for the contact
     $ids = array($this->_contactId);
     $locations = CRM_Contact_BAO_Contact_Location::getMapInfo($ids);
     $rows =& CRM_Utils_Sunlight::getInfo($locations[0]['city'], $locations[0]['state'], $locations[0]['postal_code']);
     $this->assign('rowCount', count($rows));
     $this->assign_by_ref('rows', $rows);
 }
コード例 #2
0
ファイル: Map.php プロジェクト: nielosz/civicrm-core
 /**
  * Assign smarty variables to the template that will be used by google api to plot the contacts.
  *
  * @param array $ids
  * @param int $locationId
  *   Location_id.
  * @param CRM_Core_Page $page
  * @param bool $addBreadCrumb
  * @param string $type
  */
 public static function createMapXML($ids, $locationId, &$page, $addBreadCrumb, $type = 'Contact')
 {
     $config = CRM_Core_Config::singleton();
     CRM_Utils_System::setTitle(ts('Map Location(s)'));
     $page->assign('query', 'CiviCRM Search Query');
     $page->assign('mapProvider', $config->mapProvider);
     $page->assign('mapKey', urlencode($config->mapAPIKey));
     if ($type == 'Contact') {
         $imageUrlOnly = FALSE;
         // google needs image url, CRM-6564
         if ($config->mapProvider == 'Google' || $config->mapProvider == 'OpenStreetMaps') {
             $imageUrlOnly = TRUE;
         }
         $locations = CRM_Contact_BAO_Contact_Location::getMapInfo($ids, $locationId, $imageUrlOnly);
     } else {
         $locations = CRM_Event_BAO_Event::getMapInfo($ids);
     }
     if (empty($locations)) {
         CRM_Core_Error::statusBounce(ts('This address does not contain latitude/longitude information and cannot be mapped.'));
     }
     if (empty($config->mapProvider)) {
         CRM_Core_Error::statusBounce(ts('You need to configure a Mapping Provider before using this feature (Administer > System Settings > Mapping and Geocoding).'));
     }
     if ($addBreadCrumb) {
         $session = CRM_Core_Session::singleton();
         $redirect = $session->readUserContext();
         if ($type == 'Contact') {
             $bcTitle = ts('Contact');
         } else {
             $bcTitle = ts('Event Info');
             $action = CRM_Utils_Request::retrieve('action', 'String', $page, FALSE);
             if ($action) {
                 $args = 'reset=1&action=preview&id=';
             } else {
                 $args = 'reset=1&id=';
             }
             $session->pushUserContext(CRM_Utils_System::url('civicrm/event/info', "{$args}{$ids}"));
         }
         CRM_Utils_System::appendBreadCrumb($bcTitle, $redirect);
     }
     $page->assign_by_ref('locations', $locations);
     // only issue a javascript warning if we know we will not
     // mess the poor user with too many warnings
     if (count($locations) <= 3) {
         $page->assign('geoCodeWarn', TRUE);
     } else {
         $page->assign('geoCodeWarn', FALSE);
     }
     $sumLat = $sumLng = 0;
     $maxLat = $maxLng = -400;
     $minLat = $minLng = 400;
     foreach ($locations as $location) {
         $sumLat += $location['lat'];
         $sumLng += $location['lng'];
         if ($location['lat'] > $maxLat) {
             $maxLat = $location['lat'];
         }
         if ($location['lat'] < $minLat) {
             $minLat = $location['lat'];
         }
         if ($location['lng'] > $maxLng) {
             $maxLng = $location['lng'];
         }
         if ($location['lng'] < $minLng) {
             $minLng = $location['lng'];
         }
     }
     $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations));
     $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng));
     $page->assign_by_ref('center', $center);
     $page->assign_by_ref('span', $span);
 }
コード例 #3
0
ファイル: Map.php プロジェクト: ksecor/civicrm
 /**
  * assign smarty variables to the template that will be used by google api to plot the contacts
  *
  * @param array $contactIds list of contact ids that we need to plot
  * @param int   $locationId location_id
  *
  * @return string           the location of the file we have created
  * @access protected
  */
 static function createMapXML($ids, $locationId, &$page, $addBreadCrumb, $type = 'Contact')
 {
     $config =& CRM_Core_Config::singleton();
     CRM_Utils_System::setTitle(ts('Map Location(s)'));
     $page->assign('query', 'CiviCRM Search Query');
     $page->assign('mapProvider', $config->mapProvider);
     $page->assign('mapKey', $config->mapAPIKey);
     if ($type == 'Contact') {
         require_once 'CRM/Contact/BAO/Contact/Location.php';
         $locations =& CRM_Contact_BAO_Contact_Location::getMapInfo($ids, $locationId);
     } else {
         require_once 'CRM/Event/BAO/Event.php';
         $locations =& CRM_Event_BAO_Event::getMapInfo($ids);
     }
     if (empty($locations)) {
         CRM_Core_Error::statusBounce(ts('This address does not contain latitude/longitude information and cannot be mapped.'));
     }
     if ($addBreadCrumb) {
         $session =& CRM_Core_Session::singleton();
         $redirect = $session->readUserContext();
         if ($type == 'Contact') {
             $bcTitle = ts('Contact');
         } else {
             $bcTitle = ts('Event Info');
             $action = CRM_Utils_Request::retrieve('action', 'String', $page, false);
             if ($action) {
                 $args = 'reset=1&action=preview&id=';
             } else {
                 $args = 'reset=1&id=';
             }
             $session->pushUserContext(CRM_Utils_System::url('civicrm/event/info', "{$args}{$ids}"));
         }
         CRM_Utils_System::appendBreadCrumb($bcTitle, $redirect);
     }
     $page->assign_by_ref('locations', $locations);
     // only issue a javascript warning if we know we will not
     // mess the poor user with too many warnings
     if (count($locations) <= 3) {
         $page->assign('geoCodeWarn', true);
     } else {
         $page->assign('geoCodeWarn', false);
     }
     $sumLat = $sumLng = 0;
     $maxLat = $maxLng = -400;
     $minLat = $minLng = +400;
     foreach ($locations as $location) {
         $sumLat += $location['lat'];
         $sumLng += $location['lng'];
         if ($location['lat'] > $maxLat) {
             $maxLat = $location['lat'];
         }
         if ($location['lat'] < $minLat) {
             $minLat = $location['lat'];
         }
         if ($location['lng'] > $maxLng) {
             $maxLng = $location['lng'];
         }
         if ($location['lng'] < $minLng) {
             $minLng = $location['lng'];
         }
     }
     $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations));
     $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng));
     $page->assign_by_ref('center', $center);
     $page->assign_by_ref('span', $span);
 }