From: soufiane Date: Tue, 13 Feb 2024 15:52:56 +0000 (+0100) Subject: wait #6717 @4:00 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=11f9ebab4458b6e1245118abe1fb26b4c8b9f39d;p=fluidbook-toolbox.git wait #6717 @4:00 --- diff --git a/app/Console/Commands/FluidbookSettingsExport.php b/app/Console/Commands/FluidbookSettingsExport.php index ab126bce4..115af7835 100644 --- a/app/Console/Commands/FluidbookSettingsExport.php +++ b/app/Console/Commands/FluidbookSettingsExport.php @@ -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)); diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php index 32e9fb43d..5cc6c39f9 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php @@ -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'); } }