Proyectos de Subversion LeadersLinked - Services

Rev

Rev 203 | Rev 270 | 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
 
269 efrain 1430
                $abuseReportIds = [$currentUser->id];
1431
 
1432
                $records_x_page = 10;
1433
                $page = intval($this->params()->fromQuery('page', 0), 10);
1434
                $page = $page > 0 ? $page : 1;
1435
 
1 efrain 1436
                $userMapper = UserMapper::getInstance($this->adapter);
269 efrain 1437
                $paginator  = $userMapper->fetchAllSuggestPaginateByNetworkIdAndSearchAndNotAbuseReport(
1438
                    $currentUser->network_id, $search, $records_x_page, $page, $abuseReportIds );
1 efrain 1439
 
269 efrain 1440
                $items = [];
1441
                foreach ( $paginator as $record) {
1 efrain 1442
                    if ($currentUser->id == $record->id) {
1443
                        continue;
1444
                    }
1445
 
1446
 
269 efrain 1447
                    array_push($items, [
1448
                        'uuid' => $record->uuid,
1449
                        'contact' => trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')',
1450
                        'send_link' => $this->url()->fromRoute('inmail/message/send',[ 'id' => $record->uuid ], ['force_canonical' => true]),
1 efrain 1451
                    ]);
1452
                }
269 efrain 1453
 
1454
 
1455
                $response = [
1456
                    'success' => true,
1457
                    'data' => [
1458
                        'total' => [
1459
                            'count' => $paginator->getTotalItemCount(),
1460
                            'pages' => $paginator->getPages()->pageCount,
1461
                        ],
1462
                        'current' => [
1463
                            'items'    => $items,
1464
                            'page'     => $paginator->getCurrentPageNumber(),
1465
                            'count'    => $paginator->getCurrentItemCount(),
1466
                        ]
1467
                    ]
1468
                ];
1 efrain 1469
 
269 efrain 1470
                return new JsonModel($response);
1 efrain 1471
            } else {
1472
                return new JsonModel([
1473
                    'success' => true,
1474
                    'data' => []
1475
                ]);
1476
            }
1477
        } else {
1478
            return new JsonModel([
1479
                'success' => false,
1480
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1481
            ]);
1482
        }
1483
    }
1484
 
1485
    public function footerAction()
1486
    {
1487
        $request = $this->getRequest();
1488
        if ($request->isGet()) {
1489
 
1490
 
1491
            $links = isset($this->navigation['footer']) ?  $this->navigation['footer'] : [];
1492
 
1493
 
1494
            $data = [];
1495
            foreach ($links as $link) {
1496
                $data[$link['route']] = $link['label'];
1497
            }
1498
 
1499
 
1500
            return new JsonModel([
1501
                'success' => true,
1502
                'data' => $data,
1503
            ]);
1504
        } else {
1505
            return new JsonModel([
1506
                'success' => false,
1507
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1508
            ]);
1509
        }
1510
    }
1511
 
1512
 
1513
    /**
1514
     * Recuperamos los grupos sugeridos
1515
     * tiene que enviarse un petición GET a la siguiente url: /helpers/groups-suggestion/:group_id
1516
     * retorna un json en caso de ser  positivo
1517
     * [
1518
     *  'success' : true,
1519
     *  'data' : [
1520
     *      [
1521
     *        'id'      => 'id del grupo encriptado',
1522
     *        'name'    => 'nombre del grupo',
1523
     *        'image'   => 'imagen del grupo',
1524
     *        'profile' => 'url del profile',
1525
     *     ]
1526
     * ]
1527
     * En caso de ser negativo
1528
     * [
1529
     *  'success' : false,
1530
     *  'data' : mensaje de error
1531
     * ]
1532
     * @return \Laminas\View\Model\JsonModel
1533
     */
1534
    public function myGroupsAction()
1535
    {
1536
 
1537
        $request = $this->getRequest();
1538
        if ($request->isGet()) {
1539
 
1540
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1541
            $currentUser = $currentUserPlugin->getUser();
1542
 
1543
 
1544
            $queryMapper = QueryMapper::getInstance($this->adapter);
1545
            $select = $queryMapper->getSql()->select();
1546
            $select->columns(['id', 'uuid', 'name', 'image', 'status', 'privacy', 'priority' => new Expression('0')]);
1547
            $select->from(['g' => GroupMapper::_TABLE]);
1548
            $select->where->equalTo('status', Group::STATUS_ACTIVE);
1549
            $select->where->equalTo('g.user_id', $currentUser->id);
1550
            $select->order('name ASC');
1551
 
1552
 
1553
            $items = [];
269 efrain 1554
            $storage = Storage::getInstance($this->config);
1 efrain 1555
 
1556
            $records = $queryMapper->fetchAll($select);
1557
            foreach ($records as $record) {
1558
 
1559
                array_push($items, [
1560
                    'id'        => $record['uuid'],
1561
                    'name'      => trim($record['name']),
269 efrain 1562
                    'image'     => $storage->getGroupImageForCodeAndFilename($record['uuid'], $record['image']),
1 efrain 1563
                    'profile'   => $this->url()->fromRoute('group/view', ['id' => $record['uuid']]),
1564
                    'priority'  => $record['priority'],
1565
 
1566
                ]);
1567
            }
1568
 
1569
            return new JsonModel([
1570
                'success' => true,
1571
                'data' => $items
1572
            ]);
1573
        } else {
1574
            return new JsonModel([
1575
                'success' => false,
1576
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1577
            ]);
1578
        }
1579
    }
1580
 
1581
    public function nextEventsAction()
