Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 558 Rev 596
Línea 67... Línea 67...
67
    /**
67
    /**
68
     *
68
     *
69
     * @var \Laminas\Db\Adapter\AdapterInterface
69
     * @var \Laminas\Db\Adapter\AdapterInterface
70
     */
70
     */
71
    private $adapter;
71
    private $adapter;
72
    
72
 
73
    /**
73
    /**
74
     *
74
     *
75
     * @var \LeadersLinked\Cache\CacheInterface
75
     * @var \LeadersLinked\Cache\CacheInterface
76
     */
76
     */
77
    private $cache;
77
    private $cache;
78
    
78
 
79
    
79
 
80
    /**
80
    /**
81
     *
81
     *
82
     * @var \Laminas\Log\LoggerInterface
82
     * @var \Laminas\Log\LoggerInterface
83
     */
83
     */
84
    private $logger;
84
    private $logger;
85
    
85
 
86
    /**
86
    /**
87
     *
87
     *
88
     * @var array
88
     * @var array
89
     */
89
     */
90
    private $config;
90
    private $config;
91
    
91
 
92
    
92
 
93
    /**
93
    /**
94
     *
94
     *
95
     * @var \Laminas\Mvc\I18n\Translator
95
     * @var \Laminas\Mvc\I18n\Translator
96
     */
96
     */
97
    private $translator;
97
    private $translator;
98
    
98
 
99
    
99
 
100
    /**
100
    /**
101
     *
101
     *
102
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
102
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
103
     * @param \LeadersLinked\Cache\CacheInterface $cache
103
     * @param \LeadersLinked\Cache\CacheInterface $cache
104
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
104
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
Línea 120... Línea 120...
120
     * {@inheritDoc}
120
     * {@inheritDoc}
121
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
121
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
122
     */
122
     */
123
    public function indexAction()
123
    public function indexAction()
124
    {
124
    {
-
 
125
        // Obtener el usuario actual del sistema
125
        $currentUserPlugin = $this->plugin('currentUserPlugin');
126
        $currentUserPlugin = $this->plugin('currentUserPlugin');
126
        $currentUser = $currentUserPlugin->getUser();
127
        $currentUser = $currentUserPlugin->getUser();
Línea -... Línea 128...
-
 
128
 
127
 
129
        // Obtener la petición HTTP
128
        $request = $this->getRequest();
130
        $request = $this->getRequest();
-
 
131
        if ($request->isGet()) {
-
 
132
            // Sanitizar el parámetro de búsqueda si existe
Línea 129... Línea 133...
129
        if ($request->isGet()) {
133
            $search = Functions::sanitizeFilterString($this->params()->fromQuery('search'));
130
 
-
 
131
                $search = Functions::sanitizeFilterString($this->params()->fromQuery('search'));
-
 
132
 
134
 
-
 
135
            // Obtener el control de acceso (ACL) para verificar permisos
133
 
136
            $acl = $this->getEvent()->getViewModel()->getVariable('acl');
134
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
137
            // Verificar permisos para diferentes acciones
135
                $allowView = $acl->isAllowed($currentUser->usertype_id, 'profile/view');
138
            $allowView = $acl->isAllowed($currentUser->usertype_id, 'profile/view');
136
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'profile/my-profiles/edit');
-
 
137
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'profile/my-profiles/delete');
-
 
138
 
-
 
Línea 139... Línea 139...
139
                
139
            $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'profile/my-profiles/edit');
140
                $storage = Storage::getInstance($this->config, $this->adapter);
140
            $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'profile/my-profiles/delete');
141
 
-
 
142
                $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
-
 
143
                $records  = $userProfileMapper->fetchAllByUserIdAndSearch($currentUser->id, $search);
-
 
144
 
-
 
Línea 145... Línea -...
145
 
-
 
146
                $items = [];
-
 
147
                foreach ($records as $record) {
141
 
148
 
142
            // Inicializar el sistema de almacenamiento para manejar imágenes
149
                    $item = [
143
            $storage = Storage::getInstance($this->config, $this->adapter);
150
                        'id' => $record->id,
144
 
151
                        'name' => $record->name,
-
 
152
                        'image' => $storage->getUserProfileImage($currentUser, $record),
-
 
153
                        'link_view' => $allowView ? $this->url()->fromRoute('profile/view', ['id' => $record->uuid])  : '',
-
 
154
                        'link_edit' => $allowEdit ? $this->url()->fromRoute('profile/my-profiles/edit', ['id' => $record->uuid])  : '',
-
 
155
                        'link_delete' => $allowDelete && $record->public == UserProfile::PUBLIC_NO ? $this->url()->fromRoute('profile/my-profiles/delete', ['id' => $record->uuid]) : '',
-
 
Línea -... Línea 145...
-
 
145
            // Obtener el mapper de perfiles de usuario
-
 
146
            $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
-
 
147
            // Obtener todos los perfiles del usuario actual, opcionalmente filtrados por búsqueda
-
 
148
            $records  = $userProfileMapper->fetchAllByUserIdAndSearch($currentUser->id, $search);
-
 
149
 
-
 
150
            // Preparar el array de items para la respuesta
-
 
151
            $items = [];
-
 
152
            foreach ($records as $record) {
-
 
153
                // Construir cada item con la información del perfil
-
 
154
                $item = [
-
 
155
                    'id' => $record->id,
-
 
156
                    'name' => $record->name,
Línea -... Línea 157...
-
 
157
                    'image' => $storage->getUserProfileImage($currentUser, $record),
-
 
158
                    'link_view' => $allowView ? $this->url()->fromRoute('profile/view', ['id' => $record->uuid])  : '',
Línea -... Línea 159...
-
 
159
                    'link_edit' => $allowEdit ? $this->url()->fromRoute('profile/my-profiles/edit', ['id' => $record->uuid])  : '',
156
                    ];
160
                    'link_delete' => $allowDelete && $record->public == UserProfile::PUBLIC_NO ? $this->url()->fromRoute('profile/my-profiles/delete', ['id' => $record->uuid]) : '',
157
 
161
                ];
158
                    array_push($items, $item);
162
 
159
                }
163
                array_push($items, $item);
Línea 160... Línea 164...
160
 
164
            }
