]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6717 @4:00
authorsoufiane <soufiane@cubedesigners.com>
Tue, 13 Feb 2024 15:52:56 +0000 (16:52 +0100)
committersoufiane <soufiane@cubedesigners.com>
Tue, 13 Feb 2024 15:52:56 +0000 (16:52 +0100)
app/Console/Commands/FluidbookSettingsExport.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php

index ab126bce4f60d2079edb75d8c740e3572a90451e..115af783569a132f63076b45746a085c01537ebf 100644 (file)
@@ -4,14 +4,18 @@ namespace App\Console\Commands;
 
 use App\Console\Commands\Base\ToolboxCommand;
 use App\Models\FluidbookPublication;
+use App\Models\Traits\PublicationSettings;
 use App\Models\User;
 use App\Notifications\ToolboxNotification;
+use App\SubForms\Link\Color;
 use Cubist\Util\ArrayUtil;
 use Cubist\Util\Files\Files;
 use Illuminate\Support\Facades\Mail;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\Style\Fill;
 use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
+use PhpOffice\PhpSpreadsheet\Style\Protection;
 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
 use App\Mail\Base;
 
@@ -37,14 +41,32 @@ class FluidbookSettingsExport extends ToolboxCommand
     public function handle()
     {
         $userID = $this->getUser()->id;
-        $user = User::withoutGlobalScopes()->find(5908);
+        $user = User::withoutGlobalScopes()->find($userID); //5908
 
         //
         $listID = ArrayUtil::parseRange($this->argument('id'));
-        $settings = FluidbookPublication::whereIn('id',$listID)->get("settings")->map(function($i){
+        $model = FluidbookPublication::whereIn('id',$listID);
+
+        $settings = $model->get("settings")->map(function($i){
             return json_decode($i->settings, true);
         })->toArray();
 
+        $fields = $model->get()->map(function($i) {
+           return $i->getFields();
+        })->toArray();
+
+        $field = [];
+
+        foreach ($fields as $key => $f) {
+            foreach ($f as $g) {
+                $name = $g->getAttribute('name');
+                $field[$name] = [
+                    'type' => $g->getAttribute('type'),
+                    'editable' => $g->getAttribute('v2') ? json_decode($g->getAttribute('v2'),true)['editable'] : false
+                ];
+            }
+        }
+
         $keys = array_keys(array_merge(...$settings));
 
         $excel = new Spreadsheet();
@@ -54,7 +76,7 @@ class FluidbookSettingsExport extends ToolboxCommand
                 NumberFormat::FORMAT_TEXT
             );
         $sheet = $excel->getActiveSheet();
-        $sheetname = "test";
+        $sheetname = "Export";
         $sheet->setTitle($sheetname);
 
         $line = 1;
@@ -63,12 +85,18 @@ class FluidbookSettingsExport extends ToolboxCommand
 
         foreach ($keys as $key) {
             $c++;
-            $columns = max($columns, $c);
-            $cell = $sheet->getCellByColumnAndRow($c, $line);
-            $cell->setValue($key);
-            $style = $sheet->getStyleByColumnAndRow($c, $line);
-            $style->getFont()->setBold(true);
-            $style->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
+            if($field[$key]['type'] !== 'hidden') {
+                $columns = max($columns, $c);
+                $cell = $sheet->getCellByColumnAndRow($c, $line);
+                $cell->setValue($key);
+                $style = $sheet->getStyleByColumnAndRow($c, $line);
+                if(!$field[$key]['editable'] || $field[$key]['type'] === 'noteditable') {
+                    $style->getProtection()->setLocked(Protection::PROTECTION_PROTECTED);
+                    $style->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('dddddd');
+                }
+                $style->getFont()->setBold(true);
+                $style->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
+            }
         }
 
         for ($i = 0; $i < sizeof($settings); $i++) {
@@ -76,11 +104,16 @@ class FluidbookSettingsExport extends ToolboxCommand
             $line++;
             foreach ($keys as $key) {
                 $columns = max($columns, $c);
-                if (array_key_exists($key, $settings[$i])) {
+                if (array_key_exists($key, $settings[$i]) && $field[$key]['type'] !== 'hidden') {
                     $value = $settings[$i][$key] ?? "";
                     $value = is_array($value) ? json_encode($value) : $value;
                     $sheet->getCellByColumnAndRow($c, $line)->setValue($value);
                     $style = $sheet->getStyleByColumnAndRow($c, $line);
+
+                    if(!$field[$key]['editable'] || $field[$key]['type'] === 'noteditable') {
+                        $style->getProtection()->setLocked(Protection::PROTECTION_PROTECTED);
+                        $style->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('dddddd');
+                    }
                     $style->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
                     $style->getAlignment()->setWrapText(true);
                 }
@@ -97,10 +130,10 @@ class FluidbookSettingsExport extends ToolboxCommand
         $writer->save($tmpfile);
 
         $url = route('download_settings', ['file' => base64_encode($tmpfile)]);
-        $subject = "Export groupé des paramètres des fluidbooks prêt au téléchargement";
+        $subject = __("Export groupé des paramètres des fluidbooks prêt au téléchargement");
         $notification = '';
         $action = [
-            'Télécharger' => $url,
+            __('Télécharger') => $url,
         ];
 
         $user->notify(new ToolboxNotification($subject, $notification, $action, true));
index 32e9fb43d2cedd950c067c59e715cfbe3031ff36..5cc6c39f9f24f479b1c1fb140c9748d3d45c6aff 100644 (file)
@@ -132,6 +132,6 @@ trait DownloadOperation
         $name = "settings_export";
         $path = base64_decode($file);
         if(!file_exists($path)) abort(404);
-        return response()->download($path, $name . '.xlsx')->deleteFileAfterSend(true);
+        return response()->download($path, $name . '.xlsx');
     }
 }