Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 16769 Rev 16797
Línea 19... Línea 19...
19
use LeadersLinked\Form\KnowledgeArea\KnowledgeAreaCategoryUserForm;
19
use LeadersLinked\Form\KnowledgeArea\KnowledgeAreaCategoryUserForm;
20
use LeadersLinked\Mapper\QueryMapper;
20
use LeadersLinked\Mapper\QueryMapper;
21
use Laminas\Paginator\Adapter\DbSelect;
21
use Laminas\Paginator\Adapter\DbSelect;
22
use Laminas\Paginator\Paginator;
22
use Laminas\Paginator\Paginator;
23
use LeadersLinked\Model\KnowledgeAreaCategoryUser;
23
use LeadersLinked\Model\KnowledgeAreaCategoryUser;
-
 
24
use LeadersLinked\Model\User;
-
 
25
use LeadersLinked\Model\Company;
-
 
26
use LeadersLinked\Mapper\JobDescriptionMapper;
-
 
27
use LeadersLinked\Mapper\KnowledgeAreaCategoryJobDescriptionMapper;
-
 
28
use LeadersLinked\Model\KnowledgeAreaCategoryJobDescription;
Línea 24... Línea 29...
24
 
29
 
Línea 25... Línea 30...
25
 
30
 
Línea 113... Línea 118...
113
                        'data' => [
118
                        'data' => [
114
                            'total' => 0,
119
                            'total' => 0,
115
                            'items' => [],
120
                            'items' => [],
116
                            'link_add' => '',
121
                            'link_add' => '',
117
                            'link_upload' => '',
122
                            'link_upload' => '',
-
 
123
                            'link_jobs_description' => '', 
-
 
124
                            'roles' => [],
-
 
125
                            'jobs_description' =>  [],
118
                        ]
126
                        ]
119
                    ]);
127
                    ]);
Línea 120... Línea 128...
120
                    
128
                    
Línea 165... Línea 173...
165
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
173
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
166
                $allowAdd = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/add');
174
                $allowAdd = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/add');
167
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/edit');
175
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/edit');
168
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/delete');
176
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/delete');
169
                $allowUpload = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/upload');
177
                $allowUpload = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/upload');
-
 
178
                $allowJobsDescription = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/jobs-description');
Línea 170... Línea 179...
170
                
179
                
Línea 171... Línea 180...
171
              
180
              
Línea 250... Línea 259...
250
                        KnowledgeAreaCategoryUser::ROLE_EDITOR => 'LABEL_EDITOR',
259
                        KnowledgeAreaCategoryUser::ROLE_EDITOR => 'LABEL_EDITOR',
251
                        KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR => 'LABEL_ADMINISTRATOR',
260
                        KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR => 'LABEL_ADMINISTRATOR',
252
                    ];
261
                    ];
253
                }
262
                }
Línea -... Línea 263...
-
 
263
                
Línea -... Línea 264...
-
 
264
                $jobs_description = [];
-
 
265
                
-
 
266
                
-
 
267
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
-
 
268
                $knowledgeAreaCategoryJobDescriptionMapper = KnowledgeAreaCategoryJobDescriptionMapper::getInstance($this->adapter);
-
 
269
                $records = $knowledgeAreaCategoryJobDescriptionMapper->fetchAllByCategoryId($knowledgeAreaCategory->id);
-
 
270
                foreach($records as $record)
-
 
271
                {
-
 
272
                    $jobDescription = $jobDescriptionMapper->fetchOne($record->job_description_id);
-
 
273
                    array_push($jobs_description, $jobDescription->uuid);
-
 
274
                }
Línea 254... Línea 275...
254
                
275
                
255
                
276
        
256
 
277
 
