Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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