1582
    {
1583
        $request = $this->getRequest();
1584
        if ($request->isGet()) {
1585
 
1586
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1587
            $currentUser = $currentUserPlugin->getUser();
1588
 
1589
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1590
            $currentNetwork = $currentNetworkPlugin->getNetwork();
1591
 
1592
 
1593
 
1594
            $dt = new \DateTime();
1595
            $dt->setTime(0, 0, 0);
1596
            $start = $dt->format('Y-m-d H:i:s');
1597
 
1598
            $dt->add(new \DateInterval('P30D'));
1599
            $dt->setTime(23, 59, 59);
1600
            $end = $dt->format('Y-m-d H:i:s');
1601
 
1602
 
1603
 
1604
 
1605
            $events = [];
1606
 
1607
 
1608
 
1609
            //3 días
1610
            $expirePeriod = 86400 * 3;
1611
            $t1 = time();
1612
 
1613
            $companies = [];
1614
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1615
 
1616
            $companyUsers = [];
1617
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1618
            $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
1619
 
1620
            foreach ($records as $record) {
1621
                $companyUsers[$record->company_id] = $record->backend == CompanyUser::BACKEND_YES;
1622
            }
1623
 
1624
 
1625
 
1626
            $zoomMeetingMapper = ZoomMeetingMapper::getInstance($this->adapter);
1627
            $recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
1628
            $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1629
            $recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
1630
            $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
1631
            $performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
1632
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
1633
            $userMapper = UserMapper::getInstance($this->adapter);
1634
 
1635
            $calendarEventMapper = CalendarEventMapper::getInstance($this->adapter);
1636
            $records = $calendarEventMapper->fetchAllByUserIdAndStartTimeAndEndTime($currentUser->id, $start, $end);
1637
            foreach ($records as $record) {
1638
                switch ($record->type) {
1639
 
1640
                    case CalendarEvent::TYPE_SURVEY_NORMAL:
1641
                        $backgroundColor = $currentNetwork->css_calendar_survey_bg_color;
1642
                        $textColor = $currentNetwork->css_calendar_survey_text_color;
1643
 
1644
                        $surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
1645
                        $surveyTest = $surveyTestMapper->fetchOne($record->relational_id);
1646
 
1647
                        if($surveyTest && $surveyTest->user_id == $currentUser->id) {
1648
 
1649
                            $surveyCampaingMapper = SurveyCampaignMapper::getInstance($this->adapter);
1650
                            $surveyCampaing = $surveyCampaingMapper->fetchOne($surveyTest->campaign_id);
1651
 
1652
                            $url = '';
1653
                            $hasLink = !empty($companyUsers[$surveyTest->company_id]);
1654
 
1655
                            if ($hasLink) {
1656
 
1657
                                if (!isset($companies[$surveyTest->company_id])) {
1658
                                    $company  = $companyMapper->fetchOne($surveyTest->company_id);
1659
 
1660
                                    $companies[$company->id]  = $company;
1661
                                } else {
1662
                                    $company = $companies[$surveyTest->company_id];
1663
                                }
1664
 
1665
 
1666
                                $url = $this->url()->fromRoute('backend/signin-company', [
1667
                                    'id' => $company->uuid,
1668
                                    'relational' => $surveyTest->uuid,
1669
                                    'type' => CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE,
136 efrain 1670
                                ], ['force_canonical' => true]);
1 efrain 1671
                            }
1672
 
1673
                            $dtStart = \DateTime::createFromFormat('Y-m-d', $surveyCampaing->end_date);
1674
 
1675
 
1676
                            array_push($events, [
1677
                                'id'                => $surveyTest->uuid,
1678
                                'title'             => $surveyCampaing->name,
146 efrain 1679
                                'start'             => $dtStart->format('Y-m-d'),
1 efrain 1680
                                'url'               => $url,
1681
                                'backgroundColor'   => $backgroundColor,
1682
                                'textColor'         => $textColor,
1683
                                'allDay'            => true,
1684
                                'type'              => 'task',
135 efrain 1685
                                'source'            => 'internal',
1 efrain 1686
                            ]);
1687
                        }
1688
 
1689
                        break;
1690
 
1691
                    case CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE:
1692
                        $backgroundColor = $currentNetwork->css_calendar_organizational_climate_bg_color;
1693
                        $textColor = $currentNetwork->css_calendar_organizational_climate_text_color;
1694
 
1695
                        $surveyTestMapper = SurveyTestMapper::getInstance($this->adapter);
1696
                        $surveyTest = $surveyTestMapper->fetchOne($record->relational_id);
1697
 
1698
                        if($surveyTest && $surveyTest->user_id == $currentUser->id) {
1699
 
1700
                            $surveyCampaingMapper = SurveyCampaignMapper::getInstance($this->adapter);
1701
                            $surveyCampaing = $surveyCampaingMapper->fetchOne($surveyTest->campaign_id);
1702
 
1703
                            $url = '';
1704
                            $hasLink = !empty($companyUsers[$surveyTest->company_id]);
1705
 
1706
                            if ($hasLink) {
1707
 
1708
                                if (!isset($companies[$surveyTest->company_id])) {
1709
                                    $company  = $companyMapper->fetchOne($surveyTest->company_id);
1710
 
1711
                                    $companies[$company->id]  = $company;
1712
                                } else {
1713
                                    $company = $companies[$surveyTest->company_id];
1714
                                }
1715
 
1716
 
1717
                                $url = $this->url()->fromRoute('backend/signin-company', [
1718
                                    'id' => $company->uuid,
1719
                                    'relational' => $surveyTest->uuid,
1720
                                    'type' => CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE,
136 efrain 1721
                                ], ['force_canonical' => true]);
1 efrain 1722
                            }
1723
 
1724
                            $dtStart = \DateTime::createFromFormat('Y-m-d', $surveyCampaing->end_date);
1725
 
1726
 
1727
                            array_push($events, [
1728
                                'id'                => $surveyTest->uuid,
1729
                                'title'             => $surveyCampaing->name,
146 efrain 1730
                                'start'             => $dtStart->format('Y-m-d'),
1 efrain 1731
                                'url'               => $url,
1732
                                'backgroundColor'   => $backgroundColor,
1733
                                'textColor'         => $textColor,
1734
                                'allDay'            => true,
1735
                                'type'              => 'task',
135 efrain 1736
                                'source'            => 'internal',
1 efrain 1737
                            ]);
1738
                        }
1739
 
1740
                        break;
1741
 
1742
 
1743
 
1744
 
1745
 
1746
 
1747
 
1748
 
1749
 
1750
 
1751
                    case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW:
1752
                        $backgroundColor = $currentNetwork->css_calendar_recruitment_and_selection_bg_color;
1753
                        $textColor = $currentNetwork->css_calendar_recruitment_and_selection_text_color;
1754
 
1755
 
1756
                        $recruitmentSelectionInterview = $recruitmentSelectionInterviewMapper->fetchOne($record->relational_id);
1757
                        if ($recruitmentSelectionInterview) {
1758
                            $recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($recruitmentSelectionInterview->vacancy_id);
1759
 
1760
                            $recruitmentSelectionCandidate = $recruitmentSelectionCandidateMapper->fetchOne($recruitmentSelectionInterview->candidate_id);
1761
                            if ($recruitmentSelectionVacancy && $recruitmentSelectionCandidate) {
1762
                                $jobDescription = $jobDescriptionMapper->fetchOne($recruitmentSelectionVacancy->job_description_id);
1763
                                if ($jobDescription) {
1764
                                    $url = '';
1765
                                    $hasLink = !empty($companyUsers[$recruitmentSelectionInterview->company_id]);
1766
 
1767
                                    if ($hasLink) {
1768
 
1769
                                        if (!isset($companies[$recruitmentSelectionInterview->company_id])) {
1770
                                            $company  = $companyMapper->fetchOne($recruitmentSelectionInterview->company_id);
1771
 
1772
                                            $companies[$company->id]  = $company;
1773
                                        } else {
1774
                                            $company = $companies[$recruitmentSelectionInterview->company_id];
1775
                                        }
1776
 
1777
 
1778
                                        $url = $this->url()->fromRoute('backend/signin-company', [
1779
                                            'id' => $company->uuid,
1780
                                            'relational' => $recruitmentSelectionInterview->uuid,
1781
                                            'type' => CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW
136 efrain 1782
                                        ], ['force_canonical' => true]);
1 efrain 1783
                                    }
1784
 
1785
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $recruitmentSelectionInterview->last_date);
1786
 
1787
 
1788
 
1789
 
1790
                                    array_push($events, [
1791
                                        'id'                => $recruitmentSelectionInterview->uuid,
1792
                                        'title'             => $recruitmentSelectionVacancy->name,
146 efrain 1793
                                        'start'             => $dtStart->format('Y-m-d'),
1 efrain 1794
                                        'url'               => $url,
1795
                                        'backgroundColor'   => $backgroundColor,
1796
                                        'textColor'         => $textColor,
1797
                                        'allDay'            => true,
1798
                                        'type'              => 'task',
135 efrain 1799
                                        'source'            => 'internal',
1 efrain 1800
                                    ]);
1801
                                }
1802
                            }
1803
                        }
1804
 
1805
 
1806
                        break;
1807
 
1808
                    case CalendarEvent::TYPE_PERFORMANCE_EVALUATION:
1809
 
1810
 
1811
                        $backgroundColor = $currentNetwork->css_calendar_performance_evaluation_bg_color;
1812
                        $textColor = $currentNetwork->css_calendar_performance_evaluation_text_color;
1813
 
1814
 
1815
                        $performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOne($record->relational_id);
1816
                        if ($performanceEvaluationTest) {
1817
 
1818
                            $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
1819
                            if ($performanceEvaluationForm) {
1820
                                $jobDescription = $jobDescriptionMapper->fetchOne($performanceEvaluationForm->job_description_id);
1821
                                if ($jobDescription) {
1822
                                    $url = '';
1823
                                    $hasLink = !empty($companyUsers[$performanceEvaluationTest->company_id]);
1824
 
1825
                                    if ($performanceEvaluationTest->supervisor_id) {
1826
                                        $supervisor = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);
1827
                                    } else {
1828
                                        $supervisor = '';
1829
                                    }
1830
 
1831
                                    if ($performanceEvaluationTest->employee_id) {
1832
                                        $employee = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
1833
                                    } else {
1834
                                        $employee = '';
1835
                                    }
1836
 
1837
 
1838
 
1839
                                    if ($hasLink) {
1840
 
1841
                                        if (!isset($companies[$performanceEvaluationTest->company_id])) {
1842
                                            $company  = $companyMapper->fetchOne($performanceEvaluationTest->company_id);
1843
 
1844
                                            $companies[$company->id]  = $company;
1845
                                        } else {
1846
                                            $company = $companies[$performanceEvaluationTest->company_id];
1847
                                        }
1848
 
1849
 
1850
                                        $url = $this->url()->fromRoute('backend/signin-company', [
1851
                                            'id' => $company->uuid,
1852
                                            'relational' => $performanceEvaluationTest->uuid,
1853
                                            'type' => CalendarEvent::TYPE_PERFORMANCE_EVALUATION
136 efrain 1854
                                        ], ['force_canonical' => true]);
1 efrain 1855
                                    }
1856
 
1857
                                    $dtStart = \DateTime::createFromFormat('Y-m-d', $performanceEvaluationTest->last_date);
1858
 
1859
                                    array_push($events, [
1860
                                        'id'                => $performanceEvaluationTest->uuid,
1861
                                        'title'             =>  $performanceEvaluationForm->name,
146 efrain 1862
                                        'start'             => $dtStart->format('Y-m-d'),
1 efrain 1863
                                        'url'               => $url,
1864
                                        'backgroundColor'   => $backgroundColor,
1865
                                        'textColor'         => $textColor,
1866
                                        'allDay'            => true,
1867
                                        'type'              => 'task',
135 efrain 1868
                                        'source'            => 'internal',
1 efrain 1869
                                    ]);
1870
                                }
1871
                            }
1872
                        }
1873
 
1874
 
1875
 
1876
 
1877
 
1878
                        break;
1879
 
1880
 
1881
                    case CalendarEvent::TYPE_ZOOM:
1882
                        $zoomMeeting = $zoomMeetingMapper->fetchOne($record->relational_id);
1883
                        if ($zoomMeeting) {
1884
 
1885
                            $backgroundColor = $currentNetwork->css_calendar_zoom_bg_color;
1886
                            $textColor = $currentNetwork->css_calendar_zoom_text_color;
1887
 
1888
                            $dtStart = \DateTime::createFromFormat('Y-m-d H:i:s', $zoomMeeting->start_time);
1889
                            $t2 = $dtStart->getTimestamp();
1890
 
1891
                            if ($t2 > $t1) {
1892
 
1893
                                $t3 = $t1 + $expirePeriod;
1894
                                if ($t3 > $t2) {
1895
                                    $backgroundColor = $currentNetwork->css_calendar_expire_bg_color;
1896
                                    $textColor = $currentNetwork->css_calendar_expire_text_color;
1897
                                }
1898
                            }
1899
 
1900
 
1901
 
1902
                            if ($currentUser->timezone && $currentUser->timezone != $zoomMeeting->timezone) {
1903
 
1904
                                $start =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->start_time, $zoomMeeting->timezone, $currentUser->timezone));
1905
                                $end =  str_replace(' ', 'T', Functions::convertDateTimeBetweenTimeZones($zoomMeeting->end_time, $zoomMeeting->timezone, $currentUser->timezone));
1906
                            } else {
1907
                                $start = str_replace(' ', 'T', $zoomMeeting->start_time);
1908
                                $end = str_replace(' ', 'T', $zoomMeeting->end_time);
1909
                            }
1910
 
1911
 
1912
 
1913
                            $url = $zoomMeeting->join_url;
1914
 
1915
 
1916
 
1917
 
1918
                            $agenda = $zoomMeeting->agenda . "<br>" .
1919
                                " LABEL_ZOOM_MEETING_START_DATE : " . $dtStart->format('Y-m-d') . "<br>" .
1920
                                " LABEL_ZOOM_MEETING_START_TIME : " . $dtStart->format('H:i a') . "<br>" .
1921
                                " LABEL_ZOOM_MEETING_TIMEZONE : " . $zoomMeeting->timezone . "<br>" .
1922
                                " LABEL_ZOOM_MEETING_TITLE :  " . $zoomMeeting->topic  . "<br>" .
1923
                                " LABEL_ZOOM_MEETING_URL : " . $zoomMeeting->join_url . "<br>" .
1924
                                " LABEL_ZOOM_MEETING_PASSWORD : " . $zoomMeeting->password . "<br>";
1925
 
1926
                            array_push($events, [
1927
                                'id'                => $zoomMeeting->id,
1928
                                'title'             => $zoomMeeting->topic,
1929
                                'agenda'            => $agenda,
1930
                                'start'             => $start,
1931
                                'end'               => $end,
1932
                                'url'               => $zoomMeeting->join_url,
1933
                                'backgroundColor'   => $backgroundColor,
1934
                                'textColor'         => $textColor,
135 efrain 1935
                                'type'              => 'event',
1936
                                'source'            => 'external',
1 efrain 1937
                            ]);
1938
                        }
