Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 7174 | 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) {
7300 efrain 207
                                    $url = '';
7174 efrain 208
                                    $hasLink = !empty($companyUsers[$recruitmentSelectionInterview->company_id]);
5050 efrain 209
 
7300 efrain 210
 
211
 
5050 efrain 212
                                    if($hasLink) {
213
 
214
                                        if(!isset($companies[$recruitmentSelectionInterview->company_id])) {
215
                                            $company  = $companyMapper->fetchOne($recruitmentSelectionInterview->company_id);
216
 
217
                                            $companies[ $company->id ]  = $company;
218
                                        } else {
219
                                            $company = $companies[ $recruitmentSelectionInterview->company_id ];
220
                                        }
221
 
222
 
7300 efrain 223
                                        $url = $this->url()->fromRoute('backend/signin-company', [
5050 efrain 224
                                            'id' => $company->uuid,
225
                                            'relational' => $recruitmentSelectionInterview->uuid,
226
                                            'type' => CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW
227
                                        ]);
228
                                    }
229
 
7300 efrain 230
                                    $agenda = " LABEL_RECRUITMENT_SELECTION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
5050 efrain 231
                                    switch($recruitmentSelectionInterview->type)
232
                                    {
233
                                        case RecruitmentSelectionInterview::TYPE_BOSS :
234
                                            $agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_BOSS_INTERVIEW <br>";
235
                                            break;
236
 
237
                                        case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE :
238
                                            $agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_HUMAN_RESOURCE <br>";
239
                                            break;
240
                                    }
241
 
242
                                    $agenda .= " LABEL_RECRUITMENT_SELECTION_CANDIDATE : " . trim($recruitmentSelectionCandidate->first_name . ' ' . $recruitmentSelectionCandidate->last_name) . " <br>";
243
 
244
 
245
 
246
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $recruitmentSelectionInterview->last_date);
247
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>" ;
248
 
249
 
250
                                    array_push($events, [
251
                                        'id'                => $recruitmentSelectionInterview->uuid,
252
                                        'title'             => $recruitmentSelectionVacancy->name,
253
                                        'agenda'            => $agenda,
7300 efrain 254
                                        'url'               => $url,
5050 efrain 255
                                        'start'             => $dtStart->format('Y-m-d'),
256
                                        'url'               => '',
257
                                        'backgroundColor'   => $backgroundColor,
258
                                        'textColor'         => $textColor,
259
                                        'allDay'            => true,
260
                                        'type'              => 'task',
261
                                    ]);
262
                                }
263
                            }
264
                        }
265
 
266
 
267
                        break;
4300 efrain 268
 
269
                    case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :
4696 efrain 270
 
271
 
4300 efrain 272
                        $backgroundColor = $currentNetwork->css_calendar_performance_evaluation_bg_color ;
273
                        $textColor = $currentNetwork->css_calendar_performance_evaluation_text_color;
274
 
275
 
4656 efrain 276
                        $performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOne($record->relational_id);
