/**
  * Checks the TCA for address mapping rules and returns the address value.
  * If a mapping rule is defined, this tells us what field contains address
  * related information.  If no rules are defined, we pick default fields
  * to use.
  *
  * @param	string	The portion of the address we're trying to map.
  * @param	array	Array of field related data.
  * @return	string	The specified portion of the address.
  * @todo			Refactor this to use getFieldNameForTable().
  */
 static function getFieldValue($key, $PA)
 {
     global $TCA;
     $table = $PA['table'];
     $row = $PA['row'];
     /* If the address mapping array has a mapping for this address, use it */
     $addressFields = $PA['fieldConf']['config']['params']['addressFields'];
     if (isset($addressFields[$key])) {
         $fieldName = $addressFields[$key];
     } else {
         /* If the address mapping array has a mapping for this lat/long, use it */
         $latlongFields = $PA['fieldConf']['config']['params']['latlongFields'];
         if (isset($latlongFields[$key])) {
             $fieldName = $latlongFields[$key];
         } else {
             /* If the ctrl section of the TCA has a name, use it */
             if (isset($ctrlAddressFields[$key])) {
                 $fieldName = tx_wecmap_shared::getAddressField($table, $key);
             } else {
                 /* Otherwise, use the default name */
                 $fieldName = $key;
             }
         }
     }
     /* If the source data has a value for the address field, grab it */
     if (isset($row[$fieldName])) {
         $value = $row[$fieldName];
     } else {
         /* Otherwise, use an empty string */
         $value = '';
     }
     return $value;
 }
Пример #2
0
 /**
  * Adds a marker by getting the address info from the TCA
  *
  * @param	string		The db table that contains the mappable records
  * @param	integer		The uid of the record to be mapped
  * @param	string		The title for the marker popup.
  * @param	string		The description to be displayed in the marker popup.
  * @param	integer		Minimum zoom level for marker to appear.
  * @param	integer		Maximum zoom level for marker to appear.
  * @return	marker object
  **/
 function addMarkerByTCA($table, $uid, $title = '', $description = '', $minzoom = 0, $maxzoom = 18, $iconID = '')
 {
     $uid = intval($uid);
     // first get the mappable info from the TCA
     $tca = $GLOBALS['TCA'][$table]['ctrl']['EXT']['wec_map'];
     if (!$tca) {
         return false;
     }
     if (!$tca['isMappable']) {
         return false;
     }
     // get address from db for this record
     $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $table, 'uid=' . intval($uid));
     $record = $record[0];
     if ($tca['addressFields']) {
         $streetfield = tx_wecmap_shared::getAddressField($table, 'street');
         $cityfield = tx_wecmap_shared::getAddressField($table, 'city');
         $statefield = tx_wecmap_shared::getAddressField($table, 'state');
         $zipfield = tx_wecmap_shared::getAddressField($table, 'zip');
         $countryfield = tx_wecmap_shared::getAddressField($table, 'country');
         $street = $record[$streetfield];
         $city = $record[$cityfield];
         $state = $record[$statefield];
         $zip = $record[$zipfield];
         $country = $record[$countryfield];
         if (empty($country) && $countryfield == 'static_info_country') {
             $country = $record['country'];
         } else {
             if (empty($country) && $countryfield == 'country') {
                 $country = $record['static_info_country'];
             }
         }
         /* Geocode the address */
         $latlong = tx_wecmap_cache::lookup($street, $city, $state, $zip, $country, $this->key);
         /* Create a marker at the specified latitude and longitude */
         return $this->addMarkerByLatLong($latlong['lat'], $latlong['long'], $title, $description, $minzoom, $maxzoom, $iconID);
     } else {
         if ($tca['latlongFields']) {
             $latfield = tx_wecmap_shared::getLatLongField($table, 'lat');
             $longfield = tx_wecmap_shared::getLatLongField($table, 'long');
             $lat = $record[$latfield];
             $long = $record[$longfield];
             /* Create a marker at the specified latitude and longitude */
             return $this->addMarkerByLatLong($lat, $long, $title, $description, $minzoom, $maxzoom, $iconID);
         } else {
             return false;
         }
     }
 }
