Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1709 eleazar 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
2667 eleazar 8
use LeadersLinked\Library\InterviewPDF;
1709 eleazar 9
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
10
use Laminas\Mvc\Controller\AbstractActionController;
11
use Laminas\Log\LoggerInterface;
12
use Laminas\View\Model\JsonModel;
13
use LeadersLinked\Form\RecruitmentSelectionInterviewFormForm;
8758 eleazar 14
use LeadersLinked\Form\InterviewFileForm;
1828 eleazar 15
use LeadersLinked\Form\JobDescriptionForm;
1829 eleazar 16
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
17
use LeadersLinked\Library\Functions;
18
use LeadersLinked\Mapper\CompanyMapper;
19
use LeadersLinked\Mapper\CompetencyTypeMapper;
20
use LeadersLinked\Model\JobDescription;
21
use LeadersLinked\Mapper\CompetencyMapper;
4029 eleazar 22
use LeadersLinked\Mapper\BehaviorCompetencyMapper;
23
use LeadersLinked\Model\BehaviorCompetency;
1829 eleazar 24
use LeadersLinked\Library\JobPdf;
25
use LeadersLinked\Mapper\JobDescriptionCompetencyMapper;
26
use LeadersLinked\Mapper\JobDescriptionSubordinateMapper;
27
use LeadersLinked\Model\JobDescriptionCompetency;
28
use LeadersLinked\Model\JobDescriptionBehaviorCompetency;
29
use LeadersLinked\Mapper\JobDescriptionBehaviorCompetencyMapper;
30
use LeadersLinked\Model\JobDescriptionSubordinate;
31
use LeadersLinked\Mapper\BehaviorMapper;
32
use LeadersLinked\Model\Behavior;
33
use LeadersLinked\Model\Company;
1713 eleazar 34
use LeadersLinked\Mapper\RecruitmentSelectionInterviewMapper;
8779 eleazar 35
use LeadersLinked\Mapper\RecruitmentSelectionInterviewFileMapper;
1713 eleazar 36
use LeadersLinked\Model\RecruitmentSelectionInterview;
8779 eleazar 37
use LeadersLinked\Model\RecruitmentSelectionInterviewFile;
1713 eleazar 38
use LeadersLinked\Mapper\RecruitmentSelectionVacancyMapper;
39
use LeadersLinked\Model\RecruitmentSelectionVacancy;
40
use LeadersLinked\Mapper\RecruitmentSelectionCandidateMapper;
41
use LeadersLinked\Model\RecruitmentSelectionCandidate;
42
use LeadersLinked\Mapper\JobDescriptionMapper;
1717 eleazar 43
use Laminas\View\Model\ViewModel;
44
use LeadersLinked\Form\RecruitmentSelectionCandidateFormForm;
45
use Laminas\Hydrator\ArraySerializableHydrator;
46
use Laminas\Db\ResultSet\HydratingResultSet;
47
use LeadersLinked\Mapper\QueryMapper;
48
use Laminas\Paginator\Adapter\DbSelect;
49
use Laminas\Paginator\Paginator;
1709 eleazar 50
 
