function __construct(FluidbookPublication $book, $scormVariant = false, $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false, FluidbookTheme $theme = null, $hybrid = false, Command $command = null)
{
+ ExcelToArray::setCache(protected_path('fluidbookpublication/cache/exceltoarray'));
+
parent::__construct();
$this->setFluidbook($book);
$this->addJsLib('cfoc', 'js/libs/fluidbook/cart/fluidbook.cart.cfoc.js');
- // NOTE: $this->config->basketReferences initially contains the uploaded filename and if we don't
- // modify it, the writeCartConfig() function will replace it with the extracted data from the spreadsheet đ€
- // It would be much better if the extracted data had its own variable but it would break too many things to
- // change it now, so we'll follow the same approach.
-
- if (!empty($this->config->basketReferences)) {
+ if (!empty($this->config->basketReferences) && is_string($this->config->basketReferences)) {
if (file_exists($this->config->basketReferences) || Url::isDistant($this->config->basketReferences)) {
$referencesFile = $this->config->basketReferences;
} else {
$references = [];
if (file_exists($referencesFile) || Url::isDistant($referencesFile)) {
- $raw_data = ExcelToArray::excelToArray($referencesFile);
- $first_sheet_rows = reset($raw_data); // First sheet's data will be returned since it's the first array element
+ $rows = ExcelToArray::excelToArrayFirstSheet($referencesFile);
+
// Expected headings are: EXCLU, LIGNE, EAN, REF, DESIGNATION, COULEUR, QTE MINI, PRIX TTC
- $column_headings = array_shift($first_sheet_rows); // We assume the first row will be the headings, so we slice it off
+ $column_headings = array_shift($rows); // We assume the first row will be the headings, so we slice it off
$column_headings = array_map(function ($heading) { // Clean the headings a bit
return trim(strtoupper($heading));
}, $column_headings);
- foreach ($first_sheet_rows as $row) {
+ foreach ($rows as $row) {
// First, trim values in case there are any stray spaces
$row = array_map('trim', $row);
$this->config->cartEmailSubject = $extra['email_subject'] ?? 'Récapitulatif de votre commande CFOC';
}
+ /**
+ * @throws \Exception
+ */
public function writeBastideCart()
{
$this->addJsLib('bastide', 'js/libs/fluidbook/cart/fluidbook.cart.bastide.js');
- // NOTE: $this->config->basketReferences initially contains the uploaded filename and if we don't
- // modify it, the writeCartConfig() function will replace it with the extracted data from the spreadsheet đ€
- // It would be much better if the extracted data had its own variable but it would break too many things to
- // change it now, so we'll follow the same approach.
if (!empty($this->config->basketReferences)) {
if (file_exists($this->config->basketReferences) || Url::isDistant($this->config->basketReferences)) {
$references = [];
if (file_exists($referencesFile) || Url::isDistant($referencesFile)) {
- $raw_data = ExcelToArray::excelToArray($referencesFile);
- $first_sheet_rows = reset($raw_data); // First sheet's data will be returned since it's the first array element
+ $rows = ExcelToArray::excelToArrayFirstSheet($referencesFile);
// Expected headings are: n° page, Chapitre, Article Code, Article, Conditionnement
- $column_headings = array_shift($first_sheet_rows); // We assume the first row will be the headings, so we slice it off
+ $column_headings = array_shift($rows); // We assume the first row will be the headings, so we slice it off
$column_headings = array_map(function ($heading) { // Normalise the headings, removing extra spaces and line breaks
return trim(strtoupper(preg_replace('/\s+/', ' ', $heading)));
}, $column_headings);
- foreach ($first_sheet_rows as $row) {
+ foreach ($rows as $row) {
// First, trim values in case there are any stray spaces
$row = array_map('trim', $row);
}
$this->config->basketReferences = $references;
+
+ // Allow individual Fluidbooks to override the columns shown in the cart
+ $extra = Link::parseExtras($this->config->cartExtraSettings, true);
+
+ if (!empty($extra['cart_columns'])) {
+ // In the "ParamĂštres panier" field (cartExtraSettings), the cart columns can be defined in this format:
+ // cart_columns=XLS COL NAME|Display name,XLS COL 2|Display name 2
+ // This setting needs to be trimmed and converted into an associative array with column_name => display_name
+ // Split by commas, then by pipes |
+ $columns = array_map(function ($heading) {
+ return explode('|', $heading);
+ }, explode(',', $extra['cart_columns']));
+ $processed_columns = [];
+ foreach ($columns as $column) {
+ $processed_columns[strtoupper(trim($column[0]))] = trim($column[1] ?? '');
+ }
+
+ // Ensure that special QUANTITY and DELETE columns are present (see getColumns() in fluidbook.cart.bastide.js)
+ $processed_columns['QUANTITY'] = $processed_columns['QUANTITY'] ?? 'Quantité';
+ $processed_columns['DELETE'] = '';
+
+ $this->config->cartColumns = $processed_columns;
+ }
}
public function writeCartConfig()
}
}
- if ($this->config->basketReferences) {
+ if ($this->config->basketReferences && is_string($this->config->basketReferences)) {
if (file_exists($this->config->basketReferences) || Url::isDistant($this->config->basketReferences)) {
$referencesFile = $this->config->basketReferences;
} else {
protected function detectPageDifferences($pagesInfos)
{
+ return false;
// Vérifie si la cropbox et la trimbox sont identiques pour toutes les pages
- $difference = false;
- foreach ($pagesInfos->pdf_data['page'] as $page => $infos) {
- if (!isset($infos['crop']) || !isset($infos['crop'])) {
- continue;
- }
- if ($infos['crop'] != $infos['trim']) {
- $difference = true;
- }
- }
- if (!$difference) {
- return false;
- }
- // VĂ©rifie si la trimbox dĂ©finie toutes les pages de la mĂȘme taille
- $heights = array();
- $widths = array();
- foreach ($pagesInfos->pdf_data['page'] as $page => $infos) {
- $heights[] = round($infos['trim']->height);
- $widths[] = round($infos['trim']->width);
- }
- $heights = array_unique($heights);
- $widths = array_unique($widths);
- if (count($heights) == 1 && count($widths) == 1) {
- $this->autocrop = 'trim';
- $this->manualcrop = false;
- } else {
- $this->autocrop = false;
- $this->manualcrop = true;
- }
+// $difference = false;
+// foreach ($pagesInfos->pdf_data['page'] as $page => $infos) {
+// if (!isset($infos['crop']) || !isset($infos['crop'])) {
+// continue;
+// }
+// if ($infos['crop'] != $infos['trim']) {
+// $difference = true;
+// }
+// }
+// if (!$difference) {
+// return false;
+// }
+// // VĂ©rifie si la trimbox dĂ©finie toutes les pages de la mĂȘme taille
+// $heights = array();
+// $widths = array();
+// foreach ($pagesInfos->pdf_data['page'] as $page => $infos) {
+// if (isset($infos['trim']['height'])) {
+// $heights[] = round($infos['trim']['height']);
+// $widths[] = round($infos['trim']['width']);
+// }
+// }
+// $heights = array_unique($heights);
+// $widths = array_unique($widths);
+// if (count($heights) <= 1 && count($widths) <= 1) {
+// $this->autocrop = 'trim';
+// $this->manualcrop = false;
+// } else {
+// $this->autocrop = false;
+// $this->manualcrop = true;
+// }
}
protected function detectSpreads($pagesInfos)