Proyectos de Subversion LeadersLinked - Services

Rev

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

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