From 5e691e026613d9c0ae73b6bbba164845fefeea36 Mon Sep 17 00:00:00 2001 From: Armand Bahi <armand.bahi@veremes.com> Date: Tue, 5 Feb 2019 15:36:24 +0100 Subject: [PATCH] =?UTF-8?q?Resolve=20"Ajout=20de=20plusieurs=20documents?= =?UTF-8?q?=20simultan=C3=A9s"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/vmap/tools/select/select.js | 29 ++++--- web_service/ws/Map.class.inc | 10 +-- web_service/ws/Maps.class.inc | 82 ++++------------- web_service/ws/Querys.class.inc | 42 +++------ web_service/ws/Services.class.inc | 87 +++++-------------- 5 files changed, 76 insertions(+), 174 deletions(-) diff --git a/module/javascript/app/vmap/tools/select/select.js b/module/javascript/app/vmap/tools/select/select.js index 6438fce7..9abfe9a3 100755 --- a/module/javascript/app/vmap/tools/select/select.js +++ b/module/javascript/app/vmap/tools/select/select.js @@ -1556,7 +1556,7 @@ nsVmap.nsToolsManager.Select.prototype.selectController.prototype.updateBOValues 'method': 'PUT', 'url': oVmap['properties']['api_url'] + '/vmap/querys/' + bo_type, 'headers': { - 'Accept': 'application/x-vm-json' + 'Accept': 'application/x-vm-json', }, 'data': data, 'scope': this.$scope_, @@ -1647,8 +1647,14 @@ nsVmap.nsToolsManager.Select.prototype.selectController.prototype.getFormData = nsVmap.nsToolsManager.Select.prototype.selectController.prototype.getFormDataFromValues = function (oValues) { oVmap.log('nsVmap.nsToolsManager.Select.prototype.selectController.prototype.getFormDataFromValues'); - var oFormData_ = new FormData(); + var formSrvc = angular.element(vitisApp.appMainDrtv).injector().get(["formSrvc"]); + return formSrvc['getFormDataFromValues'](oValues); +}; +nsVmap.nsToolsManager.Select.prototype.selectController.prototype.getUnchangedFilesFromValues = function (oValues) { + oVmap.log('nsVmap.nsToolsManager.Select.prototype.selectController.prototype.getUnchangedFilesFromValues'); + + var oUnchangedFiles = {}; for (var key in oValues) { var bIsMultipleFiles = false; @@ -1659,19 +1665,22 @@ nsVmap.nsToolsManager.Select.prototype.selectController.prototype.getFormDataFro } // Fichier ? - if (goog.isDefAndNotNull(oValues[key]['aFiles'])) { - oFormData_.append(key + '_attached_content', oValues[key]['aFiles'][0]); - oFormData_.append(key, oValues[key]['aFiles'][0]['name']); - } else if (bIsMultipleFiles) { + if (bIsMultipleFiles) { for (var i = 0; i < oValues[key].length; i++) { - oFormData_.append(key + '[]', oValues[key][i]); + if (oValues[key][i]._modified === false) { + + if (!goog.isArray(oUnchangedFiles[key])) { + oUnchangedFiles[key] = []; + } + + oUnchangedFiles[key].push(oValues[key][i]['name']); + + } } - } else { - oFormData_.append(key, oValues[key]); } } - return oFormData_; + return oUnchangedFiles; }; /** diff --git a/web_service/ws/Map.class.inc b/web_service/ws/Map.class.inc index f57f5945..a3a8371b 100755 --- a/web_service/ws/Map.class.inc +++ b/web_service/ws/Map.class.inc @@ -12,7 +12,7 @@ require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vitis_lib/Connection * \brief This file contains the Map php class * * This class defines operation for one Map - * + * */ class Map extends Vmap { @@ -32,7 +32,7 @@ class Map extends Vmap { } /** - * @SWG\Get(path="/maps/{map_id}", + * @SWG\Get(path="/maps/{map_id}", * tags={"Maps"}, * summary="Get Map", * description="Request to get Map by id", @@ -65,7 +65,7 @@ class Map extends Vmap { */ function GET() { require $this->sRessourcesFile; - $this->aFields = $this->getFields($this->aProperties['schema_vmap'], 'v_map', 'map_id'); + $this->aFields = $this->getFields($this->aProperties['schema_vmap'], 'v_map', 'map_id', 'vmap_admin_map_vmap_admin_map'); $this->getGroups(); } @@ -94,7 +94,7 @@ class Map extends Vmap { $this->aFields['groups_label'] = implode(',', $aListGroupName); } } - + /** * delete a map */ @@ -116,4 +116,4 @@ class Map extends Vmap { } } -?> \ No newline at end of file +?> diff --git a/web_service/ws/Maps.class.inc b/web_service/ws/Maps.class.inc index 59edd049..5c1c649f 100755 --- a/web_service/ws/Maps.class.inc +++ b/web_service/ws/Maps.class.inc @@ -9,7 +9,7 @@ * \brief This file contains the Maps php class * * This class defines Rest Api to Vmap Maps - * + * */ require_once 'Vmap.class.inc'; require_once 'Map.class.inc'; @@ -195,45 +195,18 @@ class Maps extends Vmap { function POST() { require $this->sRessourcesFile; - // Vignette à uploader ? - if (!empty($_FILES['thumbnail'])) { - // la colonne thumbnail vaudra le nom du fichier - $this->aValues["thumbnail"] = $_FILES['thumbnail']["name"]; - } + // Fichiers à uploader + $aUploadFiles = array( + 'thumbnail' => [] + ); - // Redimmensionnement de l'image. if (!empty($this->aValues['thumbnail_width']) && !empty($this->aValues['thumbnail_height'])) { - // Renomme l'image en jpg - $aPointsArray = explode('.', $this->aValues["thumbnail"]); - $aPointsArray[count($aPointsArray) - 1] = 'jpg'; - $this->aValues["thumbnail"] = join('.', $aPointsArray); + $aUploadFiles['thumbnail']['width'] = $this->aValues['thumbnail_width']; + $aUploadFiles['thumbnail']['height'] = $this->aValues['thumbnail_height']; } // Création de la carte. - $aReturn = $this->genericPost($this->aProperties['schema_vmap'], 'map', $this->aProperties['schema_vmap'] . '.seq_common', 'map_id'); - - // Vignette à uploader ? - if (!empty($_FILES['thumbnail'])) { - $sImageDir = $this->aProperties['ws_data_dir'] . '/vitis/vmap_admin_map_vmap_admin_map/documents/' . $this->aValues["my_vitis_id"] . '/thumbnail/' . $_FILES['thumbnail']["name"]; - - // Crée les répertoires si ils n'existent pas - $sDirPath = $this->createElementFilesFolder('vmap_admin_map_vmap_admin_map', $this->aValues["my_vitis_id"]); - $sDirColumnPath = $sDirPath . '/thumbnail'; - if (!is_dir($sDirColumnPath)) { - mkdir($sDirColumnPath, 0777, true); - } - - $sErrorMessage = uploadFile("thumbnail", "", $sImageDir, $_FILES['thumbnail']['size'] + 1); - - if ($sErrorMessage != "") { - writeToErrorLog($sErrorMessage); - } else { - // Redimmensionnement de l'image. - if (!empty($this->aValues['thumbnail_width']) && !empty($this->aValues['thumbnail_height'])) { - $this->pictureResampler($sImageDir, $this->aValues['thumbnail_width'], $this->aValues['thumbnail_height']); - } - } - } + $aReturn = $this->genericPost($this->aProperties['schema_vmap'], 'map', $this->aProperties['schema_vmap'] . '.seq_common', 'map_id', $aUploadFiles, 'vmap_admin_map_vmap_admin_map'); // Si création OK -> maj des groupes rattachés à la carte. if ($aReturn['sStatus'] == 1) { @@ -342,7 +315,7 @@ class Maps extends Vmap { * description="Poprerties Response", * @SWG\Schema(ref="#/definitions/maps") * ), - * + * * ) */ @@ -352,35 +325,18 @@ class Maps extends Vmap { */ function PUT() { require $this->sRessourcesFile; - // Vignette à uploader ? - if (!empty($this->aValues["thumbnail_file"])) { - - $sImageDir = $this->aProperties['ws_data_dir'] . '/vitis/vmap_admin_map_vmap_admin_map/documents/' . $this->aValues["my_vitis_id"] . '/thumbnail/' . $this->aValues["thumbnail_name"]; - - // Crée les répertoires si ils n'existent pas - $sDirPath = $this->createElementFilesFolder('vmap_admin_map_vmap_admin_map', $this->aValues["my_vitis_id"]); - $sDirColumnPath = $sDirPath . '/thumbnail'; - if (!is_dir($sDirColumnPath)) { - mkdir($sDirColumnPath, 0777, true); - } - // la colonne thumbnail vaudra le nom du fichier - $this->aValues["thumbnail"] = $this->aValues["thumbnail_name"]; - $fp = fopen($sImageDir, "w"); - fwrite($fp, $this->aValues["thumbnail_file"]); - fclose($fp); - - // Redimmensionnement de l'image. - if (!empty($this->aValues['thumbnail_width']) && !empty($this->aValues['thumbnail_height'])) { - $this->pictureResampler($sImageDir, $this->aValues['thumbnail_width'], $this->aValues['thumbnail_height']); - // Renomme l'image en jpg - $aPointsArray = explode('.', $this->aValues["thumbnail"]); - $aPointsArray[count($aPointsArray) - 1] = 'jpg'; - $this->aValues["thumbnail"] = join('.', $aPointsArray); - } + // Fichiers à uploader + $aUploadFiles = array( + 'thumbnail' => [] + ); + if (!empty($this->aValues['thumbnail_width']) && !empty($this->aValues['thumbnail_height'])) { + $aUploadFiles['thumbnail']['width'] = $this->aValues['thumbnail_width']; + $aUploadFiles['thumbnail']['height'] = $this->aValues['thumbnail_height']; } + // Mise à jour. - $aReturn = $this->genericPut($this->aProperties['schema_vmap'], 'map', 'map_id'); + $aReturn = $this->genericPut($this->aProperties['schema_vmap'], 'map', 'map_id', $aUploadFiles, 'vmap_admin_map_vmap_admin_map'); // Si mise à jour OK -> maj des groupes rattachés à la carte. if ($aReturn['sStatus'] == 1) { $aXmlRacineAttribute['status'] = 1; @@ -492,4 +448,4 @@ class Maps extends Vmap { } -?> \ No newline at end of file +?> diff --git a/web_service/ws/Querys.class.inc b/web_service/ws/Querys.class.inc index da9788fb..41656427 100644 --- a/web_service/ws/Querys.class.inc +++ b/web_service/ws/Querys.class.inc @@ -52,8 +52,7 @@ class Querys extends Vmap { $this->aProperties = $properties; $this->aValues['getGroup'] = false; $this->oConnection = new Connection($this->aValues, $this->aProperties); - - error_log('$_FILES: '. print_r($_FILES, true)); + $this->oFilesManager = new Files_manager($this->aProperties); } /** @@ -848,10 +847,16 @@ class Querys extends Vmap { if (count($aFiles) > 1) { $aLigne['bo_' . $type][$key] = []; for ($i=0; $i < count($aFiles); $i++) { - array_push($aLigne['bo_' . $type][$key], $sDataUrl . "/" . $key . "/" . $aFiles[$i] . "?d=" . $date->getTimestamp()); + if (file_exists($sDataDir . "/" . $key . "/" . $aFiles[$i])) { + array_push($aLigne['bo_' . $type][$key], $this->oFilesManager->oFileInterface->getProxyPassUrl($sDataDir . "/" . $key . "/" . $aFiles[$i])); + } } } else { - $aLigne['bo_' . $type][$key] = $sDataUrl . "/" . $key . "/" . $value . "?d=" . $date->getTimestamp(); + if (!empty($value)) { + if (file_exists($sDataDir . "/" . $key . "/" . $value)) { + $aLigne['bo_' . $type][$key] = $this->oFilesManager->oFileInterface->getProxyPassUrl($sDataDir . "/" . $key . "/" . $value); + } + } } } } @@ -1440,18 +1445,8 @@ class Querys extends Vmap { $this->aValues['my_vitis_id'] = $this->aValues[$bo_id_field]; - // Fichiers à uploader ? - if (!empty($_FILES) && !empty($this->aValues['my_vitis_id'])) { - - // Écriture du fichier - $oFileManager = new Files_manager($this->aProperties); - foreach ($_FILES as $sName => $aFile) { - $aUploadReturn = $oFileManager->uploadInWsDataDir('vitis', $sBusinessObjectId, $this->aValues['my_vitis_id'], $sName, 'documents'); - $this->aValues[$sName] = $aUploadReturn['field_value']; - } - - $aReturn = $this->genericPut($bo_schema, $bo_table, $bo_id_field); - } + // Maj en base + $aReturn = $this->genericPut($bo_schema, $bo_table, $bo_id_field, '*', $sBusinessObjectId, "vitis", "documents"); // Lance l'évènement webSocket if (!empty($bo_event)) { @@ -1618,20 +1613,7 @@ class Querys extends Vmap { // $this->aValues['my_vitis_id'] = $this->aValues[$bo_id_field]; unset($this->aValues['my_vitis_id']); - $aReturn = $this->genericPost($bo_schema, $bo_table, '', $bo_id_field); - - // Fichiers à uploader ? - if (!empty($_FILES) && !empty($this->aValues['my_vitis_id'])) { - - // Écriture du fichier - $oFileManager = new Files_manager($this->aProperties); - foreach ($_FILES as $sName => $aFile) { - $aUploadReturn = $oFileManager->uploadInWsDataDir('vitis', $sBusinessObjectId, $this->aValues['my_vitis_id'], $sName, 'documents'); - $this->aValues[$sName] = $aUploadReturn['field_value']; - } - - $this->genericPut($bo_schema, $bo_table, $bo_id_field); - } + $aReturn = $this->genericPost($bo_schema, $bo_table, '', $bo_id_field, '*', $sBusinessObjectId, "vitis", "documents"); // Lance l'évènement webSocket if (!empty($bo_event)) { diff --git a/web_service/ws/Services.class.inc b/web_service/ws/Services.class.inc index d5e8deda..ff4423e4 100755 --- a/web_service/ws/Services.class.inc +++ b/web_service/ws/Services.class.inc @@ -9,7 +9,7 @@ * \brief This file contains the Services php class * * This class defines Rest Api to Vmap Services - * + * */ require_once 'Vmap.class.inc'; require_once 'Service.class.inc'; @@ -128,7 +128,7 @@ class Services extends Vmap { } } - // Reformatte la réponse + // Reformatte la réponse if (isset($this->aValues['sEncoding'])) { $sEncoding = $this->aValues['sEncoding']; } else { @@ -220,7 +220,7 @@ class Services extends Vmap { * ) * * ) - * + * * ) */ @@ -230,45 +230,17 @@ class Services extends Vmap { */ function POST() { - // Vignette à uploader ? - if (!empty($_FILES['thumbnail'])) { - // la colonne thumbnail vaudra le nom du fichier - $this->aValues["thumbnail"] = $_FILES['thumbnail']["name"]; - } - - // Redimmensionnement de l'image. + // Fichiers à uploader + $aUploadFiles = array( + 'thumbnail' => [] + ); if (!empty($this->aValues['thumbnail_width']) && !empty($this->aValues['thumbnail_height'])) { - // Renomme l'image en jpg - $aPointsArray = explode('.', $this->aValues["thumbnail"]); - $aPointsArray[count($aPointsArray) - 1] = 'jpg'; - $this->aValues["thumbnail"] = join('.', $aPointsArray); - } - - $aReturn = $this->genericPost($this->aProperties['schema_vmap'], 'service', $this->aProperties['schema_vmap'] . '.seq_common', 'service_id'); - - // Vignette à uploader ? - if (!empty($_FILES['thumbnail'])) { - $sImageDir = $this->aProperties['ws_data_dir'] . '/vitis/vmap_admin_map_vmap_services/documents/' . $this->aValues["my_vitis_id"] . '/thumbnail/' . $_FILES['thumbnail']["name"]; - - // Crée les répertoires si ils n'existent pas - $sDirPath = $this->createElementFilesFolder('vmap_admin_map_vmap_services', $this->aValues["my_vitis_id"]); - $sDirColumnPath = $sDirPath . '/thumbnail'; - if (!is_dir($sDirColumnPath)) { - mkdir($sDirColumnPath, 0777, true); - } - - $sErrorMessage = uploadFile("thumbnail", "", $sImageDir, $_FILES['thumbnail']['size'] + 1); - - if ($sErrorMessage != "") { - writeToErrorLog($sErrorMessage); - } else { - // Redimmensionnement de l'image. - if (!empty($this->aValues['thumbnail_width']) && !empty($this->aValues['thumbnail_height'])) { - $this->pictureResampler($sImageDir, $this->aValues['thumbnail_width'], $this->aValues['thumbnail_height']); - } - } + $aUploadFiles['thumbnail']['width'] = $this->aValues['thumbnail_width']; + $aUploadFiles['thumbnail']['height'] = $this->aValues['thumbnail_height']; } + // Envoi Post + $aReturn = $this->genericPost($this->aProperties['schema_vmap'], 'service', $this->aProperties['schema_vmap'] . '.seq_common', 'service_id', $aUploadFiles, 'vmap_admin_map_vmap_services'); return $aReturn['sMessage']; } @@ -347,7 +319,7 @@ class Services extends Vmap { * description="Poprerties Response", * @SWG\Schema(ref="#/definitions/services") * ), - * + * * ) */ @@ -356,35 +328,18 @@ class Services extends Vmap { * @return array containing the status and the message */ function PUT() { - // Vignette à uploader ? - if (!empty($this->aValues["thumbnail_file"])) { - - $sImageDir = $this->aProperties['ws_data_dir'] . '/vitis/vmap_admin_map_vmap_services/documents/' . $this->aValues["my_vitis_id"] . '/thumbnail/' . $this->aValues["thumbnail_name"]; - // Crée les répertoires si ils n'existent pas - $sDirPath = $this->createElementFilesFolder('vmap_admin_map_vmap_services', $this->aValues["my_vitis_id"]); - $sDirColumnPath = $sDirPath . '/thumbnail'; - if (!is_dir($sDirColumnPath)) { - mkdir($sDirColumnPath, 0777, true); - } - - // la colonne thumbnail vaudra le nom du fichier - $this->aValues["thumbnail"] = $this->aValues["thumbnail_name"]; - $fp = fopen($sImageDir, "w"); - fwrite($fp, $this->aValues["thumbnail_file"]); - fclose($fp); - - // Redimmensionnement de l'image. - if (!empty($this->aValues['thumbnail_width']) && !empty($this->aValues['thumbnail_height'])) { - $this->pictureResampler($sImageDir, $this->aValues['thumbnail_width'], $this->aValues['thumbnail_height']); - // Renomme l'image en jpg - $aPointsArray = explode('.', $this->aValues["thumbnail"]); - $aPointsArray[count($aPointsArray) - 1] = 'jpg'; - $this->aValues["thumbnail"] = join('.', $aPointsArray); - } + // Fichiers à uploader + $aUploadFiles = array( + 'thumbnail' => [] + ); + if (!empty($this->aValues['thumbnail_width']) && !empty($this->aValues['thumbnail_height'])) { + $aUploadFiles['thumbnail']['width'] = $this->aValues['thumbnail_width']; + $aUploadFiles['thumbnail']['height'] = $this->aValues['thumbnail_height']; } - $aReturn = $this->genericPut($this->aProperties['schema_vmap'], 'service', 'service_id'); + // Envoi Put + $aReturn = $this->genericPut($this->aProperties['schema_vmap'], 'service', 'service_id', $aUploadFiles, 'vmap_admin_map_vmap_services'); return $aReturn['sMessage']; } -- GitLab