Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 212 | Rev 215 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 212 Rev 213
Línea 1... Línea 1...
1
<?php
1
<?php
-
 
2
 
2
declare(strict_types=1);
3
declare(strict_types=1);
Línea 3... Línea 4...
3
 
4
 
Línea 4... Línea 5...
4
namespace LeadersLinked\Controller;
5
namespace LeadersLinked\Controller;
5
 
6
 
6
use Laminas\Db\Adapter\AdapterInterface;
-
 
7
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
-
 
8
 
7
use Laminas\Db\Adapter\AdapterInterface;
9
 
-
 
10
use Laminas\Mvc\Controller\AbstractActionController;
8
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
11
 
-
 
12
use Laminas\Log\LoggerInterface;
9
use Laminas\Mvc\Controller\AbstractActionController;
13
 
10
use Laminas\Log\LoggerInterface;
14
use Laminas\View\Model\ViewModel;
11
use Laminas\View\Model\ViewModel;
15
use Laminas\View\Model\JsonModel;
12
use Laminas\View\Model\JsonModel;
16
use LeadersLinked\Library\Functions;
13
use LeadersLinked\Library\Functions;
17
use LeadersLinked\Mapper\CompanySelfEvaluationFormMapper;
14
use LeadersLinked\Mapper\CompanySelfEvaluationFormMapper;
18
use LeadersLinked\Form\CompanySelfEvaluationFormForm;
15
use LeadersLinked\Form\CompanySelfEvaluationFormForm;
19
use LeadersLinked\Model\CompanySelfEvaluationForm; 
16
use LeadersLinked\Model\CompanySelfEvaluationForm;
Línea 20... Línea 17...
20
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
17
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
21
use LeadersLinked\Mapper\CompanySelfEvaluationFormUserMapper;
18
use LeadersLinked\Mapper\CompanySelfEvaluationFormUserMapper;
22
 
19
 
