Proyectos de Subversion LeadersLinked - Services

Rev

Rev 786 | | 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');
2012
            if($currentUserPlugin->hasIdentity()) {
2013
                $currentUser = $currentUserPlugin->getUser();
157 efrain 2014
 
1 efrain 2015
 
2016
 
2017
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
2018
 
2019
                $link_admin         = $currentUser->usertype_id == UserType::ADMIN ? 1 : 0;
2020
                $link_impersonate   = $currentUser->is_super_user == User::IS_SUPER_USER_YES ? 1 : 0;
2021
                if($link_impersonate) {
2022
                    $url_impersonate = $this->url()->fromRoute('signin/impersonate');
2023
                } else {
2024
                    $url_impersonate = '';
2025
                }
2026
 
2027
                $fullname = trim($currentUser->first_name . ' ' . $currentUser->last_name);
2028
 
2029
                $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
2030
                $visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
2031
 
2032
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
2033
                $connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
2034
 
2035
 
2036
                if($currentUser->location_id) {
2037
                    $locationMapper = LocationMapper::getInstance($this->adapter);
2038
                    $location = $locationMapper->fetchOne($currentUser->location_id);
2039
 
2040
                    $country = $location->country;
2041
                } else {
2042
                    $country = '';
2043
                }
2044
 
2045
 
2046
 
2047
 
2048
                if($currentUser->usertype_id == UserType::ADMIN) {
2049
                    $url_admin = $this->url()->fromRoute( 'backend/signin-admin');
2050
                } else {
2051
                    $url_admin = '';
2052
                }
2053
 
2054
 
2055
 
2056
                $link_company = '';
2057
                if($network->default != Network::DEFAULT_YES) {
2058
                    $companyMapper = CompanyMapper::getInstance($this->adapter);
2059
                    $company = $companyMapper->fetchDefaultForNetworkByNetworkId($network->id);
2060
                    if($company) {
2061
                        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
2062
                        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
2063
                        if($companyUser) {
2064
                            if($companyUser && $companyUser->status == CompanyUser::STATUS_ACCEPTED && $companyUser->backend == CompanyUser::BACKEND_YES ) {
2065
                                $link_company = ['route' => 'backend/signin-company', 'id' => $company->uuid ];
2066
                            }
2067
                        }
2068
                    }
2069
                }
2070
 
167 efrain 2071
 
2072
 
2073
 
2074
 
1 efrain 2075
                if ($acl->isAllowed($currentUser->usertype_id,  'knowledge-area')) {
302 www 2076
                    $route_knowledge_area = $this->url()->fromRoute('knowledge-area', [], ['force_canonical' => true]);
1 efrain 2077
                    $link_knowledge_area = 1;
2078
                } else {
2079
 
2080
                    $route_knowledge_area = '';
2081
                    $link_knowledge_area = 0;
2082
                }
2083
 
2084
                if ($acl->isAllowed($currentUser->usertype_id,  'my-coach')) {
302 www 2085
                    $route_my_coach = $this->url()->fromRoute('my-coach', [], ['force_canonical' => true]);
1 efrain 2086
                    $link_my_coach = 1;
2087
                } else {
2088
 
2089
                    $route_my_coach = '';
2090
                    $link_my_coach = 0;
2091
                }
2092
 
2093
                if($network->default == Network::DEFAULT_YES) {
2094
                    if($network->relationship_user_mode == Network::RELATIONSHIP_USER_MODE_USER_2_USER)  {
2095
                        $pages = getAclMenuDefaultNetworkConnectionUser2User();
2096
                    } else {
2097
                        $pages = getAclMenuDefaultNetworkConnectionAll2All();
2098
                    }
2099
                } else {
2100
                    if($network->relationship_user_mode == Network::RELATIONSHIP_USER_MODE_USER_2_USER)  {
2101
 
2102
                        $pages = getAclMenuNonDefaulNetworkConnectionUser2User();
2103
 
2104
                    } else {
2105
                        $pages = getAclMenuNonDefaultNetworkConnectionAll2All();
2106
                    }
2107
                }
2108
 
2109
 
2110
                $menu = [];
2111
                foreach ($pages as $page) {
2112
 
2113
                    if (!$page || empty($page['route']) || !$acl->isAllowed($currentUser->usertype_id, $page['route'])) {
2114
                        continue;
2115
                    }
2116
 
269 efrain 2117
                    $childs = [];
2118
 
1 efrain 2119
                    $ajax = false;
2120
                    if ($page['route'] == 'company' && $network->default == Network::DEFAULT_NO) {
2121
 
269 efrain 2122
 
2123
 
1 efrain 2124
                        if ($link_company) {
269 efrain 2125
                            $ajax = true;
157 efrain 2126
                            $page['route'] = $this->url()->fromRoute($link_company['route'], ['id' => $link_company['id']]);
269 efrain 2127
 
2128
                            $childs = [
2129
                                'label' => 'Acceder',
2130
                                'href' => $page['route'],
2131
                                'ajax' => $ajax,
2132
                                'childs' => []
2133
                            ];
1 efrain 2134
                        } else {
2135
                            continue;
2136
                        }
2137
                    }
2138
 
2139
                    $option = [
2140
                        'label' => $page['label'],
2141
                        'href' => $page['route'],
2142
                        'img' => empty($page['class']) ? '' : $page['class'],
2143
                        'ajax' => $ajax ? 1 : 0,
269 efrain 2144
                        'childs' => $childs,
1 efrain 2145
                    ];
2146
 
269 efrain 2147
                    if ($page['route'] == 'company' && $network->default == Network::DEFAULT_NO) {
2148
                        if ($link_company) {
2149
                            array_push($option['childs'], );
2150
 
2151
 
2152
                        }
2153
                    }
2154
 
1 efrain 2155
                    $childs = empty($page['pages']) ? [] : $page['pages'];
2156
                    if ($childs) {
2157
                        foreach ($childs as $child) {
2158
                            if (!$acl->isAllowed($currentUser->usertype_id,  $child['route'])) {
2159
                                continue;
2160
                            }
2161
 
2162
                            $childs_level2 = [];
2163
 
2164
                            $childsLevel2 = empty($child['pages']) ? [] : $child['pages'];
2165
 
2166
                            if ($childsLevel2) {
2167
                                foreach ($childsLevel2 as $childLevel2) {
2168
                                    if (!$acl->isAllowed($currentUser->usertype_id,  $childLevel2['route'])) {
2169
                                        continue;
2170
                                    }
2171
 
2172
                                    array_push($childs_level2, [
2173
                                        'label' => $childLevel2['label'],
2174
                                        'href' => $childLevel2['route'],
2175
 
2176
                                    ]);
2177
                                }
2178
                            }
2179
 
2180
                            array_push($option['childs'], [
2181
                                'label' => $child['label'],
2182
                                'href' => $child['route'],
2183
                                'childs' => $childs_level2,
2184
                            ]);
2185
                        }
2186
                    }
2187
 
2188
                    array_push($menu, $option);
2189
                }
2190
 
269 efrain 2191
 
333 www 2192
                $storage = Storage::getInstance($this->config, $this->adapter);
283 www 2193
 
1 efrain 2194
 
269 efrain 2195
                $image = $storage->getUserImage($currentUser);
1 efrain 2196
                $isChatPage = $this->getEvent()->getViewModel()->getVariable('is_chat');
2197
                $routeCheckSession = $this->url()->fromRoute('check-session');
203 efrain 2198
                $routeAbuseReport = $this->url()->fromRoute('abuse-report');
1 efrain 2199
 
2200
 
269 efrain 2201
                if($network->navbar) {
281 efrain 2202
 
2203
 
2204
 
333 www 2205
                    $storage = Storage::getInstance($this->config, $this->adapter);
283 www 2206
                    $path = $storage->getPathNetwork();
281 efrain 2207
 
283 www 2208
                    $navbar = $storage->getGenericImage($path, $network->uuid, $network->navbar);
281 efrain 2209
 
2210
 
283 www 2211
 
269 efrain 2212
                } else {
2213
                    $navbar = '';
2214
                }
1 efrain 2215
 
2216
                return new JsonModel([
2217
                    'menu'                  => $menu,
2218
                    'isChatPage'            => $isChatPage == 1,
2219
                    'routeCheckSession'     => $routeCheckSession,
203 efrain 2220
                    'routeAbuseReport'      => $routeAbuseReport,
1 efrain 2221
                    'linkAdmin'             => $link_admin == 1,
2222
                    'urlAdmin'              => $url_admin,
2223
                    'linkImpersonate'       => $link_impersonate ==1 ,
2224
                    'urlImpersonate'        => $url_impersonate,
2225
                    'image'                 => $image,
2226
                    'fullName'              => $fullname,
2227
                    'country'               => $country,
2228
                    'visits'                => $visits,
2229
                    'connections'           => $connections,
269 efrain 2230
                    'logoForNavbar'         => $navbar,
1 efrain 2231
                    'defaultNetwork'        => $network->default,
2232
               ]);
2233
 
2234
 
2235
 
2236
            }
