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;
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();
NumberFormat::FORMAT_TEXT
);
$sheet = $excel->getActiveSheet();
- $sheetname = "test";
+ $sheetname = "Export";
$sheet->setTitle($sheetname);
$line = 1;
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++) {
$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);
}
$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));