277
                        if($performanceEvaluationTest) {
4300 efrain 278
 
7170 efrain 279
 
280
 
4656 efrain 281
                            $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
4398 efrain 282
                            if($performanceEvaluationForm) {
7172 efrain 283
                                $jobDescription = $jobDescriptionMapper->fetchOne($performanceEvaluationForm->job_description_id);
284
                                if($jobDescription) {
7300 efrain 285
                                    $url = '';
7172 efrain 286
                                    if($performanceEvaluationTest->supervisor_id) {
287
                                        $supervisor = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);
288
                                    } else {
289
                                        $supervisor = '';
290
                                    }
291
 
292
                                    if($performanceEvaluationTest->employee_id) {
293
                                        $employee = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
294
                                    } else {
295
                                        $employee = '';
296
                                    }
4300 efrain 297
 
7172 efrain 298
 
7174 efrain 299
                                    $hasLink = !empty($companyUsers[$performanceEvaluationTest->company_id]);
4300 efrain 300
 
7172 efrain 301
                                    switch ($performanceEvaluationTest->type)
302
                                    {
303
                                        case PerformanceEvaluationTest::TYPE_SUPERVISOR :
304
                                        case PerformanceEvaluationTest::TYPE_BOTH  :
305
                                            if($performanceEvaluationTest->supervisor_id != $currentUser->id) {
306
                                                $hasLink = false;
307
                                            }
308
                                            break;
309
 
310
                                        case  PerformanceEvaluationTest::TYPE_EMPLOYEE  :
311
                                            if($performanceEvaluationTest->employee_id != $currentUser->id) {
312
                                                $hasLink = false;
313
                                            }
314
                                            break;
315
 
316
                                        default :
7170 efrain 317
                                            $hasLink = false;
7172 efrain 318
                                            break;
319
                                    }
7170 efrain 320
 
321
 
4398 efrain 322
 
323
                                    if($hasLink) {
324
 
4656 efrain 325
                                        if(!isset($companies[$performanceEvaluationTest->company_id])) {
326
                                            $company  = $companyMapper->fetchOne($performanceEvaluationTest->company_id);
4398 efrain 327
 
328
                                            $companies[ $company->id ]  = $company;
329
                                        } else {
4656 efrain 330
                                            $company = $companies[ $performanceEvaluationTest->company_id ];
4398 efrain 331
                                        }
332
 
333
 
7300 efrain 334
                                        $url = $this->url()->fromRoute('backend/signin-company', [
4398 efrain 335
                                            'id' => $company->uuid,
4656 efrain 336
                                            'relational' => $performanceEvaluationTest->uuid,
4398 efrain 337
                                            'type' => CalendarEvent::TYPE_PERFORMANCE_EVALUATION
338
                                        ]);
339
 
340
 
7300 efrain 341
 
342
                                    }
4398 efrain 343
 
7300 efrain 344
                                    $agenda = " LABEL_PERFORMANCE_EVALUATION_FORM_NAME : " . $performanceEvaluationForm->name . "<br>";
4398 efrain 345
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
4300 efrain 346
 
4656 efrain 347
                                    switch($performanceEvaluationTest->type)
4398 efrain 348
                                    {
4656 efrain 349
                                        case PerformanceEvaluationTest::TYPE_BOTH :
4398 efrain 350
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH <br>";
351
                                            break;
352
 
4656 efrain 353
                                        case PerformanceEvaluationTest::TYPE_SUPERVISOR :
4398 efrain 354
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR <br>";
355
                                            break;
356
 
4656 efrain 357
                                        case PerformanceEvaluationTest::TYPE_EMPLOYEE :
4398 efrain 358
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE <br>";
359
                                            break;
360
 
361
 
362
                                    }
363
 
364
                                    if($supervisor) {
365
                                        $agenda .= " LABEL_PERFORMANCE_EVALUATION_SUPERVISOR : " . trim($supervisor->first_name . ' ' . $supervisor->last_name) . " <br>";
366
 
367
                                    }
368
                                    if($employee) {
369
                                        $agenda .= " LABEL_PERFORMANCE_EVALUATION_EMPLOYEE : " . trim($employee->first_name . ' ' . $employee->last_name) . " <br>";
370
 
371
                                    }
372
 
4656 efrain 373
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $performanceEvaluationTest->last_date);
4398 efrain 374
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>" ;
7300 efrain 375
 
4632 efrain 376
 
4398 efrain 377
 
378
                                    array_push($events, [
4656 efrain 379
                                        'id'                => $performanceEvaluationTest->uuid,
4398 efrain 380
                                        'title'             =>  $performanceEvaluationForm->name,
381
                                        'agenda'            => $agenda,
4632 efrain 382
                                        'start'             => $dtStart->format('Y-m-d'),
7300 efrain 383
                                        'url'               => $url,
4398 efrain 384
                                        'backgroundColor'   => $backgroundColor,
385
                                        'textColor'         => $textColor,
4632 efrain 386
                                        'allDay'            => true,
4700 efrain 387
                                        'type'              => 'task',
4398 efrain 388
                                    ]);
7172 efrain 389
                                }
