Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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