Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4156 | Rev 4398 | 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;
4300 efrain 21
use LeadersLinked\Mapper\PerformanceEvaluationEvaluationMapper;
22
use LeadersLinked\Mapper\PerformanceEvaluationFormMapper;
23
use LeadersLinked\Model\PerformanceEvaluationEvaluation;
24
use LeadersLinked\Mapper\JobDescriptionMapper;
25
use LeadersLinked\Mapper\CompanyUserMapper;
26
use LeadersLinked\Model\CompanyUser;
4113 efrain 27
 
4131 efrain 28
 
4113 efrain 29
class CalendarController extends AbstractActionController
30
{
31
    /**
32
     *
33
     * @var AdapterInterface
34
     */
35
    private $adapter;
36
 
37
 
38
    /**
39
     *
40
     * @var AbstractAdapter
41
     */
42
    private $cache;
43
 
44
    /**
45
     *
46
     * @var  LoggerInterface
47
     */
48
    private $logger;
49
 
50
 
51
    /**
52
     *
53
     * @var array
54
     */
55
    private $config;
56
 
57
    /**
58
     *
59
     * @param AdapterInterface $adapter
60
     * @param AbstractAdapter $cache
61
     * @param LoggerInterface $logger
62
     * @param array $config
63
     */
64
    public function __construct($adapter, $cache, $logger,  $config)
65
    {
66
        $this->adapter      = $adapter;
67
        $this->cache        = $cache;
68
        $this->logger       = $logger;
69
        $this->config       = $config;
70
    }
71
 
72
 
73
 
74
    public function indexAction()
75
    {
4131 efrain 76
        $currentUserPlugin = $this->plugin('currentUserPlugin');
77
        $currentUser = $currentUserPlugin->getUser();
78
 
4113 efrain 79
 
80
 
81
        $this->layout()->setTemplate('layout/layout.phtml');
82
        $viewModel = new ViewModel();
83
        $viewModel->setTemplate('leaders-linked/calendar/index.phtml');
4131 efrain 84
 
4113 efrain 85
        return $viewModel;
86
    }
87
 
88
 
89
 
90
 
91
    public function eventsAction()
92
    {
93
 
4141 efrain 94
        $request = $this->getRequest();
95
        if($request->isGet()) {
96
 
97
            $currentUserPlugin = $this->plugin('currentUserPlugin');
98
            $currentUser = $currentUserPlugin->getUser();
99
 
4155 efrain 100
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
101
            $currentNetwork = $currentNetworkPlugin->getNetwork();
4141 efrain 102
 
4155 efrain 103
 
104
 
4141 efrain 105
            $start  = $this->params()->fromQuery('start');
106
            $end    = $this->params()->fromQuery('end');
107
 
108
            if(!empty($start) && !empty($end)) {
109
 
110
                $dtStart = \DateTime::createFromFormat('Y-m-d', $start);
111
                $dtEnd = \DateTime::createFromFormat('Y-m-d', $end);
112
            } else {
113
                $dtStart = null;
114
                $dtEnd = null;
115
            }
116
 
117
            if(!$dtStart || !$dtEnd) {
118
              $t = time();
119
              $year = intval(date('Y', $t), 10);
120
              $month = intval(date('m', $t), 10);
121
              $last_day = intval(date('t', $t), 10);
122
 
123
              $start = mktime(0, 0, 0, $month, 1, $year);
124
              $start = date('Y-m-d H:i:s');
125
 
126
              $start = mktime(23, 56, 59, $month, $last_day, $year);
127
              $end = date('Y-m-d H:i:s');
128
 
129
            } else {
130
                $dtStart->setTime(0, 0, 0);
131
                $start = $dtStart->format('Y-m-d H:i:s');
132
 
133
                $dtEnd->setTime(23, 59, 59);
134
                $end  = $dtEnd->format('Y-m-d H:i:s');
135
            }
136
 
137
 
138
            $events = [];
4113 efrain 139
 
4141 efrain 140
 
4155 efrain 141
 
142
            //3 días
4156 efrain 143
            $expirePeriod = 86400 * 3;
4155 efrain 144
            $t1 = time();
145
 
4300 efrain 146
 
147
            $companyUser = [];
148
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
149
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
150
 
151
            foreach($records as $record) {
152
                $companyUsers[$record->company_id] = $record->backend == CompanyUser::BACKEND_YES;
153
             }
154
 
155
 
4141 efrain 156
 
157
            $zoomMeetingMapper = ZoomMeetingMapper::getInstance($this->adapter);
4300 efrain 158
            $performanceEvaluationEvaluationMapper = PerformanceEvaluationEvaluationMapper::getInstance($this->adapter);
159
            $performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
160
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
161
            $userMapper = UserMapper::getInstance($this->adapter);
4141 efrain 162
 
163
            $calendarEventMapper = CalendarEventMapper::getInstance($this->adapter);
164
            $records = $calendarEventMapper->fetchAllByUserIdAndStartTimeAndEndTime($currentUser->id, $start, $end);
165
            foreach($records as $record)
166
            {
167
                switch($record->type)
168
                {
4300 efrain 169
 
170
                    case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :
171
                        $backgroundColor = $currentNetwork->css_calendar_performance_evaluation_bg_color ;
172
                        $textColor = $currentNetwork->css_calendar_performance_evaluation_text_color;
173
 
174
 
175
                        $performanceEvaluationEvaluation = $performanceEvaluationEvaluationMapper->fetchOne($record->relational_id);
176
                        if($performanceEvaluationEvaluation) {
177
 
178
                            $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationEvaluation->form_id);
179
                            if(!$performanceEvaluationForm) {
180
                                continue;
181
                            }
182
 
183
                            $jobDescription = $jobDescriptionMapper->fetchOne($performanceEvaluationForm->job_description_id);
184
                            if(!$jobDescription) {
185
                                continue;
186
                            }
187
 
188
 
189
                            if($performanceEvaluationEvaluation->supervisor_id) {
190
                                $supervisor = $userMapper->fetchOne($performanceEvaluationEvaluation->supervisor_id);
191
                            } else {
192
                                $supervisor = '';
193
                            }
194
 
195
                            if($performanceEvaluationEvaluation->employee_id) {
196
                                $employee = $userMapper->fetchOne($performanceEvaluationEvaluation->employee_id);
197
                            } else {
198
                                $employee = '';
199
                            }
200
 
201
 
202
                            $agenda = " LABEL_PERFORMANCE_EVALUATION_FORM_NAME : " . $performanceEvaluationForm->name . "<br>";
203
                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
204
 
205
                            switch($performanceEvaluationEvaluation->type)
206
                            {
207
                                case PerformanceEvaluationEvaluation::TYPE_BOTH :
208
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH <br>";
209
                                    break;
210
 
211
                                case PerformanceEvaluationEvaluation::TYPE_SUPERVISOR :
212
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR <br>";
213
                                    break;
214
 
215
                                case PerformanceEvaluationEvaluation::TYPE_EMPLOYEE :
216
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE <br>";
217
                                    break;
218
 
219
 
220
                            }
221
 
222
                            if($supervisor) {
223
                                $agenda .= " LABEL_PERFORMANCE_EVALUATION_SUPERVISOR : " . trim($supervisor->first_name . ' ' . $supervisor->last_name) . " <br>";
224
 
225
                            }
226
                            if($employee) {
227
                                $agenda .= " LABEL_PERFORMANCE_EVALUATION_EMPLOYEE : " . trim($employee->first_name . ' ' . $employee->last_name) . " <br>";
228
 
229
                            }
230
 
231
                            $dtStart = \DateTime::createFromFormat('Y-m-d', $performanceEvaluationEvaluation->last_date);
232
                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>" ;
233
 
234
                            array_push($events, [
235
                                'id'                => $performanceEvaluationEvaluation->uuid,
236
                                'title'             =>  $performanceEvaluationForm->name,
237
                                'agenda'            => $agenda,
238
                                'start'             => $start,
239
                                'url'               => '',
240
                                'backgroundColor'   => $backgroundColor,
241
                                'textColor'         => $textColor,
242
                            ]);
243
 
244
 
245
 
246
                        }
247
 
248
 
249
 
250
 
251
 
252
                        break;
253
 
4141 efrain 254
                    case CalendarEvent::TYPE_ZOOM :
255
                        $zoomMeeting = $zoomMeetingMapper->fetchOne($record->relational_id);
256
                        if($zoomMeeting) {
257
 
4155 efrain 258
                            $backgroundColor = $currentNetwork->css_calendar_zoom_bg_color ;
259
                            $textColor = $currentNetwork->css_calendar_zoom_text_color;
4141 efrain 260
 
4155 efrain 261
                            $dtStart = \DateTime::createFromFormat('Y-m-d H:i:s', $zoomMeeting->start_time);
262
                            $t2 = $dtStart->getTimestamp();
263
 
264
                            if($t2 > $t1) {
265
 
266
                                $t3 = $t1 + $expirePeriod;
267
                                if($t3 > $t2) {
268
                                    $backgroundColor = $currentNetwork->css_calendar_expire_bg_color;
269
                                    $textColor = $currentNetwork->css_calendar_expire_text_color;
270
                                }
271
 
272
                            }
273
 
274
 
275
 
4141 efrain 276
                            if($currentUser->timezone && $currentUser->timezone != $zoomMeeting->timezone) {
277
 
278
                                $start =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->start_time, $zoomMeeting->timezone, $currentUser->timezone));
279
                                $end =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->end_time, $zoomMeeting->timezone, $currentUser->timezone));
280
 
281
 
282
 
283
 
284
 
285
                            } else {
286
                                $start = str_replace(' ', 'T', $zoomMeeting->start_time);
287
                                $end = str_replace(' ', 'T', $zoomMeeting->end_time);
288
                            }
289
 
290
 
4155 efrain 291
 
292
 
293
 
294
 
4141 efrain 295
                            $agenda = "<a href=\"{$zoomMeeting->join_url}\" target=\"_blank\">" .  $zoomMeeting->agenda . "<br>" .
296
                                " LABEL_ZOOM_MEETING_START_DATE : " . $dtStart->format('Y-m-d') . "<br>" .
297
                                " LABEL_ZOOM_MEETING_START_TIME : " . $dtStart->format('H:i a') . "<br>" .
298
                                " LABEL_ZOOM_MEETING_TIMEZONE : " . $zoomMeeting->timezone . "<br>" .
299
                                " LABEL_ZOOM_MEETING_TITLE :  " . $zoomMeeting->topic  . "<br>" .
300
                                " LABEL_ZOOM_MEETING_URL : " . $zoomMeeting->join_url . "<br>" .
301
                                " LABEL_ZOOM_MEETING_PASSWORD : " . $zoomMeeting->password . "<br>" .
302
                                "</a>";
303
 
304
                            array_push($events, [
305
                                'id'                => $zoomMeeting->id,
4148 efrain 306
                                'title'             => $zoomMeeting->topic,
4141 efrain 307
                                'agenda'            => $agenda,
308
                                'start'             => $start,
309
                                'end'               => $end,
310
                                'url'               => $zoomMeeting->join_url,
4155 efrain 311
                                'backgroundColor'   => $backgroundColor,
312
                                'textColor'         => $textColor,
4141 efrain 313
                            ]);
314
                        }
315
                        break;
316
 
317
 
318
                }
319
 
320
 
321
 
322
            }
323
 
324
 
325
 
326
 
327
 
328
 
329
 
330
 
4113 efrain 331
 
332
 
4141 efrain 333
            return new JsonModel($events);
4113 efrain 334
 
4141 efrain 335
        } else {
336
            $response = [
337
                'success' => false,
338
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
339
            ];
340
        }
4113 efrain 341
 
4141 efrain 342
        return new JsonModel($response);
4113 efrain 343
    }
344
 
345
 
346
 
347
 
348
}