Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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