Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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