Proyectos de Subversion LeadersLinked - Services

Rev

Rev 278 | Rev 282 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
7
use Laminas\Mvc\Controller\AbstractActionController;
8
use Laminas\View\Model\JsonModel;
9
use LeadersLinked\Mapper\CalendarEventMapper;
10
use LeadersLinked\Mapper\CompanyFollowerMapper;
11
use LeadersLinked\Mapper\JobDescriptionMapper;
12
use LeadersLinked\Mapper\PerformanceEvaluationFormMapper;
13
use LeadersLinked\Mapper\PerformanceEvaluationTestMapper;
14
use LeadersLinked\Mapper\QueryMapper;
15
use LeadersLinked\Mapper\RecruitmentSelectionCandidateMapper;
16
use LeadersLinked\Mapper\RecruitmentSelectionInterviewMapper;
17
use LeadersLinked\Mapper\RecruitmentSelectionVacancyMapper;
18
use LeadersLinked\Mapper\UserMapper;
19
use LeadersLinked\Mapper\ZoomMeetingMapper;
20
use LeadersLinked\Library\Functions;
21
use LeadersLinked\Mapper\UserNotificationSettingMapper;
22
 
23
use LeadersLinked\Model\CalendarEvent;
24
use LeadersLinked\Model\User;
25
use LeadersLinked\Mapper\ConnectionMapper;
26
use LeadersLinked\Mapper\ProfileVisitMapper;
27
use LeadersLinked\Mapper\GroupMemberMapper;
28
use LeadersLinked\Model\GroupMember;
29
use LeadersLinked\Mapper\GroupMapper;
30
use LeadersLinked\Model\Group;
31
use Laminas\Db\Sql\Expression;
32
use LeadersLinked\Mapper\CompanyUserMapper;
33
use LeadersLinked\Model\CompanyUser;
34
use LeadersLinked\Model\UserType;
269 efrain 35
use LeadersLinked\Mapper\MicrolearningCapsuleUserMapper;
1 efrain 36
use LeadersLinked\Model\Notification;
37
use LeadersLinked\Mapper\NotificationMapper;
38
use LeadersLinked\Mapper\EmailTemplateMapper;
39
use LeadersLinked\Model\EmailTemplate;
40
use LeadersLinked\Library\QueueEmail;
41
use LeadersLinked\Mapper\PostMapper;
42
use LeadersLinked\Mapper\CompanyMapper;
43
use LeadersLinked\Model\Company;
44
use LeadersLinked\Model\Connection;
45
use LeadersLinked\Mapper\UserProfileMapper;
46
use LeadersLinked\Model\Network;
47
use LeadersLinked\Mapper\LocationMapper;
48
use LeadersLinked\Mapper\CompanySizeMapper;
49
use LeadersLinked\Mapper\DegreeMapper;
50
use LeadersLinked\Mapper\LanguageMapper;
51
use LeadersLinked\Mapper\SkillMapper;
52
use LeadersLinked\Mapper\AptitudeMapper;
53
use LeadersLinked\Mapper\HobbyAndInterestMapper;
54
use LeadersLinked\Mapper\IndustryMapper;
55
use LeadersLinked\Mapper\SurveyTestMapper;
56
use LeadersLinked\Mapper\SurveyCampaignMapper;
117 efrain 57
use LeadersLinked\Mapper\GroupTypeMapper;
192 efrain 58
use LeadersLinked\Mapper\FeedMapper;
59
use LeadersLinked\Model\Feed;
60
use LeadersLinked\Model\AbuseReport;
61
use LeadersLinked\Form\AbuseReport\CreateForm;
62
use LeadersLinked\Model\Post;
63
use LeadersLinked\Mapper\CommentMapper;
64
use LeadersLinked\Model\Comment;
65
use LeadersLinked\Mapper\AbuseReportMapper;
66
use LeadersLinked\Mapper\UserBlockedMapper;
67
use LeadersLinked\Model\UserBlocked;
269 efrain 68
use LeadersLinked\Library\Storage;
1 efrain 69
 
70
class HelperController extends AbstractActionController
71
{
281 efrain 72
    const _USE_S3 = false;
73
 
1 efrain 74
    /**
75
     *
76
     * @var \Laminas\Db\Adapter\AdapterInterface
77
     */
78
    private $adapter;
79
 
80
    /**
81
     *
82
     * @var \LeadersLinked\Cache\CacheInterface
83
     */
84
    private $cache;
85
 
86
 
87
    /**
88
     *
89
     * @var \Laminas\Log\LoggerInterface
90
     */
91
    private $logger;
92
 
93
    /**
94
     *
95
     * @var array
96
     */
97
    private $config;
98
 
99
 
100
    /**
101
     *
102
     * @var \Laminas\Mvc\I18n\Translator
103
     */
104
    private $translator;
105
 
106
 
107
    /**
108
     *
109
     * @var array
110
     */
111
    private $navigation;
112
 
113
    /**
114
     *
115
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
116
     * @param \LeadersLinked\Cache\CacheInterface $cache
117
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
118
     * @param array $config
119
     * @param \Laminas\Mvc\I18n\Translator $translator
120
     * @param array $navigation
121
     */
122
    public function __construct($adapter, $cache, $logger, $config, $translator, $navigation)
123
    {
124
        $this->adapter      = $adapter;
125
        $this->cache        = $cache;
126
        $this->logger       = $logger;
127
        $this->config       = $config;
128
        $this->translator   = $translator;
129
        $this->navigation   = $navigation;
130
    }
131
 
132
 
133
    /**
134
     * Recuperamos las personas que pueda conocer
135
     * tiene que enviarse un petición GET a la siguiente url: /helpers/people-you-may-know
136
     * retorna un json en caso de ser  positivo
137
     * [
138
     *  'success' : true,
139
     *  'data' : [
140
     *      [
141
     *        'id'      => 'id del usuario encriptado',
142
     *        'name'    => 'nombre del usuario',
143
     *        'image'   => 'imagen del usuario',
144
     *        'profile' => 'url del profile',
145
     *     ]
146
     * ]
147
     * En caso de ser negativo
148
     * [
149
     *  'success' : false,
150
     *  'data' : mensaje de error
151
     * ]
152
     * @return \Laminas\View\Model\JsonModel
153
     */
154
    public function peopleYouMayKnowAction()
155
    {
156
        $request = $this->getRequest();
157
        if ($request->isGet()) {
158
            $currentUserPlugin = $this->plugin('currentUserPlugin');
159
            $currentUser = $currentUserPlugin->getUser();
160
 
161
            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
162
            $first_degree_connections_ids = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
163
            $first_degree_connections_ids = $first_degree_connections_ids ? $first_degree_connections_ids : [0];
164
 
165
            $second_degree_connections_ids = $connectionMapper->fetchAllSecondDegreeConnectionsForUserIdReturnIds($currentUser->id);
166
            $second_degree_connections_ids = $second_degree_connections_ids ? $second_degree_connections_ids : [0];
167
 
168
            /*Usuarios de la empresas donde trabajo o soy dueño */
169
            $company_user_ids = [];
170
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
171
 
172
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
173
            foreach ($records as $record) {
174
 
175
                if ($record->status != CompanyUser::STATUS_ACCEPTED) {
176
                    continue;
177
                }
178
 
179
                $otherUsers = $companyUserMapper->fetchAllByCompanyId($record->company_id);
180
                foreach ($otherUsers as $otherUser) {
181
                    if ($currentUser->id != $otherUser->user_id && $otherUser->creator == CompanyUser::CREATOR_NO && $otherUser->status == CompanyUser::STATUS_ACCEPTED) {
182
 
183
                        if (!in_array($otherUser->user_id, $company_user_ids)) {
184
                            array_push($company_user_ids, $otherUser->user_id);
185
                        }
186
                    }
187
                }
188
            }
189
            $company_user_ids =  $company_user_ids ? $company_user_ids : [0];
190
 
191
            /* Usuario de los grupos donde soy dueño o participo */
192
 
193
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
194
 
195
            $group_member_ids = [];
196
 
197
            $records = $groupMemberMapper->fetchAllByUserId($currentUser->id);
198
            foreach ($records as $record) {
199
                if ($record->status != GroupMember::STATUS_ACCEPTED) {
200
                    continue;
201
                }
202
 
203
                $otherUsers = $groupMemberMapper->fetchAllByGroupId($record->group_id);
204
                foreach ($otherUsers as $otherUser) {
205
                    if ($currentUser->id != $otherUser->user_id && $otherUser->status == GroupMember::STATUS_ACCEPTED) {
206
 
207
                        if (!in_array($otherUser->user_id, $group_member_ids)) {
208
                            array_push($group_member_ids, $otherUser->user_id);
209
                        }
210
                    }
211
                }
212
            }
213
 
214
            $group_member_ids = $group_member_ids ? $group_member_ids : [0];
215
 
216
 
217
 
218
            /* Usuarios con que comparto capsulas */
219
            $capsule_user_ids = [];
269 efrain 220
            $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
1 efrain 221
 
222
            $company_ids = [];
223
            $records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
224
            foreach ($records as $record) {
225
                if (!in_array($record->company_id, $company_ids)) {
226
                    array_push($company_ids, $record->company_id);
227
                }
228
            }
229
 
230
 
231
 
232
            foreach ($company_ids as $company_id) {
233
                $otherUsers = $capsuleUserMapper->fetchAllUserIdsForCapsulesActiveByCompanyId($company_id);
234
                foreach ($otherUsers as $user_id) {
235
                    if ($currentUser->id != $user_id) {
236
 
237
                        if (!in_array($user_id, $capsule_user_ids)) {
238
                            array_push($capsule_user_ids, $user_id);
239
                        }
240
                    }
241
                }
242
            }
243
 
244
            $capsule_user_ids = $capsule_user_ids ? $capsule_user_ids : [0];
245
 
246
 
247
            $other_users = array_unique(array_merge(
248
                $second_degree_connections_ids,
249
                $company_user_ids,
250
                $group_member_ids,
251
                $capsule_user_ids
252
            ));
253
 
254
 
255
 
256
 
257
 
258
 
259
 
260
 
261
            $items = [];
262
            $queryMapper = QueryMapper::getInstance($this->adapter);
263
            $select = $queryMapper->getSql()->select();
264
            $select->columns(['id', 'uuid',  'first_name', 'last_name', 'image']);
265
            $select->from(['u' => UserMapper::_TABLE]);
266
            $select->join(['up' => UserProfileMapper::_TABLE], 'up.user_id = u.id ', ['description']);
267
            $select->where->equalTo('network_id', $currentUser->network_id);
268
            $select->where->in('u.id', $other_users);
269
            $select->where->notIn('u.id', $first_degree_connections_ids);
270
            $select->where->notEqualTo('u.id', $currentUser->id);
271
            $select->where->equalTo('u.status', User::STATUS_ACTIVE);
272
            $select->where->in('u.usertype_id', [UserType::ADMIN, UserType::USER]);
273
            $select->order(['first_name', 'last_name']);
274
 
275
            //echo $select->getSqlString($this->adapter->platform); exit;
276
 
281 efrain 277
            if(self::_USE_S3) {
278
                $storage = Storage::getInstance($this->config);
279
            } else {
280
                $storage = null;
281
            }
269 efrain 282
 
1 efrain 283
            $records = $queryMapper->fetchAll($select);
284
            foreach ($records as $record) {
285
 
286
                $relation = [];
287
                if (in_array($record['id'], $second_degree_connections_ids)) {
288
                    array_push($relation, 'LABEL_RELATION_TYPE_SECOND_GRADE');
289
                }
290
                if (in_array($record['id'], $company_user_ids)) {
291
                    array_push($relation, 'LABEL_RELATION_TYPE_COMPANY_USER');
292
                }
293
                if (in_array($record['id'], $group_member_ids)) {
294
                    array_push($relation, 'LABEL_RELATION_TYPE_GROUP_MEMBER');
295
                }
296
                if (in_array($record['id'], $capsule_user_ids)) {
297
                    array_push($relation, 'LABEL_RELATION_TYPE_CAPSULE_USER');
298
                }
299
 
300
 
301
                $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $record['id']);
302
 
303
                $item = [
304
                    'id'    => $record['uuid'],
305
                    'name'  => trim($record['first_name'] . ' ' . $record['last_name']),
281 efrain 306
                    'image' => $storage
307
                        ? $storage->getUserImageForCodeAndFilename($record['uuid'], $record['image'])
308
                        : $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image'] ]),
1 efrain 309
                    'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
310
                    'relation' => $relation,
311
                    'link_cancel'   => '',
312
                    'link_request'  => '',
313
                    'user_profile' => $record['description'],
314
                ];
315
 
316
                if ($connection) {
317
                    switch ($connection->status) {
318
                        case Connection::STATUS_SENT:
319
                            $item['link_cancel'] = $this->url()->fromRoute('connection/delete', ['id' => $record['uuid']]);
320
                            break;
321
 
322
                        case Connection::STATUS_ACCEPTED:
323
                            $item['link_cancel'] = $this->url()->fromRoute('connection/cancel', ['id' => $record['uuid']]);
324
                            break;
325
 
326
                        default:
327
                            $item['link_request'] = $this->url()->fromRoute('connection/request', ['id' => $record['uuid']]);
328
                            break;
329
                    }
330
                } else {
331
                    $item['link_request'] = $this->url()->fromRoute('connection/request', ['id' => $record['uuid']]);
332
                }
333
 
334
 
335
                array_push($items, $item);
336
            }
337
 
338
            return new JsonModel([
339
                'success' => true,
340
                'data' => $items
341
            ]);
342
        } else {
343
            return new JsonModel([
344
                'success' => false,
345
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
346
            ]);
347
        }
348
    }
