Proyectos de Subversion LeadersLinked - Services

Rev

Rev 1 | Rev 123 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
8
 
9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\View\Model\ViewModel;
12
use Laminas\View\Model\JsonModel;
13
use LeadersLinked\Mapper\UserMapper;
14
use LeadersLinked\Mapper\CalendarEventMapper;
15
use LeadersLinked\Mapper\ZoomMeetingMapper;
16
use LeadersLinked\Model\CalendarEvent;
17
use LeadersLinked\Library\Functions;
18
use LeadersLinked\Mapper\PerformanceEvaluationTestMapper;
19
use LeadersLinked\Mapper\PerformanceEvaluationFormMapper;
20
use LeadersLinked\Model\PerformanceEvaluationTest;
21
use LeadersLinked\Mapper\JobDescriptionMapper;
22
use LeadersLinked\Mapper\CompanyUserMapper;
23
use LeadersLinked\Model\CompanyUser;
24
use LeadersLinked\Mapper\CompanyMapper;
25
use LeadersLinked\Mapper\RecruitmentSelectionInterviewMapper;
26
use LeadersLinked\Mapper\RecruitmentSelectionCandidateMapper;
27
use LeadersLinked\Mapper\RecruitmentSelectionVacancyMapper;
28
use LeadersLinked\Model\RecruitmentSelectionInterview;
29
use Laminas\Mvc\I18n\Translator;
30
use LeadersLinked\Cache\CacheInterface;
31
use LeadersLinked\Mapper\SurveyTestMapper;
32
use LeadersLinked\Mapper\SurveyCampaignMapper;
33
 
34
 
