/
IndexController.php
96 lines (71 loc) · 2.16 KB
/
IndexController.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
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
{
public function indexAction()
{
return new ViewModel();
}
public function render($data)
{
$json = array();
if($data->hasNext())
{
while($data->hasNext())
{
$json[] = $data->getNext();
}
}
echo json_encode($json);
}
public function parksAction()
{
$mongodb = $GLOBALS['mongodb'];
$this->render($mongodb->parkpoints->find());
return $this->response;
}
public function parkAction()
{
$mongodb = $GLOBALS['mongodb'];
$event = $this->getEvent();
$matches = $event->getRouteMatch();
$park = $matches->getParam("park");
$park = $mongodb->parkpoints->findOne(array('_id' => new \MongoId($park)));
echo json_encode($park);
return $this->response;
}
public function nearAction()
{
$mongodb = $GLOBALS['mongodb'];
$lat = floatval($_GET['lat']);
$lon = floatval($_GET['lon']);
$this->render($mongodb->parkpoints->find(array('pos' => array('$near' => array($lon,$lat))))) ;
return $this->response;
}
public function namedNearAction()
{
$mongodb = $GLOBALS['mongodb'];
$event = $this->getEvent();
$matches = $event->getRouteMatch();
$name = $matches->getParam("name");
$lat = floatval($_GET['lat']);
$lon = floatval($_GET['lon']);
$this->render($mongodb->parkpoints->find(array('Name' => array('$regex' => $name, '$options' => 'i'), 'pos' => array('$near' => array($lon,$lat)))));
return $this->response;
}
public function testAction()
{
$mongodb = $GLOBALS['mongodb'];
echo "<strong>It actually worked</strong>";
return $this->response;
}
}