161
 
-
 
162
 
165
 
-
 
166
            // Preparar la respuesta exitosa con los items
163
                $response = [
167
            $response = [
164
                    'success' => true,
168
                'success' => true,
165
                    'data' => $items
169
                'data' => $items
166
                ];
170
            ];
167
 
171
 
Línea 269... Línea 273...
269
        }
273
        }
Línea 270... Línea 274...
270
 
274
 
271
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
275
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
272
        $userProfile = $userProfileMapper->fetchOneByUuid($id);
276
        $userProfile = $userProfileMapper->fetchOneByUuid($id);
273
        if (!$userProfile) {
277
        if (!$userProfile) {
274
             // Use helper for consistency
278
            // Use helper for consistency
275
            return $this->_createSimpleErrorResponse('ERROR_RECORD_NOT_FOUND');
279
            return $this->_createSimpleErrorResponse('ERROR_RECORD_NOT_FOUND');
Línea 276... Línea 280...
276
        }
280
        }
277
 
281
 
278
        // Authorize: Check if current user owns the profile
282
        // Authorize: Check if current user owns the profile
279
        if ($currentUser->id != $userProfile->user_id) {
283
        if ($currentUser->id != $userProfile->user_id) {
280
             // Use helper for consistency
284
            // Use helper for consistency
Línea 281... Línea 285...
281
            return $this->_createSimpleErrorResponse('ERROR_UNAUTHORIZED');
285
            return $this->_createSimpleErrorResponse('ERROR_UNAUTHORIZED');
282
        }
286
        }
Línea 302... Línea 306...
302
                }
306
                }
303
            }
307
            }
304
            $cover_deleted = true;
308
            $cover_deleted = true;
305
            if ($userProfile->cover) {
309
            if ($userProfile->cover) {
306
                $cover_deleted = $storage->deleteFile($target_path, $user_uuid, $userProfile->cover);
310
                $cover_deleted = $storage->deleteFile($target_path, $user_uuid, $userProfile->cover);
307
                 if (!$cover_deleted) {
311
                if (!$cover_deleted) {
308
                    $this->logger->err("Failed to delete profile cover file: {$target_path}/{$user_uuid}/{$userProfile->cover}", ['user_id' => $userProfile->user_id]);
312
                    $this->logger->err("Failed to delete profile cover file: {$target_path}/{$user_uuid}/{$userProfile->cover}", ['user_id' => $userProfile->user_id]);
309
                    // Decide if this is a critical error. Proceeding with DB deletion for now.
313
                    // Decide if this is a critical error. Proceeding with DB deletion for now.
310
                }
314
                }
311
            }
315
            }
Línea 332... Línea 336...
332
        // Return JsonModel for all paths
336
        // Return JsonModel for all paths
333
        return $data instanceof JsonModel ? $data : new JsonModel($data);
337
        return $data instanceof JsonModel ? $data : new JsonModel($data);
334
    }
338
    }
Línea 335... Línea 339...
335
 
339
 
336
    /**
340
    /**
-
 
341
     * Presenta el perfil con las opciones de edición de cada sección.
-
 
342
     * Este método:
-
 
343
     * - Obtiene y valida el perfil del usuario
-
 
344
     * - Recopila toda la información relacionada (educación, experiencia, habilidades, etc.)
-
 
345
     * - Prepara los datos para la vista de edición
-
 
346
     * - Genera las URLs necesarias para las diferentes acciones de edición
337
     * Presenta el perfil con las opciónes de edición de cada sección
347
     * 
338
     * @return \Laminas\Http\Response|\Laminas\View\Model\ViewModel|\Laminas\View\Model\JsonModel
348
     * @return \Laminas\Http\Response|\Laminas\View\Model\ViewModel|\Laminas\View\Model\JsonModel
339
     */
349
     */
340
    public function editAction()
350
    public function editAction()
-
 
