Proyectos de Subversion LeadersLinked - Services

Rev

Rev 835 | | Comparar con el anterior | Ultima modificación | Ver Log |

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