Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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