Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16769 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 16769 Rev 16817
Línea 9... Línea 9...
9
use Laminas\Mvc\Controller\AbstractActionController;
9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Log\LoggerInterface;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\View\Model\ViewModel;
11
use Laminas\View\Model\ViewModel;
12
use Laminas\View\Model\JsonModel;
12
use Laminas\View\Model\JsonModel;
13
use LeadersLinked\Library\Functions;
13
use LeadersLinked\Library\Functions;
14
use LeadersLinked\Mapper\OrganizationalClimateFormMapper;
-
 
15
use LeadersLinked\Form\OrganizationalClimateFormForm;
-
 
16
use LeadersLinked\Model\OrganizationalClimateForm;
-
 
17
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
14
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
-
 
15
use LeadersLinked\Mapper\SurveyFormMapper;
-
 
16
use LeadersLinked\Form\Survey\SurveyFormForm;
-
 
17
use LeadersLinked\Model\SurveyForm;
Línea 18... Línea 18...
18
 
18
 
Línea 19... Línea 19...
19
class OrganizationalClimateFormController extends AbstractActionController {
19
class OrganizationalClimateFormController extends AbstractActionController {
20
 
20
 
Línea 113... Línea 113...
113
 
113
 
114
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
114
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
115
                    $order_direction = 'ASC';
115
                    $order_direction = 'ASC';
Línea 116... Línea 116...
116
                }
116
                }
117
 
117
 
Línea 118... Línea 118...
118
                $organizationalClimateMapper = OrganizationalClimateFormMapper::getInstance($this->adapter);
118
                $surveyMapper = SurveyFormMapper::getInstance($this->adapter);
119
                $paginator = $organizationalClimateMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
119
                $paginator = $surveyMapper->fetchAllDataTableOrganizationClimateByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
Línea 120... Línea 120...
120
 
120
 
Línea 121... Línea 121...
121
                $items = [];
121
                $items = [];
122
                $records = $paginator->getCurrentItems();
122
                $records = $paginator->getCurrentItems();
123
              
123
              
124
                foreach ($records as $record) {
124
                foreach ($records as $record) {
125
                   
125
                   
126
                    $item = [
126
                    $item = [
127
                        'id' => $record->id,
127
                        'id' => $record->id,
128
                        'name' => $record->name,
128
                        'name' => $record->name,
129
                        'description' => $record->description,
129
                        'text' => $record->text,
Línea 144... Línea 144...
144
                        'total' => $paginator->getTotalItemCount(),
144
                        'total' => $paginator->getTotalItemCount(),
145
                    ]
145
                    ]
146
                ]);
146
                ]);
147
            } else {
147
            } else {
Línea 148... Línea 148...
148
 
148
 
Línea 149... Línea 149...
149
                $form = new OrganizationalClimateFormForm($this->adapter, $currentCompany->id);
149
                $form = new SurveyFormForm($this->adapter, $currentCompany->id);
150
 
150
 
151
                $this->layout()->setTemplate('layout/layout-backend');
151
                $this->layout()->setTemplate('layout/layout-backend');
152
                $viewModel = new ViewModel();
152
                $viewModel = new ViewModel();
Línea 161... Línea 161...
161
            ]);
161
            ]);
162
            ;
162
            ;
163
        }
163
        }
164
    }
164
    }
Línea 165... Línea 165...
165
 
165
 
-
 
166
    public function addAction() 
