Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5978 | Rev 6271 | 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();
6270 anderson 130
        // if ($request->isGet()) {
131
        //     $currentUserPlugin = $this->plugin('currentUserPlugin');
132
        //     $currentUser = $currentUserPlugin->getUser();
5966 anderson 133
 
6270 anderson 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];
1 www 137
 
6270 anderson 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
 
6270 anderson 141
        //     /*Usuarios de la empresas donde trabajo o soy dueño */
142
        //     $company_user_ids = [];
143
        //     $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
5966 anderson 144
 
6270 anderson 145
        //     $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
146
        //     foreach ($records as $record) {
5966 anderson 147
 
6270 anderson 148
        //         if ($record->status != CompanyUser::STATUS_ACCEPTED) {
149
        //             continue;
150
        //         }
5966 anderson 151
 
6270 anderson 152
        //         $otherUsers = $companyUserMapper->fetchAllByCompanyId($record->company_id);
153
        //         foreach ($otherUsers as $otherUser) {
154
        //             if ($currentUser->id != $otherUser->user_id && $otherUser->creator == CompanyUser::CREATOR_NO && $otherUser->status == CompanyUser::STATUS_ACCEPTED) {
5966 anderson 155
 
6270 anderson 156
        //                 if (!in_array($otherUser->user_id, $company_user_ids)) {
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
 
6270 anderson 164
        //     /* Usuario de los grupos donde soy dueño o participo */
5966 anderson 165
 
6270 anderson 166
        //     $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
5966 anderson 167
 
6270 anderson 168
        //     $group_member_ids = [];
5966 anderson 169
 
6270 anderson 170
        //     $records = $groupMemberMapper->fetchAllByUserId($currentUser->id);
171
        //     foreach ($records as $record) {
172
        //         if ($record->status != GroupMember::STATUS_ACCEPTED) {
173
        //             continue;
174
        //         }
5966 anderson 175
 
6270 anderson 176
        //         $otherUsers = $groupMemberMapper->fetchAllByGroupId($record->group_id);
177
        //         foreach ($otherUsers as $otherUser) {
178
        //             if ($currentUser->id != $otherUser->user_id && $otherUser->status == GroupMember::STATUS_ACCEPTED) {
5966 anderson 179
 
6270 anderson 180
        //                 if (!in_array($otherUser->user_id, $group_member_ids)) {
181
        //                     array_push($group_member_ids, $otherUser->user_id);
182
        //                 }
183
        //             }
184
        //         }
185
        //     }
5966 anderson 186
 
6270 anderson 187
        //     $group_member_ids = $group_member_ids ? $group_member_ids : [0];
1 www 188
 
5966 anderson 189
 
190
 
6270 anderson 191
        //     /* Usuarios con que comparto capsulas */
192
        //     $capsule_user_ids = [];
193
        //     $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
5966 anderson 194
 
6270 anderson 195
        //     $company_ids = [];
196
        //     $records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
197
        //     foreach ($records as $record) {
198
        //         if (!in_array($record->company_id, $company_ids)) {
199
        //             array_push($company_ids, $record->company_id);
200
        //         }
201
        //     }
5966 anderson 202
 
203
 
204
 
6270 anderson 205
        //     foreach ($company_ids as $company_id) {
206
        //         $otherUsers = $capsuleUserMapper->fetchAllUserIdsForCapsulesActiveByCompanyId($company_id);
207
        //         foreach ($otherUsers as $user_id) {
208
        //             if ($currentUser->id != $user_id) {
5966 anderson 209
 
6270 anderson 210
        //                 if (!in_array($user_id, $capsule_user_ids)) {
211
        //                     array_push($capsule_user_ids, $user_id);
212
        //                 }
213
        //             }
214
        //         }
215
        //     }
5966 anderson 216
 
6270 anderson 217
        //     $capsule_user_ids = $capsule_user_ids ? $capsule_user_ids : [0];
5966 anderson 218
 
219
 
6270 anderson 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
 
6270 anderson 234
        //     $items = [];
235
        //     $queryMapper = QueryMapper::getInstance($this->adapter);
