Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5051 | Rev 5966 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Db\Adapter\AdapterInterface;
7
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
8
use Laminas\Mvc\Controller\AbstractActionController;
9
use Laminas\Log\LoggerInterface;
10
use Laminas\View\Model\JsonModel;
4179 efrain 11
use LeadersLinked\Mapper\CalendarEventMapper;
1 www 12
use LeadersLinked\Mapper\CompanyFollowerMapper;
5205 efrain 13
use LeadersLinked\Mapper\CompanyServiceMapper;
4751 efrain 14
use LeadersLinked\Mapper\JobDescriptionMapper;
15
use LeadersLinked\Mapper\PerformanceEvaluationFormMapper;
16
use LeadersLinked\Mapper\PerformanceEvaluationTestMapper;
1 www 17
use LeadersLinked\Mapper\QueryMapper;
5051 efrain 18
use LeadersLinked\Mapper\RecruitmentSelectionCandidateMapper;
19
use LeadersLinked\Mapper\RecruitmentSelectionInterviewMapper;
20
use LeadersLinked\Mapper\RecruitmentSelectionVacancyMapper;
1 www 21
use LeadersLinked\Mapper\UserMapper;
4179 efrain 22
use LeadersLinked\Mapper\ZoomMeetingMapper;
1 www 23
use LeadersLinked\Library\Functions;
24
use LeadersLinked\Mapper\UserNotificationSettingMapper;
25
 
4179 efrain 26
use LeadersLinked\Model\CalendarEvent;
4751 efrain 27
use LeadersLinked\Model\PerformanceEvaluationTest;
5051 efrain 28
use LeadersLinked\Model\RecruitmentSelectionInterview;
1 www 29
use LeadersLinked\Model\User;
30
use LeadersLinked\Mapper\ConnectionMapper;
31
use LeadersLinked\Mapper\ProfileVisitMapper;
32
use LeadersLinked\Mapper\GroupMemberMapper;
33
use LeadersLinked\Model\GroupMember;
34
use LeadersLinked\Mapper\GroupMapper;
35
use LeadersLinked\Model\Group;
36
use Laminas\Db\Sql\Expression;
37
use LeadersLinked\Mapper\CompanyUserMapper;
38
use LeadersLinked\Model\CompanyUser;
39
use LeadersLinked\Model\UserType;
40
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleUserMapper;
41
use LeadersLinked\Model\Notification;
42
use LeadersLinked\Mapper\NotificationMapper;
43
use LeadersLinked\Mapper\EmailTemplateMapper;
44
use LeadersLinked\Model\EmailTemplate;
45
use LeadersLinked\Library\QueueEmail;
46
use LeadersLinked\Mapper\PostMapper;
47
use LeadersLinked\Mapper\CompanyMapper;
48
use LeadersLinked\Model\Company;
49
use LeadersLinked\Model\Connection;
5205 efrain 50
use LeadersLinked\Model\Service;
51
use LeadersLinked\Mapper\DailyPulseEmojiMapper;
1 www 52
 
53
class HelperController extends AbstractActionController
54
{
55
    /**
56
     *
57
     * @var AdapterInterface
58
     */
59
    private $adapter;
60
 
61
 
62
    /**
63
     *
64
     * @var AbstractAdapter
65
     */
66
    private $cache;
67
 
68
    /**
69
     *
70
     * @var  LoggerInterface
71
     */
72
    private $logger;
73
 
74
    /**
75
     *
76
     * @var array
77
     */
78
    private $config;
79
 
80
 
2444 efrain 81
    /**
82
     *
83
     * @var array
84
     */
85
    private $navigation;
1 www 86
 
87
    /**
88
     *
89
     * @param AdapterInterface $adapter
90
     * @param AbstractAdapter $cache
91
     * @param LoggerInterface $logger
92
     * @param array $config
2444 efrain 93
     * @param array $navigation
1 www 94
     */
2444 efrain 95
    public function __construct($adapter, $cache , $logger, $config, $navigation)
1 www 96
    {
97
        $this->adapter      = $adapter;
98
        $this->cache        = $cache;
99
        $this->logger       = $logger;
100
        $this->config       = $config;
2444 efrain 101
        $this->navigation   = $navigation;
1 www 102
    }
103
 
104
 
105
    /**
106
     * Recuperamos las personas que pueda conocer
107
     * tiene que enviarse un petición GET a la siguiente url: /helpers/people-you-may-know
108
     * retorna un json en caso de ser  positivo
109
     * [
110
     *  'success' : true,
111
     *  'data' : [
112
     *      [
113
     *        'id'      => 'id del usuario encriptado',
114
     *        'name'    => 'nombre del usuario',
115
     *        'image'   => 'imagen del usuario',
116
     *        'profile' => 'url del profile',
117
     *     ]
118
     * ]
119
     * En caso de ser negativo
120
     * [
121
     *  'success' : false,
122
     *  'data' : mensaje de error
123
     * ]
124
     * @return \Laminas\View\Model\JsonModel
125
     */
126
    public function peopleYouMayKnowAction()
127
    {
128
        $request = $this->getRequest();
129
        if($request->isGet()) {
130
            $currentUserPlugin = $this->plugin('currentUserPlugin');
131
            $currentUser = $currentUserPlugin->getUser();
132
 
133
            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
134
            $first_degree_connections_ids = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
135
            $first_degree_connections_ids = $first_degree_connections_ids ? $first_degree_connections_ids : [0];
136
 
137
            $second_degree_connections_ids = $connectionMapper->fetchAllSecondDegreeConnectionsForUserIdReturnIds($currentUser->id);
138
            $second_degree_connections_ids = $second_degree_connections_ids ? $second_degree_connections_ids : [0];
139
 
140
            /*Usuarios de la empresas donde trabajo o soy dueño */
141
            $company_user_ids = [];
142
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
143
 
144
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
145
            foreach($records as $record)
146
            {
147
 
148
                if($record->status != CompanyUser::STATUS_ACCEPTED) {
149
                    continue;
150
                }
151
 
152
                $otherUsers = $companyUserMapper->fetchAllByCompanyId($record->company_id);
153
                foreach($otherUsers as $otherUser)
154
                {
155
                    if($currentUser->id != $otherUser->user_id && $otherUser->creator == CompanyUser::CREATOR_NO && $otherUser->status == CompanyUser::STATUS_ACCEPTED) {
156
 
157
                        if(!in_array($otherUser->user_id, $company_user_ids)) {
158
                            array_push($company_user_ids, $otherUser->user_id);
159
                        }
160
                    }
161
                }
162
            }
163
            $company_user_ids =  $company_user_ids ? $company_user_ids : [0];
164
 
165
            /* Usuario de los grupos donde soy dueño o participo */
166
 
167
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
168
 
169
            $group_member_ids = [];
170
 
171
            $records = $groupMemberMapper->fetchAllByUserId($currentUser->id);
172
            foreach($records as $record)
173
            {
174
                if($record->status != GroupMember::STATUS_ACCEPTED) {
175
                    continue;
176
                }
177
 
178
                $otherUsers = $groupMemberMapper->fetchAllByGroupId($record->group_id);
179
                foreach($otherUsers as $otherUser)
180
                {
181
                    if($currentUser->id != $otherUser->user_id && $otherUser->status == GroupMember::STATUS_ACCEPTED) {
182
 
183
                        if(!in_array($otherUser->user_id, $group_member_ids)) {
184
                            array_push($group_member_ids, $otherUser->user_id);
185
                        }
186
                    }
187
                }
188
 
189
 
190
            }
191
 
192
            $group_member_ids = $group_member_ids ? $group_member_ids : [0];
193
 
194
 
195
 
196
            /* Usuarios con que comparto capsulas */
197
            $capsule_user_ids = [];
198
            $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
199
 
200
            $company_ids = [];
201
            $records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
202
            foreach($records as $record)
203
            {
204
                if(!in_array($record->company_id,$company_ids)) {
205
                    array_push($company_ids, $record->company_id);
206
                }
207
            }
208
 
209
 
210
 
211
            foreach($company_ids as $company_id)
212
            {
213
                $otherUsers = $capsuleUserMapper->fetchAllUserIdsForCapsulesActiveByCompanyId($company_id);
214
                foreach($otherUsers as $user_id)
215
                {
216
                    if($currentUser->id != $user_id ) {
217
 
218
                        if(!in_array($user_id, $capsule_user_ids)) {
219
                            array_push($capsule_user_ids, $user_id);
220
                        }
221
                    }
222
                }
223
            }
224
 
225
            $capsule_user_ids = $capsule_user_ids ? $capsule_user_ids : [0];
226
 
227
 
228
            $other_users = array_unique(array_merge(
229
                $second_degree_connections_ids,
230
                $company_user_ids,
231
                $group_member_ids,
232
                $capsule_user_ids
233
            ));
234
 
235
 
236
 
237
 
238
 
239
 
240
 
241
 
242
            $items = [];
243
            $queryMapper = QueryMapper::getInstance($this->adapter);
244
            $select = $queryMapper->getSql()->select();
245
            $select->columns(['id', 'uuid',  'first_name','last_name', 'image']);
246
            $select->from(['u' => UserMapper::_TABLE]);
3639 efrain 247
            $select->where->equalTo('network_id', $currentUser->network_id);
1 www 248
            $select->where->in('u.id', $other_users);
249
            $select->where->notIn('u.id', $first_degree_connections_ids);
250
            $select->where->notEqualTo('u.id', $currentUser->id);
251
            $select->where->equalTo('u.status', User::STATUS_ACTIVE);
252
            $select->where->in('u.usertype_id', [UserType::ADMIN, UserType::USER]);
253
            $select->order(['first_name','last_name']);
254
 
255
                //echo $select->getSqlString($this->adapter->platform); exit;
256
 
257
            $records = $queryMapper->fetchAll($select);
258
            foreach($records as $record)
259
            {
260
 
261
                $relation = [];
262
                if(in_array($record['id'], $second_degree_connections_ids)) {
263
                    array_push($relation, 'LABEL_RELATION_TYPE_SECOND_GRADE');
264
                }
265
                if(in_array($record['id'], $company_user_ids)) {
266
                    array_push($relation, 'LABEL_RELATION_TYPE_COMPANY_USER');
267
                }
268
                if(in_array($record['id'], $group_member_ids)) {
269
                    array_push($relation, 'LABEL_RELATION_TYPE_GROUP_MEMBER');
270
                }
271
                if(in_array($record['id'], $capsule_user_ids)) {
272
                    array_push($relation, 'LABEL_RELATION_TYPE_CAPSULE_USER');
273
                }
274
 
275
 
276
                $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $record['id']);
277
 
278
                $item = [
279
                    'id'    => $record['uuid'],
280
                    'name'  => trim($record['first_name'] . ' ' . $record['last_name']),
281
                    'image' => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
282
                    'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid'] ]),
283
                    'relation' => $relation,
284
                    'link_cancel'   => '',
285
                    'link_request'  => '',
286
                ];