2237
 
2238
 
2239
            return new JsonModel([
2240
                'menu'                  => [],
2241
                'isChatPage'            => false,
2242
                'routeCheckSession'     => '',
2243
                'linkAdmin'             => false,
2244
                'urlAdmin'              => '',
2245
                'linkImpersonate'       => false,
2246
                'urlImpersonate'        => '',
2247
                'image'                 => '',
2248
                'fullName'              => '',
2249
                'country'               => 0,
2250
                'visits'                => 0,
2251
                'connections'           => 0,
2252
                'logoForNavbar'         => 'https://' . $network->main_hostname . '/storage-network/type/navbar',
2253
                'defaultNetwork'        => $network->default,
2254
                'linkKnowledgeArea'     => false,
2255
                'routeKnowledgeArea'    => '',
2256
                'linkMyCoach'           => false,
2257
                'routeMyCoach'          => '',
2258
            ]);
2259
 
2260
        } else {
2261
 
2262
            return new JsonModel([
2263
                'success' => false,
2264
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2265
            ]);
2266
        }
2267
 
2268
 
2269
        return new JsonModel([
2270
            'success' => false,
2271
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2272
        ]);
2273
    }
2274
 
2275
    public function companySizesAction()
2276
    {
2277
        $request = $this->getRequest();
2278
 
2279
 
2280
 
2281
        if ($request->isGet()) {
2282
            $items = [];
2283
 
2284
            $mapper = CompanySizeMapper::getInstance($this->adapter);
2285
            $records = $mapper->fetchAllActive();
2286
            foreach($records as $record)
2287
            {
2288
                 $items[ $record->uuid ] = $record->name;
2289
            }
2290
 
2291
            return new JsonModel([
2292
                'success' => true,
2293
                'data' => $items
2294
            ]);
2295
 
2296
 
2297
        }
2298
        return new JsonModel([
2299
            'success' => false,
2300
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2301
        ]);
2302
    }
