Proyectos de Subversion LeadersLinked - Services

Rev

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