287
 
288
                if($connection) {
289
                    switch($connection->status)
290
                    {
291
                        case Connection::STATUS_SENT :
292
                            $item['link_cancel'] = $this->url()->fromRoute('connection/delete',['id' => $record['uuid'] ]);
293
                            break;
294
 
295
                        case Connection::STATUS_ACCEPTED :
296
                            $item['link_cancel'] = $this->url()->fromRoute('connection/cancel',['id' => $record['uuid'] ]);
297
                            break;
298
 
299
                        default :
300
                            $item['link_request'] = $this->url()->fromRoute('connection/request',['id' => $record['uuid'] ]);
301
                            break;
302
 
303
                    }
304
 
305
 
306
                } else {
307
                    $item['link_request'] = $this->url()->fromRoute('connection/request',['id' => $record['uuid'] ]);
308
                }
309
 
310
 
311
                array_push($items, $item);
312
            }
313
 
314
            return new JsonModel([
315
                'success' => true,
316
                'data' => $items
317
            ]);
318
 
319
 
320
        } else {
321
            return new JsonModel([
322
                'success' => false,
323
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
324
            ]);
325
        }
326
 
327
    }
328
 
329
    /**
330
     * Recuperamos las personas que pueda conocer
331
     * tiene que enviarse un petición GET a la siguiente url: /helpers/people-viewed-profile/:user_profile_id
332
     * retorna un json en caso de ser  positivo
333
     * [
334
     *  'success' : true,
335
     *  'data' : [
336
     *      [
337
     *        'id'      => 'id del usuario encriptado',
338
     *        'name'    => 'nombre del usuario',
339
     *        'image'   => 'imagen del usuario',
340
     *        'profile' => 'url del profile',
341
     *     ]
342
     * ]
343
     * En caso de ser negativo
344
     * [
345
     *  'success' : false,
346
     *  'data' : mensaje de error
347
     * ]
348
     * @return \Laminas\View\Model\JsonModel
349
     */
350
    public function peopleViewedProfileAction()
351
    {
352
        $request = $this->getRequest();
353
        if($request->isGet()) {
3639 efrain 354
            $currentUserPlugin = $this->plugin('currentUserPlugin');
355
            $currentUser = $currentUserPlugin->getUser();
1 www 356
 
357
            $items = [];
358
            $user_profile_id = $this->params()->fromRoute('user_profile_id');
359
 
360
            $items = [];
361
 
362
            $mapper = QueryMapper::getInstance($this->adapter);
363
            $select = $mapper->getSql()->select(ProfileVisitMapper::_TABLE);
364
            $select->columns(['user_id' => new Expression('DISTINCT(visitor_id)')]);
365
            $select->where->equalTo('user_profile_id', $user_profile_id);
366
            $records = $mapper->fetchAll($select);
367
 
368
            if($records) {
369
 
370
                $user_ids = [];
371
                foreach($records as $record)
372
                {
373
                    array_push($user_ids, $record['user_id']);
374
                }
375
 
376
                $mapper = QueryMapper::getInstance($this->adapter);
377
                $select = $mapper->getSql()->select( UserMapper::_TABLE);
378
                $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
379
                $select->where->in('id', $user_ids);
3639 efrain 380
                $select->where->equalTo('network_id', $currentUser->network_id);
1 www 381
                $select->where->equalTo('status',User::STATUS_ACTIVE);
382
                $select->order(['last_name ASC', 'first_name ASC']);
383
 
384
                $records = $mapper->fetchAll($select);
385
                foreach($records as $record)
386
                {
387
                    array_push($items, [
388
                        'id'        => $record['uuid'],
389
                        'name'      => trim($record['first_name'] . ' ' . $record['last_name']),
390
                        'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
391
                        'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid'] ]),
392
                    ]);
393
                }
394
            }
395
 
396
 
397
            return new JsonModel([
398
                'success' => true,
399
                'data' => $items
400
            ]);
401
 
402
        } else {
403
            return new JsonModel([
404
                'success' => false,
405
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
406
            ]);
407
        }
408
    }
409
 
410
 
411
    /**
412
     * Recuperamos los seguidores de la empresa
413
     * tiene que enviarse un petición GET a la siguiente url: /helpers/company-follower/:company_id
414
     * retorna un json en caso de ser  positivo
415
     * [
416
     *  'success' : true,
417
     *  'data' : [
418
     *      [
419
     *        'id'      => 'id del usuario encriptado',
420
     *        'name'    => 'nombre del usuario',
421
     *        'image'   => 'imagen del usuario',
422
     *        'profile' => 'url del profile',
423
     *     ]
424
     * ]
425
     * En caso de ser negativo
426
     * [
427
     *  'success' : false,
428
     *  'data' : mensaje de error
429
     * ]
430
     * @return \Laminas\View\Model\JsonModel
431
     */
432
    public function companyFollowerAction()
433
    {
434
 
435
 
436
        $request = $this->getRequest();
437
        if($request->isGet()) {
3639 efrain 438
            $currentUserPlugin = $this->plugin('currentUserPlugin');
439
            $currentUser = $currentUserPlugin->getUser();
1 www 440
 
441
            $company_uuid  = $this->params()->fromRoute('company_id');
442
 
443
            $companyMapper = CompanyMapper::getInstance($this->adapter);
3639 efrain 444
            $company = $companyMapper->fetchOneByUuidAndNetworkId($company_uuid, $currentUser->network_id);
1 www 445
 
446
            $items = [];
447
            if($company && $company->status == Company::STATUS_ACTIVE) {
448
 
449
 
450
                //print_r($company);
451
 
452
                $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
453
                $records = $companyFollowerMapper->fetchAllByCompanyId($company->id);
454
 
455
                $ids = [];
456
                foreach($records as $record)
457
                {
458
                    if(!in_array($record->follower_id, $ids)) {
459
                        array_push($ids, $record->follower_id);
460
                    }
461
                }
462
 
463
                //print_r($records);
464
 
465
 
466
                if($ids) {
467
 
468
                    $mapper = QueryMapper::getInstance($this->adapter);
469
                    $select = $mapper->getSql()->select(UserMapper::_TABLE);
470
                    $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
3639 efrain 471
                    $select->where->equalTo('network_id', $currentUser->network_id);
1 www 472
                    $select->where->in('id',$ids);
473
                    $select->where->equalTo('status',User::STATUS_ACTIVE);
474
                    $select->order(['last_name','first_name']);
475
 
476
                    //echo $select->getSqlString($this->adapter->platform); exit;
477
 
478
 
479
 
480
                    $records = $mapper->fetchAll($select);
481
                    foreach($records as $record)
482
                    {
483
 
484
 
485
                        array_push($items, [
486
                            'id'        => $record['uuid'],
487
                            'name'      => trim($record['first_name'] . ' ' . $record['last_name']),
488
                            'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
489
                            'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid'] ]),
490
                        ]);
491
                    }
492
                }