349
 
350
    /**
351
     * Recuperamos las personas que pueda conocer
352
     * tiene que enviarse un petición GET a la siguiente url: /helpers/people-viewed-profile/:user_profile_id
353
     * retorna un json en caso de ser  positivo
354
     * [
355
     *  'success' : true,
356
     *  'data' : [
357
     *      [
358
     *        'id'      => 'id del usuario encriptado',
359
     *        'name'    => 'nombre del usuario',
360
     *        'image'   => 'imagen del usuario',
361
     *        'profile' => 'url del profile',
362
     *     ]
363
     * ]
364
     * En caso de ser negativo
365
     * [
366
     *  'success' : false,
367
     *  'data' : mensaje de error
368
     * ]
369
     * @return \Laminas\View\Model\JsonModel
370
     */
371
    public function peopleViewedProfileAction()
372
    {
373
        $request = $this->getRequest();
374
        if ($request->isGet()) {
375
            $currentUserPlugin = $this->plugin('currentUserPlugin');
376
            $currentUser = $currentUserPlugin->getUser();
377
 
378
            $items = [];
379
            $user_profile_id = $this->params()->fromRoute('user_profile_id');
380
 
381
            $items = [];
382
 
383
            $mapper = QueryMapper::getInstance($this->adapter);
384
            $select = $mapper->getSql()->select(ProfileVisitMapper::_TABLE);
385
            $select->columns(['user_id' => new Expression('DISTINCT(visitor_id)')]);
386
            $select->where->equalTo('user_profile_id', $user_profile_id);
387
            $records = $mapper->fetchAll($select);
388
 
389
            if ($records) {
390
 
391
                $user_ids = [];
392
                foreach ($records as $record) {
393
                    array_push($user_ids, $record['user_id']);
394
                }
395
 
396
                $mapper = QueryMapper::getInstance($this->adapter);
397
                $select = $mapper->getSql()->select(UserMapper::_TABLE);
398
                $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
399
                $select->where->in('id', $user_ids);
400
                $select->where->equalTo('network_id', $currentUser->network_id);
401
                $select->where->equalTo('status', User::STATUS_ACTIVE);
402
                $select->order(['last_name ASC', 'first_name ASC']);
403
 
281 efrain 404
                if(self::_USE_S3) {
405
                    $storage = Storage::getInstance($this->config);
406
                } else {
407
                    $storage = null;
408
                }
269 efrain 409
 
1 efrain 410
                $records = $mapper->fetchAll($select);
411
                foreach ($records as $record) {
412
                    array_push($items, [
413
                        'id'        => $record['uuid'],
414
                        'name'      => trim($record['first_name'] . ' ' . $record['last_name']),
281 efrain 415
                        'image' => $storage
416
                            ? $storage->getUserImageForCodeAndFilename($record['uuid'], $record['image'])
417
                            : $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image'] ]),
1 efrain 418
                        'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
281 efrain 419
                        'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
1 efrain 420
                    ]);
421
                }
422
            }
423
 
424
 
425
            return new JsonModel([
426
                'success' => true,
427
                'data' => $items
428
            ]);
429
        } else {
430
            return new JsonModel([
431
                'success' => false,
432
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
433
            ]);
434
        }
435
    }
436
 
437
 
438
    /**
439
     * Recuperamos los seguidores de la empresa
440
     * tiene que enviarse un petición GET a la siguiente url: /helpers/company-follower/:company_id
441
     * retorna un json en caso de ser  positivo
442
     * [
443
     *  'success' : true,
444
     *  'data' : [
445
     *      [
446
     *        'id'      => 'id del usuario encriptado',
447
     *        'name'    => 'nombre del usuario',
448
     *        'image'   => 'imagen del usuario',
449
     *        'profile' => 'url del profile',
450
     *     ]
451
     * ]
452
     * En caso de ser negativo
453
     * [
454
     *  'success' : false,
455
     *  'data' : mensaje de error
456
     * ]
457
     * @return \Laminas\View\Model\JsonModel
458
     */
459
    public function companyFollowerAction()
460
    {
461
 
462
 
463
        $request = $this->getRequest();
464
        if ($request->isGet()) {
465
            $currentUserPlugin = $this->plugin('currentUserPlugin');
466
            $currentUser = $currentUserPlugin->getUser();
467
 
468
            $company_uuid  = $this->params()->fromRoute('company_id');
469
 
470
            $companyMapper = CompanyMapper::getInstance($this->adapter);
471
            $company = $companyMapper->fetchOneByUuidAndNetworkId($company_uuid, $currentUser->network_id);
472
 
473
            $items = [];
474
            if ($company && $company->status == Company::STATUS_ACTIVE) {
475
 
476
                $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
477
                $records = $companyFollowerMapper->fetchAllByCompanyId($company->id);
478
 
479
                $ids = [];
480
                foreach ($records as $record) {
481
                    if (!in_array($record->follower_id, $ids)) {
482
                        array_push($ids, $record->follower_id);
483
                    }
484
                }
485
 
486
                if ($ids) {
487
 
488
                    $mapper = QueryMapper::getInstance($this->adapter);
489
                    $select = $mapper->getSql()->select(UserMapper::_TABLE);
490
                    $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
491
                    $select->where->equalTo('network_id', $currentUser->network_id);
492
                    $select->where->in('id', $ids);
493
                    $select->where->equalTo('status', User::STATUS_ACTIVE);
494
                    $select->order(['last_name', 'first_name']);
495
 
496
                    //echo $select->getSqlString($this->adapter->platform); exit;
497
 
498
 
281 efrain 499
                    if(self::_USE_S3) {
500
                        $storage = Storage::getInstance($this->config);
501
                    } else {
502
                        $storage = null;
503
                    }
1 efrain 504
 
505
                    $records = $mapper->fetchAll($select);
506
                    foreach ($records as $record) {
507
 
508
 
509
                        array_push($items, [
510
                            'id'        => $record['uuid'],
511
                            'name'      => trim($record['first_name'] . ' ' . $record['last_name']),
281 efrain 512
                            'image' => $storage
513
                                ? $storage->getUserImageForCodeAndFilename($record['uuid'], $record['image'])
514
                                : $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image'] ]),
1 efrain 515
                            'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
516
                        ]);
517
                    }
518
                }
519
            }
520
 
521
            return new JsonModel([
522
                'success' => true,
523
                'data' => $items
524
            ]);
525
        } else {
526
            return new JsonModel([
527
                'success' => false,
528
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
529
            ]);
530
        }
531
    }
532
 
533
    public function companySuggestionAction()
534
    {
535
        $request = $this->getRequest();
536
        if ($request->isGet()) {
537
            $currentUserPlugin = $this->plugin('currentUserPlugin');
538
            $currentUser = $currentUserPlugin->getUser();
539
 
540
            $company_uuid = $this->params()->fromRoute('company_id');
541
 
542
            $companyMapper = CompanyMapper::getInstance($this->adapter);
543
            $company = $companyMapper->fetchOneByUuidAndNetworkId($company_uuid, $currentUser->network_id);
544
 
545
            $items = [];
546
            if ($company && $company->status == Company::STATUS_ACTIVE) {
547
 
548
 
549
                $mapper = QueryMapper::getInstance($this->adapter);
550
                $select = $mapper->getSql()->select(CompanyMapper::_TABLE);
551
                $select->columns(['id', 'uuid', 'name', 'image']);
552
                $select->where->equalTo('network_id', $currentUser->network_id);
553
                $select->where->notEqualTo('id', $company->id);
554
                $select->where->equalTo('status', Company::STATUS_ACTIVE);
555
                $select->where->equalTo('industry_id', $company->industry_id);
556
                //  $select->where->equalTo('company_size_id', $company->company_size_id);
557
                $select->order(['name']);
558
 
559
 
560
                //echo $select->getSqlString($this->adapter->platform); exit;
561
 
281 efrain 562
                if(self::_USE_S3) {
563
                    $storage = Storage::getInstance($this->config);
564
                } else {
565
                    $storage = null;
566
                }
269 efrain 567
 
1 efrain 568
                $records = $mapper->fetchAll($select);
569
                foreach ($records as $record) {
570
                    array_push($items, [
571
                        'id'        => $record['uuid'],
572
                        'name'      => trim($record['name']),
281 efrain 573
                        'image'     => $storage
574
                            ? $storage->getCompanyImageForCodeAndFilename($record['uuid'], $record['image'])
575
                            : $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'company', 'filename' => $record['image'] ]),
1 efrain 576
                        'profile'   => $this->url()->fromRoute('company/view', ['id' => $record['uuid']]),
577
                    ]);
578
                }
579
            }
580
 
581
            return new JsonModel([
582
                'success' => true,
583
                'data' => $items
584
            ]);
585
        } else {
586
            return new JsonModel([
587
                'success' => false,
588
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
589
            ]);
590
        }
591
    }
592
 
593
    /**
594
     * Recuperamos los miembros del grupo
595
     * tiene que enviarse un petición GET a la siguiente url: /helpers/group-members/:group_id
596
     * retorna un json en caso de ser  positivo
597
     * [
598
     *  'success' : true,
599
     *  'data' : [
600
     *      [
601
     *        'id'      => 'id del usuario encriptado',
602
     *        'name'    => 'nombre del usuario',
603
     *        'image'   => 'imagen del usuario',
604
     *        'profile' => 'url del profile',
605
     *     ]
606
     * ]
607
     * En caso de ser negativo
608
     * [
609
     *  'success' : false,
610
     *  'data' : mensaje de error
611
     * ]
612
     * @return \Laminas\View\Model\JsonModel
613
     */
614
    public function groupMembersAction()
615
    {
616
        $currentUserPlugin = $this->plugin('currentUserPlugin');
617
        $currentUser = $currentUserPlugin->getUser();
618
 
619
        $request = $this->getRequest();
620
        if ($request->isGet()) {
621
 
622
            $group_uuid = $this->params()->fromRoute('group_id');
623
 
624
            $groupMapper = GroupMapper::getInstance($this->adapter);
625
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
626
 
627
            $items = [];
628
            if ($group && $group->status == Group::STATUS_ACTIVE) {
629
 
630
                $mapper = QueryMapper::getInstance($this->adapter);
631
                $select = $mapper->getSql()->select();
632
                $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
633
                $select->from(['u' => UserMapper::_TABLE]);
634
                $select->join(['gm' => GroupMemberMapper::_TABLE], 'gm.user_id = u.id ', ['user_id', 'status']);
635
                $select->join(['g' => GroupMapper::_TABLE], 'gm.group_id = g.id', ['group_uuid' => 'uuid']);
636
                $select->where->equalTo('u.network_id',  $currentUser->network_id);
637
                $select->where->equalTo('g.network_id', $currentUser->network_id);
638
                $select->where->equalTo('g.uuid', $group_uuid);
639
 
640
                if ($group->user_id == $currentUser->id) {
641
                    $select->where->in('gm.status', [
642
                        GroupMember::STATUS_ACCEPTED,
643
                        GroupMember::STATUS_ADDED_BY_ADMIN,
644
                        GroupMember::STATUS_AUTO_JOIN,
645
                        GroupMember::STATUS_JOINING_REQUESTED,
646
                    ]);
647
                } else {
648
                    $select->where->in('gm.status', [GroupMember::STATUS_ACCEPTED, GroupMember::STATUS_AUTO_JOIN]);
649
                }
650
 
651
 
652
                $select->where->equalTo('u.status', User::STATUS_ACTIVE);
653
                $select->order(['last_name', 'first_name']);
654
 
655
                //echo $select->getSqlString($this->adapter->platform);
656
 
657
 
281 efrain 658
                if(self::_USE_S3) {
659
                    $storage = Storage::getInstance($this->config);
660
                } else {
661
                    $storage = null;
662
                }
1 efrain 663
 
664
 
665
                $records = $mapper->fetchAll($select);
666
                foreach ($records as $record) {
667
 
668
                    $actions = [];
669
                    if ($group->user_id == $currentUser->id) {
670
                        if ($record['id'] != $currentUser->id) {
671
 
672
 
673
 
674
                            switch ($record['status']) {
675
                                case GroupMember::STATUS_JOINING_REQUESTED:
676
                                    $actions['link_approve'] = $this->url()->fromRoute('helpers/group-members/approve', ['group_id' => $group->uuid, 'user_id' => $record['uuid']]);
677
                                    $actions['link_reject'] = $this->url()->fromRoute('helpers/group-members/reject', ['group_id' => $group->uuid, 'user_id' => $record['uuid']]);
678
                                    break;
679
 
680
                                case GroupMember::STATUS_ACCEPTED:
681
                                case GroupMember::STATUS_AUTO_JOIN:
682
                                case GroupMember::STATUS_ADDED_BY_ADMIN:
683
                                    $actions['link_cancel'] = $this->url()->fromRoute('helpers/group-members/cancel', ['group_id' => $group->uuid, 'user_id' => $record['uuid']]);
684
                                    break;
685
                            }
686
                        }
687
                    }
688
 
689
                    array_push($items, [
690
                        'id'        => $record['uuid'],
691
                        'name'      => trim($record['first_name'] . ' ' . $record['last_name']),
281 efrain 692
 
693
                        'image'     => $storage
694
                        ? $storage->getGroupImageForCodeAndFilename($record['uuid'], $record['image'])
695
                        : $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'group', 'filename' => $record['image'] ]),
696
 
1 efrain 697
                        'profile'   => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
698
                        'actions'   => $actions,
699
 
700
                    ]);
701
                }
702
            }
