Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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