]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7828 @0:20
authorsoufiane <soufiane@cubedesigners.com>
Tue, 4 Nov 2025 10:15:48 +0000 (11:15 +0100)
committersoufiane <soufiane@cubedesigners.com>
Tue, 4 Nov 2025 10:15:48 +0000 (11:15 +0100)
app/Http/Controllers/Admin/Operations/FluidbookCollection/AuditLinksOperation.php

index a43802bb79ae4488e70f813ba0f2d806cc0c3d77..5911754d392d21aa08cdb57c2006a1e10b7ae7e0 100644 (file)
@@ -37,65 +37,74 @@ trait AuditLinksOperation
             ->getNumberFormat()
             ->setFormatCode(
                 NumberFormat::FORMAT_TEXT
-            );
-        $sheet = $excel->getActiveSheet();
-        $sheetname_error = "Erreurs";
-        $sheet->setTitle($sheetname_error);
+        );
 
-        $excel->getActiveSheet()->getProtection()->setSheet(true);
-        $excel->getDefaultStyle()->getProtection()->setLocked(false);
+        $index = 0;
+        foreach ($links as $key => $link) {
+            $sheet = $excel->createSheet($index);
+            $sheetname = ucfirst($key);
+            $sheet->setTitle($sheetname);
 
-        foreach ($links as $sheets) {}
-        $line = 1;
-        $columns = 0;
-        $c = 0;
-
-        for ($i = 1; $i < sizeof($errorKeys); $i++) {
-            $c++;
-            $columns = max($columns, $c);
-            $cell = $sheet->getCellByColumnAndRow($c, $line);
-            $cell->setValue($errorKeys[$i]);
-            $style = $sheet->getStyleByColumnAndRow($c, $line);
-            $style->getFont()->setBold(true);
-            $style->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
-        }
+            $line = 1;
+            $columns = 0;
+            $c = 0;
 
-        $maxColSize = [];
-
-        for ($i = 0; $i < sizeof($errorlinks); $i++) {
-            $c = 1;
-            $line++;
-            foreach ($errorlinks[$i] as $k => $value) {
-                if($k === "id") {
-                    continue;
-                }
+            for ($i = 1; $i < sizeof($errorKeys); $i++) {
+                $c++;
                 $columns = max($columns, $c);
-                $maxColSize[$c][] = strlen($value);
-                $sheet->getCellByColumnAndRow($c, $line)->setValue($value);
+                $cell = $sheet->getCellByColumnAndRow($c, $line);
+                $cell->setValue($errorKeys[$i]);
                 $style = $sheet->getStyleByColumnAndRow($c, $line);
-                if ($k !== "new_url") {
-                    $style->getProtection()->setLocked(Protection::PROTECTION_PROTECTED);
-                }
+                $style->getFont()->setBold(true);
                 $style->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
-                $style->getAlignment()->setWrapText(false);
-                $c++;
             }
-        }
 
-        $j = 1;
-        for ($i = 0; $i <= $columns; $i++) {
-            if (array_key_exists($j, $maxColSize)) {
-                if (max($maxColSize[$j]) > 50) {
-                    $sheet->getColumnDimensionByColumn($j)->setWidth(100);
+            $maxColSize = [];
+
+            for ($i = 0; $i < sizeof($link); $i++) {
+                $c = 1;
+                $line++;
+                foreach ($link[$i] as $k => $value) {
+                    if($k === "id") {
+                        continue;
+                    }
+                    $columns = max($columns, $c);
+                    $maxColSize[$c][] = strlen($value);
+                    $sheet->getCellByColumnAndRow($c, $line)->setValue($value);
+                    $style = $sheet->getStyleByColumnAndRow($c, $line);
+                    if ($k !== "new_url") {
+                        $style->getProtection()->setLocked(Protection::PROTECTION_PROTECTED);
+                    }
+                    $style->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
+                    $style->getAlignment()->setWrapText(false);
+                    $c++;
+                }
+            }
+
+            $j = 1;
+            for ($i = 0; $i <= $columns; $i++) {
+                if (array_key_exists($j, $maxColSize)) {
+                    if (max($maxColSize[$j]) > 50) {
+                        $sheet->getColumnDimensionByColumn($j)->setWidth(100);
+                    } else {
+                        $sheet->getColumnDimensionByColumn($j)->setAutoSize(true);
+                    }
                 } else {
                     $sheet->getColumnDimensionByColumn($j)->setAutoSize(true);
                 }
-            } else {
-                $sheet->getColumnDimensionByColumn($j)->setAutoSize(true);
+                $j++;
             }
-            $j++;
+
+            $index++;
         }
 
+        $excel->setActiveSheetIndex(0);
+        $excel->getActiveSheet()->getProtection()->setSheet(true);
+        $excel->getDefaultStyle()->getProtection()->setLocked(false);
+
+        // Il y a une feuille "Worksheet" qui apparait alors qu'elle a pas été invitée
+        $excel->removeSheetByIndex(2);
+
         // Direct download
         $tmpfile = Files::tempnam() . '.xlsx';
         $writer = new Xlsx($excel);