35
class CalendarController extends AbstractActionController
36
{
37
    /**
38
     *
39
     * @var \Laminas\Db\Adapter\AdapterInterface
40
     */
41
    private $adapter;
42
 
43
    /**
44
     *
45
     * @var \LeadersLinked\Cache\CacheInterface
46
     */
47
    private $cache;
48
 
49
 
50
    /**
51
     *
52
     * @var \Laminas\Log\LoggerInterface
53
     */
54
    private $logger;
55
 
56
    /**
57
     *
58
     * @var array
59
     */
60
    private $config;
61
 
62
 
63
    /**
64
     *
65
     * @var \Laminas\Mvc\I18n\Translator
66
     */
67
    private $translator;
68
 
69
 
70
    /**
71
     *
72
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
73
     * @param \LeadersLinked\Cache\CacheInterface $cache
74
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
75
     * @param array $config
76
     * @param \Laminas\Mvc\I18n\Translator $translator
77
     */
78
    public function __construct($adapter, $cache, $logger, $config, $translator)
79
    {
80
        $this->adapter      = $adapter;
81
        $this->cache        = $cache;
82
        $this->logger       = $logger;
83
        $this->config       = $config;
84
        $this->translator   = $translator;
85
    }
86
 
87
 
88
 
89
    public function indexAction()
90
    {
91
        return new JsonModel([
92
            'success' => false,
93
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
94
        ]);
95
    }
96
 
97
 
98
 
99
 
100
    public function eventsAction()
101
    {
102
 
103
        $request = $this->getRequest();
104
        if($request->isGet()) {
105
 
106
            $currentUserPlugin = $this->plugin('currentUserPlugin');
107
            $currentUser = $currentUserPlugin->getUser();
108
 
109
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
110
            $currentNetwork = $currentNetworkPlugin->getNetwork();
111
 
112
 
113
 
114
            $start  = $this->params()->fromQuery('start');
115
            $end    = $this->params()->fromQuery('end');
116
 
117
            if(!empty($start) && !empty($end)) {
118
 
119
                $dtStart = \DateTime::createFromFormat('Y-m-d', $start);
120
                $dtEnd = \DateTime::createFromFormat('Y-m-d', $end);
121
            } else {
122
                $dtStart = null;
123
                $dtEnd = null;
124
            }
125
 
126
            if(!$dtStart || !$dtEnd) {
127
              $t = time();
128
              $year = intval(date('Y', $t), 10);
129
              $month = intval(date('m', $t), 10);
130
              $last_day = intval(date('t', $t), 10);
131
 
132
              $start = mktime(0, 0, 0, $month, 1, $year);
133
              $start = date('Y-m-d H:i:s');
134
 
135
              $end = mktime(23, 56, 59, $month, $last_day, $year);
136
              $end = date('Y-m-d H:i:s');
137
 
138
            } else {
139
                $dtStart->setTime(0, 0, 0);
140
                $start = $dtStart->format('Y-m-d H:i:s');
141
 
142
                $dtEnd->setTime(23, 59, 59);
143
                $end  = $dtEnd->format('Y-m-d H:i:s');
144
            }
145
 
146
 
147
            $events = [];
148
 
149
 
150
 
151
            //3 días
152
            $expirePeriod = 86400 * 3;
153
            $t1 = time();
154
 
155
 
156
            $companies = [];
157
            $companyMapper = CompanyMapper::getInstance($this->adapter);
158
 
159
            $companyUsers = [];
160
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
161
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
162
 
163
            foreach($records as $record) {
164
                $companyUsers[$record->company_id] = $record->backend == CompanyUser::BACKEND_YES;
165
             }
166
 
167
 
168
 
169
 
170
 
171
 
172
            $zoomMeetingMapper = ZoomMeetingMapper::getInstance($this->adapter);
173
            $recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
174
            $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
175
            $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
176
            $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
177
            $performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
178
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
179
            $userMapper = UserMapper::getInstance($this->adapter);
180
 
181
            $calendarEventMapper = CalendarEventMapper::getInstance($this->adapter);
182
            $records = $calendarEventMapper->fetchAllByUserIdAndStartTimeAndEndTime($currentUser->id, $start, $end);
183
 
184
            foreach($records as $record)
185
            {
186
                switch($record->type)
187
                {
188
                    case CalendarEvent::TYPE_SURVEY_NORMAL:
189
                        $backgroundColor = $currentNetwork->css_calendar_survey_bg_color;
190
                        $textColor = $currentNetwork->css_calendar_survey_text_color;
191
 
192
                        $surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
193
                        $surveyTest = $surveyTestMapper->fetchOne($record->relational_id);
194
 
195
                        if($surveyTest && $surveyTest->user_id == $currentUser->id) {
196
 
197
                            $surveyCampaingMapper = SurveyCampaignMapper::getInstance($this->adapter);
198
                            $surveyCampaing = $surveyCampaingMapper->fetchOne($surveyTest->campaign_id);
199
 
200
                            $url = '';
201
                            $hasLink = !empty($companyUsers[$surveyTest->company_id]);
202
 
203
                            if ($hasLink) {
204
 
205
                                if (!isset($companies[$surveyTest->company_id])) {
206
                                    $company  = $companyMapper->fetchOne($surveyTest->company_id);
207
 
208
                                    $companies[$company->id]  = $company;
209
                                } else {
210
                                    $company = $companies[$surveyTest->company_id];
211
                                }
212
 
213
 
214
                                $url = $this->url()->fromRoute('backend/signin-company', [
215
                                    'id' => $company->uuid,
216
                                    'relational' => $surveyTest->uuid,
217
                                    'type' => CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE,
218
                                ]);
219
                            }
220
 
221
                            $dtStart = \DateTime::createFromFormat('Y-m-d', $surveyCampaing->end_date);
222
 
223
 
224
                            array_push($events, [
225
                                'id'                => $surveyTest->uuid,
226
                                'title'             => $surveyCampaing->name,
227
                                'start'             => $dtStart->format('d/m/Y'),
228
                                'url'               => $url,
229
                                'backgroundColor'   => $backgroundColor,
230
                                'textColor'         => $textColor,
231
                                'allDay'            => true,
232
                                'type'              => 'task',
233
                            ]);
234
                        }
235
 
236
                        break;
237
 
238
                    case CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE:
239
                        $backgroundColor = $currentNetwork->css_calendar_organizational_climate_bg_color;
240
                        $textColor = $currentNetwork->css_calendar_organizational_climate_text_color;
241
 
242
                        $surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
243
                        $surveyTest = $surveyTestMapper->fetchOne($record->relational_id);
244
 
245
                        if($surveyTest && $surveyTest->user_id == $currentUser->id) {
246
 
247
                            $surveyCampaingMapper = SurveyCampaignMapper::getInstance($this->adapter);
248
                            $surveyCampaing = $surveyCampaingMapper->fetchOne($surveyTest->campaign_id);
249
 
250
                            $url = '';
251
                            $hasLink = !empty($companyUsers[$surveyTest->company_id]);
252
 
253
                            if ($hasLink) {
254
 
255
                                if (!isset($companies[$surveyTest->company_id])) {
256
                                    $company  = $companyMapper->fetchOne($surveyTest->company_id);
257
 
258
                                    $companies[$company->id]  = $company;
259
                                } else {
260
                                    $company = $companies[$surveyTest->company_id];
261
                                }
262
 
263
 
264
                                $url = $this->url()->fromRoute('backend/signin-company', [
265
                                    'id' => $company->uuid,
266
                                    'relational' => $surveyTest->uuid,
267
                                    'type' => CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE,
268
                                ]);
269
                            }
270
 
271
                            $dtStart = \DateTime::createFromFormat('Y-m-d', $surveyCampaing->end_date);
272
 
273
 
274
                            array_push($events, [
275
                                'id'                => $surveyTest->uuid,
276
                                'title'             => $surveyCampaing->name,
277
                                'start'             => $dtStart->format('d/m/Y'),
278
                                'url'               => $url,
279
                                'backgroundColor'   => $backgroundColor,
280
                                'textColor'         => $textColor,
281
                                'allDay'            => true,
282
                                'type'              => 'task',
283
                            ]);
284
                        }
285
 
286
                        break;
287
 
288
 
289
 
290
 
291
 
292
                    case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW  :
293
                        $backgroundColor = $currentNetwork->css_calendar_recruitment_and_selection_bg_color ;
294
                        $textColor = $currentNetwork->css_calendar_recruitment_and_selection_text_color;
295
 
296
 
297
                        $recruitmentSelectionInterview = $recruitmentSelectionInterviewMapper->fetchOne($record->relational_id);
298
                        if($recruitmentSelectionInterview) {
299
 
300
                            $recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($recruitmentSelectionInterview->vacancy_id);
301
 
302
 
303
 
304
                            $recruitmentSelectionCandidate = $recruitmentSelectionCandidateMapper->fetchOne($recruitmentSelectionInterview->candidate_id);
305
                            if($recruitmentSelectionVacancy && $recruitmentSelectionCandidate) {
306
                                $jobDescription = $jobDescriptionMapper->fetchOne($recruitmentSelectionVacancy->job_description_id);
307
                                if($jobDescription) {
308
                                    $url = '';
309
                                    $hasLink = !empty($companyUsers[$recruitmentSelectionInterview->company_id]);
310
 
311
 
312
 
313
                                    if($hasLink) {
314
 
315
                                        if(!isset($companies[$recruitmentSelectionInterview->company_id])) {
316
                                            $company  = $companyMapper->fetchOne($recruitmentSelectionInterview->company_id);
317
 
318
                                            $companies[ $company->id ]  = $company;
319
                                        } else {
320
                                            $company = $companies[ $recruitmentSelectionInterview->company_id ];
321
                                        }
322
 
323
 
324
                                        $url = $this->url()->fromRoute('backend/signin-company', [
325
                                            'id' => $company->uuid,
326
                                            'relational' => $recruitmentSelectionInterview->uuid,
327
                                            'type' => CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW
328
                                        ]);
329
                                    }
330
 
331
                                    $agenda = " LABEL_RECRUITMENT_SELECTION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
332
                                    switch($recruitmentSelectionInterview->type)
333
                                    {
334
                                        case RecruitmentSelectionInterview::TYPE_BOSS :
335
                                            $agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_BOSS_INTERVIEW <br>";
336
                                            break;
337
 
338
                                        case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE :
339
                                            $agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_HUMAN_RESOURCE <br>";
340
                                            break;
341
                                    }
342
 
343
                                    $agenda .= " LABEL_RECRUITMENT_SELECTION_CANDIDATE : " . trim($recruitmentSelectionCandidate->first_name . ' ' . $recruitmentSelectionCandidate->last_name) . " <br>";
344
 
345
 
346
 
347
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $recruitmentSelectionInterview->last_date);
348
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>" ;
349
 
350
 
351
                                    array_push($events, [
352
                                        'id'                => $recruitmentSelectionInterview->uuid,
353
                                        'title'             => $recruitmentSelectionVacancy->name,
354
                                        'agenda'            => $agenda,
355
                                        'url'               => $url,
356
                                        'start'             => $dtStart->format('Y-m-d'),
357
                                        'url'               => '',
358
                                        'backgroundColor'   => $backgroundColor,
359
                                        'textColor'         => $textColor,
360
                                        'allDay'            => true,
361
                                        'type'              => 'task',
362
                                    ]);
363
                                }
364
                            }
365
                        }
366
 
367
 
368
                        break;
369
 
370
                    case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :
371
 
372
 
373
                        $backgroundColor = $currentNetwork->css_calendar_performance_evaluation_bg_color ;
374
                        $textColor = $currentNetwork->css_calendar_performance_evaluation_text_color;
375
 
376
 
377
                        $performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOne($record->relational_id);
378
                        if($performanceEvaluationTest) {
379
 
380
 
381
 
382
                            $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
383
                            if($performanceEvaluationForm) {
384
                                $jobDescription = $jobDescriptionMapper->fetchOne($performanceEvaluationForm->job_description_id);
385
                                if($jobDescription) {
386
                                    $url = '';
387
                                    if($performanceEvaluationTest->supervisor_id) {
388
                                        $supervisor = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);
389
                                    } else {
390
                                        $supervisor = '';
391
                                    }
392
 
393
                                    if($performanceEvaluationTest->employee_id) {
394
                                        $employee = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
395
                                    } else {
396
                                        $employee = '';
397
                                    }
398
 
399
 
400
                                    $hasLink = !empty($companyUsers[$performanceEvaluationTest->company_id]);
401
 
402
                                    switch ($performanceEvaluationTest->type)
403
                                    {
404
                                        case PerformanceEvaluationTest::TYPE_SUPERVISOR :
405
                                        case PerformanceEvaluationTest::TYPE_BOTH  :
406
                                            if($performanceEvaluationTest->supervisor_id != $currentUser->id) {
407
                                                $hasLink = false;
408
                                            }
409
                                            break;
410
 
411
                                        case  PerformanceEvaluationTest::TYPE_EMPLOYEE  :
412
                                            if($performanceEvaluationTest->employee_id != $currentUser->id) {
413
                                                $hasLink = false;
414
                                            }
415
                                            break;
416
 
417
                                        default :
418
                                            $hasLink = false;
419
                                            break;
420
                                    }
421
 
422
 
423
 
424
                                    if($hasLink) {
425
 
426
                                        if(!isset($companies[$performanceEvaluationTest->company_id])) {
427
                                            $company  = $companyMapper->fetchOne($performanceEvaluationTest->company_id);
428
 
429
                                            $companies[ $company->id ]  = $company;
430
                                        } else {
431
                                            $company = $companies[ $performanceEvaluationTest->company_id ];
432
                                        }
433
 
434
 
435
                                        $url = $this->url()->fromRoute('backend/signin-company', [
436
                                            'id' => $company->uuid,
437
                                            'relational' => $performanceEvaluationTest->uuid,
438
                                            'type' => CalendarEvent::TYPE_PERFORMANCE_EVALUATION
439
                                        ]);
440
 
441
 
442
 
443
                                    }
444
 
445
                                    $agenda = " LABEL_PERFORMANCE_EVALUATION_FORM_NAME : " . $performanceEvaluationForm->name . "<br>";
446
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
447
 
448
                                    switch($performanceEvaluationTest->type)
449
                                    {
450
                                        case PerformanceEvaluationTest::TYPE_BOTH :
451
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH <br>";
452
                                            break;
453
 
454
                                        case PerformanceEvaluationTest::TYPE_SUPERVISOR :
455
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR <br>";
456
                                            break;
457
 
458
                                        case PerformanceEvaluationTest::TYPE_EMPLOYEE :
459
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE <br>";
460
                                            break;
461
 
462
 
463
                                    }
464
 
465
                                    if($supervisor) {
466
                                        $agenda .= " LABEL_PERFORMANCE_EVALUATION_SUPERVISOR : " . trim($supervisor->first_name . ' ' . $supervisor->last_name) . " <br>";
467
 
468
                                    }
469
                                    if($employee) {
470
                                        $agenda .= " LABEL_PERFORMANCE_EVALUATION_EMPLOYEE : " . trim($employee->first_name . ' ' . $employee->last_name) . " <br>";
471
 
472
                                    }
473
 
474
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $performanceEvaluationTest->last_date);
475
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>" ;
476
 
477
 
478
 
479
                                    array_push($events, [
480
                                        'id'                => $performanceEvaluationTest->uuid,
481
                                        'title'             =>  $performanceEvaluationForm->name,
482
                                        'agenda'            => $agenda,
483
                                        'start'             => $dtStart->format('Y-m-d'),
484
                                        'url'               => $url,
485
                                        'backgroundColor'   => $backgroundColor,
486
                                        'textColor'         => $textColor,
487
                                        'allDay'            => true,
488
                                        'type'              => 'task',
489
                                    ]);
490
                                }
491
                            }
492
 
493
                        }
494
 
495
 
496
 
497
 
498
 
499
                        break;
500
 
501
                    case CalendarEvent::TYPE_ZOOM :
502
                        $zoomMeeting = $zoomMeetingMapper->fetchOne($record->relational_id);
503
                        if($zoomMeeting) {
504
 
505
                            $backgroundColor = $currentNetwork->css_calendar_zoom_bg_color ;
506
                            $textColor = $currentNetwork->css_calendar_zoom_text_color;
507
 
508
                            $dtStart = \DateTime::createFromFormat('Y-m-d H:i:s', $zoomMeeting->start_time);
509
                            $t2 = $dtStart->getTimestamp();
510
 
511
                            if($t2 > $t1) {
512
 
513
                                $t3 = $t1 + $expirePeriod;
514
                                if($t3 > $t2) {
515
                                    $backgroundColor = $currentNetwork->css_calendar_expire_bg_color;
516
                                    $textColor = $currentNetwork->css_calendar_expire_text_color;
517
                                }
518
 
519
                            }
520
 
521
 
522
 
523
                            if($currentUser->timezone && $currentUser->timezone != $zoomMeeting->timezone) {
524
 
525
                                $start =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->start_time, $zoomMeeting->timezone, $currentUser->timezone));
526
                                $end =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->end_time, $zoomMeeting->timezone, $currentUser->timezone));
