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