2303
 
2304
    public function degreesAction()
2305
    {
2306
        $request = $this->getRequest();
2307
 
2308
 
2309
 
2310
        if ($request->isGet()) {
2311
            $items = [];
2312
 
2313
            $mapper = DegreeMapper::getInstance($this->adapter);
2314
            $records = $mapper->fetchAllActive();
2315
            foreach($records as $record)
2316
            {
2317
                $items[ $record->uuid ] = $record->name;
2318
            }
2319
 
2320
            return new JsonModel([
2321
                'success' => true,
2322
                'data' => $items
2323
            ]);
2324
 
2325
 
2326
        }
2327
        return new JsonModel([
2328
            'success' => false,
2329
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2330
        ]);
2331
    }
2332
 
2333
    public function languagesAction()
2334
    {
2335
        $request = $this->getRequest();
2336
 
2337
 
2338
 
2339
        if ($request->isGet()) {
2340
            $items = [];
2341
 
2342
            $mapper = LanguageMapper::getInstance($this->adapter);
2343
            $records = $mapper->fetchAllActive();
2344
            foreach($records as $record)
2345
            {
2346
                $items[ $record->id ] = $record->name;
2347
            }
2348
 
2349
            return new JsonModel([
2350
                'success' => true,
2351
                'data' => $items
2352
            ]);
2353
 
2354
 
2355
        }
2356
        return new JsonModel([
2357
            'success' => false,
2358
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2359
        ]);
2360
    }
2361
 
2362
    public function skillsAction()
2363
    {
2364
        $request = $this->getRequest();
2365
 
2366
 
2367
 
2368
        if ($request->isGet()) {
2369
            $items = [];
2370
 
2371
            $mapper = SkillMapper::getInstance($this->adapter);
2372
            $records = $mapper->fetchAllActive();
2373
            foreach($records as $record)
2374
            {
2375
                $items[ $record->uuid ] = $record->name;
2376
            }
2377
 
2378
            return new JsonModel([
2379
                'success' => true,
2380
                'data' => $items
2381
            ]);
2382
 
2383
 
2384
        }
2385
        return new JsonModel([
2386
            'success' => false,
2387
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2388
        ]);
2389
    }
2390
 
2391
 
2392
    public function aptitudesAction()
