$subtitle = trim(trim($data['Age Group'] ?? '') . ' - ' . $data['Genre'] . ' - ' . trim($data['Product Line'] ?? ''), '- ');
$key = md5($title . $subtitle);
if (!isset($planches[$key])) {
- $planches[$key] = ['class' => $data['Catégorie'], 'title' => $title, 'subtitle' => $subtitle, 'groups' => ['top' => [], 'bottom' => []]];
+ $planches[$key] = ['class' => $data['Catégorie'], 'title' => $title, 'subtitle' => $subtitle, 'bottomsbycolor' => [], 'groups' => ['top' => [], 'bottom' => []]];
}
- $group = 'top';
- foreach ($bottomStrings as $str) {
- if (stristr($data['Article Type'], $str) !== false) {
- $group = 'bottom';
- break;
+ if ($data['Catégorie'] === 'Footwear') {
+ $group = 'footwear';
+ } else {
+ $group = 'top';
+ foreach ($bottomStrings as $str) {
+ if (stristr($data['Article Type'], $str) !== false) {
+ $group = 'bottom';
+ break;
+ }
}
}
+ $data['group'] = $group;
+ if ($group === 'bottom') {
+ $colorCode = $data['Couleur'];
+ if (!isset($planches[$key]['bottomsbycolor'][$colorCode])) {
+ $planches[$key]['bottomsbycolor'][$colorCode] = [];
+ }
+ $planches[$key]['bottomsbycolor'][$colorCode][$reference] = $data;
+ }
$planches[$key]['groups'][$group][$reference] = $data;
}
$html .= '<body>';
foreach ($planches as $data) {
$cols = $data['class'] === 'Footwear' ? 5 : 6;
- $rows = $data['class'] === 'Footwear' ? 4 : 2;
+ $rows = $data['class'] === 'Footwear' ? 4 : 1;
$lines = [];
foreach ($data['groups'] as $group => $products) {
+ if ($group === 'bottom') {
+ continue;
+ }
if (!count($products)) {
continue;
}
}
$subs = array_chunk($lines, $rows, true);
- $csubs = count($subs);
- $emptyImg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==';
- $emptyImgAttr = ' class="empty" ';
+ $countSection = 0;
+
+ $all = '';
foreach ($subs as $i => $lines) {
- $pos = $csubs == 1 ? '' : ' (' . ($i + 1) . '/' . $csubs . ')';
- $html .= '<section class="' . $data['class'] . '">';
- $html .= '<h1>' . $data['title'] . '</h1>';
- $html .= '<h2>' . $data['subtitle'] . $pos . '</h2>';
- $html .= '<div class="products">';
- foreach ($lines as $line) {
- foreach ($line as $reference => $product) {
- if (isset($product['zoom_image'])) {
- $f = protected_path('fluidbookpublication/cache/zoomarea/zoomarea/books/' . $id . '/' . $product['zoom_image']);
- if (file_exists($f)) {
- $img = Files::asDataURI($f);
- $img_attr = ' data-file="' . $f . '" ';
- } else {
- $img = $emptyImg;
- $img_attr = $emptyImgAttr;
- }
- } else {
- $img = $emptyImg;
- $img_attr = $emptyImgAttr;
- }
-
- $html .= '<article>';
- $html .= '<img ' . $img_attr . ' src="' . $img . '">';
- $html .= '<div class="infos">';
- $html .= '<h3>' . $reference . '</h3>';
- $html .= '<div>' . $product['Désignation'] ?? '' . '</div>';
- $html .= '<div>' . $product['Color Name'] ?? '' . '</div>';
- if ($pa || $pvp) {
- $html .= '<div>';
- if ($pa) {
- $html .= 'PA : ' . number_format(floatval($product['Tarif'] ?? 0), 2, ',', ' ') . ' € ';
- }
- if ($pa && $pvp) {
- $html .= ' / ';
- }
- if ($pvp) {
- $html .= 'PVP : ' . number_format(floatval($product['PVC'] ?? 0), 2, ',', ' ') . ' €';
- }
- $html .= '</div>';
- }
- $html .= '</div>';
- $html .= '</article>';
- }
- for ($i = count($line); $i < $cols; $i++) {
- $html .= '<article></article>';
- }
+ $all .= $this->_renderSection($data, $lines, $cols, $id, $pa, $pvp);
+ $countSection++;
+ }
+
+ if (count($data['groups']['bottom']) > 0) {
+ $rows = 2;
+ $products = $data['groups']['bottom'];
+ $lines = array_chunk($products, $cols, true);
+ $subs = array_chunk($lines, $rows, true);
+ foreach ($subs as $i => $lines) {
+ $all .= $this->_renderSection($data, $lines, $cols, $id, $pa, $pvp);
+ $countSection++;
}
+ }
- $html .= '</div>';
- $html .= '</section>';
+ if ($countSection <= 1) {
+ $all = str_replace('$pos', '', $all);
+ } else {
+ $i = 1;
+ $all = preg_replace_callback('/\$pos/', function ($matches) use ($countSection, &$i) {
+ $res = ' (' . $i . '/' . $countSection . ')';
+ $i++;
+ return $res;
+ }, $all);
}
+
+ $html .= $all;
}
$html .= '</body>';
return $html;
return file_get_contents(resource_path('puma/planogramme/style.css'));
}
+ protected function _renderSection(&$data, $lines, $cols, $id, $pa, $pvp)
+ {
+ $html = '<section class="' . $data['class'] . '">';
+ $html .= '<h1>' . $data['title'] . '</h1>';
+ $html .= '<h2>' . $data['subtitle'] . '$pos</h2>';
+ $html .= '<div class="products">';
+ foreach ($lines as $line) {
+ $bottomLine = [];
+ $hasBottomLine = false;
+ foreach ($line as $reference => $product) {
+ $html .= '<article>' . $this->_renderProduct($reference, $product, $id, $pa, $pvp) . '</article>';
+ if ($product['group'] === 'top' && isset($data['bottomsbycolor'][$product['Couleur']])) {
+ foreach ($data['bottomsbycolor'][$product['Couleur']] as $r => $p) {
+ $bottomLine[] = $this->_renderProduct($r, $p, $id, $pa, $pvp);
+ $hasBottomLine = true;
+ unset($data['groups']['bottom'][$r]);
+ unset($data['bottomsbycolor'][$product['Couleur']][$r]);
+ break;
+ }
+ } else {
+ $bottomLine[] = '';
+ }
+ }
+ for ($i = count($line); $i < $cols; $i++) {
+ $html .= '<article></article>';
+ }
+
+ if ($hasBottomLine) {
+ $html .= '<article>' . implode('</article><article>', $bottomLine) . '</article>';
+ }
+ }
+ $html .= '</div>';
+ $html .= '</section>';
+ return $html;
+ }
+
+ protected function _renderProduct($reference, $product, $id, $pa, $pvp)
+ {
+ $emptyImg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==';
+ $emptyImgAttr = ' class="empty" ';
+ $html = '';
+ if (isset($product['zoom_image'])) {
+ $f = protected_path('fluidbookpublication/cache/zoomarea/zoomarea/books/' . $id . '/' . $product['zoom_image']);
+ if (file_exists($f)) {
+ $img = Files::asDataURI($f);
+ $img_attr = ' data-file="' . $f . '" ';
+ } else {
+ $img = $emptyImg;
+ $img_attr = $emptyImgAttr;
+ }
+ } else {
+ $img = $emptyImg;
+ $img_attr = $emptyImgAttr;
+ }
+
+
+ $html .= '<img ' . $img_attr . ' src="' . $img . '">';
+ $html .= '<div class="infos">';
+ $html .= '<h3>' . $reference . '</h3>';
+ $html .= '<div>' . $product['Désignation'] ?? '' . '</div>';
+ $html .= '<div>' . $product['Color Name'] ?? '' . '</div>';
+ if ($pa || $pvp) {
+ $html .= '<div>';
+ if ($pa) {
+ $html .= 'PA : ' . number_format(floatval($product['Tarif'] ?? 0), 2, ',', ' ') . ' € ';
+ }
+ if ($pa && $pvp) {
+ $html .= ' / ';
+ }
+ if ($pvp) {
+ $html .= 'PVP : ' . number_format(floatval($product['PVC'] ?? 0), 2, ',', ' ') . ' €';
+ }
+ $html .= '</div>';
+ }
+ $html .= '</div>';
+ return $html;
+ }
+
}