493
            }
494
 
495
            return new JsonModel([
496
                'success' => true,
497
                'data' => $items
498
            ]);
499
 
500
        } else {
501
            return new JsonModel([
502
                'success' => false,
503
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
504
            ]);
505
        }
506
    }
507
 
508
    public function companySuggestionAction()
509
    {
510
        $request = $this->getRequest();
511
        if($request->isGet()) {
3639 efrain 512
            $currentUserPlugin = $this->plugin('currentUserPlugin');
513
            $currentUser = $currentUserPlugin->getUser();
1 www 514
 
3639 efrain 515
            $company_uuid = $this->params()->fromRoute('company_id');
1 www 516
 
517
            $companyMapper = CompanyMapper::getInstance($this->adapter);
3639 efrain 518
            $company = $companyMapper->fetchOneByUuidAndNetworkId($company_uuid, $currentUser->network_id);
1 www 519
 
520
            $items = [];
521
            if($company && $company->status == Company::STATUS_ACTIVE) {
522
 
523
 
524
                $mapper = QueryMapper::getInstance($this->adapter);
525
                $select = $mapper->getSql()->select(CompanyMapper::_TABLE);
526
                $select->columns(['id', 'uuid', 'name', 'image']);
3639 efrain 527
                $select->where->equalTo('network_id', $currentUser->network_id);
1 www 528
                $select->where->notEqualTo('id', $company->id);
529
                $select->where->equalTo('status',Company::STATUS_ACTIVE);
530
                $select->where->equalTo('industry_id', $company->industry_id);
531
              //  $select->where->equalTo('company_size_id', $company->company_size_id);
532
                $select->order(['name']);
533
 
534
 
535
                //echo $select->getSqlString($this->adapter->platform); exit;
536
 
537
                $records = $mapper->fetchAll($select);
538
                foreach($records as $record)
539
                {
540
                    array_push($items, [
541
                        'id'        => $record['uuid'],
542
                        'name'      => trim($record['name']),
543
                        'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'company', 'filename' => $record['image']]),
544
                        'profile'   => $this->url()->fromRoute('company/view', ['id' => $record['uuid'] ]),
545
                    ]);
546
                }
547
            }
548
 
549
            return new JsonModel([
550
                'success' => true,
551
                'data' => $items
552
            ]);
553
 
554
        } else {
555
            return new JsonModel([
556
                'success' => false,
557
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
558
            ]);
559
        }
560
    }
561
 
562
    /**
563
     * Recuperamos los miembros del grupo
564
     * tiene que enviarse un petición GET a la siguiente url: /helpers/group-members/:group_id
565
     * retorna un json en caso de ser  positivo
566
     * [
567
     *  'success' : true,
568
     *  'data' : [
569
     *      [
570
     *        'id'      => 'id del usuario encriptado',
571
     *        'name'    => 'nombre del usuario',
572
     *        'image'   => 'imagen del usuario',
573
     *        'profile' => 'url del profile',
574
     *     ]
575
     * ]
576
     * En caso de ser negativo
577
     * [
578
     *  'success' : false,
579
     *  'data' : mensaje de error
580
     * ]
581
     * @return \Laminas\View\Model\JsonModel
582
     */
583
    public function groupMembersAction()
584
    {
585
        $currentUserPlugin = $this->plugin('currentUserPlugin');
586
        $currentUser = $currentUserPlugin->getUser();
3639 efrain 587
 
1 www 588
        $request = $this->getRequest();
589
        if($request->isGet()) {
590
 
591
            $group_uuid = $this->params()->fromRoute('group_id');
592
 
593
            $groupMapper = GroupMapper::getInstance($this->adapter);
3639 efrain 594
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
1 www 595
 
596
            $items = [];
597
            if($group && $group->status == Group::STATUS_ACTIVE) {
598
 
599
                $mapper = QueryMapper::getInstance($this->adapter);
600
                $select = $mapper->getSql()->select();
601
                $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
602
                $select->from(['u' => UserMapper::_TABLE]);
603
                $select->join(['gm' => GroupMemberMapper::_TABLE], 'gm.user_id = u.id ', ['user_id', 'status']);
604
                $select->join(['g' => GroupMapper::_TABLE], 'gm.group_id = g.id', ['group_uuid' => 'uuid']  );
3639 efrain 605
                $select->where->equalTo('u.network_id',  $currentUser->network_id);
606
                $select->where->equalTo('g.network_id', $currentUser->network_id);
1 www 607
                $select->where->equalTo('g.uuid', $group_uuid);
608
 
609
                if($group->user_id == $currentUser->id) {
610
                    $select->where->in('gm.status', [
611
                        GroupMember::STATUS_ACCEPTED,
612
                        GroupMember::STATUS_ADDED_BY_ADMIN,
613
                        GroupMember::STATUS_AUTO_JOIN,
614
                        GroupMember::STATUS_JOINING_REQUESTED,
615
                    ]);
616
                } else {
617
                    $select->where->in('gm.status', [GroupMember::STATUS_ACCEPTED, GroupMember::STATUS_AUTO_JOIN]);
618
                }
619
 
620
 
621
                $select->where->equalTo('u.status', User::STATUS_ACTIVE);
622
                $select->order(['last_name', 'first_name']);
623
 
624
                //echo $select->getSqlString($this->adapter->platform);
625
 
626
 
627
 
628
 
629
                $records = $mapper->fetchAll($select);
630
                foreach($records as $record)
631
                {
632
 
633
                    $actions = [];
634
                    if($group->user_id == $currentUser->id) {
635
                        if($record['id'] != $currentUser->id) {
636
 
637
 
638
 
639
                            switch($record['status'])
640
                            {
641
                                case GroupMember::STATUS_JOINING_REQUESTED :
642
                                    $actions['link_approve'] = $this->url()->fromRoute('helpers/group-members/approve', ['group_id' => $group->uuid, 'user_id' => $record['uuid']]);
643
                                    $actions['link_reject'] = $this->url()->fromRoute('helpers/group-members/reject', ['group_id' => $group->uuid, 'user_id' => $record['uuid']]);
644
                                    break;
645
 
646
                                case GroupMember::STATUS_ACCEPTED :
647
                                case GroupMember::STATUS_AUTO_JOIN :
648
                                case GroupMember::STATUS_ADDED_BY_ADMIN :
649
                                    $actions['link_cancel'] = $this->url()->fromRoute('helpers/group-members/cancel', ['group_id' => $group->uuid, 'user_id' => $record['uuid']]);
650
                                    break;
651
                            }
652
                        }
653
 
654
 
655
 
656
                    }
657
 
658
                    array_push($items, [
659
                        'id'        => $record['uuid'],
660
                        'name'      => trim($record['first_name'] . ' ' . $record['last_name']),
661
                        'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
662
                        'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
663
                        'actions'   => $actions,
664
 
665
                    ]);
666
                }
667
            }
668
 
669
            return new JsonModel([
670
                'success' => true,
671
                'data' => [
672
                    'items' => $items,
673
                    'link_invite' => $group->user_id == $currentUser->id ? $this->url()->fromRoute('helpers/group-members/invite',['group_id' => $group->uuid])  : '',
674
                ]
675
            ]);
676
 
677
        } else {
678
            return new JsonModel([
679
                'success' => false,
680
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
681
            ]);
682
        }
683
    }
684
 
685
    public function groupMemberInviteAction()
