Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 16770 Rev 16790
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 -...
4
namespace LeadersLinked\Controller;
-
 
Línea 5... Línea 5...
5
 
5
namespace LeadersLinked\Controller;
6
use Laminas\Db\Adapter\AdapterInterface;
-
 
7
 
6
 
8
use Laminas\Mvc\Controller\AbstractActionController;
7
 
-
 
8
use Laminas\Mvc\Controller\AbstractActionController;
-
 
9
use Laminas\View\Model\ViewModel;
-
 
10
use Laminas\View\Model\JsonModel;
-
 
11
use LeadersLinked\Form\OrganizationPosition\OrganizationPositionForm;
-
 
12
use LeadersLinked\Model\Company;
-
 
13
use LeadersLinked\Model\OrganizationPosition;
-
 
14
use LeadersLinked\Model\OrganizationPositionCompetency;
-
 
15
use LeadersLinked\Model\OrganizationPositionCompetencyBehavior;
-
 
16
use LeadersLinked\Mapper\BehaviorMapper;
-
 
17
use LeadersLinked\Mapper\CompetencyMapper;
-
 
18
use LeadersLinked\Mapper\CompetencyBehaviorMapper;
-
 
19
use LeadersLinked\Mapper\CompetencyTypeMapper;
9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
20
use LeadersLinked\Mapper\OrganizationPositionMapper;
10
use Laminas\View\Model\ViewModel;
21
use LeadersLinked\Mapper\OrganizationPositionCompetencyBehaviorMapper;
-
 
22
use LeadersLinked\Mapper\OrganizationPositionCompetencyMapper;
11
use Laminas\View\Model\JsonModel;
23
use LeadersLinked\Library\Functions;
-
 
24
use LeadersLinked\Library\OrganizationPositionPdf;
12
use LeadersLinked\Library\Functions;
25
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
13
use LeadersLinked\Form\Organization\PositionForm;
-
 
14
use LeadersLinked\Mapper\UserMapper;
-
 
15
use LeadersLinked\Mapper\JobDescriptionMapper;
-
 
16
use LeadersLinked\Mapper\OrganizationPositionMapper;
-
 
Línea 17... Línea 26...
17
use LeadersLinked\Model\OrganizationPosition;
26
use LeadersLinked\Model\User;
18
use LeadersLinked\Mapper\OrganizationPositionSubordinateMapper;
27
use Laminas\Http\Response;
19
use LeadersLinked\Form\Organization\DatatableForm;
28
use LeadersLinked\Mapper\JobDescriptionMapper;
Línea 68... Línea 77...
68
        $this->cache        = $cache;
77
        $this->cache        = $cache;
69
        $this->logger       = $logger;
78
        $this->logger       = $logger;
70
        $this->config       = $config;
79
        $this->config       = $config;
71
        $this->translator   = $translator;
80
        $this->translator   = $translator;
72
    }
81
    }
73
    
82
 
74
    public function indexAction()
83
    public function indexAction()
