Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6849 | | Comparar con el anterior | Ultima modificación | Ver Log |

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