686
    {
687
        $currentUserPlugin = $this->plugin('currentUserPlugin');
688
        $currentUser = $currentUserPlugin->getUser();
3639 efrain 689
 
1 www 690
        $group_uuid = $this->params()->fromRoute('group_id');
691
 
692
        $groupMapper = GroupMapper::getInstance($this->adapter);
3639 efrain 693
        $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
1 www 694
 
695
        if(!$group) {
696
            return new JsonModel([
697
                'success' => false,
698
                'data' => 'ERROR_GROUP_NOT_FOUND'
699
            ]);
700
        }
701
 
702
        if($group->status != Group::STATUS_ACTIVE) {
703
            return new JsonModel([
704
                'success' => false,
705
                'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
706
            ]);
707
        }
708
 
709
        if($currentUser->id != $group->user_id) {
710
            return new JsonModel([
711
                'success' => false,
712
                'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
713
            ]);
714
        }
715
 
716
 
717
        $request = $this->getRequest();
718
        if($request->isGet()) {
719
            $search = filter_var($this->params()->fromQuery('search', ''));
720
            if(strlen($search) >= 3) {
721
 
722
                $userMapper = UserMapper::getInstance($this->adapter);
3639 efrain 723
                $records  = $userMapper->fetchAllSuggestForInvitationByGroupIdAndNetworkIdAndSearch($group->id, $currentUser->network_id, $search);
1 www 724
 
725
                $users = [];
726
                foreach($records as $record)
727
                {
728
                    array_push($users, [
729
                        'value' => $record->uuid,
730
                        'text' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')'
731
 
732
                    ]);
733
                }
734
 
735
                return new JsonModel([
736
                    'success' => true,
737
                    'data' => $users
738
                ]);
739
 
740
 
741
 
742
 
743
            } else {
744
                return new JsonModel([
745
                    'success' => true,
746
                    'data' => [
747
 
748
                    ]
749
                ]);
750
            }
751
 
752
 
753
 
754
        }
755
        else if($request->isPost()) {
756
            $uuid = $this->params()->fromPost('id');
757
            if(!$uuid) {
758
                return new JsonModel([
759
                    'success'   => false,
760
                    'data'      => 'ERROR_INVALID_PARAMETER'
761
                ]);
762
            }
763
 
764
            $userMapper = UserMapper::getInstance($this->adapter);
3639 efrain 765
            $user = $userMapper->fetchOneByUuidAndNetworkId($uuid, $currentUser->network_id);
1 www 766
 
767
            if(!$user) {
768
                return new JsonModel([
769
                    'success'   => false,
770
                    'data'      => 'ERROR_USER_NOT_FOUND'
771
                ]);
772
            }
773
 
774
            if($user->status != User::STATUS_ACTIVE) {
775
                return new JsonModel([
776
                    'success'   => false,
777
                    'data'      => 'ERROR_USER_IS_INACTIVE'
778
                ]);
779
            }
780
 
781
            if($group->user_id == $user->id) {
782
                return new JsonModel([
783
                    'success'   => false,
784
                    'data'      => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
785
                ]);
786
            }
787
 
788
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
789
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
790
 
791
 
792
 
793
            if($groupMember) {
794
                $result = false;
795
 
796
                switch($groupMember->status)
797
                {
798
                    case GroupMember::STATUS_ACCEPTED:
799
                    case GroupMember::STATUS_AUTO_JOIN:
800
 
801
                        return new JsonModel([
802
                            'success'   => false,
803
                            'data'      => 'ERROR_GROUP_YOU_ARE_MEMBER',
804
                        ]);
805
                        break;
806
 
807
 
808
                    case $groupMember->status == GroupMember::STATUS_REJECTED :
809
                    case $groupMember->status == GroupMember::STATUS_CANCELLED :
810
 
811
                        $groupMember->status = GroupMember::STATUS_ADDED_BY_ADMIN;
812
                        $groupMember->joining_request_on = date('H-m-d H:i:s');
813
 
814
                        $result = $groupMemberMapper->update($groupMember);
815
                        break;
816
 
817
                    case GroupMember::STATUS_ADDED_BY_ADMIN :
818
                    case  GroupMember::STATUS_JOINING_REQUESTED :
819
                        return new JsonModel([
820
                            'success'   => false,
821
                            'data'      => 'ERROR_GROUP_THERE_IS_A_PENDING_REQUEST'
822
                        ]);
823
                        break;
824
 
825
                    default :
826
                        return new JsonModel([
827
                            'success'   => false,
828
                            'data'      => 'ERROR_UNKNOWN_OPERATION'
829
                        ]);
830
                        break;
831
 
832
                }
833
 
834
 
835
 
836
 
837
 
838
 
839
            } else {
840
 
841
 
842
 
843
                $groupMember = new GroupMember();
844
                $groupMember->user_id = $user->id;
845
                $groupMember->group_id = $group->id;
846
                $groupMember->status = GroupMember::STATUS_ADDED_BY_ADMIN;
847
                $groupMember->joining_request_on = date('H-m-d H:i:s');
848
 
849
                $result = $groupMemberMapper->insert($groupMember);
850
 
851
 
852
            }
853
 
854
            if($result) {
855
 
856
                $notification = new Notification();
857
                $notification->type     = Notification::TYPE_RECEIVE_INVITATION_GROUP;
858
                $notification->read     = Notification::NO;
859
                $notification->user_id  = $user->id;
860
                $notification->group_id = $group->id;
861
                $notification->message  = 'LABEL_NOTIFICATION_RECEIVE_INVITATION_GROUP';
862
                $notification->url      = $this->url()->fromRoute('group/view',['id' => $group->uuid]);
863
 
864
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
865
                $notificationMapper->insert($notification);
866
 
867
                $userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
868
                $userNotification = $userNotificationMapper->fetchOne($user->id);
869
 
870
                if($userNotification && $userNotification->receive_invitation_group)
871
                {
872
                    $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
3639 efrain 873
                    $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RECEIVE_INVITATION_GROUP, $currentUser->network_id);
1 www 874
 
875
                    if($emailTemplate) {
876
                        $arrayCont = [
877
                            'firstname'             => $currentUser->first_name,
878
                            'lastname'              => $currentUser->last_name,
879
                            'other_user_firstname'  => $user->first_name,
880
                            'other_user_lastname'   => $user->last_name,
881
                            'company_name'          => '',
882
                            'group_name'            => $group->name,
883
                            'content'               => '',
884
                            'code'                  => '',
885
                            'link'                  => $this->url()->fromRoute('group/view', ['id' => $group->uuid], ['force_canonical' => true])
886
                        ];
887
 
888
                        $email = new QueueEmail($this->adapter);
889
                        $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
890
                    }
891
                }
892
 
893
                return new JsonModel([
894
                    'success'   => true,
895
                    'data'      => 'LABEL_GROUP_REQUEST_SUCCESS'
896
                ]);
897
 
898
            } else {
899
 
900
                return new JsonModel([
901
                    'success'   => false,
902
                    'data'      => 'ERROR_GROUP_REQUEST_COULD_NOT_BE_SENT'
903
                ]);
904
 
905
            }
906
 
907
 
908
 
909
        } else {
910
            return new JsonModel([
911
                'success' => false,
912
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
913
            ]);
914
        }
915
    }
916
 
917
    public function  groupMemberCancelAction()
918
    {
919
        $currentUserPlugin = $this->plugin('currentUserPlugin');
920
        $currentUser = $currentUserPlugin->getUser();
3639 efrain 921
 
1 www 922
        $request = $this->getRequest();
923
        if($request->isPost()) {
924
            $group_uuid = $this->params()->fromRoute('group_id');
925
            $user_uuid  = $this->params()->fromRoute('user_id');
926
 
927
            $groupMapper = GroupMapper::getInstance($this->adapter);
3639 efrain 928
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
1 www 929
 
930
            if(!$group) {
931
                return new JsonModel([
932
                    'success' => false,
933
                    'data' => 'ERROR_GROUP_NOT_FOUND'
934
                ]);
935
            }
936
 
937
            if($group->status != Group::STATUS_ACTIVE) {
938
                return new JsonModel([
939
                    'success' => false,
940
                    'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
941
                ]);
942
            }
943
 
944
            if($currentUser->id != $group->user_id) {
945
                return new JsonModel([
946
                    'success' => false,
947
                    'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
948
                ]);
949
            }
950
 
951
            $userMapper = UserMapper::getInstance($this->adapter);
3639 efrain 952
            $user = $userMapper->fetchOneByUuidAndNetworkId($user_uuid, $currentUser->network_id);
1 www 953
 
954
            if(!$user) {
955
                return new JsonModel([
956
                    'success' => false,
957
                    'data' => 'ERROR_USER_NOT_FOUND'
958
                ]);
959
            }
960
 
961
            if($user->id == $currentUser->id) {
962
                return new JsonModel([
963
                    'success' => false,
964
                    'data' => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
965
                ]);
966
            }
967
 
968
 
969
 
970
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
971
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
972
            if($groupMember) {
973
 
974
                if($groupMember->status == GroupMember::STATUS_ACCEPTED ||
975
                    $groupMember->status == GroupMember::STATUS_ADDED_BY_ADMIN ||
976
                    $groupMember->status == GroupMember::STATUS_AUTO_JOIN) {
977
 
978
                    $groupMember->status = GroupMember::STATUS_CANCELLED;
979
                    if($groupMemberMapper->update($groupMember)) {
980
 
981
                        return new JsonModel([
982
                            'success' => true,
983
                            'data' =>  'LABEL_GROUP_MEMBER_CANCELLED_SUCCESS'
984
                        ]);
985
 
986
                    } else {
987
                        return new JsonModel([
988
                            'success' => true,
989
                            'data' =>    'LABEL_GROUP_MEMBER_CANCELLED_FAILED'
990
                        ]);
991
                    }
992
                }
993
 
994
            }
995
 
996
 
997
            return new JsonModel([
998
                'success' => false,
999
                'data' => 'ERROR_GROUP_REQUEST_OR_MEMBER_NOT_FOUND_TO_CANCEL'
1000
            ]);
1001
 
1002
 
1003
 
1004
 
1005
 
1006
        } else {
1007
 
1008
            return new JsonModel([
1009
                'success' => false,
1010
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1011
            ]);
1012
        }
1013
    }
1014
 
1015
    public function  groupMemberRejectAction()
1016
    {
1017
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1018
        $currentUser = $currentUserPlugin->getUser();
1019
 
1020
        $request = $this->getRequest();
1021
        if($request->isPost()) {
1022
            $group_uuid = $this->params()->fromRoute('group_id');
1023
            $user_uuid  = $this->params()->fromRoute('user_id');
1024
 
1025
            $groupMapper = GroupMapper::getInstance($this->adapter);
3639 efrain 1026
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
1 www 1027
 
1028
            if(!$group) {
1029
                return new JsonModel([
1030
                    'success' => false,
1031
                    'data' => 'ERROR_GROUP_NOT_FOUND'
1032
                ]);
1033
            }
1034
 
1035
            if($group->status != Group::STATUS_ACTIVE) {
1036
                return new JsonModel([
1037
                    'success' => false,
1038
                    'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
1039
                ]);
1040
            }
1041
 
1042
            if($currentUser->id != $group->user_id) {
1043
                return new JsonModel([
1044
                    'success' => false,
1045
                    'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1046
                ]);
1047
            }
1048
 
1049
            $userMapper = UserMapper::getInstance($this->adapter);
3639 efrain 1050
            $user = $userMapper->fetchOneByUuidAndNetworkId($user_uuid, $currentUser->network_id);
1 www 1051
 
1052
            if(!$user) {
1053
                return new JsonModel([
1054
                    'success' => false,
1055
                    'data' => 'ERROR_USER_NOT_FOUND'
1056
                ]);
1057
            }
1058
 
1059
            if($user->id == $currentUser->id) {
1060
                return new JsonModel([
1061
                    'success' => false,
1062
                    'data' => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1063
                ]);
1064
            }
1065
 
1066
 
1067
 
1068
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1069
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
1070
            if($groupMember) {
1071
 
1072
                if($groupMember->status == GroupMember::STATUS_JOINING_REQUESTED) {
1073
 
1074
                        $groupMember->status = GroupMember::STATUS_REJECTED;
1075
                        if($groupMemberMapper->update($groupMember)) {
1076
 
1077
                            return new JsonModel([
1078
                                'success' => true,
1079
                                'data' =>  'LABEL_GROUP_MEMBER_REJECTED_SUCCESS'
1080
                            ]);
1081
 
1082
                        } else {
1083
                            return new JsonModel([
1084
                                'success' => true,
1085
                                'data' =>    'LABEL_GROUP_MEMBER_REJECTED_FAILED'
1086
                            ]);
1087
                        }
1088
                    }
1089
 
1090
            }
1091
 
1092
 
1093
            return new JsonModel([
1094
                'success' => false,
1095
                'data' => 'ERROR_GROUP_THERE_IS_NO_PENDING_REQUEST_TO_REJECT'
1096
            ]);
1097
 
1098
 
1099
 
1100
 
1101
 
1102
        } else {
1103
 
1104
            return new JsonModel([
1105
                'success' => false,
1106
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1107
            ]);
1108
        }
1109
    }
1110
 
1111
    public function  groupMemberApproveAction()
1112
    {
1113
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1114
        $currentUser = $currentUserPlugin->getUser();
1115
 
1116
        $request = $this->getRequest();
1117
        if($request->isPost()) {
1118
            $group_uuid = $this->params()->fromRoute('group_id');
1119
            $user_uuid  = $this->params()->fromRoute('user_id');
1120
 
1121
            $groupMapper = GroupMapper::getInstance($this->adapter);
3639 efrain 1122
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
1 www 1123
 
1124
            if(!$group) {
1125
                return new JsonModel([
1126
                    'success' => false,
1127
                    'data' => 'ERROR_GROUP_NOT_FOUND'
1128
                ]);
1129
            }
1130
 
1131
            if($group->status != Group::STATUS_ACTIVE) {
1132
                return new JsonModel([
1133
                    'success' => false,
1134
                    'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
1135
                ]);
1136
            }
1137
 
1138
            if($currentUser->id != $group->user_id) {
1139
                return new JsonModel([
1140
                    'success' => false,
1141
                    'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1142
                ]);
1143
            }
1144
 
1145
            $userMapper = UserMapper::getInstance($this->adapter);
3639 efrain 1146
            $user = $userMapper->fetchOneByUuidAndNetworkId($user_uuid, $currentUser->network_id);
1 www 1147
 
1148
            if(!$user) {
1149
                return new JsonModel([
1150
                    'success' => false,
1151
                    'data' => 'ERROR_USER_NOT_FOUND'
1152
                ]);
1153
            }
1154
 
1155
            if($user->id == $currentUser->id) {
1156
                return new JsonModel([
1157
                    'success' => false,
1158
                    'data' => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1159
                ]);
1160
            }
1161
 
1162
 
1163
 
1164
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1165
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
1166
            if($groupMember) {
1167
 
1168
                if($groupMember->status == GroupMember::STATUS_JOINING_REQUESTED) {
1169
 
1170
                    $groupMember->status = GroupMember::STATUS_ACCEPTED;
1171
                    if($groupMemberMapper->update($groupMember)) {
1172
 
1173
 
1174
                        $notification = new Notification();
1175
                        $notification->type     = Notification::TYPE_ACCEPT_MY_REQUEST_JOIN_GROUP;
1176
                        $notification->read     = Notification::NO;
1177
                        $notification->user_id  = $user->id;
1178
                        $notification->group_id = $group->id;
1179
                        $notification->message  = 'LABEL_NOTIFICATION_ACCEPT_MY_REQUEST_JOIN_GROUP';
1180
                        $notification->url      = $this->url()->fromRoute('group/view', ['id' => $group->uuid]);
1181
 
1182
                        $notificationMapper = NotificationMapper::getInstance($this->adapter);
1183
                        $notificationMapper->insert($notification);
1184
 
1185
                        $userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
1186
                        $userNotification = $userNotificationMapper->fetchOne($user->id);
1187
 
1188
                        if($userNotification && $userNotification->receive_invitation_group)
1189
                        {
1190
                            $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
3639 efrain 1191
                            $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_ACCEPT_MY_REQUEST_JOIN_GROUP, $currentUser->network_id);
1 www 1192
 
1193
                            if($emailTemplate) {
1194
                                $arrayCont = [
1195
                                    'firstname'             => $currentUser->first_name,
1196
                                    'lastname'              => $currentUser->last_name,
1197
                                    'other_user_firstname'  => $user->first_name,
1198
                                    'other_user_lastname'   => $user->last_name,
1199
                                    'company_name'          => '',
1200
                                    'group_name'            => $group->name,
1201
                                    'content'               => '',
1202
                                    'code'                  => '',
1203
                                    'link'                  => $this->url()->fromRoute('group/view', ['id' => $group->uuid], ['force_canonical' => true])
1204
                                ];
1205
 
1206
                                $email = new QueueEmail($this->adapter);
1207
                                $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1208
                            }
1209
                        }
1210
 
1211
                        return new JsonModel([
1212
                            'success' => true,
1213
                            'data' =>  'LABEL_GROUP_MEMBER_APPROVED_SUCCESS'
1214
                        ]);
1215
 
1216
                    } else {
1217
                        return new JsonModel([
1218
                            'success' => true,
1219
                            'data' =>    'LABEL_GROUP_MEMBER_APPROVED_FAILED'
1220
                        ]);
1221
                    }
1222
                }
1223
 
1224
            }
1225
 
1226
 
1227
            return new JsonModel([
1228
                'success' => false,
1229
                'data' => 'ERROR_GROUP_THERE_IS_NO_PENDING_REQUEST_TO_APPROVED'
1230
            ]);
1231
 
1232
 
1233
 
1234
 
1235
 
1236
        } else {
1237
 
1238
            return new JsonModel([
1239
                'success' => false,
1240
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1241
            ]);
1242
        }
1243
    }
1244
 
1245
 
1246
    /**
1247
     * Recuperamos los grupos sugeridos
1248
     * tiene que enviarse un petición GET a la siguiente url: /helpers/groups-suggestion/:group_id
1249
     * retorna un json en caso de ser  positivo
1250
     * [
1251
     *  'success' : true,
1252
     *  'data' : [
1253
     *      [
1254
     *        'id'      => 'id del grupo encriptado',
1255
     *        'name'    => 'nombre del grupo',
1256
     *        'image'   => 'imagen del grupo',
1257
     *        'profile' => 'url del profile',
1258
     *     ]
1259
     * ]
1260
     * En caso de ser negativo
1261
     * [
1262
     *  'success' : false,
1263
     *  'data' : mensaje de error
1264
     * ]
1265
     * @return \Laminas\View\Model\JsonModel
1266
     */
1267
    public function groupsSuggestionAction()
1268
    {
1269
 
1270
        $request = $this->getRequest();
1271
        if($request->isGet()) {
1272
 
1273
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1274
            $currentUser = $currentUserPlugin->getUser();
1275
 
1276
            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1277
            $first_degree_connections_ids = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
1278
            $first_degree_connections_ids = $first_degree_connections_ids ? $first_degree_connections_ids : [0];
1279
 
1280
            $second_degree_connections_ids = $connectionMapper->fetchAllSecondDegreeConnectionsForUserIdReturnIds($currentUser->id);
1281
            $second_degree_connections_ids = $second_degree_connections_ids ? $second_degree_connections_ids : [0];
1282
 
1283
            /*Usuarios de la empresas donde trabajo o soy dueño */
1284
            $company_user_ids = [];
1285
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1286
 
1287
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
1288
            foreach($records as $record)
1289
            {
1290
 
1291
                if($record->status != CompanyUser::STATUS_ACCEPTED) {
1292
                    continue;
1293
                }
1294
 
1295
                $otherUsers = $companyUserMapper->fetchAllByCompanyId($record->company_id);
1296
                foreach($otherUsers as $otherUser)
1297
                {
1298
                    if($currentUser->id != $otherUser->user_id && $otherUser->creator == CompanyUser::CREATOR_NO && $otherUser->status == CompanyUser::STATUS_ACCEPTED) {
1299
 
1300
                        if(!in_array($otherUser->user_id, $company_user_ids)) {
1301
                            array_push($company_user_ids, $otherUser->user_id);
1302
                        }
1303
                    }
1304
                }
1305
            }
1306
            $company_user_ids =  $company_user_ids ? $company_user_ids : [0];
1307
 
1308
            /* Usuario de los grupos donde soy dueño o participo */
1309
 
1310
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1311
 
1312
            $group_member_ids = [];
1313
 
1314
            $records = $groupMemberMapper->fetchAllByUserId($currentUser->id);
1315
            foreach($records as $record)
1316
            {
1317
                if($record->status != GroupMember::STATUS_ACCEPTED) {
1318
                    continue;
1319
                }
1320
 
1321
                $otherUsers = $groupMemberMapper->fetchAllByGroupId($record->group_id);
1322
                foreach($otherUsers as $otherUser)
1323
                {
1324
                    if($currentUser->id != $otherUser->user_id && $otherUser->status == GroupMember::STATUS_ACCEPTED) {
1325
 
1326
                        if(!in_array($otherUser->user_id, $group_member_ids)) {
1327
                            array_push($group_member_ids, $otherUser->user_id);
1328
                        }
1329
                    }
1330
                }
1331
 
1332
 
1333
            }
1334
 
1335
            $group_member_ids = $group_member_ids ? $group_member_ids : [0];
1336
 
1337
            /* Usuarios con que comparto capsulas */
1338
            $capsule_user_ids = [];
1339
            $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
1340
 
1341
            $company_ids = [];
1342
            $records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
1343
            foreach($records as $record)
1344
            {
1345
                if(!in_array($record->company_id,$company_ids)) {
1346
                    array_push($company_ids, $record->company_id);
1347
                }
1348
            }
1349
 
1350
            foreach($company_ids as $company_id)
1351
            {
1352
                $otherUsers = $capsuleUserMapper->fetchAllUserIdsForCapsulesActiveByCompanyId($company_id);
1353
                foreach($otherUsers as $user_id)
1354
                {
1355
                    if($currentUser->id != $user_id ) {
1356
 
1357
                        if(!in_array($user_id, $capsule_user_ids)) {
1358
                            array_push($capsule_user_ids, $user_id);
1359
                        }
1360
                    }
1361
                }
1362
            }
1363
 
1364
            $capsule_user_ids = $capsule_user_ids ? $capsule_user_ids : [0];
1365
 
3285 efrain 1366
 
1 www 1367
            $other_users = array_unique(array_merge(
3285 efrain 1368
 
1 www 1369
                $second_degree_connections_ids,
1370
                $company_user_ids,
1371
                $group_member_ids,
1372
                $capsule_user_ids
1373
            ));
1374
 
3285 efrain 1375
            $queryMapper = QueryMapper::getInstance($this->adapter);
1376
 
1 www 1377
 
1378
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1379
            $group_ids = $groupMemberMapper->fetchAllGroupIdsByUserIds( $other_users);
1380
            $group_ids = $group_ids ? $group_ids : [0];
3285 efrain 1381
 
1 www 1382
 
1383
 
3285 efrain 1384
 
1 www 1385
            $select = $queryMapper->getSql()->select();
3285 efrain 1386
            $select->columns(['id', 'uuid', 'name','image','status','privacy', 'priority' => new Expression('0') ]);
1 www 1387
            $select->from(['g' => GroupMapper::_TABLE]);
3639 efrain 1388
            $select->where->equalTo('network_id', $currentUser->network_id);
1 www 1389
            $select->where->equalTo('privacy', Group::PRIVACY_IS_PUBLIC);
1390
            $select->where->equalTo('status', Group::STATUS_ACTIVE);
3285 efrain 1391
            $select->where->in('g.id', $group_ids);
1 www 1392
            $select->where->notEqualTo('g.user_id', $currentUser->id);
3285 efrain 1393
            $select->order('name ASC');
1 www 1394
 
3285 efrain 1395
 
1396
 
1 www 1397
            //echo $select->getSqlString($this->adapter->platform); exit;
3285 efrain 1398
 
1399
            $records = $queryMapper->fetchAll($select);
1400
            usort($records, function ($a, $b) {
1401
                if( $a['priority'] == $b['priority'] ) {
1402
                    return 0;
1403
                } else {
1404
                    return $a['priority'] < $b['priority'] ? 1 : -1;
1405
                }
1406
            });
1407
 
1408
 
1 www 1409
            $items = [];
3285 efrain 1410
 
1 www 1411
            foreach($records as $record)
1412
            {
1413
 
1414
                array_push($items, [
1415
                    'id'        => $record['uuid'],
1416
                    'name'      => trim($record['name']),
1417
                    'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'group', 'filename' => $record['image']]),
1418
                    'profile'   => $this->url()->fromRoute('group/view', ['id' => $record['uuid'] ]),
3285 efrain 1419
                    'priority'  => $record['priority'],
1420
 
1 www 1421
                ]);
1422
 
1423
            }
1424
 
1425
            return new JsonModel([
1426
                'success' => true,
1427
                'data' => $items
1428
            ]);
1429
 
1430
 
1431
        } else {
1432
            return new JsonModel([
1433
                'success' => false,
1434
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1435
            ]);
1436
        }
1437
    }
1438
 
1439
    public function postsAction()
1440
    {
3671 efrain 1441
        $request = $this->getRequest();
1 www 1442
        if($request->isGet()) {
3639 efrain 1443
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1444
            $currentUser = $currentUserPlugin->getUser();
1445
 
1 www 1446
            $items = [];
1447
            $postMapper = PostMapper::getInstance($this->adapter);
3639 efrain 1448
            $posts = $postMapper->fetchAllActiveByNetworkId($currentUser->network_id);
1 www 1449
 
1450
            //print_r($posts);
1451
 
1452
            foreach($posts as $post)
1453
            {
1454
                $dt = \DateTime::createFromFormat('Y-m-d', $post->date);
1455
                array_push($items, [
2919 efrain 1456
                    'image' => $this->url()->fromRoute('storage', ['code' => $post->uuid, 'type' => 'post', 'filename' => $post->image  ]),
1457
                    'date' => $dt->format('d/m/Y'),
1 www 1458
                   'title' => $post->title,
1459
                   'link' => $this->url()->fromRoute('post', ['id' => $post->uuid]),
1460
                ]);
1461
 
1462
            }
1463
 
1464
            return new JsonModel([
1465
                'success' => true,
1466
                'data' => $items
1467
            ]);
1468
        }
1469
 
1470
        return new JsonModel([
1471
            'success' => false,
1472
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1473
        ]);
1474
    }
1475
 
1476
 
1477
 
1478
    public function searchPeopleAction()
1479
    {
1480
        $request = $this->getRequest();
1481
        if($request->isGet()) {
3639 efrain 1482
 
1 www 1483
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1484
            $currentUser = $currentUserPlugin->getUser();
3639 efrain 1485
 
1 www 1486
            $search = trim(filter_var( $this->params()->fromQuery('search'), FILTER_SANITIZE_STRING)) ;
1487
            if(strlen($search) >= 3) {
1488
 
1489
 
1490
                $userMapper = UserMapper::getInstance($this->adapter);
3639 efrain 1491
                $records  = $userMapper->fetchAllSuggestByNetworkIdAndSearch($currentUser->network_id, $search);
1 www 1492
 
1493
                $users = [];
1494
                foreach($records as $record)
1495
                {
1496
                    if($currentUser->id == $record->id) {
1497
                        continue;
1498
                    }
1499
 
1500
 
1501
                    array_push($users, [
1502
                        'value' => $record->uuid,
1503
                        'text' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')'
1504
 
1505
                    ]);
1506
                }
1507
 
1508
                return new JsonModel([
1509
                    'success' => true,
1510
                    'data' => $users
1511
                ]);
1512
 
1513
 
1514
 
1515
 
1516
            } else {
1517
                return new JsonModel([
1518
                    'success' => true,
1519
                    'data' => [
1520
 
1521
                    ]
1522
                ]);
1523
            }
1524
 
1525
 
1526
 
1527
 
1528
        } else {
1529
            return new JsonModel([
1530
                'success' => false,
1531
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1532
            ]);
1533
        }
1534
    }
1535
 
2444 efrain 1536
    public function footerAction()
1537
    {
1538
        $request = $this->getRequest();
1539
        if($request->isGet()) {
1540
 
1541
 
1542
            $links = isset($this->navigation['footer']) ?  $this->navigation['footer'] : [];
1543
 
1544
 
1545
            $data = [];
1546
            foreach($links as $link)
1547
            {
1548
                $data[ $link['route'] ] = $link['label'];
1549
            }
1550
 
1551
 
1552
            return new JsonModel([
1553
               'success' => true,
1554
               'data' => $data,
1555
            ]);
1556
 
1557
        } else {
1558
            return new JsonModel([
1559
                'success' => false,
1560
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1561
            ]);
1562
        }
1563
    }
1564
 
3298 efrain 1565
 
1566
    /**
1567
     * Recuperamos los grupos sugeridos
1568
     * tiene que enviarse un petición GET a la siguiente url: /helpers/groups-suggestion/:group_id
1569
     * retorna un json en caso de ser  positivo
1570
     * [
1571
     *  'success' : true,
1572
     *  'data' : [
1573
     *      [
1574
     *        'id'      => 'id del grupo encriptado',
1575
     *        'name'    => 'nombre del grupo',
1576
     *        'image'   => 'imagen del grupo',
1577
     *        'profile' => 'url del profile',
1578
     *     ]
1579
     * ]
1580
     * En caso de ser negativo
1581
     * [
1582
     *  'success' : false,
1583
     *  'data' : mensaje de error
1584
     * ]
1585
     * @return \Laminas\View\Model\JsonModel
1586
     */
1587
    public function myGroupsAction()
1588
    {
1589
 
1590
        $request = $this->getRequest();
1591
        if($request->isGet()) {
1592
 
1593
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1594
            $currentUser = $currentUserPlugin->getUser();
1595
 
1596
 
1597
            $queryMapper = QueryMapper::getInstance($this->adapter);
1598
            $select = $queryMapper->getSql()->select();
1599
            $select->columns(['id', 'uuid', 'name','image','status','privacy', 'priority' => new Expression('0') ]);
1600
            $select->from(['g' => GroupMapper::_TABLE]);
1601
            $select->where->equalTo('status', Group::STATUS_ACTIVE);
1602
            $select->where->equalTo('g.user_id', $currentUser->id);
1603
            $select->order('name ASC');
1604
 
1605
 
1606
            $items = [];
1607
 
1608
            $records = $queryMapper->fetchAll($select);
1609
            foreach($records as $record)
1610
            {
1611
 
1612
                array_push($items, [
1613
                    'id'        => $record['uuid'],
1614
                    'name'      => trim($record['name']),
1615
                    'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'group', 'filename' => $record['image']]),
1616
                    'profile'   => $this->url()->fromRoute('group/view', ['id' => $record['uuid'] ]),
1617
                    'priority'  => $record['priority'],
1618
 
1619
                ]);
1620
 
1621
            }
1622
 
1623
            return new JsonModel([
1624
                'success' => true,
1625
                'data' => $items
1626
            ]);
1627
 
1628
 
1629
        } else {
1630
            return new JsonModel([
1631
                'success' => false,
1632
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1633
            ]);
1634
        }
1635
    }
1636
 
4179 efrain 1637
    public function nextEventsAction()
1638
    {
1639
        $request = $this->getRequest();
1640
        if($request->isGet()) {
1641
 
1642
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1643
            $currentUser = $currentUserPlugin->getUser();
1644
 
1645
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1646
            $currentNetwork = $currentNetworkPlugin->getNetwork();
1647
 
1648
 
1649
 
1650
            $dt = new \DateTime();
1651
            $dt->setTime(0, 0, 0);
1652
            $start = $dt->format('Y-m-d H:i:s');
1653
 
1654
            $dt->add(new \DateInterval('P30D'));
1655
            $dt->setTime(23, 59, 59);
1656
            $end = $dt->format('Y-m-d H:i:s');
1657
 
1658
 
1659
 
1660
 
1661
            $events = [];
1662
 
1663
 
1664
 
1665
            //3 días
1666
            $expirePeriod = 86400 * 3;
1667
            $t1 = time();
1668
 
4751 efrain 1669
            $companies = [];
1670
            $companyMapper = CompanyMapper::getInstance($this->adapter);
4179 efrain 1671
 
4751 efrain 1672
            $companyUsers = [];
1673
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1674
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
1675
 
1676
            foreach($records as $record) {
1677
                $companyUsers[$record->company_id] = $record->backend == CompanyUser::BACKEND_YES;
1678
            }
1679
 
1680
 
1681
 
4179 efrain 1682
            $zoomMeetingMapper = ZoomMeetingMapper::getInstance($this->adapter);
5051 efrain 1683
            $recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
1684
            $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1685
            $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
4751 efrain 1686
            $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
1687
            $performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
1688
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
1689
            $userMapper = UserMapper::getInstance($this->adapter);
4179 efrain 1690
 
1691
            $calendarEventMapper = CalendarEventMapper::getInstance($this->adapter);
1692
            $records = $calendarEventMapper->fetchAllByUserIdAndStartTimeAndEndTime($currentUser->id, $start, $end);
1693
            foreach($records as $record)
1694
            {
1695
                switch($record->type)
1696
                {
5051 efrain 1697
                    case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW  :
1698
                        $backgroundColor = $currentNetwork->css_calendar_recruitment_and_selection_bg_color ;
1699
                        $textColor = $currentNetwork->css_calendar_recruitment_and_selection_text_color;
1700
 
1701
 
1702
                        $recruitmentSelectionInterview = $recruitmentSelectionInterviewMapper->fetchOne($record->relational_id);
1703
                        if($recruitmentSelectionInterview) {
1704
 
1705
                            $recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($recruitmentSelectionInterview->vacancy_id);
1706
 
1707
 
1708
 
1709
                            $recruitmentSelectionCandidate = $recruitmentSelectionCandidateMapper->fetchOne($recruitmentSelectionInterview->candidate_id);
1710
                            if($recruitmentSelectionVacancy && $recruitmentSelectionCandidate) {
1711
                                $jobDescription = $jobDescriptionMapper->fetchOne($recruitmentSelectionVacancy->job_description_id);
1712
                                if($jobDescription) {
1713
                                    $hasLink = false;
1714
                                    if(isset($companyUsers[$currentUser->id])) {
1715
                                        if($companyUsers[$currentUser->id]) {
1716
                                            $hasLink = true;
1717
                                        }
1718
                                    }
1719
 
1720
                                    if($hasLink) {
1721
 
1722
                                        if(!isset($companies[$recruitmentSelectionInterview->company_id])) {
1723
                                            $company  = $companyMapper->fetchOne($recruitmentSelectionInterview->company_id);
1724
 
1725
                                            $companies[ $company->id ]  = $company;
1726
                                        } else {
1727
                                            $company = $companies[ $recruitmentSelectionInterview->company_id ];
1728
                                        }
1729
 
1730
 
1731
                                        $href = $this->url()->fromRoute('backend/signin-company', [
1732
                                            'id' => $company->uuid,
1733
                                            'relational' => $recruitmentSelectionInterview->uuid,
1734
                                            'type' => CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW
1735
                                        ]);
1736
 
1737
 
1738
                                        $agenda = '<a href="'.$href.'" class="goto-backend"><br>';
1739
                                    }
1740
 
1741
                                    $agenda .= " LABEL_RECRUITMENT_SELECTION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
1742
                                    switch($recruitmentSelectionInterview->type)
1743
                                    {
1744
                                        case RecruitmentSelectionInterview::TYPE_BOSS :
1745
                                            $agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_BOSS_INTERVIEW <br>";
1746
                                            break;
1747
 
1748
                                        case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE :
1749
                                            $agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_HUMAN_RESOURCE <br>";
1750
                                            break;
1751
                                    }
1752
 
1753
                                    $agenda .= " LABEL_RECRUITMENT_SELECTION_CANDIDATE : " . trim($recruitmentSelectionCandidate->first_name . ' ' . $recruitmentSelectionCandidate->last_name) . " <br>";
1754
 
1755
 
1756
 
1757
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $recruitmentSelectionInterview->last_date);
1758
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>" ;
1759
 
1760
                                    if($hasLink) {
1761
                                        $agenda .= "</a><br>";
1762
                                    }
1763
 
1764
 
1765
 
1766
 
1767
                                    array_push($events, [
1768
                                        'id'                => $recruitmentSelectionInterview->uuid,
1769
                                        'title'             => $recruitmentSelectionVacancy->name,
1770
                                        'agenda'            => $agenda,
1771
                                        'start'             => $dtStart->format('Y-m-d'),
1772
                                        'url'               => '',
1773
                                        'backgroundColor'   => $backgroundColor,
1774
                                        'textColor'         => $textColor,
1775
                                        'allDay'            => true,
1776
                                        'type'              => 'task',
1777
                                    ]);
1778
                                }
1779
                            }
1780
                        }
1781
 
1782
 
1783
                        break;
1784
 
4751 efrain 1785
                    case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :
1786
 
1787
 
1788
                        $backgroundColor = $currentNetwork->css_calendar_performance_evaluation_bg_color ;
1789
                        $textColor = $currentNetwork->css_calendar_performance_evaluation_text_color;
1790
 
1791
 
1792
                        $performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOne($record->relational_id);
1793
                        if($performanceEvaluationTest) {
1794
 
1795
                            $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
1796
                            if($performanceEvaluationForm) {
1797
                                $jobDescription = $jobDescriptionMapper->fetchOne($performanceEvaluationForm->job_description_id);
1798
                                if($jobDescription) {
1799
 
1800
 
1801
                                    if($performanceEvaluationTest->supervisor_id) {
1802
                                        $supervisor = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);
1803
                                    } else {
1804
                                        $supervisor = '';
1805
                                    }
1806
 
1807
                                    if($performanceEvaluationTest->employee_id) {
1808
                                        $employee = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
1809
                                    } else {
1810
                                        $employee = '';
1811
                                    }
1812
 
1813
 
1814
 
1815
 
1816
                                    $hasLink = false;
1817
                                    if(isset($companyUsers[$currentUser->id])) {
1818
                                        if($companyUsers[$currentUser->id]) {
1819
                                            $hasLink = true;
1820
                                        }
1821
                                    }
1822
 
1823
                                    if($hasLink) {
1824
 
1825
                                        if(!isset($companies[$performanceEvaluationTest->company_id])) {
1826
                                            $company  = $companyMapper->fetchOne($performanceEvaluationTest->company_id);
1827
 
1828
                                            $companies[ $company->id ]  = $company;
1829
                                        } else {
1830
                                            $company = $companies[ $performanceEvaluationTest->company_id ];
1831
                                        }
1832
 
1833
 
1834
                                        $href = $this->url()->fromRoute('backend/signin-company', [
1835
                                            'id' => $company->uuid,
1836
                                            'relational' => $performanceEvaluationTest->uuid,
1837
                                            'type' => CalendarEvent::TYPE_PERFORMANCE_EVALUATION
1838
                                        ]);
1839
 
1840
 
1841
                                        $agenda = '<a href="'.$href.'" class="goto-backend"><br>';
1842
                                    }
1843
 
1844
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_FORM_NAME : " . $performanceEvaluationForm->name . "<br>";
1845
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
1846
 
1847
                                    switch($performanceEvaluationTest->type)
1848
                                    {
1849
                                        case PerformanceEvaluationTest::TYPE_BOTH :
1850
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH <br>";
1851
                                            break;
1852
 
1853
                                        case PerformanceEvaluationTest::TYPE_SUPERVISOR :
1854
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR <br>";
1855
                                            break;
1856
 
1857
                                        case PerformanceEvaluationTest::TYPE_EMPLOYEE :
1858
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE <br>";
1859
                                            break;
1860
 
1861
 
1862
                                    }
1863
 
1864
                                    if($supervisor) {
1865
                                        $agenda .= " LABEL_PERFORMANCE_EVALUATION_SUPERVISOR : " . trim($supervisor->first_name . ' ' . $supervisor->last_name) . " <br>";
1866
 
1867
                                    }
1868
                                    if($employee) {
1869
                                        $agenda .= " LABEL_PERFORMANCE_EVALUATION_EMPLOYEE : " . trim($employee->first_name . ' ' . $employee->last_name) . " <br>";
1870
 
1871
                                    }
1872
 
1873
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $performanceEvaluationTest->last_date);
1874
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>" ;
1875
 
1876
                                    if($hasLink) {
1877
                                        $agenda .= "</a><br>";
1878
                                    }
1879
 
1880
 
1881
 
1882
 
1883
                                    array_push($events, [
1884
                                        'id'                => $performanceEvaluationTest->uuid,
1885
                                        'title'             =>  $performanceEvaluationForm->name,
1886
                                        'agenda'            => $agenda,
1887
                                        'start'             => $dtStart->format('Y-m-d'),
1888
                                        'url'               => '',
1889
                                        'backgroundColor'   => $backgroundColor,
1890
                                        'textColor'         => $textColor,
1891
                                        'allDay'            => true,
1892
                                        'type'              => 'task',
1893
                                    ]);
1894
                                }
1895
                            }
1896
 
1897
                        }
1898
 
1899
 
1900
 
1901
 
1902
 
1903
                        break;
1904
 
1905
 
4179 efrain 1906
                    case CalendarEvent::TYPE_ZOOM :
1907
                        $zoomMeeting = $zoomMeetingMapper->fetchOne($record->relational_id);
1908
                        if($zoomMeeting) {
1909
 
1910
                            $backgroundColor = $currentNetwork->css_calendar_zoom_bg_color ;
1911
                            $textColor = $currentNetwork->css_calendar_zoom_text_color;
1912
 
1913
                            $dtStart = \DateTime::createFromFormat('Y-m-d H:i:s', $zoomMeeting->start_time);
1914
                            $t2 = $dtStart->getTimestamp();
1915
 
1916
                            if($t2 > $t1) {
1917
 
1918
                                $t3 = $t1 + $expirePeriod;
1919
                                if($t3 > $t2) {
1920
                                    $backgroundColor = $currentNetwork->css_calendar_expire_bg_color;
1921
                                    $textColor = $currentNetwork->css_calendar_expire_text_color;
1922
                                }
1923
 
1924
                            }
1925
 
1926
 
1927
 
1928
                            if($currentUser->timezone && $currentUser->timezone != $zoomMeeting->timezone) {
1929
 
1930
                                $start =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->start_time, $zoomMeeting->timezone, $currentUser->timezone));
1931
                                $end =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->end_time, $zoomMeeting->timezone, $currentUser->timezone));
1932
 
1933
 
1934
 
1935
 
1936
 
1937
                            } else {
1938
                                $start = str_replace(' ', 'T', $zoomMeeting->start_time);
1939
                                $end = str_replace(' ', 'T', $zoomMeeting->end_time);
1940
                            }
1941
 
1942
 
1943
 
1944
 
1945
 
1946
 
1947
                            $agenda = "<a href=\"{$zoomMeeting->join_url}\" target=\"_blank\">" .  $zoomMeeting->agenda . "<br>" .
1948
                                " LABEL_ZOOM_MEETING_START_DATE : " . $dtStart->format('Y-m-d') . "<br>" .
1949
                                " LABEL_ZOOM_MEETING_START_TIME : " . $dtStart->format('H:i a') . "<br>" .
1950
                                " LABEL_ZOOM_MEETING_TIMEZONE : " . $zoomMeeting->timezone . "<br>" .
1951
                                " LABEL_ZOOM_MEETING_TITLE :  " . $zoomMeeting->topic  . "<br>" .
1952
                                " LABEL_ZOOM_MEETING_URL : " . $zoomMeeting->join_url . "<br>" .
1953
                                " LABEL_ZOOM_MEETING_PASSWORD : " . $zoomMeeting->password . "<br>" .
1954
                                "</a>";
1955
 
1956
                            array_push($events, [
1957
                                'id'                => $zoomMeeting->id,
1958
                                'title'             => $zoomMeeting->topic,
1959
                                'agenda'            => $agenda,
1960
                                'start'             => $start,
1961
                                'end'               => $end,
1962
                                'url'               => $zoomMeeting->join_url,
1963
                                'backgroundColor'   => $backgroundColor,
1964
                                'textColor'         => $textColor,
4700 efrain 1965
                                'type'              => 'event'
4179 efrain 1966
                            ]);
1967
                        }
1968
                        break;
1969
 
1970
 
1971
                }
1972
 
1973
 
1974
 
1975
            }
1976
 
1977
 
1978
 
1979
            return new JsonModel([
1980
                'success' => true,
1981
                'data' => $events
1982
            ]);
1983
 
1984
 
1985
        } else {
1986
            return new JsonModel([
1987
                'success' => false,
1988
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1989
            ]);
1990
        }
1991
    }
1992
 
5205 efrain 1993
 
1994
 
1 www 1995
}