51
class RecruitmentSelectionInterviewFormController extends AbstractActionController {
52
 
53
    /**
54
     *
55
     * @var AdapterInterface
56
     */
57
    private $adapter;
58
 
59
    /**
60
     *
61
     * @var AbstractAdapter
62
     */
63
    private $cache;
64
 
65
    /**
66
     *
67
     * @var  LoggerInterface
68
     */
69
    private $logger;
70
 
71
    /**
72
     *
73
     * @var array
74
     */
75
    private $config;
76
 
77
    /**
78
     *
79
     * @param AdapterInterface $adapter
80
     * @param AbstractAdapter $cache
81
     * @param LoggerInterface $logger
82
     * @param array $config
83
     */
84
    public function __construct($adapter, $cache, $logger, $config) {
85
        $this->adapter = $adapter;
86
        $this->cache = $cache;
87
        $this->logger = $logger;
88
        $this->config = $config;
89
    }
90
 
91
    public function indexAction() {
92
        $currentUserPlugin = $this->plugin('currentUserPlugin');
93
        $currentUser = $currentUserPlugin->getUser();
94
        $currentCompany = $currentUserPlugin->getCompany();
3458 eleazar 95
 
1709 eleazar 96
        $request = $this->getRequest();
3458 eleazar 97
 
1709 eleazar 98
        if($request->isGet())
99
        {
100
            $headers  = $request->getHeaders();
3458 eleazar 101
 
1709 eleazar 102
            $isJson = false;
103
            if($headers->has('Accept')) {
104
                $accept = $headers->get('Accept');
3458 eleazar 105
 
1709 eleazar 106
                $prioritized = $accept->getPrioritized();
3458 eleazar 107
 
1709 eleazar 108
                foreach($prioritized as $key => $value) {
109
                    $raw = trim($value->getRaw());
3458 eleazar 110
 
1709 eleazar 111
                    if(!$isJson) {
112
                        $isJson = strpos($raw, 'json');
113
                    }
114
                }
115
            }
3458 eleazar 116
 
2021 eleazar 117
            if ($isJson) {
4350 eleazar 118
                $vacancy_uuid = $this->params()->fromRoute('vacancy_uuid');
119
 
3458 eleazar 120
                $search = $this->params()->fromQuery('search', []);
121
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
122
 
123
                $page = intval($this->params()->fromQuery('start', 1), 10);
124
                $records_x_page = intval($this->params()->fromQuery('length', 10), 10);
125
                $order = $this->params()->fromQuery('order', []);
126
                $order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
127
                $order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var($order[0]['dir'], FILTER_SANITIZE_STRING));
128
 
129
                $fields = ['uuid', 'first_name', 'last_name', 'email'];
130
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
131
 
132
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
133
                     $order_direction = 'ASC';
134
                }
135
 
3536 eleazar 136
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
137
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/interview/form/edit');
138
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/interview/form/delete');
139
                $allowReport = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/interview/report');
8781 eleazar 140
                $allowFile = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/interview/file');
3536 eleazar 141
 
3484 eleazar 142
                $queryMapper = QueryMapper::getInstance($this->adapter);
143
                $sql = $queryMapper->getSql();
3515 eleazar 144
                $select = $sql->select();
8884 eleazar 145
                $select->columns(['uuid', 'company_id', 'status', 'type', 'vacancy_id', 'points']);
3516 eleazar 146
                $select->from(['i' => RecruitmentSelectionInterviewMapper::_TABLE]);
3526 eleazar 147
                $select->join(['c' => RecruitmentSelectionCandidateMapper::_TABLE], "i.candidate_id = c.id", ['first_name', 'last_name', 'email']);
4361 eleazar 148
                $select->join(['v' => RecruitmentSelectionVacancyMapper::_TABLE],"c.vacancy_id = v.id", ['name', 'last_date']);
4360 eleazar 149
                $select->where->equalTo('i.company_id', $currentCompany->id);
4361 eleazar 150
                $select->where->equalTo('v.uuid', $vacancy_uuid);
3514 eleazar 151
 
3887 eleazar 152
               // echo $select->getSqlString($this->adapter->platform); exit;
3458 eleazar 153
 
3484 eleazar 154
                if($search) {
155
                    $select->where->nest()
156
                    ->like('first_name', '%' . $search . '%')
157
                    ->unnest();
158
                }
3458 eleazar 159
 
3484 eleazar 160
                $select->order($order_field . ' ' . $order_direction);
3458 eleazar 161
 
3484 eleazar 162
                $hydrator = new ArraySerializableHydrator();
163
                $resultset = new HydratingResultSet($hydrator);
164
 
4359 eleazar 165
                $adapter = new DbSelect($select, $sql, $resultset);
166
                $paginator = new Paginator($adapter);
167
                $paginator->setItemCountPerPage($records_x_page);
168
                $paginator->setCurrentPageNumber($page);
169
 
3484 eleazar 170
                $items = [];
171
                $records = $paginator->getCurrentItems();
9388 eleazar 172
 
3484 eleazar 173
                foreach ($records as $record) {
174
                    $params = [
7966 eleazar 175
                        'vacancy_uuid' => $vacancy_uuid,
3537 eleazar 176
                        'interview_uuid' => $record['uuid'],
3484 eleazar 177
                    ];
3536 eleazar 178
 
179
                    $link_delete = $this->url()->fromRoute('recruitment-and-selection/interview/form/delete', $params);
180
 
181
                    $link_edit = $this->url()->fromRoute('recruitment-and-selection/interview/form/edit', $params);
3710 eleazar 182
 
183
                    $link_report = $this->url()->fromRoute('recruitment-and-selection/interview/report', $params);
3536 eleazar 184
 
8781 eleazar 185
                    $link_file = $this->url()->fromRoute('recruitment-and-selection/interview/file', $params);
3484 eleazar 186
 
187
                    $item = [
188
                        'uuid' => $record['uuid'],
189
                        'first_name' => $record['first_name'],
190
                        'last_name' => $record['last_name'],
191
                        'email' => $record['email'],
3882 eleazar 192
                        'vacancy' =>$record['name'],
8886 eleazar 193
                        'points' =>$record['points'],
3953 eleazar 194
                        'last_date' =>$record['last_date'],
3543 eleazar 195
                        'status' => $record['status'],
3561 eleazar 196
                        'type' => $record['type'],
3484 eleazar 197
                        // 'file' => $this->url()->fromRoute('storage', ['type' => 'recruitment_selection', 'code' => $record['uuid'], 'filename' => $record['file']]),
3536 eleazar 198
                        'actions' => [
199
                            'link_edit' => $allowEdit ? $link_edit : '',
200
                            'link_delete' => $allowDelete ? $link_delete : '',
3710 eleazar 201
                            'link_report' => $allowReport ? $link_report : '',
9395 eleazar 202
                            'link_file' => $allowFile ? $link_file : '',
3536 eleazar 203
                        ]
3484 eleazar 204
                    ];
205
 
9414 eleazar 206
                    if($record['type'] == 'r'){
207
                        $item['actions']['link_file'] = $allowFile ? $link_file : '';
208
                    } else{
209
                        $item['actions']['link_file'] = null;
210
                    }
211
 
3484 eleazar 212
                    array_push($items, $item);
213
                }
214
 
2029 eleazar 215
                return new JsonModel([
216
                    'success' => true,
2033 eleazar 217
                    'data' => [
3528 eleazar 218
                        'items' => $items,
219
                        'total' => $paginator->getTotalItemCount()
2033 eleazar 220
                    ],
2029 eleazar 221
                ]);
1709 eleazar 222
            } else {
2199 eleazar 223
                $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
2203 eleazar 224
                $vacancies = $vacancyMapper->fetchAllByCompanyId($currentCompany->id);
2211 eleazar 225
 
226
                $form = new RecruitmentSelectionInterviewFormForm($this->adapter, $currentCompany ? $currentCompany->id : null);
8757 eleazar 227
                $formFile = new InterviewFileForm($this->adapter, $currentCompany ? $currentCompany->id : null);
3458 eleazar 228
 
1709 eleazar 229
                $this->layout()->setTemplate('layout/layout-backend');
230
                $viewModel = new ViewModel();
1718 eleazar 231
                $viewModel->setTemplate('leaders-linked/recruitment-and-selection-interview/index.phtml');
1709 eleazar 232
                $viewModel->setVariables([
2211 eleazar 233
                    'form'      => $form,
8757 eleazar 234
                    'vacancies' => $vacancies,
235
                    'formFile' => $formFile
1709 eleazar 236
                ]);
3458 eleazar 237
 
1709 eleazar 238
                return $viewModel ;
239
            }
3458 eleazar 240
 
1709 eleazar 241
        } else {
242
            return new JsonModel([
243
                'success' => false,
244
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
245
            ]);
246
        }
