Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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