236
        //     $select = $queryMapper->getSql()->select();
237
        //     $select->columns(['id', 'uuid',  'first_name', 'last_name', 'image']);
238
        //     $select->from(['u' => UserMapper::_TABLE]);
239
        //     $select->where->equalTo('network_id', $currentUser->network_id);
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]);
245
        //     $select->order(['first_name', 'last_name']);
5966 anderson 246
 
6270 anderson 247
        //     //echo $select->getSqlString($this->adapter->platform); exit;
5966 anderson 248
 
6270 anderson 249
        //     $records = $queryMapper->fetchAll($select);
250
        //     foreach ($records as $record) {
1 www 251
 
6270 anderson 252
        //         $relation = [];
253
        //         if (in_array($record['id'], $second_degree_connections_ids)) {
254
        //             array_push($relation, 'LABEL_RELATION_TYPE_SECOND_GRADE');
255
        //         }
256
        //         if (in_array($record['id'], $company_user_ids)) {
257
        //             array_push($relation, 'LABEL_RELATION_TYPE_COMPANY_USER');
258
        //         }
259
        //         if (in_array($record['id'], $group_member_ids)) {
260
        //             array_push($relation, 'LABEL_RELATION_TYPE_GROUP_MEMBER');
261
        //         }
262
        //         if (in_array($record['id'], $capsule_user_ids)) {
263
        //             array_push($relation, 'LABEL_RELATION_TYPE_CAPSULE_USER');
264
        //         }
5966 anderson 265
 
266
 
6270 anderson 267
        //         $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $record['id']);
5966 anderson 268
 
6270 anderson 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']]),
273
        //             'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
274
        //             'relation' => $relation,
275
        //             'link_cancel'   => '',
276
        //             'link_request'  => '',
277
        //         ];
5966 anderson 278
 
6270 anderson 279
        //         if ($connection) {
280
        //             switch ($connection->status) {
281
        //                 case Connection::STATUS_SENT:
282
        //                     $item['link_cancel'] = $this->url()->fromRoute('connection/delete', ['id' => $record['uuid']]);
283
        //                     break;
5966 anderson 284
 
6270 anderson 285
        //                 case Connection::STATUS_ACCEPTED:
286
        //                     $item['link_cancel'] = $this->url()->fromRoute('connection/cancel', ['id' => $record['uuid']]);
287
        //                     break;
5966 anderson 288
 
6270 anderson 289
        //                 default:
290
        //                     $item['link_request'] = $this->url()->fromRoute('connection/request', ['id' => $record['uuid']]);
291
        //                     break;
292
        //             }
293
        //         } else {
294
        //             $item['link_request'] = $this->url()->fromRoute('connection/request', ['id' => $record['uuid']]);
295
        //         }
5966 anderson 296
 
297
 
6270 anderson 298
        //         array_push($items, $item);
299
        //     }
1 www 300
 
6270 anderson 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();
5967 anderson 1389
        if ($request->isGet()) {
3639 efrain 1390
 
5967 anderson 1391
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1392
            $currentUser = $currentUserPlugin->getUser();
3639 efrain 1393
 
5978 anderson 1394
            $search = trim(filter_var($this->params()->fromQuery('search'), FILTER_SANITIZE_STRING));
5970 anderson 1395
            if (strlen($search) >= 3) {
5966 anderson 1396
 
1397
 
5967 anderson 1398
                $userMapper = UserMapper::getInstance($this->adapter);
1399
                $records  = $userMapper->fetchAllSuggestByNetworkIdAndSearch($currentUser->network_id, $search);
5966 anderson 1400
 
5967 anderson 1401
                $users = [];
1402
                foreach ($records as $record) {
1403
                    if ($currentUser->id == $record->id) {
1404
                        continue;
1405
                    }
5966 anderson 1406
 
1407
 
5967 anderson 1408
                    array_push($users, [
1409
                        'value' => $record->uuid,
5972 anderson 1410
                        'text' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')'
5966 anderson 1411
 
5967 anderson 1412
                    ]);
1413
                }
1414
 
1415
                return new JsonModel([
1416
                    'success' => true,
1417
                    'data' => $users
1418
                ]);
1419
            } else {
1420
                return new JsonModel([
1421
                    'success' => true,
1422
                    'data' => []
1423
                ]);
1424
            }
1425
        } else {
1426
            return new JsonModel([
1427
                'success' => false,
1428
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1 www 1429
            ]);
1430
        }
