Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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