Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14098 anikendra 1
<?php
2
 
3
class Geo extends AppModel {
4
/*
5
	var $mongoSchema = array(
6
			'title' => array('type'=>'string'),
7
			'body'=>array('type'=>'string'),
8
			'loc'=>array(
9
				'lat' => array('type'=>'float'),
10
				'long' => array('type'=>'float'),
11
				),
12
			'created'=>array('type'=>'datetime'),
13
			'modified'=>array('type'=>'datetime'),
14
			);
15
*/
16
 
17
	function beforeSave() {
18
		if(!empty($this->data[$this->alias]['loc'])) {
19
			//convert location info from string to float 
20
			$this->data[$this->alias]['loc']['lat'] = floatval($this->data[$this->alias]['loc']['lat']);
21
			$this->data[$this->alias]['loc']['long'] = floatval($this->data[$this->alias]['loc']['long']);
22
		}
23
		return true;
24
	}
25
 
26
 
27
	function afterSave($created) {
28
		//create Gespatial Index
29
		$mongo = $this->getDataSource();
30
		$mongo->ensureIndex($this, array('loc' => "2d"));
31
		return true;
32
	}
33
 
34
}