351
    {
341
    {
352
        // Obtener el usuario actual del sistema
342
        $currentUserPlugin = $this->plugin('currentUserPlugin');
353
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea -... Línea 354...
-
 
354
        $currentUser = $currentUserPlugin->getUser();
343
        $currentUser = $currentUserPlugin->getUser();
355
 
Línea 344... Línea -...
344
 
-
 
-
 
356
        // Obtener el plugin para mensajes flash
345
        $flashMessenger = $this->plugin('FlashMessenger');
357
        $flashMessenger = $this->plugin('FlashMessenger');
346
 
358
 
Línea 347... Línea -...
347
 
-
 
-
 
359
        // Obtener parámetros de la petición
348
        $request = $this->getRequest();
360
        $request = $this->getRequest();
349
        $id = $this->params()->fromRoute('id');
361
        $id = $this->params()->fromRoute('id');
350
 
362
 
351
 
363
        // Validar que se proporcionó un ID
Línea 352... Línea -...
352
        if (!$id) {
-
 
353
            $flashMessenger->addErrorMessage('ERROR_INVALID_PARAMETER');
-
 
-
 
364
        if (!$id) {
354
            return $this->redirect()->toRoute('dashboard');
365
            $flashMessenger->addErrorMessage('ERROR_INVALID_PARAMETER');
355
        }
366
            return $this->redirect()->toRoute('dashboard');
Línea -... Línea 367...
-
 
367
        }
356
 
368
 
357
 
369
        // Obtener el perfil de usuario correspondiente
358
 
370
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
359
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
371
        $userProfile = $userProfileMapper->fetchOneByUuid($id);
Línea -... Línea 372...
-
 
372
 
360
        $userProfile = $userProfileMapper->fetchOneByUuid($id);
373
        // Validar que el perfil existe
361
 
374
        if (!$userProfile) {
362
        if (!$userProfile) {
375
            $flashMessenger->addErrorMessage('ERROR_RECORD_NOT_FOUND');
363
            $flashMessenger->addErrorMessage('ERROR_RECORD_NOT_FOUND');
376
            return $this->redirect()->toRoute('dashboard');
Línea 364... Línea -...
364
            return $this->redirect()->toRoute('dashboard');
-
 
-
 
377
        }
365
        }
378
 
366
 
379
        // Verificar que el usuario actual es el propietario del perfil
367
        if ($currentUser->id != $userProfile->user_id) {
380
        if ($currentUser->id != $userProfile->user_id) {
368
            $flashMessenger->addErrorMessage('ERROR_UNAUTHORIZED');
381
            $flashMessenger->addErrorMessage('ERROR_UNAUTHORIZED');
369
            return $this->redirect()->toRoute('dashboard');
382
            return $this->redirect()->toRoute('dashboard');
370
        }
383
        }
Línea -... Línea 384...
-
 
384
 
371
 
385
        // Determinar la clave de API de Google Maps según el entorno
372
 
-
 
-
 
386
        $sandbox = $this->config['leaderslinked.runmode.sandbox'];
373
        $sandbox = $this->config['leaderslinked.runmode.sandbox'];
387
        if ($sandbox) {
374
        if ($sandbox) {
388
            $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
375
            $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
389
        } else {
Línea 376... Línea 390...
376
        } else {
390
            $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
Línea 388... Línea 402...
388
            } else {
402
            } else {
389
                $formattedAddress = '';
403
                $formattedAddress = '';
390
                $country = '';
404
                $country = '';
391
            }
405
            }
Línea 392... Línea -...
392
 
-
 
393
 
-
 
-
 
406
 
394
 
407
            // Obtener información del usuario
395
            $userMapper = UserMapper::getInstance($this->adapter);
408
            $userMapper = UserMapper::getInstance($this->adapter);
Línea -... Línea 409...
-
 
409
            $user = $userMapper->fetchOne($userProfile->user_id);
396
            $user = $userMapper->fetchOne($userProfile->user_id);
410
 
397
 
411
            // Obtener idiomas del usuario
398
            $userLanguages = [];
412
            $userLanguages = [];
399
            $languageMapper = LanguageMapper::getInstance($this->adapter);
413
            $languageMapper = LanguageMapper::getInstance($this->adapter);
400
            $userLanguageMapper = UserLanguageMapper::getInstance($this->adapter);
414
            $userLanguageMapper = UserLanguageMapper::getInstance($this->adapter);
401
            $records = $userLanguageMapper->fetchAllByUserProfileId($userProfile->id);
415
            $records = $userLanguageMapper->fetchAllByUserProfileId($userProfile->id);
402
            foreach ($records as $record) {
416
            foreach ($records as $record) {
403
                $language = $languageMapper->fetchOne($record->language_id);
417
                $language = $languageMapper->fetchOne($record->language_id);
Línea 404... Línea -...
404
                $userLanguages[$language->id] = $language->name;
-
 
-
 
418
                $userLanguages[$language->id] = $language->name;
405
            }
419
            }
406
 
420
 
407
 
421
            // Obtener educación del usuario
408
            $locationMapper = LocationMapper::getInstance($this->adapter);
422
            $locationMapper = LocationMapper::getInstance($this->adapter);
Línea 409... Línea -...
409
            $degreeMapper = DegreeMapper::getInstance($this->adapter);
-
 
410
            $userEducationMapper = UserEducationMapper::getInstance($this->adapter);
-
 
-
 
423
            $degreeMapper = DegreeMapper::getInstance($this->adapter);
411
            $userEducations = $userEducationMapper->fetchAllByUserProfileId($userProfile->id);
424
            $userEducationMapper = UserEducationMapper::getInstance($this->adapter);
412
 
425
            $userEducations = $userEducationMapper->fetchAllByUserProfileId($userProfile->id);
413
 
426
 
Línea 414... Línea 427...
414
 
427
            // Formatear información de educación
Línea 428... Línea 441...
428
                    'link_edit' => $this->url()->fromRoute('profile/my-profiles/education', ['id' => $userProfile->uuid, 'operation' => 'edit', 'user_education_id' => $userEducation->uuid]),
441
                    'link_edit' => $this->url()->fromRoute('profile/my-profiles/education', ['id' => $userProfile->uuid, 'operation' => 'edit', 'user_education_id' => $userEducation->uuid]),
429
                    'link_delete' => $this->url()->fromRoute('profile/my-profiles/education', ['id' => $userProfile->uuid, 'operation' => 'delete', 'user_education_id' => $userEducation->uuid]),
442
                    'link_delete' => $this->url()->fromRoute('profile/my-profiles/education', ['id' => $userProfile->uuid, 'operation' => 'delete', 'user_education_id' => $userEducation->uuid]),
430
                ];
443
                ];
431
            }
444
            }
Línea -... Línea 445...
-
 
445
 
432
 
446
            // Obtener experiencia laboral del usuario
433
            $industryMapper = IndustryMapper::getInstance($this->adapter);
447
            $industryMapper = IndustryMapper::getInstance($this->adapter);
434
            $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
-
 
435
 
448
            $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
436
            $userExperienceMapper = UserExperienceMapper::getInstance($this->adapter);
449
            $userExperienceMapper = UserExperienceMapper::getInstance($this->adapter);
Línea -... Línea 450...
-
 
450
            $userExperiences = $userExperienceMapper->fetchAllByUserProfileId($userProfile->id);
437
            $userExperiences = $userExperienceMapper->fetchAllByUserProfileId($userProfile->id);
451
 
438
 
452
            // Formatear información de experiencia laboral
