DefaultController.php
7.89 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
namespace Swpb\Bundle\CocarBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
class DefaultController extends Controller
{
/**
* @Route("/index", name="cocar_index")
* @Template()
*/
public function indexAction()
{
return array();
}
/**
* @Route("/", name="cocar_map")
* @Template()
*/
public function mapAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$search = false;
if($request->isMethod('POST'))
{
$circuit = $request->request->get('circuit');
$searchResult = $em->createQuery(
"SELECT c.description, c.id, e.identifier FROM CocarBundle:Circuits c
LEFT JOIN CocarBundle:Entity e WITH c.entity = e.id
WHERE c.description LIKE :description"
)
->setParameter('description', "%$circuit%")
->getResult();
$search = true;
}
$highTraffic = $em->createQuery(
"SELECT c.id, c.codeInterface, c.description, e.description entity FROM CocarBundle:Circuits c
LEFT JOIN CocarBundle:Entity e WITH c.entity = e.id
WHERE c.history LIKE :history
AND c.manages <> :manage
AND c.operStatus = :status"
)
->setParameter('history', '%A%')
->setParameter('manage', 'Entidades Externas')
->setParameter('status', 'UP')
->getResult();
$withoutTraffic = $em->createQuery(
"SELECT c.id, c.codeInterface, c.description, e.description entity FROM CocarBundle:Circuits c
LEFT JOIN CocarBundle:Entity e WITH c.entity = e.id
WHERE c.history LIKE :history
AND c.manages <> :manage
AND c.operStatus = :status"
)
->setParameter('history', '%Z%')
->setParameter('manage', 'Entidades Externas')
->setParameter('status', 'UP')
->getResult();
$reliability = $em->createQuery(
"SELECT c.id, c.codeInterface, c.description, e.description entity FROM CocarBundle:Circuits c
LEFT JOIN CocarBundle:Entity e WITH c.entity = e.id
WHERE (c.manages <> :manage1
AND c.manages <> :manage2)
AND c.operStatus = :status"
)
->setParameter('manage1', 'Entidades Externas')
->setParameter('manage2', 'Firewall')
->setParameter('status', 'UP')
->getResult();
$total = $em->createQuery(
"SELECT count(c.id) total FROM CocarBundle:Circuits c
WHERE c.manages <> :manage
AND c.operStatus = :status"
)
->setParameter('manage', 'Entidades Externas')
->setParameter('status', 'UP')
->getSingleResult();
return array(
'reliability' => $reliability,
'high_traffic' => $highTraffic,
'without_traffic' => $withoutTraffic,
'total' => $total['total'],
'search_result' => isset($searchResult) ? $searchResult : null,
'search' => $search
);
}
/**
* @Route("/totalizer", name="cocar_totalizer")
* @Template()
*/
public function totalizerAction()
{
$em = $this->getDoctrine()->getManager();
$entitys = $em->getRepository('CocarBundle:Entity')->findAll();
foreach ($entitys as $entity)
{
$highTraffic = $em->createQuery(
"SELECT COUNT(c.id) total FROM CocarBundle:Circuits c
LEFT JOIN CocarBundle:Entity e WITH c.entity = e.id
WHERE c.history LIKE :history
AND c.manages <> :manage
AND c.operStatus = :status
AND e.id = :id"
)
->setParameter('history', '%A%')
->setParameter('manage', 'Entidades Externas')
->setParameter('status', 'UP')
->setParameter('id', $entity->getId())
->getSingleResult();
$withoutTraffic = $em->createQuery(
"SELECT COUNT(c.id) total FROM CocarBundle:Circuits c
LEFT JOIN CocarBundle:Entity e WITH c.entity = e.id
WHERE c.history LIKE :history
AND c.manages <> :manage
AND c.operStatus = :status
AND e.id = :id"
)
->setParameter('history', '%Z%')
->setParameter('manage', 'Entidades Externas')
->setParameter('status', 'UP')
->setParameter('id', $entity->getId())
->getSingleResult();
$reliability = $em->createQuery(
"SELECT COUNT(c.id) total FROM CocarBundle:Circuits c
LEFT JOIN CocarBundle:Entity e WITH c.entity = e.id
WHERE (c.manages <> :manage1
AND c.manages <> :manage2)
AND c.operStatus = :status
AND e.id = :id"
)
->setParameter('manage1', 'Entidades Externas')
->setParameter('manage2', 'Firewall')
->setParameter('status', 'UP')
->setParameter('id', $entity->getId())
->getSingleResult();
$total = $em->createQuery(
"SELECT count(c.id) total FROM CocarBundle:Circuits c
WHERE c.manages <> :manage
AND c.operStatus = :status
AND c.entity = :entity"
)
->setParameter('manage', 'Entidades Externas')
->setParameter('status', 'UP')
->setParameter('entity', $entity->getId())
->getSingleResult();
$circuits[$entity->getId()] = array(
'high' => $highTraffic['total'],
'without' => $withoutTraffic['total'],
'rly' => $reliability['total'],
'description' => $entity->getDescription(),
'totalCirc' => $highTraffic['total'] + $withoutTraffic['total'] + $reliability['total'],
'total' => isset($total['total']) ? $total['total'] : 0
);
}
return array('circuits' => $circuits);
}
}