2393
    {
2394
        $request = $this->getRequest();
2395
 
2396
 
2397
 
2398
        if ($request->isGet()) {
2399
            $items = [];
2400
 
2401
            $mapper = AptitudeMapper::getInstance($this->adapter);
2402
            $records = $mapper->fetchAllActive();
2403
            foreach($records as $record)
2404
            {
2405
                $items[ $record->uuid ] = $record->name;
2406
            }
2407
 
2408
            return new JsonModel([
2409
                'success' => true,
2410
                'data' => $items
2411
            ]);
2412
 
2413
 
2414
        }
2415
        return new JsonModel([
2416
            'success' => false,
2417
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2418
        ]);
2419
    }
2420
 
2421
    public function hobbiesAction()
2422
    {
2423
        $request = $this->getRequest();
2424
 
2425
 
2426
 
2427
        if ($request->isGet()) {
2428
            $items = [];
2429
 
2430
            $mapper = HobbyAndInterestMapper::getInstance($this->adapter);
2431
            $records = $mapper->fetchAllActive();
2432
            foreach($records as $record)
2433
            {
2434
                $items[ $record->uuid ] = $record->name;
2435
            }
2436
 
2437
            return new JsonModel([
2438
                'success' => true,
2439
                'data' => $items
2440
            ]);
2441
 
2442
 
2443
        }
2444
        return new JsonModel([
2445
            'success' => false,
2446
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2447
        ]);
2448
    }
2449
 
2450
    public function industriesAction()
2451
    {
2452
        $request = $this->getRequest();
2453
 
2454
 
2455
 
2456
        if ($request->isGet()) {
2457
            $items = [];
2458
 
2459
            $mapper = IndustryMapper::getInstance($this->adapter);
2460
            $records = $mapper->fetchAllActive();
2461
            foreach($records as $record)
2462
            {
2463
                $items[ $record->uuid ] = $record->name;
2464
            }
2465
 
2466
            return new JsonModel([
2467
                'success' => true,
2468
                'data' => $items
2469
            ]);
2470
 
2471
 
2472
        }
2473
        return new JsonModel([
2474
            'success' => false,
2475
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2476
        ]);
2477
    }
2478
 
2479
    public function timeZonesAction() {
2480
 
2481
        $request = $this->getRequest();
2482
 
2483
 
2484
 
2485
        if ($request->isGet()) {
2486
            $items = [];
2487
 
2488
 
2489
            $records = Functions::getAllTimeZones();
2490
            foreach($records as $record)
2491
            {
2492
                $items[ $record ] = $record;
2493
            }
2494
 
2495
            return new JsonModel([
2496
                'success' => true,
2497
                'data' => $items
2498
            ]);
2499
 
2500
 
2501
        }
2502
        return new JsonModel([
2503
            'success' => false,
2504
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2505
        ]);
2506
 
2507
 
2508
 
2509
 
2510
 
2511
 
2512
    }
2513
 
117 efrain 2514
 
2515
    public function groupTypesAction()
2516
    {
2517
        $request = $this->getRequest();
2518
 
2519
 
2520
 
2521
        if ($request->isGet()) {
2522
            $items = [];
2523
 
2524
            $mapper = GroupTypeMapper::getInstance($this->adapter);
2525
            $records = $mapper->fetchAllActive();
2526
            foreach($records as $record)
2527
            {
2528
                $items[ $record->uuid ] = $record->name;
2529
            }
2530
 
2531
            return new JsonModel([
2532
                'success' => true,
2533
                'data' => $items
2534
            ]);
2535
 
2536
 
2537
        }
2538
        return new JsonModel([
2539
            'success' => false,
2540
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2541
        ]);
2542
    }
2543
 
2544
 
192 efrain 2545
    public function abuseReportAction()
