Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6822 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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