This commit is contained in:
176
src/Helper/HiltesImport.php
Normal file
176
src/Helper/HiltesImport.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helper;
|
||||
|
||||
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class HiltesImport
|
||||
{
|
||||
protected $currentDirPath;
|
||||
protected $arrData = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->currentDirPath = getcwd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function startImport()
|
||||
{
|
||||
#*** Holt alle Dateien
|
||||
if($this->getFiles()){
|
||||
if(!empty($this->arrData['orgFiles']['data']) && count($this->arrData['orgFiles']['data'])){
|
||||
foreach ($this->arrData['orgFiles']['data'] as $file) {
|
||||
if(is_file($file['realPath'])){
|
||||
$this->loadFiles($file['realPath'],$file['fileSize']);
|
||||
}else{
|
||||
return array('error'=>1,'text'=>'Error is_file('.$file['realPath'].')');
|
||||
}
|
||||
}
|
||||
}else
|
||||
return array('success'=>1,'text'=>'No Files');
|
||||
}else
|
||||
return array('error'=>1,'text'=>'Error in getFiles');
|
||||
}
|
||||
protected function getFiles()
|
||||
{
|
||||
$return = true;
|
||||
$finder = Finder::create();
|
||||
$finder
|
||||
->in($this->currentDirPath.'/hiltes/h2c/')
|
||||
->depth(0);
|
||||
#->filter(static function (SplFileInfo $file) {
|
||||
# return $file->isDir() || \preg_match('/\.(php|json)$/', $file->getPathname());
|
||||
#});
|
||||
if ($finder->hasResults()) {
|
||||
foreach ($finder as $file) {
|
||||
$this->arrData['orgFiles']['data'][] = array(
|
||||
'realPath' => $file->getRealPath(),
|
||||
'fileSize' => $file->getFileInfo()->getSize(),
|
||||
'onlyFileName' => $file->getRelativePathname(),
|
||||
);
|
||||
/*
|
||||
$absoluteFilePath = $file->getRealPath();
|
||||
$fileInfo = $file->getFileInfo();
|
||||
$fileNameWithExtension = $file->getRelativePathname();
|
||||
dump($absoluteFilePath);
|
||||
dump($fileInfo->getSize());
|
||||
dump($fileNameWithExtension);
|
||||
*/
|
||||
#dump($this->arrData);
|
||||
}
|
||||
return $return;
|
||||
}else{
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
#print_r(\iterator_to_array($finder,true));
|
||||
}
|
||||
protected function loadFiles($srcFile,$size)
|
||||
{
|
||||
# $t = memory_get_usage();
|
||||
# dump($t);
|
||||
$file = new \SplFileObject($srcFile);
|
||||
# dump(memory_get_usage()-$t);
|
||||
|
||||
$c = 0;
|
||||
while (!$file->eof()) {
|
||||
#*** Convertiert die Zeile in UTF8
|
||||
$str = iconv('ISO-8859-1','UTF-8',$file->fgets());
|
||||
#*** Zerlegt die Zeile **********
|
||||
$arr = $this->splitLine($str);
|
||||
$this->switchSaveData($arr);
|
||||
#
|
||||
#dump('-----------------------');
|
||||
#dump($str);
|
||||
#dump($arr);
|
||||
$c++;
|
||||
# if($c>=50){
|
||||
# dump(memory_get_usage()-$t);
|
||||
# die();
|
||||
# }
|
||||
}
|
||||
# dump(memory_get_usage()-$t);
|
||||
# die();
|
||||
}
|
||||
protected function splitLine($str){
|
||||
return str_getcsv($str,';','"');
|
||||
}
|
||||
|
||||
/**
|
||||
* Hier wird festgelegt wo und wie die Zeile gespeichert wird
|
||||
*
|
||||
* @param array $arr
|
||||
* @return void
|
||||
*/
|
||||
protected function switchSaveData(array $arr){
|
||||
if(!empty($arr[0])){
|
||||
#*** Leerzeichen löschen bei den einzelnen Einträgen **********
|
||||
$this->trimArray($arr);
|
||||
#***
|
||||
$arr[0] = strtolower($arr[0]);
|
||||
switch ($arr[0]){
|
||||
case 'datei': # Datei
|
||||
$this->saveInfoDatei($arr);
|
||||
break;
|
||||
case 'filiale': # Filiale
|
||||
#$this->saveInfoFiliale($arr);
|
||||
break;
|
||||
case 'land': # Länder
|
||||
$this->saveInfoLand($arr);
|
||||
break;
|
||||
case 'hwg': # Hauptwarengruppe
|
||||
#$this->saveInfoHauptWarenGruppe($arr);
|
||||
break;
|
||||
case 'wg': # Warengruppe
|
||||
#$this->saveInfoWarenGruppe($arr);
|
||||
break;
|
||||
case 'anrede': # Anrede
|
||||
#$this->saveInfoAnrede($arr);
|
||||
break;
|
||||
case 'lieferant': # Lieferant
|
||||
#$this->saveInfoLieferant($arr);
|
||||
break;
|
||||
case 'farb': # Farbcodierung
|
||||
#$this->saveInfoFarbCodierung($arr);
|
||||
break;
|
||||
case 'nlart': # NachlassArt
|
||||
#$this->saveInfoNachlassArt($arr);
|
||||
break;
|
||||
case 'kollektion': # Kollektion
|
||||
#$this->saveInfoKollektion($arr);
|
||||
break;
|
||||
case 'bestand': # Bestand
|
||||
#$this->saveInfoBestand($arr);
|
||||
break;
|
||||
case 'merkmale': # Made In XXXX = Land
|
||||
#$this->saveInfoMerkmale($arr);
|
||||
break;
|
||||
case 'material': # MAterial
|
||||
#$this->saveInfoMaterial($arr);
|
||||
break;
|
||||
default: #
|
||||
dump('!!!!! KEIN DEFINIERTER ANFANG "'.$arr[0].'" !!!!!!!!!');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected function trimArray(Array &$arr){
|
||||
foreach ($arr as $k=>$v) {
|
||||
$arr[$k] = trim($v);
|
||||
}
|
||||
}
|
||||
protected function saveInfoDatei(Array $arr){
|
||||
|
||||
}
|
||||
protected function saveInfoLand(Array $arr){
|
||||
#dump($arr);
|
||||
|
||||
dd($arr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user