Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 67 Rev 1320
Línea 14... Línea 14...
14
use LeadersLinked\Mapper\PositionMapper;
14
use LeadersLinked\Mapper\PositionMapper;
15
use LeadersLinked\Model\Position;
15
use LeadersLinked\Model\Position;
16
use LeadersLinked\Form\PositionForm;
16
use LeadersLinked\Form\PositionForm;
17
use LeadersLinked\Mapper\UserMapper;
17
use LeadersLinked\Mapper\UserMapper;
18
use LeadersLinked\Mapper\JobDescriptionMapper;
18
use LeadersLinked\Mapper\JobDescriptionMapper;
-
 
19
use LeadersLinked\Mapper\JobDescriptionSubordinateMapper;
-
 
20
use LeadersLinked\Mapper\PositionSubordinateMapper;
Línea 19... Línea 21...
19
 
21
 
20
 
22
 
21
class PositionController extends AbstractActionController
23
class PositionController extends AbstractActionController
Línea 354... Línea 356...
354
            $hydrator = new ObjectPropertyHydrator();
356
            $hydrator = new ObjectPropertyHydrator();
Línea 355... Línea 357...
355
            
357
            
356
            $data = $hydrator->extract($position);
358
            $data = $hydrator->extract($position);
357
            $data['user_id'] = $user->uuid;
359
            $data['user_id'] = $user->uuid;
-
 
360
            $data['job_description_id'] = $jobDescription->uuid;
-
 
361
            $data['users'] = [];
-
 
362
            $data['subordinates'] = [];
-
 
363
            
-
 
364
            $ids = [];
-
 
365
            
-
 
366
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
367
           
-
 
368
            $positionSubordinateMapper = PositionSubordinateMapper::getInstance($this->adapter);
-
 
369
            $subordinates = $positionSubordinateMapper->fetchAllByPositionId($position->id);
-
 
370
            
-
 
371
            foreach($subordinates as $subordinate)
-
 
372
            {
-
 
373
                $user = $userMapper->fetchOne($subordinate->user_id);
-
 
374
                if($user) {
-
 
375
                    array_push($data['subordinates'], $user->uuid);
-
 
376
                }
-
 
377
            }
-
 
378
            
-
 
379
            
-
 
380
            $jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
-
 
381
            $jobDescriptionSubordinates = $jobDescriptionSubordinateMapper->fetchAllByJobDescriptionIdTopLevel($jobDescription->id);
-
 
382
            
-
 
383
            foreach($jobDescriptionSubordinates as $jobDescriptionSubordinate)
-
 
384
            {
-
 
385
                $positions = $positionMapper->fetchAllByJobDescriptionIdAndCompanyId($jobDescriptionSubordinate->job_description_id_low_level, $currentCompany->id);
-
 
386
                
-
 
387
                foreach($positions as $position)
-
 
388
                {
-
 
389
                    if(!in_array($position->user_id, $ids)) {
-
 
390
                        array_push($ids, $position->user_id);
-
 
391
                    }
-
 
392
                }
-
 
393
                
-
 
394
            }
-
 
395
            
-
 
396
            
-
 
397
            
-
 
398
            if($ids) {
-
 
399
                $users = $userMapper->fetchAllByIds($ids);
-
 
400
                foreach($users as $user)
-
 
401
                {
-
 
402
                    array_push($data['users'], [
-
 
403
                        'uuid' => $user->uuid, 
-
 
404
                        'name' => trim(trim($user->first_name) . ' ' . trim($user->last_name)) . ' (' . trim($user->email) . ')',
-
 
405
                    ]);
-
 
406
                
-
 
407
                }
-
 
408
            }
Línea 358... Línea 409...
358
            $data['job_description_id'] = $jobDescription->uuid;
409
            
359
            
410
            
360
            $response = [
411
            $response = [
361
                'success' => true,
412
                'success' => true,
Línea 446... Línea 497...
446
        }
497
        }