23
class SelfEvaluationFormController extends AbstractActionController
20
class SelfEvaluationFormController extends AbstractActionController {
24
{
21
 
25
    /**
22
    /**
26
     *
23
     *
27
     * @var AdapterInterface
-
 
28
     */
24
     * @var AdapterInterface
29
    private $adapter;
25
     */
30
    
26
    private $adapter;
31
    
27
 
32
    /**
28
    /**
33
     *
29
     *
34
     * @var AbstractAdapter
30
     * @var AbstractAdapter
35
     */
31
     */
36
    private $cache;
32
    private $cache;
37
    
33
 
38
    /**
34
    /**
39
     *
35
     *
40
     * @var  LoggerInterface
36
     * @var  LoggerInterface
41
     */
37
     */
42
    private $logger;
38
    private $logger;
43
    
39
 
44
    /**
40
    /**
45
     *
41
     *
Línea 52... Línea 48...
52
     * @param AdapterInterface $adapter
48
     * @param AdapterInterface $adapter
53
     * @param AbstractAdapter $cache
49
     * @param AbstractAdapter $cache
54
     * @param LoggerInterface $logger
50
     * @param LoggerInterface $logger
55
     * @param array $config
51
     * @param array $config
56
     */
52
     */
57
    public function __construct($adapter, $cache , $logger, $config)
53
    public function __construct($adapter, $cache, $logger, $config) {
58
    {
-
 
59
        $this->adapter      = $adapter;
54
        $this->adapter = $adapter;
60
        $this->cache        = $cache;
55
        $this->cache = $cache;
61
        $this->logger       = $logger;
56
        $this->logger = $logger;
62
        $this->config       = $config;
57
        $this->config = $config;
63
        
-
 
64
    }
58
    }
65
    
59
 
66
    public function indexAction()
60
    public function indexAction() {
67
    {
-
 
68
        $request = $this->getRequest();
61
        $request = $this->getRequest();
69
        $currentUserPlugin = $this->plugin('currentUserPlugin');
62
        $currentUserPlugin = $this->plugin('currentUserPlugin');
70
        $currentCompany = $currentUserPlugin->getCompany();
63
        $currentCompany = $currentUserPlugin->getCompany();
71
        $currentUser    = $currentUserPlugin->getUser();
64
        $currentUser = $currentUserPlugin->getUser();
72
        
65
 
73
        
66
 
74
        $request = $this->getRequest();
67
        $request = $this->getRequest();
75
        if($request->isGet()) {
68
        if ($request->isGet()) {
76
            
69
 
77
            $headers  = $request->getHeaders();
70
            $headers = $request->getHeaders();
78
            
71
 
79
            $isJson = false;
72
            $isJson = false;
80
            if($headers->has('Accept')) {
73
            if ($headers->has('Accept')) {
81
                $accept = $headers->get('Accept');
74
                $accept = $headers->get('Accept');
82
                
75
 
83
                $prioritized = $accept->getPrioritized();
76
                $prioritized = $accept->getPrioritized();
84
                
77
 
85
                foreach($prioritized as $key => $value) {
78
                foreach ($prioritized as $key => $value) {
86
                    $raw = trim($value->getRaw());
79
                    $raw = trim($value->getRaw());
87
                    
80
 
88
                    if(!$isJson) {
81
                    if (!$isJson) {
89
                        $isJson = strpos($raw, 'json');
82
                        $isJson = strpos($raw, 'json');
90
                    }
83
                    }
91
                    
-
 
92
                }
84
                }
93
            }
85
            }
94
            
86
 
95
            if($isJson) {
87
            if ($isJson) {
96
                $search = $this->params()->fromQuery('search', []);
88
                $search = $this->params()->fromQuery('search', []);
97
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
89
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
98
                
90
 
99
                $page               = intval($this->params()->fromQuery('start', 1), 10);
91
                $page = intval($this->params()->fromQuery('start', 1), 10);
100
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
92
                $records_x_page = intval($this->params()->fromQuery('length', 10), 10);
101
                $order              =  $this->params()->fromQuery('order', []);
93
                $order = $this->params()->fromQuery('order', []);
102
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
94
                $order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
103
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var( $order[0]['dir'], FILTER_SANITIZE_STRING));
95
                $order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var($order[0]['dir'], FILTER_SANITIZE_STRING));
104
    
96
 
105
                $fields =  ['name'];
97
                $fields = ['name'];
106
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
98
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
107
                
99
 
108
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
100
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
109
                    $order_direction = 'ASC';
101
                    $order_direction = 'ASC';
110
                }
102
                }
111
    
103
 
112
                $companySelfEvaluationMapper = CompanySelfEvaluationFormMapper::getInstance($this->adapter);
104
                $companySelfEvaluationMapper = CompanySelfEvaluationFormMapper::getInstance($this->adapter);
113
                $paginator = $companySelfEvaluationMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
105
                $paginator = $companySelfEvaluationMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
114
                
106
 
115
                $items = [];
107
                $items = [];
116
                $records = $paginator->getCurrentItems();
108
                $records = $paginator->getCurrentItems();
117
                foreach($records as $record)
109
                foreach ($records as $record) {
118
                {
-
 
119
                   
110
 
120
                    if($record->language == CompanySelfEvaluationForm::LANGUAGE_SPANISH) {
111
                    if ($record->language == CompanySelfEvaluationForm::LANGUAGE_SPANISH) {
121
                        $language = 'LABEL_SPANISH';
112
                        $language = 'LABEL_SPANISH';
122
                    } else if($record->language == CompanySelfEvaluationForm::LANGUAGE_ENGLISH) {
113
                    } else if ($record->language == CompanySelfEvaluationForm::LANGUAGE_ENGLISH) {
123
                        $language = 'LABEL_ENGLISH';
114
                        $language = 'LABEL_ENGLISH';
124
                    } else {
115
                    } else {
125
                        $language = '';
116
                        $language = '';
126
                    } 
117
                    }
127
                    
118
 
128
                    $item = [
119
                    $item = [
129
                        'id' => $record->id,
120
                        'id' => $record->id,
130
                        'name' => $record->name,
121
                        'name' => $record->name,
131
                        'language' => $language,
122
                        'language' => $language,
132
                        'status' => $record->status,
123
                        'status' => $record->status,
133
                        'actions' => [
124
                        'actions' => [
134
                            'link_edit' => $this->url()->fromRoute('self-evaluation/forms/edit', ['id' => $record->uuid ]),
125
                            'link_edit' => $this->url()->fromRoute('self-evaluation/forms/edit', ['id' => $record->uuid]),
135
                            'link_delete' => $this->url()->fromRoute('self-evaluation/forms/delete', ['id' =>$record->uuid ])
126
                            'link_delete' => $this->url()->fromRoute('self-evaluation/forms/delete', ['id' => $record->uuid])
136
                        ] 
127
                        ]
137
                    ];
128
                    ];
138
                    
129
 
139
                    array_push($items, $item);
130
                    array_push($items, $item);
140
                }
131
                }
141
                
132
 
142
                return new JsonModel([
133
                return new JsonModel([
143
                    'success' => true,
134
                    'success' => true,
144
                    'data' => [
135
                    'data' => [
145
                        'items' => $items,
136
                        'items' => $items,
146
                        'total' => $paginator->getTotalItemCount(),
137
                        'total' => $paginator->getTotalItemCount(),
147
                    ]
138
                    ]
148
                ]);
139
                ]);
149
            } else { 
140
            } else {
Línea 150... Línea 141...
150
 
141
 
151
                $form = new CompanySelfEvaluationFormForm();
142
                $form = new CompanySelfEvaluationFormForm();
152
                
143
 
153
                $this->layout()->setTemplate('layout/layout-backend');
144
                $this->layout()->setTemplate('layout/layout-backend');
154
                $viewModel = new ViewModel();
145
                $viewModel = new ViewModel();
155
                $viewModel->setTemplate('leaders-linked/self-evaluation-forms/index.phtml');
146
                $viewModel->setTemplate('leaders-linked/self-evaluation-forms/index.phtml');
156
                $viewModel->setVariable('form', $form);
147
                $viewModel->setVariable('form', $form);
157
                return $viewModel ;
148
                return $viewModel;
158
            }
-
 
159
      
149
            }
160
        } else {
150
        } else {
161
            return new JsonModel([
151
            return new JsonModel([
162
                'success' => false,
152
                'success' => false,
163
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
153
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
154
            ]);
164
            ]);;
155
            ;
165
        }
156
        }