1939
                        break;
1940
                }
1941
            }
1942
 
1943
 
1944
 
1945
            return new JsonModel([
1946
                'success' => true,
1947
                'data' => $events
1948
            ]);
1949
        } else {
1950
            return new JsonModel([
1951
                'success' => false,
1952
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1953
            ]);
1954
        }
1955
    }
1956
 
1957
    public function menuAction()
1958
    {
1959
 
1960
 
1961
        $request = $this->getRequest();
1962
 
1963
 
1964
 
1965
        if ($request->isGet()) {
1966
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
1967
            $network =  $currentNetworkPlugin->getNetwork();
1968
 
1969
 
1970
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1971
            if($currentUserPlugin->hasIdentity()) {
1972
                $currentUser = $currentUserPlugin->getUser();
157 efrain 1973
 
1 efrain 1974
 
1975
 
1976
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
1977
 
1978
                $link_admin         = $currentUser->usertype_id == UserType::ADMIN ? 1 : 0;
1979
                $link_impersonate   = $currentUser->is_super_user == User::IS_SUPER_USER_YES ? 1 : 0;
1980
                if($link_impersonate) {
1981
                    $url_impersonate = $this->url()->fromRoute('signin/impersonate');
1982
                } else {
1983
                    $url_impersonate = '';
1984
                }
1985
 
1986
                $fullname = trim($currentUser->first_name . ' ' . $currentUser->last_name);
1987
 
1988
                $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
1989
                $visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
1990
 
1991
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1992
                $connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
1993
 
1994
 
1995
                if($currentUser->location_id) {
1996
                    $locationMapper = LocationMapper::getInstance($this->adapter);
1997
                    $location = $locationMapper->fetchOne($currentUser->location_id);
1998
 
1999
                    $country = $location->country;
2000
                } else {
2001
                    $country = '';
2002
                }
2003
 
2004
 
2005
 
2006
 
2007
                if($currentUser->usertype_id == UserType::ADMIN) {
2008
                    $url_admin = $this->url()->fromRoute( 'backend/signin-admin');
2009
                } else {
2010
                    $url_admin = '';
2011
                }
2012
 
2013
 
2014
 
2015
                $link_company = '';
2016
                if($network->default != Network::DEFAULT_YES) {
2017
                    $companyMapper = CompanyMapper::getInstance($this->adapter);
2018
                    $company = $companyMapper->fetchDefaultForNetworkByNetworkId($network->id);
2019
                    if($company) {
2020
                        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
2021
                        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
2022
                        if($companyUser) {
2023
                            if($companyUser && $companyUser->status == CompanyUser::STATUS_ACCEPTED && $companyUser->backend == CompanyUser::BACKEND_YES ) {
2024
                                $link_company = ['route' => 'backend/signin-company', 'id' => $company->uuid ];
2025
                            }
2026
                        }
2027
                    }
157 efrain 2028
                } else {
2029
 
1 efrain 2030
                }
2031
 
167 efrain 2032
 
2033
 
2034
 
2035
 
1 efrain 2036
                if ($acl->isAllowed($currentUser->usertype_id,  'knowledge-area')) {
2037
                    $route_knowledge_area = $this->url()->fromRoute('knowledge-area');
2038
                    $link_knowledge_area = 1;
2039
                } else {
2040
 
2041
                    $route_knowledge_area = '';
2042
                    $link_knowledge_area = 0;
2043
                }
2044
 
2045
                if ($acl->isAllowed($currentUser->usertype_id,  'my-coach')) {
2046
                    $route_my_coach = $this->url()->fromRoute('my-coach');
2047
                    $link_my_coach = 1;
2048
                } else {
2049
 
2050
                    $route_my_coach = '';
2051
                    $link_my_coach = 0;
2052
                }
2053
 
2054
                if($network->default == Network::DEFAULT_YES) {
2055
                    if($network->relationship_user_mode == Network::RELATIONSHIP_USER_MODE_USER_2_USER)  {
2056
                        $pages = getAclMenuDefaultNetworkConnectionUser2User();
2057
                    } else {
2058
                        $pages = getAclMenuDefaultNetworkConnectionAll2All();
2059
                    }
2060
                } else {
2061
                    if($network->relationship_user_mode == Network::RELATIONSHIP_USER_MODE_USER_2_USER)  {
2062
 
2063
                        $pages = getAclMenuNonDefaulNetworkConnectionUser2User();
2064
 
2065
                    } else {
2066
                        $pages = getAclMenuNonDefaultNetworkConnectionAll2All();
2067
                    }
2068
                }
2069
 
2070
 
2071
                $menu = [];
2072
                foreach ($pages as $page) {
2073
 
2074
                    if (!$page || empty($page['route']) || !$acl->isAllowed($currentUser->usertype_id, $page['route'])) {
2075
                        continue;
2076
                    }
2077
 
269 efrain 2078
                    $childs = [];
2079
 
1 efrain 2080
                    $ajax = false;
2081
                    if ($page['route'] == 'company' && $network->default == Network::DEFAULT_NO) {
2082
 
269 efrain 2083
 
2084
 
1 efrain 2085
                        if ($link_company) {
269 efrain 2086
                            $ajax = true;
157 efrain 2087
                            $page['route'] = $this->url()->fromRoute($link_company['route'], ['id' => $link_company['id']]);
269 efrain 2088
 
2089
                            $childs = [
2090
                                'label' => 'Acceder',
2091
                                'href' => $page['route'],
2092
                                'ajax' => $ajax,
2093
                                'childs' => []
2094
                            ];
2095
 
2096
 
2097
 
2098
 
1 efrain 2099
                        } else {
2100
                            continue;
2101
                        }
2102
                    }
2103
 
2104
                    $option = [
2105
                        'label' => $page['label'],
2106
                        'href' => $page['route'],
2107
                        'img' => empty($page['class']) ? '' : $page['class'],
2108
                        'ajax' => $ajax ? 1 : 0,
269 efrain 2109
                        'childs' => $childs,
1 efrain 2110
                    ];
2111
 
269 efrain 2112
                    if ($page['route'] == 'company' && $network->default == Network::DEFAULT_NO) {
2113
                        if ($link_company) {
2114
                            array_push($option['childs'], );
2115
 
2116
 
2117
                        }
2118
                    }
2119
 
1 efrain 2120
                    $childs = empty($page['pages']) ? [] : $page['pages'];
2121
                    if ($childs) {
2122
                        foreach ($childs as $child) {
2123
                            if (!$acl->isAllowed($currentUser->usertype_id,  $child['route'])) {
2124
                                continue;
2125
                            }
2126
 
2127
                            $childs_level2 = [];
2128
 
2129
                            $childsLevel2 = empty($child['pages']) ? [] : $child['pages'];
2130
 
2131
                            if ($childsLevel2) {
2132
                                foreach ($childsLevel2 as $childLevel2) {
2133
                                    if (!$acl->isAllowed($currentUser->usertype_id,  $childLevel2['route'])) {
2134
                                        continue;
2135
                                    }
2136
 
2137
                                    array_push($childs_level2, [
2138
                                        'label' => $childLevel2['label'],
2139
                                        'href' => $childLevel2['route'],
2140
 
2141
                                    ]);
2142
                                }
2143
                            }
2144
 
2145
                            array_push($option['childs'], [
2146
                                'label' => $child['label'],
2147
                                'href' => $child['route'],
2148
                                'childs' => $childs_level2,
2149
                            ]);
2150
                        }
2151
                    }
2152
 
2153
                    array_push($menu, $option);
2154
                }
2155
 
269 efrain 2156
 
1 efrain 2157
 
269 efrain 2158
                $storage = Storage::getInstance($this->config);
2159
 
2160
 
2161
                $image = $storage->getUserImage($currentUser);
1 efrain 2162
                $isChatPage = $this->getEvent()->getViewModel()->getVariable('is_chat');
2163
                $routeCheckSession = $this->url()->fromRoute('check-session');
203 efrain 2164
                $routeAbuseReport = $this->url()->fromRoute('abuse-report');
1 efrain 2165
 
269 efrain 2166
                $storage = Storage::getInstance($this->config);
2167
                $path = $storage->getPathNetwork();
1 efrain 2168
 
269 efrain 2169
                if($network->navbar) {
2170
                    $navbar = $storage->getGenericImage($path, $network->uuid, $network->navbar);
2171
                } else {
2172
                    $navbar = '';
2173
                }
1 efrain 2174
 
2175
                return new JsonModel([
2176
                    'menu'                  => $menu,
2177
                    'isChatPage'            => $isChatPage == 1,
2178
                    'routeCheckSession'     => $routeCheckSession,
203 efrain 2179
                    'routeAbuseReport'      => $routeAbuseReport,
1 efrain 2180
                    'linkAdmin'             => $link_admin == 1,
2181
                    'urlAdmin'              => $url_admin,
2182
                    'linkImpersonate'       => $link_impersonate ==1 ,
2183
                    'urlImpersonate'        => $url_impersonate,
2184
                    'image'                 => $image,
2185
                    'fullName'              => $fullname,
2186
                    'country'               => $country,
2187
                    'visits'                => $visits,
2188
                    'connections'           => $connections,
269 efrain 2189
                    'logoForNavbar'         => $navbar,
1 efrain 2190
                    'defaultNetwork'        => $network->default,
2191
               ]);
2192
 
2193
 
2194
 
2195
            }
2196
 
2197
 
2198
            return new JsonModel([
2199
                'menu'                  => [],
2200
                'isChatPage'            => false,
2201
                'routeCheckSession'     => '',
2202
                'linkAdmin'             => false,
2203
                'urlAdmin'              => '',
2204
                'linkImpersonate'       => false,
2205
                'urlImpersonate'        => '',
2206
                'image'                 => '',
2207
                'fullName'              => '',
2208
                'country'               => 0,
2209
                'visits'                => 0,
2210
                'connections'           => 0,
2211
                'logoForNavbar'         => 'https://' . $network->main_hostname . '/storage-network/type/navbar',
2212
                'defaultNetwork'        => $network->default,
2213
                'linkKnowledgeArea'     => false,
2214
                'routeKnowledgeArea'    => '',
2215
                'linkMyCoach'           => false,
2216
                'routeMyCoach'          => '',
2217
            ]);
2218
 
2219
        } else {
2220
 
2221
            return new JsonModel([
2222
                'success' => false,
2223
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2224
            ]);
2225
        }
2226
 
2227
 
2228
        return new JsonModel([
2229
            'success' => false,
2230
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2231
        ]);
2232
    }
