From: vincent@cubedesigners.com Date: Mon, 15 Nov 2021 13:32:04 +0000 (+0000) Subject: wip #4682 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=b63283a7565319fa4ed24fd1a6570f9308ad15e7;p=cubeextranet.git wip #4682 @0.5 --- diff --git a/inc/ws/Util/class.ws.util.php b/inc/ws/Util/class.ws.util.php index 78a78fbbc..06f27ded0 100644 --- a/inc/ws/Util/class.ws.util.php +++ b/inc/ws/Util/class.ws.util.php @@ -80,6 +80,47 @@ class wsUtil return $res; } + public static function excelToArrayIndexKeyVars($excelFile, $reader = 'Excel2007', $skipEmptyId = false) + { + global $core; + + $e = explode('#', $excelFile); + $excelFile = $e[0]; + + $worksheets = self::excelToArray($excelFile, false, $reader); + + if (isset($e[1])) { + $sheetName = trim($e[1]); + } + + if (isset($sheetName, $worksheets[$sheetName])) { + $worksheet = $worksheets[$sheetName]; + } else { + $worksheet = array_shift($worksheets); + } + + $res = []; + foreach ($worksheet as $i => $line) { + if ($i === 0) { + $vars = []; + foreach ($line as $j => $varname) { + $vars[$j] = $varname; + } + } else { + if (trim(implode('', $line)) == '') { + continue; + } + $r = []; + foreach ($vars as $j => $varname) { + $r[$varname] = trim($line[$j]); + } + $res[] = $r; + } + } + + return $res; + } + public static function excelToArrayKeyVars($excelFile, $reader = 'Excel2007', $skipEmptyId = false) { global $core; @@ -97,9 +138,11 @@ class wsUtil if (isset($sheetName, $worksheets[$sheetName])) { $worksheet = $worksheets[$sheetName]; } else { - $worksheet = array_unshift($worksheets); + $worksheet = array_shift($worksheets); } + + $res = []; foreach ($worksheet as $i => $line) { if ($i === 0) { diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index 4aa341289..851d51e0e 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -670,7 +670,10 @@ class wsHTML5Compiler $this->addVideoJs(); $this->config->basketReferences = wsUtil::excelToArrayKeyVars($this->wdir . 'commerce/' . $this->book->parametres->basketReferences); - $this->config->eanReferences = wsUtil::excelToArrayKeyVars($this->wdir . 'commerce/ean.xlsx'); + $eanFile = $this->wdir . 'commerce/ean.xlsx'; + if (file_exists($eanFile)) { + $this->config->eanReferences = wsUtil::excelToArrayIndexKeyVars($eanFile); + } wsLinks::getLinksAndRulersFromFile($this->book_id, $links, $rulers); foreach ($links as $link) {