166
    }
157
    }
167
    
158
 
168
    public function addAction()
-
 
169
    {
159
    public function addAction() {
170
        $request = $this->getRequest();
160
        $request = $this->getRequest();
171
        $currentUserPlugin = $this->plugin('currentUserPlugin');
161
        $currentUserPlugin = $this->plugin('currentUserPlugin');
172
        $currentCompany = $currentUserPlugin->getCompany();
162
        $currentCompany = $currentUserPlugin->getCompany();
173
        $currentUser    = $currentUserPlugin->getUser();
163
        $currentUser = $currentUserPlugin->getUser();
174
        
164
 
175
        $request = $this->getRequest();
165
        $request = $this->getRequest();
176
        
166
 
177
        
167
 
178
        if($request->isPost()) {
168
        if ($request->isPost()) {
179
            $form = new  CompanySelfEvaluationFormForm();
169
            $form = new CompanySelfEvaluationFormForm();
180
            $dataPost = $request->getPost()->toArray();
170
            $dataPost = $request->getPost()->toArray();
181
            $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : CompanySelfEvaluationForm::STATUS_INACTIVE;
171
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : CompanySelfEvaluationForm::STATUS_INACTIVE;
182
            
172
 
183
            $form->setData($dataPost);
173
            $form->setData($dataPost);
184
            
174
 
185
            if($form->isValid()) {
175
            if ($form->isValid()) {
Línea 186... Línea 176...
186
                $dataPost = (array) $form->getData();
176
                $dataPost = (array) $form->getData();
187
 
177
 
188
                $hydrator = new ObjectPropertyHydrator();
178
                $hydrator = new ObjectPropertyHydrator();
189
                $companySelfEvaluation = new CompanySelfEvaluationForm();
179
                $companySelfEvaluation = new CompanySelfEvaluationForm();
190
                $hydrator->hydrate($dataPost, $companySelfEvaluation);
180
                $hydrator->hydrate($dataPost, $companySelfEvaluation);
191
                
181
 
192
                if(!$companySelfEvaluation->status) {
182
                if (!$companySelfEvaluation->status) {
193
                    $companySelfEvaluation->status = CompanySelfEvaluationForm::STATUS_INACTIVE;
183
                    $companySelfEvaluation->status = CompanySelfEvaluationForm::STATUS_INACTIVE;
Línea 194... Línea 184...
194
                }
184
                }
195
                $companySelfEvaluation->company_id = $currentCompany->id;
185
                $companySelfEvaluation->company_id = $currentCompany->id;
196
 
186
 
197
                
187
 
198
                $companySelfEvaluationMapper = CompanySelfEvaluationFormMapper::getInstance($this->adapter);
188
                $companySelfEvaluationMapper = CompanySelfEvaluationFormMapper::getInstance($this->adapter);
199
                $result = $companySelfEvaluationMapper->insert($companySelfEvaluation);
189
                $result = $companySelfEvaluationMapper->insert($companySelfEvaluation);
-
 
190
 
Línea -... Línea 191...
-
 
191
                if ($result) {
200
                
192
                    $this->logger->info('Se agrego el tamaño de empresa ' . $companySelfEvaluation->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
201
                if($result) {
-
 
202
                    $this->logger->info('Se agrego el tamaño de empresa ' . $companySelfEvaluation->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
203
                    
-
 
204
                    $record = $companySelfEvaluationMapper->fetchOne($companySelfEvaluation->id);
-
 
205
                    if($record) {
-
 
206
 
-
 
207
                    $data = [
-
 
208
                        'success'   => true,
-
 
209
                        'id' => $record->id,
-
 
210
                        'action_edit' => $this->url()->fromRoute('self-evaluation/forms/edit', ['id' => $record->uuid ]),
-
 
Línea -... Línea 193...
-
 
193
 
-
 
194
                    
-
 
195
                    // Get record by id
-
 
196
                    $record = $companySelfEvaluationMapper->fetchOne($companySelfEvaluation->id);
-
 
197
 
-
 
198
                    if ($record) {
-
 
199
                        $data = [
-
 
200
                            'success' => true,
-
 
201
                            'id' => $record->id,
211
                        'data'   => 'LABEL_RECORD_ADDED'
202
                            'action_edit' => $this->url()->fromRoute('self-evaluation/forms/edit', ['id' => $record->uuid]),
212
                    ];
203
                            'data' => 'LABEL_RECORD_ADDED'
213
 
204
                        ];
214
                }
205
                    }
215
 
206
                    
216
                } else {
-
 
217
                    $data = [
207
                } else {
218
                        'success'   => false,
208
                    $data = [
219
                        'data'      => $companySelfEvaluationMapper->getError()
209
                        'success' => false,
220
                    ];
-
 
221
                    
210
                        'data' => $companySelfEvaluationMapper->getError()
222
                }
211
                    ];
223
                
212
                }
224
                return new JsonModel($data);
213
 
225
                
-
 
226
            } else {
214
                return new JsonModel($data);
227
                $messages = [];
215
            } else {
228
                $form_messages = (array) $form->getMessages();
216
                $messages = [];
229
                foreach($form_messages  as $fieldname => $field_messages)
217
                $form_messages = (array) $form->getMessages();
230
                {
218
                foreach ($form_messages as $fieldname => $field_messages) {
231
                    
219
 
232
                    $messages[$fieldname] = array_values($field_messages);
220
                    $messages[$fieldname] = array_values($field_messages);
233
                }
221
                }
234
                
222
 
235
                return new JsonModel([
-
 
236
                    'success'   => false,
223
                return new JsonModel([
237
                    'data'   => $messages
224
                    'success' => false,
238
                ]);
225
                    'data' => $messages
239
            }
226
                ]);
240
 
227
            }
241
        } else {
228
        } else {
242
            $data = [
229
            $data = [
243
                'success' => false,
230
                'success' => false,
244
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
231
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
245
            ];
232
            ];
246
            
233
 
247
            return new JsonModel($data);
234
            return new JsonModel($data);
248
        }
235
        }
249
        
-
 
250
        return new JsonModel($data);
236
 
251
    }
237
        return new JsonModel($data);
252
    
238
    }
253
    public function editAction()
239
 
254
    {
240
    public function editAction() {
255
        $request = $this->getRequest();
241
        $request = $this->getRequest();
256
        $currentUserPlugin = $this->plugin('currentUserPlugin');
242
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 257... Línea 243...
257
        $currentCompany = $currentUserPlugin->getCompany();
243
        $currentCompany = $currentUserPlugin->getCompany();
258
        $currentUser    = $currentUserPlugin->getUser();
244
        $currentUser = $currentUserPlugin->getUser();
259
        
245
 
260
        $request = $this->getRequest();
246
        $request = $this->getRequest();
261
        $uuid = $this->params()->fromRoute('id');
247
        $uuid = $this->params()->fromRoute('id');
262
 
248
 
263
        
249
 
264
        if(!$uuid) {
250
        if (!$uuid) {
265
            $data = [
251
            $data = [
Línea 266... Línea 252...
266
                'success'   => false,
252
                'success' => false,
267
                'data'   => 'ERROR_INVALID_PARAMETER'
253
                'data' => 'ERROR_INVALID_PARAMETER'
268
            ];
254
            ];
269
            
255
 
270
            return new JsonModel($data);
256
            return new JsonModel($data);
271
        }
257
        }
272
 
258
 
273
        $companySelfEvaluationMapper = CompanySelfEvaluationFormMapper::getInstance($this->adapter);
259
        $companySelfEvaluationMapper = CompanySelfEvaluationFormMapper::getInstance($this->adapter);
274
        $companySelfEvaluation = $companySelfEvaluationMapper->fetchOneByUuid($uuid);
260
        $companySelfEvaluation = $companySelfEvaluationMapper->fetchOneByUuid($uuid);
275
        if(!$companySelfEvaluation) {
261
        if (!$companySelfEvaluation) {
276
            $data = [
262
            $data = [
277
                'success'   => false,
263
                'success' => false,
278
                'data'   => 'ERROR_RECORD_NOT_FOUND'
264
                'data' => 'ERROR_RECORD_NOT_FOUND'
279
            ];
265
            ];
280
            
266
 
281
            return new JsonModel($data);
267
            return new JsonModel($data);
282
        }
268
        }
283
        
269
 
284
        if($companySelfEvaluation->company_id != $currentCompany->id) {
270
        if ($companySelfEvaluation->company_id != $currentCompany->id) {
285
            return new JsonModel([
271
            return new JsonModel([
286
                'success'   => false,
272
                'success' => false,
287
                'data'   => 'ERROR_UNAUTHORIZED'
273
                'data' => 'ERROR_UNAUTHORIZED'
288
            ]);
274
            ]);
289
        }
275
        }
290
        
276
 
291
        
277
 
292
        if($request->isPost()) {
278
        if ($request->isPost()) {
293
            $form = new  CompanySelfEvaluationFormForm();
279
            $form = new CompanySelfEvaluationFormForm();
294
            $dataPost = $request->getPost()->toArray();
280
            $dataPost = $request->getPost()->toArray();
295
            $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : CompanySelfEvaluationForm::STATUS_INACTIVE;
281
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : CompanySelfEvaluationForm::STATUS_INACTIVE;
296
            
282
 
297
            $form->setData($dataPost);
283
            $form->setData($dataPost);
298
            
284
 
299
            if($form->isValid()) {
285
            if ($form->isValid()) {
300
                $dataPost = (array) $form->getData();
286
                $dataPost = (array) $form->getData();
301
                
287
 
302
                $hydrator = new ObjectPropertyHydrator();
288
                $hydrator = new ObjectPropertyHydrator();
303
                $hydrator->hydrate($dataPost, $companySelfEvaluation);
289
                $hydrator->hydrate($dataPost, $companySelfEvaluation);
304
                
290
 
305
                if(!$companySelfEvaluation->status) {
291
                if (!$companySelfEvaluation->status) {
306
                    $companySelfEvaluation->status = CompanySelfEvaluationForm::STATUS_INACTIVE;
292
                    $companySelfEvaluation->status = CompanySelfEvaluationForm::STATUS_INACTIVE;
307
                }
293
                }
308
                
294
 
309
                $result = $companySelfEvaluationMapper->update($companySelfEvaluation);
295
                $result = $companySelfEvaluationMapper->update($companySelfEvaluation);
310
                
296
 
311
                if($result) {
297
                if ($result) {
312
                    $this->logger->info('Se actualizo el tamaño de empresa ' . $companySelfEvaluation->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
298
                    $this->logger->info('Se actualizo el tamaño de empresa ' . $companySelfEvaluation->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
313
                    
299
 
314
                    
300
 
315
                    $data = [
301
                    $data = [
316
                        'success' => true,
302
                        'success' => true,
317
                        'data' => 'LABEL_RECORD_UPDATED'
303
                        'data' => 'LABEL_RECORD_UPDATED'
318
                    ];
304
                    ];
319
                } else {
305
                } else {
320
                    $data = [
-
 
321
                        'success'   => false,
306
                    $data = [
322
                        'data'      => $companySelfEvaluationMapper->getErrno()
307
                        'success' => false,
323
                    ];
308
                        'data' => $companySelfEvaluationMapper->getErrno()
324
                }
309
                    ];
325
                
-
 
326
                return new JsonModel($data);
310
                }
327
                
311
 
328
            } else {
312
                return new JsonModel($data);
329
                $messages = [];
313
            } else {
330
                $form_messages = (array) $form->getMessages();
314
                $messages = [];
331
                foreach($form_messages  as $fieldname => $field_messages)
315
                $form_messages = (array) $form->getMessages();
332
                {
316
                foreach ($form_messages as $fieldname => $field_messages) {
333
                    $messages[$fieldname] = array_values($field_messages);
317
                    $messages[$fieldname] = array_values($field_messages);
334
                }
318
                }
335
                
319
 
336
                return new JsonModel([
320
                return new JsonModel([
337
                    'success'   => false,
321
                    'success' => false,
338
                    'data'   => $messages
322
                    'data' => $messages
339
                ]);
323
                ]);
340
            }
324
            }
341
        } else if ($request->isGet()) {
325
        } else if ($request->isGet()) {
342
            $hydrator = new ObjectPropertyHydrator();
326
            $hydrator = new ObjectPropertyHydrator();
343
            
327
 
344
            $data = [
328
            $data = [
345
                'success' => true,
329
                'success' => true,
346
                'data' => [
330
                'data' => [
347
                    'id' => $companySelfEvaluation->uuid,
-
 
348
                    'name' => $companySelfEvaluation->name,
331
                    'id' => $companySelfEvaluation->uuid,
349
                    'description' => $companySelfEvaluation->description,
332
                    'name' => $companySelfEvaluation->name,
350
                    'text' => $companySelfEvaluation->text,
333
                    'description' => $companySelfEvaluation->description,
351
                    'language' => $companySelfEvaluation->language,
334
                    'text' => $companySelfEvaluation->text,
352
                    'status' => $companySelfEvaluation->status,
335
                    'language' => $companySelfEvaluation->language,
353
                    'content' => $companySelfEvaluation->content ? json_decode($companySelfEvaluation->content) : [],
336
                    'status' => $companySelfEvaluation->status,
354
                    
337
                    'content' => $companySelfEvaluation->content ? json_decode($companySelfEvaluation->content) : [],
355
                ]
338
                ]
356
            ];
339
            ];
357
            
340
 
358
            return new JsonModel($data);
341
            return new JsonModel($data);
359
        } else {
342
        } else {
360
            $data = [
343
            $data = [
361
                'success' => false,
344
                'success' => false,
362
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
345
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
363
            ];
346
            ];
364
            
347
 
365
            return new JsonModel($data);
-
 
366
        }
348
            return new JsonModel($data);
367
        
349
        }
368
        return new JsonModel($data);
350
 
369
    }
351
        return new JsonModel($data);
370
    
352
    }
371
    public function deleteAction()
353
 
372
    {
354
    public function deleteAction() {
373
        $request = $this->getRequest();
355
        $request = $this->getRequest();
374
        $currentUserPlugin = $this->plugin('currentUserPlugin');
356
        $currentUserPlugin = $this->plugin('currentUserPlugin');
375
        $currentCompany = $currentUserPlugin->getCompany();
357
        $currentCompany = $currentUserPlugin->getCompany();
376
        $currentUser    = $currentUserPlugin->getUser();
358
        $currentUser = $currentUserPlugin->getUser();
377
        
359
 
378
        $request = $this->getRequest();
360
        $request = $this->getRequest();
379
        $uuid = $this->params()->fromRoute('id');
361
        $uuid = $this->params()->fromRoute('id');
380
        
362
 
381
        if(!$uuid) {
363
        if (!$uuid) {
382
            $data = [
364
            $data = [
383
                'success'   => false,
365
                'success' => false,
384
                'data'   => 'ERROR_INVALID_PARAMETER'
366
                'data' => 'ERROR_INVALID_PARAMETER'
385
            ];
367
            ];
386
            
368
 
387
            return new JsonModel($data);
369
            return new JsonModel($data);
388
        }
370
        }
389
        
371
 
390
        $companySelfEvaluationMapper = CompanySelfEvaluationFormMapper::getInstance($this->adapter);
372
        $companySelfEvaluationMapper = CompanySelfEvaluationFormMapper::getInstance($this->adapter);
391
        $companySelfEvaluation = $companySelfEvaluationMapper->fetchOneByUuid($uuid);
373
        $companySelfEvaluation = $companySelfEvaluationMapper->fetchOneByUuid($uuid);
392
        if(!$companySelfEvaluation) {
374
        if (!$companySelfEvaluation) {
393
            $data = [
375
            $data = [
394
                'success'   => false,
376
                'success' => false,
395
                'data'   => 'ERROR_RECORD_NOT_FOUND'
377
                'data' => 'ERROR_RECORD_NOT_FOUND'
396
            ];
378
            ];
397
            
379
 
398
            return new JsonModel($data);
380
            return new JsonModel($data);
399
        }
381
        }
Línea 400... Línea 382...
400
        
382
 
401
        if($companySelfEvaluation->company_id != $currentCompany->id) {
383
        if ($companySelfEvaluation->company_id != $currentCompany->id) {
402
            return new JsonModel([
384
            return new JsonModel([
403
                'success'   => false,
385
                'success' => false,
Línea 404... Línea 386...
404
                'data'   => 'ERROR_UNAUTHORIZED'
386
                'data' => 'ERROR_UNAUTHORIZED'
405
            ]);
387
            ]);
406
        }
388
        }
407
 
389
 
408
        
390
 
409
        
391
 
410
        if($request->isPost()) {
392
        if ($request->isPost()) {
411
            
393
 
412
 
394
 
413
            //Falta borrar los test  primeramente
395
            //Falta borrar los test  primeramente
414
            $companySelfEvaluationFormUserMapper = CompanySelfEvaluationFormUserMapper::getInstance($this->adapter);
396
            $companySelfEvaluationFormUserMapper = CompanySelfEvaluationFormUserMapper::getInstance($this->adapter);
415
            $companySelfEvaluationFormUserMapper->deleteAllByFormId($companySelfEvaluation->id);
397
            $companySelfEvaluationFormUserMapper->deleteAllByFormId($companySelfEvaluation->id);
416
            
398
 
417
            
399
 
Línea 418... Línea 400...
418
            $result = $companySelfEvaluationMapper->delete($companySelfEvaluation->id);
400
            $result = $companySelfEvaluationMapper->delete($companySelfEvaluation->id);
419
            if($result) {
401
            if ($result) {
420
                $this->logger->info('Se borro el formulario de auto-evaluación ' . $companySelfEvaluation->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
402
                $this->logger->info('Se borro el formulario de auto-evaluación ' . $companySelfEvaluation->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
421
                
403
 
Línea 422... Línea 404...
422
                $data = [
404
                $data = [
423
                    'success' => true,
405
                    'success' => true,
424
                    'data' => 'LABEL_RECORD_DELETED'
-
 
425
                ];
406
                    'data' => 'LABEL_RECORD_DELETED'
426
            } else {
407
                ];
427
 
408
            } else {
428
                $data = [
409
 
429
                    'success'   => false,
410
                $data = [
430
                    'data'      => $companySelfEvaluationMapper->getError()
411
                    'success' => false,
431
                ];
412
                    'data' => $companySelfEvaluationMapper->getError()
432
 
413
                ];
433
                return new JsonModel($data);
414
 
434
            }
415
                return new JsonModel($data);
435
 
416
            }
-
 
417
        } else {
436
        } else {
418
            $data = [