703
 
704
            return new JsonModel([
705
                'success' => true,
706
                'data' => [
707
                    'items' => $items,
708
                    'link_invite' => $group->user_id == $currentUser->id ? $this->url()->fromRoute('helpers/group-members/invite', ['group_id' => $group->uuid])  : '',
709
                ]
710
            ]);
711
        } else {
712
            return new JsonModel([
713
                'success' => false,
714
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
715
            ]);
716
        }
717
    }
718
 
719
    public function groupMemberInviteAction()
720
    {
721
        $currentUserPlugin = $this->plugin('currentUserPlugin');
722
        $currentUser = $currentUserPlugin->getUser();
723
 
724
        $group_uuid = $this->params()->fromRoute('group_id');
725
 
726
        $groupMapper = GroupMapper::getInstance($this->adapter);
727
        $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
728
 
729
        if (!$group) {
730
            return new JsonModel([
731
                'success' => false,
732
                'data' => 'ERROR_GROUP_NOT_FOUND'
733
            ]);
734
        }
735
 
736
        if ($group->status != Group::STATUS_ACTIVE) {
737
            return new JsonModel([
738
                'success' => false,
739
                'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
740
            ]);
741
        }
742
 
743
        if ($currentUser->id != $group->user_id) {
744
            return new JsonModel([
745
                'success' => false,
746
                'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
747
            ]);
748
        }
749
 
750
 
751
        $request = $this->getRequest();
752
        if ($request->isGet()) {
753
            $search = filter_var($this->params()->fromQuery('search', ''));
754
            if (strlen($search) >= 3) {
755
 
756
                $userMapper = UserMapper::getInstance($this->adapter);
757
                $records  = $userMapper->fetchAllSuggestForInvitationByGroupIdAndNetworkIdAndSearch($group->id, $currentUser->network_id, $search);
758
 
759
                $users = [];
760
                foreach ($records as $record) {
761
                    array_push($users, [
762
                        'value' => $record->uuid,
763
                        'text' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')'
764
 
765
                    ]);
766
                }
767
 
768
                return new JsonModel([
769
                    'success' => true,
770
                    'data' => $users
771
                ]);
772
            } else {
773
                return new JsonModel([
774
                    'success' => true,
775
                    'data' => []
776
                ]);
777
            }
778
        } else if ($request->isPost()) {
779
            $uuid = $this->params()->fromPost('id');
780
            if (!$uuid) {
781
                return new JsonModel([
782
                    'success'   => false,
783
                    'data'      => 'ERROR_INVALID_PARAMETER'
784
                ]);
785
            }
786
 
787
            $userMapper = UserMapper::getInstance($this->adapter);
788
            $user = $userMapper->fetchOneByUuidAndNetworkId($uuid, $currentUser->network_id);
789
 
790
            if (!$user) {
791
                return new JsonModel([
792
                    'success'   => false,
793
                    'data'      => 'ERROR_USER_NOT_FOUND'
794
                ]);
795
            }
796
 
797
            if ($user->status != User::STATUS_ACTIVE) {
798
                return new JsonModel([
799
                    'success'   => false,
800
                    'data'      => 'ERROR_USER_IS_INACTIVE'
801
                ]);
802
            }
803
 
804
            if ($group->user_id == $user->id) {
805
                return new JsonModel([
806
                    'success'   => false,
807
                    'data'      => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
808
                ]);
809
            }
810
 
811
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
812
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
813
 
814
 
815
 
816
            if ($groupMember) {
817
                $result = false;
818
 
819
                switch ($groupMember->status) {
820
                    case GroupMember::STATUS_ACCEPTED:
821
                    case GroupMember::STATUS_AUTO_JOIN:
822
 
823
                        return new JsonModel([
824
                            'success'   => false,
825
                            'data'      => 'ERROR_GROUP_YOU_ARE_MEMBER',
826
                        ]);
827
                        break;
828
 
829
 
830
                    case $groupMember->status == GroupMember::STATUS_REJECTED:
831
                    case $groupMember->status == GroupMember::STATUS_CANCELLED:
832
 
833
                        $groupMember->status = GroupMember::STATUS_ADDED_BY_ADMIN;
834
                        $groupMember->joining_request_on = date('H-m-d H:i:s');
835
 
836
                        $result = $groupMemberMapper->update($groupMember);
837
                        break;
838
 
839
                    case GroupMember::STATUS_ADDED_BY_ADMIN:
840
                    case  GroupMember::STATUS_JOINING_REQUESTED:
841
                        return new JsonModel([
842
                            'success'   => false,
843
                            'data'      => 'ERROR_GROUP_THERE_IS_A_PENDING_REQUEST'
844
                        ]);
845
                        break;
846
 
847
                    default:
848
                        return new JsonModel([
849
                            'success'   => false,
850
                            'data'      => 'ERROR_UNKNOWN_OPERATION'
851
                        ]);
852
                        break;
853
                }
854
            } else {
855
 
856
 
857
 
858
                $groupMember = new GroupMember();
859
                $groupMember->user_id = $user->id;
860
                $groupMember->group_id = $group->id;
861
                $groupMember->status = GroupMember::STATUS_ADDED_BY_ADMIN;
862
                $groupMember->joining_request_on = date('H-m-d H:i:s');
863
 
864
                $result = $groupMemberMapper->insert($groupMember);
865
            }
866
 
867
            if ($result) {
868
 
869
                $notification = new Notification();
870
                $notification->type     = Notification::TYPE_RECEIVE_INVITATION_GROUP;
871
                $notification->read     = Notification::NO;
872
                $notification->user_id  = $user->id;
873
                $notification->group_id = $group->id;
874
                $notification->message  = 'LABEL_NOTIFICATION_RECEIVE_INVITATION_GROUP';
875
                $notification->url      = $this->url()->fromRoute('group/view', ['id' => $group->uuid]);
876
 
877
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
878
                $notificationMapper->insert($notification);
879
 
880
                $userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
881
                $userNotification = $userNotificationMapper->fetchOne($user->id);
882
 
883
                if ($userNotification && $userNotification->receive_invitation_group) {
884
                    $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
885
                    $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_RECEIVE_INVITATION_GROUP, $currentUser->network_id);
886
 
887
                    if ($emailTemplate) {
888
                        $arrayCont = [
889
                            'firstname'             => $currentUser->first_name,
890
                            'lastname'              => $currentUser->last_name,
891
                            'other_user_firstname'  => $user->first_name,
892
                            'other_user_lastname'   => $user->last_name,
893
                            'company_name'          => '',
894
                            'group_name'            => $group->name,
895
                            'content'               => '',
896
                            'code'                  => '',
897
                            'link'                  => $this->url()->fromRoute('group/view', ['id' => $group->uuid], ['force_canonical' => true])
898
                        ];
899
 
900
                        $email = new QueueEmail($this->adapter);
901
                        $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
902
                    }
903
                }
904
 
905
                return new JsonModel([
906
                    'success'   => true,
907
                    'data'      => 'LABEL_GROUP_REQUEST_SUCCESS'
908
                ]);
909
            } else {
910
 
911
                return new JsonModel([
912
                    'success'   => false,
913
                    'data'      => 'ERROR_GROUP_REQUEST_COULD_NOT_BE_SENT'
914
                ]);
915
            }
916
        } else {
917
            return new JsonModel([
918
                'success' => false,
919
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
920
            ]);
921
        }
922
    }
923
 
924
    public function  groupMemberCancelAction()
925
    {
926
        $currentUserPlugin = $this->plugin('currentUserPlugin');
927
        $currentUser = $currentUserPlugin->getUser();
928
 
929
        $request = $this->getRequest();
930
        if ($request->isPost()) {
931
            $group_uuid = $this->params()->fromRoute('group_id');
932
            $user_uuid  = $this->params()->fromRoute('user_id');
933
 
934
            $groupMapper = GroupMapper::getInstance($this->adapter);
935
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
936
 
937
            if (!$group) {
938
                return new JsonModel([
939
                    'success' => false,
940
                    'data' => 'ERROR_GROUP_NOT_FOUND'
941
                ]);
942
            }
943
 
944
            if ($group->status != Group::STATUS_ACTIVE) {
945
                return new JsonModel([
946
                    'success' => false,
947
                    'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
948
                ]);
949
            }
950
 
951
            if ($currentUser->id != $group->user_id) {
952
                return new JsonModel([
953
                    'success' => false,
954
                    'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
955
                ]);
956
            }
957
 
958
            $userMapper = UserMapper::getInstance($this->adapter);
959
            $user = $userMapper->fetchOneByUuidAndNetworkId($user_uuid, $currentUser->network_id);
960
 
961
            if (!$user) {
962
                return new JsonModel([
963
                    'success' => false,
964
                    'data' => 'ERROR_USER_NOT_FOUND'
965
                ]);
966
            }
967
 
968
            if ($user->id == $currentUser->id) {
969
                return new JsonModel([
970
                    'success' => false,
971
                    'data' => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
972
                ]);
973
            }
974
 
975
 
976
 
977
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
978
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
979
            if ($groupMember) {
980
 
981
                if (
982
                    $groupMember->status == GroupMember::STATUS_ACCEPTED ||
983
                    $groupMember->status == GroupMember::STATUS_ADDED_BY_ADMIN ||
984
                    $groupMember->status == GroupMember::STATUS_AUTO_JOIN
985
                ) {
986
 
987
                    $groupMember->status = GroupMember::STATUS_CANCELLED;
988
                    if ($groupMemberMapper->update($groupMember)) {
989
 
990
                        return new JsonModel([
991
                            'success' => true,
992
                            'data' =>  'LABEL_GROUP_MEMBER_CANCELLED_SUCCESS'
993
                        ]);
994
                    } else {
995
                        return new JsonModel([
996
                            'success' => true,
997
                            'data' =>    'LABEL_GROUP_MEMBER_CANCELLED_FAILED'
998
                        ]);
999
                    }
1000
                }
1001
            }
1002
 
1003
 
1004
            return new JsonModel([
1005
                'success' => false,
1006
                'data' => 'ERROR_GROUP_REQUEST_OR_MEMBER_NOT_FOUND_TO_CANCEL'
1007
            ]);
1008
        } else {
1009
 
1010
            return new JsonModel([
1011
                'success' => false,
1012
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1013
            ]);
1014
        }
1015
    }
1016
 
1017
    public function  groupMemberRejectAction()
1018
    {
1019
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1020
        $currentUser = $currentUserPlugin->getUser();
1021
 
1022
        $request = $this->getRequest();
1023
        if ($request->isPost()) {
1024
            $group_uuid = $this->params()->fromRoute('group_id');
1025
            $user_uuid  = $this->params()->fromRoute('user_id');
1026
 
1027
            $groupMapper = GroupMapper::getInstance($this->adapter);
1028
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
1029
 
1030
            if (!$group) {
1031
                return new JsonModel([
1032
                    'success' => false,
1033
                    'data' => 'ERROR_GROUP_NOT_FOUND'
1034
                ]);
1035
            }
1036
 
1037
            if ($group->status != Group::STATUS_ACTIVE) {
1038
                return new JsonModel([
1039
                    'success' => false,
1040
                    'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
1041
                ]);
1042
            }
1043
 
1044
            if ($currentUser->id != $group->user_id) {
1045
                return new JsonModel([
1046
                    'success' => false,
1047
                    'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1048
                ]);
1049
            }
1050
 
1051
            $userMapper = UserMapper::getInstance($this->adapter);
1052
            $user = $userMapper->fetchOneByUuidAndNetworkId($user_uuid, $currentUser->network_id);
1053
 
1054
            if (!$user) {
1055
                return new JsonModel([
1056
                    'success' => false,
1057
                    'data' => 'ERROR_USER_NOT_FOUND'
1058
                ]);
1059
            }
1060
 
1061
            if ($user->id == $currentUser->id) {
1062
                return new JsonModel([
1063
                    'success' => false,
1064
                    'data' => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1065
                ]);
1066
            }
1067
 
1068
 
1069
 
1070
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1071
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
1072
            if ($groupMember) {
1073
 
1074
                if ($groupMember->status == GroupMember::STATUS_JOINING_REQUESTED) {
1075
 
1076
                    $groupMember->status = GroupMember::STATUS_REJECTED;
1077
                    if ($groupMemberMapper->update($groupMember)) {
1078
 
1079
                        return new JsonModel([
1080
                            'success' => true,
1081
                            'data' =>  'LABEL_GROUP_MEMBER_REJECTED_SUCCESS'
1082
                        ]);
1083
                    } else {
1084
                        return new JsonModel([
1085
                            'success' => true,
1086
                            'data' =>    'LABEL_GROUP_MEMBER_REJECTED_FAILED'
1087
                        ]);
1088
                    }
1089
                }
1090
            }
1091
 
1092
 
1093
            return new JsonModel([
1094
                'success' => false,
1095
                'data' => 'ERROR_GROUP_THERE_IS_NO_PENDING_REQUEST_TO_REJECT'
1096
            ]);
1097
        } else {
1098
 
1099
            return new JsonModel([
1100
                'success' => false,
1101
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1102
            ]);
1103
        }
1104
    }