1431
    }
5966 anderson 1432
 
2444 efrain 1433
    public function footerAction()
1434
    {
1435
        $request = $this->getRequest();
5966 anderson 1436
        if ($request->isGet()) {
1437
 
1438
 
2444 efrain 1439
            $links = isset($this->navigation['footer']) ?  $this->navigation['footer'] : [];
5966 anderson 1440
 
1441
 
2444 efrain 1442
            $data = [];
5966 anderson 1443
            foreach ($links as $link) {
1444
                $data[$link['route']] = $link['label'];
2444 efrain 1445
            }
5966 anderson 1446
 
1447
 
2444 efrain 1448
            return new JsonModel([
5966 anderson 1449
                'success' => true,
1450
                'data' => $data,
2444 efrain 1451
            ]);
1452
        } else {
1453
            return new JsonModel([
1454
                'success' => false,
1455
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1456
            ]);
1457
        }
1458
    }
5966 anderson 1459
 
1460
 
3298 efrain 1461
    /**
1462
     * Recuperamos los grupos sugeridos
1463
     * tiene que enviarse un petición GET a la siguiente url: /helpers/groups-suggestion/:group_id
1464
     * retorna un json en caso de ser  positivo
1465
     * [
1466
     *  'success' : true,
1467
     *  'data' : [
1468
     *      [
1469
     *        'id'      => 'id del grupo encriptado',
1470
     *        'name'    => 'nombre del grupo',
1471
     *        'image'   => 'imagen del grupo',
1472
     *        'profile' => 'url del profile',
1473
     *     ]
1474
     * ]
1475
     * En caso de ser negativo
1476
     * [
1477
     *  'success' : false,
1478
     *  'data' : mensaje de error
1479
     * ]
1480
     * @return \Laminas\View\Model\JsonModel
1481
     */
1482
    public function myGroupsAction()
1483
    {
5966 anderson 1484
 
3298 efrain 1485
        $request = $this->getRequest();
5966 anderson 1486
        if ($request->isGet()) {
1487
 
3298 efrain 1488
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1489
            $currentUser = $currentUserPlugin->getUser();
5966 anderson 1490
 
1491
 
3298 efrain 1492
            $queryMapper = QueryMapper::getInstance($this->adapter);
1493
            $select = $queryMapper->getSql()->select();
5966 anderson 1494
            $select->columns(['id', 'uuid', 'name', 'image', 'status', 'privacy', 'priority' => new Expression('0')]);
3298 efrain 1495
            $select->from(['g' => GroupMapper::_TABLE]);
1496
            $select->where->equalTo('status', Group::STATUS_ACTIVE);
1497
            $select->where->equalTo('g.user_id', $currentUser->id);
1498
            $select->order('name ASC');
5966 anderson 1499
 
1500
 
3298 efrain 1501
            $items = [];
5966 anderson 1502
 
3298 efrain 1503
            $records = $queryMapper->fetchAll($select);
5966 anderson 1504
            foreach ($records as $record) {
1505
 
3298 efrain 1506
                array_push($items, [
1507
                    'id'        => $record['uuid'],
1508
                    'name'      => trim($record['name']),
1509
                    'image'     => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'group', 'filename' => $record['image']]),
5966 anderson 1510
                    'profile'   => $this->url()->fromRoute('group/view', ['id' => $record['uuid']]),
3298 efrain 1511
                    'priority'  => $record['priority'],
5966 anderson 1512
 
3298 efrain 1513
                ]);
1514
            }
5966 anderson 1515
 
3298 efrain 1516
            return new JsonModel([
1517
                'success' => true,
1518
                'data' => $items
1519
            ]);
1520
        } else {
1521
            return new JsonModel([
1522
                'success' => false,
1523
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1524
            ]);
1525
        }
1526
    }
