Proyectos de Subversion LeadersLinked - Services

Rev

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