2233
 
2234
    public function companySizesAction()
2235
    {
2236
        $request = $this->getRequest();
2237
 
2238
 
2239
 
2240
        if ($request->isGet()) {
2241
            $items = [];
2242
 
2243
            $mapper = CompanySizeMapper::getInstance($this->adapter);
2244
            $records = $mapper->fetchAllActive();
2245
            foreach($records as $record)
2246
            {
2247
                 $items[ $record->uuid ] = $record->name;
2248
            }
2249
 
2250
            return new JsonModel([
2251
                'success' => true,
2252
                'data' => $items
2253
            ]);
2254
 
2255
 
2256
        }
2257
        return new JsonModel([
2258
            'success' => false,
2259
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2260
        ]);
2261
    }
2262
 
2263
    public function degreesAction()
2264
    {
2265
        $request = $this->getRequest();
2266
 
2267
 
2268
 
2269
        if ($request->isGet()) {
2270
            $items = [];
2271
 
2272
            $mapper = DegreeMapper::getInstance($this->adapter);
2273
            $records = $mapper->fetchAllActive();
2274
            foreach($records as $record)
2275
            {
2276
                $items[ $record->uuid ] = $record->name;
2277
            }
2278
 
2279
            return new JsonModel([
2280
                'success' => true,
2281
                'data' => $items
2282
            ]);
2283
 
2284
 
2285
        }
2286
        return new JsonModel([
2287
            'success' => false,
2288
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2289
        ]);
2290
    }