1105
 
1106
    public function  groupMemberApproveAction()
1107
    {
1108
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1109
        $currentUser = $currentUserPlugin->getUser();
1110
 
1111
        $request = $this->getRequest();
1112
        if ($request->isPost()) {
1113
            $group_uuid = $this->params()->fromRoute('group_id');
1114
            $user_uuid  = $this->params()->fromRoute('user_id');
1115
 
1116
            $groupMapper = GroupMapper::getInstance($this->adapter);
1117
            $group = $groupMapper->fetchOneByUuidAndNetworkId($group_uuid, $currentUser->network_id);
1118
 
1119
            if (!$group) {
1120
                return new JsonModel([
1121
                    'success' => false,
1122
                    'data' => 'ERROR_GROUP_NOT_FOUND'
1123
                ]);
1124
            }
1125
 
1126
            if ($group->status != Group::STATUS_ACTIVE) {
1127
                return new JsonModel([
1128
                    'success' => false,
1129
                    'data' => 'ERROR_GROUP_IS_NOT_ACTIVE'
1130
                ]);
1131
            }
1132
 
1133
            if ($currentUser->id != $group->user_id) {
1134
                return new JsonModel([
1135
                    'success' => false,
1136
                    'data' => 'ERROR_GROUP_IS_NOT_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1137
                ]);
1138
            }
1139
 
1140
            $userMapper = UserMapper::getInstance($this->adapter);
1141
            $user = $userMapper->fetchOneByUuidAndNetworkId($user_uuid, $currentUser->network_id);
1142
 
1143
            if (!$user) {
1144
                return new JsonModel([
1145
                    'success' => false,
1146
                    'data' => 'ERROR_USER_NOT_FOUND'
1147
                ]);
1148
            }
1149
 
1150
            if ($user->id == $currentUser->id) {
1151
                return new JsonModel([
1152
                    'success' => false,
1153
                    'data' => 'ERROR_GROUP_YOU_ARE_THE_OWNER_OF_THIS_GROUP'
1154
                ]);
1155
            }
1156
 
1157
 
1158
 
1159
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1160
            $groupMember = $groupMemberMapper->fetchOneByGroupIdAndUserId($group->id, $user->id);
1161
            if ($groupMember) {
1162
 
1163
                if ($groupMember->status == GroupMember::STATUS_JOINING_REQUESTED) {
1164
 
1165
                    $groupMember->status = GroupMember::STATUS_ACCEPTED;
1166
                    if ($groupMemberMapper->update($groupMember)) {
1167
 
1168
 
1169
                        $notification = new Notification();
1170
                        $notification->type     = Notification::TYPE_ACCEPT_MY_REQUEST_JOIN_GROUP;
1171
                        $notification->read     = Notification::NO;
1172
                        $notification->user_id  = $user->id;
1173
                        $notification->group_id = $group->id;
1174
                        $notification->message  = 'LABEL_NOTIFICATION_ACCEPT_MY_REQUEST_JOIN_GROUP';
1175
                        $notification->url      = $this->url()->fromRoute('group/view', ['id' => $group->uuid]);
1176
 
1177
                        $notificationMapper = NotificationMapper::getInstance($this->adapter);
1178
                        $notificationMapper->insert($notification);
1179
 
1180
                        $userNotificationMapper = UserNotificationSettingMapper::getInstance($this->adapter);
1181
                        $userNotification = $userNotificationMapper->fetchOne($user->id);
1182
 
1183
                        if ($userNotification && $userNotification->receive_invitation_group) {
1184
                            $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
1185
                            $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_ACCEPT_MY_REQUEST_JOIN_GROUP, $currentUser->network_id);
1186
 
1187
                            if ($emailTemplate) {
1188
                                $arrayCont = [
1189
                                    'firstname'             => $currentUser->first_name,
1190
                                    'lastname'              => $currentUser->last_name,
1191
                                    'other_user_firstname'  => $user->first_name,
1192
                                    'other_user_lastname'   => $user->last_name,
1193
                                    'company_name'          => '',
1194
                                    'group_name'            => $group->name,
1195
                                    'content'               => '',
1196
                                    'code'                  => '',
1197
                                    'link'                  => $this->url()->fromRoute('group/view', ['id' => $group->uuid], ['force_canonical' => true])
1198
                                ];
1199
 
1200
                                $email = new QueueEmail($this->adapter);
1201
                                $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
1202
                            }
1203
                        }
1204
 
1205
                        return new JsonModel([
1206
                            'success' => true,
1207
                            'data' =>  'LABEL_GROUP_MEMBER_APPROVED_SUCCESS'
1208
                        ]);
1209
                    } else {
1210
                        return new JsonModel([
1211
                            'success' => true,
1212
                            'data' =>    'LABEL_GROUP_MEMBER_APPROVED_FAILED'
1213
                        ]);
1214
                    }
1215
                }
1216
            }
1217
 
1218
 
1219
            return new JsonModel([
1220
                'success' => false,
1221
                'data' => 'ERROR_GROUP_THERE_IS_NO_PENDING_REQUEST_TO_APPROVED'
1222
            ]);
1223
        } else {
1224
 
1225
            return new JsonModel([
1226
                'success' => false,
1227
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1228
            ]);
1229
        }
1230
    }
1231
 
1232
 
1233
    /**
1234
     * Recuperamos los grupos sugeridos
1235
     * tiene que enviarse un petición GET a la siguiente url: /helpers/groups-suggestion/:group_id
1236
     * retorna un json en caso de ser  positivo
1237
     * [
1238
     *  'success' : true,
1239
     *  'data' : [
1240
     *      [
1241
     *        'id'      => 'id del grupo encriptado',
1242
     *        'name'    => 'nombre del grupo',
1243
     *        'image'   => 'imagen del grupo',
1244
     *        'profile' => 'url del profile',
1245
     *     ]
1246
     * ]
1247
     * En caso de ser negativo
1248
     * [
1249
     *  'success' : false,
1250
     *  'data' : mensaje de error
1251
     * ]
1252
     * @return \Laminas\View\Model\JsonModel
1253
     */
1254
    public function groupsSuggestionAction()
1255
    {
1256
 
1257
        $request = $this->getRequest();
1258
        if ($request->isGet()) {
1259
 
1260
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1261
            $currentUser = $currentUserPlugin->getUser();
1262
 
1263
            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1264
            $first_degree_connections_ids = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
1265
            $first_degree_connections_ids = $first_degree_connections_ids ? $first_degree_connections_ids : [0];
1266
 
1267
            $second_degree_connections_ids = $connectionMapper->fetchAllSecondDegreeConnectionsForUserIdReturnIds($currentUser->id);
1268
            $second_degree_connections_ids = $second_degree_connections_ids ? $second_degree_connections_ids : [0];
1269
 
1270
            /*Usuarios de la empresas donde trabajo o soy dueño */
1271
            $company_user_ids = [];
1272
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1273
 
1274
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
1275
            foreach ($records as $record) {
1276
 
1277
                if ($record->status != CompanyUser::STATUS_ACCEPTED) {
1278
                    continue;
1279
                }
1280
 
1281
                $otherUsers = $companyUserMapper->fetchAllByCompanyId($record->company_id);
1282
                foreach ($otherUsers as $otherUser) {
1283
                    if ($currentUser->id != $otherUser->user_id && $otherUser->creator == CompanyUser::CREATOR_NO && $otherUser->status == CompanyUser::STATUS_ACCEPTED) {
1284
 
1285
                        if (!in_array($otherUser->user_id, $company_user_ids)) {
1286
                            array_push($company_user_ids, $otherUser->user_id);
1287
                        }
1288
                    }
1289
                }
1290
            }
1291
            $company_user_ids =  $company_user_ids ? $company_user_ids : [0];
1292
 
1293
            /* Usuario de los grupos donde soy dueño o participo */
1294
 
1295
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1296
 
1297
            $group_member_ids = [];
1298
 
1299
            $records = $groupMemberMapper->fetchAllByUserId($currentUser->id);
1300
            foreach ($records as $record) {
1301
                if ($record->status != GroupMember::STATUS_ACCEPTED) {
1302
                    continue;
1303
                }
1304
 
1305
                $otherUsers = $groupMemberMapper->fetchAllByGroupId($record->group_id);
1306
                foreach ($otherUsers as $otherUser) {
1307
                    if ($currentUser->id != $otherUser->user_id && $otherUser->status == GroupMember::STATUS_ACCEPTED) {
1308
 
1309
                        if (!in_array($otherUser->user_id, $group_member_ids)) {
1310
                            array_push($group_member_ids, $otherUser->user_id);
1311
                        }
1312
                    }
1313
                }
1314
            }
1315
 
1316
            $group_member_ids = $group_member_ids ? $group_member_ids : [0];
1317
 
1318
            /* Usuarios con que comparto capsulas */
1319
            $capsule_user_ids = [];
269 efrain 1320
            $capsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
1 efrain 1321
 
1322
            $company_ids = [];
1323
            $records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
1324
            foreach ($records as $record) {
1325
                if (!in_array($record->company_id, $company_ids)) {
1326
                    array_push($company_ids, $record->company_id);
1327
                }
1328
            }
1329
 
1330
            foreach ($company_ids as $company_id) {
1331
                $otherUsers = $capsuleUserMapper->fetchAllUserIdsForCapsulesActiveByCompanyId($company_id);
1332
                foreach ($otherUsers as $user_id) {
1333
                    if ($currentUser->id != $user_id) {
1334
 
1335
                        if (!in_array($user_id, $capsule_user_ids)) {
1336
                            array_push($capsule_user_ids, $user_id);
1337
                        }
1338
                    }
1339
                }
1340
            }
1341
 
1342
            $capsule_user_ids = $capsule_user_ids ? $capsule_user_ids : [0];
1343
 
1344
 
1345
            $other_users = array_unique(array_merge(
1346
 
1347
                $second_degree_connections_ids,
1348
                $company_user_ids,
1349
                $group_member_ids,
1350
                $capsule_user_ids
1351
            ));
1352
 
1353
            $queryMapper = QueryMapper::getInstance($this->adapter);
1354
 
1355
 
1356
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
1357
            $group_ids = $groupMemberMapper->fetchAllGroupIdsByUserIds($other_users);
1358
            $group_ids = $group_ids ? $group_ids : [0];
1359
 
1360
 
1361
 
1362
 
1363
            $select = $queryMapper->getSql()->select();
1364
            $select->columns(['id', 'uuid', 'name', 'image', 'status', 'privacy', 'priority' => new Expression('0')]);
1365
            $select->from(['g' => GroupMapper::_TABLE]);
1366
            $select->where->equalTo('network_id', $currentUser->network_id);
1367
            $select->where->equalTo('privacy', Group::PRIVACY_IS_PUBLIC);
1368
            $select->where->equalTo('status', Group::STATUS_ACTIVE);
1369
            $select->where->in('g.id', $group_ids);
1370
            $select->where->notEqualTo('g.user_id', $currentUser->id);
1371
            $select->order('name ASC');
1372
 
1373
 
1374
 
1375
            //echo $select->getSqlString($this->adapter->platform); exit;
1376
 
1377
            $records = $queryMapper->fetchAll($select);
1378
            usort($records, function ($a, $b) {
1379
                if ($a['priority'] == $b['priority']) {
1380
                    return 0;
1381
                } else {
1382
                    return $a['priority'] < $b['priority'] ? 1 : -1;
1383
                }
1384
            });
1385
 
1386
 
1387
            $items = [];
269 efrain 1388
 
281 efrain 1389
            if(self::_USE_S3) {
1390
                $storage = Storage::getInstance($this->config);
1391
            } else {
1392
                $storage = null;
1393
            }
1 efrain 1394
 
1395
            foreach ($records as $record) {
1396
 
1397
                array_push($items, [
1398
                    'id'        => $record['uuid'],
1399
                    'name'      => trim($record['name']),
281 efrain 1400
                    'image'     => $storage
1401
                    ? $storage->getGroupImageForCodeAndFilename($record['uuid'], $record['image'])
1402
                    : $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'group', 'filename' => $record['image'] ]),
1403
 
1 efrain 1404
                    'profile'   => $this->url()->fromRoute('group/view', ['id' => $record['uuid']]),
1405
                    'priority'  => $record['priority'],
1406
 
1407
                ]);
1408
            }
1409
 
1410
            return new JsonModel([
1411
                'success' => true,
1412
                'data' => $items
1413
            ]);
1414
        } else {
1415
            return new JsonModel([
1416
                'success' => false,
1417
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1418
            ]);
1419
        }
1420
    }
1421
 
1422
    public function postsAction()