527
 
528
 
529
 
530
 
531
 
532
                            } else {
533
                                $start = str_replace(' ', 'T', $zoomMeeting->start_time);
534
                                $end = str_replace(' ', 'T', $zoomMeeting->end_time);
535
                            }
536
 
537
 
538
 
539
 
540
 
541
 
542
                            $agenda = "<a href=\"{$zoomMeeting->join_url}\" target=\"_blank\">" .  $zoomMeeting->agenda . "<br>" .
543
                                " LABEL_ZOOM_MEETING_START_DATE : " . $dtStart->format('Y-m-d') . "<br>" .
544
                                " LABEL_ZOOM_MEETING_START_TIME : " . $dtStart->format('H:i a') . "<br>" .
545
                                " LABEL_ZOOM_MEETING_TIMEZONE : " . $zoomMeeting->timezone . "<br>" .
546
                                " LABEL_ZOOM_MEETING_TITLE :  " . $zoomMeeting->topic  . "<br>" .
547
                                " LABEL_ZOOM_MEETING_URL : " . $zoomMeeting->join_url . "<br>" .
548
                                " LABEL_ZOOM_MEETING_PASSWORD : " . $zoomMeeting->password . "<br>" .
549
                                "</a>";
550
 
551
                            array_push($events, [
552
                                'id'                => $zoomMeeting->id,
553
                                'title'             => $zoomMeeting->topic,
554
                                'agenda'            => $agenda,
555
                                'start'             => $start,
556
                                'end'               => $end,
557
                                'url'               => $zoomMeeting->join_url,
558
                                'backgroundColor'   => $backgroundColor,
559
                                'textColor'         => $textColor,
560
                                'type'              => 'event',
561
                            ]);
562
                        }
563
                        break;
564
 
565
 
566
                }
567
 
568
 
569
 
570
            }
571
 
572
 
573
 
574
 
121 efrain 575
            return new JsonModel([
576
                'success' => true,
577
                'data' => $events
578
            ]);
1 efrain 579
 
580
        } else {
581
            $response = [
582
                'success' => false,
583
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
584
            ];
585
        }
586
 
587
        return new JsonModel($response);
588
    }
589
 
590
 
591
 
592
 
593
}