257
                return new JsonModel([
278
                return new JsonModel([
258
                    'success' => true,
279
                    'success' => true,
259
                    'data' => [
280
                    'data' => [
260
                        'total' => $paginator->getTotalItemCount(),
281
                        'total' => $paginator->getTotalItemCount(),
-
 
282
                        'items' => $items,
261
                        'items' => $items,
283
                        'link_add' => $allowAdd ? $this->url()->fromRoute('knowledge-area/categories/users/add', ['id' => $knowledgeAreaCategory->uuid ] ) : '',
-
 
284
                        'link_upload' => $allowUpload ? $this->url()->fromRoute('knowledge-area/categories/users/upload', ['id' => $knowledgeAreaCategory->uuid ] ) : '',
262
                        'link_add' => $allowAdd ? $this->url()->fromRoute('knowledge-area/categories/users/add', ['id' => $knowledgeAreaCategory->uuid ] ) : '',
285
                        'link_jobs_description' => $allowJobsDescription ? $this->url()->fromRoute('knowledge-area/categories/users/jobs-description', ['id' => $knowledgeAreaCategory->uuid ] ) : '',
263
                        'link_upload' => $allowUpload ? $this->url()->fromRoute('knowledge-area/categories/users/upload', ['id' => $knowledgeAreaCategory->uuid ] ) : '',
286
                        'roles' => $roles,
264
                        'roles' => $roles,
287
                        'jobs_description' =>  $jobs_description,
Línea -... Línea 288...
-
 
288
                    ]
-
 
289
                ]);
-
 
290
            } else {
-
 
291
                
-
 
292
                $jobDescriptionIdBoss = 0;
265
                    ]
293
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
266
                ]);
294
                $jobsDescription = $this->recursiveLoad($currentUser, $currentCompany, $jobDescriptionMapper, $jobDescriptionIdBoss);
Línea 267... Línea 295...
267
            } else {
295
                
268
                
296
                
269
                $form = new  KnowledgeAreaCategoryUserForm($this->adapter, $currentCompany->id, KnowledgeAreaCategory::PRIVACY_COMPANY);
297
                $form = new  KnowledgeAreaCategoryUserForm($this->adapter, $currentCompany->id, KnowledgeAreaCategory::PRIVACY_COMPANY);
270
                $formFilter = new KnowledgeAreaCategoryUserDataForm($this->adapter, $currentCompany->id);
298
                $formFilter = new KnowledgeAreaCategoryUserDataForm($this->adapter, $currentCompany->id);
271
                
299
                
272
 
300
 
-
 
301
                $this->layout()->setTemplate('layout/layout-backend');
-
 
302
                $viewModel = new ViewModel();
273
                $this->layout()->setTemplate('layout/layout-backend');
303
                $viewModel->setTemplate('leaders-linked/knowledge-area-category-users/index.phtml');
274
                $viewModel = new ViewModel();
304
                $viewModel->setVariables([
275
                $viewModel->setTemplate('leaders-linked/knowledge-area-category-users/index.phtml');
305
                    'form' =>  $form,
276
                $viewModel->setVariables([
306
                    'formFilter' => $formFilter,
277
                    'form' =>  $form,
307
                    'jobsDescription' => $jobsDescription,
Línea 285... Línea 315...
285
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
315
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
286
            ]);
316
            ]);
287
        }
317
        }
Línea 288... Línea 318...
288
 
318
 
-
 
319
    }
-
 
320
    
-
 
321
    
-
 
322
    /**
-
 
323
     *
-
 
324
     * @param User $currentUser
-
 
325
     * @param Company $currentCompany
-
 
326
     * @param JobDescriptionMapper $jobDescriptionMapper
-
 
327
     * @param int $jobDescriptionIdBoss
-
 
328
     * @return array
-
 
329
     */
-
 
330
    private function recursiveLoad($currentUser, $currentCompany, $jobDescriptionMapper, $jobDescriptionIdBoss)
-
 
331
    {
-
 
332
        $items = [];
-
 
333
        $records = $jobDescriptionMapper->fetchAllByCompanyIdAndJobDescriptionIdBoss($currentCompany->id, $jobDescriptionIdBoss);
-
 
334
 
-
 
335
        
-
 
336
        foreach($records as $record)
-
 
337
        {
-
 
338
            
-
 
339
            
-
 
340
            
-
 
341
            array_push($items, [
-
 
342
                'uuid' => $record->uuid,
-
 
343
                'name' => $record->name,
-
 
344
                'children' => $this->recursiveLoad($currentUser, $currentCompany, $jobDescriptionMapper, $record->id),
-
 
345
            ]);
-
 
346
        }
-
 
347
        
-
 
348
        return $items;
Línea 289... Línea 349...
289
    }