1423
    {
1424
        $request = $this->getRequest();
1425
        if ($request->isGet()) {
1426
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1427
            $currentUser = $currentUserPlugin->getUser();
1428
 
1429
            $items = [];
1430
            $postMapper = PostMapper::getInstance($this->adapter);
1431
            $posts = $postMapper->fetchAllActiveByNetworkId($currentUser->network_id);
1432
 
1433
 
281 efrain 1434
            if(self::_USE_S3) {
1435
                $storage = Storage::getInstance($this->config);
1436
                $path = $storage->getPathPost();
1437
            } else {
1438
                $storage = null;
1439
            }
1440
 
269 efrain 1441
 
1 efrain 1442
            foreach ($posts as $post) {
1443
                $dt = \DateTime::createFromFormat('Y-m-d', $post->date);
1444
                array_push($items, [
281 efrain 1445
                    'image' => $storage
1446
                    ? $storage->getGenericImage($path, $post->uuid, $post->image)
1447
                    : $this->url()->fromRoute('storage', ['code' => $post->uuid, 'type' => 'post', 'filename' => $post->image ]),
1 efrain 1448
                    'date' => $dt->format('d/m/Y'),
1449
                    'title' => $post->title,
1450
                    'link' => $this->url()->fromRoute('post', ['id' => $post->uuid]),
1451
                ]);
1452
            }
1453
 
1454
            return new JsonModel([
1455
                'success' => true,
1456
                'data' => $items
1457
            ]);
1458
        }
1459
 
1460
        return new JsonModel([
1461
            'success' => false,
1462
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1463
        ]);
1464
    }
1465
 
1466
 
1467
 
1468
    public function searchPeopleAction()
1469
    {
1470
        $request = $this->getRequest();
1471
        if ($request->isGet()) {
1472
 
1473
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1474
            $currentUser = $currentUserPlugin->getUser();
1475
 
1476
            $search = Functions::sanitizeFilterString($this->params()->fromQuery('search'));
1477
            if (strlen($search) >= 3) {
1478
 
270 efrain 1479
                $userBlockedIds = [$currentUser->id];
269 efrain 1480
 
270 efrain 1481
 
1482
                $userBlockedMapper = \LeadersLinked\Mapper\UserBlockedMapper::getInstance($this->adapter);
1483
                $ids = $userBlockedMapper->fetchAllBlockedReturnIds($currentUser->id);
1484
                foreach($ids as $id)
1485
                {
1486
                    if(!in_array($id, $userBlockedIds)) {
1487
                        array_push($userBlockedIds, $id);
1488
                    }
1489
                }
1490
 
1491
                $ids = $userBlockedMapper->fetchAllUserBlockMeReturnIds($currentUser->id);
1492
                foreach($ids as $id)
1493
                {
1494
                    if(!in_array($id, $userBlockedIds)) {
1495
                        array_push($userBlockedIds, $id);
1496
                    }
1497
                }
1498
 
1499
 
1500
 
1501
 
269 efrain 1502
                $records_x_page = 10;
1503
                $page = intval($this->params()->fromQuery('page', 0), 10);
1504
                $page = $page > 0 ? $page : 1;
1505
 
1 efrain 1506
                $userMapper = UserMapper::getInstance($this->adapter);
270 efrain 1507
                $paginator  = $userMapper->fetchAllSuggestPaginateByNetworkIdAndSearchAndNotBlocked(
1508
                    $currentUser->network_id, $search, $records_x_page, $page, $userBlockedIds );
1 efrain 1509
 
269 efrain 1510
                $items = [];
1511
                foreach ( $paginator as $record) {
1 efrain 1512
                    if ($currentUser->id == $record->id) {
1513
                        continue;
1514
                    }
278 efrain 1515
 
1 efrain 1516
 
269 efrain 1517
                    array_push($items, [
1518
                        'uuid' => $record->uuid,
1519
                        'contact' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')',
1520
                        'send_link' => $this->url()->fromRoute('inmail/message/send',[ 'id' => $record->uuid ], ['force_canonical' => true]),
1 efrain 1521
                    ]);
1522
                }
269 efrain 1523
 
1524
 
1525
                $response = [
1526
                    'success' => true,
1527
                    'data' => [
1528
                        'total' => [
1529
                            'count' => $paginator->getTotalItemCount(),
1530
                            'pages' => $paginator->getPages()->pageCount,
1531
                        ],
1532
                        'current' => [
1533
                            'items'    => $items,
1534
                            'page'     => $paginator->getCurrentPageNumber(),
1535
                            'count'    => $paginator->getCurrentItemCount(),
1536
                        ]
1537
                    ]
1538
                ];
1 efrain 1539
 
269 efrain 1540
                return new JsonModel($response);
1 efrain 1541
            } else {
1542
                return new JsonModel([
1543
                    'success' => true,
1544
                    'data' => []
1545
                ]);
1546
            }
1547
        } else {
1548
            return new JsonModel([
1549
                'success' => false,
1550
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1551
            ]);
1552
        }
1553
    }
1554
 
1555
    public function footerAction()
1556
    {
1557
        $request = $this->getRequest();
1558
        if ($request->isGet()) {
1559
 
1560
 
1561
            $links = isset($this->navigation['footer']) ?  $this->navigation['footer'] : [];
1562
 
1563
 
1564
            $data = [];
1565
            foreach ($links as $link) {
1566
                $data[$link['route']] = $link['label'];
1567
            }
1568
 
1569
 
1570
            return new JsonModel([
1571
                'success' => true,
1572
                'data' => $data,
1573
            ]);
1574
        } else {
1575
            return new JsonModel([
1576
                'success' => false,
1577
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1578
            ]);
1579
        }
1580
    }
1581
 
1582
 
1583
    /**
1584
     * Recuperamos los grupos sugeridos
1585
     * tiene que enviarse un petición GET a la siguiente url: /helpers/groups-suggestion/:group_id
1586
     * retorna un json en caso de ser  positivo
1587
     * [
1588
     *  'success' : true,
1589
     *  'data' : [
1590
     *      [
1591
     *        'id'      => 'id del grupo encriptado',
1592
     *        'name'    => 'nombre del grupo',
1593
     *        'image'   => 'imagen del grupo',
1594
     *        'profile' => 'url del profile',
1595
     *     ]
1596
     * ]
1597
     * En caso de ser negativo
1598
     * [
1599
     *  'success' : false,
1600
     *  'data' : mensaje de error
1601
     * ]
1602
     * @return \Laminas\View\Model\JsonModel
1603
     */
1604
    public function myGroupsAction()
1605
    {
1606
 
1607
        $request = $this->getRequest();
1608
        if ($request->isGet()) {
1609
 
1610
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1611
            $currentUser = $currentUserPlugin->getUser();
1612
 
1613
 
1614
            $queryMapper = QueryMapper::getInstance($this->adapter);
1615
            $select = $queryMapper->getSql()->select();
1616
            $select->columns(['id', 'uuid', 'name', 'image', 'status', 'privacy', 'priority' => new Expression('0')]);
1617
            $select->from(['g' => GroupMapper::_TABLE]);
1618
            $select->where->equalTo('status', Group::STATUS_ACTIVE);
1619
            $select->where->equalTo('g.user_id', $currentUser->id);
1620
            $select->order('name ASC');
1621
 
1622
 
1623
            $items = [];
281 efrain 1624
            if(self::_USE_S3) {
1625
                $storage = Storage::getInstance($this->config);
1626
            } else {
1627
                $storage = null;
1628
            }
1629
 
1 efrain 1630
 
1631
            $records = $queryMapper->fetchAll($select);
1632
            foreach ($records as $record) {
1633
 
1634
                array_push($items, [
1635
                    'id'        => $record['uuid'],
1636
                    'name'      => trim($record['name']),
281 efrain 1637
                    'image'     => $storage
1638
                    ? $storage->getGroupImageForCodeAndFilename($record['uuid'], $record['image'])
1639
                    : $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'group', 'filename' => $record['image'] ]),
1640
 
1 efrain 1641
                    'profile'   => $this->url()->fromRoute('group/view', ['id' => $record['uuid']]),
1642
                    'priority'  => $record['priority'],
1643
 
1644
                ]);
1645
            }
1646
 
1647
            return new JsonModel([
1648
                'success' => true,
1649
                'data' => $items
1650
            ]);
1651
        } else {
1652
            return new JsonModel([
1653
                'success' => false,
1654
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1655
            ]);
1656
        }
1657
    }
1658
 
1659
    public function nextEventsAction()