439
            foreach ($userExperiences  as &$userExperience) {
453
            foreach ($userExperiences  as &$userExperience) {
440
                $location = $locationMapper->fetchOne($userExperience->location_id);
454
                $location = $locationMapper->fetchOne($userExperience->location_id);
Línea 456... Línea 470...
456
                    'link_edit' => $this->url()->fromRoute('profile/my-profiles/experience', ['id' => $userProfile->uuid, 'operation' => 'edit', 'user_experience_id' => $userExperience->uuid]),
470
                    'link_edit' => $this->url()->fromRoute('profile/my-profiles/experience', ['id' => $userProfile->uuid, 'operation' => 'edit', 'user_experience_id' => $userExperience->uuid]),
457
                    'link_delete' => $this->url()->fromRoute('profile/my-profiles/experience', ['id' => $userProfile->uuid, 'operation' => 'delete', 'user_experience_id' => $userExperience->uuid])
471
                    'link_delete' => $this->url()->fromRoute('profile/my-profiles/experience', ['id' => $userProfile->uuid, 'operation' => 'delete', 'user_experience_id' => $userExperience->uuid])
458
                ];
472
                ];
459
            }
473
            }
Línea -... Línea 474...
-
 
474
 
460
 
475
            // Obtener aptitudes del usuario
461
            $userAptitudes = [];
476
            $userAptitudes = [];
462
            $aptitudeMapper = AptitudeMapper::getInstance($this->adapter);
477
            $aptitudeMapper = AptitudeMapper::getInstance($this->adapter);
463
            $userAptitudeMapper = UserAptitudeMapper::getInstance($this->adapter);
478
            $userAptitudeMapper = UserAptitudeMapper::getInstance($this->adapter);
464
            $records  = $userAptitudeMapper->fetchAllByUserProfileId($userProfile->id);
479
            $records  = $userAptitudeMapper->fetchAllByUserProfileId($userProfile->id);
Línea 467... Línea 482...
467
                if ($aptitude) {
482
                if ($aptitude) {
468
                    $userAptitudes[$aptitude->uuid] = $aptitude->name;
483
                    $userAptitudes[$aptitude->uuid] = $aptitude->name;
469
                }
484
                }
470
            }
485
            }
Línea -... Línea 486...
-
 
486
 
471
 
487
            // Obtener hobbies e intereses del usuario
472
            $userHobbiesAndInterests = [];
488
            $userHobbiesAndInterests = [];
473
            $hobbyAndInterestMapper = HobbyAndInterestMapper::getInstance($this->adapter);
489
            $hobbyAndInterestMapper = HobbyAndInterestMapper::getInstance($this->adapter);
474
            $userHobbyAndInterestMapper = UserHobbyAndInterestMapper::getInstance($this->adapter);
490
            $userHobbyAndInterestMapper = UserHobbyAndInterestMapper::getInstance($this->adapter);
475
            $records  = $userHobbyAndInterestMapper->fetchAllByUserProfileId($userProfile->id);
491
            $records  = $userHobbyAndInterestMapper->fetchAllByUserProfileId($userProfile->id);
Línea 478... Línea 494...
478
                if ($hobbyAndInterest) {
494
                if ($hobbyAndInterest) {
479
                    $userHobbiesAndInterests[$hobbyAndInterest->uuid] = $hobbyAndInterest->name;
495
                    $userHobbiesAndInterests[$hobbyAndInterest->uuid] = $hobbyAndInterest->name;
480
                }
496
                }
481
            }
497
            }
Línea 482... Línea -...
482
 
-
 
-
 
498
 
483
 
499
            // Obtener habilidades del usuario
484
            $userSkills = [];
500
            $userSkills = [];
485
            $userSkillMapper = UserSkillMapper::getInstance($this->adapter);
501
            $userSkillMapper = UserSkillMapper::getInstance($this->adapter);
486
            $skillMapper = SkillMapper::getInstance($this->adapter);
502
            $skillMapper = SkillMapper::getInstance($this->adapter);
487
            $records  = $userSkillMapper->fetchAllByUserProfileId($userProfile->id);
503
            $records  = $userSkillMapper->fetchAllByUserProfileId($userProfile->id);
488
            foreach ($records as $record) {
504
            foreach ($records as $record) {
489
                $skill = $skillMapper->fetchOne($record->skill_id);
505
                $skill = $skillMapper->fetchOne($record->skill_id);
490
                $userSkills[$skill->uuid] = $skill->name;
506
                $userSkills[$skill->uuid] = $skill->name;
Línea 491... Línea -...
491
            }
-
 
-
 
507
            }
492
 
508
 
493
 
509
            // Obtener estadísticas de conexiones
Línea 494... Línea 510...
494
            $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
510
            $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
495
            $following = $companyFollowerMapper->getCountFollowing($user->id);
511
            $following = $companyFollowerMapper->getCountFollowing($user->id);
Línea 496... Línea -...
496
 
-
 
-
 
512
 
497
            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
513
            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
498
            $follower = $connectionMapper->fetchTotalConnectionByUser($user->id);
514
            $follower = $connectionMapper->fetchTotalConnectionByUser($user->id);
Línea -... Línea 515...
-
 
515
 
499
 
516
            // Obtener configuraciones de tamaño de imágenes
Línea -... Línea 517...
-
 
517
            $image_size_cover = $this->config['leaderslinked.image_sizes.user_cover_upload'];
500
 
518
            $image_size_profile = $this->config['leaderslinked.image_sizes.user_upload'];
501
            $image_size_cover = $this->config['leaderslinked.image_sizes.user_cover_upload'];
519
 
502
            $image_size_profile = $this->config['leaderslinked.image_sizes.user_upload'];
520
            // Inicializar el sistema de almacenamiento
503
 
521
            $storage = Storage::getInstance($this->config, $this->adapter);
504
            $storage = Storage::getInstance($this->config, $this->adapter);
522
 
505
 
523
            // Preparar datos para la respuesta
