Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3255 | Rev 3648 | 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
2
/**
3
 *
4
 * Controlador: Mis Perfiles
5
 *
6
 */
7
declare(strict_types=1);
8
 
9
namespace LeadersLinked\Controller;
10
 
11
use Laminas\Db\Adapter\AdapterInterface;
12
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
13
use Laminas\Mvc\Controller\AbstractActionController;
14
use Laminas\Log\LoggerInterface;
15
use Laminas\View\Model\ViewModel;
16
use Laminas\View\Model\JsonModel;
17
 
18
use LeadersLinked\Form\UserProfile\SkillForm;
19
use LeadersLinked\Form\UserProfile\LanguageForm;
20
 
21
use LeadersLinked\Library\Functions;
22
use LeadersLinked\Mapper\UserProfileMapper;
23
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
24
use LeadersLinked\Model\UserProfile;
25
use LeadersLinked\Mapper\CompanyFollowerMapper;
26
use LeadersLinked\Mapper\LocationMapper;
27
use LeadersLinked\Model\UserLanguage;
28
use LeadersLinked\Mapper\UserLanguageMapper;
29
use LeadersLinked\Mapper\UserSkillMapper;
30
 
31
use LeadersLinked\Model\UserSkill;
32
use LeadersLinked\Mapper\UserMapper;
33
use LeadersLinked\Form\UserProfile\ExtendedForm;
34
use LeadersLinked\Form\UserProfile\LocationForm;
35
use LeadersLinked\Model\Location;
36
use LeadersLinked\Form\UserProfile\SocialNetworkForm;
37
use LeadersLinked\Form\UserProfile\EducationForm;
38
use LeadersLinked\Model\UserEducation;
39
use LeadersLinked\Mapper\UserEducationMapper;
40
use LeadersLinked\Mapper\DegreeMapper;
41
use LeadersLinked\Form\UserProfile\ExperienceForm;
42
use LeadersLinked\Mapper\LanguageMapper;
43
use LeadersLinked\Mapper\UserExperienceMapper;
44
use LeadersLinked\Mapper\IndustryMapper;
45
use LeadersLinked\Mapper\CompanySizeMapper;
46
use LeadersLinked\Model\UserExperience;
47
use LeadersLinked\Mapper\ConnectionMapper;
48
use LeadersLinked\Form\UserProfile\ImageForm;
49
use LeadersLinked\Library\Image;
50
use LeadersLinked\Form\UserProfile\CoverForm;
51
use LeadersLinked\Mapper\SkillMapper;
52
use LeadersLinked\Form\MyProfiles\CreateForm;
53
 
54
 
55
class MyProfilesController extends AbstractActionController
56
{
57
    /**
58
     *
59
     * @var AdapterInterface
60
     */
61
    private $adapter;
62
 
63
 
64
    /**
65
     *
66
     * @var AbstractAdapter
67
     */
68
    private $cache;
69
 
70
    /**
71
     *
72
     * @var  LoggerInterface
73
     */
74
    private $logger;
75
 
76
 
77
    /**
78
     *
79
     * @var array
80
     */
81
    private $config;
82
 
83
    /**
84
     *
85
     * @param AdapterInterface $adapter
86
     * @param AbstractAdapter $cache
87
     * @param LoggerInterface $logger
88
     * @param array $config
89
     */
90
    public function __construct($adapter, $cache , $logger,  $config)
91
    {
92
        $this->adapter      = $adapter;
93
        $this->cache        = $cache;
94
        $this->logger       = $logger;
95
        $this->config       = $config;
96
 
97
    }
98
 
99
    /**
100
     *
101
     * Generación del listado de perfiles
102
     * {@inheritDoc}
103
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
104
     */
105
    public function indexAction()
106
    {
107
        $currentUserPlugin = $this->plugin('currentUserPlugin');
108
        $currentUser = $currentUserPlugin->getUser();
109
 
110
        $request = $this->getRequest();
111
        if($request->isGet()) {
112
 
113
 
114
            $headers  = $request->getHeaders();
115
            $isJson = false;
116
            if($headers->has('Accept')) {
117
                $accept = $headers->get('Accept');
118
 
119
                $prioritized = $accept->getPrioritized();
120
 
121
                foreach($prioritized as $key => $value) {
122
                    $raw = trim($value->getRaw());
123
 
124
                    if(!$isJson) {
125
                        $isJson = str_contains($raw, 'json');
126
                    }
127
 
128
                }
129
            }
130
            if($isJson) {
3255 efrain 131
                $search = filter_var($this->params()->fromQuery('search'), FILTER_SANITIZE_STRING);
132
 
133
 
1 www 134
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
135
                $allowView = $acl->isAllowed($currentUser->usertype_id, 'profile/view');
136
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'profile/my-profiles/edit');
137
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'profile/my-profiles/delete');
138
 
139
 
140
                $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
3255 efrain 141
                $records  = $userProfileMapper->fetchAllByUserIdAndSearch($currentUser->id, $search);
1 www 142
 
143
 
144
                $items = [];
145
                foreach($records as $record)
146
                {
147
 
148
                    $item = [
149
                        'id' => $record->id,
150
                        'name' => $record->name,
151
                        'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $currentUser->uuid, 'filename' => $record->image ]),
152
                        'link_view' => $allowView ? $this->url()->fromRoute('profile/view', ['id' => $record->uuid ])  : '',
153
                        'link_edit' => $allowEdit ? $this->url()->fromRoute('profile/my-profiles/edit', ['id' => $record->uuid ])  : '',
154
                        'link_delete' => $allowDelete && $record->public == UserProfile::PUBLIC_NO ? $this->url()->fromRoute('profile/my-profiles/delete', ['id' =>$record->uuid ]) : '',
155
                    ];
156
 
157
                    array_push($items, $item);
158
                }
159
 
160
 
161
 
162
                $response = [
163
                    'success' => true,
164
                    'data' => $items
165
                ];
166
 
167
                return new JsonModel($response);
168
 
169
 
170
            } else {
171
                $formAdd = new CreateForm();
172
 
173
                $this->layout()->setTemplate('layout/layout.phtml');
174
                $viewModel = new ViewModel();
175
                $viewModel->setTemplate('leaders-linked/my-profiles/index.phtml');
176
                $viewModel->setVariables([
177
                    'formAdd' => $formAdd,
178
 
179
                ]);
180
                return $viewModel ;
181
            }
182
 
183
        } else {
184
            return new JsonModel([
185
                'success' => false,
186
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
187
            ]);
188
        }
189
    }
190
 
191
 
192
 
193
    /**
194
     *
195
     * Agregar un nuevo perfil
196
     * @return \Laminas\View\Model\JsonModel
197
     */
198
    public function addAction()