1660
    {
1661
        $request = $this->getRequest();
1662
        if ($request->isGet()) {
1663
 
1664
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1665
            $currentUser = $currentUserPlugin->getUser();
1666
 
1667
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1668
            $currentNetwork = $currentNetworkPlugin->getNetwork();
1669
 
1670
 
1671
 
1672
            $dt = new \DateTime();
1673
            $dt->setTime(0, 0, 0);
1674
            $start = $dt->format('Y-m-d H:i:s');
1675
 
1676
            $dt->add(new \DateInterval('P30D'));
1677
            $dt->setTime(23, 59, 59);
1678
            $end = $dt->format('Y-m-d H:i:s');
1679
 
1680
 
1681
 
1682
 
1683
            $events = [];
1684
 
1685
 
1686
 
1687
            //3 días
1688
            $expirePeriod = 86400 * 3;
1689
            $t1 = time();
1690
 
1691
            $companies = [];
1692
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1693
 
1694
            $companyUsers = [];
1695
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1696
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
1697
 
1698
            foreach ($records as $record) {
1699
                $companyUsers[$record->company_id] = $record->backend == CompanyUser::BACKEND_YES;
1700
            }
1701
 
1702
 
1703
 
1704
            $zoomMeetingMapper = ZoomMeetingMapper::getInstance($this->adapter);
1705
            $recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
1706
            $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1707
            $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
1708
            $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
1709
            $performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
1710
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
1711
            $userMapper = UserMapper::getInstance($this->adapter);
1712
 
1713
            $calendarEventMapper = CalendarEventMapper::getInstance($this->adapter);
1714
            $records = $calendarEventMapper->fetchAllByUserIdAndStartTimeAndEndTime($currentUser->id, $start, $end);
1715
            foreach ($records as $record) {
1716
                switch ($record->type) {
1717
 
1718
                    case CalendarEvent::TYPE_SURVEY_NORMAL:
1719
                        $backgroundColor = $currentNetwork->css_calendar_survey_bg_color;
1720
                        $textColor = $currentNetwork->css_calendar_survey_text_color;
1721
 
1722
                        $surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
1723
                        $surveyTest = $surveyTestMapper->fetchOne($record->relational_id);
1724
 
1725
                        if($surveyTest && $surveyTest->user_id == $currentUser->id) {
1726
 
1727
                            $surveyCampaingMapper = SurveyCampaignMapper::getInstance($this->adapter);
1728
                            $surveyCampaing = $surveyCampaingMapper->fetchOne($surveyTest->campaign_id);
1729
 
1730
                            $url = '';
1731
                            $hasLink = !empty($companyUsers[$surveyTest->company_id]);
1732
 
1733
                            if ($hasLink) {
1734
 
1735
                                if (!isset($companies[$surveyTest->company_id])) {
1736
                                    $company  = $companyMapper->fetchOne($surveyTest->company_id);
1737
 
1738
                                    $companies[$company->id]  = $company;
1739
                                } else {
1740
                                    $company = $companies[$surveyTest->company_id];
1741
                                }
1742
 
1743
 
1744
                                $url = $this->url()->fromRoute('backend/signin-company', [
1745
                                    'id' => $company->uuid,
1746
                                    'relational' => $surveyTest->uuid,
1747
                                    'type' => CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE,
136 efrain 1748
                                ], ['force_canonical' => true]);
1 efrain 1749
                            }
1750
 
1751
                            $dtStart = \DateTime::createFromFormat('Y-m-d', $surveyCampaing->end_date);
1752
 
1753
 
1754
                            array_push($events, [
1755
                                'id'                => $surveyTest->uuid,
1756
                                'title'             => $surveyCampaing->name,
146 efrain 1757
                                'start'             => $dtStart->format('Y-m-d'),
1 efrain 1758
                                'url'               => $url,
1759
                                'backgroundColor'   => $backgroundColor,
1760
                                'textColor'         => $textColor,
1761
                                'allDay'            => true,
1762
                                'type'              => 'task',
135 efrain 1763
                                'source'            => 'internal',
1 efrain 1764
                            ]);
1765
                        }
1766
 
1767
                        break;
1768
 
1769
                    case CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE:
1770
                        $backgroundColor = $currentNetwork->css_calendar_organizational_climate_bg_color;
1771
                        $textColor = $currentNetwork->css_calendar_organizational_climate_text_color;
1772
 
1773
                        $surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
1774
                        $surveyTest = $surveyTestMapper->fetchOne($record->relational_id);
1775
 
1776
                        if($surveyTest && $surveyTest->user_id == $currentUser->id) {
1777
 
1778
                            $surveyCampaingMapper = SurveyCampaignMapper::getInstance($this->adapter);
1779
                            $surveyCampaing = $surveyCampaingMapper->fetchOne($surveyTest->campaign_id);
1780
 
1781
                            $url = '';
1782
                            $hasLink = !empty($companyUsers[$surveyTest->company_id]);
1783
 
1784
                            if ($hasLink) {
1785
 
1786
                                if (!isset($companies[$surveyTest->company_id])) {
1787
                                    $company  = $companyMapper->fetchOne($surveyTest->company_id);
1788
 
1789
                                    $companies[$company->id]  = $company;
1790
                                } else {
1791
                                    $company = $companies[$surveyTest->company_id];
1792
                                }
1793
 
1794
 
1795
                                $url = $this->url()->fromRoute('backend/signin-company', [
1796
                                    'id' => $company->uuid,
1797
                                    'relational' => $surveyTest->uuid,
1798
                                    'type' => CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE,
136 efrain 1799
                                ], ['force_canonical' => true]);
1 efrain 1800
                            }
1801
 
1802
                            $dtStart = \DateTime::createFromFormat('Y-m-d', $surveyCampaing->end_date);
1803
 
1804
 
1805
                            array_push($events, [
1806
                                'id'                => $surveyTest->uuid,
1807
                                'title'             => $surveyCampaing->name,
146 efrain 1808
                                'start'             => $dtStart->format('Y-m-d'),
1 efrain 1809
                                'url'               => $url,
1810
                                'backgroundColor'   => $backgroundColor,
1811
                                'textColor'         => $textColor,
1812
                                'allDay'            => true,
1813
                                'type'              => 'task',
135 efrain 1814
                                'source'            => 'internal',
1 efrain 1815
                            ]);
1816
                        }
1817
 
1818
                        break;
1819
 
1820
 
1821
 
1822
 
1823
 
1824
 
1825
 
1826
 
1827
 
1828
 
1829
                    case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW:
1830
                        $backgroundColor = $currentNetwork->css_calendar_recruitment_and_selection_bg_color;
1831
                        $textColor = $currentNetwork->css_calendar_recruitment_and_selection_text_color;
1832
 
1833
 
1834
                        $recruitmentSelectionInterview = $recruitmentSelectionInterviewMapper->fetchOne($record->relational_id);
1835
                        if ($recruitmentSelectionInterview) {
1836
                            $recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($recruitmentSelectionInterview->vacancy_id);
1837
 
1838
                            $recruitmentSelectionCandidate = $recruitmentSelectionCandidateMapper->fetchOne($recruitmentSelectionInterview->candidate_id);
1839
                            if ($recruitmentSelectionVacancy && $recruitmentSelectionCandidate) {
1840
                                $jobDescription = $jobDescriptionMapper->fetchOne($recruitmentSelectionVacancy->job_description_id);
1841
                                if ($jobDescription) {
1842
                                    $url = '';
1843
                                    $hasLink = !empty($companyUsers[$recruitmentSelectionInterview->company_id]);
1844
 
1845
                                    if ($hasLink) {
1846
 
1847
                                        if (!isset($companies[$recruitmentSelectionInterview->company_id])) {
1848
                                            $company  = $companyMapper->fetchOne($recruitmentSelectionInterview->company_id);
1849
 
1850
                                            $companies[$company->id]  = $company;
1851
                                        } else {
1852
                                            $company = $companies[$recruitmentSelectionInterview->company_id];
1853
                                        }
1854
 
1855
 
1856
                                        $url = $this->url()->fromRoute('backend/signin-company', [
1857
                                            'id' => $company->uuid,
1858
                                            'relational' => $recruitmentSelectionInterview->uuid,
1859
                                            'type' => CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW
136 efrain 1860
                                        ], ['force_canonical' => true]);
1 efrain 1861
                                    }
1862
 
1863
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $recruitmentSelectionInterview->last_date);
1864
 
1865
 
1866
 
1867
 
1868
                                    array_push($events, [
1869
                                        'id'                => $recruitmentSelectionInterview->uuid,
1870
                                        'title'             => $recruitmentSelectionVacancy->name,
146 efrain 1871
                                        'start'             => $dtStart->format('Y-m-d'),
1 efrain 1872
                                        'url'               => $url,
1873
                                        'backgroundColor'   => $backgroundColor,
1874
                                        'textColor'         => $textColor,
1875
                                        'allDay'            => true,
1876
                                        'type'              => 'task',
135 efrain 1877
                                        'source'            => 'internal',
1 efrain 1878
                                    ]);
1879
                                }
1880
                            }
1881
                        }
1882
 
1883
 
1884
                        break;
1885
 
1886
                    case CalendarEvent::TYPE_PERFORMANCE_EVALUATION:
1887
 
1888
 
1889
                        $backgroundColor = $currentNetwork->css_calendar_performance_evaluation_bg_color;
1890
                        $textColor = $currentNetwork->css_calendar_performance_evaluation_text_color;
1891
 
1892
 
1893
                        $performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOne($record->relational_id);
1894
                        if ($performanceEvaluationTest) {
1895
 
1896
                            $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
1897
                            if ($performanceEvaluationForm) {
1898
                                $jobDescription = $jobDescriptionMapper->fetchOne($performanceEvaluationForm->job_description_id);
1899
                                if ($jobDescription) {
1900
                                    $url = '';
1901
                                    $hasLink = !empty($companyUsers[$performanceEvaluationTest->company_id]);
1902
 
1903
                                    if ($performanceEvaluationTest->supervisor_id) {
1904
                                        $supervisor = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);
1905
                                    } else {
1906
                                        $supervisor = '';
1907
                                    }
1908
 
1909
                                    if ($performanceEvaluationTest->employee_id) {
1910
                                        $employee = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
1911
                                    } else {
1912
                                        $employee = '';
1913
                                    }
1914
 
1915
 
1916
 
1917
                                    if ($hasLink) {
1918
 
1919
                                        if (!isset($companies[$performanceEvaluationTest->company_id])) {
1920
                                            $company  = $companyMapper->fetchOne($performanceEvaluationTest->company_id);
1921
 
1922
                                            $companies[$company->id]  = $company;
1923
                                        } else {
1924
                                            $company = $companies[$performanceEvaluationTest->company_id];
1925
                                        }
1926
 
1927
 
1928
                                        $url = $this->url()->fromRoute('backend/signin-company', [
1929
                                            'id' => $company->uuid,
1930
                                            'relational' => $performanceEvaluationTest->uuid,
1931
                                            'type' => CalendarEvent::TYPE_PERFORMANCE_EVALUATION
136 efrain 1932
                                        ], ['force_canonical' => true]);
1 efrain 1933
                                    }
1934
 
1935
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $performanceEvaluationTest->last_date);
1936
 
1937
                                    array_push($events, [
1938
                                        'id'                => $performanceEvaluationTest->uuid,
1939
                                        'title'             =>  $performanceEvaluationForm->name,
146 efrain 1940
                                        'start'             => $dtStart->format('Y-m-d'),
1 efrain 1941
                                        'url'               => $url,
1942
                                        'backgroundColor'   => $backgroundColor,
1943
                                        'textColor'         => $textColor,
1944
                                        'allDay'            => true,
1945
                                        'type'              => 'task',
135 efrain 1946
                                        'source'            => 'internal',
1 efrain 1947
                                    ]);
1948
                                }
1949
                            }
1950
                        }
1951
 
1952
 
1953
 
1954
 
1955
 
1956
                        break;
1957
 
1958
 
1959
                    case CalendarEvent::TYPE_ZOOM:
1960
                        $zoomMeeting = $zoomMeetingMapper->fetchOne($record->relational_id);
1961
                        if ($zoomMeeting) {
1962
 
1963
                            $backgroundColor = $currentNetwork->css_calendar_zoom_bg_color;
1964
                            $textColor = $currentNetwork->css_calendar_zoom_text_color;
1965
 
1966
                            $dtStart = \DateTime::createFromFormat('Y-m-d H:i:s', $zoomMeeting->start_time);
1967
                            $t2 = $dtStart->getTimestamp();
1968
 
1969
                            if ($t2 > $t1) {
1970
 
1971
                                $t3 = $t1 + $expirePeriod;
1972
                                if ($t3 > $t2) {
1973
                                    $backgroundColor = $currentNetwork->css_calendar_expire_bg_color;
1974
                                    $textColor = $currentNetwork->css_calendar_expire_text_color;
1975
                                }
1976
                            }
1977
 
1978
 
1979
 
1980
                            if ($currentUser->timezone && $currentUser->timezone != $zoomMeeting->timezone) {
1981
 
1982
                                $start =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->start_time, $zoomMeeting->timezone, $currentUser->timezone));
1983
                                $end =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->end_time, $zoomMeeting->timezone, $currentUser->timezone));
1984
                            } else {
1985
                                $start = str_replace(' ', 'T', $zoomMeeting->start_time);
1986
                                $end = str_replace(' ', 'T', $zoomMeeting->end_time);
1987
                            }
1988
 
1989
 
1990
 
1991
                            $url = $zoomMeeting->join_url;
1992
 
1993
 
1994
 
1995
 
1996
                            $agenda = $zoomMeeting->agenda . "<br>" .
1997
                                " LABEL_ZOOM_MEETING_START_DATE : " . $dtStart->format('Y-m-d') . "<br>" .
1998
                                " LABEL_ZOOM_MEETING_START_TIME : " . $dtStart->format('H:i a') . "<br>" .
1999
                                " LABEL_ZOOM_MEETING_TIMEZONE : " . $zoomMeeting->timezone . "<br>" .
2000
                                " LABEL_ZOOM_MEETING_TITLE :  " . $zoomMeeting->topic  . "<br>" .
2001
                                " LABEL_ZOOM_MEETING_URL : " . $zoomMeeting->join_url . "<br>" .
2002
                                " LABEL_ZOOM_MEETING_PASSWORD : " . $zoomMeeting->password . "<br>";
2003
 
2004
                            array_push($events, [
2005
                                'id'                => $zoomMeeting->id,
2006
                                'title'             => $zoomMeeting->topic,
2007
                                'agenda'            => $agenda,
2008
                                'start'             => $start,
2009
                                'end'               => $end,
2010
                                'url'               => $zoomMeeting->join_url,
2011
                                'backgroundColor'   => $backgroundColor,
2012
                                'textColor'         => $textColor,
135 efrain 2013
                                'type'              => 'event',
2014
                                'source'            => 'external',
1 efrain 2015
                            ]);
2016
                        }
2017
                        break;
2018
                }
2019
            }
2020
 
2021
 
2022
 
2023
            return new JsonModel([
2024
                'success' => true,
2025
                'data' => $events
2026
            ]);
2027
        } else {
2028
            return new JsonModel([
2029
                'success' => false,
2030
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2031
            ]);
2032
        }
2033
    }
2034
 
2035
    public function menuAction()