Línea 447... Línea 498...
447
        
498
        
448
        return new JsonModel($data);
499
        return new JsonModel($data);
Línea -... Línea 500...
-
 
500
    }
-
 
501
    
-
 
502
    public function subordinatesAction()
-
 
503
    {
-
 
504
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
505
        $currentUser = $currentUserPlugin->getUser();
-
 
506
        $currentCompany = $currentUserPlugin->getCompany();
-
 
507
        
-
 
508
        $request = $this->getRequest();
-
 
509
        $uuid = $this->params()->fromRoute('job_description_id');
-
 
510
        
-
 
511
        
-
 
512
        if(!$uuid) {
-
 
513
            $data = [
-
 
514
                'success'   => false,
-
 
515
                'data'   => 'ERROR_INVALID_PARAMETER'
-
 
516
            ];
-
 
517
            
-
 
518
            return new JsonModel($data);
-
 
519
        }
-
 
520
        
-
 
521
        $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
-
 
522
        $jobDescription = $jobDescriptionMapper->fetchOneByUuid($uuid);
-
 
523
        if(!$jobDescription) {
-
 
524
            $data = [
-
 
525
                'success'   => false,
-
 
526
                'data'   => 'ERROR_RECORD_NOT_FOUND'
-
 
527
            ];
-
 
528
            
-
 
529
            return new JsonModel($data);
-
 
530
        }
-
 
531
        
-
 
532
        
-
 
533
      
-
 
534
        
-
 
535
        if($jobDescription->company_id != $currentCompany->id) {
-
 
536
            $data = [
-
 
537
                'success'   => false,
-
 
538
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
539
            ];
-
 
540
            
-
 
541
            return new JsonModel($data);
-
 
542
        }
-
 
543
        
-
 
544
 
-
 
545
        if ($request->isGet()) {
-
 
546
            $ids = [];
-
 
547
            
-
 
548
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
549
            $positionMapper = PositionMapper::getInstance($this->adapter);
-
 
550
            
-
 
551
            
-
 
552
            $jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
-
 
553
            $jobDescriptionSubordinates = $jobDescriptionSubordinateMapper->fetchAllByJobDescriptionIdTopLevel($jobDescription->id);
-
 
554
            
-
 
555
            foreach($jobDescriptionSubordinates as $jobDescriptionSubordinate)
-
 
556
            {
-
 
557
                $positions = $positionMapper->fetchAllByJobDescriptionIdAndCompanyId($jobDescriptionSubordinate->job_description_id_low_level, $currentCompany->id);
-
 
558
                
-
 
559
                foreach($positions as $position)
-
 
560
                {
-
 
561
                    if(!in_array($position->user_id, $ids)) {
-
 
562
                        array_push($ids, $position->user_id);
-
 
563
                    }
-
 
564
                }
-
 
565
                
-
 
566
            }
-
 
567
            
-
 
568
            $data = [];
-
 
569
            
-
 
570
            if($ids) {
-
 
571
                $users = $userMapper->fetchAllByIds($ids);
-
 
572
                foreach($users as $user) 
-
 
573
                {
-
 
574
                    array_push($data, [
-
 
575
                        'uuid' => $user->uuid,
-
 
576
                        'name' => trim(trim($user->first_name) . ' ' . trim($user->last_name)) . ' (' . trim($user->email) . ')',
-
 
577
                    ]);
-
 
578
                }
-
 
579
            }
-
 
580
            
-
 
581
            
-
 
582
            $response = [
-
 
583
                'success' => true,
-
 
584
                'data' => $data
-
 
585
            ];
-
 
586
            
-
 
587
            return new JsonModel($response);
-
 
588
        } else {
-
 
589
            $data = [
-
 
590
                'success' => false,
-
 
591
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
592
            ];
-
 
593
            
-
 
594
 
-
 
595
        }
-
 
596
        
-
 
597
        return new JsonModel($data);
Línea 449... Línea 598...
449
    }
598
    }