Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 1 Rev 28
Línea 13... Línea 13...
13
use LeadersLinked\Library\Functions;
13
use LeadersLinked\Library\Functions;
14
use LeadersLinked\Mapper\CompetencyMapper;
14
use LeadersLinked\Mapper\CompetencyMapper;
15
use LeadersLinked\Model\Competency;
15
use LeadersLinked\Model\Competency;
16
use LeadersLinked\Form\CompetencyForm;
16
use LeadersLinked\Form\CompetencyForm;
17
use LeadersLinked\Mapper\CompetencyTypeMapper;
17
use LeadersLinked\Mapper\CompetencyTypeMapper;
-
 
18
use LeadersLinked\Model\CompetencyType;
Línea 18... Línea 19...
18
 
19
 
19
 
20
 
20
class CompetencyController extends AbstractActionController
21
class CompetencyController extends AbstractActionController
Línea 62... Línea 63...
62
        
63
        
Línea 63... Línea 64...
63
    }
64
    }
64
    
65
    
65
    public function indexAction()
-
 
-
 
66
    public function indexAction()
-
 
67
    {
-
 
68
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 66... Línea 69...
66
    {
69
        $currentUser = $currentUserPlugin->getUser();
Línea 67... Línea 70...
67
        
70
        $currentCompany = $currentUserPlugin->getCompany();
Línea 108... Línea 111...
108
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
111
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
109
                    $order_direction = 'ASC';
112
                    $order_direction = 'ASC';
110
                }
113
                }
Línea 111... Línea 114...
111
    
114
    
112
                $competenceMapper = CompetencyMapper::getInstance($this->adapter);
-
 
Línea -... Línea 115...
-
 
115
                $competenceMapper = CompetencyMapper::getInstance($this->adapter);
-
 
116
                
-
 
117
                
-
 
118
                
-
 
119
                if($currentCompany) {
-
 
120
                    $paginator = $competenceMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
-
 
121
                } else {
113
                $paginator = $competenceMapper->fetchAllDataTable($search, $page, $records_x_page, $order_field, $order_direction);
122
                    $paginator = $competenceMapper->fetchAllDataTable($search, $page, $records_x_page, $order_field, $order_direction);
114
                
123
                }
115
                $items = [];
124
                $items = [];
116
                $records = $paginator->getCurrentItems();
125
                $records = $paginator->getCurrentItems();
117
                foreach($records as $record)
126
                foreach($records as $record)
Línea 158... Línea 167...
158
    
167
    
159
    public function addAction()
168
    public function addAction()