2546
    {
195 efrain 2547
 
2548
 
2549
 
192 efrain 2550
        $request = $this->getRequest();
2551
 
2552
        if ($request->isPost()) {
2553
 
2554
            $dataPost = $request->getPost()->toArray();
2555
 
2556
            $form = new CreateForm();
2557
            $form->setData($dataPost);
2558
 
195 efrain 2559
 
2560
 
192 efrain 2561
            if(!$form->isValid()) {
2562
                $messages = [];
195 efrain 2563
 
192 efrain 2564
 
2565
 
2566
                $form_messages = (array) $form->getMessages();
2567
                foreach($form_messages  as $fieldname => $field_messages)
2568
                {
2569
 
2570
                    $messages[$fieldname] = array_values($field_messages);
2571
                }
2572
 
195 efrain 2573
 
2574
 
192 efrain 2575
                return new JsonModel([
2576
                    'success'   => false,
2577
                    'data'   => $messages
2578
                ]);
2579
 
2580
            }
195 efrain 2581
 
192 efrain 2582
 
2583
            $dataPost = (array) $form->getData();
1 efrain 2584
 
192 efrain 2585
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
2586
            $network =  $currentNetworkPlugin->getNetwork();
2587
 
2588
 
2589
            $currentUserPlugin = $this->plugin('currentUserPlugin');
2590
            $currentUser = $currentUserPlugin->getUser();
2591
 
2592
            $id     = $this->params()->fromRoute('id');
2593
            $type   = $this->params()->fromRoute('type');
2594
 
2595
            $blockUser = $dataPost['block_user'] == 'y';
2596
 
2597
            $abuseReport = new AbuseReport();
2598
            $abuseReport->network_id = $network->id;
2599
            $abuseReport->user_reporting_id = $currentUser->id;
2600
            $abuseReport->status = AbuseReport::STATUS_PENDING;
2601
            $abuseReport->comment = $dataPost['comment'];
2602
            $abuseReport->reason = $dataPost['reason'];
2603
 
195 efrain 2604
 
192 efrain 2605
 
2606
            switch($type)
2607
            {
2608
                case 'feed' :
195 efrain 2609
                    $feedMapper = FeedMapper::getInstance($this->adapter);
192 efrain 2610
                    $feed = $feedMapper->fetchOneByUuid($id);
2611
                    if(!$feed || $feed->status != Feed::STATUS_PUBLISHED || $feed->network_id != $network->id) {
2612
 
2613
                        return new JsonModel([
2614
                            'success' => false,
2615
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2616
                        ]);
2617
                    }
2618
 
2619
                    if($feed->user_id == 1) {
2620
                        return new JsonModel([
2621
                            'success' => false,
2622
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2623
                        ]);
2624
                    }
2625
 
2626
                    if($feed->user_id == $currentUser->id) {
2627
                        return new JsonModel([
2628
                            'success' => false,
2629
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_IS_YOURSELF'
2630
                        ]);
2631
                    }
2632
 
2633
                    $abuseReport->related_id        =  $feed->id;
2634
                    $abuseReport->user_reported_id  = $feed->user_id;
2635
                    $abuseReport->type              = AbuseReport::TYPE_FEED;
2636
 
2637
 
2638
 
2639
                    break;
2640
 
2641
                case 'post' :
2642
                    $postMapper = PostMapper::getInstance($this->adapter);
2643
                    $post = $postMapper->fetchOneByUuid($id);
2644
                    if(!$post || $post->status != Post::STATUS_ACTIVE || $post->network_id != $network->id) {
2645
 
2646
                        return new JsonModel([
2647
                            'success' => false,
2648
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2649
                        ]);
2650
                    }
2651
 
2652
                    if($post->user_id == 1) {
2653
                        return new JsonModel([
2654
                            'success' => false,
2655
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2656
                        ]);
2657
                    }
2658
 
2659
 
2660
                    if($post->user_id == $currentUser->id) {
2661
                        return new JsonModel([
2662
                            'success' => false,
2663
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_IS_YOURSELF'
2664
                        ]);
2665
                    }
2666
 
2667
 
2668
                    $abuseReport->related_id        = $post->id;
2669
                    $abuseReport->user_reported_id  = $post->user_id;
2670
                    $abuseReport->type              = AbuseReport::TYPE_POST;
2671
 
2672
                    break;
2673
 
2674
 
2675
                case 'comment' :
2676
                    $commentMapper = CommentMapper::getInstance($this->adapter);
2677
                    $comment = $commentMapper->fetchOneByUuid($id);
2678
                    if(!$comment || $comment->network_id != $network->id || $comment->status != Comment::STATUS_PUBLISHED) {
2679
 
2680
                        return new JsonModel([
2681
                            'success' => false,
2682
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2683
                        ]);
2684
                    }
2685
 
2686
                    if($comment->user_id == 1) {
2687
                        return new JsonModel([
2688
                            'success' => false,
2689
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2690
                        ]);
2691
                    }
2692
 
2693
                    if($comment->user_id == $currentUser->id) {
2694
                        return new JsonModel([
2695
                            'success' => false,
2696
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_IS_YOURSELF'
2697
                        ]);
2698
                    }
2699
 
2700
                    $abuseReport->related_id        = $comment->id;
2701
                    $abuseReport->user_reported_id  = $comment->user_id;
2702
                    $abuseReport->type              = AbuseReport::TYPE_COMMENT;
2703
 
2704
                    break;
2705
 
709 stevensc 2706
 
192 efrain 2707
                case 'message' :
2708
                    $messageMapper = MessageMapper::getInstance($this->adapter);
2709
                    $message = $messageMapper->fetchOneByUuid($id);
2710
                    if(!$message || $message->receiver_id != $currentUser->id || $message->receiver_status != Message::STATUS_NORMAL) {
2711
 
2712
                        return new JsonModel([
2713
                            'success' => false,
2714
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2715
                        ]);
2716
                    }
2717
 
2718
                    if($message->sender_id == 1) {
2719
                        return new JsonModel([
2720
                            'success' => false,
2721
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2722
                        ]);
2723
                    }
2724
 
2725
                    $abuseReport->related_id        = $message->id;
2726
                    $abuseReport->user_reported_id  = $message->sender_id;
2727
                    $abuseReport->type              = AbuseReport::TYPE_INMAIL_MESSAGE;
2728
 
2729
                    break;
269 efrain 2730
 
192 efrain 2731
                case 'chat-message' :
2732
                    $messageMapper = ChatMessageMapper::getInstance($this->adapter);
2733
                    $message = $messageMapper->fetchOneByUuid($id);
2734
                    if(!$message || $message->to_id != $currentUser->id || $message->status != ChatMessage::STATUS_PUBLISHED) {
2735
 
2736
                        return new JsonModel([
2737
                            'success' => false,
2738
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2739
                        ]);
2740
                    }
2741
 
2742
                    if($message->from_id == 1) {
2743
                        return new JsonModel([
2744
                            'success' => false,
2745
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2746
                        ]);
2747
                    }
2748
 
2749
                    $abuseReport->related_id        = $message->id;
2750
                    $abuseReport->user_reported_id  = $message->from_id;
2751
                    $abuseReport->type              = AbuseReport::TYPE_CHAT_USER_MESSAGE;
2752
 
2753
                    break;
269 efrain 2754
 
192 efrain 2755
                case 'chat-group-message' :
2756
                    $messageMapper = ChatGroupMessageMapper::getInstance($this->adapter);
2757
                    $message = $messageMapper->fetchOne($id);
2758
                    if(!$message || $message->status != ChatMessage::STATUS_PUBLISHED) {
2759
 
2760
                        return new JsonModel([
2761
                            'success' => false,
2762
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2763
                        ]);
2764
                    }
2765
 
2766
                    $userMessageMapper = ChatGroupUserMessageMapper::getInstance($this->adapter);
2767
                    $userMessage = $userMessageMapper->fetchOneByIdMessageIdAndReceiverId($message->id, $currentUser->id);
2768
                    if(!$userMessage) {
2769
 
2770
                        return new JsonModel([
2771
                            'success' => false,
2772
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_NOT_AVAILABLE'
2773
                        ]);
2774
                    }
2775
 
2776
 
2777
                    if($message->sender_id == 1) {
2778
                        return new JsonModel([
2779
                            'success' => false,
2780
                            'data' => 'ERROR_ABUSE_REPORT_CONTENT_OWNER_SYSADMIN'
2781
                        ]);
2782
                    }
2783
 
2784
                    $abuseReport->related_id        = $message->id;
2785
                    $abuseReport->user_reported_id  = $message->sender_id;
2786
                    $abuseReport->type              = AbuseReport::TYPE_CHAT_USER_MESSAGE;
2787
 
709 stevensc 2788
                    break;
192 efrain 2789
            }
195 efrain 2790
 
2791
 
192 efrain 2792
 
2793
            $abuseReportMapper = AbuseReportMapper::getInstance($this->adapter);
2794
            if($abuseReportMapper->insert($abuseReport)) {
2795
 
2796
                if($blockUser) {
2797
 
2798
                    $userBlockedMapper = UserBlockedMapper::getInstance($this->adapter);
2799
                    $userBlocked = $userBlockedMapper->fetchOneByUserIdAndBlockedId($abuseReport->user_reporting_id, $abuseReport->user_reporting_id);
2800
                    if($userBlocked) {
2801
 
2802
 
2803
                        return new JsonModel([
2804
                            'success' => true,
2805
                            'data' => [
2806
                                'message' => 'LABEL_ABUSE_REPORT_SENT_WITH_BLOCK_USER',
2807
                                'block' => true
2808
                            ]
2809
                        ]);
2810
 
2811
                    } else {
2812
 
2813
                        $userBlocked = new UserBlocked();
2814
                        $userBlocked->user_id = $abuseReport->user_reporting_id;
2815
                        $userBlocked->blocked_id = $abuseReport->user_reported_id;
2816
 
2817
                        if($userBlockedMapper->insert($userBlocked)) {
2818
                            return new JsonModel([
2819
                                'success' => true,
2820
                                'data' => [
2821
                                    'message' => 'LABEL_ABUSE_REPORT_SENT_WITH_BLOCK_USER',
2822
                                    'block' => true
2823
                                ]
2824
                            ]);
2825
 
2826
                        } else {
2827
                            return new JsonModel([
2828
                                'success' => true,
2829
                                'data' => [
2830
                                    'message' => 'LABEL_ABUSE_REPORT_SENT_WITHOUT_BLOCK_USER',
2831
                                    'block' => false
2832
                                ]
2833
                            ]);
2834
 
2835
 
2836
                        }
2837
                    }
2838
 
2839
 
2840
                } else {
2841
                    return new JsonModel([
2842
                        'success' => true,
2843
                        'data' => [
2844
                            'message' => 'LABEL_ABUSE_REPORT_SENT_WITHOUT_BLOCK_USER',
2845
                            'block' => false
2846
                        ]
2847
                    ]);
2848
                }
2849
 
2850
 
2851
            } else {
2852
                return new JsonModel([
2853
                    'success' => false,
2854
                    'data' => 'ERROR_ABUSE_REPORT_NOT_SENT'
2855
                ]);
2856
            }
2857
 
2858
 
2859
 
2860
 
2861
 
2862
 
2863
 
2864
 
2865
        }
2866
        return new JsonModel([
2867
            'success' => false,
2868
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2869
        ]);
2870
 
2871
 
307 www 2872
 
2873
 
2874
 
192 efrain 2875
    }
