Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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