75
    {
84
    {
76
        $currentUserPlugin = $this->plugin('currentUserPlugin');
85
        $currentUserPlugin = $this->plugin('currentUserPlugin');
77
        $currentUser = $currentUserPlugin->getUser();
86
        $currentUser = $currentUserPlugin->getUser();
78
        $currentCompany = $currentUserPlugin->getCompany();
87
        $currentCompany = $currentUserPlugin->getCompany();
-
 
88
 
Línea 79... Línea 89...
79
        
89
        
-
 
90
        $request = $this->getRequest();
-
 
91
        $headers = $request->getHeaders();
Línea 80... Línea -...
80
        $request = $this->getRequest();
-
 
81
        
-
 
82
        $headers  = $request->getHeaders();
-
 
83
        
92
 
Línea -... Línea 93...
-
 
93
        
-
 
94
        if ($request->isPost()) {
-
 
95
            
-
 
96
            $data = $this->params()->fromPost('data');
-
 
97
         
-
 
98
            if(!empty($data)) {
-
 
99
                
-
 
100
                $json = json_decode($data, true);
-
 
101
                if(is_array($json)) {
-
 
102
                    
-
 
103
                    $jobDescriptionIdBoss = 0;
-
 
104
                    $jobDescriptionMapper = OrganizationPositionMapper::getInstance($this->adapter);
-
 
105
                    
-
 
106
                    
-
 
107
                    
-
 
108
                    $position = 0;
-
 
109
                    foreach($json as $item)
-
 
110
                    {
-
 
111
 
-
 
112
                        $this->recursiveSave($currentCompany, $jobDescriptionMapper, $jobDescriptionIdBoss, $item, $position);
-
 
113
                        $position++;
-
 
114
                    }
-
 
115
 
-
 
116
                }
-
 
117
            }
Línea 84... Línea -...
84
        $request = $this->getRequest();
-
 
Línea -... Línea 118...
-
 
118
            return new JsonModel([
-
 
119
                'success' => true,
-
 
120
            ]);
-
 
121
            
-
 
122
            
85
        if($request->isGet()) {
123
        } else if ($request->isGet()) {
86
            
124
 
87
            
125
 
88
            $headers  = $request->getHeaders();
126
            $headers = $request->getHeaders();
89
            
127
 
90
            $isJson = false;
128
            $isJson = false;
91
            if($headers->has('Accept')) {
129
            if ($headers->has('Accept')) {
92
                $accept = $headers->get('Accept');
130
                $accept = $headers->get('Accept');
93
                
131
 
94
                $prioritized = $accept->getPrioritized();
132
                $prioritized = $accept->getPrioritized();
95
                
133
 
96
                foreach($prioritized as $key => $value) {
134
                foreach ($prioritized as $key => $value) {
97
                    $raw = trim($value->getRaw());
-
 
98
                    
135
                    $raw = trim($value->getRaw());
99
                    if(!$isJson) {
136
 
100
                        $isJson = strpos($raw, 'json');
137
                    if (!$isJson) {
101
                    }
138
                        $isJson = strpos($raw, 'json');
102
                    
-
 
103
                }
-
 
104
            }
-
 
105
            
-
 
106
            if($isJson) {
-
 
107
                $job_description_id = Functions::sanitizeFilterString($this->params()->fromQuery('job_description_id'));
-
 
108
                if(empty($job_description_id)) {
-
 
109
                    
-
 
110
                    return new JsonModel([
-
 
111
                        'success' => false,
-
 
112
                        'data' => [
-
 
113
                            'items' => [],
-
 
Línea 114... Línea -...
114
                            'total' => 0,
-
 
115
                            'link_add' => ''
-
 
Línea 116... Línea -...
116
                        ]
-
 
117
                    ]);
-
 
118
                }
-
 
119
                
-
 
120
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
-
 
121
                $jobDescription = $jobDescriptionMapper->fetchOneByUuid($job_description_id);
-
 
122
                
-
 
123
                if(!$jobDescription) {
-
 
Línea 124... Línea -...
124
                    
-
 
125
                    return new JsonModel([
-
 
126
                        'success' => false,
-
 
127
                        'data' => 'ERROR_JOB_DESCRIPTION_NOT_FOUND'
-
 
128
                    ]);
139
                    }
129
                }
-
 
130
                    
-
 
131
                
-
 
132
                if($jobDescription->company_id != $currentCompany->id) {
-
 
133
                    return new JsonModel([
-
 
Línea -... Línea 140...
-
 
140
                }
-
 
141
            }
Línea 134... Línea -...
134
                        'success' => false,
-
 
135
                        'data' => 'ERROR_UNAUTHORIZED' 
-
 
Línea 136... Línea -...
136
                    ]);
-
 
137
                }
-
 
138
                    
-
 
139
                    
-
 
140
                    
-
 
141
                    
-
 
142
                
-
 
143
                
-
 
Línea 144... Línea 142...
144
                $search = $this->params()->fromQuery('search', []);
142
 
145
                $search = empty($search['value']) ? '' :  Functions::sanitizeFilterString($search['value']);
-
 
146
                
-
 
147
                $page               = intval($this->params()->fromQuery('start', 1), 10);
143
            if ($isJson) {
148
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
-
 
149
                $order =  $this->params()->fromQuery('order', []);
-
 
-
 
144
                
Línea 150... Línea -...
150
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
-
 
151
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
-
 
152
    
-
 
153
                $fields =  ['user'];
-
 
154
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'user';
-
 
155
                
-
 
156
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
-
 
157
                    $order_direction = 'ASC';
-
 
158
                }
-
 
159
    
-
 
160
                $positionMapper = OrganizationPositionMapper::getInstance($this->adapter);
-
 
161
                $paginator = $positionMapper->fetchAllDataTableByCompanyIdAndJobDescriptionId($jobDescription->company_id, $jobDescription->id, $search, $page, $records_x_page, $order_field, $order_direction);
-
 
162
                
-
 
163
                $items = [];
-
 
164
                $records = $paginator->getCurrentItems();
-
 
165
                foreach($records as $record)
-
 
Línea 166... Línea 145...
166
                {   
145
                
167
                    $item = [
146
                
168
                        'user' => $record['user'],
147
                $items = [];
169
                        'status' => $record['status'],
148
                
170
                        'actions' => [
-
 
171
                            'link_edit' => $this->url()->fromRoute('organization/positions/edit', ['id' => $record['uuid'] ]),
-
 
-
 
149
                $jobDescriptionIdBoss = 0;
172
                            'link_delete' => $this->url()->fromRoute('organization/positions/delete', ['id' => $record['uuid'] ]),
150
                $jobDescriptionMapper = OrganizationPositionMapper::getInstance($this->adapter);
173
                            'link_subordinates' => $this->url()->fromRoute('organization/positions/subordinates', ['id' => $record['uuid'] ])
151
                
-
 
152
                
-
 
153
                
Línea 174... Línea -...
174
                        ] 
-
 
Línea 175... Línea -...
175
                    ];
-
 
-
 
154
                $items = $this->recursiveLoad($currentUser, $currentCompany, $jobDescriptionMapper, $jobDescriptionIdBoss);
176
                    
155
               
Línea 177... Línea 156...
177
                    array_push($items, $item);
156
                
178
                }
157
                
179
                
158
                
180
                return new JsonModel([
159
                return new JsonModel([
181
                    'success' => true,
160
                    'success' => true,
182
                    'data' => [
161
                    'data' => [
-
 
162
                        'items' => $items,
Línea 183... Línea -...
183
                        'items' => $items,
-
 
184
                        'total' => $paginator->getTotalItemCount(),
163
  
185
                        'link_add' => $this->url()->fromRoute('organization/positions/add', ['job_description_id' => $jobDescription->uuid ]),
164
                    ]
186
                    ]
165
                ]);
187
                ]);
-
 
188
                
166
 
189
                
167
            } else {
190
            } else  {
168
                
191
                
169
                
192
                $formDatatable    = new DatatableForm($this->adapter, $currentCompany->id);
170
                
-
 
171
 
-
 
172
                $form = new OrganizationPositionForm($this->adapter, $currentCompany ? $currentCompany->id : null);
-
 
173
 
-
 
174
                $this->layout()->setTemplate('layout/layout-backend');
-
 
175
                $viewModel = new ViewModel();
-
 
176
                $viewModel->setTemplate('leaders-linked/jobs-description/index.phtml');
-
 
177
                $viewModel->setVariables([
-
 
178
                    'form' => $form,
-
 
179
                    'company_name' => $currentCompany->name,
-
 
180
 
-
 
181
                    
-
 
182
                ]);
-
 
183
                return $viewModel;
-
 
184
            }
-
 
185
        } else {
-
 
186
            return new JsonModel([
-
 
187
                'success' => false,
-
 
188
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
189
            ]);
-
 
190
        }
-
 
191
    }
-
 
192
    
-
 
193
    
-
 
194
    /**
-
 
195
     * 
-
 
196
     * @param Company $currentCompany
-
 
197
     * @param OrganizationPositionMapper $jobDescriptionMapper
-
 
198
     * @param int $jobDescriptionIdBoss
-
 
199
     * @param int $position
-
 
200
     * @param array $item
-
 
201
     */
-
 
202
    private function recursiveSave($currentCompany, $jobDescriptionMapper, $jobDescriptionIdBoss, $item, $position)
-
 
203
    {
-
 
204
        
-
 
205
 
-
 
206
        if(!empty($item) && is_array($item)) {
-
 
207
            foreach($item as $subitem)
-
 
208
            {
-
 
209
                $jobDescription = $jobDescriptionMapper->fetchOneByUuid($subitem['id']);
-
 
210
                if($jobDescriptionMapper) {
-
 
211
                    if($jobDescriptionIdBoss) {
-
 
212
 
-
 
213
            
-
 
214
                        $jobDescriptionMapper->setOrganizationPositionIdBossByJobDescripcionId($jobDescription->id,  $jobDescriptionIdBoss, $position);
-
 
215
                    } else {
193
                $formPosition = new PositionForm($this->adapter, $currentCompany->id);
216
                        $jobDescriptionMapper->removeOrganizationPositionIdBossByOrganizationPositionId($jobDescription->id, $position);
194
 
217
                    }
Línea -... Línea 218...
-
 
218
                    
-
 
219
                    $position++;
-
 
220
                    
-
 
221
                    if(!empty($subitem['children']) && is_array($subitem['children'])) {
-
 
222
                        
-
 
223
                        $position2 = 0;
-
 
224
                        foreach($subitem['children'] as $subitem2)
-
 
225
                        {
-
 
226
                            $this->recursiveSave($currentCompany, $jobDescriptionMapper, $jobDescription->id,  $subitem2, $position2);
-
 
227
                            $position2++;
-
 
228
                        }
-
 
229
                        
-
 
230
                    }
-
 
231
    
-
 
232
                    
-
 
233
                }
-
 
234
            }
-
 
235
        }
-
 
236
    }
-
 
237
    
-
 
238
    
-
 
239
    /**
-
 
240
     * 
-
 
241
     * @param User $currentUser
-
 
242
     * @param Company $currentCompany
-
 
243
     * @param OrganizationPositionMapper $jobDescriptionMapper
-
 
244
     * @param int $jobDescriptionIdBoss
-
 
245
     * @return array
-
 
246
     */
-
 
247
    private function recursiveLoad($currentUser, $currentCompany, $jobDescriptionMapper, $jobDescriptionIdBoss)
-
 
248
    {
-
 
249
        $acl            = $this->getEvent()->getViewModel()->getVariable('acl');
-
 
250
        $allowAdd       = $acl->isAllowed($currentUser->usertype_id, 'jobs-description/add') ? 1 : 0;
-
 
251
        $allowEdit      = $acl->isAllowed($currentUser->usertype_id, 'jobs-description/edit') ? 1 : 0;
-
 
252
        $allowDelete    = $acl->isAllowed($currentUser->usertype_id, 'jobs-description/delete') ? 1 : 0;
-
 
253
        $allowReport    = $acl->isAllowed($currentUser->usertype_id, 'jobs-description/report') ? 1 : 0;
-
 
254
        
-
 
255
        
-
 
256
        $items = [];
-
 
257
 
-
 
258
        
-
 
259
        if ($currentCompany) {
-
 
260
            $records = $jobDescriptionMapper->fetchAllByCompanyIdAndOrganizationPositionIdBoss($currentCompany->id, $jobDescriptionIdBoss);
-
 
261
        } else {
-
 
262
            $records = $jobDescriptionMapper->fetchAllDefaultAndOrganizationPositionIdBoss($jobDescriptionIdBoss);
-
 
263
        }
-
 
264
 
-
 
265
        
195
                $this->layout()->setTemplate('layout/layout-backend');
266
        foreach($records as $record)
196
                $viewModel = new ViewModel();
267
        {
-
 
268
            
-
 
269
            
197
                $viewModel->setTemplate('leaders-linked/organization/positions');
270
            
198
                $viewModel->setVariables([
271
            array_push($items, [
199
                    'formDatatable' => $formDatatable,
272
                'uuid' => $record->uuid,
200
                    'formPosition' => $formPosition,
273
                'name' => $record->name,
201
                    
274
                'children' => $this->recursiveLoad($currentUser, $currentCompany, $jobDescriptionMapper, $record->id),
202
                        
275
                'status' => $record->status,
203
                ]);
276
                'link_report' => $allowReport ? $this->url()->fromRoute('jobs-description/report', ['id' => $record->uuid]) : '',
204
                return $viewModel ;
277
                'link_edit' => $allowEdit ? $this->url()->fromRoute('jobs-description/edit', ['id' => $record->uuid]) : '',
-
 
278
                'link_delete' => $allowDelete ? $this->url()->fromRoute('jobs-description/delete', ['id' => $record->uuid]) : '',
205
            } 
279
                'link_add' => $allowAdd ? $this->url()->fromRoute('jobs-description/add', ['id' => $record->uuid]) : '',
Línea 206... Línea -...
206
      
-
 
207
        } else {
-
 
Línea 208... Línea 280...
208
            return new JsonModel([
280
            ]);
-
 
281
        }
-
 
282
        
-
 
283
        return $items;
-
 
284
    }
-
 
285
 
-
 
286
    public function addAction()
-
 
287
    {
-
 
288
 
-
 
289
        
-
 
290
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
291
        $currentUser = $currentUserPlugin->getUser();
209
                'success' => false,
292
        $currentCompany = $currentUserPlugin->getCompany();
210
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
293
 
211
            ]);;
294
        $request = $this->getRequest();
212
        }
295
 
213
    }
