/
ParametrizarController.php
201 lines (154 loc) · 5.6 KB
/
ParametrizarController.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
namespace Dispo\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Doctrine\ORM\EntityManager;
use Zend\View\Model\JsonModel;
use Dispo\BO\ParametrizarBO;
use Dispo\DATA\ParametrizarData;
class ParametrizarController extends AbstractActionController
{
public function mantenimientoAction()
{
try
{
$viewModel = new ViewModel();
$EntityManagerPlugin = $this->EntityManagerPlugin();
//Controla el acceso a la informacion, solo accedera si es administrador
$SesionUsuarioPlugin = $this->SesionUsuarioPlugin();
$respuesta = $SesionUsuarioPlugin->isLoginAdmin();
if ($respuesta==false) return false;
$ParametrizarBO = new ParametrizarBO();
$ParametrizarBO->setEntityManager($EntityManagerPlugin->getEntityManager());
$condiciones = null;
$result = $ParametrizarBO->listado($condiciones);
$this->layout($SesionUsuarioPlugin->getUserLayout());
$viewModel->result = $result;
$viewModel->setTemplate('dispo/parametrizar/mantenimiento.phtml');
return $viewModel;
}catch (\Exception $e) {
$excepcion_msg = utf8_encode($this->ExcepcionPlugin()->getMessageFormat($e));
$response = $this->getResponse();
$response->setStatusCode(500);
$response->setContent($excepcion_msg);
return $response;
}
}//end function
public function nuevodataAction()
{
try
{
$SesionUsuarioPlugin = $this->SesionUsuarioPlugin();
$EntityManagerPlugin = $this->EntityManagerPlugin();
$respuesta = $SesionUsuarioPlugin->isLoginAdmin();
if ($respuesta==false) return false;
$condiciones = null;
$response = new \stdClass();
$response->cbo_tipo = \Application\Classes\ComboGeneral::getComboTipo("","");
$response->respuesta_code = 'OK';
$response->respuesta_mensaje = '';
$json = new JsonModel(get_object_vars($response));
return $json;
//false
}catch (\Exception $e) {
$excepcion_msg = utf8_encode($this->ExcepcionPlugin()->getMessageFormat($e));
$response = $this->getResponse();
$response->setStatusCode(500);
$response->setContent($excepcion_msg);
return $response;
}
}//end function nuevodataAction
public function consultardataAction()
{
try
{
$SesionUsuarioPlugin = $this->SesionUsuarioPlugin();
$EntityManagerPlugin = $this->EntityManagerPlugin();
$ParametrizarBO = new ParametrizarBO();
$ParametrizarBO->setEntityManager($EntityManagerPlugin->getEntityManager());
$respuesta = $SesionUsuarioPlugin->isLoginAdmin();
if ($respuesta==false) return false;
$body = $this->getRequest()->getContent();
$json = json_decode($body, true);
$id = $json['id'];
$row = $ParametrizarBO->consultar($id, \Application\Constants\ResultType::MATRIZ);
$response = new \stdClass();
$response->row = $row;
//$response->cbo_tipo = \Application\Classes\ComboGeneral::getComboTipo($row['tipo'], "<Seleccione>");
$response->respuesta_code = 'OK';
$response->respuesta_mensaje = '';
$json = new JsonModel(get_object_vars($response));
return $json;
//false
}catch (\Exception $e) {
$excepcion_msg = utf8_encode($this->ExcepcionPlugin()->getMessageFormat($e));
$response = $this->getResponse();
$response->setStatusCode(500);
$response->setContent($excepcion_msg);
return $response;
}
}//end function consultardataAction
public function grabardataAction()
{
try
{
$SesionUsuarioPlugin = $this->SesionUsuarioPlugin();
$usuario_id = $SesionUsuarioPlugin->getUsuarioId();
$EntityManagerPlugin = $this->EntityManagerPlugin();
$ParametrizarData = new ParametrizarData();
$ParametrizarBO = new ParametrizarBO();
$ParametrizarBO->setEntityManager($EntityManagerPlugin->getEntityManager());
$respuesta = $SesionUsuarioPlugin->isLoginAdmin();
if ($respuesta==false) return false;
$body = $this->getRequest()->getContent();
$json = json_decode($body, true);
$accion = $json['accion']; //I, M
$ParametrizarData->setId ($json['id']);
$ParametrizarData->setValorTexto ($json['valor_texto']);
$ParametrizarData->setValorNumerico ($json['valor_numerico']);
$ParametrizarData->setObservacion ($json['observacion']);
switch ($accion)
{
case 'I':
$ParametrizarData->setUsuarioIngId($usuario_id);
$result = $ParametrizarBO->ingresar($ParametrizarData);
break;
case 'M':
$ParametrizarData->setUsuarioModId($usuario_id);
$result = $ParametrizarBO->modificar($ParametrizarData);
break;
default:
$result['validacion_code'] = 'ERROR';
$result['respuesta_mensaje']= 'ACCESO NO VALIDO';
break;
}//end switch
//Se consulta el registro siempre y cuando el validacion_code sea OK
if ($result['validacion_code']=='OK')
{
}else{
$row = null;
}//end if
//Retorna la informacion resultante por JSON
$row = null;
$response = new \stdClass();
$response->respuesta_code = 'OK';
$response->validacion_code = $result['validacion_code'];
$response->respuesta_mensaje = $result['respuesta_mensaje'];
if ($row)
{
$response->row = $row;
}else{
$response->row = null;
}//end if
$json = new JsonModel(get_object_vars($response));
return $json;
//false
}catch (\Exception $e) {
$excepcion_msg = utf8_encode($this->ExcepcionPlugin()->getMessageFormat($e));
$response = $this->getResponse();
$response->setStatusCode(500);
$response->setContent($excepcion_msg);
return $response;
}
}//end function consultarAction
}//end controller