Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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