Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 1709 Rev 15461
Línea 5... Línea 5...
5
namespace LeadersLinked\Controller;
5
namespace LeadersLinked\Controller;
Línea 6... Línea 6...
6
 
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
7
use Laminas\Db\Adapter\AdapterInterface;
8
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
8
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
-
 
9
use Laminas\Mvc\Controller\AbstractActionController;
9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Mvc\I18n\Translator;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\Log\LoggerInterface;
-
 
12
use Laminas\View\Model\JsonModel;
-
 
13
use LeadersLinked\Mapper\RecruitmentSelectionApplicationMapper;
-
 
14
use LeadersLinked\Mapper\RecruitmentSelectionCandidateMapper;
-
 
15
use LeadersLinked\Mapper\RecruitmentSelectionInterviewMapper;
-
 
16
use LeadersLinked\Mapper\RecruitmentSelectionVacancyMapper;
-
 
17
use LeadersLinked\Mapper\UserMapper;
-
 
18
use LeadersLinked\Model\RecruitmentSelectionApplication;
-
 
19
use LeadersLinked\Model\RecruitmentSelectionInterview;
-
 
20
use LeadersLinked\Model\RecruitmentSelectionVacancy;
-
 
21
use LeadersLinked\Form\RecruitmentSelection\RecruitmentSelectionApplicationInterviewForm;
-
 
22
use LeadersLinked\Library\Functions;
Línea 11... Línea 23...
11
use Laminas\View\Model\JsonModel;
23
use LeadersLinked\Library\RecruitmentSelectionInterviewPDF;
Línea 12... Línea 24...
12
 
24
 
