new methods instead.
)
);
- $fnName = isset($config->geocodeMethod) ? $config->geocodeMethod : NULL;
- if (empty($fnName)) {
- CRM_Core_Error::fatal(ts('Proximity searching requires you to set a valid geocoding provider'));
- }
-
$query->_tables['civicrm_address'] = $query->_whereTables['civicrm_address'] = 1;
- require_once str_replace('_', DIRECTORY_SEPARATOR, $fnName) . '.php';
- $fnName::format($proximityAddress);
+ if (!CRM_Core_BAO_Address::addGeocoderData($proximityAddress)) {
+ throw new CRM_Core_Exception(ts('Proximity searching requires you to set a valid geocoding provider'));
+ }
+
if (
!is_numeric(CRM_Utils_Array::value('geo_code_1', $proximityAddress)) ||
!is_numeric(CRM_Utils_Array::value('geo_code_2', $proximityAddress))
// CRM-11665 geocode override option
$geoCode = FALSE;
- if (!empty($config->geocodeMethod)) {
+ if (CRM_Utils_GeocodeProvider::getUsableClassName()) {
$geoCode = TRUE;
$form->addElement('checkbox',
"address[$blockId][manual_geo_code]",
}
// extend addresses with proximity search
- if (!empty($config->geocodeMethod)) {
+ if (CRM_Utils_GeocodeProvider::getUsableClassName()) {
$form->addElement('text', 'prox_distance', ts('Find contacts within'), array('class' => 'six'));
$form->addElement('select', 'prox_distance_unit', NULL, array(
'miles' => ts('Miles'),
}
// use the address to get the latitude and longitude
- CRM_Utils_Geocode_Google::format($this->_formValues);
+ CRM_Core_BAO_Address::addGeocoderData($this->_formValues);
if (!is_numeric(CRM_Utils_Array::value('geo_code_1', $this->_formValues)) ||
!is_numeric(CRM_Utils_Array::value('geo_code_2', $this->_formValues)) ||
!isset($this->_formValues['distance'])
) {
- CRM_Core_Error::fatal(ts('Could not geocode input'));
+ throw new CRM_Core_Exception(ts('Could not geocode input'));
}
$this->_latitude = $this->_formValues['geo_code_1'];
$config = CRM_Core_Config::singleton();
$geoCode = FALSE;
- if (!empty($config->geocodeMethod)) {
+ if (CRM_Utils_GeocodeProvider::getUsableClassName()) {
$geoCode = TRUE;
$this->addElement('checkbox', 'doGeocodeAddress', ts('Geocode addresses during import?'));
}
$params['country'] = CRM_Core_PseudoConstant::country($params['country_id']);
}
- $config = CRM_Core_Config::singleton();
-
$asp = Civi::settings()->get('address_standardization_provider');
// clean up the address via USPS web services if enabled
if ($asp === 'USPS' &&
$params = array_merge($params, $parsedFields);
}
- // check if geocode should be skipped (can be forced with an optional parameter through the api)
- $skip_geocode = (isset($params['skip_geocode']) && $params['skip_geocode']) ? TRUE : FALSE;
-
- // add latitude and longitude and format address if needed
- if (!$skip_geocode && !empty($config->geocodeMethod) && ($config->geocodeMethod != 'CRM_Utils_Geocode_OpenStreetMaps') && empty($params['manual_geo_code'])) {
- $class = $config->geocodeMethod;
- $class::format($params);
+ // skip_geocode is an optional parameter through the api.
+ // manual_geo_code is on the contact edit form. They do the same thing....
+ if (empty($params['skip_geocode']) && empty($params['manual_geo_code'])) {
+ self::addGeocoderData($params);
}
+
}
/**
*/
public function run() {
- $config = &CRM_Core_Config::singleton();
-
// do check for geocoding.
$processGeocode = FALSE;
- if (empty($config->geocodeMethod)) {
+ if (!CRM_Utils_GeocodeProvider::getUsableClassName()) {
if (CRM_Utils_String::strtobool($this->geocoding) === TRUE) {
$this->returnMessages[] = ts('Error: You need to set a mapping provider under Administer > System Settings > Mapping and Geocoding');
$this->returnError = 1;
}
// do check for parse street address.
- return $this->processContacts($config, $processGeocode, $parseStreetAddress);
+ return $this->processContacts($processGeocode, $parseStreetAddress);
}
/**
* Process contacts.
*
- * @param CRM_Core_Config $config
* @param bool $processGeocode
* @param bool $parseStreetAddress
*
* @return array
* @throws Exception
*/
- public function processContacts(&$config, $processGeocode, $parseStreetAddress) {
+ public function processContacts($processGeocode, $parseStreetAddress) {
// build where clause.
$clause = array('( c.id = a.contact_id )');
$params = array();
$totalGeocoded = $totalAddresses = $totalAddressParsed = 0;
$dao = CRM_Core_DAO::executeQuery($query, $params);
- if ($processGeocode) {
- require_once str_replace('_', DIRECTORY_SEPARATOR, $config->geocodeMethod) . '.php';
- }
$unparseableContactAddress = array();
while ($dao->fetch()) {
usleep(5000000);
}
- $className = $config->geocodeMethod;
- $className::format($params, TRUE);
+ CRM_Core_BAO_Address::addGeocoderData($params);
// see if we got a geocode error, in this case we'll trigger a fatal
// CRM-13760
isset($params['geo_code_error']) &&
$params['geo_code_error'] == 'OVER_QUERY_LIMIT'
) {
- CRM_Core_Error::fatal('Aborting batch geocoding. Hit the over query limit on geocoder.');
+ throw new CRM_Core_Exception('Aborting batch geocoding. Hit the over query limit on geocoder.');
}
array_shift($params);