2876
 
307 www 2877
    public function habitsAndSkillsAction()
2878
    {
2879
        $request = $this->getRequest();
2880
        $request = $this->getRequest();
2881
        if ($request->isGet()) {
321 www 2882
 
2883
            $items = [];
322 www 2884
 
321 www 2885
                $currentUserPlugin = $this->plugin('currentUserPlugin');
2886
                $currentUser = $currentUserPlugin->getUser();
2887
 
2888
 
2889
 
2890
                $company_ids = [];
2891
                $habitUserMapper = \LeadersLinked\Mapper\HabitUserMapper::getInstance($this->adapter);
2892
                $records = $habitUserMapper->fetchAllActiveByUserId($currentUser->id);
2893
                foreach($records as $record)
2894
                {
2895
                    if($record->company_id) {
2896
 
2897
                        if(!in_array($record->company_id, $company_ids)) {
2898
                            array_push($company_ids, $record->company_id);
2899
                        }
2900
                    }
2901
                }
2902
 
2903
 
2904
                if($company_ids) {
2905
 
2906
                    $habitSkillMapper = \LeadersLinked\Mapper\HabitSkillMapper::getInstance($this->adapter);
2907
                    $records = $habitSkillMapper->fetchAllTemplateByCompayIds($company_ids);
2908
                    foreach($records as $record)
2909
                    {
2910
                        array_push($items, [
2911
                            'uuid'  => $record->uuid,
2912
                            'name'  => $record->name,
2913
                            'link'  =>  $this->url()->fromRoute('helpers/habits-and-skills/get', ['id' => $record->uuid], ['force_canonical' => true]),
2914
 
2915
 
2916
 
2917
                        ]);
2918
                    }
2919
                }
322 www 2920
 
321 www 2921
 
2922
 
2923
            return new JsonModel([
2924
                'success' => true,
2925
                'data' => $items,
2926
            ]);
2927
 
2928
        }
2929
        return new JsonModel([
2930
            'success' => false,
2931
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2932
        ]);
2933
    }