5966 anderson 1527
 
4179 efrain 1528
    public function nextEventsAction()
1529
    {
1530
        $request = $this->getRequest();
5966 anderson 1531
        if ($request->isGet()) {
1532
 
4179 efrain 1533
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1534
            $currentUser = $currentUserPlugin->getUser();
5966 anderson 1535
 
4179 efrain 1536
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1537
            $currentNetwork = $currentNetworkPlugin->getNetwork();
1538
 
5966 anderson 1539
 
1540
 
4179 efrain 1541
            $dt = new \DateTime();
1542
            $dt->setTime(0, 0, 0);
1543
            $start = $dt->format('Y-m-d H:i:s');
5966 anderson 1544
 
4179 efrain 1545
            $dt->add(new \DateInterval('P30D'));
1546
            $dt->setTime(23, 59, 59);
1547
            $end = $dt->format('Y-m-d H:i:s');
5966 anderson 1548
 
1549
 
1550
 
1551
 
4179 efrain 1552
            $events = [];
5966 anderson 1553
 
1554
 
1555
 
4179 efrain 1556
            //3 días
1557
            $expirePeriod = 86400 * 3;
1558
            $t1 = time();
5966 anderson 1559
 
4751 efrain 1560
            $companies = [];
1561
            $companyMapper = CompanyMapper::getInstance($this->adapter);
5966 anderson 1562
 
4751 efrain 1563
            $companyUsers = [];
1564
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1565
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
5966 anderson 1566
 
1567
            foreach ($records as $record) {
4751 efrain 1568
                $companyUsers[$record->company_id] = $record->backend == CompanyUser::BACKEND_YES;
1569
            }
5966 anderson 1570
 
1571
 
1572
 
4179 efrain 1573
            $zoomMeetingMapper = ZoomMeetingMapper::getInstance($this->adapter);
5051 efrain 1574
            $recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
1575
            $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1576
            $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
4751 efrain 1577
            $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
1578
            $performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
1579
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
1580
            $userMapper = UserMapper::getInstance($this->adapter);
5966 anderson 1581
 
4179 efrain 1582
            $calendarEventMapper = CalendarEventMapper::getInstance($this->adapter);
1583
            $records = $calendarEventMapper->fetchAllByUserIdAndStartTimeAndEndTime($currentUser->id, $start, $end);
5966 anderson 1584
            foreach ($records as $record) {
1585
                switch ($record->type) {
1586
                    case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW:
1587
                        $backgroundColor = $currentNetwork->css_calendar_recruitment_and_selection_bg_color;
5051 efrain 1588
                        $textColor = $currentNetwork->css_calendar_recruitment_and_selection_text_color;
5966 anderson 1589
 
1590
 
5051 efrain 1591
                        $recruitmentSelectionInterview = $recruitmentSelectionInterviewMapper->fetchOne($record->relational_id);
5966 anderson 1592
                        if ($recruitmentSelectionInterview) {
1593
 
5051 efrain 1594
                            $recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($recruitmentSelectionInterview->vacancy_id);
5966 anderson 1595
 
1596
 
1597
 
5051 efrain 1598
                            $recruitmentSelectionCandidate = $recruitmentSelectionCandidateMapper->fetchOne($recruitmentSelectionInterview->candidate_id);
5966 anderson 1599
                            if ($recruitmentSelectionVacancy && $recruitmentSelectionCandidate) {
5051 efrain 1600
                                $jobDescription = $jobDescriptionMapper->fetchOne($recruitmentSelectionVacancy->job_description_id);
5966 anderson 1601
                                if ($jobDescription) {
5051 efrain 1602
                                    $hasLink = false;
5966 anderson 1603
                                    if (isset($companyUsers[$currentUser->id])) {
1604
                                        if ($companyUsers[$currentUser->id]) {
5051 efrain 1605
                                            $hasLink = true;
1606
                                        }
1607
                                    }
5966 anderson 1608
 
1609
                                    if ($hasLink) {
1610
 
1611
                                        if (!isset($companies[$recruitmentSelectionInterview->company_id])) {
5051 efrain 1612
                                            $company  = $companyMapper->fetchOne($recruitmentSelectionInterview->company_id);
5966 anderson 1613
 
1614
                                            $companies[$company->id]  = $company;
5051 efrain 1615
                                        } else {
5966 anderson 1616
                                            $company = $companies[$recruitmentSelectionInterview->company_id];
5051 efrain 1617
                                        }
5966 anderson 1618
 
1619
 
5051 efrain 1620
                                        $href = $this->url()->fromRoute('backend/signin-company', [
1621
                                            'id' => $company->uuid,
1622
                                            'relational' => $recruitmentSelectionInterview->uuid,
1623
                                            'type' => CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW
1624
                                        ]);
5966 anderson 1625
 
1626
 
1627
                                        $agenda = '<a href="' . $href . '" class="goto-backend"><br>';
5051 efrain 1628
                                    }
5966 anderson 1629
 
5051 efrain 1630
                                    $agenda .= " LABEL_RECRUITMENT_SELECTION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
5966 anderson 1631
                                    switch ($recruitmentSelectionInterview->type) {
1632
                                        case RecruitmentSelectionInterview::TYPE_BOSS:
5051 efrain 1633
                                            $agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_BOSS_INTERVIEW <br>";
1634
                                            break;
5966 anderson 1635
 
1636
                                        case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE:
5051 efrain 1637
                                            $agenda .= " LABEL_RECRUITMENT_SELECTION_TYPE : LABEL_RECRUITMENT_SELECTION_TYPE_HUMAN_RESOURCE <br>";
1638
                                            break;
1639
                                    }
5966 anderson 1640
 
5051 efrain 1641
                                    $agenda .= " LABEL_RECRUITMENT_SELECTION_CANDIDATE : " . trim($recruitmentSelectionCandidate->first_name . ' ' . $recruitmentSelectionCandidate->last_name) . " <br>";
5966 anderson 1642
 
1643
 
1644
 
5051 efrain 1645
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $recruitmentSelectionInterview->last_date);
5966 anderson 1646
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>";
1647
 
1648
                                    if ($hasLink) {
5051 efrain 1649
                                        $agenda .= "</a><br>";
1650
                                    }
5966 anderson 1651
 
1652
 
1653
 
1654
 
5051 efrain 1655
                                    array_push($events, [
1656
                                        'id'                => $recruitmentSelectionInterview->uuid,
1657
                                        'title'             => $recruitmentSelectionVacancy->name,
1658
                                        'agenda'            => $agenda,
1659
                                        'start'             => $dtStart->format('Y-m-d'),
1660
                                        'url'               => '',
1661
                                        'backgroundColor'   => $backgroundColor,
1662
                                        'textColor'         => $textColor,
1663
                                        'allDay'            => true,
1664
                                        'type'              => 'task',
1665
                                    ]);
1666
                                }
1667
                            }
1668
                        }
5966 anderson 1669
 
1670
 
5051 efrain 1671
                        break;
5966 anderson 1672
 
1673
                    case CalendarEvent::TYPE_PERFORMANCE_EVALUATION:
1674
 
1675
 
1676
                        $backgroundColor = $currentNetwork->css_calendar_performance_evaluation_bg_color;
4751 efrain 1677
                        $textColor = $currentNetwork->css_calendar_performance_evaluation_text_color;
5966 anderson 1678
 
1679
 
4751 efrain 1680
                        $performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOne($record->relational_id);
5966 anderson 1681
                        if ($performanceEvaluationTest) {
1682
 
4751 efrain 1683
                            $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
5966 anderson 1684
                            if ($performanceEvaluationForm) {
4751 efrain 1685
                                $jobDescription = $jobDescriptionMapper->fetchOne($performanceEvaluationForm->job_description_id);
5966 anderson 1686
                                if ($jobDescription) {
1687
 
1688
 
1689
                                    if ($performanceEvaluationTest->supervisor_id) {
4751 efrain 1690
                                        $supervisor = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);
1691
                                    } else {
1692
                                        $supervisor = '';
1693
                                    }
5966 anderson 1694
 
1695
                                    if ($performanceEvaluationTest->employee_id) {
4751 efrain 1696
                                        $employee = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
1697
                                    } else {
1698
                                        $employee = '';
1699
                                    }
5966 anderson 1700
 
1701
 
1702
 
1703
 
4751 efrain 1704
                                    $hasLink = false;
5966 anderson 1705
                                    if (isset($companyUsers[$currentUser->id])) {
1706
                                        if ($companyUsers[$currentUser->id]) {
4751 efrain 1707
                                            $hasLink = true;
1708
                                        }
1709
                                    }
5966 anderson 1710
 
1711
                                    if ($hasLink) {
1712
 
1713
                                        if (!isset($companies[$performanceEvaluationTest->company_id])) {
4751 efrain 1714
                                            $company  = $companyMapper->fetchOne($performanceEvaluationTest->company_id);
5966 anderson 1715
 
1716
                                            $companies[$company->id]  = $company;
4751 efrain 1717
                                        } else {
5966 anderson 1718
                                            $company = $companies[$performanceEvaluationTest->company_id];
4751 efrain 1719
                                        }
5966 anderson 1720
 
1721
 
4751 efrain 1722
                                        $href = $this->url()->fromRoute('backend/signin-company', [
1723
                                            'id' => $company->uuid,
1724
                                            'relational' => $performanceEvaluationTest->uuid,
1725
                                            'type' => CalendarEvent::TYPE_PERFORMANCE_EVALUATION
1726
                                        ]);
5966 anderson 1727
 
1728
 
1729
                                        $agenda = '<a href="' . $href . '" class="goto-backend"><br>';
4751 efrain 1730
                                    }
5966 anderson 1731
 
4751 efrain 1732
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_FORM_NAME : " . $performanceEvaluationForm->name . "<br>";
1733
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_JOB_DESCRIPTION : " . $jobDescription->name . "<br>";
5966 anderson 1734
 
1735
                                    switch ($performanceEvaluationTest->type) {
1736
                                        case PerformanceEvaluationTest::TYPE_BOTH:
4751 efrain 1737
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH <br>";
1738
                                            break;
5966 anderson 1739
 
1740
                                        case PerformanceEvaluationTest::TYPE_SUPERVISOR:
4751 efrain 1741
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR <br>";
1742
                                            break;
5966 anderson 1743
 
1744
                                        case PerformanceEvaluationTest::TYPE_EMPLOYEE:
4751 efrain 1745
                                            $agenda .= " LABEL_PERFORMANCE_EVALUATION_TYPE : LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE <br>";
1746
                                            break;
1747
                                    }
5966 anderson 1748
 
1749
                                    if ($supervisor) {
4751 efrain 1750
                                        $agenda .= " LABEL_PERFORMANCE_EVALUATION_SUPERVISOR : " . trim($supervisor->first_name . ' ' . $supervisor->last_name) . " <br>";
1751
                                    }
5966 anderson 1752
                                    if ($employee) {
4751 efrain 1753
                                        $agenda .= " LABEL_PERFORMANCE_EVALUATION_EMPLOYEE : " . trim($employee->first_name . ' ' . $employee->last_name) . " <br>";
1754
                                    }
5966 anderson 1755
 
4751 efrain 1756
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $performanceEvaluationTest->last_date);
5966 anderson 1757
                                    $agenda .= " LABEL_PERFORMANCE_EVALUATION_LAST_DATE : " . $dtStart->format('Y-m-d') . "<br>";
1758
 
1759
                                    if ($hasLink) {
4751 efrain 1760
                                        $agenda .= "</a><br>";
1761
                                    }
5966 anderson 1762
 
1763
 
1764
 
1765
 
4751 efrain 1766
                                    array_push($events, [
1767
                                        'id'                => $performanceEvaluationTest->uuid,
1768
                                        'title'             =>  $performanceEvaluationForm->name,
1769
                                        'agenda'            => $agenda,
1770
                                        'start'             => $dtStart->format('Y-m-d'),
1771
                                        'url'               => '',
1772
                                        'backgroundColor'   => $backgroundColor,
1773
                                        'textColor'         => $textColor,
1774
                                        'allDay'            => true,
1775
                                        'type'              => 'task',
1776
                                    ]);
1777
                                }
1778
                            }
1779
                        }
5966 anderson 1780
 
1781
 
1782
 
1783
 
1784
 
4751 efrain 1785
                        break;
5966 anderson 1786
 
1787
 
1788
                    case CalendarEvent::TYPE_ZOOM:
4179 efrain 1789
                        $zoomMeeting = $zoomMeetingMapper->fetchOne($record->relational_id);
5966 anderson 1790
                        if ($zoomMeeting) {
1791
 
1792
                            $backgroundColor = $currentNetwork->css_calendar_zoom_bg_color;
4179 efrain 1793
                            $textColor = $currentNetwork->css_calendar_zoom_text_color;
5966 anderson 1794
 
4179 efrain 1795
                            $dtStart = \DateTime::createFromFormat('Y-m-d H:i:s', $zoomMeeting->start_time);
1796
                            $t2 = $dtStart->getTimestamp();
5966 anderson 1797
 
1798
                            if ($t2 > $t1) {
1799
 
4179 efrain 1800
                                $t3 = $t1 + $expirePeriod;
5966 anderson 1801
                                if ($t3 > $t2) {
4179 efrain 1802
                                    $backgroundColor = $currentNetwork->css_calendar_expire_bg_color;
1803
                                    $textColor = $currentNetwork->css_calendar_expire_text_color;
1804
                                }
1805
                            }
5966 anderson 1806
 
1807
 
1808
 
1809
                            if ($currentUser->timezone && $currentUser->timezone != $zoomMeeting->timezone) {
1810
 
4179 efrain 1811
                                $start =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->start_time, $zoomMeeting->timezone, $currentUser->timezone));
1812
                                $end =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->end_time, $zoomMeeting->timezone, $currentUser->timezone));