13
class RecruitmentSelectionInterviewController extends AbstractActionController {
25
class RecruitmentSelectionInterviewController extends AbstractActionController {
14
 
26
 
15
    /**
27
    /**
16
     *
28
     *
17
     * @var AdapterInterface
29
     * @var AdapterInterface
18
     */
30
     */
19
    private $adapter;
31
    private $adapter;
20
 
32
    
21
    /**
33
    /**
22
     *
34
     *
23
     * @var AbstractAdapter
35
     * @var AbstractAdapter
24
     */
36
     */
25
    private $cache;
37
    private $cache;
26
 
38
    
27
    /**
39
    /**
28
     *
40
     *
29
     * @var  LoggerInterface
41
     * @var  LoggerInterface
30
     */
42
     */
31
    private $logger;
43
    private $logger;
32
 
44
    
33
    /**
45
    /**
34
     *
46
     *
35
     * @var array
47
     * @var array
-
 
48
     */
-
 
49
    private $config;
-
 
50
    
-
 
51
    /**
-
 
52
     *
-
 
53
     * @var Translator
36
     */
54
     */
37
    private $config;
55
    private $translator;
38
 
56
    
39
    /**
57
    /**
40
     *
58
     *
41
     * @param AdapterInterface $adapter
59
     * @param AdapterInterface $adapter
-
 
60
     * @param AbstractAdapter $cache
42
     * @param AbstractAdapter $cache
61
     * @param LoggerInterface $logger
43
     * @param LoggerInterface $logger
62
     * @param array $config
-
 
63
     * @param Translator $translator
44
     * @param array $config
64
     */
45
     */
65
    public function __construct($adapter, $cache, $logger, $config, $translator)
46
    public function __construct($adapter, $cache, $logger, $config) {
66
    {
47
        $this->adapter = $adapter;
67
        $this->adapter = $adapter;
-
 
68
        $this->cache = $cache;
48
        $this->cache = $cache;
69
        $this->logger = $logger;
Línea 49... Línea 70...
49
        $this->logger = $logger;
70
        $this->config = $config;
-
 
71
        $this->translator = $translator;
50
        $this->config = $config;
72
    }
51
    }
73
 
52
 
74
    public function indexAction()
53
    public function indexAction() {
75
    {
-
 
76
        
-
 
77
        $data = [
-
 
78
            'success' => false,
-
 
79
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
80
        ];
-
 
81
            
-
 
82
        return new JsonModel($data);
-
 
83
 
-
 
84
    }
-
 
85
    
-
 
86
    public function addAction()
-
 
87
    {
-
 
88
        $request = $this->getRequest();
-
 
89
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
90
        $currentCompany = $currentUserPlugin->getCompany();
-
 
91
        $currentUser = $currentUserPlugin->getUser();
-
 
92
        
-
 
93
        $request = $this->getRequest();
-
 
94
        $application_id = $this->params()->fromRoute('application_id');
-
 
95
        
-
 
96
        $vacancy_uuid = $this->params()->fromRoute('vacancy_id');
-
 
97
        
-
 
98
        $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
-
 
99
        $vacancy = $vacancyMapper->fetchOneByUuid($vacancy_uuid);
-
 
100
        
-
 
101
        if(!$vacancy) {
-
 
102
            $data = [
-
 
103
                'success' => false,
-
 
104
                'data' => 'ERROR_VACANCY_NOT_FOUND'
-
 
105
            ];
-
 
106
            
-
 
107
            return new JsonModel($data);
-
 
108
        }
-
 
109
        
-
 
110
        
-
 
111
        if($vacancy->company_id != $currentCompany->id) {
-
 
112
            $data = [
-
 
113
                'success' => false,
-
 
114
                'data' => 'ERROR_VACANCY_IS_OTHER_COMPANY',
-
 
115
            ];
-
 
116
            
-
 
117
            return new JsonModel($data);
-
 
118
        }
-
 
119
        
-
 
120
        
-
 
121
        
-
 
122
        $applicationMapper = RecruitmentSelectionApplicationMapper::getInstance($this->adapter);
-
 
123
        $application = $applicationMapper->fetchOneByUuid($application_id);
-
 
124
        
-
 
125
        
-
 
126
        if (!$application) {
-
 
127
            $data = [
-
 
128
                'success' => false,
-
 
129
                'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
130
            ];
-
 
131
            
-
 
132
            return new JsonModel($data);
-
 
133
        }
-
 
134
        
-
 
135
        
-
 
136
        if ($application->vacancy_id != $vacancy->id) {
-
 
137
            return new JsonModel([
-
 
138
                'success' => false,
-
 
139
                'data' => 'ERROR_UNAUTHORIZED'
-
 
140
            ]);
-
 
141
        }
-
 
142
        
-
 
143
        if($request->isPost()) {
-
 
144
            $form = new  RecruitmentSelectionApplicationInterviewForm($this->adapter, $currentCompany->id);
-
 
145
            
-
 
146
            $dataPost = $request->getPost()->toArray();
-
 
147
            
-
 
148
            if(!empty($dataPost['last_date'])) {
-
 
149
                $dt = \DateTime::createFromFormat('d/m/Y', $dataPost['last_date']);
-
 
150
                if($dt) {
-
 
151
                    $dataPost['last_date'] = $dt->format('Y-m-d');
-
 
152
                } else {
-
 
153
                    $dataPost['last_date'] = '';
-
 
154
                }
-
 
155
                
-
 
156
            }
-
 
157
            
-
 
158
            
-
 
159
            $form->setData($dataPost);
-
 
160
            
-
 
161
            if($form->isValid()) {
-
 
162
                
-
 
163
                $dataPost = (array) $form->getData();
-
 
164
                $userMapper = UserMapper::getInstance($this->adapter);
-
 
165
                $user = $userMapper->fetchOneByUuid($dataPost['user_id']);
-
 
166
                
-
 
167
                
-
 
168
                
-
 
169
                $interview = new RecruitmentSelectionInterview();
-
 
170
                $interview->company_id = $currentCompany->id;
-
 
171
                $interview->application_id = $application->id;
-
 
172
                $interview->candidate_id = $application->candidate_id;
-
 
173
                $interview->vacancy_id = $application->vacancy_id;
-
 
174
                $interview->interviewer_id = $user->id;
-
 
175
                $interview->type = $dataPost['type'];
-
 
176
                $interview->last_date = $dataPost['last_date'];
-
 
177
                $interview->comment = '';
-
 
178
                $interview->points = 0;
-
 
179
                
-
 
180
                
-
 
181
 
-
 
182
                
-
 
183
                $interviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
-
 
184
                
-
 
185
                if($interviewMapper->insert($interview)) {
-
 
186
                    
-
 
187
 
-
 
188
                     
-
 
189
                   $this->logger->info('Se agrego la entrevista : '  . $user->first_name . ' ' . $user->last_name . ' (' . $user->email . ')', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
190
                   $data = [
-
 
191
                        'success'   => true,
-
 
192
                        'data'   => [
-
 
193
                            'message' => 'LABEL_RECORD_ADDED',
-
 
194
                            'interviews' => $this->renderInterview($vacancy, $application)
-
 
195
                            ],
-
 
196
                    ];
-
 
197
       
-
 
198
                } else {
-
 
199
                    $data = [
-
 
200
                        'success'   => false,
-
 
201
                        'data'      => $interviewMapper->getError()
-
 
202
                    ];
-
 
203
                    
-
 
204
                }
-
 
205
                
-
 
206
                return new JsonModel($data);
-
 
207
                
-
 
208
            } else {
-
 
209
                $messages = [];
-
 
210
                $form_messages = (array) $form->getMessages();
-
 
211
                foreach ($form_messages as $fieldname => $field_messages) {
-
 
212
                    $messages[$fieldname] = array_values($field_messages);
-
 
213
                }
-
 
214
                
-
 
215
                return new JsonModel([
-
 
216
                    'success' => false,
-
 
217
                    'data' => $messages
-
 
218
                ]);
-
 
219
                
-
 
220
            }
-
 
221
            
-
 
222
        } else {
-
 
223
            $data = [
-
 
224
                'success' => false,
-
 
225
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
226
            ];
-
 
227
            
-
 
228
            return new JsonModel($data);
-
 
229
        }
-
 
230
        
-
 
231
    }
-
 
232
    
-
 
233
    
-
 
234
    public function editAction()
-
 
235
    {
-
 
236
        $request = $this->getRequest();
-
 
237
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
238
        $currentCompany = $currentUserPlugin->getCompany();
-
 
239
        $currentUser = $currentUserPlugin->getUser();
-
 
240
        
-
 
241
        $request = $this->getRequest();
-
 
242
        $application_id = $this->params()->fromRoute('application_id');
-
 
243
        $vacancy_uuid = $this->params()->fromRoute('vacancy_id');
-
 
244
        $id = $this->params()->fromRoute('id');
-
 
245
        
-
 
246
        $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
-
 
247
        $vacancy = $vacancyMapper->fetchOneByUuid($vacancy_uuid);
-
 
248
        
-
 
249
        if(!$vacancy) {
-
 
250
            $data = [
-
 
251
                'success' => false,
-
 
252
                'data' => 'ERROR_VACANCY_NOT_FOUND'
-
 
253
            ];
-
 
254
            
-
 
255
            return new JsonModel($data);
-
 
256
        }
-
 
257
        
-
 
258
        
-
 
259
        if($vacancy->company_id != $currentCompany->id) {
-
 
260
            $data = [
-
 
261
                'success' => false,
-
 
262
                'data' => 'ERROR_VACANCY_IS_OTHER_COMPANY',
-
 
263
            ];
-
 
264
            
-
 
265
            return new JsonModel($data);
-
 
266
        }
-
 
267
        
-
 
268
        
-
 
269
        
-
 
270
        $applicationMapper = RecruitmentSelectionApplicationMapper::getInstance($this->adapter);
-
 
271
        $application = $applicationMapper->fetchOneByUuid($application_id);
-
 
272
        
-
 
273
        
-
 
274
        if (!$application) {
-
 
275
            $data = [
-
 
276
                'success' => false,
-
 
277
                'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
278
            ];
-
 
279
            
-
 
280
            return new JsonModel($data);
-
 
281
        }
-
 
282
        
-
 
283
        
-
 
284
        if ($application->vacancy_id != $vacancy->id) {
-
 
285
            return new JsonModel([
-
 
286
                'success' => false,
-
 
287
                'data' => 'ERROR_UNAUTHORIZED'
-
 
288
            ]);
-
 
289
        }
-
 
290
        
-
 
291
 
-
 
292
        $interviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
-
 
293
        $interview = $interviewMapper->fetchOneByUuid($id);
-
 
294
        if(!$interview) {
-
 
295
            return new JsonModel([
-
 
296
                'success' => false,
-
 
297
                'data' => 'ERROR_INTERVIEW_NOT_FOUND'
-
 
298
            ]);
-
 
299
        }
-
 
300
        
-
 
301
        if($interview->application_id != $application->id) {
-
 
302
            return new JsonModel([
-
 
303
                'success' => false,
-
 
304
                'data' => 'ERROR_UNAUTHORIZED'
-
 
305
            ]);
-
 
306
        }
-
 
307
        
-
 
308
        
-
 
309
        if($interview->status != RecruitmentSelectionInterview::STATUS_PENDING) {
-
 
310
            return new JsonModel([
-
 
311
                'success' => false,
-
 
312
                'data' => 'ERROR_INTERVIEW_HAS_ALREADY_BEEN_DONE'
-
 
313
            ]);
-
 
314
            
-
 
315
        }
-
 
316
        
-
 
317
        if($request->isGet()) {
-
 
318
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
319
            $user = $userMapper->fetchOne($interview->interviewer_id);
-
 
320
            
-
 
321
            $dt = \DateTime::createFromFormat('Y-m-d', $interview->last_date);
-
 
322
            
-
 
323
            return new JsonModel([
-
 
324
                'success' => true,
-
 
325
                'data' => [
-
 
326
                    'user_id' => $user->uuid,
-
 
327
                    'type' => $interview->type,
-
 
328
                    'last_date' => $dt->format('d/m/Y')
-
 
329
                ]
-
 
330
            ]);
-
 
331
            
-
 
332
            
-
 
333
        } else  if($request->isPost()) {
-
 
334
            $form = new  RecruitmentSelectionApplicationInterviewForm($this->adapter, $currentCompany->id);
-
 
335
            $dataPost = $request->getPost()->toArray();
-
 
336
            if(!empty($dataPost['last_date'])) {
-
 
337
                $dt = \DateTime::createFromFormat('d/m/Y', $dataPost['last_date']);
-
 
338
                if($dt) {
-
 
339
                    $dataPost['last_date'] = $dt->format('Y-m-d');
-
 
340
                } else {
-
 
341
                    $dataPost['last_date'] = '';
-
 
342
                }
-
 
343
                
-
 
344
            }
-
 
345
            
-
 
346
            $form->setData($dataPost);
-
 
347
            
-
 
348
            if($form->isValid()) {
-
 
349
                
-
 
350
                $dataPost = (array) $form->getData();
-
 
351
                $userMapper = UserMapper::getInstance($this->adapter);
-
 
352
                $user = $userMapper->fetchOneByUuid($dataPost['user_id']);
-
 
353
                
-
 
354
                
-
 
355
                $interview->interviewer_id = $user->id;
-
 
356
                $interview->type = $dataPost['type'];
-
 
357
                $interview->last_date = $dataPost['last_date'];
-
 
358
                
-
 
359
                $interviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
-
 
360
                
-
 
361
                if($interviewMapper->update($interview)) {
-
 
362
                    
-
 
363
                    
-
 
364
                    
-
 
365
                    $this->logger->info('Se actualizo la entrevista : '  . $user->first_name . ' ' . $user->last_name . ' (' . $user->email . ')', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
366
                    $data = [
-
 
367
                        'success'   => true,
-
 
368
                        'data'   => [
-
 
369
                            'message' => 'LABEL_RECORD_UPDATED',
-
 
370
                            'interviews' => $this->renderInterview($vacancy, $application)
-
 
371
                        ],
-
 
372
                    ];
-
 
373
                    
-
 
374
                } else {
-
 
375
                    $data = [
-
 
376
                        'success'   => false,
-
 
377
                        'data'      => $interviewMapper->getError()
-
 
378
                    ];
-
 
379
                    
-
 
380
                }
-
 
381
                
-
 
382
                return new JsonModel($data);
-
 
383
                
-
 
384
            } else {
-
 
385
                $messages = [];
-
 
386
                $form_messages = (array) $form->getMessages();
-
 
387
                foreach ($form_messages as $fieldname => $field_messages) {
-
 
388
                    $messages[$fieldname] = array_values($field_messages);
-
 
389
                }
-
 
390
                
-
 
391
                return new JsonModel([
-
 
392
                    'success' => false,
-
 
393
                    'data' => $messages
-
 
394
                ]);
-
 
395
                
-
 
396
            }
-
 
397
            
-
 
398
            
-
 
399
            
-
 
400
        } else {
-
 
401
            $data = [
-
 
402
                'success' => false,
-
 
403
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
404
            ];
-
 
405
            
-
 
406
            return new JsonModel($data);
-
 
407
        }
-
 
408
        
-
 
409
    }
-
 
410
    
-
 
411
    
-
 
412
    public function deleteAction()
-
 
413
    {
-
 
414
        $request = $this->getRequest();
-
 
415
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
416
        $currentCompany = $currentUserPlugin->getCompany();
-
 
417
        $currentUser = $currentUserPlugin->getUser();
-
 
418
        
-
 
419
        $request = $this->getRequest();
-
 
420
        $application_id = $this->params()->fromRoute('application_id');
-
 
421
        
-
 
422
        $vacancy_uuid = $this->params()->fromRoute('vacancy_id');
-
 
423
        $id = $this->params()->fromRoute('id');
-
 
424
        
-
 
425
        
-
 
426
        $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
-
 
427
        $vacancy = $vacancyMapper->fetchOneByUuid($vacancy_uuid);
-
 
428
        
-
 
429
        if(!$vacancy) {
-
 
430
            $data = [
-
 
431
                'success' => false,
-
 
432
                'data' => 'ERROR_VACANCY_NOT_FOUND'
-
 
433
            ];
-
 
434
            
-
 
435
            return new JsonModel($data);
-
 
436
        }
-
 
437
        
-
 
438
        
-
 
439
        if($vacancy->company_id != $currentCompany->id) {
-
 
440
            $data = [
-
 
441
                'success' => false,
-
 
442
                'data' => 'ERROR_VACANCY_IS_OTHER_COMPANY',
-
 
443
            ];
-
 
444
            
-
 
445
            return new JsonModel($data);
-
 
446
        }
-
 
447
        
-
 
448
        
-
 
449
        
-
 
450
        $applicationMapper = RecruitmentSelectionApplicationMapper::getInstance($this->adapter);
-
 
451
        $application = $applicationMapper->fetchOneByUuid($application_id);
-
 
452
        
-
 
453
        
-
 
454
        if (!$application) {
-
 
455
            $data = [
-
 
456
                'success' => false,
-
 
457
                'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
458
            ];
-
 
459
            
-
 
460
            return new JsonModel($data);
-
 
461
        }
-
 
462
        
-
 
463
        
-
 
464
        if ($application->vacancy_id != $vacancy->id) {
-
 
465
            return new JsonModel([
-
 
466
                'success' => false,
-
 
467
                'data' => 'ERROR_UNAUTHORIZED'
-
 
468
            ]);
-
 
469
        }
-
 
470
        
-
 
471
        
-
 
472
        $interviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
-
 
473
        $interview = $interviewMapper->fetchOneByUuid($id);
-
 
474
        if(!$interview) {
-
 
475
            return new JsonModel([
-
 
476
                'success' => false,
-
 
477
                'data' => 'ERROR_INTERVIEW_NOT_FOUND'
-
 
478
            ]);
-
 
479
        }
-
 
480
        
-
 
481
        if($interview->application_id != $application->id) {
-
 
482
            return new JsonModel([
-
 
483
                'success' => false,
-
 
484
                'data' => 'ERROR_UNAUTHORIZED'
-
 
485
            ]);
-
 
486
        }
-
 
487
        
-
 
488
        
-
 
489
        if($interview->status != RecruitmentSelectionInterview::STATUS_PENDING) {
-
 
490
            return new JsonModel([
-
 
491
                'success' => false,
-
 
492
                'data' => 'ERROR_INTERVIEW_HAS_ALREADY_BEEN_DONE'
-
 
493
            ]);
-
 
494
            
-
 
495
        }
-
 
496
        
-
 
497
        if($request->isPost()) {
-
 
498
           
-
 
499
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
500
            $user = $userMapper->fetchOne($interview->interviewer_id);
-
 
501
            
-
 
502
            
-
 
503
            if($interviewMapper->delete($interview->id)) {
-
 
504
                
-
 
505
                $this->logger->info('Se borro la entrevista : '  . $user->first_name . ' ' . $user->last_name . ' (' . $user->email . ')', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
506
                $data = [
-
 
507
                    'success'   => true,
-
 
508
                    'data'   => [
-
 
509
                        'message' => 'LABEL_RECORD_DELETE',
-
 
510
                        'interviews' => $this->renderInterview($vacancy, $application)
-
 
511
                    ],
-
 
512
                ];
-
 
513
                
-
 
514
            } else {
-
 
515
                $data = [
-
 
516
                    'success'   => false,
-
 
517
                    'data'      => $interviewMapper->getError()
-
 
518
                ];
-
 
519
                
-
 
520
            }
-
 
521
            
-
 
522
           
-
 
523
            
-
 
524
        } else {
-
 
525
            $data = [
-
 
526
                'success' => false,
-
 
527
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
528
            ];
-
 
529
            
-
 
530
            return new JsonModel($data);
-
 
531
        }
-
 
532
        
-
 
533
    }
-
 
534
    
-
 
535
    /**
-
 
536
     *
-
 
537
     * @param RecruitmentSelectionVacancy $vacany
-
 
538
     * @param RecruitmentSelectionApplication $application
-
 
539
     * @return array
-
 
540
     */
-
 
541
    public function renderInterview($vacancy, $application)
-
 
542
    {
-
 
543
        $userMapper = UserMapper::getInstance($this->adapter);
-
 
544
        $interviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
-
 
545
        
-
 
546
        
-
 
547
        
-
 
548
        
-
 
549
        $interviews = [];
-
 
550
        $records = $interviewMapper->fetchAllByVacancyId($vacancy->id);
-
 
551
        foreach($records as $record)
-
 
552
        {
-
 
553
            $status = '';
-
 
554
            switch($record->status)
-
 
555
            {
-
 
556
                case RecruitmentSelectionInterview::STATUS_ACCEPTED :
-
 
557
                    $status = 'LABEL_ACCEPTED';
-
 
558
                    $link_report = $this->url()->fromRoute('recruitment-and-selection/applications/interviews/report', ['vacancy_id' => $vacancy->uuid, 'application_id' => $application->uuid, 'id' => $record->uuid]);
-
 
559
                    break;
-
 
560
                    
-
 
561
                case RecruitmentSelectionInterview::STATUS_PENDING :
-
 
562
                    $link_view = '';
-
 
563
                    $link_report = 'LABEL_PENDING';
-
 
564
                    break;
-
 
565
                    
-
 
566
                case RecruitmentSelectionInterview::STATUS_REJECTED :
-
 
567
                    $link_view = $this->url()->fromRoute('recruitment-and-selection/applications/interviews/report', ['vacancy_id' => $vacancy->uuid, 'application_id' => $application->uuid, 'id' => $record->uuid]);
-
 
568
                    $link_report = 'LABEL_REJECTED';
-
 
569
                    break;
-
 
570
                    
-
 
571
                default :
-
 
572
                    $link_report = '';
-
 
573
                    $status = 'LABEL_UNKNOWN';
-
 
574
                    break;
-
 
575
                    
-
 
576
            }
-
 
577
            
-
 
578
            $type = '';
-
 
579
            switch($record->type)
-
 
580
            {
-
 
581
                case RecruitmentSelectionInterview::TYPE_BOSS :
-
 
582
                    $type = 'LABEL_BOSS_INTERVIEW';
-
 
583
                    break;
-
 
584
                    
-
 
585
                case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE :
-
 
586
                    $type = 'LABEL_HUMAN_RESOURCE';
-
 
587
                    break;
-
 
588
                    
-
 
589
                default :
-
 
590
                    $type = 'LABEL_UNKNOWN';
-
 
591
                    break;
-
 
592
                    
-
 
593
            }
-
 
594
            
-
 
595
            $dt = \DateTime::createFromFormat('Y-m-d',  $record->last_date);
-
 
596
            $last_date = $dt->format('d/m/Y');
-
 
597
            
-
 
598
            if($record->actual_date) {
-
 
599
            
-
 
600
                $dt = \DateTime::createFromFormat('Y-m-d',  $record->actual_date);
-
 
601
                $actual_date = $dt->format('d/m/Y');
-
 
602
            } else {
-
 
603
                $actual_date = '';
-
 
604
            }
-
 
605
            
-
 
606
            $user = $userMapper->fetchOne($record->interviewer_id);
-
 
607
            $interviewer = $user->first_name . ' ' . $user->last_name  . '(' . $user->email . ')';
-
 
608
            
-
 
609
            
-
 
610
            
-
 
611
            
-
 
612
            array_push($interviews, [
-
 
613
                'type' => $type,
-
 
614
                'status' => $status,
-
 
615
                'last_date' => $last_date,
-
 
616
                'actual_date' => $actual_date,
-
 
617
                'interviewer' => $interviewer,
-
 
618
                'points' => $record->points,
-
 
619
                'link_edit' => $this->url()->fromRoute('recruitment-and-selection/applications/interviews/edit', ['vacancy_id' => $vacancy->uuid, 'application_id' => $application->uuid, 'id' => $record->uuid]),
-
 
620
                'link_report' => $link_report,
-
 
621
                'link_delete' => $this->url()->fromRoute('recruitment-and-selection/applications/interviews/delete', ['vacancy_id' => $vacancy->uuid, 'application_id' => $application->uuid, 'id' => $record->uuid]),
-
 
622
                
-
 
623
            ]);
-
 
624
        }
-
 
625
        
-
 
626
        return $interviews;
-
 
627
        
-
 
628
    }
-
 
629
    
-
 
630
    public function reportAction()
-
 
631
    {
-
 
632
        $request = $this->getRequest();
-
 
633
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
634
        $currentCompany = $currentUserPlugin->getCompany();
-
 
635
        $currentUser = $currentUserPlugin->getUser();
-
 
636
        
-
 
637
        $request = $this->getRequest();
-
 
638
        $application_id = $this->params()->fromRoute('application_id');
-
 
639
        
-
 
640
        $vacancy_uuid = $this->params()->fromRoute('vacancy_id');
-
 
641
        $id = $this->params()->fromRoute('id');
-
 
642
        
-
 
643
        
-
 
644
        $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
-
 
645
        $vacancy = $vacancyMapper->fetchOneByUuid($vacancy_uuid);
-
 
646
        
-
 
647
        if(!$vacancy) {
-
 
648
            $data = [
-
 
649
                'success' => false,
-
 
650
                'data' => 'ERROR_VACANCY_NOT_FOUND'
-
 
651
            ];
-
 
652
            
-
 
653
            return new JsonModel($data);
-
 
654
        }
-
 
655
        
-
 
656
        
-
 
657
        if($vacancy->company_id != $currentCompany->id) {
-
 
658
            $data = [
-
 
659
                'success' => false,
-
 
660
                'data' => 'ERROR_VACANCY_IS_OTHER_COMPANY',
-
 
661
            ];
-
 
662
            
-
 
663
            return new JsonModel($data);
-
 
664
        }
-
 
665
        
-
 
666
        
-
 
667
        
-
 
668
        $applicationMapper = RecruitmentSelectionApplicationMapper::getInstance($this->adapter);
-
 
669
        $application = $applicationMapper->fetchOneByUuid($application_id);
-
 
670
        
-
 
671
        
-
 
672
        if (!$application) {
-
 
673
            $data = [
-
 
674
                'success' => false,
-
 
675
                'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
676
            ];
-
 
677
            
-
 
678
            return new JsonModel($data);
-
 
679
        }
-
 
680
        
-
 
681
        
-
 
682
        if ($application->vacancy_id != $vacancy->id) {
-
 
683
            return new JsonModel([
-
 
684
                'success' => false,
-
 
685
                'data' => 'ERROR_UNAUTHORIZED'
-
 
686
            ]);
-
 
687
        }
-
 
688
        
-
 
689
        
-
 
690
        $interviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
-
 
691
        $interview = $interviewMapper->fetchOneByUuid($id);
-
 
692
        if(!$interview) {
-
 
693
            return new JsonModel([
-
 
694
                'success' => false,
-
 
695
                'data' => 'ERROR_INTERVIEW_NOT_FOUND'
-
 
696
            ]);
-
 
697
        }
-
 
698
        
-
 
699
        if($interview->application_id != $application->id) {
-
 
700
            return new JsonModel([
-
 
701
                'success' => false,
-
 
702
                'data' => 'ERROR_UNAUTHORIZED'
-
 
703
            ]);
-
 
704
        }
-
 
705
        
-
 
706
        if($interview->status == RecruitmentSelectionInterview::STATUS_PENDING) {
-
 
707
            return new JsonModel([
-
 
708
                'success' => false,
-
 
709
                'data' =>   'ERROR_RECORD_IS_PENDING'
-
 
710
            ]);
-
 
711
            
-
 
712
        }
-
 
713
        
-
 
714
        
-
 
715
        
-
 
716
        $request = $this->getRequest();
-
 
717
        if ($request->isGet()) {
-
 
718
            
-
 
719
            switch( $interview->type)
-
 
720
            {
-
 
721
                case RecruitmentSelectionInterview::TYPE_BOSS :
-
 
722
                    $type = $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_TYPE_BOTH');
-
 
723
                    break;
-
 
724
                    
-
 
725
                case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE :
-
 
726
                    $type = $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_TYPE_HUMAN_RESOURCE');
-
 
727
                    break;
-
 
728
                    
-
 
729
                    
-
 
730
                    
-
 
731
                default :
-
 
732
                    $type = $this->translator->translate('LABEL_UNKNOWN');
-
 
733
                    break;
-
 
734
            }
-
 
735
            
-
 
736
            
-
 
737
            $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
-
 
738
            $recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($interview->vacancy_id);
-
 
739
            
-
 
740
            
-
 
741
            $recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
-
 
742
            $recruitmentSelectionCandidate = $recruitmentSelectionCandidateMapper->fetchOne($interview->candidate_id);
-
 
743
            
-
 
744
            $filename = $recruitmentSelectionVacancy->name . '-' . trim($recruitmentSelectionCandidate->first_name) . '-' . trim($recruitmentSelectionCandidate->last_name)  . '-' . $type . '-' . date('Y-m-d H:i a') . '.pdf';
-
 
745
            
-
 
746
            $filename = Functions::normalizeStringFilename( $filename );
-
 
747
            
-
 
748
            
-
 
749
            
-
 
750
            
-
 
751
            $content = base64_encode($this->renderPDF($interview));
-
 
752
            $data = [
-
 
753
                'success' => true,
-
 
754
                'data' => [
-
 
755
                    'basename' => $filename,
-
 
756
                    'content' => $content
-
 
757
                ]
-
 
758
            ];
-
 
759
            
-
 
760
            return new JsonModel($data);
-
 
761
            
-
 
762
            /*
-
 
763
            
-
 
764
            $content = $this->renderPdf($currentCompany, $jobDescription);
-
 
765
            $response = new Response();
-
 
766
            $response->setStatusCode(200);
-
 
767
            $response->setContent($content);
-
 
768
            
-
 
769
            
-
 
770
            
-
 
771
            $headers = $response->getHeaders();
-
 
772
            $headers->clearHeaders();
-
 
773
            
-
 
774
            $headers->addHeaderLine('Content-Description: File Transfer');
-
 
775
            $headers->addHeaderLine('Content-Type: application/pdf');
-
 
776
            //$headers->addHeaderLine('Content-Disposition: attachment; filename=' . $filename);
-
 
777
            $headers->addHeaderLine('Content-Transfer-Encoding: binary');
-
 
778
            $headers->addHeaderLine('Expires: 0');
-
 
779
            $headers->addHeaderLine('Cache-Control: must-revalidate');
-
 
780
            $headers->addHeaderLine('Pragma: public');
-
 
781
            return $response;
-
 
782
            */
-
 
783
            
-
 
784
            
-
 
785
            
-
 
786
            
-
 
787
            return ;
-
 
788
        } else {
-
 
789
            
-
 
790
            
-
 
791
            return new JsonModel([
-
 
792
                'success' => false,
-
 
793
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
794
            ]);
-
 
795
        }
-
 
796
    }
-
 
797
    
-
 
798
    /**
-
 
799
     * Render PDF
-
 
800
     * @param RecruitmentSelectionInterview $recruitmentSelectionInterview
-
 
801
     
-
 
802
     * @return mixed
-
 
803
     */
-
 
804
    private function renderPDF($recruitmentSelectionInterview)
-
 
805
    {
-
 
806
        $request = $this->getRequest();
-
 
807
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
808
        $currentCompany = $currentUserPlugin->getCompany();
-
 
809
        $currentUser = $currentUserPlugin->getUser();
-
 
810
        
-
 
811
        
-
 
812
        //Generate New PDF
-
 
813
        $pdf = new RecruitmentSelectionInterviewPDF();
-
 
814
        
-
 
815
        $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $currentCompany->uuid;
-
 
816
        $header = $currentCompany->header ? $target_path . DIRECTORY_SEPARATOR . $currentCompany->header : '';
-
 
817
        if (empty($header) || !file_exists($header)) {
-
 
818
            $header = $this->config['leaderslinked.images_default.company_pdf_header'];
-
 
819
        }
-
 
820
        
-
 
821
        $footer = $currentCompany->footer ? $target_path . DIRECTORY_SEPARATOR . $currentCompany->footer : '';
-
 
822
        if (empty($footer) || !file_exists($footer)) {
-
 
823
            $footer = $this->config['leaderslinked.images_default.company_pdf_footer'];
-
 
824
        }
-
 
825
        
-
 
826
        $content = json_decode($recruitmentSelectionInterview->content);
-
 
827
        
-
 
828
        $pdf->header = $header;
-
 
829
        $pdf->footer = $footer;
-
 
830
        $pdf->translator = $this->translator;
-
 
831
        
-
 
832
        $pdf->SetMargins(10, 0, 10);
-
 
833
        
-
 
834
        $pdf->AliasNbPages();
-
 
835
        $pdf->AddPage();
-
 
836
        
-
 
837
        switch( $recruitmentSelectionInterview->type)
-
 
838
        {
-
 
839
            case RecruitmentSelectionInterview::TYPE_BOSS :
-
 
840
                $type = $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_TYPE_BOTH');
-
 
841
                break;
-
 
842
                
-
 
843
            case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE :
-
 
844
                $type = $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_TYPE_HUMAN_RESOURCE');
-
 
845
                break;
-
 
846
                
-
 
847
                
-
 
848
                
-
 
849
            default :
-
 
850
                $type = $this->translator->translate('LABEL_UNKNOWN');
-
 
851
                break;
-
 
852
        }
-
 
853
        
-
 
854
        $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $recruitmentSelectionInterview->updated_on);
-
 
855
        
-
 
856
        
-
 
857
        
-
 
858
        $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
-
 
859
        $recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($recruitmentSelectionInterview->vacancy_id);
-
 
860
        
-
 
861
        
-
 
862
        $recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
-
 
863
        $recruitmentSelectionCandidate = $recruitmentSelectionCandidateMapper->fetchOne($recruitmentSelectionInterview->candidate_id);
-
 
864
        
-
 
865
        $userMapper = UserMapper::getInstance($this->adapter);
-
 
866
        $user = $userMapper->fetchOne($recruitmentSelectionInterview->interviewer_id);
-
 
867
        if($user) {
-
 
868
            $interviewer  = ucwords(strtolower(trim($user->first_name . ' ' . $user->last_name)));
-
 
869
            
-
 
870
        }
-
 
871
        if($recruitmentSelectionCandidate) {
-
 
872
            $candidate = ucwords(strtolower(trim($recruitmentSelectionCandidate->first_name . ' ' . $recruitmentSelectionCandidate->last_name)));
-
 
873
            
-
 
874
        }
-
 
875
        
-
 
876
        $rows = [
-
 
877
            [
-
 
878
                'title' => $this->translator->translate('LABEL_TYPE') . ' : ',
-
 
879
                'content' => $type,
-
 
880
            ],
-
 
881
            [
-
 
882
                'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_POSITION') . ' : ',
-
 
883
                'content' => $recruitmentSelectionVacancy->name,
-
 
884
            ],
-
 
885
            [
-
 
886
                'title' => $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_CANDIDATE')  . ' : ',
-
 
887
                'content' => utf8_decode($candidate),
-
 
888
            ],
-
 
889
            
-
 
890
            [
-
 
891
                'title' => $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_CANDIDATE_SIGNATURE') . ' : ',
-
 
892
                'content' => ''
-
 
893
            ],
-
 
894
            [
-
 
895
                'title' => $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_INTERVIEWER') . ' : ',
-
 
896
                'content' => utf8_decode($interviewer),
-
 
897
            ],
-
 
898
            [
-
 
899
                'title' => $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_INTERVIEWER_SIGNATURE') . ' : ',
-
 
900
                'content' => ''
-
 
901
            ],
54
 
902
            [
-
 
903
                'title' => $this->translator->translate('LABEL_DATE'),
-
 
904
                'content' => $dt->format('d/m/Y H:i a')
-
 
905
            ]
-
 
906
        ];
-
 
907
        
-
 
908
        
-
 
909
        
-
 
910
        
-
 
911
        
-
 
912
        $pdf->borderTable($this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_TITLE'), $rows);
-
 
913
        
-
 
914
        switch( $recruitmentSelectionInterview->status)
-
 
915
        {
-
 
916
            case RecruitmentSelectionInterview::STATUS_ACCEPTED :
-
 
917
                $status = $this->translator->translate('LABEL_ACCEPTED');
-
 
918
                break;
-
 
919
                
-
 
920
            case RecruitmentSelectionInterview::STATUS_REJECTED :
-
 
921
                $status = $this->translator->translate('LABEL_REJECTED');
-
 
922
                break;
-
 
923
                
-
 
924
                
-
 
925
                
-
 
926
            default :
-
 
927
                $status = $this->translator->translate('LABEL_UNKNOWN');
-
 
928
                break;
-
 
929
        }
-
 
930
        
-
 
931
        
-
 
932
        $pdf->evaluationTable($status, $content->comment, $content->points);
-
 
933
        
-
 
934
        
-
 
935
        
-
 
936
        // Competencies
-
 
937
        if ($content->competencies_selected) {
-
 
938
            $pdf->AddPage();
-
 
939
            
-
 
940
            $i = 0;
-
 
941
            
-
 
942
            $max = count($content->competencies_selected);
-
 
943
            for($i = 0; $i < $max; $i++)
-
 
944
            {
-
 
945
                $competency_selected = $content->competencies_selected[$i];
-
 
946
                
-
 
947
                $j = $i + 1;
-
 
948
                $last = $j == $max;
-
 
949
                $pdf->competencyTable($i, $competency_selected, $content->competencies, $content->competency_types, $content->behaviors, $content->evaluation, $last);
-
 
950
            }
55
        return new JsonModel([
951
            
-
 
952
        }
Línea 56... Línea 953...
56
            'success' => false,
953