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