X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FProximityQuery.php;h=b5e065df0fa7459126cae5589dd0a9f00ab8562f;hb=2c6bbd0646494e3ce48ea7e87f88c90dfaf5f64a;hp=9008e6f4e8e9429e901593c6426233bce8ca315e;hpb=1aa17e959badfacdd2f9711945949747596e6e15;p=civicrm-core.git diff --git a/CRM/Contact/BAO/ProximityQuery.php b/CRM/Contact/BAO/ProximityQuery.php index 9008e6f4e8..b5e065df0f 100644 --- a/CRM/Contact/BAO/ProximityQuery.php +++ b/CRM/Contact/BAO/ProximityQuery.php @@ -1,9 +1,9 @@ = $minLatitude "; + } + if (!is_nan($maxLatitude)) { + $geoCodeWhere[] = "{$tablePrefix}.geo_code_1 <= $maxLatitude "; + } + if (!is_nan($minLongitude)) { + $geoCodeWhere[] = "{$tablePrefix}.geo_code_2 >= $minLongitude "; + } + if (!is_nan($maxLongitude)) { + $geoCodeWhere[] = "{$tablePrefix}.geo_code_2 <= $maxLongitude "; + } + $geoCodeWhereClause = implode(' AND ', $geoCodeWhere); + $where = " -{$tablePrefix}.geo_code_1 >= $minLatitude AND -{$tablePrefix}.geo_code_1 <= $maxLatitude AND -{$tablePrefix}.geo_code_2 >= $minLongitude AND -{$tablePrefix}.geo_code_2 <= $maxLongitude AND +{$geoCodeWhereClause} AND ACOS( COS(RADIANS({$tablePrefix}.geo_code_1)) * COS(RADIANS($latitude)) * @@ -216,10 +238,15 @@ ACOS( SIN(RADIANS($latitude)) ) * 6378137 <= $distance "; - return $where; } + /** + * @param $query + * @param $values + * + * @throws Exception + */ static function process(&$query, &$values) { list($name, $op, $distance, $grouping, $wildcard) = $values; @@ -262,7 +289,7 @@ ACOS( if (!isset($proximityAddress['country_id'])) { // get it from state if state is present if (isset($proximityAddress['state_province_id'])) { - $proximityAddress['country_id'] = CRM_Core_PseudoConstant::countryForState($proximityAddress['state_province_id']); + $proximityAddress['country_id'] = CRM_Core_PseudoConstant::countryIDForStateID($proximityAddress['state_province_id']); } elseif (isset($config->defaultContactCountry)) { $proximityAddress['country_id'] = $config->defaultContactCountry; @@ -324,6 +351,9 @@ ACOS( return; } + /** + * @param $input + */ static function fixInputParams(&$input) { foreach ($input as $param) { if (CRM_Utils_Array::value('0', $param) == 'prox_distance') {