506
                $data = [
524
            $data = [
507
                    'following'         => $following,
525
                'following'         => $following,
508
                    'follower'          => $follower,
526
                'follower'          => $follower,
509
                    'user_id'           => $user->id,
527
                'user_id'           => $user->id,
510
                    'user_uuid'         => $user->uuid,
528
                'user_uuid'         => $user->uuid,
511
                    'full_name'         => trim($user->first_name . ' ' . $user->last_name),
529
                'full_name'         => trim($user->first_name . ' ' . $user->last_name),
512
                    'user_profile_id'   => $userProfile->id,
530
                'user_profile_id'   => $userProfile->id,
513
                    'user_profile_uuid' => $userProfile->uuid,
531
                'user_profile_uuid' => $userProfile->uuid,
514
                    'image'             => $storage->getUserProfileImage($currentUser, $userProfile),
532
                'image'             => $storage->getUserProfileImage($currentUser, $userProfile),
515
                    'cover'             => $storage->getUserProfileCover($currentUser, $userProfile),
533
                'cover'             => $storage->getUserProfileCover($currentUser, $userProfile),
516
                    'overview'          => $userProfile->description,
534
                'overview'          => $userProfile->description,
517
                    'facebook'          => $userProfile->facebook,
535
                'facebook'          => $userProfile->facebook,
518
                    'instagram'         => $userProfile->instagram,
536
                'instagram'         => $userProfile->instagram,
519
                    'twitter'           => $userProfile->twitter,
537
                'twitter'           => $userProfile->twitter,
520
                    'formatted_address' => $formattedAddress,
538
                'formatted_address' => $formattedAddress,
521
                    'country'           => $country,
539
                'country'           => $country,
522
                    'user_skills'       => $userSkills,
540
                'user_skills'       => $userSkills,
523
                    'user_languages'    => $userLanguages,
541
                'user_languages'    => $userLanguages,
524
                    'user_educations'   => $userEducations,
542
                'user_educations'   => $userEducations,
-
 
543
                'user_experiences'  => $userExperiences,
525
                    'user_experiences'  => $userExperiences,
544
                'user_aptitudes'                => $userAptitudes,
526
                    'user_aptitudes'                => $userAptitudes,
545
                'user_hobbies_and_interests'    => $userHobbiesAndInterests,
527
                    'user_hobbies_and_interests'    => $userHobbiesAndInterests,
546
                'image_size_cover' =>  $image_size_cover,
528
                    'image_size_cover' =>  $image_size_cover,
547
                'image_size_profile' => $image_size_profile,
529
                    'image_size_profile' => $image_size_profile,
548
 
530
                    
549
                // Generar URLs para las diferentes acciones de edición
531
                    'link_extended' => $this->url()->fromRoute('profile/my-profiles/extended', ['id' => $userProfile->uuid] ),
550
                'link_extended' => $this->url()->fromRoute('profile/my-profiles/extended', ['id' => $userProfile->uuid]),
532
                    'link_image_upload' => $this->url()->fromRoute('profile/my-profiles/image', ['id' => $userProfile->uuid, 'operation' => 'upload']),
551
                'link_image_upload' => $this->url()->fromRoute('profile/my-profiles/image', ['id' => $userProfile->uuid, 'operation' => 'upload']),
533
                    'link_image_delete' => $this->url()->fromRoute('profile/my-profiles/image', ['id' => $userProfile->uuid, 'operation' => 'delete']),
552
                'link_image_delete' => $this->url()->fromRoute('profile/my-profiles/image', ['id' => $userProfile->uuid, 'operation' => 'delete']),
534
                    'link_cover_upload' => $this->url()->fromRoute('profile/my-profiles/cover', ['id' => $userProfile->uuid, 'operation' => 'upload']),
553
                'link_cover_upload' => $this->url()->fromRoute('profile/my-profiles/cover', ['id' => $userProfile->uuid, 'operation' => 'upload']),
535
                    'link_cover_delete' => $this->url()->fromRoute('profile/my-profiles/cover', ['id' => $userProfile->uuid, 'operation' => 'delete']),
554
                'link_cover_delete' => $this->url()->fromRoute('profile/my-profiles/cover', ['id' => $userProfile->uuid, 'operation' => 'delete']),
536
                    'link_experience_add' => $this->url()->fromRoute('profile/my-profiles/experience', ['id' => $userProfile->uuid, 'operation' => 'add']),
555
                'link_experience_add' => $this->url()->fromRoute('profile/my-profiles/experience', ['id' => $userProfile->uuid, 'operation' => 'add']),
537
                    'link_education_add' => $this->url()->fromRoute('profile/my-profiles/education', ['id' => $userProfile->uuid, 'operation' => 'add']),
556
                'link_education_add' => $this->url()->fromRoute('profile/my-profiles/education', ['id' => $userProfile->uuid, 'operation' => 'add']),
538
                    'link_language' => $this->url()->fromRoute('profile/my-profiles/language', ['id' => $userProfile->uuid]),
-
 
539
                    'link_location' => $this->url()->fromRoute('profile/my-profiles/location', ['id' => $userProfile->uuid]),
557
                'link_language' => $this->url()->fromRoute('profile/my-profiles/language', ['id' => $userProfile->uuid]),
Línea 540... Línea 558...
540
                    'link_skill' => $this->url()->fromRoute('profile/my-profiles/skill', ['id' => $userProfile->uuid] ),
558
                'link_location' => $this->url()->fromRoute('profile/my-profiles/location', ['id' => $userProfile->uuid]),
541
                    'link_social_network' => $this->url()->fromRoute('profile/my-profiles/social-network', ['id' => $userProfile->uuid]),
-
 
542
                    'link_aptitude' => $this->url()->fromRoute('profile/my-profiles/aptitude', ['id' => $userProfile->uuid] ),
559
                'link_skill' => $this->url()->fromRoute('profile/my-profiles/skill', ['id' => $userProfile->uuid]),
-
 
560
                'link_social_network' => $this->url()->fromRoute('profile/my-profiles/social-network', ['id' => $userProfile->uuid]),
543
                    'link_hobby_and_interest' => $this->url()->fromRoute('profile/my-profiles/hobby-and-interest', ['id' => $userProfile->uuid]),
561
                'link_aptitude' => $this->url()->fromRoute('profile/my-profiles/aptitude', ['id' => $userProfile->uuid]),
544
 
562
                'link_hobby_and_interest' => $this->url()->fromRoute('profile/my-profiles/hobby-and-interest', ['id' => $userProfile->uuid]),
545
                ];
563
            ];