2934
 
2935
    public function habitsAndSkillsGetAction()
2936
    {
2937
        $request = $this->getRequest();
2938
        $request = $this->getRequest();
2939
        if ($request->isGet()) {
2940
 
307 www 2941
            $currentUserPlugin = $this->plugin('currentUserPlugin');
2942
            $currentUser = $currentUserPlugin->getUser();
2943
 
321 www 2944
 
2945
            $id = Functions::sanitizeFilterString($this->params()->fromRoute('id'));
2946
 
2947
            $habitSkillMapper = \LeadersLinked\Mapper\HabitSkillMapper::getInstance($this->adapter);
2948
            $habitSkill = $habitSkillMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
2949
 
2950
 
2951
            if(!$habitSkill) {
2952
                return new JsonModel([
2953
                    'success' => true,
2954
                    'data' => 'ERROR_HABIT_NOT_FOUND'
2955
                ]);
2956
            }
2957
 
2958
 
2959
            $allow = false;
307 www 2960
            $habitUserMapper = \LeadersLinked\Mapper\HabitUserMapper::getInstance($this->adapter);
2961
            $records = $habitUserMapper->fetchAllActiveByUserId($currentUser->id);
2962
            foreach($records as $record)
2963
            {
321 www 2964
                if($habitSkill->company_id ==  $record->company_id) {
2965
 
2966
                    $allow = true;
2967
                    break;
307 www 2968
                }
2969
            }
2970
 
321 www 2971
            if(!$allow) {
2972
                return new JsonModel([
2973
                    'success' => true,
2974
                    'data' => 'ERROR_HABIT_YOU_DO_NOT_HAVE_ACCESS_TO_THIS'
2975
                ]);
307 www 2976
            }
321 www 2977
 
307 www 2978
            return new JsonModel([
2979
                'success' => true,
321 www 2980
                'data' =>[
2981
                    'uuid'              => $habitSkill->uuid,
2982
                    'name'              => $habitSkill->name,
2983
                    'description'       => $habitSkill->description,
2984
                    'intelligence'      => $habitSkill->intelligence,
2985
                    'monday_active'     => $habitSkill->monday_active,
2986
                    'monday_time'       => $habitSkill->monday_time,
2987
                    'tuesday_active'    => $habitSkill->tuesday_active,
2988
                    'tuesday_time'      => $habitSkill->tuesday_time,
2989
                    'wednesday_active'  => $habitSkill->wednesday_active,
2990
                    'wednesday_time'    => $habitSkill->wednesday_time,
2991
                    'thursday_active'   => $habitSkill->thursday_active,
2992
                    'thursday_time'     => $habitSkill->thursday_time,
2993
                    'friday_active'     => $habitSkill->friday_active,
2994
                    'friday_time'       => $habitSkill->friday_time,
2995
                    'saturday_active'   => $habitSkill->saturday_active,
2996
                    'saturday_time'     => $habitSkill->saturday_time,
2997
                    'sunday_active'     => $habitSkill->sunday_active,
2998
                    'sunday_time'       => $habitSkill->sunday_time,
2999
 
3000
                    'quantitative_value' => $habitSkill->quantitative_value,
3001
                    'qualitative_description' => $habitSkill->qualitative_description,
3002
                    'notification_10min_before' => $habitSkill->notification_10min_before,
3003
                    'notification_30min_before' => $habitSkill->notification_30min_before,
3004
 
3005
 
3006
                ],
307 www 3007
            ]);
3008
 
3009
        }
3010
        return new JsonModel([
3011
            'success' => false,
3012
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
3013
        ]);
3014
    }
