]> _ Git - cubeextranet.git/commitdiff
wip #4740 @4
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 22 Nov 2021 16:29:22 +0000 (16:29 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 22 Nov 2021 16:29:22 +0000 (16:29 +0000)
inc/ws/Controlleur/class.ws.maintenance.php

index dec4504d96a0000564204c000b2bc73d969e4b1d..feed2161d6bd0986777f6e610e4f502af1a50edc 100644 (file)
@@ -1717,6 +1717,92 @@ class wsMaintenance
         exit;
     }
 
+    public static function wescogroups()
+    {
+        CubeIT_Library::PHPExcel();
+        $reader = new PHPExcel_Reader_Excel2007();
+        $file = '/home/wesco/groups.xlsx';
+        if (!file_exists($file)) {
+            die(':(');
+        }
+        $xlsx = $reader->load('/home/wesco/groups.xlsx');
+
+        ob_end_clean();
+        $allgroups = [];
+        foreach ($xlsx->getAllSheets() as $s) {
+            if ($s->getTitle() === 'Lexique' || $s->getSheetState() !== PHPExcel_Worksheet::SHEETSTATE_VISIBLE) {
+                continue;
+            }
+            $groups = [];
+            $subgroups = [];
+            foreach ($s->getRowIterator() as $row) {
+                $rowIndex = $row->getRowIndex();
+                foreach ($row->getCellIterator() as $cell) {
+                    $v = trim($cell->getValue());
+                    $colIndex = PHPExcel_Cell::columnIndexFromString($cell->getColumn());
+
+                    if (isset($groups[$colIndex])) {
+                        $groupname = $groups[$colIndex];
+                    } else {
+                        $groupname = '';
+                    }
+
+                    if (isset($subgroups[$colIndex])) {
+                        $subgroupname = $subgroups[$colIndex];
+                    } else {
+                        $subgroupname = '';
+                    }
+
+                    if (!$v) {
+                        continue;
+                    }
+                    if ($cell->getMergeRange()) {
+
+                        $e = explode(':', $cell->getMergeRange(), 2);
+                        $start = PHPExcel_Cell::columnIndexFromString(substr($e[0], 0, 1));
+                        $end = PHPExcel_Cell::columnIndexFromString(substr($e[1], 0, 1));
+
+                        for ($i = $start; $i <= $end; $i++) {
+                            $groups[$i] = $v;
+                        }
+                    } else if (preg_match('/^(\d{1,5})$/', $v, $matches)) {
+                        $grouplabel = $s->getTitle() . ' - ' . $groupname . ' - ' . $subgroupname;
+                        if (!isset($allgroups[$grouplabel])) {
+                            $allgroups[$grouplabel] = [];
+                        }
+                        $allgroups[$grouplabel][] = $v;
+                    } else {
+                        $subgroups[$colIndex] = $v;
+                    }
+                }
+            }
+
+        }
+
+        $res = [];
+        foreach ($allgroups as $k => $allgroup) {
+            $res[$k] = array_unique($allgroup);
+        }
+
+        $p = new PHPExcel();
+        $s = $p->getActiveSheet();
+        $s->setTitle('Groupes');
+        $s->setCellValueByColumnAndRow(0, 1, 'Onglet');
+        $s->setCellValueByColumnAndRow(1, 1, 'Références');
+        $rowIndex = 2;
+        foreach ($res as $groupName => $references) {
+            $s->setCellValueByColumnAndRow(0, $rowIndex, $groupName);
+            foreach ($references as $k => $reference) {
+                $s->setCellValueByColumnAndRow(1 + $k, $rowIndex, $reference);
+            }
+            $rowIndex++;
+        }
+        $writer = new PHPExcel_Writer_Excel2007($p);
+        $writer->save('/home/wesco/groups1.xlsx');
+
+        exit;
+    }
+
 }