546
 
564
 
Línea 1089... Línea 1107...
1089
 
1107
 
1090
        return new JsonModel($data);
1108
        return new JsonModel($data);
Línea 1091... Línea 1109...
1091
    }
1109
    }
Línea 1092... Línea 1110...
1092
 
1110
 
1093
 
1111
 
1094
    
1112
 
1095
 
1113
 
Línea 1581... Línea 1599...
1581
 
1599
 
1582
        return new JsonModel($data);
1600
        return new JsonModel($data);
Línea 1583... Línea 1601...
1583
    }
1601
    }
-
 
1602
 
-
 
1603
    /**
1584
 
1604
     * Maneja la subida y eliminación de la imagen del perfil de usuario.
-
 
1605
     * Este método permite:
-
 
1606
     * - Subir una nueva imagen de perfil
-
 
1607
     * - Eliminar la imagen existente
1585
    /**
1608
     * - Actualizar la imagen principal del usuario si el perfil es público
1586
     * Cambio de la imagen del image del perfil
1609
     * 
1587
     * @return \Laminas\View\Model\JsonModel
1610
     * @return \Laminas\View\Model\JsonModel
1588
     */
1611
     */
-
 
1612
    public function imageAction()
1589
    public function imageAction()
1613
    {
1590
    {
1614
        // Obtener el usuario actual del sistema
Línea -... Línea 1615...
-
 
1615
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1591
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1616
        $currentUser = $currentUserPlugin->getUser();
1592
        $currentUser = $currentUserPlugin->getUser();
1617
 
Línea -... Línea 1618...
-
 
1618
        // Obtener parámetros de la ruta: ID del perfil y operación (upload/delete)
1593
 
1619
        $user_profile_id    = $this->params()->fromRoute('id');
1594
        $user_profile_id    = $this->params()->fromRoute('id');
-
 
1595
        $operation          = $this->params()->fromRoute('operation');
1620
        $operation          = $this->params()->fromRoute('operation');
-
 
1621
 
-
 
1622
        // Obtener el perfil de usuario correspondiente
1596
 
1623
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
1597
        $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
-
 
1598
 
1624
        $userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
1599
        $userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
1625
 
Línea 1600... Línea 1626...
1600
        if (!$userProfile) {
1626
        // Validar que el perfil existe
1601
            // Use helper
1627
        if (!$userProfile) {
1602
            return $this->_createSimpleErrorResponse('ERROR_INVALID_PARAMETER');
-
 
1603
        }
1628
            return $this->_createSimpleErrorResponse('ERROR_INVALID_PARAMETER');
1604
 
1629
        }
Línea -... Línea 1630...
-
 
1630
 
1605
        // Authorize: Check if current user owns the profile
1631
        // Verificar que el usuario actual es el propietario del perfil
1606
        if ($currentUser->id != $userProfile->user_id) {
1632
        if ($currentUser->id != $userProfile->user_id) {
1607
            // Use helper
-
 
-
 
1633
            return $this->_createSimpleErrorResponse('ERROR_UNAUTHORIZED');
1608
            return $this->_createSimpleErrorResponse('ERROR_UNAUTHORIZED');
1634
        }
1609
        }
1635
 
1610
 
1636
        // Procesar solo peticiones POST
1611
        $request = $this->getRequest();
1637
        $request = $this->getRequest();
-
 
1638
        if ($request->isPost()) {
1612
        if ($request->isPost()) {
1639
            // Inicializar el sistema de almacenamiento
-
 
1640
            $storage = Storage::getInstance($this->config, $this->adapter);
1613
            
1641
            $target_path = $storage->getPathUser();
Línea -... Línea 1642...
-
 
1642
            $user_uuid = $currentUser->uuid;
1614
            $storage = Storage::getInstance($this->config, $this->adapter);
1643
 
1615
            $target_path = $storage->getPathUser();
-
 
1616
            $user_uuid = $currentUser->uuid; // Assuming user UUID for path
1644
            // Manejar la eliminación de la imagen
1617
            
-
 
1618
            if ($operation == 'delete') {
1645
            if ($operation == 'delete') {
1619
                $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()]);
1646
                // Registrar la acción en el log
1620
 
1647
                $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()]);
Línea 1621... Línea 1648...
1621
                if ($userProfile->image) {
1648
 
1622
                    // Attempt deletion
1649
                // Si existe una imagen, intentar eliminarla
1623
                    if (!$storage->deleteFile($target_path, $user_uuid, $userProfile->image)) {
1650
                if ($userProfile->image) {
1624
                        // Use helper
-
 
1625
                        return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1651
                    if (!$storage->deleteFile($target_path, $user_uuid, $userProfile->image)) {
1626
                    }
1652
                        return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1627
                }
1653
                    }
-
 
1654
                }
1628
 
1655
 
1629
                // Clear image field and update DB
1656
                // Limpiar el campo de imagen y actualizar la base de datos
Línea 1630... Línea 1657...
1630
                $userProfile->image = '';
1657
                $userProfile->image = '';
Línea 1631... Línea 1658...
1631
                if (!$userProfileMapper->updateImage($userProfile)) {
1658
                if (!$userProfileMapper->updateImage($userProfile)) {
1632
                    // Use helper
-
 
-
 
1659
                    return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1633
                    return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1660
                }
1634
                }
-
 
1635
            } else { // Handle upload
1661
            } else {
1636
                $form = new ImageForm($this->config);
-
 
1637
                $data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
1662
                // Manejar la subida de una nueva imagen
1638
 
1663
                $form = new ImageForm($this->config);
Línea 1639... Línea 1664...
1639
                $form->setData($data);
1664
                $data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
1640
 
1665
 
1641
                if ($form->isValid()) {
1666
                $form->setData($data);
1642
 
1667
 
1643
                    $storage->setFiles($request->getFiles()->toArray());
1668
                if ($form->isValid()) {
-
 
1669
                    // Configurar el archivo para procesamiento
1644
                    // *** FIX: Use correct input field name 'image' ***
1670
                    $storage->setFiles($request->getFiles()->toArray());
1645
                    if (!$storage->setCurrentFilename('image')) { 
1671
                    if (!$storage->setCurrentFilename('image')) {
1646
                        // Use helper
1672
                        return $this->_createSimpleErrorResponse('ERROR_UPLOAD_FILE');
1647
                        return $this->_createSimpleErrorResponse('ERROR_UPLOAD_FILE');
1673
                    }
1648
                    }
1674
 
1649
 
1675
                    // Obtener dimensiones objetivo para el redimensionamiento
1650
                    // Prepare for resize and save
-
 
1651
                    list($target_width_str, $target_height_str) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
1676
                    list($target_width_str, $target_height_str) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
1652
                    $target_width = (int)$target_width_str;
1677
                    $target_width = (int)$target_width_str;
1653
                    $target_height = (int)$target_height_str;
1678
                    $target_height = (int)$target_height_str;
1654
                    
1679
 
1655
                    $source_filename    = $storage->getTmpFilename();
1680
                    // Generar nombres de archivo únicos
1656
                    $filename           = 'user-profile-' . uniqid() . '.png';
1681
                    $source_filename    = $storage->getTmpFilename();
1657
                    $target_filename    = $storage->composePathToFilename(Storage::TYPE_USER, $user_uuid, $filename); 
-
 
1658
                   
1682
                    $filename           = 'user-profile-' . uniqid() . '.png';
1659
                    // Upload, resize, save
1683
                    $target_filename    = $storage->composePathToFilename(Storage::TYPE_USER, $user_uuid, $filename);
1660
                    if (!$storage->uploadImageResize($source_filename, $target_filename, $target_width, $target_height)) {
1684
 
Línea 1661... Línea 1685...
1661
                        // Use helper
1685
                    // Subir y redimensionar la imagen
1662
                        return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1686
                    if (!$storage->uploadImageResize($source_filename, $target_filename, $target_width, $target_height)) {
1663
                    }
1687
                        return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1664
                    
-
 
1665
                    // Delete old image if exists
1688
                    }
1666
                    if ($userProfile->image) {
1689
 
Línea 1667... Línea 1690...
1667
                        if (!$storage->deleteFile($target_path, $user_uuid, $userProfile->image)) {
1690
                    // Eliminar la imagen anterior si existe
1668
                            // Use helper
1691
                    if ($userProfile->image) {
1669
                            return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
-
 
1670
                        }
1692
                        if (!$storage->deleteFile($target_path, $user_uuid, $userProfile->image)) {
1671
                    }
-
 
1672
 
1693
                            return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1673
                    // Update profile model and DB
1694
                        }
1674
                    $userProfile->image = $filename;
1695
                    }
1675
                    if (!$userProfileMapper->updateImage($userProfile)) {
1696
 
1676
                        // Use helper
-
 
1677
                        return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1697
                    // Actualizar el perfil con la nueva imagen
1678
                    }
1698
                    $userProfile->image = $filename;
1679
 
1699
                    if (!$userProfileMapper->updateImage($userProfile)) {
1680
                    // Special handling: If this is the PUBLIC profile, also update the main user image
1700
                        return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1681
                    if ($userProfile->public == UserProfile::PUBLIC_YES) {
1701
                    }
1682
                        
1702
 
1683
                        $main_user_filename = 'user-' . uniqid() . '.png'; // Use different name for safety?
-
 
1684
                        // $source_filename_for_copy = $target_filename; // The newly saved profile image
1703
                    // Si es un perfil público, actualizar también la imagen principal del usuario
1685
                        $target_filename_main_user = $storage->composePathToFilename(Storage::TYPE_USER, $user_uuid, $main_user_filename); 
1704
                    if ($userProfile->public == UserProfile::PUBLIC_YES) {
1686
                        
1705
                        $main_user_filename = 'user-' . uniqid() . '.png';
Línea 1687... Línea 1706...
1687
                        // Copy the *newly processed* profile image to be the main user image
1706
                        $target_filename_main_user = $storage->composePathToFilename(Storage::TYPE_USER, $user_uuid, $main_user_filename);
1688
                        if (!$storage->copyFile($target_filename, $target_filename_main_user)) { // Source is the *new* profile image
1707
 
1689
                            // Use helper
1708
                        // Copiar la imagen del perfil para la imagen principal
1690
                             return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1709
                        if (!$storage->copyFile($target_filename, $target_filename_main_user)) {
1691
                        }
-
 
1692
                        
1710
                            return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1693
                        // Delete the old main user image if it exists
1711
                        }
1694
                        if ($currentUser->image) {
1712
 
Línea -... Línea 1713...
-
 
1713
                        // Eliminar la imagen principal anterior si existe
1695
                            if (!$storage->deleteFile($target_path, $user_uuid, $currentUser->image)) {
1714
                        if ($currentUser->image) {
1696
                                 // Use helper
1715
                            if (!$storage->deleteFile($target_path, $user_uuid, $currentUser->image)) {
1697
                                return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1716
                                return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1698
                            }
1717
                            }
1699
                        }
1718
                        }
1700
 
1719
 
1701
                        // Update current user model and DB
1720
                        // Actualizar la imagen principal del usuario
1702
                        $currentUser->image = $main_user_filename;
1721
                        $currentUser->image = $main_user_filename;
1703
                        $userMapper = UserMapper::getInstance($this->adapter);
-
 
1704
                        if (!$userMapper->updateImage($currentUser)) {
1722
                        $userMapper = UserMapper::getInstance($this->adapter);
1705
                             // Use helper
1723
                        if (!$userMapper->updateImage($currentUser)) {
1706
                             return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1724
                            return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1707
                        }
1725
                        }
1708
                    }
1726
                    }
1709
 
1727
 
1710
                    $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()]);
1728
                    // Registrar la actualización en el log
1711
                } else {
1729
                    $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()]);
