Exemplo n.º 1
0
 /**
  * create_json_with_father
  *
  * 
  * @access	public
  * @param	string	mapping
  * @param	string	
  * @return	array
  */
 public static function create_json_with_father($map, $value, $pere, $type)
 {
     if (count($map) == 1) {
         if ($type == "INT") {
             $pere[$map[0]] = intval($value);
         } else {
             if ($type == "FLOAT") {
                 $pere[$map[0]] = floatval($value);
             } else {
                 $pere[$map[0]] = $value;
             }
         }
     } else {
         $newmap = array_splice($map, 1);
         if (isset($pere[$map[0]])) {
             $pere[$map[0]] = FileHelper::create_json_with_father($newmap, $value, $pere[$map[0]], $type);
         } else {
             $pere[$map[0]] = FileHelper::create_json($newmap, $value, $type);
         }
     }
     return $pere;
 }
Exemplo n.º 2
0
 public static function previewData($post)
 {
     /**** new ****/
     if (isset($post['infoCreateData']) && isset($post['idCollection']) && isset($post['subFile']) && isset($post['nameFile'])) {
         $pathSubFile = '../../modules/cityData/filesImportData/' . $post['nameFile'] . '/' . $post['subFile'];
         $arrayCSV = new SplFileObject($pathSubFile, 'r');
         $arrayCSV->setFlags(SplFileObject::READ_CSV);
         $arrayCSV->setCsvControl(',', '"', '"');
         $i = 0;
         while (!$arrayCSV->eof() && $i == 0) {
             $arrayHeadCSV = $arrayCSV->fgetcsv();
             $i++;
         }
         $i = 0;
         // On parcourt les lignes du CSV
         foreach ($arrayCSV as $keyCSV => $lineCSV) {
             // On rejet la premier lignes qui correspond a l'en-tete, et les lignes qui seraient null
             if ($i > 0 && $lineCSV[0] != null) {
                 if ($i % 500 == 0) {
                     set_time_limit(30);
                 }
                 foreach ($post['infoCreateData'] as $key => $objetInfoData) {
                     //$objetInfoData->idHeadCSV;
                     //$objetInfoData->valueLinkCollection;
                     $valueData = $lineCSV[$objetInfoData['idHeadCSV']];
                     //var_dump($valueData);
                     if (!empty($valueData)) {
                         $paramsInfoCollection = array("_id" => new MongoId($post['idCollection']));
                         $fieldsInfoCollection = array("mappingFields." . $objetInfoData['valueLinkCollection']);
                         $infoCollection = ImportData::getMicroFormats($paramsInfoCollection);
                         //var_dump($infoCollection) ;
                         $mappingTypeData = explode(".", $post['idCollection'] . ".mappingFields." . $objetInfoData['valueLinkCollection']);
                         $typeData = FileHelper::get_value_json($infoCollection, $mappingTypeData);
                         /*var_dump($mappingTypeData) ; 
                           
                            var_dump($typeData) ; */
                         $mapping = explode(".", $objetInfoData['valueLinkCollection']);
                         if (isset($jsonData[$mapping[0]])) {
                             if (count($mapping) > 1) {
                                 $newmap = array_splice($mapping, 1);
                                 $jsonData[$mapping[0]] = FileHelper::create_json_with_father($newmap, $valueData, $jsonData[$mapping[0]], $typeData);
                             } else {
                                 $jsonData[$mapping[0]] = $valueData;
                             }
                         } else {
                             if (count($mapping) > 1) {
                                 $newmap = array_splice($mapping, 1);
                                 $jsonData[$mapping[0]] = FileHelper::create_json($newmap, $valueData, $typeData);
                             } else {
                                 $jsonData[$mapping[0]] = $valueData;
                             }
                         }
                     }
                 }
                 $newOrganization = Organization::newOrganizationFromImportData($jsonData);
                 //var_dump($newOrganization);
                 try {
                     $arrayJson[] = Organization::getAndCheckOrganization($newOrganization);
                 } catch (CTKException $e) {
                     $newOrganization["msgError"] = $e->getMessage();
                     $arrayJsonError[] = $newOrganization;
                 }
                 //var_dump($arrayJson);
             }
             $i++;
         }
         if (!isset($arrayJson)) {
             $arrayJson = [];
         }
         if (!isset($arrayJsonError)) {
             $arrayJsonError = [];
         }
         $params = array("result" => true, "jsonImport" => json_encode($arrayJson), "jsonError" => json_encode($arrayJsonError));
     } else {
         $params = array("result" => false);
     }
     return $params;
 }