2036
    {
2037
 
2038
 
2039
        $request = $this->getRequest();
2040
 
2041
 
2042
 
2043
        if ($request->isGet()) {
2044
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
2045
            $network =  $currentNetworkPlugin->getNetwork();
2046
 
2047
 
2048
            $currentUserPlugin = $this->plugin('currentUserPlugin');
2049
            if($currentUserPlugin->hasIdentity()) {
2050
                $currentUser = $currentUserPlugin->getUser();
157 efrain 2051
 
1 efrain 2052
 
2053
 
2054
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
2055
 
2056
                $link_admin         = $currentUser->usertype_id == UserType::ADMIN ? 1 : 0;
2057
                $link_impersonate   = $currentUser->is_super_user == User::IS_SUPER_USER_YES ? 1 : 0;
2058
                if($link_impersonate) {
2059
                    $url_impersonate = $this->url()->fromRoute('signin/impersonate');
2060
                } else {
2061
                    $url_impersonate = '';
2062
                }
2063
 
2064
                $fullname = trim($currentUser->first_name . ' ' . $currentUser->last_name);
2065
 
2066
                $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
2067
                $visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
2068
 
2069
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
2070
                $connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
2071
 
2072
 
2073
                if($currentUser->location_id) {
2074
                    $locationMapper = LocationMapper::getInstance($this->adapter);
2075
                    $location = $locationMapper->fetchOne($currentUser->location_id);
2076
 
2077
                    $country = $location->country;
2078
                } else {
2079
                    $country = '';
2080
                }
2081
 
2082
 
2083
 
2084
 
2085
                if($currentUser->usertype_id == UserType::ADMIN) {
2086
                    $url_admin = $this->url()->fromRoute( 'backend/signin-admin');
2087
                } else {
2088
                    $url_admin = '';
2089
                }
2090
 
2091
 
2092
 
2093
                $link_company = '';
2094
                if($network->default != Network::DEFAULT_YES) {
2095
                    $companyMapper = CompanyMapper::getInstance($this->adapter);
2096
                    $company = $companyMapper->fetchDefaultForNetworkByNetworkId($network->id);
2097
                    if($company) {
2098
                        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
2099
                        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
2100
                        if($companyUser) {
2101
                            if($companyUser && $companyUser->status == CompanyUser::STATUS_ACCEPTED && $companyUser->backend == CompanyUser::BACKEND_YES ) {
2102
                                $link_company = ['route' => 'backend/signin-company', 'id' => $company->uuid ];
2103
                            }
2104
                        }
2105
                    }
157 efrain 2106
                } else {
2107
 
1 efrain 2108
                }
2109
 
167 efrain 2110
 
2111
 
2112
 
2113
 
1 efrain 2114
                if ($acl->isAllowed($currentUser->usertype_id,  'knowledge-area')) {
2115
                    $route_knowledge_area = $this->url()->fromRoute('knowledge-area');
2116
                    $link_knowledge_area = 1;
2117
                } else {
2118
 
2119
                    $route_knowledge_area = '';
2120
                    $link_knowledge_area = 0;
2121
                }
2122
 
2123
                if ($acl->isAllowed($currentUser->usertype_id,  'my-coach')) {
2124
                    $route_my_coach = $this->url()->fromRoute('my-coach');
2125
                    $link_my_coach = 1;
2126
                } else {
2127
 
2128
                    $route_my_coach = '';
2129
                    $link_my_coach = 0;
2130
                }
2131
 
2132
                if($network->default == Network::DEFAULT_YES) {
2133
                    if($network->relationship_user_mode == Network::RELATIONSHIP_USER_MODE_USER_2_USER)  {
2134
                        $pages = getAclMenuDefaultNetworkConnectionUser2User();
2135
                    } else {
2136
                        $pages = getAclMenuDefaultNetworkConnectionAll2All();
2137
                    }
2138
                } else {
2139
                    if($network->relationship_user_mode == Network::RELATIONSHIP_USER_MODE_USER_2_USER)  {
2140
 
2141
                        $pages = getAclMenuNonDefaulNetworkConnectionUser2User();
2142
 
2143
                    } else {
2144
                        $pages = getAclMenuNonDefaultNetworkConnectionAll2All();
2145
                    }
2146
                }
2147
 
2148
 
2149
                $menu = [];
2150
                foreach ($pages as $page) {
2151
 
2152
                    if (!$page || empty($page['route']) || !$acl->isAllowed($currentUser->usertype_id, $page['route'])) {
2153
                        continue;
2154
                    }
2155
 
269 efrain 2156
                    $childs = [];
2157
 
1 efrain 2158
                    $ajax = false;
2159
                    if ($page['route'] == 'company' && $network->default == Network::DEFAULT_NO) {
2160
 
269 efrain 2161
 
2162
 
1 efrain 2163
                        if ($link_company) {
269 efrain 2164
                            $ajax = true;
157 efrain 2165
                            $page['route'] = $this->url()->fromRoute($link_company['route'], ['id' => $link_company['id']]);
269 efrain 2166
 
2167
                            $childs = [
2168
                                'label' => 'Acceder',
2169
                                'href' => $page['route'],
2170
                                'ajax' => $ajax,
2171
                                'childs' => []
2172
                            ];
2173
 
2174
 
2175
 
2176
 
1 efrain 2177
                        } else {
2178
                            continue;
2179
                        }
2180
                    }
2181
 
2182
                    $option = [
2183
                        'label' => $page['label'],
2184
                        'href' => $page['route'],
2185
                        'img' => empty($page['class']) ? '' : $page['class'],
2186
                        'ajax' => $ajax ? 1 : 0,
269 efrain 2187
                        'childs' => $childs,
1 efrain 2188
                    ];
2189
 
269 efrain 2190
                    if ($page['route'] == 'company' && $network->default == Network::DEFAULT_NO) {
2191
                        if ($link_company) {
2192
                            array_push($option['childs'], );
2193
 
2194
 
2195
                        }
2196
                    }
2197
 
1 efrain 2198
                    $childs = empty($page['pages']) ? [] : $page['pages'];
2199
                    if ($childs) {
2200
                        foreach ($childs as $child) {
2201
                            if (!$acl->isAllowed($currentUser->usertype_id,  $child['route'])) {
2202
                                continue;
2203
                            }
2204
 
2205
                            $childs_level2 = [];
2206
 
2207
                            $childsLevel2 = empty($child['pages']) ? [] : $child['pages'];
2208
 
2209
                            if ($childsLevel2) {
2210
                                foreach ($childsLevel2 as $childLevel2) {
2211
                                    if (!$acl->isAllowed($currentUser->usertype_id,  $childLevel2['route'])) {
2212
                                        continue;
2213
                                    }
2214
 
2215
                                    array_push($childs_level2, [
2216
                                        'label' => $childLevel2['label'],
2217
                                        'href' => $childLevel2['route'],
2218
 
2219
                                    ]);
2220
                                }
2221
                            }
2222
 
2223
                            array_push($option['childs'], [
2224
                                'label' => $child['label'],
2225
                                'href' => $child['route'],
2226
                                'childs' => $childs_level2,
2227
                            ]);
2228
                        }
2229
                    }
2230
 
2231
                    array_push($menu, $option);
2232
                }
2233
 
269 efrain 2234
 
281 efrain 2235
                if(self::_USE_S3) {
2236
                    $storage = Storage::getInstance($this->config);
2237
                } else {
2238
                    $storage = null;
2239
                }
1 efrain 2240
 
269 efrain 2241
                $image = $storage->getUserImage($currentUser);
1 efrain 2242
                $isChatPage = $this->getEvent()->getViewModel()->getVariable('is_chat');
2243
                $routeCheckSession = $this->url()->fromRoute('check-session');
203 efrain 2244
                $routeAbuseReport = $this->url()->fromRoute('abuse-report');
1 efrain 2245
 
2246
 
269 efrain 2247
                if($network->navbar) {
281 efrain 2248
 
2249
 
2250
 
2251
 
2252
                    if(self::_USE_S3) {
2253
 
2254
                        $storage = Storage::getInstance($this->config);
2255
                        $path = $storage->getPathNetwork();
2256
 
2257
                        $navbar = $storage->getGenericImage($path, $network->uuid, $network->navbar);
2258
 
2259
                    } else {
2260
                        $storage = null;
2261
                    }
2262
 
2263
                    $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
2264
                    $currentNetwork = $currentNetworkPlugin->getNetwork();
2265
 
2266
                    $parts = explode('.', $currentNetwork->main_hostname);
2267
                    if($parts[1] === 'com') {
2268
                        $replace_main = false;
2269
                    } else {
2270
                        $replace_main = true;
2271
                    }
2272
 
2273
                    if($currentNetwork->navbar) {
2274
                        $navbar_url = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->navbar);
2275
                    } else {
2276
                        $navbar_url = '';
2277
                    }
2278
 
2279
                    if($replace_main) {
2280
                        $navbar_url = str_replace($currentNetwork->main_hostname, $currentNetwork->service_hostname, $navbar_url);
2281
                    }
2282
 
2283
                    if($currentNetwork->alternative_hostname) {
2284
                        $navbar_url = str_replace($currentNetwork->alternative_hostname, $currentNetwork->service_hostname, $navbar_url);
2285
 
2286
                    }
2287
                }
2288
 
2289
 
2290
 
2291
                if($network->navbar) {
2292
 
269 efrain 2293
                } else {
2294
                    $navbar = '';
2295
                }
1 efrain 2296
 
2297
                return new JsonModel([
2298
                    'menu'                  => $menu,
2299
                    'isChatPage'            => $isChatPage == 1,
2300
                    'routeCheckSession'     => $routeCheckSession,
203 efrain 2301
                    'routeAbuseReport'      => $routeAbuseReport,
1 efrain 2302
                    'linkAdmin'             => $link_admin == 1,
2303
                    'urlAdmin'              => $url_admin,
2304
                    'linkImpersonate'       => $link_impersonate ==1 ,
2305
                    'urlImpersonate'        => $url_impersonate,
2306
                    'image'                 => $image,
2307
                    'fullName'              => $fullname,
2308
                    'country'               => $country,
2309
                    'visits'                => $visits,
2310
                    'connections'           => $connections,
269 efrain 2311
                    'logoForNavbar'         => $navbar,
1 efrain 2312
                    'defaultNetwork'        => $network->default,
2313
               ]);
2314
 
2315
 
2316
 
2317
            }
2318
 
2319
 
2320
            return new JsonModel([
2321
                'menu'                  => [],
2322
                'isChatPage'            => false,
2323
                'routeCheckSession'     => '',
2324
                'linkAdmin'             => false,
2325
                'urlAdmin'              => '',
2326
                'linkImpersonate'       => false,
2327
                'urlImpersonate'        => '',
2328
                'image'                 => '',
2329
                'fullName'              => '',
2330
                'country'               => 0,
2331
                'visits'                => 0,
2332
                'connections'           => 0,
2333
                'logoForNavbar'         => 'https://' . $network->main_hostname . '/storage-network/type/navbar',
2334
                'defaultNetwork'        => $network->default,
2335
                'linkKnowledgeArea'     => false,
2336
                'routeKnowledgeArea'    => '',
2337
                'linkMyCoach'           => false,
2338
                'routeMyCoach'          => '',
2339
            ]);
2340
 
2341
        } else {
2342
 
2343
            return new JsonModel([
2344
                'success' => false,
2345
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2346
            ]);
2347
        }
2348
 
2349
 
2350
        return new JsonModel([
2351
            'success' => false,
2352
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2353
        ]);
2354
    }
2355
 
2356
    public function companySizesAction()
2357
    {
2358
        $request = $this->getRequest();
2359
 
2360
 
2361
 
2362
        if ($request->isGet()) {
2363
            $items = [];
2364
 
2365
            $mapper = CompanySizeMapper::getInstance($this->adapter);
2366
            $records = $mapper->fetchAllActive();
2367
            foreach($records as $record)
2368
            {
2369
                 $items[ $record->uuid ] = $record->name;
2370
            }
2371
 
2372
            return new JsonModel([
2373
                'success' => true,
2374
                'data' => $items
2375
            ]);
2376
 
2377
 
2378
        }
2379
        return new JsonModel([
2380
            'success' => false,
2381
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2382
        ]);
2383
    }
2384
 
2385
    public function degreesAction()
2386
    {
2387
        $request = $this->getRequest();
2388
 
2389
 
2390
 
2391
        if ($request->isGet()) {
2392
            $items = [];
2393
 
2394
            $mapper = DegreeMapper::getInstance($this->adapter);
2395
            $records = $mapper->fetchAllActive();
2396
            foreach($records as $record)
2397
            {
2398
                $items[ $record->uuid ] = $record->name;
2399
            }
2400
 
2401
            return new JsonModel([
2402
                'success' => true,
2403
                'data' => $items
2404
            ]);
2405
 
2406
 
2407
        }
2408
        return new JsonModel([
2409
            'success' => false,
2410
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2411
        ]);
2412
    }
2413
 
2414
    public function languagesAction()
2415
    {
2416
        $request = $this->getRequest();
2417
 
2418
 
2419
 
2420
        if ($request->isGet()) {
2421
            $items = [];
2422
 
2423
            $mapper = LanguageMapper::getInstance($this->adapter);
2424
            $records = $mapper->fetchAllActive();
2425
            foreach($records as $record)
2426
            {
2427
                $items[ $record->id ] = $record->name;
2428
            }
2429
 
2430
            return new JsonModel([
2431
                'success' => true,
2432
                'data' => $items
2433
            ]);
2434
 
2435
 
2436
        }
2437
        return new JsonModel([
2438
            'success' => false,
2439
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2440
        ]);
2441
    }
2442
 
2443
    public function skillsAction()
2444
    {
2445
        $request = $this->getRequest();
2446
 
2447
 
2448
 
2449
        if ($request->isGet()) {
2450
            $items = [];
2451
 
2452
            $mapper = SkillMapper::getInstance($this->adapter);
2453
            $records = $mapper->fetchAllActive();
2454
            foreach($records as $record)
2455
            {
2456
                $items[ $record->uuid ] = $record->name;
2457
            }
2458
 
2459
            return new JsonModel([
2460
                'success' => true,
2461
                'data' => $items
2462
            ]);
2463
 
2464
 
2465
        }
2466
        return new JsonModel([
2467
            'success' => false,
2468
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2469
        ]);
2470
    }
2471
 
2472
 
2473
    public function aptitudesAction()
2474
    {
2475
        $request = $this->getRequest();
2476
 
2477
 
2478
 
2479
        if ($request->isGet()) {
2480
            $items = [];
2481
 
2482
            $mapper = AptitudeMapper::getInstance($this->adapter);
2483
            $records = $mapper->fetchAllActive();
2484
            foreach($records as $record)
2485
            {
2486
                $items[ $record->uuid ] = $record->name;
2487
            }
2488
 
2489
            return new JsonModel([
2490
                'success' => true,
2491
                'data' => $items
2492
            ]);
2493
 
2494
 
2495
        }
2496
        return new JsonModel([
2497
            'success' => false,
2498
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2499
        ]);
2500
    }
2501
 
2502
    public function hobbiesAction()
2503
    {
2504
        $request = $this->getRequest();
2505
 
2506
 
2507
 
2508
        if ($request->isGet()) {
2509
            $items = [];
2510
 
2511
            $mapper = HobbyAndInterestMapper::getInstance($this->adapter);
2512
            $records = $mapper->fetchAllActive();
2513
            foreach($records as $record)
2514
            {
2515
                $items[ $record->uuid ] = $record->name;
2516
            }
2517
 
2518
            return new JsonModel([
2519
                'success' => true,
2520
                'data' => $items
2521
            ]);
2522
 
2523
 
2524
        }
2525
        return new JsonModel([
2526
            'success' => false,
2527
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2528
        ]);
2529
    }
2530
 
2531
    public function industriesAction()