2291
 
2292
    public function languagesAction()
2293
    {
2294
        $request = $this->getRequest();
2295
 
2296
 
2297
 
2298
        if ($request->isGet()) {
2299
            $items = [];
2300
 
2301
            $mapper = LanguageMapper::getInstance($this->adapter);
2302
            $records = $mapper->fetchAllActive();
2303
            foreach($records as $record)
2304
            {
2305
                $items[ $record->id ] = $record->name;
2306
            }
2307
 
2308
            return new JsonModel([
2309
                'success' => true,
2310
                'data' => $items
2311
            ]);
2312
 
2313
 
2314
        }
2315
        return new JsonModel([
2316
            'success' => false,
2317
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2318
        ]);
2319
    }
2320
 
2321
    public function skillsAction()
2322
    {
2323
        $request = $this->getRequest();
2324
 
2325
 
2326
 
2327
        if ($request->isGet()) {
2328
            $items = [];
2329
 
2330
            $mapper = SkillMapper::getInstance($this->adapter);
2331
            $records = $mapper->fetchAllActive();
2332
            foreach($records as $record)
2333
            {
2334
                $items[ $record->uuid ] = $record->name;
2335
            }
2336
 
2337
            return new JsonModel([
2338
                'success' => true,
2339
                'data' => $items
2340
            ]);
2341
 
2342
 
2343
        }
2344
        return new JsonModel([
2345
            'success' => false,
2346
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2347
        ]);
2348
    }