Exemplo n.º 3
0
 public static function createMappingWithJSON($post)
 {
     $json_array = json_decode($post['json_origine'], true);
     $jsonMapping["src"] = $post['source'];
     //json mapping
     if ($post['chooseSelected'] == "new") {
         $jsonMapping["date_create"] = date("d/m/y");
     } else {
         $oneMapping = PHDB::findOne(City::COLLECTION_IMPORTHISTORY, array("_id" => new MongoId($post['mappingSelected'])));
         $jsonMapping["date_create"] = $oneMapping["date_create"];
         // $jsonmapping["lastImportId"] = $oneMapping['lastImportId'];
     }
     $jsonMapping["date_update"] = date("d/m/y");
     $jsonMapping["url"] = $post['url'];
     $jsonMapping["nameFile"] = $post['nameFile'];
     $jsonMapping["lien"] = $post['lien'];
     foreach ($post['tabmapping'] as $key => $value) {
         if ($value != '') {
             $jsonfilsFields[$post['tabidmapping'][$key]] = $value;
         }
     }
     $jsonMapping["fields"] = $jsonfilsFields;
     $idLien = $post['lien'];
     $cheminLien = explode(".", $idLien);
     //var_dump($cheminLien);
     $valueIdLien = FileHelper::get_value_json($json_array, $cheminLien);
     //var_dump($valueIdLien);
     $res = PHDB::findOne(City::COLLECTION, array("insee" => $valueIdLien));
     $inc_import = 0;
     $inc_rejet = 0;
     if ($res != null) {
         $commune["insee"] = $valueIdLien;
         foreach ($jsonMapping['fields'] as $key => $value) {
             $map = explode(".", $value);
             $cheminJson = explode(".", $key);
             $value_json = FileHelper::get_value_json($json_array, $cheminJson);
             if (!isset($commune[$map[0]])) {
                 if (count($map) > 1) {
                     $newmap = array_splice($map, 1);
                     $commune[$map[0]] = FileHelper::create_json($newmap, $value_json);
                 } else {
                     $commune[$map[0]] = $value_json;
                 }
             } else {
                 if (count($map) > 1) {
                     $newmap = array_splice($map, 1);
                     $commune[$map[0]] = FileHelper::create_json_with_father($newmap, $value_json, $commune[$map[0]]);
                 } else {
                     $commune[$map[0]] = $value_json;
                 }
             }
         }
     } else {
         foreach ($jsonMapping['fields'] as $key => $value) {
             $map = explode(".", $value);
             $cheminJson = explode(".", $key);
             if (!isset($rejet[$valueIdLien])) {
                 if (count($map) > 1) {
                     $newmap = array_splice($map, 1);
                     $rejet[$map[0]] = FileHelper::create_json_with_father($newmap, $value_json);
                 } else {
                     $rejet[$map[0]] = $value_json;
                 }
             } else {
                 if (count($map) > 1) {
                     $newmap = array_splice($map, 1);
                     $rejet[$map[0]] = FileHelper::create_json_with_father($newmap, $value_json, $rejet[$map[0]]);
                 } else {
                     $rejet[$map[0]] = $value_json;
                 }
             }
         }
     }
     if (isset($commune)) {
         $jsonimport = $commune;
     } else {
         $jsonimport = [];
         $arrayCsvImport = [];
     }
     if (isset($rejet)) {
         $jsonrejet = $rejet;
     } else {
         $jsonrejet = [];
         $arrayCsvRejet = [];
     }
     $params = array('result' => true, 'jsonmapping' => FileHelper::indent_json(json_encode($jsonMapping)), "jsonimport" => FileHelper::indent_json(json_encode($jsonimport)), "jsonrejet" => FileHelper::indent_json(json_encode($jsonrejet)), "lien" => $post['lien']);
     return $params;
 }