Пример #3
0
 /**
  * Shows map
  *
  * @return String
  **/
 function showMap()
 {
     global $LANG;
     /* Create the Map object */
     $width = 500;
     $height = 500;
     $conf = $GLOBALS['BE_USER']->getModuleData('tools_txwecmapM2');
     // get options
     $scale = $conf['scale'];
     $minimap = $conf['minimap'];
     $maptype = $conf['maptype'];
     $mapcontrolsize = $conf['mapcontrolsize'];
     $streetField = tx_wecmap_shared::getAddressField('fe_users', 'street');
     $cityField = tx_wecmap_shared::getAddressField('fe_users', 'city');
     $stateField = tx_wecmap_shared::getAddressField('fe_users', 'state');
     $zipField = tx_wecmap_shared::getAddressField('fe_users', 'zip');
     $countryField = tx_wecmap_shared::getAddressField('fe_users', 'country');
     $map = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\tx_wecmap_map_google::class, $apiKey, $width, $height);
     // evaluate map controls based on configuration
     switch ($mapcontrolsize) {
         case 'large':
             $map->addControl('largeMap');
             break;
         case 'small':
             $map->addControl('smallMap');
             break;
         case 'zoomonly':
             $map->addControl('smallZoom');
             break;
         default:
             // do nothing
             break;
     }
     if ($scale) {
         $map->addControl('scale');
     }
     if ($minimap) {
         $map->addControl('overviewMap');
     }
     if ($maptype) {
         $map->addControl('mapType');
     }
     $map->enableDirections(false, 'directions');
     /* Select all frontend users */
     $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'fe_users', '');
     // create country and zip code array to keep track of which country and state we already added to the map.
     // the point is to create only one marker per country on a higher zoom level to not
     // overload the map with all the markers and do the same with zip codes.
     $countries = array();
     $cities = array();
     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
         // add check for country and use different field if empty
         // @TODO: make this smarter with TCA or something
         if (empty($row[$countryField]) && $countryField == 'static_info_country') {
             $countryField = 'country';
         } else {
             if (empty($row[$countryField]) && $countryField == 'country') {
                 $countryField = 'static_info_country';
             }
         }
         /* Only try to add marker if there's a city */
         if ($row[$cityField] != '') {
             // if we haven't added a marker for this country yet, do so.
             if (!in_array($row[$countryField], $countries) && !empty($row[$countryField])) {
                 // add this country to the array
                 $countries[] = $row[$countryField];
                 // add a little info so users know what to do
                 $title = '';
                 $description = '<div class="description">' . sprintf($LANG->getLL('country_zoominfo_desc'), $row[$countryField]) . '</div>';
                 // add a marker for this country and only show it between zoom levels 0 and 2.
                 $map->addMarkerByAddress(null, $row[$cityField], $row[$stateField], $row[$zipField], $row[$countryField], $title, $description, 0, 2);
             }
             // if we haven't added a marker for this zip code yet, do so.
             if (!in_array($row[$cityField], $cities) && !empty($cityField)) {
                 // add this country to the array
                 $cities[] = $row[$cityField];
                 // add a little info so users know what to do
                 $title = '';
                 $description = '<div class="description">' . $LANG->getLL('area_zoominfo_desc') . '</div>';
                 // add a marker for this country and only show it between zoom levels 0 and 2.
                 $map->addMarkerByAddress(null, $row[$cityField], $row[$stateField], $row[$zipField], $row[$countryField], $title, $description, 3, 7);
             }
             // make title and description
             $title = '<div style="font-size: 110%; font-weight: bold;">' . $row['name'] . '</div>';
             $content = '<div>' . $row[$streetField] . '<br />' . $row[$cityField] . ', ' . $row[$stateField] . ' ' . $row[$zipField] . '<br />' . $row[$countryField] . '</div>';
             // add all the markers starting at zoom level 3 so we don't crowd the map right away.
             // if private was checked, don't use address to geocode
             if ($private) {
                 $map->addMarkerByAddress(null, $row[$cityField], $row[$stateField], $row[$zipField], $row[$countryField], $title, $content, 8);
             } else {
                 $map->addMarkerByAddress($row[$streetField], $row[$cityField], $row[$stateField], $row[$zipField], $row[$countryField], $title, $content, 8);
             }
         }
     }
     $content = $map->drawMap();
     $content .= '<div id="directions"></div>';
     return $content;
 }
Пример #4
0
 function getSidebar()
 {
     if (empty($this->sidebarLinks)) {
         return null;
     }
     $c = '';
     foreach ($this->sidebarLinks as $link) {
         $c .= $link;
     }
     $out = tx_wecmap_shared::render(array('map_height' => $this->height, 'map_id' => $this->mapName, 'content' => $c), $this->conf['sidebar.']);
     return $out;
 }
 /**
  * Gets the address of the user who is currently logged in
  *
  * @return string
  **/
 function getUserAddress()
 {
     if ($this->prefillAddress) {
         if (TYPO3_MODE == 'FE') {
             $feuser_id = $GLOBALS['TSFE']->fe_user->user['uid'];
             if (!empty($feuser_id)) {
                 $table = 'fe_users';
                 $streetField = \tx_wecmap_shared::getAddressField($table, 'street');
                 $cityField = \tx_wecmap_shared::getAddressField($table, 'city');
                 $stateField = \tx_wecmap_shared::getAddressField($table, 'state');
                 $zipField = \tx_wecmap_shared::getAddressField($table, 'zip');
                 $countryField = \tx_wecmap_shared::getAddressField($table, 'country');
                 $select = $streetField . ', ' . $cityField . ', ' . $stateField . ', ' . $zipField . ', ' . $countryField;
                 $selectArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $select, true);
                 $select = implode(',', $selectArray);
                 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($select, 'fe_users', '`uid`=' . intval($feuser_id));
                 return $rows[0][$streetField] . ', ' . $rows[0][$cityField] . ', ' . $rows[0][$stateField] . ' ' . $rows[0][$zipField] . ', ' . $rows[0][$countryField];
             }
         } else {
         }
     }
     return '';
 }
 /**
  * Performs geocoding on an individual table.
  *
  * @param		string		Name of the table.
  * @return		none
  */
 function geocodeTable($table)
 {
     global $TYPO3_DB;
     $addressFields = array('street' => tx_wecmap_shared::getAddressField($table, 'street'), 'city' => tx_wecmap_shared::getAddressField($table, 'city'), 'state' => tx_wecmap_shared::getAddressField($table, 'state'), 'zip' => tx_wecmap_shared::getAddressField($table, 'zip'), 'country' => tx_wecmap_shared::getAddressField($table, 'country'));
     $where = "1=1" . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table);
     $result = $TYPO3_DB->exec_SELECTquery('*', $table, $where);
     while ($row = $TYPO3_DB->sql_fetch_assoc($result)) {
         if ($this->stopGeocoding()) {
             return;
         } else {
             $this->geocodeRecord($row, $addressFields);
         }
     }
 }
 public function test_get_city_field_for_fe_users()
 {
     $city = tx_wecmap_shared::getAddressField('fe_users', 'city');
     $this->assertEquals('city', $city);
 }