Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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