Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14098 anikendra 1
<?php
2
/**
3
 * GeoController class
4
 *
5
 * @uses          AppController
6
 * @package       mongodb
7
 * @subpackage    mongodb.samples.controllers
8
 */
9
class GeosController extends AppController {
10
 
11
	/**
12
	 * name property
13
	 *
14
	 * @var string 'Geo'
15
	 * @access public
16
	 */
17
	public $name = 'Geos';
18
 
19
	/**
20
	 * index method
21
	 *
22
	 * @return void
23
	 * @access public
24
	 */
25
	public function index($type = null, $lat = null, $long = null, $opt1 = null, $opt2 = null) {
26
 
27
		$params = array(
28
				'limit' => 35,
29
				'page' => 1,
30
				);
31
 
32
		if(!empty($type) && !empty($lat) && !empty($long)) {
33
			$lat = floatval($lat);
34
			$long = floatval($long);
35
			$opt1 = floatval($opt1);
36
			$opt2 = floatval($opt2);
37
 
38
			switch($type) {
39
				case('near'):
40
					if(!empty($opt1)){
41
						$cond = array('loc' => array('$near' => array($lat, $long), '$maxDistance' => $opt1));
42
					} else {
43
						$cond = array('loc' => array('$near' => array($lat, $long)));
44
					}
45
					break;
46
				case('box'):
47
					$lowerLeft = array($lat, $long);
48
					$upperRight = array($opt1, $opt2);
49
					$cond = array('loc' => array('$within' => array('$box' => array($lowerLeft, $upperRight))));
50
					break;
51
				case('circle'):
52
					$center = array($lat, $long);
53
					$radius = $opt1;
54
					$cond = array('loc' => array('$within' => array('$center' => array($center, $radius))));
55
					break;
56
			}
57
			$params['conditions'] = $cond;
58
 
59
		} else {
60
			$params['order'] = array('_id' => -1);
61
		}
62
 
63
		$results = $this->Geo->find('all', $params);
64
		$this->set(compact('results'));
65
	}
66
 
67
	/**
68
	 * add method
69
	 *
70
	 * @return void
71
	 * @access public
72
	 */
73
	public function add() {
74
		if (!empty($this->data)) {
75
 
76
			$this->Geo->create();
77
			if ($this->Geo->save($this->data)) {
78
				$this->flash(__('Geo saved.', true), array('action' => 'index'));
79
			} else {
80
			}
81
		}
82
	}
83
 
84
	/**
85
	 * delete method
86
	 *
87
	 * @param mixed $id null
88
	 * @return void
89
	 * @access public
90
	 */
91
	public function delete($id = null) {
92
		if (!$id) {
93
			$this->flash(__('Invalid Geo', true), array('action' => 'index'));
94
		}
95
		if ($this->Geo->delete($id)) {
96
			$this->flash(__('Geo deleted', true), array('action' => 'index'));
97
		} else {
98
			$this->flash(__('Geo deleted Fail', true), array('action' => 'index'));
99
		}
100
	}
101
}