1813
                            } else {
1814
                                $start = str_replace(' ', 'T', $zoomMeeting->start_time);
1815
                                $end = str_replace(' ', 'T', $zoomMeeting->end_time);
1816
                            }
5966 anderson 1817
 
1818
 
1819
 
1820
 
1821
 
1822
 
4179 efrain 1823
                            $agenda = "<a href=\"{$zoomMeeting->join_url}\" target=\"_blank\">" .  $zoomMeeting->agenda . "<br>" .
1824
                                " LABEL_ZOOM_MEETING_START_DATE : " . $dtStart->format('Y-m-d') . "<br>" .
1825
                                " LABEL_ZOOM_MEETING_START_TIME : " . $dtStart->format('H:i a') . "<br>" .
1826
                                " LABEL_ZOOM_MEETING_TIMEZONE : " . $zoomMeeting->timezone . "<br>" .
1827
                                " LABEL_ZOOM_MEETING_TITLE :  " . $zoomMeeting->topic  . "<br>" .
1828
                                " LABEL_ZOOM_MEETING_URL : " . $zoomMeeting->join_url . "<br>" .
1829
                                " LABEL_ZOOM_MEETING_PASSWORD : " . $zoomMeeting->password . "<br>" .
1830
                                "</a>";
5966 anderson 1831
 
4179 efrain 1832
                            array_push($events, [
1833
                                'id'                => $zoomMeeting->id,
1834
                                'title'             => $zoomMeeting->topic,
1835
                                'agenda'            => $agenda,
1836
                                'start'             => $start,
1837
                                'end'               => $end,
1838
                                'url'               => $zoomMeeting->join_url,
1839
                                'backgroundColor'   => $backgroundColor,
1840
                                'textColor'         => $textColor,
4700 efrain 1841
                                'type'              => 'event'
4179 efrain 1842
                            ]);
1843
                        }
1844
                        break;
1845
                }
1846
            }
5966 anderson 1847
 
1848
 
1849
 
4179 efrain 1850
            return new JsonModel([
1851
                'success' => true,
1852
                'data' => $events
1853
            ]);
1854
        } else {
1855
            return new JsonModel([
1856
                'success' => false,
1857
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1858
            ]);
1859
        }
1860
    }
1 www 1861
}