Proyectos de Subversion LeadersLinked - Services

Rev

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