1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Api\Controller; |
4
|
|
|
|
5
|
|
|
use Zend\Mvc\Controller\AbstractRestfulController; |
6
|
|
|
use Zend\View\Model\JsonModel; |
7
|
|
|
use Api\Helper\Utils; |
8
|
|
|
use Api\Entity\Emission; |
9
|
|
|
use Api\Entity\Sector; |
10
|
|
|
use Api\Entity\Subactivity; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @SWG\Swagger( |
14
|
|
|
* schemes={"http"}, |
15
|
|
|
* basePath="/informe", |
16
|
|
|
* @SWG\Info( |
17
|
|
|
* title="API documentation", |
18
|
|
|
* version="1.0.1" |
19
|
|
|
* ) |
20
|
|
|
* ) |
21
|
|
|
*/ |
22
|
|
|
class EvolutionReportController extends AbstractRestfulController |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Entity manager. |
26
|
|
|
* @var Doctrine\ORM\EntityManager |
27
|
|
|
*/ |
28
|
|
|
private $entityManager; |
29
|
|
|
|
30
|
|
|
const START_YEAR = 1990; |
31
|
|
|
|
32
|
|
|
const END_YEAR = 2014; |
33
|
|
|
|
34
|
4 |
|
public function __construct($entityManager) |
35
|
|
|
{ |
36
|
4 |
|
$this->entityManager = $entityManager; |
37
|
4 |
|
} |
38
|
|
|
|
39
|
1 |
|
public function getWholeSectoralEvolutionAction() |
40
|
|
|
{ |
41
|
1 |
|
$response = []; |
42
|
|
|
|
43
|
|
|
// TRAIGO LOS SECTORES CON SUS COLORES |
44
|
|
|
|
45
|
1 |
|
$arrSectores = $this->entityManager->getRepository(Sector::class) |
46
|
1 |
|
->getSectorsOrderedyName(); |
47
|
|
|
|
48
|
|
|
// TRAIGO LOS VALORES POR ANO |
49
|
|
|
// LO QUE ESTA ADENTRO DEL LOOP DEBERIA IR ACA |
50
|
|
|
|
51
|
1 |
|
$arrAnos = []; |
52
|
1 |
|
$arrValores = []; |
|
|
|
|
53
|
1 |
|
$arrColores = []; |
|
|
|
|
54
|
|
|
|
55
|
1 |
|
for ($i = self::START_YEAR; $i <= self::END_YEAR; $i++) { |
56
|
1 |
|
$arrAnos[] = $i; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
$column = 2; |
60
|
|
|
|
61
|
1 |
|
foreach ($arrSectores as $sector) { |
62
|
1 |
|
$response['column_'.$column][] = $sector['name']; |
63
|
1 |
|
$response['colores'][] = $sector['color']; |
64
|
|
|
|
65
|
1 |
|
foreach ($arrAnos as $ano) { |
66
|
|
|
// ATENCION, CABECEADA |
67
|
|
|
// ESTOY EJECUTANDO EL QUERY CADA VEZ QUE NECESITO LA LISTA DE VALORES |
68
|
|
|
// ESTA PARTE DEBERIA AFUERA DEL LOOP Y SE DEBERIA REUTILIZAR $arrValoresCrudo |
69
|
1 |
|
$arrValoresCrudo = $this->entityManager->getRepository(Emission::class) |
70
|
1 |
|
->findSectorGroupedByYear(); |
71
|
|
|
|
72
|
1 |
|
if (empty($arrValoresCrudo)) { |
73
|
|
|
$this->response->setStatusCode(404); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
// HASTA ACA |
76
|
|
|
|
77
|
1 |
|
$response['column_'.$column][] = Utils::returnSectorAno($arrValoresCrudo, $sector['name'], $ano); |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
$column++; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
1 |
|
$arrAnos = array_merge(array('x'), $arrAnos); |
85
|
1 |
|
$response['column_1'] = $arrAnos; |
86
|
|
|
|
87
|
1 |
|
return new JsonModel($response); |
88
|
|
|
} |
89
|
|
|
|
90
|
1 |
View Code Duplication |
public function getSectoralEvolutionAction() |
|
|
|
|
91
|
|
|
{ |
92
|
1 |
|
$sector = (int) $this->params()->fromRoute('sector'); |
93
|
|
|
|
94
|
1 |
|
$response = []; |
95
|
|
|
|
96
|
|
|
// TRAIGO LOS SECTORES CON SUS COLORES |
97
|
|
|
|
98
|
1 |
|
$arrSectores = $this->entityManager->getRepository(Sector::class)->getSector($sector); |
99
|
|
|
|
100
|
1 |
|
if (empty($arrSectores)) { |
101
|
|
|
$this->response->setStatusCode(404); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
// TRAIGO LOS VALORES POR ANO |
105
|
|
|
// LO QUE ESTA ADENTRO DEL LOOP DEBERIA IR ACA |
106
|
|
|
|
107
|
1 |
|
$arrAnos = []; |
108
|
1 |
|
$arrValores = []; |
|
|
|
|
109
|
1 |
|
$arrColores = []; |
|
|
|
|
110
|
|
|
|
111
|
1 |
|
for ($i = self::START_YEAR; $i <= self::END_YEAR; $i++) { |
112
|
1 |
|
$arrAnos[] = $i; |
113
|
|
|
} |
114
|
|
|
|
115
|
1 |
|
$column = 2; |
116
|
|
|
|
117
|
1 |
|
foreach ($arrSectores as $sector) { |
118
|
1 |
|
$response['column_'.$column][] = $sector['name']; |
119
|
1 |
|
$response['colores'][] = $sector['color']; |
120
|
|
|
|
121
|
1 |
|
foreach ($arrAnos as $ano) { |
122
|
|
|
// ATENCION, CABECEADA |
123
|
|
|
// ESTOY EJECUTANDO EL QUERY CADA VEZ QUE NECESITO LA LISTA DE VALORES |
124
|
|
|
// ESTA PARTE DEBERIA AFUERA DEL LOOP Y SE DEBERIA REUTILIZAR $arrValoresCrudo |
125
|
1 |
|
$arrValoresCrudo = $this->entityManager->getRepository(Emission::class) |
126
|
1 |
|
->findSectorGroupedByYear(); |
127
|
|
|
|
128
|
1 |
|
if (empty($arrValoresCrudo)) { |
129
|
|
|
$this->response->setStatusCode(404); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
// HASTA ACA |
132
|
|
|
|
133
|
1 |
|
$response['column_'.$column][] = Utils::returnSectorAno($arrValoresCrudo, $sector['name'], $ano); |
134
|
|
|
} |
135
|
|
|
|
136
|
1 |
|
$column++; |
137
|
|
|
} |
138
|
|
|
|
139
|
1 |
|
$arrAnos = array_merge(array('x'), $arrAnos); |
140
|
1 |
|
$response['column_1'] = $arrAnos; |
141
|
|
|
|
142
|
1 |
|
return new JsonModel($response); |
143
|
|
|
} |
144
|
|
|
|
145
|
1 |
View Code Duplication |
public function getSectoralEvolutionSubactivityAction() |
|
|
|
|
146
|
|
|
{ |
147
|
1 |
|
$sector = (int) $this->params()->fromRoute('sector'); |
148
|
|
|
|
149
|
1 |
|
$response = []; |
150
|
|
|
|
151
|
1 |
|
$arrSubactividades = $this->entityManager->getRepository(Subactivity::class) |
152
|
1 |
|
->findActivitySectorBySector($sector); |
153
|
|
|
|
154
|
1 |
|
if (empty($arrSubactividades)) { |
155
|
|
|
$this->response->setStatusCode(404); |
|
|
|
|
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
// TRAIGO LOS VALORES POR ANO |
159
|
|
|
// LO QUE ESTA ADENTRO DEL LOOP DEBERIA IR ACA |
160
|
|
|
|
161
|
1 |
|
$arrAnos = []; |
162
|
1 |
|
$arrValores = []; |
|
|
|
|
163
|
1 |
|
$arrColores = []; |
|
|
|
|
164
|
|
|
|
165
|
1 |
|
for ($i = self::START_YEAR; $i <= self::END_YEAR; $i++) { |
166
|
1 |
|
$arrAnos[] = $i; |
167
|
|
|
} |
168
|
|
|
|
169
|
1 |
|
$column = 2; |
170
|
|
|
|
171
|
1 |
|
foreach ($arrSubactividades as $subactividad) { |
172
|
1 |
|
$response['column_'.$column][] = $subactividad['name']; |
173
|
1 |
|
$response['groups'][] = $subactividad['name']; |
174
|
|
|
|
175
|
1 |
|
foreach ($arrAnos as $ano) { |
176
|
|
|
// ATENCION, CABECEADA |
177
|
|
|
// ESTOY EJECUTANDO EL QUERY CADA VEZ QUE NECESITO LA LISTA DE VALORES |
178
|
|
|
// ESTA PARTE DEBERIA AFUERA DEL LOOP Y SE DEBERIA REUTILIZAR $arrValoresCrudo |
179
|
1 |
|
$arrValoresCrudo = $this->entityManager->getRepository(Emission::class) |
180
|
1 |
|
->findSubactivitySectorBySector($sector); |
181
|
|
|
|
182
|
1 |
|
if (empty($arrValoresCrudo)) { |
183
|
|
|
$this->response->setStatusCode(404); |
|
|
|
|
184
|
|
|
} |
185
|
|
|
// HASTA ACA |
186
|
|
|
|
187
|
1 |
|
$response['column_'.$column][] = Utils::returnSectorAno($arrValoresCrudo, $subactividad['name'], $ano); |
188
|
|
|
} |
189
|
|
|
|
190
|
1 |
|
$column++; |
191
|
|
|
} |
192
|
|
|
|
193
|
1 |
|
$arrAnos = array_merge(array('x'), $arrAnos); |
194
|
1 |
|
$response['column_1'] = $arrAnos; |
195
|
|
|
|
196
|
1 |
|
return new JsonModel($response); |
197
|
|
|
} |
198
|
|
|
|
199
|
1 |
|
public function getSectoralEvolutionSubactivityCategoryAction() |
200
|
|
|
{ |
201
|
1 |
|
$sector = (int) $this->params()->fromRoute('sector'); |
202
|
1 |
|
$subactivity = (int) $this->params()->fromRoute('subactivity'); |
203
|
|
|
|
204
|
1 |
|
$response = []; |
205
|
|
|
|
206
|
1 |
|
$arrCategorias = $this->entityManager->getRepository(Emission::class) |
207
|
1 |
|
->findSubactivitySectorCategoryBySectorSubactivity($sector, $subactivity); |
208
|
|
|
|
209
|
|
|
// LO QUE ESTA ADENTRO DEL LOOP DEBERIA IR ACA |
210
|
1 |
|
$arrAnos = []; |
211
|
1 |
|
$arrValores = []; |
|
|
|
|
212
|
1 |
|
$arrColores = []; |
|
|
|
|
213
|
|
|
|
214
|
1 |
|
for ($i = self::START_YEAR; $i <= self::END_YEAR; $i++) { |
215
|
1 |
|
$arrAnos[] = $i; |
216
|
|
|
} |
217
|
|
|
|
218
|
1 |
|
$column = 2; |
219
|
|
|
|
220
|
|
|
// // // pr($arrCategorias); |
221
|
|
|
// // // pr($arr); |
222
|
|
|
|
223
|
1 |
|
foreach ($arrCategorias as $categoria) { |
224
|
1 |
|
$response['column_'.$column][] = $categoria['name']; |
225
|
1 |
|
$response['groups'][] = $categoria['name']; |
226
|
|
|
|
227
|
1 |
|
foreach ($arrAnos as $ano) { |
228
|
|
|
|
229
|
|
|
// ATENCION, CABECEADA |
230
|
|
|
// ESTOY EJECUTANDO EL QUERY CADA VEZ QUE NECESITO LA LISTA DE VALORES |
231
|
|
|
// ESTA PARTE DEBERIA AFUERA DEL LOOP Y SE DEBERIA REUTILIZAR $arrValoresCrudo |
232
|
1 |
|
$arrValoresCrudo = $this->entityManager->getRepository(Emission::class) |
233
|
1 |
|
->findSubactivitySectorCategoryBySectorSubactivityGroupByYearName($sector, $subactivity); |
234
|
|
|
|
235
|
1 |
|
if (empty($arrValoresCrudo)) { |
|
|
|
|
236
|
|
|
//$this->response->setStatusCode(404); |
|
|
|
|
237
|
|
|
} |
238
|
|
|
// HASTA ACA |
239
|
|
|
|
240
|
1 |
|
$response['column_'.$column][] = Utils::returnCategoriaAno($arrValoresCrudo, $categoria['name'], $ano); |
241
|
|
|
} |
242
|
|
|
|
243
|
1 |
|
$column++; |
244
|
|
|
} |
245
|
|
|
|
246
|
1 |
|
$arrAnos = array_merge(array('x'), $arrAnos); |
247
|
1 |
|
$response['column_1'] = $arrAnos; |
248
|
|
|
|
249
|
1 |
|
return new JsonModel($response); |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.