<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
);
}
+ /**
+ * @param $latitude
+ * @param $longitude
+ * @param $distance
+ * @param string $tablePrefix
+ *
+ * @return string
+ */
static function where($latitude, $longitude, $distance, $tablePrefix = 'civicrm_address') {
self::initialize();
$distance
);
+ // DONT consider NAN values (which is returned by rad2deg php function)
+ // for checking BETWEEN geo_code's criteria as it throws obvious 'NAN' field not found DB: Error
+ $geoCodeWhere = array();
+ if (!is_nan($minLatitude)) {
+ $geoCodeWhere[] = "{$tablePrefix}.geo_code_1 >= $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)) *
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;
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;
return;
}
+ /**
+ * @param $input
+ */
static function fixInputParams(&$input) {
foreach ($input as $param) {
if (CRM_Utils_Array::value('0', $param) == 'prox_distance') {