247
    }
248
 
3571 eleazar 249
    public function addAction(){
1827 eleazar 250
        $currentUserPlugin = $this->plugin('currentUserPlugin');
251
        $currentUser = $currentUserPlugin->getUser();
252
        $currentCompany = $currentUserPlugin->getCompany();
1709 eleazar 253
 
7964 eleazar 254
        $request = $this->getRequest();
7962 eleazar 255
        $vacancy_uuid = $this->params()->fromRoute('vacancy_uuid');
256
 
7961 eleazar 257
        if ($request->isPost()) {
2578 eleazar 258
            $dataPost = $request->getPost()->toArray();
7965 eleazar 259
            $dataPost['vacancy_uuid'] = $vacancy_uuid;
3458 eleazar 260
 
2578 eleazar 261
            $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
7962 eleazar 262
            $vacancy = $vacancyMapper->fetchOneByUuid($vacancy_uuid);
2606 eleazar 263
 
264
            $candidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
265
            $candidate = $candidateMapper->fetchOneByUuid($dataPost['candidate_uuid']);
3458 eleazar 266
 
2578 eleazar 267
            $form = new RecruitmentSelectionInterviewFormForm($this->adapter, $currentCompany->id, $vacancy->id);
1827 eleazar 268
 
2574 eleazar 269
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : RecruitmentSelectionInterview::STATUS_REJECTED;
3911 eleazar 270
            $dataPost['type'] = RecruitmentSelectionInterview::STATUS_HUMAN_RESOURCE;
2573 eleazar 271
 
2572 eleazar 272
            $form->setData($dataPost);
273
 
1827 eleazar 274
            if ($form->isValid()) {
275
                $dataPost = (array) $form->getData();
2603 eleazar 276
 
2596 eleazar 277
                $hydrator = new ObjectPropertyHydrator();
278
                $recruitmentSelectionInterview = new RecruitmentSelectionInterview();
279
                $hydrator->hydrate($dataPost, $recruitmentSelectionInterview);
1827 eleazar 280
 
2597 eleazar 281
                if (!$recruitmentSelectionInterview->status) {
282
                    $recruitmentSelectionInterview->status = RecruitmentSelectionInterview::STATUS_REJECTED;
283
                }
3458 eleazar 284
 
2598 eleazar 285
                $recruitmentSelectionInterview->company_id = $currentCompany->id;
3458 eleazar 286
                $recruitmentSelectionInterview->vacancy_id = $vacancy->id;
287
                $recruitmentSelectionInterview->candidate_id = $candidate->id;
2613 eleazar 288
                $recruitmentSelectionInterview->user_id = $currentUser->id;
3458 eleazar 289
 
2599 eleazar 290
                $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
3626 eleazar 291
 
292
                $interviews = $recruitmentSelectionInterviewMapper->fetchAllByCandidateIdAndVacancyId($candidate->id, $vacancy->id);
293
 
294
                if (count($interviews) > 0) {
295
                    $hasHumanResourcesInterview = false;
296
 
297
                    foreach($interviews as $interview) {
298
                        if ($interview->type === RecruitmentSelectionInterview::STATUS_HUMAN_RESOURCE) {
299
                            $hasHumanResourcesInterview = true;
300
                        }
4199 eleazar 301
                        if ($interview->type === RecruitmentSelectionInterview::STATUS_BOSS){
302
                            return new JsonModel([
303
                                'success' => false,
4202 eleazar 304
                                'data' => 'LABEL_BOSS_DONE'
4199 eleazar 305
                            ]);
306
                        }
3626 eleazar 307
                    }
308
 
309
                    $recruitmentSelectionInterview->type = $hasHumanResourcesInterview
310
                        ? RecruitmentSelectionInterview::STATUS_BOSS
311
                        : RecruitmentSelectionInterview::STATUS_HUMAN_RESOURCE;
312
                }
313
 
2600 eleazar 314
                $result = $recruitmentSelectionInterviewMapper->insert($recruitmentSelectionInterview);
7952 eleazar 315
 
2588 eleazar 316
 
1827 eleazar 317
                if ($result) {
2621 eleazar 318
                    $this->logger->info('Se agrego la entrevista ' . $recruitmentSelectionInterview->id, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
3458 eleazar 319
 
2622 eleazar 320
                    // Get record by id
321
                    $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
322
                    $record = $recruitmentSelectionInterviewMapper->fetchOne($recruitmentSelectionInterview->id);
323
 
3458 eleazar 324
 
2504 eleazar 325
                    if ($record) {
1827 eleazar 326
 
2504 eleazar 327
                        $data = [
328
                            'success' => true,
329
                            'id' => $record->id,
330
                            'data' => 'LABEL_RECORD_ADDED'
331
                        ];
332
                    } else {
1827 eleazar 333
 
2504 eleazar 334
                        $data = [
335
                            'success' => false,
336
                            'data' => 'ERROR_RECORD_NOT_FOUND'
337
                        ];
1827 eleazar 338
                    }
339
                } else {
340
                    $data = [
341
                        'success' => false,
2504 eleazar 342
                        'data' => $recruitmentSelectionInterviewMapper->getError()
1827 eleazar 343
                    ];
344
                }
345
 
346
                return new JsonModel($data);
347
            } else {
348
                $messages = [];
349
                $form_messages = (array) $form->getMessages();
350
                foreach ($form_messages as $fieldname => $field_messages) {
1906 eleazar 351
 
1827 eleazar 352
                    $messages[$fieldname] = array_values($field_messages);
353
                }
354
 
355
                return new JsonModel([
356
                    'success' => false,
357
                    'data' => $messages
358
                ]);
359
            }
360
        } else {
361
            $data = [
362
                'success' => false,
363
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
364
            ];
365
 
366
            return new JsonModel($data);
367
        }
368
 
369
        return new JsonModel($data);
370
    }
3458 eleazar 371
 
3580 eleazar 372
    public function vacancyAction() {
3571 eleazar 373
        $currentUserPlugin = $this->plugin('currentUserPlugin');
374
        $currentUser = $currentUserPlugin->getUser();
375
        $currentCompany = $currentUserPlugin->getCompany();
376
 
377
        $request = $this->getRequest();
378
 
379
        $vacancy_uuid = $this->params()->fromRoute('vacancy_uuid');
380
 
381
        if ($request->isGet()) {
382
            $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
383
            $vacancy = $vacancyMapper->fetchOneByUuid($vacancy_uuid);
384
 
385
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
386
            $jobDescription = $jobDescriptionMapper->fetchOne($vacancy->job_description_id);
387
 
388
            $jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
389
            $jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($jobDescription->id);
390
 
391
            $candidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
4030 eleazar 392
            $activeCandidates = $candidateMapper->fetchAllActives($vacancy->id);
3947 eleazar 393
 
3571 eleazar 394
            $competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
395
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
396
            $behaviorCompetencyMapper = BehaviorCompetencyMapper::getInstance($this->adapter);
397
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
4342 eleazar 398
 
3571 eleazar 399
            $data = [
4030 eleazar 400
                'candidates' => $activeCandidates,
3571 eleazar 401
                'job_description' => [
402
                    'uuid' => $jobDescription->uuid,
403
                    'name' => $jobDescription->name,
404
                    'functions' => $jobDescription->functions,
405
                    'objectives' => $jobDescription->objectives,
406
                    'competencies' => []
407
                ],
4341 eleazar 408
                'interview' => [
409
                    'type' => RecruitmentSelectionInterview::STATUS_HUMAN_RESOURCE,
410
                    'status' => RecruitmentSelectionInterview::STATUS_ACCEPTED,
411
                    'points' => 0,
412
                    'comment' => '',
413
                ],
3598 eleazar 414
                'vacancy' => $vacancy,
3571 eleazar 415
            ];
416
 
417
            foreach ($jobDescriptionCompetencies as $jobDescriptionCompetency) {
418
                $competency = $competencyMapper->fetchOne($jobDescriptionCompetency->competency_id);
419
                $competencyType = $competencyTypeMapper->fetchOne($competency->competency_type_id);
420
                $behaviorCompetencies = $behaviorCompetencyMapper->fetchByCompetencyId($competency->id);
421
 
422
                $behaviors = [];
423
 
424
                foreach ($behaviorCompetencies as $behaviorCompetency) {
425
                    $behavior = $behaviorMapper->fetchOne($behaviorCompetency->behavior_id);
426
 
427
                    $behaviors []= [
428
                        'uuid' => $behavior->uuid,
429
                        'description' => $behavior->description,
430
                        'points' => 0,
431
                        'comment' => '',
432
                        'competency_uuid' => $competency->uuid,
433
                    ];
434
                }
435
 
436
                array_push($data['job_description']['competencies'], [
437
                    'competency_uuid' => $competency->uuid,
438
                    'competency_name' => $competency->name,
439
                    'competency_type_uuid' => $competencyType->uuid,
440
                    'competency_type_name' => $competencyType->name,
441
                    'behaviors' => $behaviors,
442
                ]);
443
            }
444
 
445
            return new JsonModel([
446
                'success' => true,
447
                'data' => $data
448
            ]);
449
 
450
        } else {
451
            return new JsonModel([
452
                'success' => true,
453
                'data' => 'ERROR_METHOD_NOT_ALLOWED',
454
            ]);
455
        }
456
    }
457
 
4367 eleazar 458
    public function typeAction(){
4365 eleazar 459
        $currentUserPlugin = $this->plugin('currentUserPlugin');
460
        $currentUser = $currentUserPlugin->getUser();
461
        $currentCompany = $currentUserPlugin->getCompany();
462
 
463
        $request = $this->getRequest();
464
 
465
        $candidate_uuid = $this->params()->fromRoute('candidate_uuid');
466
 
4368 eleazar 467
        if(!$request->isGet()){
4365 eleazar 468
            return new JsonModel([
469
                'success' => false,
470
                'data' => 'ERROR_METHOD_NOT_ALLOWED',
471
            ]);
472
        }
473
 
474
        $candidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
475
        $candidate = $candidateMapper->fetchOneByUuid($candidate_uuid);
476
 
477
        $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
478
        $vacancy = $vacancyMapper->fetchOne($candidate->vacancy_id);
479
 
480
        $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
481
        $interviews = $recruitmentSelectionInterviewMapper->fetchAllByCandidateIdAndVacancyId($candidate->id, $vacancy->id);
8741 eleazar 482
        if (count($interviews) === 2){
8658 eleazar 483
            return new JsonModel([
484
                'success' => true,
485
                'data' => 'Este candidato completo su ciclo de entrevistas'
486
            ]);
8741 eleazar 487
        } else if(count($interviews) === 1){
8660 eleazar 488
           return new JsonModel([
489
               'success' => true,
490
               'data' => 'Entrevista por el Jefe' ,
491
           ]);
492
        } else{
493
            return new JsonModel([
494
                'success' => true,
495
                'data' =>  'Entrevista por Recursos Humanos',
496
            ]);
8658 eleazar 497
        }
8654 eleazar 498
 
4365 eleazar 499
    }
500
 
2126 efrain 501
    public function editAction() {
2757 eleazar 502
        $request = $this->getRequest();
503
        $currentUserPlugin = $this->plugin('currentUserPlugin');
504
        $currentCompany = $currentUserPlugin->getCompany();
505
        $currentUser = $currentUserPlugin->getUser();
3458 eleazar 506
 
2757 eleazar 507
        $request = $this->getRequest();
2668 eleazar 508
        $interview_uuid = $this->params()->fromRoute('interview_uuid');
2757 eleazar 509
 
510
        if (!$interview_uuid) {
511
            $data = [
512
                'success' => false,
513
                'data' => 'ERROR_INVALID_PARAMETER'
514
            ];
515
 
516
            return new JsonModel($data);
517
        }
518
 
519
        $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
520
        $interview = $recruitmentSelectionInterviewMapper->fetchOneByUuid($interview_uuid);
521
 
2838 eleazar 522
        $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
523
        $vacancy = $vacancyMapper->fetchOne($interview->vacancy_id);
524
 
2757 eleazar 525
        if(!$interview){
526
           $data = [
527
               'success' => false,
528
               'data' => 'ERROR_INVALID_PARAMETER'
529
           ];
530
 
531
           return new JsonModel($data);
532
        }
533
 
534
        if ($interview->company_id != $currentCompany->id) {
535
            return new JsonModel([
536
                'success' => false,
537
                'data' => 'ERROR_UNAUTHORIZED'
538
            ]);
539
        }
540
 
541
        if ($request->isPost()) {
2838 eleazar 542
            $form = new RecruitmentSelectionInterviewFormForm($this->adapter, $currentCompany->id, $vacancy->id);
2757 eleazar 543
            $dataPost = $request->getPost()->toArray();
8894 efrain 544
            $dataPost['vacancy_uuid'] = $vacancy->uuid;
2757 eleazar 545
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : RecruitmentSelectionInterview::STATUS_REJECTED;
3632 eleazar 546
            $dataPost['type'] = $interview->type;
2757 eleazar 547
 
548
            $form->setData($dataPost);
549
 
550
            if ($form->isValid()) {
551
                $dataPost = (array) $form->getData();
552
 
553
                $hydrator = new ObjectPropertyHydrator();
554
                $hydrator->hydrate($dataPost, $interview);
555
 
556
                if (!$interview->status) {
557
                    $interview->status = RecruitmentSelectionInterview::STATUS_REJECTED;
558
                }
559
 
2831 eleazar 560
                $candidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
2837 eleazar 561
                $candidate = $candidateMapper->fetchOneByUuid($dataPost['candidate_uuid']);
3458 eleazar 562
 
2831 eleazar 563
                $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
2837 eleazar 564
                $vacancy = $vacancyMapper->fetchOneByUuid($dataPost['vacancy_uuid']);
2831 eleazar 565
 
2757 eleazar 566
                $interview->company_id = $currentCompany->id;
3458 eleazar 567
                $interview->vacancy_id = $vacancy->id;
568
                $interview->candidate_id = $candidate->id;
2757 eleazar 569
                $interview->user_id = $currentUser->id;
570
 
571
                $result = $recruitmentSelectionInterviewMapper->update($interview);
572
 
3458 eleazar 573
 
2757 eleazar 574
                if ($result) {
575
                    $this->logger->info('Se edito correctamente la entrevista' . $interview->id, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
576
                    $data = [
577
                        'success' => true,
578
                        'data' => 'LABEL_RECORD_UPDATED'
579
                    ];
580
                } else {
581
                    $data = [
582
                        'success' => false,
583
                        'data' => $recruitmentSelectionInterviewMapper->getError()
584
                    ];
585
                }
586
 
587
                return new JsonModel($data);
588
            } else {
589
                $messages = [];
590
                $form_messages = (array) $form->getMessages();
591
                foreach ($form_messages as $fieldname => $field_messages) {
592
                    $messages[$fieldname] = array_values($field_messages);
593
                }
594
 
595
                return new JsonModel([
596
                    'success' => false,
597
                    'data' => $messages
598
                ]);
599
            }
600
        } else if ($request->isGet()) {
601
            $hydrator = new ObjectPropertyHydrator();
602
 
2793 eleazar 603
            $candidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
604
            $candidate = $candidateMapper->fetchOne($interview->candidate_id);
3458 eleazar 605
 
2793 eleazar 606
            $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
607
            $vacancy = $vacancyMapper->fetchOne($candidate->vacancy_id);
3458 eleazar 608
 
2793 eleazar 609
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
610
            $jobDescription = $jobDescriptionMapper->fetchOne($vacancy->job_description_id);
3458 eleazar 611
 
2793 eleazar 612
            $jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
613
            $jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($jobDescription->id);
3458 eleazar 614
 
2793 eleazar 615
            $competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
616
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
617
            $behaviorCompetencyMapper = BehaviorCompetencyMapper::getInstance($this->adapter);
618
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
619
 
2757 eleazar 620
            $data = [
2793 eleazar 621
                'candidate' => [
622
                    'uuid' => $candidate->uuid,
623
                    'first_name' => $candidate->first_name,
624
                    'last_name' => $candidate->last_name,
625
                    'email' => $candidate->email
3458 eleazar 626
                ],
2793 eleazar 627
                'job_description' => [
628
                    'uuid' => $jobDescription->uuid,
629
                    'name' => $jobDescription->name,
3458 eleazar 630
                    'functions' => $jobDescription->functions,
2793 eleazar 631
                    'objectives' => $jobDescription->objectives,
632
                    'competencies' => []
3458 eleazar 633
                ],
2793 eleazar 634
                'interview' => [
2757 eleazar 635
                    'id' => $interview->uuid,
636
                    'status' => $interview->status,
637
                    'content' => $interview->content ? json_decode($interview->content) : [],
3458 eleazar 638
                    'type' => $interview->type,
639
                    'status' => $interview->status,
640
                    'points' => $interview->points,
2757 eleazar 641
                    'comment' => $interview->comment,
3634 eleazar 642
                ],
643
                'vacancy' => $vacancy,
2757 eleazar 644
            ];
645
 
2793 eleazar 646
            foreach ($jobDescriptionCompetencies as $jobDescriptionCompetency) {
647
                $competency = $competencyMapper->fetchOne($jobDescriptionCompetency->competency_id);
648
                $competencyType = $competencyTypeMapper->fetchOne($competency->competency_type_id);
649
                $behaviorCompetencies = $behaviorCompetencyMapper->fetchByCompetencyId($competency->id);
650
 
651
                $behaviors = [];
652
 
653
                foreach ($behaviorCompetencies as $behaviorCompetency) {
654
                    $behavior = $behaviorMapper->fetchOne($behaviorCompetency->behavior_id);
3458 eleazar 655
 
2853 eleazar 656
                    $behaviors []= [
2793 eleazar 657
                        'uuid' => $behavior->uuid,
658
                        'description' => $behavior->description,
659
                        'points' => 0,
2853 eleazar 660
                        'comment' => '',
661
                        'competency_uuid' => $competency->uuid,
662
                    ];
2793 eleazar 663
                }
664
 
665
                array_push($data['job_description']['competencies'], [
666
                    'competency_uuid' => $competency->uuid,
667
                    'competency_name' => $competency->name,
668
                    'competency_type_uuid' => $competencyType->uuid,
669
                    'competency_type_name' => $competencyType->name,
670
                    'behaviors' => $behaviors,
671
                ]);
672
            }
2830 eleazar 673
 
2796 eleazar 674
            return new JsonModel([
675
                'success' => true,
676
                'data' => $data
677
            ]);
2757 eleazar 678
        } else {
679
            $data = [
680
                'success' => false,
681
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
682
            ];
683
 
684
            return new JsonModel($data);
685
        }
686
 
687
        return new JsonModel($data);
2126 efrain 688
    }
1827 eleazar 689
 
2747 eleazar 690
    public function deleteAction() {
2667 eleazar 691
        $request = $this->getRequest();
692
        $currentUserPlugin = $this->plugin('currentUserPlugin');
693
        $currentCompany = $currentUserPlugin->getCompany();
694
        $currentUser = $currentUserPlugin->getUser();
695
 
696
        $request = $this->getRequest();
2789 eleazar 697
        $uuid = $this->params()->fromRoute('interview_uuid');
2667 eleazar 698
 
699
        if (!$uuid) {
700
            $data = [
701
                'success' => false,
702
                'data' => 'ERROR_INVALID_PARAMETER'
703
            ];
704
 
705
            return new JsonModel($data);
706
        }
707
 
2754 eleazar 708
        $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
709
        $recruitmentSelectionInterview = $recruitmentSelectionInterviewMapper->fetchOneByUuid($uuid);
710
        if (!$recruitmentSelectionInterview) {
2667 eleazar 711
            $data = [
712
                'success' => false,
713
                'data' => 'ERROR_RECORD_NOT_FOUND'
714
            ];
715
 
716
            return new JsonModel($data);
717
        }
718
 
2754 eleazar 719
        if ($recruitmentSelectionInterview->company_id != $currentCompany->id) {
2667 eleazar 720
            return new JsonModel([
721
                'success' => false,
722
                'data' => 'ERROR_UNAUTHORIZED'
723
            ]);
724
        }
725
 
726
        if ($request->isPost()) {
727
 
2754 eleazar 728
            $result = $recruitmentSelectionInterviewMapper->delete($recruitmentSelectionInterview->id);
2667 eleazar 729
            if ($result) {
2755 eleazar 730
                $this->logger->info('Se borro la entrevista ' . $recruitmentSelectionInterview->uuid, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2667 eleazar 731
 
732
                $data = [
733
                    'success' => true,
734
                    'data' => 'LABEL_RECORD_DELETED'
735
                ];
736
            } else {
737
 
738
                $data = [
739
                    'success' => false,
2754 eleazar 740
                    'data' => $recruitmentSelectionInterviewMapper->getError()
2667 eleazar 741
                ];
742
 
743
                return new JsonModel($data);
744
            }
745
        } else {
746
            $data = [
747
                'success' => false,
748
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
749
            ];
750
 
751
            return new JsonModel($data);
752
        }
753
 
754
        return new JsonModel($data);
755
    }
2864 eleazar 756
 
2667 eleazar 757
    public function reportAction() {
758
        $currentUserPlugin = $this->plugin('currentUserPlugin');
759
        $currentUser = $currentUserPlugin->getUser();
760
        $currentCompany = $currentUserPlugin->getCompany();
761
 
2880 eleazar 762
        $uuid = $this->params()->fromRoute('interview_uuid');
2667 eleazar 763
 
2747 eleazar 764
        $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
765
        $recruitmentSelectionInterview = $recruitmentSelectionInterviewMapper->fetchOneByUuid($uuid);
2667 eleazar 766
 
2747 eleazar 767
        $recruitmentSelectionVacancyMapper = RecruitmentSelectionvacancyMapper::getInstance($this->adapter);
768
        $recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($recruitmentSelectionInterview->vacancy_id);
769
 
770
 
771
        if (!$recruitmentSelectionInterview) {
2667 eleazar 772
            return new JsonModel([
773
                'success' => false,
774
                'data' => 'ERROR_FORM_EVALUATION_NOT_FOUND'
775
            ]);
776
        }
777
 
778
        $request = $this->getRequest();
779
        if ($request->isGet()) {
780
            //Competencies
781
 
782
            $jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
783
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
784
            $competenceTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
785
            $behaviorCompetencyMapper = BehaviorCompetencyMapper::getInstance($this->adapter);
786
            $jobDescriptionBehaviorCompetencyMapper = JobDescriptionBehaviorCompetencyMapper::getInstance($this->adapter);
787
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
788
 
789
            $competencies = [];
790
 
2747 eleazar 791
            $jobDescriptionCompetency = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($recruitmentSelectionVacancy->job_description_id);
2667 eleazar 792
 
3458 eleazar 793
            $content = json_decode($recruitmentSelectionInterview->content, true);
2898 eleazar 794
 
2667 eleazar 795
            foreach ($jobDescriptionCompetency as $record) {
796
 
797
                $competency = $competencyMapper->fetchOne($record->competency_id);
798
                $competenceType = $competenceTypeMapper->fetchOne($competency->competency_type_id);
799
 
800
                if ($competency && $competenceType) {
801
 
802
                    $behaviorCompetencies = $behaviorCompetencyMapper->fetchByCompetencyId($competency->id);
803
                    $behaviors = [];
804
 
805
                    foreach ($behaviorCompetencies as $rows) {
806
 
807
                        $behavior = $behaviorMapper->fetchOne($rows->behavior_id);
2747 eleazar 808
                        $jobDescriptionBehaviorCompetency = $jobDescriptionBehaviorCompetencyMapper->fetchOneByBehavior($recruitmentSelectionVacancy->job_description_id, $record->competency_id, $rows->behavior_id);
2667 eleazar 809
 
810
                        if ($behavior && $jobDescriptionBehaviorCompetency) {
2898 eleazar 811
                            $rowData = [
2667 eleazar 812
                                'description' => $behavior->description,
813
                                'level' => $jobDescriptionBehaviorCompetency->level,
2898 eleazar 814
                                'comment' => '',
4077 eleazar 815
                                'evaluation' => '',
4040 eleazar 816
 
2898 eleazar 817
                            ];
818
 
819
                            foreach($content as $eval) {
820
                                if ($eval['competencyUuid'] == $competency->uuid &&
821
                                    $eval['behaviorUuid'] == $behavior->uuid) {
3458 eleazar 822
 
2898 eleazar 823
                                    $rowData['comment'] = $eval['comment'];
4077 eleazar 824
                                    $rowData['evaluation'] = $eval['evaluation'];
4040 eleazar 825
 
3458 eleazar 826
 
2898 eleazar 827
                                    break;
828
                                }
829
                            }
830
 
831
                            $behaviors []= $rowData;
2667 eleazar 832
                        }
833
                    }
834
 
835
                    array_push($competencies, [
836
                        'name' => $competency->name,
837
                        'description' => $competency->description,
838
                        'type' => $competenceType->name,
839
                        'behaviors' => $behaviors
840
                    ]);
841
                }
842
            }
843
 
2747 eleazar 844
            return $this->renderPDF($currentCompany, $recruitmentSelectionInterview, $competencies);
2667 eleazar 845
        }
846
 
847
        return new JsonModel([
848
            'success' => false,
849
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
850
        ]);
2747 eleazar 851
    }
2667 eleazar 852
 
853
    /**
854
     * Render PDF
855
     * @param Company $currentCompany
2747 eleazar 856
     * @param recruitmentSelectionInterview $interviewEvaluation
2667 eleazar 857
     * @param array $competencies
858
     * @return mixed
859
     */
2864 eleazar 860
    public function renderPDF($currentCompany, $interviewEvaluation, $competencies) {
2667 eleazar 861
 
3458 eleazar 862
        $currentUserPlugin = $this->plugin('currentUserPlugin');
863
        $currentUser = $currentUserPlugin->getUser();
864
 
2667 eleazar 865
        //Generate New PDF
866
        $pdf = new InterviewPDF();
867
 
868
        $pdf->header = '';
869
        $pdf->footer = '';
870
 
871
        if ($currentCompany) {
872
            //get company Data
873
            $companyMapper = CompanyMapper::getInstance($this->adapter);
874
            $company = $companyMapper->fetchOne($currentCompany->id);
875
 
2891 eleazar 876
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
2667 eleazar 877
 
878
            $pdf->header = $company->header ? $target_path . DIRECTORY_SEPARATOR . $company->header : '';
879
            $pdf->footer = $company->footer ? $target_path . DIRECTORY_SEPARATOR . $company->footer : '';
880
        }
881
 
882
        $pdf->SetMargins(10, 0, 10);
883
 
884
        $pdf->AliasNbPages();
885
        $pdf->AddPage();
886
 
2894 eleazar 887
        $recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
888
        $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
2747 eleazar 889
        $vacancy = $recruitmentSelectionVacancyMapper->fetchOne($interviewEvaluation->vacancy_id);
2894 eleazar 890
        $candidate = $recruitmentSelectionCandidateMapper->fetchOne($interviewEvaluation->candidate_id);
2667 eleazar 891
 
4037 eleazar 892
        switch ($interviewEvaluation->type) {
4036 eleazar 893
            case "r":
4046 eleazar 894
                $type = "Recursos Humanos";
4036 eleazar 895
                break;
896
            case "b":
4038 eleazar 897
                $type = "Jefe";
4036 eleazar 898
                break;
899
            default :
900
                $type = "ERROR";
901
                break;
902
        }
903
 
4247 eleazar 904
        switch ($interviewEvaluation->points) {
905
            case "0":
906
                $points = "Sugerir otro cargo";
907
                break;
908
            case "1":
909
                $points = "25%";
910
                break;
911
            case "2":
912
                $points = "50%";
913
                break;
914
            case "3":
915
                $points = "75%";
916
                break;
917
            case "4":
918
                $points = "100%";
919
                break;
920
            default :
921
                $points = "ERROR";
922
                break;
923
        }
924
 
2667 eleazar 925
        $rows = [
926
            array(
927
                'title' => 'Nombre Evaluado: ',
3458 eleazar 928
                'content' => $candidate ? ' ' . $candidate->first_name . ' ' . $candidate->last_name : 'No Aplica'
2667 eleazar 929
            ),
930
            array(
931
                'title' => 'Cargo: ',
2747 eleazar 932
                'content' => $vacancy ? ' ' . $vacancy->name : ' No aplica'
2667 eleazar 933
            ),
934
            array(
3458 eleazar 935
                'title' => 'Entrevistado por: ',
936
                'content' => $currentUser ? ' ' . $currentUser->first_name . ' ' . $currentUser->last_name : ' No Aplica '
2667 eleazar 937
            ),
938
            array(
3458 eleazar 939
                'title' => 'Estatus del candidato: ',
4036 eleazar 940
                'content' => $type
2667 eleazar 941
            ),
942
            array(
3458 eleazar 943
                'title' => 'Comentarios del entrevistador: ',
944
                'content' => $interviewEvaluation ? ' ' . $interviewEvaluation->comment : 'No Aplica'
2667 eleazar 945
            ),
946
            array(
3458 eleazar 947
                'title' => 'Porcentage de adaptibilidad ',
4247 eleazar 948
                'content' => $points
2667 eleazar 949
            )
950
        ];
951
 
2922 eleazar 952
        $pdf->borderTable('DATOS DE LA ENTREVISTA', $rows);
4050 eleazar 953
 
954
        $sections = json_decode($interviewEvaluation->content, true);
4052 eleazar 955
        /*
4050 eleazar 956
                for ($s = 0; $s < count($sections); $s++) {
957
 
958
                    $pdf->singleTable($sections[$s]['title'], [
959
                        array(
960
                            'content' => $sections[$s]['type'] != 'multiple' ? $sections[$s]['text'] : ''
961
                    )]);
962
 
963
                    if ($sections[$s]['type'] == 'multiple') {
964
 
965
                        $pdf->titleOptionTable($sections[$s]['text']);
966
 
967
                        for ($o = 0; $o < count($sections[$s]['options']); $o++) {
968
 
969
                            $pdf->optionTable($sections[$s]['options'][$o]['title']);
970
                        }
971
                        $pdf->Ln();
972
                    }
973
                    if ($s % 2 == 0 && $s > 1) {
974
                        $pdf->AddPage();
975
                    }
4052 eleazar 976
                }*/
4050 eleazar 977
 
3458 eleazar 978
        // Competencies
2667 eleazar 979
        if (count($competencies) != 0) {
980
 
4053 eleazar 981
            // add new page
2667 eleazar 982
 
983
            $pdf->AddPage();
984
 
985
            $competencies_header[] = array('content' => 'Indique el nivel de desempeño del evaluado en relación a sus conductas y actitudes frente a cada valor, según la clasificación siguiente:');
986
 
987
            $pdf->singleTable('Anexo de valores:', $competencies_header);
988
 
989
 
990
            // Add scale section
991
            $pdf->sectionScale();
992
 
993
            $i = 0;
4053 eleazar 994
 
995
            foreach ($competencies as $record) {
996
 
997
                $i = $i + 1;
998
 
999
                $pdf->competencyTable($i, $record);
1000
 
1001
                if ($i % 3 == 0 && $i < count($competencies)) {
1002
                    $pdf->AddPage();
1003
                }
1004
            }
4029 eleazar 1005
 
2893 eleazar 1006
        }
4027 eleazar 1007
 
2667 eleazar 1008
        return $pdf->Output();
4027 eleazar 1009
 
2864 eleazar 1010
    }
1709 eleazar 1011
}