예제 #1
0
 public static function parsingCSV($file, $post)
 {
     header('Content-Type: text/html; charset=UTF-8');
     if (isset($file['fileImport']) && isset($post['separateurDonnees']) && isset($post['separateurTexte']) && isset($post['chooseCollection'])) {
         $csv = new SplFileObject($file['fileImport']['tmp_name'], 'r');
         $csv->setFlags(SplFileObject::READ_CSV);
         $csv->setCsvControl($post['separateurDonnees'], $post['separateurTexte'], '"');
         /*$csvControl = $csv->getCsvControl();
           var_dump($csvControl);
           $csv->setCsvControl($csvControl[0], $csvControl[1]);*/
         $arrayNameFile = explode(".", $file['fileImport']['name']);
         // On découpe le fichier s'il est trop gros, 5000 ligne par fichier
         $path = '../../modules/cityData/filesImportData/';
         if (!file_exists($path)) {
             mkdir($path, 0775);
         }
         $path = '../../modules/cityData/filesImportData/' . $arrayNameFile[0] . '/';
         if (!file_exists($path)) {
             mkdir($path, 0775);
         }
         $countLine = 0;
         $countFile = 1;
         foreach ($csv as $key => $value) {
             //if(is_string($value))
             $arrayCSV[$key] = $value;
             if ($key == 0) {
                 $headerCSV = $value;
             }
             if ($countLine == 0 || $key == 0) {
                 $arrayCSV[0] = $headerCSV;
             } else {
                 $arrayCSV[$countLine] = $value;
             }
             if ($countLine == 5000) {
                 $nameFile = $arrayNameFile[0] . '_' . $countFile . '.csv';
                 ImportData::createCSV($arrayCSV, $nameFile, $path);
                 $countLine = 0;
                 $countFile++;
                 $arrayCSV = array();
             } else {
                 $countLine++;
             }
         }
         $nameFile = $arrayNameFile[0] . '_' . $countFile . '.csv';
         ImportData::createCSV($arrayCSV, $nameFile, $path);
         $params = array("createLink" => true, "arrayCSV" => $arrayCSV, "nameFile" => $file['fileImport']['name'], "idCollection" => $post['chooseCollection']);
     } else {
         $params = array("createLink" => false);
     }
     return $params;
 }
예제 #2
0
 public static function useCSV($file, $post)
 {
     header('Content-Type: text/html; charset=UTF-8');
     if (isset($file['fileimport'])) {
         $csv = new SplFileObject($file['fileimport']['tmp_name'], 'r');
         $csv->setFlags(SplFileObject::READ_CSV);
         $csv->setCsvControl($post['separateurDonnees'], $post['separateurTexte'], '"');
         $arrayNameFile = explode(".", $file['fileimport']['name']);
         $path = '../../modules/cityData/filesCityData/' . $arrayNameFile[0] . '/';
         if (!file_exists($path)) {
             mkdir($path, 0777);
         }
         $countLine = 0;
         $countFile = 1;
         foreach ($csv as $key => $value) {
             $tabCSV[$key] = $value;
             if ($key == 0) {
                 $headerCSV = $value;
             }
             if ($countLine == 0 || $key == 0) {
                 $arrayCSV[0] = $headerCSV;
             } else {
                 $arrayCSV[$countLine] = $value;
             }
             if ($countLine == 5000) {
                 $nameFile = $arrayNameFile[0] . '_' . $countFile . '.csv';
                 ImportData::createCSV($arrayCSV, $nameFile, $path);
                 $countLine = 0;
                 $countFile++;
                 $arrayCSV = array();
             } else {
                 $countLine++;
             }
         }
         $nameFile = $arrayNameFile[0] . '_' . $countFile . '.csv';
         ImportData::createCSV($arrayCSV, $nameFile, $path);
         //Yii::app()->session["tabCSV"] = $tabCSV;
         $params = array("result" => true, "tabCSV" => $tabCSV, "separateur" => $post['separateurDonnees'], "nameFile" => $file['fileimport']['name'], "choose" => $post['choose']);
         if ($post['choose'] == "modify") {
             $params['chooseMapping'] = $post['chooseMapping'];
         }
     } else {
         $params = array("choose" => false, "result" => false);
     }
     return $params;
 }