1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Api\Controller; |
4
|
|
|
|
5
|
|
|
use Zend\Mvc\Controller\AbstractRestfulController; |
6
|
|
|
use Zend\View\Model\JsonModel; |
7
|
|
|
use Api\Entity\Indicator; |
8
|
|
|
use Api\Entity\IndicatorValue; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* |
12
|
|
|
*/ |
13
|
|
|
class IndicatorsReportController extends AbstractRestfulController |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Entity manager. |
17
|
|
|
* @var Doctrine\ORM\EntityManager |
18
|
|
|
*/ |
19
|
|
|
private $entityManager; |
20
|
|
|
|
21
|
1 |
|
public function __construct($entityManager) |
22
|
|
|
{ |
23
|
1 |
|
$this->entityManager = $entityManager; |
24
|
1 |
|
} |
25
|
1 |
|
public function getIndicatorAction() |
26
|
|
|
{ |
27
|
1 |
|
$indicator = (int) $this->params()->fromRoute('indicator'); |
28
|
|
|
|
29
|
1 |
|
$response = []; |
30
|
|
|
|
31
|
|
|
// DATOS GENERALES DEL INDICADOR |
32
|
1 |
|
$arrIndicador = $this->entityManager->getRepository(Indicator::class) |
33
|
1 |
|
->getIndicator($indicator); |
34
|
|
|
|
35
|
1 |
|
foreach ($arrIndicador as $indicador) { |
36
|
1 |
|
$response['indicador'] = $indicador; |
37
|
1 |
|
break; |
38
|
|
|
} |
39
|
|
|
|
40
|
1 |
|
$arrValores = $this->entityManager->getRepository(IndicatorValue::class) |
41
|
1 |
|
->getIndicatorValue($indicator); |
42
|
|
|
|
43
|
1 |
|
$arrAnos = []; |
44
|
1 |
|
$arrValor = []; |
45
|
|
|
|
46
|
1 |
|
foreach ($arrValores as $a) { |
47
|
|
|
// SI EL NOMBRE TIENE UNA COMA LO TENGO QUE PONER ENTRE COMILLAS |
48
|
1 |
|
$arrAnos[] = $a['year']; |
49
|
1 |
|
$arrValor[] = $a['value']; |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
$arrAnos = array_merge(array('x'), $arrAnos); |
53
|
1 |
|
$response['column_1'] = $arrAnos; |
54
|
|
|
|
55
|
1 |
|
$arrValor = array_merge(array($indicador['name']), $arrValor); |
|
|
|
|
56
|
1 |
|
$response['column_2'] = $arrValor; |
57
|
|
|
|
58
|
1 |
|
$response['unidad'] = $indicador['unit']; |
59
|
1 |
|
$response['descripcion'] = nl2br($indicador['description']); |
60
|
|
|
|
61
|
1 |
|
$response['colores'] = "#8064a2"; |
62
|
|
|
|
63
|
1 |
|
return new JsonModel($response); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
It seems like you are relying on a variable being defined by an iteration: