Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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