1712
                    // Use helper for form errors
1730
                } else {
1713
                    return $this->_createFormErrorResponse($form);
1731
                    // Devolver errores de validación del formulario
Línea 1714... Línea 1732...
1714
                }
1732
                    return $this->_createFormErrorResponse($form);
1715
            } // End upload/delete logic
-
 
1716
            
1733
                }
1717
            // Success response (for both upload and delete)
1734
            }
Línea 1718... Línea 1735...
1718
            // Instantiate storage again just to be safe, though the instance from above should be okay
1735
 
1719
            $storage = Storage::getInstance($this->config, $this->adapter);
1736
            // Devolver respuesta exitosa con las URLs actualizadas
Línea 1764... Línea 1781...
1764
        $request = $this->getRequest();
1781
        $request = $this->getRequest();
1765
        if ($request->isPost()) {
1782
        if ($request->isPost()) {
1766
            $storage = Storage::getInstance($this->config, $this->adapter);
1783
            $storage = Storage::getInstance($this->config, $this->adapter);
1767
            $target_path = $storage->getPathUser(); // Base path for user-specific files
1784
            $target_path = $storage->getPathUser(); // Base path for user-specific files
1768
            $user_uuid = $currentUser->uuid;
1785
            $user_uuid = $currentUser->uuid;
1769
  
1786
 
1770
            // Handle cover deletion operation
1787
            // Handle cover deletion operation
1771
            if ($operation == 'delete') {
1788
            if ($operation == 'delete') {
1772
                if ($userProfile->cover) {
1789
                if ($userProfile->cover) {
1773
                    // Attempt to delete the existing cover file from storage
1790
                    // Attempt to delete the existing cover file from storage
1774
                    if (!$storage->deleteFile($target_path, $user_uuid, $userProfile->cover)) {
1791
                    if (!$storage->deleteFile($target_path, $user_uuid, $userProfile->cover)) {
Línea 1776... Línea 1793...
1776
                    }
1793
                    }
1777
                }
1794
                }
1778
                // Log the deletion action
1795
                // Log the deletion action
1779
                $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()]);
1796
                $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()]);
