Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6749 | Rev 6849 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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