2349
 
2350
 
2351
    public function aptitudesAction()
2352
    {
2353
        $request = $this->getRequest();
2354
 
2355
 
2356
 
2357
        if ($request->isGet()) {
2358
            $items = [];
2359
 
2360
            $mapper = AptitudeMapper::getInstance($this->adapter);
2361
            $records = $mapper->fetchAllActive();
2362
            foreach($records as $record)
2363
            {
2364
                $items[ $record->uuid ] = $record->name;
2365
            }
2366
 
2367
            return new JsonModel([
2368
                'success' => true,
2369
                'data' => $items
2370
            ]);
2371
 
2372
 
2373
        }
2374
        return new JsonModel([
2375
            'success' => false,
2376
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2377
        ]);
2378
    }
2379
 
2380
    public function hobbiesAction()
2381
    {
2382
        $request = $this->getRequest();
2383
 
2384
 
2385
 
2386
        if ($request->isGet()) {
2387
            $items = [];
2388
 
2389
            $mapper = HobbyAndInterestMapper::getInstance($this->adapter);
2390
            $records = $mapper->fetchAllActive();
2391
            foreach($records as $record)
2392
            {
2393
                $items[ $record->uuid ] = $record->name;
2394
            }
2395
 
2396
            return new JsonModel([
2397
                'success' => true,
2398
                'data' => $items
2399
            ]);
2400
 
2401
 
2402
        }
2403
        return new JsonModel([
2404
            'success' => false,
2405
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2406
        ]);
2407
    }
2408
 
2409
    public function industriesAction()
2410
    {
2411
        $request = $this->getRequest();
2412
 
2413
 
2414
 
2415
        if ($request->isGet()) {
2416
            $items = [];
2417
 
2418
            $mapper = IndustryMapper::getInstance($this->adapter);
2419
            $records = $mapper->fetchAllActive();
2420
            foreach($records as $record)
2421
            {
2422
                $items[ $record->uuid ] = $record->name;
2423
            }
2424
 
2425
            return new JsonModel([
2426
                'success' => true,
2427
                'data' => $items
2428
            ]);
2429
 
2430
 
2431
        }
2432
        return new JsonModel([
2433
            'success' => false,
2434
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2435
        ]);
2436
    }
2437
 
2438
    public function timeZonesAction() {
2439
 
2440
        $request = $this->getRequest();
2441
 
2442
 
2443
 
2444
        if ($request->isGet()) {
2445
            $items = [];
2446
 
2447
 
2448
            $records = Functions::getAllTimeZones();
2449
            foreach($records as $record)
2450
            {
2451
                $items[ $record ] = $record;
2452
            }
2453
 
2454
            return new JsonModel([
2455
                'success' => true,
2456
                'data' => $items
2457
            ]);
2458
 
2459
 
2460
        }
2461
        return new JsonModel([
2462
            'success' => false,
2463
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2464
        ]);
2465
 
2466
 
2467
 
2468
 
2469
 
2470
 
2471
    }