349
    }
290
 
350
 
291
    public function addAction() 
351
    public function addAction() 
292
    { 
352
    { 
Línea 594... Línea 654...
594
 
654
 
Línea 595... Línea 655...
595
        
655
        
-
 
656
        return new JsonModel($data);
-
 
657
 
-
 
658
    }
-
 
659
    
-
 
660
    public function jobsDescriptionAction()
-
 
661
    {
-
 
662
        $request = $this->getRequest();
-
 
663
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
664
        $currentCompany = $currentUserPlugin->getCompany();
-
 
665
        $currentUser = $currentUserPlugin->getUser();
-
 
666
        
-
 
667
        $request = $this->getRequest();
-
 
668
        $uuid = $this->params()->fromRoute('id');
-
 
669
 
-
 
670
        
-
 
671
        
-
 
672
        $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
-
 
673
        $knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOneByUuid($uuid);
-
 
674
        
-
 
675
        if(!$knowledgeAreaCategory) {
-
 
676
            return new JsonModel([
-
 
677
                'success' => false,
-
 
678
                'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_NOT_FOUND'
-
 
679
            ]);
-
 
680
        }
-
 
681
        
-
 
682
        if($knowledgeAreaCategory->company_id != $currentCompany->id) {
-
 
683
            return new JsonModel([
-
 
684
                'success' => false,
-
 
685
                'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_IS_OTHER_COMPANY'
-
 
686
            ]);
-
 
687
        }
-
 
688
        
-
 
689
        if ($request->isPost()) {
-
 
690
            
-
 
691
            $knowledgeAreaCategoryJobDescriptionMapper = KnowledgeAreaCategoryJobDescriptionMapper::getInstance($this->adapter);
-
 
692
            $knowledgeAreaCategoryJobDescriptionMapper->deleteAllByCategoryId($knowledgeAreaCategory->id);
-
 
693
            
-
 
694
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
-
 
695
            $jobs_description_uuid = $this->params()->fromPost('job_description_id');
-
 
696
            
-
 
697
            if(!empty($jobs_description_uuid)) {
-
 
698
                
-
 
699
                foreach($jobs_description_uuid as $job_description_uuid)
-
 
700
                {
-
 
701
                    $jobDescription = $jobDescriptionMapper->fetchOneByUuid($job_description_uuid);
-
 
702
                    
-
 
703
  
-
 
704
                    if($jobDescription && $jobDescription->company_id == $currentCompany->id) {
-
 
705
                        
-
 
706
                        
-
 
707
                        $knowledgeAreaCategoryJobDescription = new  KnowledgeAreaCategoryJobDescription();
-
 
708
                        $knowledgeAreaCategoryJobDescription->category_id = $knowledgeAreaCategory->id;
-
 
709
                        $knowledgeAreaCategoryJobDescription->job_description_id = $jobDescription->id;
-
 
710
                        
-
 
711
                        
-
 
712
                        $knowledgeAreaCategoryJobDescriptionMapper->insert($knowledgeAreaCategoryJobDescription);
-
 
713
                    }
-
 
714
                    
-
 
715
                }
-
 
716
            }
-
 
717
            
-
 
718
 
-
 
719
            $data = [
-
 
720
                'success' => true,
-
 
721
                'data' => 'LABEL_RECORD_UPDATED'
-
 
722
            ];
-
 
723
 
-
 
724
        } else {
-
 
725
            $data = [
-
 
726
                'success' => false,
-
 
727
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
728
            ];
-
 
729
            
-
 
730
            
-
 
731
        }
-
 
732
        
-
 
733
        
596
        return new JsonModel($data);
734
        return new JsonModel($data);
597
 
735