1780
                $userProfile->cover = ''; // Clear the cover field in the profile model
1797
                $userProfile->cover = ''; // Clear the cover field in the profile model
1781
                
1798
 
1782
                // Persist the cleared cover information to the database
1799
                // Persist the cleared cover information to the database
1783
                if (!$userProfileMapper->updateCover($userProfile)) {
1800
                if (!$userProfileMapper->updateCover($userProfile)) {
1784
                    // Handle error if database update fails for deletion
1801
                    // Handle error if database update fails for deletion
1785
                    return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1802
                    return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1786
                }
1803
                }
Línea 1810... Línea 1827...
1810
 
1827
 
1811
                    // Upload, resize, and save the image
1828
                    // Upload, resize, and save the image
1812
                    if (!$storage->uploadImageResize($source_filename, $target_filename, $target_width, $target_height)) {
1829
                    if (!$storage->uploadImageResize($source_filename, $target_filename, $target_width, $target_height)) {
1813
                        return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1830
                        return $this->_createSimpleErrorResponse('ERROR_THERE_WAS_AN_ERROR');
1814
                    }
1831
                    }
1815
                    
1832
 
1816
                    // If an old cover exists, delete it from storage
1833
                    // If an old cover exists, delete it from storage
1817
                    if ($userProfile->cover) {
1834
                    if ($userProfile->cover) {
1818
                        if (!$storage->deleteFile($target_path, $user_uuid, $userProfile->cover)) {
1835
                        if (!$storage->deleteFile($target_path, $user_uuid, $userProfile->cover)) {
1819
                            // Decide if this is a critical error. Original code returns error.
1836
                            // Decide if this is a critical error. Original code returns error.
Línea 1834... Línea 1851...
1834
                } else {
1851
                } else {
1835
                    // Form is invalid, return validation messages
1852
                    // Form is invalid, return validation messages
1836
                    return $this->_createFormErrorResponse($form);
1853
                    return $this->_createFormErrorResponse($form);
1837
                }
1854
                }
1838
            } // End of upload/delete specific logic
1855
            } // End of upload/delete specific logic
1839
            
1856
 
1840
            // Successful operation (upload or delete has been handled and persisted)
1857
            // Successful operation (upload or delete has been handled and persisted)
1841
            // Return success response with the current cover URL (new, or default after delete)
1858
            // Return success response with the current cover URL (new, or default after delete)
1842
            // The $storage instance from the beginning of the POST block is still valid.
1859
            // The $storage instance from the beginning of the POST block is still valid.
1843
            return new JsonModel([
1860
            return new JsonModel([
1844
                'success'   => true,
1861
                'success'   => true,
Línea 2105... Línea 2122...
2105
     */
2122
     */
2106
    private function _createSimpleErrorResponse($errorMessageKey)
2123
    private function _createSimpleErrorResponse($errorMessageKey)
2107
    {
2124
    {
2108
        return new JsonModel([
2125
        return new JsonModel([
2109
            'success' => false,
2126
            'success' => false,
2110
            'data'    => $errorMessageKey 
2127
            'data'    => $errorMessageKey
2111
        ]);
2128
        ]);
2112
    }
2129
    }
Línea 2113... Línea 2130...
2113
 
2130
 
2114
    /**
2131
    /**