192 efrain 3015
 
323 www 3016
 
3017
    public function myHabitsAndSkillsGetAction()
3018
    {
3019
        $request = $this->getRequest();
3020
        $request = $this->getRequest();
3021
        if ($request->isGet()) {
3022
 
3023
            $items = [];
3024
 
3025
            $currentUserPlugin = $this->plugin('currentUserPlugin');
3026
            $currentUser = $currentUserPlugin->getUser();
3027
 
3028
 
3029
            $habitSkillMapper = \LeadersLinked\Mapper\HabitSkillMapper::getInstance($this->adapter);
3030
            $records = $habitSkillMapper->fetchAllByUserId($currentUser->id);
3031
            foreach($records as $record)
3032
            {
3033
                array_push($items, [
3034
                    'uuid'  => $record->uuid,
3035
                    'name'  => $record->name,
3036
                    'link'  =>  $this->url()->fromRoute('habits/skills/registers', ['id' => $record->uuid], ['force_canonical' => true]),
3037
                ]);
3038
            }
192 efrain 3039
 
323 www 3040
 
3041
            return new JsonModel([
3042
                'success' => true,
3043
                'data' => $items,
3044
            ]);
3045
 
3046
        }
3047
        return new JsonModel([
3048
            'success' => false,
3049
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
3050
        ]);
3051
    }
3052
 
3053
 
1 efrain 3054
}