296
 
214
    
-
 
Línea -... Línea 297...
-
 
297
        if ($request->isGet()) {
-
 
298
            $behaviors = [];
-
 
299
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
-
 
300
            
-
 
301
            
-
 
302
            if($currentCompany) {
-
 
303
                $records = $behaviorMapper->fetchAllActiveByCompanyId($currentCompany->id);
215
    public function addAction()
304
            } else {
-
 
305
                $records = $behaviorMapper->fetchAllActiveByDefault();
-
 
306
            }
-
 
307
            
-
 
308
            $behaviorIds = [];
-
 
309
            foreach($records as $record)
-
 
310
            {
-
 
311
                
-
 
312
                $behaviorIds[ $record->id ] = $record->uuid;
-
 
313
                
-
 
314
                array_push($behaviors, [
-
 
315
                    'uuid' => $record->uuid,
216
    {
316
                    'description' => $record->description
217
        $currentUserPlugin = $this->plugin('currentUserPlugin');
317
                ]);
218
        $currentUser = $currentUserPlugin->getUser();
318
            }
219
        $currentCompany = $currentUserPlugin->getCompany();
319
            
220
        
320
            
Línea -... Línea 321...
-
 
321
            $competencyTypes = [];
-
 
322
            
-
 
323
            
-
 
324
            $competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
-
 
325
            
-
 
326
            if($currentCompany) {
Línea 221... Línea 327...
221
        $request = $this->getRequest();
327
                $records = $competencyTypeMapper->fetchAllActiveByCompanyId($currentCompany->id);
222
        
-
 
Línea 223... Línea -...
223
        
-
 
Línea -... Línea 328...
-
 
328
            } else {
224
        if($request->isPost()) {
329
                $records = $competencyTypeMapper->fetchAllActiveByDefault();
-
 
330
            }
225
            $job_description_id = $this->params()->fromRoute('job_description_id');
331
            
-
 
332
            
226
            
333
            $competencyTypeIds = [];
-
 
334
            foreach($records as $record)
-
 
335
            {
Línea 227... Línea -...
227
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
-
 
228
            $jobDescription = $jobDescriptionMapper->fetchOneByUuid($job_description_id);
-
 
229
            
336
                $competencyTypeIds[ $record->id ] =  $record->uuid;
Línea -... Línea 337...
-
 
337
                
-
 
338
                
-
 
339
                array_push($competencyTypes, [
-
 
340
                    'uuid' => $record->uuid,
-
 
341
                    'name' => $record->name,
-
 
342
                ]);
-
 
343
            }
-
 
344
            
-
 
345
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
-
 
346
            if($currentCompany) {
-
 
347
                $records = $competencyMapper->fetchAllActiveByCompanyId($currentCompany->id);
-
 
348
            } else {
-
 
349
                $records = $competencyMapper->fetchAllActiveByDefault();
-
 
350
            }
-
 
351
            
-
 
352
            $competencyBehaviorMapper = CompetencyBehaviorMapper::getInstance($this->adapter);
230
            if(!$jobDescription) {
353
            
-
 
354
            
-
 
355
            
-
 
356
            $competencies = [];
-
 
357
            
-
 
358
            foreach($records as $record)
-
 
359
            {
-
 
360
                if(!isset($competencyTypeIds[ $record->competency_type_id ])) {
-
 
361
                    continue;
231
                return new JsonModel([
362
                }
-
 
363
                
-
 
364
                $behaviors_by_competency = [];
-
 
365
                
-
 
366
                $competencyBehaviors = $competencyBehaviorMapper->fetchAllByCompetencyId($record->id);
-
 
367
                foreach($competencyBehaviors as $competencyBehavior)
-
 
368
                {
232
                    'success'   => false,
369
                    if(!isset($behaviorIds[ $competencyBehavior->behavior_id ])) {
-
 
370
                        continue;
-
 
371
                    }
-
 
372
                    
-
 
373
                    array_push($behaviors_by_competency, $behaviorIds[ $competencyBehavior->behavior_id ]);
-
 
374
                }
-
 
375
                
233
                    'data'   => 'JOB_DESCRIPTION_NOT_FOUND'
376
                
-
 
377
                if($behaviors_by_competency) {
-
 
378
                    array_push($competencies, [
-
 
379
                        'competency_type_uuid' => $competencyTypeIds[ $record->competency_type_id ],
-
 
380
                        'uuid' => $record->uuid,
-
 
381
                        'name' => $record->name,
-
 
382
                        'behaviors' => $behaviors_by_competency,
-
 
383
                    ]);
-
 
384
                }
-
 
385
                
-
 
386
                
-
 
387
            }
-
 
388
            
-
 
389
            
-
 
390
            
-
 
391
            $jobDescriptionMapper = OrganizationPositionMapper::getInstance($this->adapter);
-
 
392
            $records = $jobDescriptionMapper->fetchAllByCompanyId($currentCompany->id);
-
 
393
            
Línea 234... Línea 394...
234
                ]);
394
            $jobsDescription = [];
Línea -... Línea 395...
-
 
395
            
-
 
396
            foreach ($records as $record) 
-
 
397
            {   
-
 
398
                $jobsDescription[ $record->uuid ] = $record->name;
-
 
399
            }
-
 
400
 
-
 
401
 
-
 
402
            $data = [
-
 
403
                'success' => true,
-
 
404
                'data' => [
-
 
405
                    'jobs_description' => $jobsDescription,
-
 
406
                    'behaviors' => $behaviors,
-
 
407
                    'competency_types' => $competencyTypes,
-
 
408
                    'competencies' => $competencies,
-
 
409
                ] 
-
 
410
            ];
-
 
411
 
-
 
412
 
Línea 235... Línea -...
235
            }
-
 
236
  
-
 
Línea -... Línea 413...
-
 
413
            return new JsonModel($data);
-
 
414
        } else if ($request->isPost()) {
-
 
415
            $form = new OrganizationPositionForm($this->adapter, $currentCompany ? $currentCompany->id : null);
-
 
416
            $dataPost = $request->getPost()->toArray();
-
 
417
 
Línea -... Línea 418...
-
 
418
 
-
 
419
            $form->setData($dataPost);
237
            
420
 
-
 
421
            if ($form->isValid()) {
-
 
422
                $jobDescriptionMapper = OrganizationPositionMapper::getInstance($this->adapter);
238
            if($jobDescription->company_id != $currentCompany->id) {
423
                
Línea -... Línea 424...
-
 
424
                $dataPost = (array) $form->getData();
-
 
425
 
-
 
426
                if(!empty($dataPost['job_description_id_boss'])) {
-
 
427
                    
-
 
428
                    $jobDescriptionBoos = $jobDescriptionMapper->fetchOneByUuid(Functions::sanitizeFilterString($dataPost['job_description_id_boss']));
-
 
429
                    if($jobDescriptionBoos && $jobDescriptionBoos->company_id == $currentCompany->id) {
-
 
430
                        $dataPost['job_description_id_boss'] = $jobDescriptionBoos->id;
-
 
431
                    } else {
-
 
432
                        $dataPost['job_description_id_boss'] = 0;
-
 
433
                    }
-
 
434
                    
-
 
435
                    
-
 
436
                }
-
 
437
                
-
 
438
                
-
 
439
               
-
 
440
                $dataPost['status'] = empty($dataPost['status']) ? OrganizationPosition::STATUS_INACTIVE : $dataPost['status'];
-
 
441
                
-
 
442
                $hydrator = new ObjectPropertyHydrator();
-
 
443
                $jobDescription = new OrganizationPosition();
-
 
444
 
-
 
445
                
-
 
446
                if ($currentCompany) {
-
 
447
                    $jobDescription->company_id = $currentCompany ? $currentCompany->id : null;
-
 
448
                }
-
 
449
                
-
 
450
                $hydrator->hydrate($dataPost, $jobDescription);
-
 
451
                
-
 
452
                $result = $jobDescriptionMapper->insert($jobDescription);
-
 
453
 
-
 
454
                if ($result) {
-
 
455
                    $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
-
 
456
                    $competencyMapper = CompetencyMapper::getInstance($this->adapter);
-
 
457
                    $competencyBehaviorMapper = CompetencyBehaviorMapper::getInstance($this->adapter);
-
 
458
                    
-
 
459
                    
-
 
460
                    $jobDescriptionCompetencyBehaviorMapper = OrganizationPositionCompetencyBehaviorMapper::getInstance($this->adapter);
-
 
461
                    $jobDescriptionCompetencyMapper = OrganizationPositionCompetencyMapper::getInstance($this->adapter);
-
 
462
                    
-
 
463
                    $competencies_selected = isset($dataPost['competencies_selected']) ? $dataPost['competencies_selected'] : [];
-
 
464
                    foreach($competencies_selected as $competency_selected)
-
 
465
                    {
-
 
466
 
-
 
467
                        $competency_uuid = isset($competency_selected['competency_uuid']) ? $competency_selected['competency_uuid'] : '';
-
 
468
                        $competency = $competencyMapper->fetchOneByUuid($competency_uuid);
-
 
469
                        
-
 
470
                        
-
 
471
                        if($competency) {
-
 
472
                            if($currentCompany) {
-
 
473
                                $ok = $competency->company_id == $currentCompany->id;
-
 
474
                            } else {
-
 
475
                                $ok = empty($competency->company_id);
-
 
476
                            }
-
 
477
                        } else {
-
 
478
                            $ok = false;
-
 
479
                        }
-
 
480
                        
-
 
481
                        if(!$ok) {
-
 
482
                            continue;
-
 
483
                        }
-
 
484
                        
-
 
485
                        
-
 
486
                        $behavior_uuid = isset($competency_selected['behavior_uuid']) ? $competency_selected['behavior_uuid'] : '';
-
 
487
                        $behavior = $behaviorMapper->fetchOneByUuid($behavior_uuid);
-
 
488
                        if($behavior) {
-
 
489
                            if($currentCompany) {
-
 
490
                                $ok = $behavior->company_id == $currentCompany->id;
-
 
491
                            } else {
-
 
492
                                $ok = empty($behavior->company_id);
-
 
493
                            }
-
 
494
                            
-
 
495
                            
-
 
496
                        } else {
-
 
497
                            $ok = false;
-
 
498
                        }
-
 
499
                        
239
                return new JsonModel([
500
                        if($competency->company_id != $behavior->company_id) {
240
                    'success'   => false,
501
                            continue;
241
                    'data'   =>  'ERROR_UNAUTHORIZED'
502
                        }
242
                ]);
503
                        
243
            }
504
                        $competencyBehavior = $competencyBehaviorMapper->fetchOneByBehaviorIdAndCompetencyId($behavior->id, $competency->id);
244
            
505
                        if(!$competencyBehavior) {
245
            
506
                            continue;
246
            $form = new PositionForm($this->adapter, $currentCompany->id);
507
                        }
247
            $dataPost = $request->getPost()->toArray();
508
                        
248
            
-
 
249
            $form->setData($dataPost);
509
                        $level = isset($competency_selected['level']) ? $competency_selected['level'] : 0;
250
            
510
                        $level = intval($level, 10);
251
            if($form->isValid()) {
511
                        
252
                $dataPost = (array) $form->getData();
-
 
253
                $dataPost['status'] = $dataPost['status'] ? $dataPost['status'] : OrganizationPosition::STATUS_INACTIVE;
512
                        
254
                
513
                        $jobDescriptionCompetency =  $jobDescriptionCompetencyMapper->fetchOneByOrganizationPositionIdAndCompetencyId($jobDescription->id, $competency->id);
255
                $userMapper = UserMapper::getInstance($this->adapter);
514
                        if(!$jobDescriptionCompetency) {
256
                $user = $userMapper->fetchOneByUuid($dataPost['user_id']);
515
                            $jobDescriptionCompetency = new OrganizationPositionCompetency();
257
                $dataPost['user_id'] = $user->id;
-
 
258
                
516
                            $jobDescriptionCompetency->competency_id = $competency->id;
259
                $hydrator = new ObjectPropertyHydrator();
517
                            $jobDescriptionCompetency->job_description_id = $jobDescription->id;
260
                $position = new OrganizationPosition();
518
                            $jobDescriptionCompetencyMapper->insert($jobDescriptionCompetency);
261
                $position->company_id = $jobDescription->company_id;
519
                            
262
                $position->job_description_id = $jobDescription->id;
520
                        }
263
                
521
                        
264
                $hydrator->hydrate($dataPost, $position);
522
                        
265
 
523
                        
266
 
524
                        $jobDescriptionCompetencyBehavior = new OrganizationPositionCompetencyBehavior();
267
                $positionMapper = OrganizationPositionMapper::getInstance($this->adapter);
-
 
268
                $result = $positionMapper->insert($position);
525
                        $jobDescriptionCompetencyBehavior->job_description_id = $jobDescription->id;
269
                
526
                        $jobDescriptionCompetencyBehavior->competency_id = $competency->id;
270
                
527
                        $jobDescriptionCompetencyBehavior->behavior_id = $behavior->id;
271
                if($result) {
528
                        $jobDescriptionCompetencyBehavior->level = $level;
272
                    $this->logger->info('Se agrego la posicion ' . $jobDescription->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
529
                        $jobDescriptionCompetencyBehaviorMapper->insert($jobDescriptionCompetencyBehavior);
273
                    
530
                    }
274
                    $data = [
531
 
275
                        'success'   => true,
532
 
276
                        'data'   => 'LABEL_RECORD_ADDED'
533
                    $this->logger->info('Se agrego el cargo ' . $jobDescription->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
277
                    ];
534
 
278
                } else {
535
                    $data = [
Línea 279... Línea 536...
279
                    $data = [
536
                        'success' => true,
280
                        'success'   => false,
537
                        'data' => 'LABEL_RECORD_ADDED'
281
                        'data'      => $positionMapper->getError()
538
                    ];
282
                    ];
539
                } else {
283
                    
540
                    $data = [
284
                }
541
                        'success' => false,
285
                
542
                        'data' => $jobDescriptionMapper->getError()
286
                return new JsonModel($data);
543
                    ];
Línea 287... Línea 544...
287
                
544
                }
288
            } else {
545
 
289
                $messages = [];
546
                return new JsonModel($data);
290
                $form_messages = (array) $form->getMessages();
547
            } else {
291
                foreach($form_messages  as $fieldname => $field_messages)
548
                $messages = [];
292
                {
549
                $form_messages = (array) $form->getMessages();
293
                    
550
                foreach ($form_messages as $fieldname => $field_messages) {
294
                    $messages[$fieldname] = array_values($field_messages);
551
 
295
                }
552
                    $messages[$fieldname] = array_values($field_messages);
Línea 296... Línea 553...
296
                
553
                }
297
                return new JsonModel([
554
 
298
                    'success'   => false,
555
                return new JsonModel([
299
                    'data'   => $messages
556
                    'success' => false,
300
                ]);
557
                    'data' => $messages
301
            }
558
                ]);
302
 
559
            }
303
        } else {
560
        } else {
304
            $data = [
561
            $data = [
305
                'success' => false,
562
                'success' => false,
306
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
563
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
307
            ];
564
            ];
308
            
565
 
309
            return new JsonModel($data);
566
            return new JsonModel($data);
310
        }
567
        }
311
        
568
 
312
        return new JsonModel($data);
569
        return new JsonModel($data);
313
    }
570
    }
314
 
571
 
315
    public function editAction()
572
    public function editAction()
316
    {
-
 
317
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
318
        $currentUser = $currentUserPlugin->getUser();
573
    {
319
        $currentCompany = $currentUserPlugin->getCompany();
574
        $currentUserPlugin = $this->plugin('currentUserPlugin');
320
        
575
        $currentUser = $currentUserPlugin->getUser();
321
        $request = $this->getRequest();
576
        $currentCompany = $currentUserPlugin->getCompany();
322
        $uuid = $this->params()->fromRoute('id');
-
 
323
 
577
 
324
        
578
        $request = $this->getRequest();
325
        if(!$uuid) {
579
        $uuid = $this->params()->fromRoute('id');
326
            $data = [
580
 
327
                'success'   => false,
581
 
328
                'data'   => 'ERROR_INVALID_PARAMETER'
582
        if (!$uuid) {
329
            ];
583
            $data = [
-
 
584
                'success' => false,
330
            
585
                'data' => 'ERROR_INVALID_PARAMETER'
331
            return new JsonModel($data);
586
            ];
-
 
587
 
332
        }
588
            return new JsonModel($data);
-
 
589
        }
-
 
590
 
Línea 333... Línea 591...
333
 
591
        $jobDescriptionMapper = OrganizationPositionMapper::getInstance($this->adapter);
334
        $positionMapper = OrganizationPositionMapper::getInstance($this->adapter);
592
        $jobDescription = $jobDescriptionMapper->fetchOneByUuid($uuid);
335
        $position = $positionMapper->fetchOneByUuid($uuid);
-
 
336
        if(!$position) {
-
 
Línea -... Línea 593...
-
 
593
        if (!$jobDescription) {
-
 
594
            $data = [
-
 
595
                'success' => false,
-
 
596
                'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
597
            ];
-
 
598
 
-
 
599
            return new JsonModel($data);
337
            $data = [
600
        }
-
 
601
 
-
 
602
        if ($currentCompany && $jobDescription->company_id != $currentCompany->id) {
-
 
603
            $data = [
-
 
604
                'success' => false,
-
 
605
                'data' => 'ERROR_UNAUTHORIZED'
338
                'success'   => false,
606
            ];
-
 
607
 
-
 
608
            return new JsonModel($data);
-
 
609
        }
-
 
610
 
Línea -... Línea 611...
-
 
611
 
-
 
612
        if ($request->isPost()) {
-
 
613
            $form = new OrganizationPositionForm($this->adapter, $currentCompany ? $currentCompany->id : null, $jobDescription->id);
-
 
614
            $dataPost = $request->getPost()->toArray();
-
 
615
 
-
 
616
            $form->setData($dataPost);
-
 
617
 
-
 
618
            if ($form->isValid()) {
-
 
619
                $dataPost = (array) $form->getData();
-
 
620
                if(!empty($dataPost['job_description_id_boss'])) {
-
 
621
                    
-
 
622
                    $jobDescriptionBoos = $jobDescriptionMapper->fetchOneByUuid(Functions::sanitizeFilterString($dataPost['job_description_id_boss']));
-
 
623
                    if($jobDescriptionBoos && $jobDescriptionBoos->company_id == $currentCompany->id) {
-
 
624
                        $dataPost['job_description_id_boss'] = $jobDescriptionBoos->id;
-
 
625
                    } else {
-
 
626
                        $dataPost['job_description_id_boss'] = 0;
-
 
627
                    }
-
 
628
                }
-
 
629
 
-
 
630
                $hydrator = new ObjectPropertyHydrator();
-
 
631
                $hydrator->hydrate($dataPost, $jobDescription);
-
 
632
                
-
 
633
                $dataPost['status'] = $dataPost['status'] ? $dataPost['status'] : OrganizationPosition::STATUS_INACTIVE;
-
 
634
                
-
 
635
                $jobDescriptionMapper = OrganizationPositionMapper::getInstance($this->adapter);
-
 
636
                
-
 
637
                
-
 
638
                $result = $jobDescriptionMapper->update($jobDescription);
-
 
639
 
-
 
640
                if ($result) {
-
 
641
                    $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
-
 
642
                    $competencyMapper = CompetencyMapper::getInstance($this->adapter);
-
 
643
                    $competencyBehaviorMapper = CompetencyBehaviorMapper::getInstance($this->adapter);
-
 
644
                    
-
 
645
                    
-
 
646
                    $jobDescriptionCompetencyBehaviorMapper = OrganizationPositionCompetencyBehaviorMapper::getInstance($this->adapter);
-
 
647
                    $jobDescriptionCompetencyBehaviorMapper->deleteAllBOrganizationPositionId($jobDescription->id);
-
 
648
                    
-
 
649
                    $jobDescriptionCompetencyMapper = OrganizationPositionCompetencyMapper::getInstance($this->adapter);
-
 
650
                    $jobDescriptionCompetencyMapper->deleteAllBOrganizationPositionId($jobDescription->id);
-
 
651
                    
-
 
652
                    $competencies_selected = isset($dataPost['competencies_selected']) ? $dataPost['competencies_selected'] : [];
-
 
653
                    foreach($competencies_selected as $competency_selected)
-
 
654
                    {
-
 
655
                        $competency_uuid = isset($competency_selected['competency_uuid']) ? $competency_selected['competency_uuid'] : '';
-
 
656
                        $competency = $competencyMapper->fetchOneByUuid($competency_uuid);
-
 
657
                        
-
 
658
                        
-
 
659
                        if($competency) {
-
 
660
                            if($currentCompany) {
-
 
661
                                $ok = $competency->company_id == $currentCompany->id;
-
 
662
                            } else {
-
 
663
                                $ok = empty($competency->company_id);
-
 
664
                            }
-
 
665
                        } else {
-
 
666
                            $ok = false;
-
 
667
                        }
-
 
668
                        
-
 
669
                        if(!$ok) {
-
 
670
                            continue;
-
 
671
                        }
-
 
672
                        
-
 
673
                        
-
 
674
                        $behavior_uuid = isset($competency_selected['behavior_uuid']) ? $competency_selected['behavior_uuid'] : '';
-
 
675
                        $behavior = $behaviorMapper->fetchOneByUuid($behavior_uuid);
-
 
676
                        if($behavior) {
-
 
677
                            if($currentCompany) {
-
 
678
                                $ok = $behavior->company_id == $currentCompany->id;
-
 
679
                            } else {
-
 
680
                                $ok = empty($behavior->company_id);
-
 
681
                            }
-
 
682
                            
339
                'data'   => 'ERROR_RECORD_NOT_FOUND'
683
                            
340
            ];
684
                        } else {
341
            
685
                            $ok = false;
342
            return new JsonModel($data);
686
                        }
343
        }
687
                        
344
        
688
                        if($competency->company_id != $behavior->company_id) {
345
        if($position->company_id != $currentCompany->id) {
689
                            continue;
346
            $data = [
690
                        }
347
                'success'   => false,
691
                        
348
                'data'   => 'ERROR_UNAUTHORIZED'
692
                        $competencyBehavior = $competencyBehaviorMapper->fetchOneByBehaviorIdAndCompetencyId($behavior->id, $competency->id);
349
            ];
693
                        if(!$competencyBehavior) {
350
                
694
                            continue;
351
            return new JsonModel($data);
-
 
352
        }
695
                        }
353
        
696
                        
354
        $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
697
                        $level = isset($competency_selected['level']) ? $competency_selected['level'] : 0;
355
        $jobDescription = $jobDescriptionMapper->fetchOne($position->job_description_id);
698
                        $level = intval($level, 10);
356
        
-
 
357
        if($request->isPost()) {
699
                        
358
            $form = new PositionForm($this->adapter, $currentCompany->id);
700
                        
359
            $dataPost = $request->getPost()->toArray();
701
                        $jobDescriptionCompetency =  $jobDescriptionCompetencyMapper->fetchOneByOrganizationPositionIdAndCompetencyId($jobDescription->id, $competency->id);
360
           
702
                        if(!$jobDescriptionCompetency) {
361
            
703
                            $jobDescriptionCompetency = new OrganizationPositionCompetency();
362
            $form->setData($dataPost);
704
                            $jobDescriptionCompetency->competency_id = $competency->id;
363
            
705
                            $jobDescriptionCompetency->job_description_id = $jobDescription->id;
364
            if($form->isValid()) {
706
                            $jobDescriptionCompetencyMapper->insert($jobDescriptionCompetency);
365
                $dataPost = (array) $form->getData();
707
                            
-
 
708
                        }
366
                $dataPost['status'] = $dataPost['status'] ? $dataPost['status'] : OrganizationPosition::STATUS_INACTIVE;
709
                        
-
 
710
                        
-
 
711
                        
-
 
712
                        $jobDescriptionCompetencyBehavior = new OrganizationPositionCompetencyBehavior();
-
 
713
                        $jobDescriptionCompetencyBehavior->job_description_id = $jobDescription->id;
-
 
714
                        $jobDescriptionCompetencyBehavior->competency_id = $competency->id;
367
                
715
                        $jobDescriptionCompetencyBehavior->behavior_id = $behavior->id;
-
 
716
                        $jobDescriptionCompetencyBehavior->level = $level;
-
 
717
                        $jobDescriptionCompetencyBehaviorMapper->insert($jobDescriptionCompetencyBehavior);
-
 
718
                    }
-
 
719
                    
-
 
720
                    
-
 
721
                    
-
 
722
                    $this->logger->info('Se actualizo el cargo ' . $jobDescription->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
368
                $userMapper = UserMapper::getInstance($this->adapter);
723
 
-
 
724
                    $data = [
-
 
725
                        'success' => true,
-
 
726
                        'data' => 'LABEL_RECORD_UPDATED'
-
 
727
                    ];
-
 
728
                } else {
Línea 369... Línea -...
369
                $user = $userMapper->fetchOneByUuid($dataPost['user_id']);
-
 
370
                $dataPost['user_id'] = $user->id;
-
 
Línea -... Línea 729...
-
 
729
                    $data = [
Línea 371... Línea -...
371
 
-
 
Línea 372... Línea -...
372
                $hydrator = new ObjectPropertyHydrator();
-
 
373
                $hydrator->hydrate($dataPost, $position);
-
 
374
 
730
                        'success' => false,
375
                $result = $positionMapper->update($position);
-
 
376
                
-
 
Línea -... Línea 731...
-
 
731
                        'data' => $jobDescriptionMapper->getError()
-
 
732
                    ];
377
                if($result) {
733
                }
-
 
734
 
-
 
735
                return new JsonModel($data);
Línea 378... Línea -...
378
                    $this->logger->info('Se actualizo la posición ' . $jobDescription->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
379
                    
-
 
380
                    $data = [
-
 
381
                        'success' => true,
-
 
Línea -... Línea 736...
-
 
736
            } else {
382
                        'data' => 'LABEL_RECORD_UPDATED'
737
                $messages = [];
383
                    ];
738
                $form_messages = (array) $form->getMessages();
384
                } else {
739
                foreach ($form_messages as $fieldname => $field_messages) {
-
 
740
                    $messages[$fieldname] = array_values($field_messages);
-
 
741
                }
385
                    $data = [
742
 
386
                        'success'   => false,
743
                return new JsonModel([
-
 
744
                    'success' => false,
387
                        'data'      => $positionMapper->getError()
745
                    'data' => $messages
388
                    ];
746
                ]);
Línea -... Línea 747...
-
 
747
            }
389
                }
748
        } else if ($request->isGet()) {
390
                
749
            $behaviors = [];
-
 
750
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
391
                return new JsonModel($data);
751
            
-
 
752
            
Línea -... Línea 753...
-
 
753
            if($currentCompany) {
-
 
754
                $records = $behaviorMapper->fetchAllActiveByCompanyId($currentCompany->id);
-
 
755
            } else {
-
 
756
                $records = $behaviorMapper->fetchAllActiveByDefault();
-
 
757
            }
-
 
758
            
392
                
759
            $behaviorIds = [];
393
            } else {
760
            foreach($records as $record)
394
                $messages = [];
761
            {
-
 
762
                
-
 
763
                $behaviorIds[ $record->id ] = $record->uuid;
-
 
764
                
-
 
765
                array_push($behaviors, [
Línea -... Línea 766...
-
 
766
                    'uuid' => $record->uuid,
395
                $form_messages = (array) $form->getMessages();
767
                    'description' => $record->description
396
                foreach($form_messages  as $fieldname => $field_messages)
768
                ]);
397
                {
769
            }
398
                    $messages[$fieldname] = array_values($field_messages);
770
            
399
                }
771
            
-
 
772
            $competencyTypes = [];
-
 
773
            
-
 
774
            
-
 
775
            $competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
-
 
776
            
-
 
777
            if($currentCompany) {
-
 
778
                $records = $competencyTypeMapper->fetchAllActiveByCompanyId($currentCompany->id);
-
 
779
            } else {
-
 
780
                $records = $competencyTypeMapper->fetchAllActiveByDefault();
-
 
781
            }
-
 
782
            
-
 
783
            
400
                
784
            $competencyTypeIds = [];
Línea -... Línea 785...
-
 
785
            foreach($records as $record)
401
                return new JsonModel([
786
            {
Línea -... Línea 787...
-
 
787
                $competencyTypeIds[ $record->id ] =  $record->uuid;
-
 
788
                
Línea 402... Línea 789...
402
                    'success'   => false,
789
                
403
                    'data'   => $messages
-
 
-
 
790
                array_push($competencyTypes, [
404
                ]);
791
                    'uuid' => $record->uuid,
405
            }
792
                    'name' => $record->name,
406
        } else if ($request->isGet()) {
793
                ]);
407
            $userMapper = UserMapper::getInstance($this->adapter);
794
            }
408
            $user = $userMapper->fetchOne($position->user_id);
-
 
409
           
795
            
Línea -... Línea 796...
-
 
796
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
-
 
797
            if($currentCompany) {
-
 
798
                $records = $competencyMapper->fetchAllActiveByCompanyId($currentCompany->id);
-
 
799
            } else {
-
 
800
                $records = $competencyMapper->fetchAllActiveByDefault();
-
 
801
            }
-
 
802
            
-
 
803
            $competencyBehaviorMapper = CompetencyBehaviorMapper::getInstance($this->adapter);
410
            
804
            
411
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
805
            
-
 
806
            
-
 
807
            $competencies = [];
-
 
808
            
-
 
809
            foreach($records as $record)
-
 
810
            {
-
 
811
                if(!isset($competencyTypeIds[ $record->competency_type_id ])) {
-
 
812
                    continue;
-
 
813
                }
-
 
814
                
-
 
815
                $behaviors_by_competency = [];
-
 
816
                
-
 
817
                $competencyBehaviors = $competencyBehaviorMapper->fetchAllByCompetencyId($record->id);
-
 
818
                foreach($competencyBehaviors as $competencyBehavior)
-
 
819
                {
-
 
820
                    if(!isset($behaviorIds[ $competencyBehavior->behavior_id ])) {
-
 
821
                        continue;
-
 
822
                    }
-
 
823
                    
Línea -... Línea 824...
-
 
824
                    array_push($behaviors_by_competency, $behaviorIds[ $competencyBehavior->behavior_id ]);
-
 
825
                }
-
 
826
                
-
 
827
                
Línea -... Línea 828...
-
 
828
                if($behaviors_by_competency) {
-
 
829
                    array_push($competencies, [
-
 
830
                        'competency_type_uuid' => $competencyTypeIds[ $record->competency_type_id ],
-
 
831
                        'uuid' => $record->uuid,
-
 
832
                        'name' => $record->name,
-
 
833
                        'behaviors' => $behaviors_by_competency,
-
 
834
                    ]);
-
 
835
                }
-
 
836
                
-
 
837
                
-
 
838
            }
-
 
839
            
-
 
840
            
-
 
841
            $jobDescriptionMapper = OrganizationPositionMapper::getInstance($this->adapter);
-
 
842
            $records = $jobDescriptionMapper->fetchAllByCompanyId($currentCompany->id);
-
 
843
            
-
 
844
            $jobsDescription = [];
-
 
845
            
-
 
846
            foreach ($records as $record)
-
 
847
            {
-
 
848
                if($jobDescription->id == $record->id) {
-
 
849
                    continue;
-
 
850
                }
-
 
851
                
-
 
852
                $jobsDescription[ $record->uuid ] = $record->name;
-
 
853
            }
-
 
854
            
-
 
855
            $job_description_id_boss = '';
-
 
856
            if($jobDescription->job_description_id_boss) {
-
 
857
                $jobDescriptionBoss = $jobDescriptionMapper->fetchOne($jobDescription->job_description_id_boss);
-
 
858
                if($jobDescriptionBoss) {
-
 
859
                    $job_description_id_boss = $jobDescriptionBoss->uuid;
-
 
860
                }
-
 
861
            }
-
 
862
 
-
 
863
            $data = [
-
 
864
                'id' => $jobDescription->uuid,
-
 
865
                'name' => $jobDescription->name, 
-
 
866
                'functions' => $jobDescription->functions,
-
 
867
                'objectives' => $jobDescription->objectives,
-
 
868
                'status' => $jobDescription->status,
-
 
869
                'competencies_selected' => [],
-
 
870
                'behaviors' => $behaviors,
-
 
871
                'competency_types' => $competencyTypes,
-
 
872
                'competencies' => $competencies,
-
 
873
                'jobs_description' => $jobsDescription,
-
 
874
                'job_description_id_boss' => $job_description_id_boss,
-
 
875
            ]; 
-
 
876
            
-
 
877
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
-
 
878
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
-
 
879
            $competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
-
 
880
            
-
 
881
            $competencyTypes = [];
-
 
882
 
-
 
883
            $jobDescriptionCompetencyMapper = OrganizationPositionCompetencyMapper::getInstance($this->adapter);
-
 
884
            $jobDescriptionCompetencyBehaviorMapper = OrganizationPositionCompetencyBehaviorMapper::getInstance($this->adapter);
-
 
885
            
-
 
886
            $jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchAllByOrganizationPositionId($jobDescription->id);
-
 
887
            foreach($jobDescriptionCompetencies as $jobDescriptionCompetency)
-
 
888
            {
-
 
889
                $competency = $competencyMapper->fetchOne($jobDescriptionCompetency->competency_id);
-
 
890
                if(!$competency) {
412
            $jobDescription = $jobDescriptionMapper->fetchOne($position->job_description_id);
891
                    continue;
413
            
892
                }
414
            
893
                
415
            $hydrator = new ObjectPropertyHydrator();
894
                if(isset($competencyTypes[$competency->competency_type_id])) {
416
            
895
                    $competencyType = $competencyTypes[$competency->competency_type_id];
417
            $data = $hydrator->extract($position);
896
                } else {
418
            $data['user_id'] = $user->uuid;
897
                
419
            $data['job_description_id'] = $jobDescription->uuid;
898
                    $competencyType = $competencyTypeMapper->fetchOne($competency->competency_type_id);
420
            $data['users'] = [];
899
                    if(!$competencyType) {
421
            $data['subordinates'] = [];
900
                        continue;
422
            
901
                    }
423
            $ids = [];
902
                    
424
            
903
                    $competencyTypes[$competency->competency_type_id] = $competencyType;
425
            $userMapper = UserMapper::getInstance($this->adapter);
904
                }
426
           
905
                
427
            $positionSubordinateMapper = OrganizationPositionSubordinateMapper::getInstance($this->adapter);
906
                $competency_selected = [
428
            $subordinates = $positionSubordinateMapper->fetchAllByPositionId($position->id);
907
                    'uuid' => $competency->uuid,
429
            
908
                    'competency_type_uuid' => $competencyType->uuid,
430
            foreach($subordinates as $subordinate)
909
                    'behaviors' => []
431
            {
910
                ];
432
                $user = $userMapper->fetchOne($subordinate->user_id);
911
                
433
                if($user) {
912
 
434
                    array_push($data['subordinates'], $user->uuid);
913
                
435
                }
914
                foreach($competencies as $record_competency) 
436
            }
915
                {
437
            
916
                    if($record_competency['uuid'] == $competency->uuid) {
438
            /*
917
                        
439
            $jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
918
                        foreach($record_competency['behaviors'] as $uuid_behavior)
440
            $jobDescriptionSubordinates = $jobDescriptionSubordinateMapper->fetchAllByJobDescriptionIdTopLevel($jobDescription->id);
919
                        {
441
            
920
 
442
            foreach($jobDescriptionSubordinates as $jobDescriptionSubordinate)
921
                            
443
            {
922
                            $behavior = $behaviorMapper->fetchOneByUuid($uuid_behavior);
444
                $positions = $positionMapper->fetchAllByJobDescriptionIdAndCompanyId($jobDescriptionSubordinate->job_description_id_low_level, $currentCompany->id);
923
                            if($behavior) {
445
                
924
                            
446
                foreach($positions as $position)
925
                                $jobDescriptionCompetencyBehavior = $jobDescriptionCompetencyBehaviorMapper->fetchOneByOrganizationPositionIdAndCompetencyIdAndBehaviorId($jobDescription->id, $competency->id, $behavior->id);
447
                {
926
                                if($jobDescriptionCompetencyBehavior) {
448
                    if(!in_array($position->user_id, $ids)) {
927
                                    $level = $jobDescriptionCompetencyBehavior->level;
449
                        array_push($ids, $position->user_id);
928
                                } else {
450
                    }
929
                                    $level = 0;
451
                }
930
                                }
452
                
931
                                
453
            }*/
932
                                array_push($competency_selected['behaviors'], ['uuid' => $behavior->uuid, 'level' => $level]);
454
            
933
                            }
455
            
934
                        }
456
            
935
                        
457
            if($ids) {
936
                    }
458
                $users = $userMapper->fetchAllByIds($ids);
937
                    
459
                foreach($users as $user)
938
                    
460
                {
939
                }
461
                    array_push($data['users'], [
940
                
462
                        'uuid' => $user->uuid, 
941
 
463
                        'name' => trim(trim($user->first_name) . ' ' . trim($user->last_name)) . ' (' . trim($user->email) . ')',
942
                
464
                    ]);
943
                array_push($data['competencies_selected'], $competency_selected);
465
                
944
                
466
                }
945
                
467
            }
946
                
-
 
947
            }
468
            
948
 
469
            
949
            $response = [
-
 
950
                'success' => true,
-
 
951
                'data' => $data
-
 
952
            ];
470
            $response = [
953
 
471
                'success' => true,
954
            return new JsonModel($response);
472
                'data' => $data
-
 
473
            ];
-
 
474
            
-
 
475
            return new JsonModel($response);
955
        } else {
476
        } else {
956
            $data = [
477
            $data = [
957
                'success' => false,
478
                'success' => false,
958
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
479
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
959
            ];
480
            ];
960
 
481
            
961
            return new JsonModel($data);
Línea 482... Línea 962...
482
            return new JsonModel($data);
962
        }
483
        }
963
 
484
        
964
        return new JsonModel($data);
485
        return new JsonModel($data);
965
    }
Línea 486... Línea 966...
486
    }
966
 
487
    
967
    public function deleteAction()
488
    public function deleteAction()
-
 
489
    {
968
    {
490
        $currentUserPlugin = $this->plugin('currentUserPlugin');
969
        $currentUserPlugin = $this->plugin('currentUserPlugin');
491
        $currentUser = $currentUserPlugin->getUser();
970
        $currentUser = $currentUserPlugin->getUser();
492
        $currentCompany = $currentUserPlugin->getCompany();
971
        $currentCompany = $currentUserPlugin->getCompany();
493
        
972
 
494
        $request = $this->getRequest();
973
        $request = $this->getRequest();
495
        $uuid = $this->params()->fromRoute('id');
974
        $uuid = $this->params()->fromRoute('id');
496
        
975
 
497
        if(!$uuid) {
976
        if (!$uuid) {
498
            $data = [
977
            $data = [
499
                'success'   => false,
978
                'success' => false,
500
                'data'   => 'ERROR_INVALID_PARAMETER'
979
                'data' => 'ERROR_INVALID_PARAMETER'
501
            ];
980
            ];
502
            
981
 
-
 
982
            return new JsonModel($data);
503
            return new JsonModel($data);
983
        }
504
        }
984
 
505
        
985
 
506
                
986
        $jobDescriptionMapper = OrganizationPositionMapper::getInstance($this->adapter);
507
        $positionMapper = OrganizationPositionMapper::getInstance($this->adapter);
-
 
508
        $position = $positionMapper->fetchOneByUuid($uuid);
-
 
509
        if(!$position) {
-
 
510
            $data = [
-
 
511
                'success'   => false,
-
 
512
                'data'   => 'ERROR_RECORD_NOT_FOUND'
-
 
513
            ];
-
 
514
            
-
 
515
            return new JsonModel($data);
-
 
516
        }
-
 
517
        
-
 
518
        if($position->company_id != $currentCompany->id) {
-
 
519
            $data = [
-
 
520
                'success'   => false,
-
 
521
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
522
            ];
987
        $jobDescription = $jobDescriptionMapper->fetchOneByUuid($uuid);
523
                
-
 
524
            return new JsonModel($data);
-
 
525
        }
-
 
526
        
-
 
527
        if($request->isPost()) {
-
 
528
            $result = $positionMapper->delete($position);
-
 
529
            if($result) {
-
 
530
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
-
 
531
                $jobDescription = $jobDescriptionMapper->fetchOne($position->job_description_id);
-
 
532
                
-
 
533
                $this->logger->info('Se borro la posición ' . $jobDescription->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
534
                
-
 
535
                $data = [
988
        if (!$jobDescription) {
536
                    'success' => true,
989
            $data = [
537
                    'data' => 'LABEL_RECORD_DELETED'
990
                'success' => false,
538
                ];
991
                'data' => 'ERROR_RECORD_NOT_FOUND'
539
            } else {
992
            ];
540
 
993
 
541
                $data = [
994
            return new JsonModel($data);
542
                    'success'   => false,
-
 
Línea -... Línea 995...
-
 
995
        }
-
 
996
 
543
                    'data'      => $positionMapper->getError()
997
        if ($currentCompany && $jobDescription->company_id != $currentCompany->id) {
-
 
998
            $data = [
-
 
999
                'success' => false,
-
 
1000
                'data' => 'ERROR_UNAUTHORIZED'
-
 
1001
            ];
-
 
1002
 
-
 
1003
            return new JsonModel($data);
-
 
1004
        }
-
 
1005
 
544
                ];
1006
 
-
 
1007
        if ($request->isPost()) {
-
 
1008
            $jobDescriptionMapper->removeAllOrganizationPositionIdBossByJobDescripcionId($jobDescription->id);
-
 
1009
            
545
 
1010
            
546
                return new JsonModel($data);
1011
            $result = $jobDescriptionMapper->delete($jobDescription);
-
 
1012
            if ($result) {
-
 
1013
                $this->logger->info('Se borro el cargo de trabajo ' . $jobDescription->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
1014
 
-
 
1015
                $data = [
-
 
1016
                    'success' => true,
-
 
1017
                    'data' => 'LABEL_RECORD_DELETED'
-
 
1018
                ];
547
            }
1019
            } else {
548
 
1020
 
-
 
1021
                $data = [
549
        } else {
1022
                    'success' => false,
-
 
1023
                    'data' => $jobDescriptionMapper->getError()
-
 
1024
                ];
550
            $data = [
1025
 
551
                'success' => false,
1026
                return new JsonModel($data);
552
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1027
            }
-
 
1028
        } else {
553
            ];
1029
            $data = [
-
 
1030
                'success' => false,
-
 
1031
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
554
            
1032
            ];
-
 
1033
 
-
 
1034
            return new JsonModel($data);
555
            return new JsonModel($data);
1035
        }
-
 
1036
 
-
 
1037
        return new JsonModel($data);
-
 
1038
    }
-
 
1039
 
-
 
1040
    public function importAction()
556
        }
1041
    {
557
        
1042
 
558
        return new JsonModel($data);
1043
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
1044
        $currentUser = $currentUserPlugin->getUser();
559
    }
1045
        $currentCompany = $currentUserPlugin->getCompany();
-
 
1046
 
-
 
1047
        if (!$currentCompany) {
-
 
1048
            $data = [
560
    /*
1049
                'success' => false,
561
    public function subordinatesAction()
1050
                'data' => 'ERROR_UNAUTHORIZED'
562
    {
1051
            ];
563
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
564
        $currentUser = $currentUserPlugin->getUser();
1052
 
565
        $currentCompany = $currentUserPlugin->getCompany();
1053
            return new JsonModel($data);
566
        
1054
        }
567
        $request = $this->getRequest();
1055
 
-
 
1056
        $request = $this->getRequest();
568
        $uuid = $this->params()->fromRoute('job_description_id');
1057
 
569
        
1058
        if ($request->isPost()) {
-
 
1059
 
-
 
1060
            $jobDescriptionMapper = OrganizationPositionMapper::getInstance($this->adapter);
-
 
1061
            $jobDescriptionsDefault = $jobDescriptionMapper->fetchAllByDefault();
570
        
1062
 
571
        if(!$uuid) {
1063
            $new_records = 0;
572
            $data = [
1064
            foreach ($jobDescriptionsDefault as $jobDescriptionDefault) {
573
                'success'   => false,
1065
                if ($jobDescriptionDefault->status == OrganizationPosition::STATUS_INACTIVE) {
574
                'data'   => 'ERROR_INVALID_PARAMETER'
1066
                    continue;
575
            ];
1067
                }
-
 
1068
 
-
 
1069
                $jobDescription = $jobDescriptionMapper->fetchOneByCompanyId($currentCompany->id, $jobDescriptionDefault->id);
576
            
1070
                if (!$jobDescription) {
-
 
1071
 
-
 
1072
                    $jobDescription = new OrganizationPosition();
-
 
1073
                    $jobDescription->company_id = $currentCompany->id;
-
 
1074
                    $jobDescription->job_description_id_default = $jobDescriptionDefault->id;
-
 
1075
                    $jobDescription->name = $jobDescriptionDefault->name;
-
 
1076
                    $jobDescription->functions = $jobDescriptionDefault->functions;
-
 
1077
                    $jobDescription->objectives = $jobDescriptionDefault->objectives;
577
            return new JsonModel($data);
1078
                    $jobDescription->status = OrganizationPosition::STATUS_ACTIVE;
578
        }
-
 
579
        
-
 
580
        $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
-
 
581
        $jobDescription = $jobDescriptionMapper->fetchOneByUuid($uuid);
-
 
582
        if(!$jobDescription) {
-
 
583
            $data = [
-
 
584
                'success'   => false,
-
 
585
                'data'   => 'ERROR_RECORD_NOT_FOUND'
-
 
586
            ];
1079
 
587
            
1080
                    $result = $jobDescriptionMapper->insert($jobDescription);
588
            return new JsonModel($data);
1081
 
589
        }
1082
                    if ($result) {
590
        
1083
 
591
        
-
 
Línea -... Línea 1084...
-
 
1084
                        //Add Competencies
592
      
1085
                        $competenceMapper = CompetencyMapper::getInstance($this->adapter);
593
        
1086
                        $jobDescriptionCompetencyMapper = OrganizationPositionCompetencyMapper::getInstance($this->adapter);
594
        if($jobDescription->company_id != $currentCompany->id) {
1087
                        $jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchByOrganizationPositionId($jobDescriptionDefault->id);
595
            $data = [
1088
 
596
                'success'   => false,
1089
                        if (count($jobDescriptionCompetencies) != 0) {
597
                'data'   => 'ERROR_UNAUTHORIZED'
1090
                            foreach ($jobDescriptionCompetencies as $record) {
598
            ];
1091
 
599
            
1092
                                $competence = $competenceMapper->fetchOneByCompanyIdAndCompetencyIdDefault($currentCompany->id, $record->competency_id);
600
            return new JsonModel($data);
1093
                                if ($competence) {
601
        }
1094
                                    $newDescriptionCompetency = new OrganizationPositionCompetency();
602
        
1095
                                    $newDescriptionCompetency->competency_id = $competence->id;
603
 
1096
                                    $newDescriptionCompetency->job_description_id = $jobDescription->id;
604
        if ($request->isGet()) {
1097
                                    $newDescriptionCompetency->level = $record->level;
605
            $ids = [];
1098
                                    $jobDescriptionCompetencyMapper->insert($newDescriptionCompetency);
606
            
1099
                                }
607
            $userMapper = UserMapper::getInstance($this->adapter);
1100
                            }
608
            $positionMapper = PositionMapper::getInstance($this->adapter);
1101
                        }
609
            
1102
 
610
            
1103
                        $new_records++;
611
            $jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
1104
                    } else {
612
            $jobDescriptionSubordinates = $jobDescriptionSubordinateMapper->fetchAllByJobDescriptionIdTopLevel($jobDescription->id);
1105
                        $data = [
613
            
1106
                            'success' => false,
614
            foreach($jobDescriptionSubordinates as $jobDescriptionSubordinate)
1107
                            'data' => 'ERROR_CANT_ADD_JOB_DESCRIPTION'
615
            {
-
 
616
                $positions = $positionMapper->fetchAllByJobDescriptionIdAndCompanyId($jobDescriptionSubordinate->job_description_id_low_level, $currentCompany->id);
1108
                        ];
617
                
1109
 
618
                foreach($positions as $position)
1110
                        return new JsonModel($data);
619
                {
1111
                    }
620
                    if(!in_array($position->user_id, $ids)) {
1112
                }
621
                        array_push($ids, $position->user_id);
1113
            }
622
                    }
1114
 
623
                }
1115
            if ($new_records) {
624
                
1116
 
625
            }
1117
                if (1 == $new_records) {
626
            
1118
                    $data = [
627
            $data = [];
-
 
628
            
1119
                        'success' => true,
629
            if($ids) {
-
 
630
                $users = $userMapper->fetchAllByIds($ids);
-
 
631
                foreach($users as $user) 
1120
                        'data' => 'LABEL_1_JOB_DESCRIPTION_IMPORTED'
632
                {
1121
                    ];
633
                    array_push($data, [
1122
 
634
                        'uuid' => $user->uuid,
1123
                    return new JsonModel($data);
635
                        'name' => trim(trim($user->first_name) . ' ' . trim($user->last_name)) . ' (' . trim($user->email) . ')',
1124
                } else {
636
                    ]);
1125
                    $data = [
637
                }
1126
                        'success' => true,
638
            }
1127
                        'data' => $new_records . ' LABEL_MULTI_JOB_DESCRIPTION_IMPORTED'
639
            
1128
                    ];
640
            
1129
 
641
            $response = [
1130
                    return new JsonModel($data);
-
 
1131
                }
642
                'success' => true,
1132
            } else {
643
                'data' => $data
-
 
644
            ];
-
 
645
            
-
 
646
            return new JsonModel($response);
-
 
647
        } else {
-
 
648
            $data = [
-
 
649
                'success' => false,
-
 
Línea -... Línea 1133...
-
 
1133
                $data = [
-
 
1134
                    'success' => true,
-
 
1135
                    'data' => 'LABEL_NO_JOB_DESCRIPTION_IMPORTED'
-
 
1136
                ];
-
 
1137
 
-
 
1138
                return new JsonModel($data);
Línea -... Línea 1139...
-
 
1139
            }
650
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1140
        } else {
651
            ];
1141
            $data = [
652
            
1142
                'success' => false,
653
 
1143
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
654
        }
1144
            ];
655
        
-
 
656
        return new JsonModel($data);
1145
 
-
 
1146
            return new JsonModel($data);
657
    }
1147
        }
658
    
1148
 
659
    public function graphAction()
1149
        return new JsonModel($data);
660
    {
1150
    }
-
 
1151
 
Línea -... Línea 1152...
-
 
1152
    public function bossAction()
661
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1153
    {