199
    {
200
        $request = $this->getRequest();
201
 
202
 
203
        if($request->isPost()) {
204
            $form = new  CreateForm();
205
            $dataPost = $request->getPost()->toArray();
206
 
207
            $form->setData($dataPost);
208
 
209
            if($form->isValid()) {
210
                $dataPost = (array) $form->getData();
211
 
212
                $hydrator = new ObjectPropertyHydrator();
213
                $userProfile = new UserProfile();
214
                $hydrator->hydrate($dataPost, $userProfile);
215
 
216
                $currentUserPlugin = $this->plugin('currentUserPlugin');
217
                $currentUser = $currentUserPlugin->getUser();
218
 
219
                $userProfile->uuid = Functions::genUUID();
220
                $userProfile->user_id = $currentUser->id;
221
                $userProfile->public = \LeadersLinked\Model\UserProfile::PUBLIC_NO;
222
 
223
                $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
224
                $result = $userProfileMapper->insert($userProfile);
225
 
226
                if($result) {
227
                    $this->logger->info('Se agrego el perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
228
 
229
                    $data = [
230
                        'success'   => true,
231
                        'data'   => 'LABEL_RECORD_ADDED'
232
                    ];
233
                } else {
234
                    $data = [
235
                        'success'   => false,
236
                        'data'      => $userProfile->getError()
237
                    ];
238
 
239
                }
240
 
241
                return new JsonModel($data);
242
 
243
            } else {
244
                $messages = [];
245
                $form_messages = (array) $form->getMessages();
246
                foreach($form_messages  as $fieldname => $field_messages)
247
                {
248
 
249
                    $messages[$fieldname] = array_values($field_messages);
250
                }
251
 
252
                return new JsonModel([
253
                    'success'   => false,
254
                    'data'   => $messages
255
                ]);
256
            }
257
 
258
        } else {
259
            $data = [
260
                'success' => false,
261
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
262
            ];
263
 
264
            return new JsonModel($data);
265
        }
266
 
267
        return new JsonModel($data);
268
    }
269
 
270
    /**
271
     *
272
     * Borrar un perfil excepto el público
273
     * @return \Laminas\View\Model\JsonModel
274
     */
275
    public function deleteAction()
276
    {
277
        $request = $this->getRequest();
278
        $id = $this->params()->fromRoute('id');
279
 
280
        if(!$id) {
281
            $data = [
282
                'success'   => false,
283
                'data'   => 'ERROR_INVALID_PARAMETER'
284
            ];
285
 
286
            return new JsonModel($data);
287
        }
288
 
289
 
290
 
291
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
292
        $userProfile = $userProfileMapper->fetchOneByUuid($id);
293
        if(!$userProfile) {
294
            $data = [
295
                'success'   => false,
296
                'data'   => 'ERROR_RECORD_NOT_FOUND'
297
            ];
298
 
299
            return new JsonModel($data);
300
        }
301
 
302
        $currentUser = $this->plugin('currentUserPlugin');
303
        if($currentUser->getUserId() != $userProfile->user_id) {
304
            $response = [
305
                'success' => false,
306
                'data' => 'ERROR_UNAUTHORIZED'
307
            ];
308
 
309
            return new JsonModel($response);
310
        }
311
 
312
        if(!$userProfile->public == UserProfile::PUBLIC_YES) {
313
            $data = [
314
                'success'   => false,
315
                'data'   => 'ERROR_PUBLIC_PROFILE'
316
            ];
317
 
318
            return new JsonModel($data);
319
        }
320
 
321
        if($request->isPost()) {
322
            $result = $userProfileMapper->delete($userProfile);
323
            if($result) {
324
                $this->logger->info('Se borro el perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
325
 
326
                $data = [
327
                    'success' => true,
328
                    'data' => 'LABEL_RECORD_DELETED'
329
                ];
330
            } else {
331
 
332
                $data = [
333
                    'success'   => false,
334
                    'data'      => $userProfileMapper->getError()
335
                ];
336
 
337
                return new JsonModel($data);
338
            }
339
 
340
        } else {
341
            $data = [
342
                'success' => false,
343
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
344
            ];
345
 
346
            return new JsonModel($data);
347
        }
348
 
349
        return new JsonModel($data);
350
    }
351
 
352
    /**
353
     * Presenta el perfil con las opciónes de edición de cada sección
354
     * @return \Laminas\Http\Response|\Laminas\View\Model\ViewModel|\Laminas\View\Model\JsonModel
355
     */
356
    public function editAction()
357
    {
358
        $flashMessenger = $this->plugin('FlashMessenger');
359
 
360
 
361
        $request = $this->getRequest();
362
        $id = $this->params()->fromRoute('id');
363
 
364
 
365
        if(!$id) {
366
            $flashMessenger->addErrorMessage('ERROR_INVALID_PARAMETER');
367
            return $this->redirect()->toRoute('dashboard');
368
        }
369
 
370
 
371
 
372
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
373
        $userProfile = $userProfileMapper->fetchOneByUuid($id);
374
 
375
        if(!$userProfile) {
376
            $flashMessenger->addErrorMessage('ERROR_RECORD_NOT_FOUND');
377
            return $this->redirect()->toRoute('dashboard');
378
        }
379
 
380
        $currentUser = $this->plugin('currentUserPlugin');
381
        if($currentUser->getUserId() != $userProfile->user_id) {
382
            $flashMessenger->addErrorMessage('ERROR_UNAUTHORIZED');
383
            return $this->redirect()->toRoute('dashboard');
384
        }
385
 
386
 
387
        $sandbox = $this->config['leaderslinked.runmode.sandbox'];
388
        if($sandbox) {
389
            $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
390
        } else {
391
            $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
392
        }
393
 
394
        if($request->isGet()) {
395
 
396
            if($userProfile->location_id) {
397
                $locationMapper= LocationMapper::getInstance($this->adapter);
398
                $location = $locationMapper->fetchOne($userProfile->location_id);
399
 
400
                $formattedAddress = $location->formatted_address;
401
                $country = $location->country;
402
            } else {
403
                $formattedAddress = '';
404
                $country = '';
405
            }
406
 
407
 
408
 
409
            $userMapper = UserMapper::getInstance($this->adapter);
410
            $user = $userMapper->fetchOne($userProfile->user_id);
411
 
412
            $userLanguages = [];
413
            $languageMapper = LanguageMapper::getInstance($this->adapter);
414
            $userLanguageMapper = UserLanguageMapper::getInstance($this->adapter);
415
            $records = $userLanguageMapper->fetchAllByUserProfileId($userProfile->id);
416
            foreach ($records as $record)
417
            {
418
                $language = $languageMapper->fetchOne($record->language_id);
419
                $userLanguages[$language->id] = $language->name;
420
            }
421
 
422
 
423
            $locationMapper = LocationMapper::getInstance($this->adapter);
424
            $degreeMapper = DegreeMapper::getInstance($this->adapter);
425
            $userEducationMapper = UserEducationMapper::getInstance($this->adapter);
426
            $userEducations = $userEducationMapper->fetchAllByUserProfileId($userProfile->id);
427
 
428
 
429
 
430
            foreach($userEducations  as &$userEducation)
431
            {
432
                $location = $locationMapper->fetchOne($userEducation->location_id);
433
                $degree = $degreeMapper->fetchOne($userEducation->degree_id);
434
 
435
                $userEducation = [
436
                    'university' => $userEducation->university,
437
                    'degree' => $degree->name,
438
                    'field_of_study' => $userEducation->field_of_study,
439
                    'grade_or_percentage' => $userEducation->grade_or_percentage,
440
                    'formatted_address' => $location->formatted_address,
441
                    'from_year' => $userEducation->from_year,
442
                    'to_year' => $userEducation->to_year,
443
                    'description' => $userEducation->description,
444
                    'link_edit' => $this->url()->fromRoute('profile/my-profiles/education', [ 'id' => $userProfile->uuid, 'operation' => 'edit', 'user_education_id' => $userEducation->uuid ]),
445
                    'link_delete' => $this->url()->fromRoute('profile/my-profiles/education', [ 'id' => $userProfile->uuid, 'operation' => 'delete', 'user_education_id' => $userEducation->uuid ]),
446
                ];
447
            }
448
 
449
            $industryMapper = IndustryMapper::getInstance($this->adapter);
450
            $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
451
 
452
            $userExperienceMapper = UserExperienceMapper::getInstance($this->adapter);
453
            $userExperiences = $userExperienceMapper->fetchAllByUserProfileId($userProfile->id);
454
 
455
            foreach($userExperiences  as &$userExperience)
456
            {
457
                $location = $locationMapper->fetchOne($userExperience->location_id);
458
                $companySize = $companySizeMapper->fetchOne($userExperience->company_size_id);
459
                $industry = $industryMapper->fetchOne($userExperience->industry_id);
460
 
461
                $userExperience = [
462
                    'company' => $userExperience->company,
463
                    'industry' => $industry->name,
464
                    'size' => $companySize->name . ' ('.$companySize->minimum_no_of_employee . '-' . $companySize->maximum_no_of_employee .')',
465
                    'title' => $userExperience->title,
466
                    'formatted_address' => $location->formatted_address,
467
                    'from_year' => $userExperience->from_year,
468
                    'from_month' => $userExperience->from_month,
469
                    'to_year' => $userExperience->to_year,
470
                    'to_month' => $userExperience->to_month,
471
                    'description' => $userExperience->description,
472
                    'is_current' => $userExperience->is_current,
473
                    'link_edit' => $this->url()->fromRoute('profile/my-profiles/experience', [ 'id' => $userProfile->uuid, 'operation' => 'edit', 'user_experience_id' => $userExperience->uuid ]),
474
                    'link_delete' => $this->url()->fromRoute('profile/my-profiles/experience', [ 'id' => $userProfile->uuid, 'operation' => 'delete', 'user_experience_id' => $userExperience->uuid ]),
475
                ];
476
            }
477
 
478
 
479
            $headers  = $request->getHeaders();
480
 
481
            $isJson = false;
482
            if($headers->has('Accept')) {
483
                $accept = $headers->get('Accept');
484
 
485
                $prioritized = $accept->getPrioritized();
486
 
487
                foreach($prioritized as $key => $value) {
488
                    $raw = trim($value->getRaw());
489
 
490
                    if(!$isJson) {
491
                        $isJson = strpos($raw, 'json');
492
                    }
493
 
494
                }
495
            }
496
 
497
 
498
 
499
            $userSkills = [];
500
            $userSkillMapper = UserSkillMapper::getInstance($this->adapter);
501
            $skillMapper = SkillMapper::getInstance($this->adapter);
502
            $records  = $userSkillMapper->fetchAllByUserProfileId($userProfile->id);
503
            foreach($records as $record)
504
            {
505
                $skill = $skillMapper->fetchOne($record->skill_id);
506
                $userSkills[$skill->uuid] = $skill->name;
507
            }
508
 
509
 
510
            $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
511
            $following = $companyFollowerMapper->getCountFollowing($user->id);
512
 
513
            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
514
            $follower = $connectionMapper->fetchTotalConnectionByUser($user->id);
515
 
516
 
517
            $image_size_cover = $this->config['leaderslinked.image_sizes.user_cover_upload'];
518
            $image_size_profile = $this->config['leaderslinked.image_sizes.user_upload'];
519
 
520
 
521
            if($isJson) {
522
 
523
                $data = [
524
                    'following'         => $following ,
525
                    'follower'          => $follower,
526
                    'user_id'           => $user->id,
527
                    'user_uuid'         => $user->uuid,
528
                    'full_name'         => trim($user->first_name . ' ' . $user->last_name),
529
                    'user_profile_id'   => $userProfile->id,
530
                    'user_profile_uuid' => $userProfile->uuid,
531
                    'image'             => $userProfile->image,
532
                    'cover'             => $userProfile->cover,
533
                    'overview'          => $userProfile->description,
534
                    'facebook'          => $userProfile->facebook,
535
                    'instagram'         => $userProfile->instagram,
536
                    'twitter'           => $userProfile->twitter,
537
                    'formatted_address' => $formattedAddress,
538
                    'country'           => $country,
539
                    'user_skills'       => $userSkills,
540
                    'user_languages'    => $userLanguages,
541
                    'user_educations'   => $userEducations,
542
                    'user_experiences'  => $userExperiences,
543
                    'image_size_cover' =>  $image_size_cover,
544
                    'image_size_profile' => $image_size_profile
545
                ];
546
 
547
                $viewModel = new JsonModel($data);
548
 
549
            } else {
550
                $industries = [];
551
                $industryMapper = IndustryMapper::getInstance($this->adapter);
552
 
3454 efrain 553
                $records = $industryMapper->fetchAllActive();
1 www 554
                foreach($records as $record)
555
                {
556
                    $industries[$record->uuid] = $record->name;
557
                }
558
 
559
                $companySizes = [];
560
                $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
3454 efrain 561
                $records = $companySizeMapper->fetchAllActive();
1 www 562
                foreach($records as $record)
563
                {
564
                    $companySizes[$record->uuid] = $record->name . ' ('.$record->minimum_no_of_employee . '-' . $record->maximum_no_of_employee .')';
565
                }
566
 
567
                $degrees = [];
568
                $degreeMapper = DegreeMapper::getInstance($this->adapter);
3454 efrain 569
                $records = $degreeMapper->fetchAllActive();
1 www 570
                foreach($records as $record)
571
                {
572
                    $degrees[$record->uuid] = $record->name;
573
                }
574
 
575
                $languages = [];
576
                $languageMapper = LanguageMapper::getInstance($this->adapter);
3454 efrain 577
                $records = $languageMapper->fetchAllActive();
1 www 578
                foreach($records as $record) {
579
                    $languages[$record->id] = $record->name;
580
                }
581
 
582
                $skills = [];
583
                $skillMapper = SkillMapper::getInstance($this->adapter);
3454 efrain 584
                $records =  $skillMapper->fetchAllActive();
1 www 585
                foreach($records as $record) {
586
                    $skills[$record->uuid] = $record->name;
587
                }
588
 
589
 
590
                $formSkill = new SkillForm($this->adapter);
591
                $formLanguage = new LanguageForm($this->adapter);
592
                $formLocation = new LocationForm();
593
                $formExtended = new ExtendedForm();
594
                $formExperience = new ExperienceForm($this->adapter);
595
                $formEducation = new EducationForm($this->adapter);
596
                $formSocialNetwork = new SocialNetworkForm();
597
                $formImage = new ImageForm($this->config);
598
                $formCover = new CoverForm($this->config);
599
 
600
 
601
 
602
 
603
                $this->layout()->setTemplate('layout/layout.phtml');
604
                $viewModel = new ViewModel();
605
                $viewModel->setTemplate('leaders-linked/my-profiles/edit.phtml');
606
                $viewModel->setVariables([
607
                    'google_map_key'    => $google_map_key,
608
                    'following'         => $following ,
609
                    'follower'          => $follower,
610
                    'user_id'           => $user->id,
611
                    'user_uuid' => $user->uuid,
612
                    'full_name'         => trim($user->first_name . ' ' . $user->last_name),
613
                    'user_profile_id'   => $userProfile->id,
614
                    'user_profile_uuid' => $userProfile->uuid,
615
                    'public'            => $userProfile->public,
616
                    'image'             => $userProfile->image,
617
                    'cover'             => $userProfile->cover,
618
                    'overview'          => $userProfile->description,
619
                    'facebook'          => $userProfile->facebook,
620
                    'instagram'         => $userProfile->instagram,
621
                    'twitter'           => $userProfile->twitter,
622
                    'formatted_address' => $formattedAddress,
623
                    'country'           => $country,
624
                    'user_skills'       => $userSkills,
625
                    'user_languages'    => $userLanguages,
626
                    'user_educations'   => $userEducations,
627
                    'user_experiences'  => $userExperiences,
628
                    'company_sizes'     => $companySizes,
629
                    'degrees'           => $degrees,
630
                    'industries'        => $industries,
631
                    'languages'         => $languages,
632
                    'skills'            => $skills,
633
 
634
 
635
                    'formLanguage'      => $formLanguage,
636
                    'formLocation'      => $formLocation,
637
                    'formSkill'         => $formSkill,
638
                    'formSocialNetwork' => $formSocialNetwork,
639
                    'formExtended'      => $formExtended,
640
                    'formExperience'    => $formExperience,
641
                    'formEducation'     => $formEducation,
642
                    'formImage'        => $formImage,
643
                    'formCover'         => $formCover,
644
                    'image_size_cover' =>  $image_size_cover,
645
                    'image_size_profile' => $image_size_profile
646
                ]);
647
            }
648
            return $viewModel ;
649
 
650
        } else {
651
            $data = [
652
                'success' => false,
653
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
654
            ];
655
 
656
            return new JsonModel($data);
657
        }
658
 
659
        return new JsonModel($data);
660
    }
661
 
662
    /**
663
     * Actualización de las habilidades
664
     * @return \Laminas\View\Model\JsonModel
665
     */
666
    public function skillAction()
667
    {
668
 
669
        $user_profile_id = $this->params()->fromRoute('id');
670
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
671
 
672
        $userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
673
        if(!$userProfile) {
674
            $response = [
675
                'success' => false,
676
                'data' => 'ERROR_INVALID_PARAMETER'
677
            ];
678
 
679
            return new JsonModel($response);
680
 
681
        }
682
 
683
        $currentUser = $this->plugin('currentUserPlugin');
684
        if($currentUser->getUserId() != $userProfile->user_id) {
685
            $response = [
686
                'success' => false,
687
                'data' => 'ERROR_UNAUTHORIZED'
688
            ];
689
 
690
            return new JsonModel($response);
691
        }
692
 
693
 
694
 
695
        $request = $this->getRequest();
696
        if($request->isGet()) {
697
            $skillMapper = SkillMapper::getInstance($this->adapter);
698
 
699
 
700
            $userSkillMapper = UserSkillMapper::getInstance($this->adapter);
701
            $userSkills  = $userSkillMapper->fetchAllByUserProfileId($userProfile->id);
702
 
703
            $items = [];
704
            foreach($userSkills as $userSkill)
705
            {
706
                $skill = $skillMapper->fetchOne($userSkill->skill_id);
707
                array_push($items, $skill->uuid);
708
            }
709
 
710
            $data = [
711
                'success' => true,
712
                'data' => $items
713
            ];
714
 
715
            return new JsonModel($data);
716
 
717
 
718
        } else if($request->isPost()) {
719
 
720
            $form = new SkillForm($this->adapter);
721
            $dataPost = $request->getPost()->toArray();
722
 
723
            $form->setData($dataPost);
724
 
725
            if($form->isValid()) {
726
                $this->logger->info('Se actualizaron las habilidades del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
727
 
728
                $skillMapper = SkillMapper::getInstance($this->adapter);
729
 
730
 
731
                $userSkillMapper = UserSkillMapper::getInstance($this->adapter);
732
                $userSkillMapper->deleteByUserProfileId($userProfile->id);
733
 
734
                $dataPost = (array) $form->getData();
735
                $skills = $dataPost['skills'];
736
                foreach($skills as $skill_uuid)
737
                {
738
 
739
                    $skill = $skillMapper->fetchOneByUuid($skill_uuid);
740
 
741
 
742
 
743
                    $userSkill = new UserSkill();
744
                    $userSkill->user_id = $userProfile->user_id;
745
                    $userSkill->user_profile_id = $userProfile->id;
746
                    $userSkill->skill_id =  $skill->id;
747
 
748
                    $userSkillMapper->insert($userSkill);
749
                }
750
 
751
                $items = [];
752
 
753
                $records = $userSkillMapper->fetchAllByUserProfileId($userProfile->id);
754
                foreach($records as $record)
755
                {
756
                    $skill = $skillMapper->fetchOne($record->skill_id);
757
                    array_push($items,  ['value' => $skill->uuid, 'label' => $skill->name]);
758
                }
759
 
760
                return new JsonModel([
761
                    'success'   => true,
762
                    'data'   => $items
763
                ]);
764
 
765
            } else {
766
                $messages = [];
767
                $form_messages = (array) $form->getMessages();
768
                foreach($form_messages  as $fieldname => $field_messages)
769
                {
770
                    $messages[$fieldname] = array_values($field_messages);
771
                }
772
 
773
                return new JsonModel([
774
                    'success'   => false,
775
                    'data'   => $messages
776
                ]);
777
            }
778
 
779
            $userSkillMapper = UserSkillMapper::getInstance($this->adapter);
780
 
781
        }
782
 
783
 
784
        $data = [
785
            'success' => false,
786
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
787
        ];
788
 
789
 
790
        return new JsonModel($data);
791
    }
792
 
793
    /**
794
     * Actualización de los idiomas
795
     * @return \Laminas\View\Model\JsonModel
796
     */
797
    public function languageAction()
798
    {
799
 
800
        $user_profile_id = $this->params()->fromRoute('id');
801
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
802
 
803
        $userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
804
        if(!$userProfile) {
805
            $response = [
806
                'success' => false,
807
                'data' => 'ERROR_INVALID_PARAMETER'
808
            ];
809
 
810
            return new JsonModel($response);
811
 
812
        }
813
 
814
        $currentUser = $this->plugin('currentUserPlugin');
815
        if($currentUser->getUserId() != $userProfile->user_id) {
816
            $response = [
817
                'success' => false,
818
                'data' => 'ERROR_UNAUTHORIZED'
819
            ];
820
 
821
            return new JsonModel($response);
822
        }
823
 
824
 
825
 
826
        $request = $this->getRequest();
827
        if($request->isGet()) {
828
            $this->logger->info('Se actualizaron los idiomas del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
829
 
830
            $userLanguageMapper = UserLanguageMapper::getInstance($this->adapter);
831
            $languages  = $userLanguageMapper->fetchAllByUserProfileId($userProfile->id);
832
 
833
            $items = [];
834
            foreach($languages as $language)
835
            {
836
                array_push($items, $language->language_id);
837
            }
838
 
839
            $data = [
840
                'success' => true,
841
                'data' => $items
842
            ];
843
 
844
            return new JsonModel($data);
845
 
846
 
847
        } else if($request->isPost()) {
848
 
849
            $form = new LanguageForm($this->adapter);
850
            $dataPost = $request->getPost()->toArray();
851
 
852
            $form->setData($dataPost);
853
 
854
            if($form->isValid()) {
855
 
856
                $languageMapper = LanguageMapper::getInstance($this->adapter);
857
                $userLanguageMapper = UserLanguageMapper::getInstance($this->adapter);
858
                $userLanguageMapper->deleteByUserProfileId($userProfile->id);
859
 
860
                $dataPost = (array) $form->getData();
861
                $languages = $dataPost['languages'];
862
                foreach($languages as $language_id)
863
                {
864
                    $language = $languageMapper->fetchOne($language_id);
865
 
866
                    $userLanguage = new UserLanguage();
867
                    $userLanguage->user_id = $userProfile->user_id;
868
                    $userLanguage->user_profile_id = $userProfile->id;
869
                    $userLanguage->language_id = $language->id;
870
 
871
                    $userLanguageMapper->insert($userLanguage);
872
                }
873
 
874
                $items = [];
875
                $records = $userLanguageMapper->fetchAllByUserProfileId($userProfile->id);
876
                foreach($records as $record)
877
                {
878
                    $language = $languageMapper->fetchOne($record->language_id);
879
                    array_push($items,  ['value' => $language->id, 'label' => $language->name]);
880
                }
881
 
882
                return new JsonModel([
883
                    'success'   => true,
884
                    'data'   => $items
885
                ]);
886
 
887
            } else {
888
                $messages = [];
889
                $form_messages = (array) $form->getMessages();
890
                foreach($form_messages  as $fieldname => $field_messages)
891
                {
892
                    $messages[$fieldname] = array_values($field_messages);
893
                }
894
 
895
                return new JsonModel([
896
                    'success'   => false,
897
                    'data'   => $messages
898
                ]);
899
            }
900
        }
901
 
902
 
903
        $data = [
904
            'success' => false,
905
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
906
        ];
907
 
908
 
909
        return new JsonModel($data);
910
    }
911
 
912
    /**
913
     * Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
914
     * @return \Laminas\View\Model\JsonModel
915
     */
916
    public function extendedAction()
917
    {
918
 
919
        $user_profile_id = $this->params()->fromRoute('id');
920
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
921
 
922
        $userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
923
        if(!$userProfile) {
924
            $response = [
925
                'success' => false,
926
                'data' => 'ERROR_INVALID_PARAMETER'
927
            ];
928
 
929
            return new JsonModel($response);
930
 
931
        }
932
 
933
        $currentUser = $this->plugin('currentUserPlugin');
934
        if($currentUser->getUserId() != $userProfile->user_id) {
935
            $response = [
936
                'success' => false,
937
                'data' => 'ERROR_UNAUTHORIZED'
938
            ];
939
 
940
            return new JsonModel($response);
941
        }
942
 
943
 
944
 
945
        $request = $this->getRequest();
946
        if($request->isGet()) {
947
            $data = [
948
                'success' => true,
949
                'data' => [
950
                    'description' => $userProfile->description,
951
                ]
952
            ];
953
 
954
            return new JsonModel($data);
955
 
956
 
957
        } else if($request->isPost()) {
958
 
959
 
960
            $form = new ExtendedForm();
961
            $dataPost = $request->getPost()->toArray();
962
 
963
            $form->setData($dataPost);
964
 
965
            if($form->isValid()) {
966
                $dataPost = (array) $form->getData();
967
 
968
                $hydrator = new ObjectPropertyHydrator();
969
                $hydrator->hydrate($dataPost, $userProfile);
970
 
971
                $userProfileMapper->updateExtended($userProfile);
972
 
973
                $this->logger->info('Se actualizo las descripción del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
974
 
975
                return new JsonModel([
976
                    'success'   => true,
977
                    'data' => [
978
                        'description' => $userProfile->description,
979
                    ]
980
                ]);
981
 
982
            } else {
983
                $messages = [];
984
                $form_messages = (array) $form->getMessages();
985
                foreach($form_messages  as $fieldname => $field_messages)
986
                {
987
                    $messages[$fieldname] = array_values($field_messages);
988
                }
989
 
990
                return new JsonModel([
991
                    'success'   => false,
992
                    'data'   => $messages
993
                ]);
994
            }
995
        }
996
 
997
 
998
        $data = [
999
            'success' => false,
1000
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1001
        ];
1002
 
1003
 
1004
        return new JsonModel($data);
1005
    }
1006
 
1007
    /**
1008
     * Actualización de la ubucación
1009
     * @return \Laminas\View\Model\JsonModel
1010
     */
1011
    public function locationAction()
1012
    {
1013
 
1014
        $user_profile_id = $this->params()->fromRoute('id');
1015
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
1016
 
1017
        $userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
1018
        if(!$userProfile) {
1019
            $response = [
1020
                'success' => false,
1021
                'data' => 'ERROR_INVALID_PARAMETER'
1022
            ];
1023
 
1024
            return new JsonModel($response);
1025
 
1026
        }
1027
 
1028
        $currentUser = $this->plugin('currentUserPlugin');
1029
        $currentUser = $currentUser->getUser();
1030
        if($currentUser->id != $userProfile->user_id) {
1031
            $response = [
1032
                'success' => false,
1033
                'data' => 'ERROR_UNAUTHORIZED'
1034
            ];
1035
 
1036
            return new JsonModel($response);
1037
        }
1038
 
1039
 
1040
 
1041
        $request = $this->getRequest();
1042
        if($request->isPost()) {
1043
 
1044
            $form = new LocationForm();
1045
            $dataPost = $request->getPost()->toArray();
1046
 
1047
            $form->setData($dataPost);
1048
 
1049
            if($form->isValid()) {
1050
                $this->logger->info('Se actualizaron la ubicación del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1051
 
1052
                $dataPost = (array) $form->getData();
1053
 
1054
                $location = new Location();
1055
                $hydrator = new ObjectPropertyHydrator();
1056
                $hydrator->hydrate($dataPost, $location);
1057
 
1058
                $location->id = $userProfile->location_id ? $userProfile->location_id : null;
1059
 
1060
 
1061
 
1062
                $locationMapper = LocationMapper::getInstance($this->adapter);
1063
                if($userProfile->location_id) {
1064
                    $result = $locationMapper->update($location);
1065
                } else {
1066
                    $result = $locationMapper->insert($location);
1067
 
1068
                    if($result) {
1069
                        $userProfile->location_id = $location->id;
1070
                        $userProfileMapper->updateLocation($userProfile);
1071
                    }
1072
                }
1073
 
1074
                if($result) {
1075
                    if($userProfile->public == UserProfile::PUBLIC_YES) {
1076
                        $currentUser->location_id = $location->id;
1077
 
1078
                        $userMapper = UserMapper::getInstance($this->adapter);
1079
                        $userMapper->updateLocation($currentUser);
1080
                    }
1081
 
1082
 
1083
                    $response = [
1084
                        'success'   => true,
1085
                        'data' => [
1086
                            'formatted_address' => $location->formatted_address,
1087
                            'country' => $location->country,
1088
                        ]
1089
                    ];
1090
                } else {
1091
                    $response = [
1092
                        'success'   => false,
1093
                        'data' => 'ERROR_THERE_WAS_AN_ERROR'
1094
                    ];
1095
                }
1096
 
1097
 
1098
 
1099
                return new JsonModel($response);
1100
 
1101
            } else {
1102
                return new JsonModel([
1103
                    'success'   => false,
1104
                    'data'   =>   'ERROR_PLACED_AUTOCOMPLETE_DOES_NOT_CONTAIN_GEOMETRY'
1105
                ]);
1106
            }
1107
        }
1108
 
1109
 
1110
        $data = [
1111
            'success' => false,
1112
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1113
        ];
1114
 
1115
 
1116
        return new JsonModel($data);
1117
    }
1118
 
1119
    /**
1120
     * Actualización de las redes sociales
1121
     * @return \Laminas\View\Model\JsonModel
1122
     */
1123
    public function socialNetworkAction()
1124
    {
1125
 
1126
        $user_profile_id = $this->params()->fromRoute('id');
1127
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
1128
 
1129
        $userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
1130
        if(!$userProfile) {
1131
            $response = [
1132
                'success' => false,
1133
                'data' => 'ERROR_INVALID_PARAMETER'
1134
            ];
1135
 
1136
            return new JsonModel($response);
1137
 
1138
        }
1139
 
1140
        $currentUser = $this->plugin('currentUserPlugin');
1141
        if($currentUser->getUserId() != $userProfile->user_id) {
1142
            $response = [
1143
                'success' => false,
1144
                'data' => 'ERROR_UNAUTHORIZED'
1145
            ];
1146
 
1147
            return new JsonModel($response);
1148
        }
1149
 
1150
 
1151
 
1152
        $request = $this->getRequest();
1153
        if($request->isGet()) {
1154
            $data = [
1155
                'success' => true,
1156
                'data' => [
1157
                    'facebook' => $userProfile->facebook,
1158
                    'instagram' => $userProfile->instagram,
1159
                    'twitter' => $userProfile->twitter
1160
                ]
1161
            ];
1162
 
1163
            return new JsonModel($data);
1164
 
1165
 
1166
        } else if($request->isPost()) {
1167
 
1168
            $form = new SocialNetworkForm();
1169
            $dataPost = $request->getPost()->toArray();
1170
 
1171
            $form->setData($dataPost);
1172
 
1173
            if($form->isValid()) {
1174
                $this->logger->info('Se actualizaron las redes sociales del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1175
 
1176
                $dataPost = (array) $form->getData();
1177
 
1178
                $hydrator = new ObjectPropertyHydrator();
1179
                $hydrator->hydrate($dataPost, $userProfile);
1180
 
1181
                $userProfileMapper->updateSocialNetwork($userProfile);
1182
                return new JsonModel([
1183
                    'success'   => true,
1184
                    'data' => [
1185
                        'facebook' => $userProfile->facebook,
1186
                        'instagram' => $userProfile->instagram,
1187
                        'twitter' => $userProfile->twitter
1188
                    ]
1189
                ]);
1190
 
1191
            } else {
1192
                $messages = [];
1193
                $form_messages = (array) $form->getMessages();
1194
                foreach($form_messages  as $fieldname => $field_messages)
1195
                {
1196
                    $messages[$fieldname] = array_values($field_messages);
1197
                }
1198
 
1199
                return new JsonModel([
1200
                    'success'   => false,
1201
                    'data'   => $messages
1202
                ]);
1203
            }
1204
        }
1205
 
1206
 
1207
        $data = [
1208
            'success' => false,
1209
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1210
        ];
1211
 
1212
 
1213
        return new JsonModel($data);
1214
    }
1215
 
1216
    /**
1217
     * Actualización de los registros de estudios realizados
1218
     * @return \Laminas\View\Model\JsonModel
1219
     */
1220
    public function  educationAction()
1221
    {
1222
 
1223
        $user_profile_id    = $this->params()->fromRoute('id');
1224
        $user_education_id  = $this->params()->fromRoute('user_education_id');
1225
        $operation          = $this->params()->fromRoute('operation');
1226
 
1227
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
1228
 
1229
        $userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
1230
        if(!$userProfile) {
1231
            $response = [
1232
                'success' => false,
1233
                'data' => 'ERROR_INVALID_PARAMETER'
1234
            ];
1235
 
1236
            return new JsonModel($response);
1237
 
1238
        }
1239
 
1240
        $currentUser = $this->plugin('currentUserPlugin');
1241
        if($currentUser->getUserId() != $userProfile->user_id) {
1242
            $response = [
1243
                'success' => false,
1244
                'data' => 'ERROR_UNAUTHORIZED'
1245
            ];
1246
 
1247
            return new JsonModel($response);
1248
        }
1249
 
1250
 
1251
 
1252
        $request = $this->getRequest();
1253
        if($request->isPost()) {
1254
            $userEducationMapper = UserEducationMapper::getInstance($this->adapter);
1255
 
1256
            if($operation == 'delete' || $operation == 'edit') {
1257
                $userEducation = $userEducationMapper->fetchOneByUuid($user_education_id);
1258
 
1259
 
1260
                if(!$userEducation) {
1261
 
1262
                    $response = [
1263
                        'success' => false,
1264
                        'data' => 'ERROR_RECORD_NOT_FOUND'
1265
                    ];
1266
 
1267
                    return new JsonModel($response);
1268
                } else if($userProfile->id != $userEducation->user_profile_id) {
1269
                    $response = [
1270
                        'success' => false,
1271
                        'data' => 'ERROR_UNAUTHORIZED'
1272
                    ];
1273
 
1274
                    return new JsonModel($response);
1275
                }
1276
            } else {
1277
                $userEducation = null;
1278
            }
1279
 
1280
            $locationMapper = LocationMapper::getInstance($this->adapter);
1281
            if($operation == 'delete') {
1282
                $this->logger->info('Se borro un registro de educación del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1283
 
1284
                $result = $userEducationMapper->delete($userEducation);
1285
                if($result) {
1286
                    $locationMapper->delete($userEducation->location_id);
1287
                }
1288
            } else {
1289
 
1290
 
1291
                $form = new EducationForm($this->adapter);
1292
                $dataPost = $request->getPost()->toArray();
1293
 
1294
                $form->setData($dataPost);
1295
 
1296
                if($form->isValid()) {
1297
 
1298
                    if(!$userEducation) {
1299
                        $userEducation = new UserEducation();
1300
                        $userEducation->user_id = $userProfile->user_id;
1301
                        $userEducation->user_profile_id = $userProfile->id;
1302
                    }
1303
 
1304
                    $dataPost = (array) $form->getData();
1305
 
1306
                    $hydrator = new ObjectPropertyHydrator();
1307
                    $hydrator->hydrate($dataPost, $userEducation);
1308
 
1309
                    $degreeMapper = DegreeMapper::getInstance($this->adapter);
1310
                    $degree = $degreeMapper->fetchOneByUuid($dataPost['degree_id']);
1311
                    $userEducation->degree_id = $degree->id;
1312
 
1313
 
1314
 
1315
 
1316
                    if($userEducation->location_id) {
1317
                        $location = $locationMapper->fetchOne($userEducation->location_id);
1318
                    } else {
1319
                        $location = new Location();
1320
                    }
1321
 
1322
                    $hydrator->hydrate($dataPost,$location);
1323
                    if($userEducation->location_id) {
1324
                        $this->logger->info('Se actualizo un registro de educación del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1325
 
1326
                        $result = $locationMapper->update($location);
1327
                    } else {
1328
                        $this->logger->info('Se agrego un registro de educación del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1329
 
1330
                        $result = $locationMapper->insert($location);
1331
 
1332
                        if($result) {
1333
                            $userEducation->location_id = $location->id;
1334
                        }
1335
                    }
1336
                    if($result) {
1337
                        if($userEducation->id) {
1338
                            $result = $userEducationMapper->update($userEducation);
1339
                        } else {
1340
                            $result =  $userEducationMapper->insert($userEducation);
1341
                        }
1342
                    }
1343
 
1344
 
1345
 
1346
                } else {
1347
                    $messages = [];
1348
                    $form_messages = (array) $form->getMessages();
1349
                    foreach($form_messages  as $fieldname => $field_messages)
1350
                    {
1351
                        $messages[$fieldname] = array_values($field_messages);
1352
                    }
1353
 
1354
                    return new JsonModel([
1355
                        'success'   => false,
1356
                        'data'   => $messages
1357
                    ]);
1358
                }
1359
            }
1360
 
1361
            if($result) {
1362
                $degreeMapper = DegreeMapper::getInstance($this->adapter);
1363
                $userEducations = $userEducationMapper->fetchAllByUserProfileId($userProfile->id);
1364
 
1365
                foreach($userEducations  as &$userEducation)
1366
                {
1367
                    $location = $locationMapper->fetchOne($userEducation->location_id);
1368
                    $degree = $degreeMapper->fetchOne($userEducation->degree_id);
1369
 
1370
                    $userEducation = [
1371
                        'university' => $userEducation->university,
1372
                        'degree' => $degree->name,
1373
                        'field_of_study' => $userEducation->field_of_study,
1374
                        'grade_or_percentage' => $userEducation->grade_or_percentage,
1375
                        'formatted_address' => $location->formatted_address,
1376
                        'from_year' => $userEducation->from_year,
1377
                        'to_year' => $userEducation->to_year,
1378
                        'description' => $userEducation->description,
1379
                        'link_edit' => $this->url()->fromRoute('profile/my-profiles/education', [ 'id' => $userProfile->uuid, 'operation' => 'edit', 'user_education_id' => $userEducation->uuid ]),
1380
                        'link_delete' => $this->url()->fromRoute('profile/my-profiles/education', [ 'id' => $userProfile->uuid, 'operation' => 'delete', 'user_education_id' => $userEducation->uuid ]),
1381
                    ];
1382
                }
1383
 
1384
                $response = [
1385
                    'success'   => true,
1386
                    'data' => $userEducations
1387
                ];
1388
            } else {
1389
                $response = [
1390
                    'success'   => false,
1391
                    'data' => 'ERROR_THERE_WAS_AN_ERROR'
1392
                ];
1393
            }
1394
 
1395
 
1396
 
1397
            return new JsonModel($response);
1398
        }
1399
        else if ($request->isGet() && $operation == 'edit') {
1400
            $userEducationMapper = UserEducationMapper::getInstance($this->adapter);
1401
            $userEducation = $userEducationMapper->fetchOneByUuid($user_education_id);
1402
 
1403
            if(!$userEducation) {
1404
 
1405
                $response = [
1406
                    'success' => false,
1407
                    'data' => 'ERROR_RECORD_NOT_FOUND'
1408
                ];
1409
 
1410
 
1411
            } else if($userProfile->id != $userEducation->user_profile_id) {
1412
                $response = [
1413
                    'success' => false,
1414
                    'data' => 'ERROR_UNAUTHORIZED'
1415
                ];
1416
 
1417
 
1418
            } else {
1419
                $locationMapper = LocationMapper::getInstance($this->adapter);
1420
                $location = $locationMapper->fetchOne($userEducation->location_id);
1421
 
1422
                $hydrator = new ObjectPropertyHydrator();
1423
                $education = $hydrator->extract($userEducation);
1424
 
1425
                $degree = $degreeMapper = DegreeMapper::getInstance($this->adapter);
1426
                $degree = $degreeMapper->fetchOne($education['degree_id']);
1427
                $education['degree_id'] = $degree->uuid;
1428
 
1429
                $location = [
1430
                    'address1' => $location->address1,
1431
                    'address2' => $location->address2,
1432
                    'city1' => $location->city1,
1433
                    'city2' => $location->city2,
1434
                    'country' => $location->country,
1435
                    'formatted_address' => $location->formatted_address,
1436
                    'latitude' => $location->latitude,
1437
                    'longitude' => $location->longitude,
1438
                    'postal_code' => $location->postal_code,
1439
                    'state' => $location->state,
1440
                ];
1441
 
1442
                $response = [
1443
                    'success' => true,
1444
                    'data' => [
1445
                        'location' => $location,
1446
                        'education' => $education,
1447
                    ]
1448
                ];
1449
 
1450
            }
1451
 
1452
            return new JsonModel($response);
1453
        }
1454
 
1455
 
1456
 
1457
 
1458
        $data = [
1459
            'success' => false,
1460
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1461
        ];
1462
 
1463
 
1464
        return new JsonModel($data);
1465
    }
1466
 
1467
    /**
1468
     * Actualización de los registros de la experiencia laboral
1469
     * @return \Laminas\View\Model\JsonModel
1470
     */
1471
    public function  experienceAction()
1472
    {
1473
 
1474
        $user_profile_id    = $this->params()->fromRoute('id');
1475
        $user_experience_id = $this->params()->fromRoute('user_experience_id');
1476
        $operation          = $this->params()->fromRoute('operation');
1477
 
1478
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
1479
 
1480
        $userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
1481
        if(!$userProfile) {
1482
            $response = [
1483
                'success' => false,
1484
                'data' => 'ERROR_INVALID_PARAMETER'
1485
            ];
1486
 
1487
            return new JsonModel($response);
1488
 
1489
        }
1490
 
1491
        $currentUser = $this->plugin('currentUserPlugin');
1492
        if($currentUser->getUserId() != $userProfile->user_id) {
1493
            $response = [
1494
                'success' => false,
1495
                'data' => 'ERROR_UNAUTHORIZED'
1496
            ];
1497
 
1498
            return new JsonModel($response);
1499
        }
1500
 
1501
 
1502
 
1503
        $request = $this->getRequest();
1504
        if($request->isPost()) {
1505
            $userExperienceMapper = UserExperienceMapper::getInstance($this->adapter);
1506
 
1507
            if($operation == 'delete' || $operation == 'edit') {
1508
                $userExperience = $userExperienceMapper->fetchOneByUuid($user_experience_id);
1509
 
1510
                if(!$userExperience) {
1511
 
1512
                    $response = [
1513
                        'success' => false,
1514
                        'data' => 'ERROR_RECORD_NOT_FOUND'
1515
                    ];
1516
 
1517
                    return new JsonModel($response);
1518
                } else if($userProfile->id != $userExperience->user_profile_id) {
1519
                    $response = [
1520
                        'success' => false,
1521
                        'data' => 'ERROR_UNAUTHORIZED'
1522
                    ];
1523
 
1524
                    return new JsonModel($response);
1525
                }
1526
            } else {
1527
                $userExperience = null;
1528
            }
1529
 
1530
            $locationMapper = LocationMapper::getInstance($this->adapter);
1531
            if($operation == 'delete') {
1532
                $this->logger->info('Se borro un registro de experiencia del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1533
 
1534
                $result = $userExperienceMapper->delete($userExperience);
1535
                if($result) {
1536
                    $locationMapper->delete($userExperience->location_id);
1537
                }
1538
 
1539
 
1540
            } else {
1541
 
1542
 
1543
                $form = new ExperienceForm($this->adapter);
1544
                $dataPost = $request->getPost()->toArray();
1545
 
1546
 
1547
                $dataPost['is_current'] = isset($dataPost['is_current']) ? $dataPost['is_current'] : UserExperience::IS_CURRENT_NO;
1548
                if( $dataPost['is_current']  == UserExperience::IS_CURRENT_YES) {
1549
                    $dataPost['to_month'] = 12;
1550
                    $dataPost['to_year'] = date('Y');
1551
                }
1552
 
1553
 
1554
                $form->setData($dataPost);
1555
 
1556
                if($form->isValid()) {
1557
 
1558
 
1559
 
1560
 
1561
                    if(!$userExperience) {
1562
                        $userExperience = new UserExperience();
1563
                        $userExperience->user_id = $userProfile->user_id;
1564
                        $userExperience->user_profile_id = $userProfile->id;
1565
                    }
1566
 
1567
                    $dataPost = (array) $form->getData();
1568
                    $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
1569
                    $companySize = $companySizeMapper->fetchOneByUuid($dataPost['company_size_id']);
1570
 
1571
                    $industryMapper = IndustryMapper::getInstance($this->adapter);
1572
                    $industry = $industryMapper->fetchOneByUuid($dataPost['industry_id']);
1573
 
1574
                    $hydrator = new ObjectPropertyHydrator();
1575
                    $hydrator->hydrate($dataPost, $userExperience);
1576
 
1577
                    $userExperience->company_size_id = $companySize->id;
1578
                    $userExperience->industry_id = $industry->id;
1579
 
1580
                    if($userExperience->is_current == UserExperience::IS_CURRENT_YES) {
1581
                        $userExperience->to_month = null;
1582
                        $userExperience->to_year = null;
1583
                    }
1584
 
1585
                    if($userExperience->location_id) {
1586
                        $location = $locationMapper->fetchOne($userExperience->location_id);
1587
                    } else {
1588
                        $location = new Location();
1589
                    }
1590
                    $hydrator->hydrate($dataPost,$location);
1591
 
1592
                    if($userExperience->location_id) {
1593
                        $this->logger->info('Se actualizo un registro de experiencia del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1594
 
1595
                        $result = $locationMapper->update($location);
1596
                    } else {
1597
                        $this->logger->info('Se agrego un registro de experiencia del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1598
 
1599
                        $result = $locationMapper->insert($location);
1600
 
1601
                        if($result) {
1602
                            $userExperience->location_id = $location->id;
1603
                        }
1604
                    }
1605
                    if($result) {
1606
                        if($userExperience->id) {
1607
                            $result = $userExperienceMapper->update($userExperience);
1608
                        } else {
1609
                            $result =  $userExperienceMapper->insert($userExperience);
1610
                        }
1611
                    }
1612
 
1613
 
1614
 
1615
                } else {
1616
                    $messages = [];
1617
                    $form_messages = (array) $form->getMessages();
1618
                    foreach($form_messages  as $fieldname => $field_messages)
1619
                    {
1620
                        $messages[$fieldname] = array_values($field_messages);
1621
                    }
1622
 
1623
                    return new JsonModel([
1624
                        'success'   => false,
1625
                        'data'   => $messages,
1626
                    ]);
1627
                }
1628
            }
1629
 
1630
            if($result) {
1631
                $industryMapper = IndustryMapper::getInstance($this->adapter);
1632
                $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
1633
                $userExperiences = $userExperienceMapper->fetchAllByUserProfileId($userProfile->id);
1634
 
1635
                foreach($userExperiences  as &$userExperience)
1636
                {
1637
                    $location = $locationMapper->fetchOne($userExperience->location_id);
1638
                    $companySize = $companySizeMapper->fetchOne($userExperience->company_size_id);
1639
                    $industry = $industryMapper->fetchOne($userExperience->industry_id);
1640
 
1641
                    $userExperience = [
1642
                        'company' => $userExperience->company,
1643
                        'industry' => $industry,
1644
                        'size' => $companySize->name . ' (' . $companySize->minimum_no_of_employee . '-' . $companySize->maximum_no_of_employee . ') ',
1645
                        'title' => $userExperience->title,
1646
                        'formatted_address' => $location->formatted_address,
1647
                        'from_year' => $userExperience->from_year,
1648
                        'from_month' => $userExperience->from_month,
1649
                        'to_year' => $userExperience->to_year,
1650
                        'to_month' => $userExperience->to_month,
1651
                        'description' => $userExperience->description,
1652
                        'is_current' => $userExperience->is_current,
1653
                        'link_edit' => $this->url()->fromRoute('profile/my-profiles/experience', [ 'id' => $userProfile->uuid, 'operation' => 'edit', 'user_experience_id' => $userExperience->uuid ]),
1654
                        'link_delete' => $this->url()->fromRoute('profile/my-profiles/experience', [ 'id' => $userProfile->uuid, 'operation' => 'delete', 'user_experience_id' => $userExperience->uuid ]),
1655
                    ];
1656
                }
1657
 
1658
                $response = [
1659
                    'success'   => true,
1660
                    'data' => $userExperiences
1661
                ];
1662
            } else {
1663
                $response = [
1664
                    'success'   => false,
1665
                    'data' => 'ERROR_THERE_WAS_AN_ERROR'
1666
                ];
1667
            }
1668
 
1669
            return new JsonModel($response);
1670
        }
1671
        else if ($request->isGet() && $operation == 'edit') {
1672
            $userExperienceMapper = UserExperienceMapper::getInstance($this->adapter);
1673
            $userExperience = $userExperienceMapper->fetchOneByUuid($user_experience_id);
1674
 
1675
            if(!$userExperience) {
1676
                $response = [
1677
                    'success' => false,
1678
                    'data' => 'ERROR_RECORD_NOT_FOUND'
1679
                ];
1680
            } else if($userProfile->id != $userExperience->user_profile_id) {
1681
                $response = [
1682
                    'success' => false,
1683
                    'data' => 'ERROR_UNAUTHORIZED'
1684
                ];
1685
            } else {
1686
                $hydrator = new ObjectPropertyHydrator();
1687
                $experience = $hydrator->extract($userExperience);
1688
 
1689
 
1690
                $industryMapper = IndustryMapper::getInstance($this->adapter);
1691
                $industry = $industryMapper->fetchOne($userExperience->industry_id);
1692
 
1693
                $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
1694
                $companySize = $companySizeMapper->fetchOne($userExperience->company_size_id);
1695
 
1696
                $experience['industry_id'] = $industry->uuid;
1697
                $experience['company_size_id'] = $companySize->uuid;
1698
 
1699
                $locationMapper = LocationMapper::getInstance($this->adapter);
1700
                $location = $locationMapper->fetchOne($userExperience->location_id);
1701
 
1702
                $response = [
1703
                    'success' => true,
1704
                    'data' => [
1705
                        'location' => $hydrator->extract($location),
1706
                        'experience' => $experience
1707
                    ]
1708
                ];
1709
            }
1710
            return new JsonModel($response);
1711
        }
1712
 
1713
        $data = [
1714
            'success' => false,
1715
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1716
        ];
1717
 
1718
 
1719
        return new JsonModel($data);
1720
    }
1721
 
1722
    /**
1723
     * Cambio de la imagen del image del perfil
1724
     * @return \Laminas\View\Model\JsonModel
1725
     */
1726
    public function imageAction()
1727
    {
1728
        $user_profile_id    = $this->params()->fromRoute('id');
1729
        $operation          = $this->params()->fromRoute('operation');
1730
 
1731
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
1732
 
1733
        $userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
1734
        if(!$userProfile) {
1735
            $response = [
1736
                'success' => false,
1737
                'data' => 'ERROR_INVALID_PARAMETER'
1738
            ];
1739
 
1740
            return new JsonModel($response);
1741
 
1742
        }
1743
 
1744
        $currentUser = $this->plugin('currentUserPlugin');
1745
        $currentUser = $currentUser->getUser();
1746
 
1747
        if($currentUser->id != $userProfile->user_id) {
1748
            $response = [
1749
                'success' => false,
1750
                'data' => 'ERROR_UNAUTHORIZED'
1751
            ];
1752
 
1753
            return new JsonModel($response);
1754
        }
1755
 
1756
 
1757
 
1758
        $request = $this->getRequest();
1759
        if($request->isPost()) {
1760
            $target_path = $this->config['leaderslinked.fullpath.user'] . $currentUser->uuid;
1761
            if($operation == 'delete') {
1762
                $this->logger->info('Se borro el image del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1763
 
1764
                if($userProfile->image) {
1765
                    if(!Image::delete($target_path, $userProfile->image)) {
1766
                        return new JsonModel([
1767
                            'success'   => false,
1768
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1769
                        ]);
1770
                    }
1771
                }
1772
 
1773
                $userProfile->image = '';
1774
                if(!$userProfileMapper->updateImage($userProfile)) {
1775
                    return new JsonModel([
1776
                        'success'   => false,
1777
                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1778
                    ]);
1779
                }
1780
 
1781
            } else {
1782
                $form = new ImageForm($this->config);
1783
                $data 	= array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
1784
 
1785
                $form->setData($data);
1786
 
1787
                if($form->isValid()) {
1788
 
1789
                    $files = $request->getFiles()->toArray();
1790
                    if(!empty($files['image']['error'])) {
1791
 
1792
                        return new JsonModel([
1793
                            'success'   => false,
1794
                            'data'   =>  'ERROR_UPLOAD_FILE'
1795
                        ]);
1796
 
1797
 
1798
                    }
1799
 
1800
                    if($userProfile->image) {
1801
                        if(!Image::delete($target_path, $userProfile->image)) {
1802
                            return new JsonModel([
1803
                                'success'   => false,
1804
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1805
                            ]);
1806
                        }
1807
                    }
1808
 
1809
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
1810
                    $source             = $files['image']['tmp_name'];
1811
                    $target_filename    = 'user-profile-' . uniqid() . '.png';
1812
                    $crop_to_dimensions = true;
1813
 
1814
                    if(!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
1815
                        return new JsonModel([
1816
                            'success'   => false,
1817
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1818
                        ]);
1819
                    }
1820
 
1821
                    $userProfile->image = $target_filename;
1822
                    if(!$userProfileMapper->updateImage($userProfile)) {
1823
                        return new JsonModel([
1824
                            'success'   => false,
1825
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1826
                        ]);
1827
                    }
1828
 
3163 efrain 1829
                    if($userProfile->public == UserProfile::PUBLIC_YES) {
1 www 1830
 
1831
                        $currentUser->image = $target_filename;
1832
 
1833
                        $userMapper = UserMapper::getInstance($this->adapter);
3163 efrain 1834
                        $userMapper->updateImage($currentUser);
1835
 
1 www 1836
                    }
1837
 
1838
                    $this->logger->info('Se actualizo el image del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1839
 
1840
                } else {
1841
                    $messages = [];
1842
                    $form_messages = (array) $form->getMessages();
1843
                    foreach($form_messages  as $fieldname => $field_messages)
1844
                    {
1845
                        $messages[$fieldname] = array_values($field_messages);
1846
                    }
1847
 
1848
                    return new JsonModel([
1849
                        'success'   => false,
1850
                        'data'   => $messages
1851
                    ]);
1852
                }
1853
            }
1854
            return new JsonModel([
1855
                'success'   => true,
1856
                'data' => [
1857
                    'user' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $currentUser->uuid, 'filename' => $currentUser->image]),
1858
                    'profile' => $this->url()->fromRoute('storage', ['type' => 'user-profile', 'code' => $currentUser->uuid, 'filename' => $userProfile->image]),
3163 efrain 1859
                    'update_navbar' =>  $userProfile->public == UserProfile::PUBLIC_YES ? 1 : 0,
1 www 1860
 
1861
                ]
1862
            ]);
1863
        }
1864
 
1865
 
1866
        $data = [
1867
            'success' => false,
1868
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1869
        ];
1870
 
1871
 
1872
        return new JsonModel($data);
1873
    }
1874
 
1875
    /**
1876
     * Cambio de la imagen de fondo superior (cover) del perfil
1877
     * @return \Laminas\View\Model\JsonModel
1878
     */
1879
    public function coverAction()
1880
    {
1881
        $user_profile_id    = $this->params()->fromRoute('id');
1882
        $operation          = $this->params()->fromRoute('operation');
1883
 
1884
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
1885
 
1886
        $userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
1887
        if(!$userProfile) {
1888
            $response = [
1889
                'success' => false,
1890
                'data' => 'ERROR_INVALID_PARAMETER'
1891
            ];
1892
 
1893
            return new JsonModel($response);
1894
 
1895
        }
1896
 
1897
 
1898
        $currentUser = $this->plugin('currentUserPlugin');
1899
        $currentUser = $currentUser->getUser();
1900
 
1901
        if($currentUser->id != $userProfile->user_id) {
1902
            $response = [
1903
                'success' => false,
1904
                'data' => 'ERROR_UNAUTHORIZED'
1905
            ];
1906
 
1907
            return new JsonModel($response);
1908
        }
1909
 
1910
 
1911
 
1912
        $request = $this->getRequest();
1913
        if($request->isPost()) {
1914
            $target_path = $this->config['leaderslinked.fullpath.user'] . $currentUser->uuid;
1915
 
1916
            if($operation == 'delete') {
1917
                if($userProfile->cover) {
1918
                    if(!Image::delete($target_path, $userProfile->cover)) {
1919
                        return new JsonModel([
1920
                            'success'   => false,
1921
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1922
                        ]);
1923
                    }
1924
                }
1925
 
1926
                $this->logger->info('Se borro el cover del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1927
                $userProfile->cover = '';
1928
 
1929
            } else {
1930
                $form = new CoverForm($this->config);
1931
                $data 	= array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
1932
 
1933
 
1934
 
1935
                $form->setData($data);
1936
 
1937
                if($form->isValid()) {
1938
 
1939
                    $files = $request->getFiles()->toArray();
1940
                    if(!empty($files['cover']['error'])) {
1941
 
1942
                        return new JsonModel([
1943
                            'success'   => false,
1944
                            'data'   =>  'ERROR_UPLOAD_FILE'
1945
                        ]);
1946
 
1947
 
1948
                    }
1949
 
1950
 
1951
                    if($userProfile->cover) {
1952
                        if(!Image::delete($target_path, $userProfile->cover)) {
1953
                            return new JsonModel([
1954
                                'success'   => false,
1955
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1956
                            ]);
1957
                        }
1958
                    }
1959
 
1960
                    //echo '$target_path = ' . $target_path . ' cover =  ' . $userProfile->cover;
1961
                    //exit;
1962
 
1963
                    list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.user_cover_size']);
1964
                    $target_filename = 'user-cover-' . uniqid() . '.png';
1965
                    $source = $files['cover']['tmp_name'];
1966
                    $crop_to_dimensions = false;
1967
 
1968
                    if(!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions )) {
1969
                        return new JsonModel([
1970
                            'success'   => false,
1971
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1972
                        ]);
1973
                    }
1974
 
1975
                    $userProfile->cover = $target_filename;
1976
 
1977
 
1978
                    if(!$userProfileMapper->updateCover($userProfile)) {
1979
                        return new JsonModel([
1980
                            'success'   => false,
1981
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1982
                        ]);
1983
                    }
1984
 
1985
 
1986
                    $this->logger->info('Se actualizo el cover del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
1987
 
1988
                } else {
1989
                    $messages = [];
1990
                    $form_messages = (array) $form->getMessages();
1991
                    foreach($form_messages  as $fieldname => $field_messages)
1992
                    {
1993
                        $messages[$fieldname] = array_values($field_messages);
1994
                    }
1995
 
1996
                    return new JsonModel([
1997
                        'success'   => false,
1998
                        'data'   => $messages
1999
                    ]);
2000
                }
2001
            }
2002
            return new JsonModel([
2003
                'success'   => true,
2004
                'data' => $this->url()->fromRoute('storage', ['type' => 'user-cover', 'code' => $currentUser->uuid, 'filename' => $userProfile->cover])
2005
 
2006
            ]);
2007
        }
2008
 
2009
 
2010
        $data = [
2011
            'success' => false,
2012
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2013
        ];
2014
 
2015
 
2016
        return new JsonModel($data);
2017
    }
2018
 
2019
}