Proyectos de Subversion LeadersLinked - Services

Rev

Rev 707 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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