2472
 
117 efrain 2473
 
2474
    public function groupTypesAction()
2475
    {
2476
        $request = $this->getRequest();
2477
 
2478
 
2479
 
2480
        if ($request->isGet()) {
2481
            $items = [];
2482
 
2483
            $mapper = GroupTypeMapper::getInstance($this->adapter);
2484
            $records = $mapper->fetchAllActive();
2485
            foreach($records as $record)
2486
            {
2487
                $items[ $record->uuid ] = $record->name;
2488
            }
2489
 
2490
            return new JsonModel([
2491
                'success' => true,
2492
                'data' => $items
2493
            ]);
2494
 
2495
 
2496
        }
2497
        return new JsonModel([
2498
            'success' => false,
2499
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2500
        ]);
2501
    }
2502
 
2503
 
192 efrain 2504
    public function abuseReportAction()
2505
    {
195 efrain 2506
 
2507
 
2508
 
192 efrain 2509
        $request = $this->getRequest();
2510
 
2511
        if ($request->isPost()) {
2512
 
2513
            $dataPost = $request->getPost()->toArray();
2514
 
2515
            $form = new CreateForm();
2516
            $form->setData($dataPost);
2517
 
195 efrain 2518
 
2519
 
192 efrain 2520
            if(!$form->isValid()) {
2521
                $messages = [];
195 efrain 2522
 
192 efrain 2523
 
2524
 
2525
                $form_messages = (array) $form->getMessages();
2526
                foreach($form_messages  as $fieldname => $field_messages)
2527
                {
2528
 
2529
                    $messages[$fieldname] = array_values($field_messages);
2530
                }
2531
 
195 efrain 2532
 
2533
 
192 efrain 2534
                return new JsonModel([
2535
                    'success'   => false,
2536
                    'data'   => $messages
2537
                ]);
2538
 
2539
            }
195 efrain 2540
 
192 efrain 2541
 
2542
            $dataPost = (array) $form->getData();
1 efrain 2543
 
192 efrain 2544
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
2545
            $network =  $currentNetworkPlugin->getNetwork();
2546
 
2547
 
2548
            $currentUserPlugin = $this->plugin('currentUserPlugin');
2549
            $currentUser = $currentUserPlugin->getUser();
2550
 
2551
            $id     = $this->params()->fromRoute('id');
2552
            $type   = $this->params()->fromRoute('type');
2553
 
2554
            $blockUser = $dataPost['block_user'] == 'y';
2555
 
2556
            $abuseReport = new AbuseReport();
2557
            $abuseReport->network_id = $network->id;
2558
            $abuseReport->user_reporting_id = $currentUser->id;
2559
            $abuseReport->status = AbuseReport::STATUS_PENDING;
2560
            $abuseReport->comment = $dataPost['comment'];
2561
            $abuseReport->reason = $dataPost['reason'];
2562
 
195 efrain 2563
 
192 efrain 2564
 
2565
            switch($type)
2566
            {
2567
                case 'feed' :
195 efrain 2568
                    $feedMapper = FeedMapper::getInstance($this->adapter);
192 efrain 2569
                    $feed = $feedMapper->fetchOneByUuid($id);
2570
                    if(!$feed || $feed->status != Feed::STATUS_PUBLISHED || $feed->network_id != $network->id) {
2571
 
2572
                        return new JsonModel([
2573
                            'success' => false,
2574
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2575
                        ]);
2576
                    }
2577
 
2578
                    if($feed->user_id == 1) {
2579
                        return new JsonModel([
2580
                            'success' => false,
2581
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2582
                        ]);
2583
                    }
2584
 
2585
                    if($feed->user_id == $currentUser->id) {
2586
                        return new JsonModel([
2587
                            'success' => false,
2588
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_IS_YOURSELF'
2589
                        ]);
2590
                    }
2591
 
2592
                    $abuseReport->related_id        =  $feed->id;
2593
                    $abuseReport->user_reported_id  = $feed->user_id;
2594
                    $abuseReport->type              = AbuseReport::TYPE_FEED;
2595
 
2596
 
2597
 
2598
                    break;
2599
 
2600
                case 'post' :
2601
                    $postMapper = PostMapper::getInstance($this->adapter);
2602
                    $post = $postMapper->fetchOneByUuid($id);
2603
                    if(!$post || $post->status != Post::STATUS_ACTIVE || $post->network_id != $network->id) {
2604
 
2605
                        return new JsonModel([
2606
                            'success' => false,
2607
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2608
                        ]);
2609
                    }
2610
 
2611
                    if($post->user_id == 1) {
2612
                        return new JsonModel([
2613
                            'success' => false,
2614
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2615
                        ]);
2616
                    }
2617
 
2618
 
2619
                    if($post->user_id == $currentUser->id) {
2620
                        return new JsonModel([
2621
                            'success' => false,
2622
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_IS_YOURSELF'
2623
                        ]);
2624
                    }
2625
 
2626
 
2627
                    $abuseReport->related_id        = $post->id;
2628
                    $abuseReport->user_reported_id  = $post->user_id;
2629
                    $abuseReport->type              = AbuseReport::TYPE_POST;
2630
 
2631
                    break;
2632
 
2633
 
2634
                case 'comment' :
2635
                    $commentMapper = CommentMapper::getInstance($this->adapter);
2636
                    $comment = $commentMapper->fetchOneByUuid($id);
2637
                    if(!$comment || $comment->network_id != $network->id || $comment->status != Comment::STATUS_PUBLISHED) {
2638
 
2639
                        return new JsonModel([
2640
                            'success' => false,
2641
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2642
                        ]);
2643
                    }
2644
 
2645
                    if($comment->user_id == 1) {
2646
                        return new JsonModel([
2647
                            'success' => false,
2648
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2649
                        ]);
2650
                    }
2651
 
2652
                    if($comment->user_id == $currentUser->id) {
2653
                        return new JsonModel([
2654
                            'success' => false,
2655
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_IS_YOURSELF'
2656
                        ]);
2657
                    }
2658
 
2659
                    $abuseReport->related_id        = $comment->id;
2660
                    $abuseReport->user_reported_id  = $comment->user_id;
2661
                    $abuseReport->type              = AbuseReport::TYPE_COMMENT;
2662
 
2663
                    break;
2664
 
269 efrain 2665
                    /*
192 efrain 2666
                case 'message' :
2667
                    $messageMapper = MessageMapper::getInstance($this->adapter);
2668
                    $message = $messageMapper->fetchOneByUuid($id);
2669
                    if(!$message || $message->receiver_id != $currentUser->id || $message->receiver_status != Message::STATUS_NORMAL) {
2670
 
2671
                        return new JsonModel([
2672
                            'success' => false,
2673
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2674
                        ]);
2675
                    }
2676
 
2677
                    if($message->sender_id == 1) {
2678
                        return new JsonModel([
2679
                            'success' => false,
2680
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2681
                        ]);
2682
                    }
2683
 
2684
                    $abuseReport->related_id        = $message->id;
2685
                    $abuseReport->user_reported_id  = $message->sender_id;
2686
                    $abuseReport->type              = AbuseReport::TYPE_INMAIL_MESSAGE;
2687
 
2688
                    break;
269 efrain 2689
 
192 efrain 2690
                case 'chat-message' :
2691
                    $messageMapper = ChatMessageMapper::getInstance($this->adapter);
2692
                    $message = $messageMapper->fetchOneByUuid($id);
2693
                    if(!$message || $message->to_id != $currentUser->id || $message->status != ChatMessage::STATUS_PUBLISHED) {
2694
 
2695
                        return new JsonModel([
2696
                            'success' => false,
2697
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2698
                        ]);
2699
                    }
2700
 
2701
                    if($message->from_id == 1) {
2702
                        return new JsonModel([
2703
                            'success' => false,
2704
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2705
                        ]);
2706
                    }
2707
 
2708
                    $abuseReport->related_id        = $message->id;
2709
                    $abuseReport->user_reported_id  = $message->from_id;
2710
                    $abuseReport->type              = AbuseReport::TYPE_CHAT_USER_MESSAGE;
2711
 
2712
                    break;
269 efrain 2713
 
192 efrain 2714
                case 'chat-group-message' :
2715
                    $messageMapper = ChatGroupMessageMapper::getInstance($this->adapter);
2716
                    $message = $messageMapper->fetchOne($id);
2717
                    if(!$message || $message->status != ChatMessage::STATUS_PUBLISHED) {
2718
 
2719
                        return new JsonModel([
2720
                            'success' => false,
2721
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2722
                        ]);
2723
                    }
2724
 
2725
                    $userMessageMapper = ChatGroupUserMessageMapper::getInstance($this->adapter);
2726
                    $userMessage = $userMessageMapper->fetchOneByIdMessageIdAndReceiverId($message->id, $currentUser->id);
2727
                    if(!$userMessage) {
2728
 
2729
                        return new JsonModel([
2730
                            'success' => false,
2731
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2732
                        ]);
2733
                    }
2734
 
2735
 
2736
                    if($message->sender_id == 1) {
2737
                        return new JsonModel([
2738
                            'success' => false,
2739
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2740
                        ]);
2741
                    }
2742
 
2743
                    $abuseReport->related_id        = $message->id;
2744
                    $abuseReport->user_reported_id  = $message->sender_id;
2745
                    $abuseReport->type              = AbuseReport::TYPE_CHAT_USER_MESSAGE;
2746
 
269 efrain 2747
                    break; */
192 efrain 2748
            }
195 efrain 2749
 
2750
 
192 efrain 2751
 
2752
            $abuseReportMapper = AbuseReportMapper::getInstance($this->adapter);
2753
            if($abuseReportMapper->insert($abuseReport)) {
2754
 
2755
                if($blockUser) {
2756
 
2757
                    $userBlockedMapper = UserBlockedMapper::getInstance($this->adapter);
2758
                    $userBlocked = $userBlockedMapper->fetchOneByUserIdAndBlockedId($abuseReport->user_reporting_id, $abuseReport->user_reporting_id);
2759
                    if($userBlocked) {
2760
 
2761
 
2762
                        return new JsonModel([
2763
                            'success' => true,
2764
                            'data' => [
2765
                                'message' => 'LABEL_ABUSE_REPORT_SENT_WITH_BLOCK_USER',
2766
                                'block' => true
2767
                            ]
2768
                        ]);
2769
 
2770
                    } else {
2771
 
2772
                        $userBlocked = new UserBlocked();
2773
                        $userBlocked->user_id = $abuseReport->user_reporting_id;
2774
                        $userBlocked->blocked_id = $abuseReport->user_reported_id;
2775
 
2776
                        if($userBlockedMapper->insert($userBlocked)) {
2777
                            return new JsonModel([
2778
                                'success' => true,
2779
                                'data' => [
2780
                                    'message' => 'LABEL_ABUSE_REPORT_SENT_WITH_BLOCK_USER',
2781
                                    'block' => true
2782
                                ]
2783
                            ]);
2784
 
2785
                        } else {
2786
                            return new JsonModel([
2787
                                'success' => true,
2788
                                'data' => [
2789
                                    'message' => 'LABEL_ABUSE_REPORT_SENT_WITHOUT_BLOCK_USER',
2790
                                    'block' => false
2791
                                ]
2792
                            ]);
2793
 
2794
 
2795
                        }
2796
                    }
2797
 
2798
 
2799
                } else {
2800
                    return new JsonModel([
2801
                        'success' => true,
2802
                        'data' => [
2803
                            'message' => 'LABEL_ABUSE_REPORT_SENT_WITHOUT_BLOCK_USER',
2804
                            'block' => false
2805
                        ]
2806
                    ]);
2807
                }
2808
 
2809
 
2810
            } else {
2811
                return new JsonModel([
2812
                    'success' => false,
2813
                    'data' => 'ERROR_ABUSE_REPORT_NOT_SENT'
2814
                ]);
2815
            }
2816
 
2817
 
2818
 
2819
 
2820
 
2821
 
2822
 
2823
 
2824
        }
2825
        return new JsonModel([
2826
            'success' => false,
2827
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2828
        ]);
2829
 
2830
 
2831
    }
2832
 
2833
 
2834
 
1 efrain 2835
}