166
    public function addAction() {
167
    {
167
        $request = $this->getRequest();
168
        $request = $this->getRequest();
168
        $currentUserPlugin = $this->plugin('currentUserPlugin');
169
        $currentUserPlugin = $this->plugin('currentUserPlugin');
169
        $currentCompany = $currentUserPlugin->getCompany();
170
        $currentCompany = $currentUserPlugin->getCompany();
Línea 170... Línea 171...
170
        $currentUser = $currentUserPlugin->getUser();
171
        $currentUser = $currentUserPlugin->getUser();
Línea 171... Línea 172...
171
 
172
 
-
 
173
        $request = $this->getRequest();
-
 
174
 
Línea -... Línea 175...
-
 
175
        if ($request->isPost()) {
-
 
176
            $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
-
 
177
            $id = $this->params()->fromRoute('id');
-
 
178
            
-
 
179
            if($id) {
-
 
180
                $surveyForm = $surveyFormMapper->fetchOneByUuid($id);
-
 
181
                if (!$surveyForm) {
-
 
182
                    $data = [
-
 
183
                        'success' => false,
-
 
184
                        'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
185
                    ];
172
        $request = $this->getRequest();
186
                    
-
 
187
                    return new JsonModel($data);
-
 
188
                }
-
 
189
                
-
 
190
                if ($surveyForm ->company_id != $currentCompany->id) {
-
 
191
                    return new JsonModel([
-
 
192
                        'success' => false,
-
 
193
                        'data' => 'ERROR_UNAUTHORIZED'
-
 
194
                    ]);
-
 
195
                }
-
 
196
                
Línea 173... Línea -...
173
 
-
 
174
        if ($request->isPost()) {
-
 
175
            
-
 
176
            $form = new OrganizationalClimateFormForm($this->adapter, $currentCompany->id);
-
 
Línea -... Línea 197...
-
 
197
                
-
 
198
            } else {
-
 
199
                $surveyForm = new SurveyForm();
-
 
200
            }
Línea 177... Línea 201...
177
            
201
            
Línea 178... Línea 202...
178
            $dataPost = $request->getPost()->toArray();
202
            
-
 
203
            $form = new SurveyFormForm($this->adapter, $currentCompany->id);
179
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : OrganizationalClimateForm::STATUS_INACTIVE;
204
            
180
 
205
            $dataPost = $request->getPost()->toArray();
181
          
206
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : SurveyForm::STATUS_INACTIVE;
182
            
-
 
183
 
207
 
Línea -... Línea 208...
-
 
208
            $form->setData($dataPost);
-
 
209
 
-
 
210
            if ($form->isValid()) {
184
            $form->setData($dataPost);
211
               
-
 
212
                $dataPost = (array) $form->getData();
-
 
213
                
185
 
214
                $hydrator = new ObjectPropertyHydrator();
-
 
215
                $hydrator->hydrate($dataPost, $surveyForm);
-
 
216
 
-
 
217
                
186
            if ($form->isValid()) {
218
                
187
                $dataPost = (array) $form->getData();
-
 
188
 
-
 
189
                $hydrator = new ObjectPropertyHydrator();
-
 
190
                $organizationalClimate = new OrganizationalClimateForm();
-
 
191
                $hydrator->hydrate($dataPost, $organizationalClimate);
-
 
Línea 192... Línea 219...
192
 
219
                
193
                if (!$organizationalClimate->status) {
-
 
194
                    $organizationalClimate->status = OrganizationalClimateForm::STATUS_INACTIVE;
220
                if($surveyForm->id) {
195
                }
221
                    $result = $surveyFormMapper->update($surveyForm);
196
                $organizationalClimate->company_id = $currentCompany->id;
-
 
197
 
-
 
198
 
222
                } else {
199
                $organizationalClimateMapper = OrganizationalClimateFormMapper::getInstance($this->adapter);
223
                    $surveyForm->type = SurveyForm::TYPE_ORGANIZATIONAL_CLIMATE;
200
                $result = $organizationalClimateMapper->insert($organizationalClimate);
-
 
201
 
-
 
202
                if ($result) {
224
                    $surveyForm->company_id = $currentCompany->id;
203
                    $this->logger->info('Se agrego el formulario' . $organizationalClimate->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
204
 
-
 
205
                    // Get record by id
225
                    $result = $surveyFormMapper->insert($surveyForm);
-
 
226
                    
206
                    $record = $organizationalClimateMapper->fetchOne($organizationalClimate->id);
227
                }
207
 
-
 
-
 
228
 
208
                    if ($record) {
229
                if ($result) {
-
 
230
                    
209
 
231
                    if($surveyForm->uuid) {
210
                        $data = [
-
 
-
 
232
                        $message = 'LABEL_RECORD_UPDATED';
211
                            'success' => true,
233
                        
-
 
234
                        $this->logger->info('Se actualizo el formulario' . $surveyForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
235
                    } else {
-
 
236
                        $message = 'LABEL_RECORD_ADDED';
-
 
237
                        
-
 
238
                        
-
 
239
                        $this->logger->info('Se agrego el formulario' . $surveyForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
240
                    
-
 
241
                        $surveyForm = $surveyFormMapper->fetchOne($surveyForm->id);
212
                            'id' => $record->id,
242
                    
213
                            'data' => 'LABEL_RECORD_ADDED'
243
                    }
214
                        ];
244
                    
215
                    } else {
245
                    $data = [
216
 
246
                        'success' => true,
217
                        $data = [
247
                        'data' => [
Línea 218... Línea 248...
218
                            'success' => false,
248
                            'message' => $message,
219
                            'data' => 'ERROR_RECORD_NOT_FOUND'
249
                            'action' => $this->url()->fromRoute('organizational-climate/form/add', ['id'=> $surveyForm->uuid]),
Línea 250... Línea 280...
250
        }
280
        }
Línea 251... Línea 281...
251
 
281
 
252
        return new JsonModel($data);
282
        return new JsonModel($data);
Línea 253... Línea 283...
253
    }
283
    }
-
 
284
 
254
 
285
    public function editAction() 
255
    public function editAction() {
286
    {
256
        $request = $this->getRequest();
287
        $request = $this->getRequest();
257
        $currentUserPlugin = $this->plugin('currentUserPlugin');
288
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 269... Línea 300...
269
            ];
300
            ];
Línea 270... Línea 301...
270
 
301
 
271
            return new JsonModel($data);
302
            return new JsonModel($data);
Línea 272... Línea 303...
272
        }
303
        }
273
 
304
 
Línea 274... Línea 305...
274
        $organizationalClimateMapper = OrganizationalClimateFormMapper::getInstance($this->adapter);
305
        $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
275
        $organizationalClimate = $organizationalClimateMapper->fetchOneByUuid($uuid);
306
        $surveyForm = $surveyFormMapper->fetchOneByUuid($uuid);
276
       
307
       
277
        if (!$organizationalClimate) {
308
        if (!$surveyForm) {
278
            $data = [
309
            $data = [
Línea 279... Línea 310...
279
                'success' => false,
310
                'success' => false,
280
                'data' => 'ERROR_RECORD_NOT_FOUND'
311
                'data' => 'ERROR_RECORD_NOT_FOUND'
Línea 281... Línea 312...
281
            ];
312
            ];
282
 
313
 
283
            return new JsonModel($data);
314
            return new JsonModel($data);
284
        }
315
        }
285
 
316
 
286
        if ($organizationalClimate->company_id != $currentCompany->id) {
317
        if ($surveyForm ->company_id != $currentCompany->id) {
Línea 287... Línea 318...
287
            return new JsonModel([
318
            return new JsonModel([
288
                'success' => false,
319
                'success' => false,
289
                'data' => 'ERROR_UNAUTHORIZED'
320
                'data' => 'ERROR_UNAUTHORIZED'
290
            ]);
321
            ]);
Línea 291... Línea 322...
291
        }
322
        }
Línea 292... Línea 323...
292
 
323
 
293
 
324
 
Línea 294... Línea 325...
294
        if ($request->isPost()) {
325
        if ($request->isPost()) {
295
            $form = new OrganizationalClimateFormForm($this->adapter, $currentCompany->id);
326
            $form = new SurveyFormForm($this->adapter, $currentCompany->id);
Línea 296... Línea -...
296
            $dataPost = $request->getPost()->toArray();
-
 
297
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : OrganizationalClimateForm::STATUS_INACTIVE;
-
 
298
 
-
 
Línea 299... Línea 327...
299
            $form->setData($dataPost);
327
            $dataPost = $request->getPost()->toArray();
Línea 300... Línea 328...
300
 
328
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : SurveyForm::STATUS_INACTIVE;
301
            if ($form->isValid()) {
329
 
302
                $dataPost = (array) $form->getData();
330
            $form->setData($dataPost);
303
 
331
 
-
 
332
            if ($form->isValid()) {
304
                $hydrator = new ObjectPropertyHydrator();
333
                $dataPost = (array) $form->getData();
305
                $hydrator->hydrate($dataPost, $organizationalClimate);
334
 
306
 
335
                $hydrator = new ObjectPropertyHydrator();
307
                if (!$organizationalClimate->status) {
336
                $hydrator->hydrate($dataPost, $surveyForm);
308
                    $organizationalClimate->status = OrganizationalClimateForm::STATUS_INACTIVE;
337
 
309
                }
338
 
310
 
339
                $result = $surveyFormMapper->update($surveyForm);
311
                $result = $organizationalClimateMapper->update($organizationalClimate);
340
 
312
 
341
                if ($result) {
313
                if ($result) {
342
                    $this->logger->info('Se edito el formulario : ' . $surveyForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
Línea 314... Línea 343...
314
                    $this->logger->info('Se edito el formulario ' . $organizationalClimate->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
343
                    $data = [
315
                    $data = [
344
                        'success' => true,
Línea 337... Línea 366...
337
                    'success' => false,
366
                    'success' => false,
338
                    'data' => $messages
367
                    'data' => $messages
339
                ]);
368
                ]);
340
            }
369
            }
341
        } else if ($request->isGet()) {
370
        } else if ($request->isGet()) {
342
            $hydrator = new ObjectPropertyHydrator();
-
 
Línea 343... Línea 371...
343
 
371
 
344
            $data = [
372
            $data = [
345
                'success' => true,
373
                'success' => true,
346
                'data' => [
-
 
347
                    'id' => $organizationalClimate->uuid,
374
                'data' => [
348
                    'name' => $organizationalClimate->name,
-
 
349
                    'description' => $organizationalClimate->description,
375
                    'name'          => $surveyForm->name,
350
                    'text' => $organizationalClimate->text,
376
                    'text'          => $surveyForm->text,
351
                    'status' => $organizationalClimate->status,
377
                    'status'        => $surveyForm->status,
352
                    'content' => $organizationalClimate->content ? json_decode($organizationalClimate->content) : [],
378
                    'content'       => $surveyForm->content ? json_decode($surveyForm->content, true) : [],
353
                ]
379
                ]
Línea 354... Línea 380...
354
            ];
380
            ];
355
 
381
 
Línea 364... Línea 390...
364
        }
390
        }
Línea 365... Línea 391...
365
 
391
 
366
        return new JsonModel($data);
392
        return new JsonModel($data);
Línea 367... Línea 393...
367
    }
393
    }
-
 
394
 
368
 
395
    public function deleteAction() 
369
    public function deleteAction() {
396
    {
370
        $request = $this->getRequest();
397
        $request = $this->getRequest();
371
        $currentUserPlugin = $this->plugin('currentUserPlugin');
398
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 382... Línea 409...
382
            ];
409
            ];
Línea 383... Línea 410...
383
 
410
 
384
            return new JsonModel($data);
411
            return new JsonModel($data);
Línea 385... Línea 412...
385
        }
412
        }
386
 
413
 
387
        $organizationalClimateMapper = OrganizationalClimateFormMapper::getInstance($this->adapter);
414
        $surveyFormMapper = SurveyFormMapper::getInstance($this->adapter);
388
        $organizationalClimate = $organizationalClimateMapper->fetchOneByUuid($uuid);
415
        $surveyForm = $surveyFormMapper->fetchOneByUuid($uuid);
389
        if (!$organizationalClimate) {
416
        if (!$surveyForm) {
390
            $data = [
417
            $data = [
391
                'success' => false,
418
                'success' => false,
Línea 392... Línea 419...
392
                'data' => 'ERROR_RECORD_NOT_FOUND'
419
                'data' => 'ERROR_RECORD_NOT_FOUND'
393
            ];
420
            ];
Línea 394... Línea 421...
394
 
421
 
395
            return new JsonModel($data);
422
            return new JsonModel($data);
396
        }
423
        }
397
 
424
 
398
        if ($organizationalClimate->company_id != $currentCompany->id) {
425
        if ($surveyForm->company_id != $currentCompany->id) {
399
            return new JsonModel([
426
            return new JsonModel([
Línea 400... Línea 427...
400
                'success' => false,
427
                'success' => false,
Línea 401... Línea 428...
401
                'data' => 'ERROR_UNAUTHORIZED'
428
                'data' => 'ERROR_UNAUTHORIZED'
402
            ]);
429
            ]);
403
        }
430
        }
Línea 404... Línea 431...
404
 
431
 
405
        if ($request->isPost()) {
432
        if ($request->isPost()) {
406
 
433
 
407
            $result = $organizationalClimateMapper->delete($organizationalClimate->id);
434
            $result = $surveyFormMapper->delete($surveyForm->id);
408
            if ($result) {
435
            if ($result) {
Línea 409... Línea 436...
409
                $this->logger->info('Se borro el formulario ' . $organizationalClimate->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
436
                $this->logger->info('Se borro el formulario : ' . $surveyForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
410
 
437
 
411
                $data = [
438
                $data = [
412
                    'success' => true,
439
                    'success' => true,
Línea 413... Línea 440...
413
                    'data' => 'LABEL_RECORD_DELETED'
440
                    'data' => 'LABEL_RECORD_DELETED'
414
                ];
441
                ];
415
            } else {
442
            } else {