2532
    {
2533
        $request = $this->getRequest();
2534
 
2535
 
2536
 
2537
        if ($request->isGet()) {
2538
            $items = [];
2539
 
2540
            $mapper = IndustryMapper::getInstance($this->adapter);
2541
            $records = $mapper->fetchAllActive();
2542
            foreach($records as $record)
2543
            {
2544
                $items[ $record->uuid ] = $record->name;
2545
            }
2546
 
2547
            return new JsonModel([
2548
                'success' => true,
2549
                'data' => $items
2550
            ]);
2551
 
2552
 
2553
        }
2554
        return new JsonModel([
2555
            'success' => false,
2556
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2557
        ]);
2558
    }
2559
 
2560
    public function timeZonesAction() {
2561
 
2562
        $request = $this->getRequest();
2563
 
2564
 
2565
 
2566
        if ($request->isGet()) {
2567
            $items = [];
2568
 
2569
 
2570
            $records = Functions::getAllTimeZones();
2571
            foreach($records as $record)
2572
            {
2573
                $items[ $record ] = $record;
2574
            }
2575
 
2576
            return new JsonModel([
2577
                'success' => true,
2578
                'data' => $items
2579
            ]);
2580
 
2581
 
2582
        }
2583
        return new JsonModel([
2584
            'success' => false,
2585
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2586
        ]);
2587
 
2588
 
2589
 
2590
 
2591
 
2592
 
2593
    }
2594
 
117 efrain 2595
 
2596
    public function groupTypesAction()
2597
    {
2598
        $request = $this->getRequest();
2599
 
2600
 
2601
 
2602
        if ($request->isGet()) {
2603
            $items = [];
2604
 
2605
            $mapper = GroupTypeMapper::getInstance($this->adapter);
2606
            $records = $mapper->fetchAllActive();
2607
            foreach($records as $record)
2608
            {
2609
                $items[ $record->uuid ] = $record->name;
2610
            }
2611
 
2612
            return new JsonModel([
2613
                'success' => true,
2614
                'data' => $items
2615
            ]);
2616
 
2617
 
2618
        }
2619
        return new JsonModel([
2620
            'success' => false,
2621
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2622
        ]);
2623
    }
2624
 
2625
 
192 efrain 2626
    public function abuseReportAction()
2627
    {
195 efrain 2628
 
2629
 
2630
 
192 efrain 2631
        $request = $this->getRequest();
2632
 
2633
        if ($request->isPost()) {
2634
 
2635
            $dataPost = $request->getPost()->toArray();
2636
 
2637
            $form = new CreateForm();
2638
            $form->setData($dataPost);
2639
 
195 efrain 2640
 
2641
 
192 efrain 2642
            if(!$form->isValid()) {
2643
                $messages = [];
195 efrain 2644
 
192 efrain 2645
 
2646
 
2647
                $form_messages = (array) $form->getMessages();
2648
                foreach($form_messages  as $fieldname => $field_messages)
2649
                {
2650
 
2651
                    $messages[$fieldname] = array_values($field_messages);
2652
                }
2653
 
195 efrain 2654
 
2655
 
192 efrain 2656
                return new JsonModel([
2657
                    'success'   => false,
2658
                    'data'   => $messages
2659
                ]);
2660
 
2661
            }
195 efrain 2662
 
192 efrain 2663
 
2664
            $dataPost = (array) $form->getData();
1 efrain 2665
 
192 efrain 2666
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
2667
            $network =  $currentNetworkPlugin->getNetwork();
2668
 
2669
 
2670
            $currentUserPlugin = $this->plugin('currentUserPlugin');
2671
            $currentUser = $currentUserPlugin->getUser();
2672
 
2673
            $id     = $this->params()->fromRoute('id');
2674
            $type   = $this->params()->fromRoute('type');
2675
 
2676
            $blockUser = $dataPost['block_user'] == 'y';
2677
 
2678
            $abuseReport = new AbuseReport();
2679
            $abuseReport->network_id = $network->id;
2680
            $abuseReport->user_reporting_id = $currentUser->id;
2681
            $abuseReport->status = AbuseReport::STATUS_PENDING;
2682
            $abuseReport->comment = $dataPost['comment'];
2683
            $abuseReport->reason = $dataPost['reason'];
2684
 
195 efrain 2685
 
192 efrain 2686
 
2687
            switch($type)
2688
            {
2689
                case 'feed' :
195 efrain 2690
                    $feedMapper = FeedMapper::getInstance($this->adapter);
192 efrain 2691
                    $feed = $feedMapper->fetchOneByUuid($id);
2692
                    if(!$feed || $feed->status != Feed::STATUS_PUBLISHED || $feed->network_id != $network->id) {
2693
 
2694
                        return new JsonModel([
2695
                            'success' => false,
2696
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2697
                        ]);
2698
                    }
2699
 
2700
                    if($feed->user_id == 1) {
2701
                        return new JsonModel([
2702
                            'success' => false,
2703
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2704
                        ]);
2705
                    }
2706
 
2707
                    if($feed->user_id == $currentUser->id) {
2708
                        return new JsonModel([
2709
                            'success' => false,
2710
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_IS_YOURSELF'
2711
                        ]);
2712
                    }
2713
 
2714
                    $abuseReport->related_id        =  $feed->id;
2715
                    $abuseReport->user_reported_id  = $feed->user_id;
2716
                    $abuseReport->type              = AbuseReport::TYPE_FEED;
2717
 
2718
 
2719
 
2720
                    break;
2721
 
2722
                case 'post' :
2723
                    $postMapper = PostMapper::getInstance($this->adapter);
2724
                    $post = $postMapper->fetchOneByUuid($id);
2725
                    if(!$post || $post->status != Post::STATUS_ACTIVE || $post->network_id != $network->id) {
2726
 
2727
                        return new JsonModel([
2728
                            'success' => false,
2729
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2730
                        ]);
2731
                    }
2732
 
2733
                    if($post->user_id == 1) {
2734
                        return new JsonModel([
2735
                            'success' => false,
2736
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2737
                        ]);
2738
                    }
2739
 
2740
 
2741
                    if($post->user_id == $currentUser->id) {
2742
                        return new JsonModel([
2743
                            'success' => false,
2744
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_IS_YOURSELF'
2745
                        ]);
2746
                    }
2747
 
2748
 
2749
                    $abuseReport->related_id        = $post->id;
2750
                    $abuseReport->user_reported_id  = $post->user_id;
2751
                    $abuseReport->type              = AbuseReport::TYPE_POST;
2752
 
2753
                    break;
2754
 
2755
 
2756
                case 'comment' :
2757
                    $commentMapper = CommentMapper::getInstance($this->adapter);
2758
                    $comment = $commentMapper->fetchOneByUuid($id);
2759
                    if(!$comment || $comment->network_id != $network->id || $comment->status != Comment::STATUS_PUBLISHED) {
2760
 
2761
                        return new JsonModel([
2762
                            'success' => false,
2763
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2764
                        ]);
2765
                    }
2766
 
2767
                    if($comment->user_id == 1) {
2768
                        return new JsonModel([
2769
                            'success' => false,
2770
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2771
                        ]);
2772
                    }
2773
 
2774
                    if($comment->user_id == $currentUser->id) {
2775
                        return new JsonModel([
2776
                            'success' => false,
2777
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_IS_YOURSELF'
2778
                        ]);
2779
                    }
2780
 
2781
                    $abuseReport->related_id        = $comment->id;
2782
                    $abuseReport->user_reported_id  = $comment->user_id;
2783
                    $abuseReport->type              = AbuseReport::TYPE_COMMENT;
2784
 
2785
                    break;
2786
 
269 efrain 2787
                    /*
192 efrain 2788
                case 'message' :
2789
                    $messageMapper = MessageMapper::getInstance($this->adapter);
2790
                    $message = $messageMapper->fetchOneByUuid($id);
2791
                    if(!$message || $message->receiver_id != $currentUser->id || $message->receiver_status != Message::STATUS_NORMAL) {
2792
 
2793
                        return new JsonModel([
2794
                            'success' => false,
2795
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2796
                        ]);
2797
                    }
2798
 
2799
                    if($message->sender_id == 1) {
2800
                        return new JsonModel([
2801
                            'success' => false,
2802
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2803
                        ]);
2804
                    }
2805
 
2806
                    $abuseReport->related_id        = $message->id;
2807
                    $abuseReport->user_reported_id  = $message->sender_id;
2808
                    $abuseReport->type              = AbuseReport::TYPE_INMAIL_MESSAGE;
2809
 
2810
                    break;
269 efrain 2811
 
192 efrain 2812
                case 'chat-message' :
2813
                    $messageMapper = ChatMessageMapper::getInstance($this->adapter);
2814
                    $message = $messageMapper->fetchOneByUuid($id);
2815
                    if(!$message || $message->to_id != $currentUser->id || $message->status != ChatMessage::STATUS_PUBLISHED) {
2816
 
2817
                        return new JsonModel([
2818
                            'success' => false,
2819
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2820
                        ]);
2821
                    }
2822
 
2823
                    if($message->from_id == 1) {
2824
                        return new JsonModel([
2825
                            'success' => false,
2826
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2827
                        ]);
2828
                    }
2829
 
2830
                    $abuseReport->related_id        = $message->id;
2831
                    $abuseReport->user_reported_id  = $message->from_id;
2832
                    $abuseReport->type              = AbuseReport::TYPE_CHAT_USER_MESSAGE;
2833
 
2834
                    break;
269 efrain 2835
 
192 efrain 2836
                case 'chat-group-message' :
2837
                    $messageMapper = ChatGroupMessageMapper::getInstance($this->adapter);
2838
                    $message = $messageMapper->fetchOne($id);
2839
                    if(!$message || $message->status != ChatMessage::STATUS_PUBLISHED) {
2840
 
2841
                        return new JsonModel([
2842
                            'success' => false,
2843
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2844
                        ]);
2845
                    }
2846
 
2847
                    $userMessageMapper = ChatGroupUserMessageMapper::getInstance($this->adapter);
2848
                    $userMessage = $userMessageMapper->fetchOneByIdMessageIdAndReceiverId($message->id, $currentUser->id);
2849
                    if(!$userMessage) {
2850
 
2851
                        return new JsonModel([
2852
                            'success' => false,
2853
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2854
                        ]);
2855
                    }
2856
 
2857
 
2858
                    if($message->sender_id == 1) {
2859
                        return new JsonModel([
2860
                            'success' => false,
2861
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2862
                        ]);
2863
                    }
2864
 
2865
                    $abuseReport->related_id        = $message->id;
2866
                    $abuseReport->user_reported_id  = $message->sender_id;
2867
                    $abuseReport->type              = AbuseReport::TYPE_CHAT_USER_MESSAGE;
2868
 
269 efrain 2869
                    break; */
192 efrain 2870
            }
195 efrain 2871
 
2872
 
192 efrain 2873
 
2874
            $abuseReportMapper = AbuseReportMapper::getInstance($this->adapter);
2875
            if($abuseReportMapper->insert($abuseReport)) {
2876
 
2877
                if($blockUser) {
2878
 
2879
                    $userBlockedMapper = UserBlockedMapper::getInstance($this->adapter);
2880
                    $userBlocked = $userBlockedMapper->fetchOneByUserIdAndBlockedId($abuseReport->user_reporting_id, $abuseReport->user_reporting_id);
2881
                    if($userBlocked) {
2882
 
2883
 
2884
                        return new JsonModel([
2885
                            'success' => true,
2886
                            'data' => [
2887
                                'message' => 'LABEL_ABUSE_REPORT_SENT_WITH_BLOCK_USER',
2888
                                'block' => true
2889
                            ]
2890
                        ]);
2891
 
2892
                    } else {
2893
 
2894
                        $userBlocked = new UserBlocked();
2895
                        $userBlocked->user_id = $abuseReport->user_reporting_id;
2896
                        $userBlocked->blocked_id = $abuseReport->user_reported_id;
2897
 
2898
                        if($userBlockedMapper->insert($userBlocked)) {
2899
                            return new JsonModel([
2900
                                'success' => true,
2901
                                'data' => [
2902
                                    'message' => 'LABEL_ABUSE_REPORT_SENT_WITH_BLOCK_USER',
2903
                                    'block' => true
2904
                                ]
2905
                            ]);
2906
 
2907
                        } else {
2908
                            return new JsonModel([
2909
                                'success' => true,
2910
                                'data' => [
2911
                                    'message' => 'LABEL_ABUSE_REPORT_SENT_WITHOUT_BLOCK_USER',
2912
                                    'block' => false
2913
                                ]
2914
                            ]);
2915
 
2916
 
2917
                        }
2918
                    }
2919
 
2920
 
2921
                } else {
2922
                    return new JsonModel([
2923
                        'success' => true,
2924
                        'data' => [
2925
                            'message' => 'LABEL_ABUSE_REPORT_SENT_WITHOUT_BLOCK_USER',
2926
                            'block' => false
2927
                        ]
2928
                    ]);
2929
                }
2930
 
2931
 
2932
            } else {
2933
                return new JsonModel([
2934
                    'success' => false,
2935
                    'data' => 'ERROR_ABUSE_REPORT_NOT_SENT'
2936
                ]);
2937
            }
2938
 
2939
 
2940
 
2941
 
2942
 
2943
 
2944
 
2945
 
2946
        }
2947
        return new JsonModel([
2948
            'success' => false,
2949
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2950
        ]);
2951
 
2952
 
2953
    }
2954
 
2955
 
2956
 
1 efrain 2957
}