4300 efrain 390
                            }
391
 
392
                        }
393
 
394
 
395
 
396
 
397
 
398
                        break;
399
 
4141 efrain 400
                    case CalendarEvent::TYPE_ZOOM :
401
                        $zoomMeeting = $zoomMeetingMapper->fetchOne($record->relational_id);
402
                        if($zoomMeeting) {
403
 
4155 efrain 404
                            $backgroundColor = $currentNetwork->css_calendar_zoom_bg_color ;
405
                            $textColor = $currentNetwork->css_calendar_zoom_text_color;
4141 efrain 406
 
4155 efrain 407
                            $dtStart = \DateTime::createFromFormat('Y-m-d H:i:s', $zoomMeeting->start_time);
408
                            $t2 = $dtStart->getTimestamp();
409
 
410
                            if($t2 > $t1) {
411
 
412
                                $t3 = $t1 + $expirePeriod;
413
                                if($t3 > $t2) {
414
                                    $backgroundColor = $currentNetwork->css_calendar_expire_bg_color;
415
                                    $textColor = $currentNetwork->css_calendar_expire_text_color;
416
                                }
417
 
418
                            }
419
 
420
 
421
 
4141 efrain 422
                            if($currentUser->timezone && $currentUser->timezone != $zoomMeeting->timezone) {
423
 
424
                                $start =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->start_time, $zoomMeeting->timezone, $currentUser->timezone));
425
                                $end =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->end_time, $zoomMeeting->timezone, $currentUser->timezone));
426
 
427
 
428
 
429
 
430
 
431
                            } else {
432
                                $start = str_replace(' ', 'T', $zoomMeeting->start_time);
433
                                $end = str_replace(' ', 'T', $zoomMeeting->end_time);
434
                            }
435
 
436
 
4155 efrain 437
 
438
 
439
 
440
 
4141 efrain 441
                            $agenda = "<a href=\"{$zoomMeeting->join_url}\" target=\"_blank\">" .  $zoomMeeting->agenda . "<br>" .
442
                                " LABEL_ZOOM_MEETING_START_DATE : " . $dtStart->format('Y-m-d') . "<br>" .
443
                                " LABEL_ZOOM_MEETING_START_TIME : " . $dtStart->format('H:i a') . "<br>" .
444
                                " LABEL_ZOOM_MEETING_TIMEZONE : " . $zoomMeeting->timezone . "<br>" .
445
                                " LABEL_ZOOM_MEETING_TITLE :  " . $zoomMeeting->topic  . "<br>" .
446
                                " LABEL_ZOOM_MEETING_URL : " . $zoomMeeting->join_url . "<br>" .
447
                                " LABEL_ZOOM_MEETING_PASSWORD : " . $zoomMeeting->password . "<br>" .
448
                                "</a>";
449
 
450
                            array_push($events, [
451
                                'id'                => $zoomMeeting->id,
4148 efrain 452
                                'title'             => $zoomMeeting->topic,
4141 efrain 453
                                'agenda'            => $agenda,
454
                                'start'             => $start,
455
                                'end'               => $end,
456
                                'url'               => $zoomMeeting->join_url,
4155 efrain 457
                                'backgroundColor'   => $backgroundColor,
458
                                'textColor'         => $textColor,
4700 efrain 459
                                'type'              => 'event',
4141 efrain 460
                            ]);
461
                        }
462
                        break;
463
 
464
 
465
                }
466
 
467
 
468
 
469
            }
470
 
471
 
472
 
473
 
474
 
475
 
476
 
477
 
4113 efrain 478
 
479
 
4141 efrain 480
            return new JsonModel($events);
4113 efrain 481
 
4141 efrain 482
        } else {
483
            $response = [
484
                'success' => false,
485
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
486
            ];
487
        }
4113 efrain 488
 
4141 efrain 489
        return new JsonModel($response);
4113 efrain 490
    }
491
 
492
 
493
 
494
 
495
}