160
    {
169
    {
161
        $currentUserPlugin = $this->plugin('currentUserPlugin');
170
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
171
        $currentUser = $currentUserPlugin->getUser();
Línea 162... Línea 172...
162
        $currentUser = $currentUserPlugin->getUser();
172
        $currentCompany = $currentUserPlugin->getCompany();
Línea 163... Línea 173...
163
        
173
        
Línea 175... Línea 185...
175
                $dataPost['status'] = $dataPost['status'] ? $dataPost['status'] : Competency::STATUS_INACTIVE;
185
                $dataPost['status'] = $dataPost['status'] ? $dataPost['status'] : Competency::STATUS_INACTIVE;
Línea 176... Línea 186...
176
                
186
                
177
                $competenceTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
187
                $competenceTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
178
                $competenceType = $competenceTypeMapper->fetchOneByUuid($dataPost['competency_type_id']);
188
                $competenceType = $competenceTypeMapper->fetchOneByUuid($dataPost['competency_type_id']);
-
 
189
                $dataPost['competency_type_id'] = $competenceType->id;
-
 
190
                
Línea 179... Línea 191...
179
                $dataPost['competency_type_id'] = $competenceType->id;
191
 
180
 
192
 
-
 
193
                $hydrator = new ObjectPropertyHydrator();
181
                $hydrator = new ObjectPropertyHydrator();
194
                $competence = new Competency();
-
 
195
                
-
 
196
                $hydrator->hydrate($dataPost, $competence);
-
 
197
                
-
 
198
                if($currentCompany) {
-
 
199
                    $competence->company_id = $currentCompany->id;
Línea 182... Línea 200...
182
                $competenceType = new Competency();
200
                }
183
                $hydrator->hydrate($dataPost, $competenceType);
201
                
-
 
202
 
Línea 184... Línea 203...
184
 
203
                $competenceMapper = CompetencyMapper::getInstance($this->adapter);
185
                $competenceMapper = CompetencyMapper::getInstance($this->adapter);
204
                $result = $competenceMapper->insert($competence);
Línea 186... Línea 205...
186
                $result = $competenceMapper->insert($competenceType);
205
                
187
                
206
                
188
                if($result) {
207
                if($result) {
189
                    $this->logger->info('Se agrego la competencia ' . $competenceType->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
208
                    $this->logger->info('Se agrego la competencia ' . $competence->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
Línea 231... Línea 250...
231
    
250
    
232
    public function editAction()
251
    public function editAction()
233
    {
252
    {
234
        $currentUserPlugin = $this->plugin('currentUserPlugin');
253
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
254
        $currentUser = $currentUserPlugin->getUser();
Línea 235... Línea 255...
235
        $currentUser = $currentUserPlugin->getUser();
255
        $currentCompany = $currentUserPlugin->getCompany();
236
        
256
        
Línea 256... Línea 276...
256
            ];
276
            ];
Línea 257... Línea 277...
257
            
277
            
258
            return new JsonModel($data);
278
            return new JsonModel($data);
Línea -... Línea 279...
-
 
279
        }
-
 
280
        
-
 
281
        if($currentCompany) {
-
 
282
            if($competence->company_id != $currentCompany->id) {
-
 
283
                $data = [
-
 
284
                    'success'   => false,
-
 
285
                    'data'   => 'ERROR_UNAUTHORIZED'
-
 
286
                ];
-
 
287
                
-
 
288
                return new JsonModel($data);
-
 
289
            }
-
 
290
        } else {
-
 
291
            if($competence->company_id) {
-
 
292
                $data = [
-
 
293
                    'success'   => false,
-
 
294
                    'data'   => 'ERROR_UNAUTHORIZED'
-
 
295
                ];
-
 
296
                
-
 
297
                return new JsonModel($data);
-
 
298
            }
259
        }
299
        }
260
        
300
        
261
        if($request->isPost()) {
301
        if($request->isPost()) {
Línea 272... Línea 312...
272
                $competenceTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
312
                $competenceTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
273
                $competenceType = $competenceTypeMapper->fetchOneByUuid($dataPost['competency_type_id']);
313
                $competenceType = $competenceTypeMapper->fetchOneByUuid($dataPost['competency_type_id']);
274
                $dataPost['competency_type_id'] = $competenceType->id;
314
                $dataPost['competency_type_id'] = $competenceType->id;
Línea 275... Línea 315...
275
 
315
 
276
                $hydrator = new ObjectPropertyHydrator();
316
                $hydrator = new ObjectPropertyHydrator();
-
 
317
                $hydrator->hydrate($dataPost, $competence);
277
                $hydrator->hydrate($dataPost, $competenceType);
318
 
Línea 278... Línea 319...
278
                $result = $competenceMapper->update($competenceType);
319
                $result = $competenceMapper->update($competence);
279
                
320
                
Línea 280... Línea 321...
280
                if($result) {
321
                if($result) {
Línea 335... Línea 376...
335
    
376
    
336
    public function deleteAction()
377
    public function deleteAction()
337
    {
378
    {
338
        $currentUserPlugin = $this->plugin('currentUserPlugin');
379
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
380
        $currentUser = $currentUserPlugin->getUser();
Línea 339... Línea 381...
339
        $currentUser = $currentUserPlugin->getUser();
381
        $currentCompany = $currentUserPlugin->getCompany();
340
        
382
        
Línea 341... Línea 383...
341
        $request = $this->getRequest();
383
        $request = $this->getRequest();
Línea 350... Línea 392...
350
            return new JsonModel($data);
392
            return new JsonModel($data);
351
        }
393
        }
Línea 352... Línea 394...
352
        
394
        
353
                
395
                
354
        $competenceMapper = CompetencyMapper::getInstance($this->adapter);
396
        $competenceMapper = CompetencyMapper::getInstance($this->adapter);
355
        $competenceType = $competenceMapper->fetchOneByUuid($uuid);
397
        $competence = $competenceMapper->fetchOneByUuid($uuid);
356
        if(!$competenceType) {
398
        if(!$competence) {
357
            $data = [
399
            $data = [
358
                'success'   => false,
400
                'success'   => false,
Línea 359... Línea 401...
359
                'data'   => 'ERROR_RECORD_NOT_FOUND'
401
                'data'   => 'ERROR_RECORD_NOT_FOUND'
360
            ];
402
            ];
Línea -... Línea 403...
-
 
403
            
-
 
404
            return new JsonModel($data);
-
 
405
        }
-
 
406
        
-
 
407
        if($currentCompany) {
-
 
408
            if($competence->company_id != $currentCompany->id) {
-
 
409
                $data = [
-
 
410
                    'success'   => false,
-
 
411
                    'data'   => 'ERROR_UNAUTHORIZED'
-
 
412
                ];
-
 
413
                
-
 
414
                return new JsonModel($data);
-
 
415
            }
-
 
416
        } else {
-
 
417
            if($competence->company_id) {
-
 
418
                $data = [
-
 
419
                    'success'   => false,
-
 
420
                    'data'   => 'ERROR_UNAUTHORIZED'
-
 
421
                ];
-
 
422
                
361
            
423
                return new JsonModel($data);
362
            return new JsonModel($data);
424
            }
363
        }
425
        }
364
        
426
        
Línea 365... Línea 427...
365
        if($request->isPost()) {
427
        if($request->isPost()) {
366
            $result = $competenceMapper->delete($competenceType);
428
            $result = $competenceMapper->delete($competence);
367
            if($result) {
429
            if($result) {
368
                $this->logger->info('Se borro la competencia ' . $competenceType->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
430
                $this->logger->info('Se borro la competencia ' . $competence->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
Línea 384... Línea 446...
384
        } else {
446
        } else {
385
            $data = [
447
            $data = [
386
                'success' => false,
448
                'success' => false,
387
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
449
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
388
            ];
450
            ];
-
 
451
            
-
 
452
            return new JsonModel($data);
-
 
453
        }
-
 
454
        
-
 
455
        return new JsonModel($data);
-
 
456
    }
-
 
457
    
-
 
458
    public function importAction()
-
 
459
    {
-
 
460
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
461
        $currentUser = $currentUserPlugin->getUser();
-
 
462
        $currentCompany = $currentUserPlugin->getCompany();
-
 
463
        
-
 
464
        if(!$currentCompany) {
-
 
465
            $data = [
-
 
466
                'success' => false,
-
 
467
                'data' => 'ERROR_UNAUTHORIZED'
-
 
468
            ];
-
 
469
            
-
 
470
            return new JsonModel($data);
-
 
471
        }
-
 
472
        
-
 
473
        $request = $this->getRequest();
-
 
474
        
-
 
475
        if($request->isPost()) {
-
 
476
            
-
 
477
            $competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
-
 
478
            
-
 
479
            $competenceMapper = CompetencyMapper::getInstance($this->adapter);
-
 
480
            $competenciesDefault = $competenceMapper->fetchAllByDefault();
-
 
481
            
-
 
482
            $new_records = 0;
-
 
483
            foreach($competenciesDefault as $competencyDefault)
-
 
484
            {
-
 
485
 
-
 
486
                if($competencyDefault->status == Competency::STATUS_INACTIVE) {
-
 
487
                    continue;
-
 
488
                }
-
 
489
                
-
 
490
                $competency = $competenceMapper->fetchOneByCompanyIdAndCompetencyIdDefault($currentCompany->id, $competencyDefault->id);
-
 
491
                if(!$competency) {
-
 
492
                    
-
 
493
                    
-
 
494
                    $competencyType = $competencyTypeMapper->fetchOneByCompanyId($currentCompany->id, $competencyDefault->competency_type_id);
-
 
495
                    if(!$competencyType) {
-
 
496
                        
-
 
497
                        
-
 
498
                        $competencyTypeDefault = $competencyTypeMapper->fetchOne($competencyDefault->competency_type_id);
-
 
499
                        if(!$competencyTypeDefault) {
-
 
500
                            continue;
-
 
501
                        }
-
 
502
                        
-
 
503
                        $competencyType = new CompetencyType();
-
 
504
                        $competencyType->company_id = $currentCompany->id;
-
 
505
                        $competencyType->competency_type_id_default = $competencyTypeDefault->id;
-
 
506
                        $competencyType->description = $competencyTypeDefault->description;
-
 
507
                        $competencyType->name = $competencyTypeDefault->name;
-
 
508
                        $competencyType->status = CompetencyType::STATUS_ACTIVE;
-
 
509
                        
-
 
510
                        
-
 
511
                        if(!$competencyTypeMapper->insert($competencyType)) {
-
 
512
                            
-
 
513
                            $data = [
-
 
514
                                'success' => false,
-
 
515
                                'data' => 'ERROR_CANT_ADD_COMPETENCY_TYPE'
-
 
516
                            ];
-
 
517
                            
-
 
518
                            return new JsonModel($data);
-
 
519
                            
-
 
520
                            
-
 
521
                        } 
-
 
522
                        
-
 
523
                    }
-
 
524
                    
-
 
525
                    
-
 
526
                    $competency = new Competency();
-
 
527
                    $competency->competency_id_default = $competencyDefault->id;
-
 
528
                    $competency->behaviors = $competencyDefault->behaviors;
-
 
529
                    $competency->company_id = $currentCompany->id;
-
 
530
                    $competency->competency_type_id = $competencyType->id;
-
 
531
                    $competency->description = $competencyDefault->description;
-
 
532
                    $competency->name = $competencyDefault->name;
-
 
533
                    $competency->status = Competency::STATUS_ACTIVE;
-
 
534
                    
-
 
535
                    
-
 
536
                    
-
 
537
                    if($competenceMapper->insert($competency)) {
-
 
538
                        $new_records++;
-
 
539
                    } else {
-
 
540
                        $data = [
-
 
541
                            'success' => false,
-
 
542
                            'data' => 'ERROR_CANT ADD THE COMPETENCY'
-
 
543
                        ];
-
 
544
                        
-
 
545
                        return new JsonModel($data);
-
 
546
                    }
-
 
547
 
-
 
548
                }
-
 
549
            }
-
 
550
            
-
 
551
            if($new_records) {
-
 
552
                
-
 
553
                if(1 == $new_records) {
-
 
554
                    $data = [
-
 
555
                        'success' => true,
-
 
556
                        'data' => 'LABEL_1_COMPETENCY_IMPORTED'
-
 
557
                    ];
-
 
558
                    
-
 
559
                    return new JsonModel($data);
-
 
560
                } else {
-
 
561
                    $data = [
-
 
562
                        'success' => true,
-
 
563
                        'data' =>  $new_records . ' LABEL_MULTI_COMPETENCIES_IMPORTED'
-
 
564
                    ];
-
 
565
                    
-
 
566
                    return new JsonModel($data);
-
 
567
                }
-
 
568
                
-
 
569
            } else {
-
 
570
                $data = [
-
 
571
                    'success' => true,
-
 
572
                    'data' => 'LABEL_NO_COMPETENCY_IMPORTED'
-
 
573
                ];
-
 
574
                
-
 
575
                return new JsonModel($data);
-
 
576
            }
-
 
577
            
-
 
578
            
-
 
579
            
-
 
580
            
-
 
581
        } else {
-
 
582
            $data = [
-
 
583
                'success' => false,
-
 
584
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
585
            ];
Línea 389... Línea 586...
389
            
586
            
390
            return new JsonModel($data);
587
            return new JsonModel($data);
Línea 391... Línea 588...
391
        }
588
        }