Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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