Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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