Skip to content

Commit

Permalink
Adding geocode plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mariano committed Sep 1, 2009
0 parents commit 86b9101
Show file tree
Hide file tree
Showing 9 changed files with 1,590 additions and 0 deletions.
571 changes: 571 additions & 0 deletions models/behaviors/geocodable.php

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions models/geo_address.php
@@ -0,0 +1,41 @@
<?php
class GeoAddress extends AppModel {
/**
* Behaviors
*
* @var array
*/
public $actsAs = array('Geocodable');

/**
* Overriden to implement 'near' find type, and support for 'count' with 'near'
*
* @param array $conditions SQL conditions array, or type of find operation (all / first / count / neighbors / list / threaded)
* @param mixed $fields Either a single string of a field name, or an array of field names, or options for matching
* @param string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC")
* @param integer $recursive The number of levels deep to fetch associated records
* @return array Array of records
*/
public function find($conditions = null, $fields = array(), $order = null, $recursive = null) {
$findMethods = array_merge($this->_findMethods, array('near'=>true));
$findType = (is_string($conditions) && $conditions != 'count' && array_key_exists($conditions, $findMethods) ? $conditions : null);
if (empty($findType) && is_string($conditions) && $conditions == 'count' && !empty($fields['type']) && array_key_exists($fields['type'], $findMethods)) {
$findType = $fields['type'];
unset($fields['type']);
}

if ($findType == 'near' && $this->Behaviors->enabled('Geocodable')) {
$type = ($conditions == 'near' ? 'all' : $conditions);
$query = $fields;
if (!empty($query['address'])) {
foreach(array('address', 'unit', 'distance') as $field) {
$$field = isset($query[$field]) ? $query[$field] : null;
unset($query[$field]);
}
return $this->near($type, $address, $distance, $unit, $query);
}
}
return parent::find($conditions, $fields, $order, $recursive);
}
}
?>

0 comments on commit 86b9101

Please sign in to comment.