Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17313 Rev 17314
Línea 994... Línea 994...
994
     */
994
     */
995
    public function coverAction()
995
    public function coverAction()
996
    {
996
    {
997
        $operation          = $this->params()->fromRoute('operation');
997
        $operation          = $this->params()->fromRoute('operation');
Línea 998... Línea -...
998
 
-
 
999
 
998
 
1000
        $currentUserPlugin = $this->plugin('currentUserPlugin');
999
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1001
        $currentUser = $currentUserPlugin->getUser();
1000
        $currentUser = $currentUserPlugin->getUser();
Línea 1002... Línea -...
1002
        $currentCompany = $currentUserPlugin->getCompany();
-
 
1003
 
-
 
1004
 
-
 
1005
 
1001
        $currentCompany = $currentUserPlugin->getCompany();
-
 
1002
 
1006
 
1003
        $request = $this->getRequest();
Línea 1007... Línea 1004...
1007
        $request = $this->getRequest();
1004
 
1008
        if ($request->isPost()) {
1005
        if ($request->isPost()) {
-
 
1006
 
Línea 1009... Línea 1007...
1009
 
1007
            $storage = Storage::getInstance($this->config, $this->adapter);
1010
            $image = Image::getInstance($this->config);
1008
            $target_company_path = $storage->getPathCompany();
Línea 1011... Línea 1009...
1011
            $target_path = $image->getStorage()->getPathCompany();
1009
            $target_user_path = $storage->getPathUser();
Línea 1012... Línea -...
1012
 
-
 
1013
            $companyMapper = CompanyMapper::getInstance($this->adapter);
-
 
1014
            $company = $companyMapper->fetchOne($currentCompany->id);
-
 
1015
 
1010
 
1016
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
1011
            $companyMapper = CompanyMapper::getInstance($this->adapter);
Línea 1017... Línea 1012...
1017
 
1012
            $company = $companyMapper->fetchOne($currentCompany->id);
1018
 
1013
 
1019
 
1014
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
1020
 
1015
 
1021
            if ($operation == 'delete') {
1016
            if ($operation == 'delete') {
1022
                if ($company->cover) {
1017
                if ($company->cover) {
1023
 
1018
 
Línea 1024... Línea 1019...
1024
                    if (!$image->getStorage()->deleteFile($target_path, $company->uuid, $company->cover)) {
1019
                    if (!$storage->deleteFile($target_company_path, $company->uuid, $company->cover)) {
-
 
1020
                        return new JsonModel([
1025
                        return new JsonModel([
1021
                            'success'   => false,
1026
                            'success'   => false,
1022
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1027
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1023
                        ]);
1028
                        ]);
1024
                    }
1029
                    }
1025
                }
1030
                }
1026
 
1031
 
1027
                $this->logger->info('Se borro el cover de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1032
                $this->logger->info('Se borro el cover de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1028
 
1033
                $company->cover = '';
1029
                $company->cover = '';
1034
                if (!$companyMapper->updateCover($company)) {
1030
                if (!$companyMapper->updateCover($company)) {
Línea 1035... Línea 1031...
1035
                    return new JsonModel([
1031
                    return new JsonModel([
-
 
1032
                        'success'   => false,
Línea 1036... Línea 1033...
1036
                        'success'   => false,
1033
                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
Línea 1037... Línea -...
1037
                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
1038
                    ]);
-
 
1039
                }
1034
                    ]);
Línea 1040... Línea 1035...
1040
            } else {
1035
                }
1041
                $form = new ProfileCoverForm($this->config);
1036
            } else {
1042
                $data     = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
1037
                $form = new ProfileCoverForm($this->config);
1043
 
1038
                $files = $request->getFiles()->toArray();
1044
                $form->setData($data);
1039
 
Línea 1045... Línea -...
1045
 
-
 
1046
                if ($form->isValid()) {
-
 
1047
 
1040
                $form->setData($files);
1048
 
1041
                $storage->setFiles($files);
1049
                    $files = $request->getFiles()->toArray();
-
 
1050
                    if (!empty($files['cover']['error'])) {
-
 
1051
 
-
 
1052
                        return new JsonModel([
-
 
1053
                            'success'   => false,
-
 
1054
                            'data'   =>  'ERROR_UPLOAD_FILE'
-
 
1055
                        ]);
-
 
1056
                    }
-
 
1057
 
-
 
1058
                    if ($company->cover) {
-
 
1059
 
-
 
1060
                        if (!Image::delete($target_path, $company->cover)) {
-
 
1061
                            return new JsonModel([
-
 
1062
                                'success'   => false,
1042
 
1063
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1043
                if ($form->isValid()) {
1064
                            ]);
1044
 
1065
                        }
1045
                    if (!empty($files['cover']['error'])) {
1066
                    }
1046
 
Línea -... Línea 1047...
-
 
1047
                        return new JsonModel([
-
 
1048
                            'success'   => false,
-
 
1049
                            'data'   =>  'ERROR_UPLOAD_FILE'
-
 
1050
                        ]);
-
 
1051
                    }
-
 
1052
 
-
 
1053
                    // Verificar y establecer el nombre de archivo actual
-
 
1054
                    if (!$storage->setCurrentFilename('image')) {
-
 
1055
                        return new JsonModel([
Línea 1067... Línea 1056...
1067
 
1056
                            'success'   => false,
1068
                    list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.company_cover_size']);
1057
                            'data'   => 'ERROR_UPLOAD_FILE'
1069
                    $source             = $files['cover']['tmp_name'];
1058
                        ]);
1070
                    $target_filename    = 'company-cover-' . uniqid() . '.png';
1059
                    }
1071
                    $crop_to_dimensions = false;
1060
 
1072
                    $unlink_source = true;
1061
                    // Obtener dimensiones objetivo para el redimensionamiento
1073
 
1062
                    list($target_width_str, $target_height_str) = explode('x', $this->config['leaderslinked.image_sizes.company_cover_size']);
Línea -... Línea 1063...
-
 
1063
                    $target_width = (int)$target_width_str;
-
 
1064
                    $target_height = (int)$target_height_str;
-
 
1065
 
-
 
1066
                    // Generar nombres de archivo únicos
-
 
1067
                    $source = $storage->getTmpFilename();
-
 
1068
                    $filename = 'company-cover-' . uniqid() . '.png';
Línea 1074... Línea -...
1074
                    if ($image->uploadProcessChangeSize($source, $target_path, $company->uuid, $target_filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
-
 
-
 
1069
                    $target_filename = $storage->composePathToFilename(Storage::TYPE_COMPANY, $company->uuid, $filename);
-
 
1070
 
-
 
1071
                    // Subir y redimensionar la imagen  
-
 
1072
                    if ($storage->uploadImageResize($source, $target_filename, $target_width, $target_height)) {
Línea 1075... Línea 1073...
1075
                        return new JsonModel([
1073
                        return new JsonModel([
1076
                            'success'   => false,
1074
                            'success'   => false,
1077
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1075
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1078
                        ]);
1076
                        ]);
Línea 1103... Línea 1101...
1103
                        'data'   => $messages
1101
                        'data'   => $messages
1104
                    ]);
1102
                    ]);
1105
                }
1103
                }
1106
            }
1104
            }
Línea 1107... Línea -...
1107
 
-
 
1108
            $storage = Storage::getInstance($this->config, $this->adapter);
-
 
1109
 
-
 
1110
 
1105
 
1111
            return new JsonModel([
1106
            return new JsonModel([
1112
                'success'   => true,
1107
                'success'   => true,
Línea 1113... Línea 1108...
1113
                'data' => $storage->getCompanyCover($company)
1108
                'data' => $storage->getCompanyCover($company)