From e2af8a09a5117b4dca4bad113c0cbd9227ca95a1 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 16 Aug 2022 20:10:04 +0200 Subject: [PATCH] wip #5383 @0.25 --- app/Console/Commands/WorkshopMigration.php | 39 ++++++++++++++++++- app/Fields/FluidbookChapters.php | 35 ----------------- app/SubForms/FluidbookChapter.php | 1 - .../views/fields/fluidbook_chapters.blade.php | 4 +- 4 files changed, 40 insertions(+), 39 deletions(-) diff --git a/app/Console/Commands/WorkshopMigration.php b/app/Console/Commands/WorkshopMigration.php index c7a7b6636..c63d841db 100644 --- a/app/Console/Commands/WorkshopMigration.php +++ b/app/Console/Commands/WorkshopMigration.php @@ -34,7 +34,7 @@ class WorkshopMigration extends CubistCommand $actions = [ //'Backup current database' => 'backup', 'Migrate magic models' => 'migrate', - 'Import documents' => 'importDocuments', + //'Import documents' => 'importDocuments', 'Import publications' => 'importPublications', 'Clean caches' => 'cleanCache' ]; @@ -207,6 +207,8 @@ class WorkshopMigration extends CubistCommand $date = new \DateTime(); $date->setTimestamp($data); $data = $date; + } else if ($k === 'chapters') { + $data = $this->_normalizeChapters($data); } if (isset($mapValues[$data])) { $data = $mapValues[$data]; @@ -232,5 +234,40 @@ class WorkshopMigration extends CubistCommand } } + public function _normalizeChapters($value) + { + if (!$value) { + return $value; + } + if (is_string($value)) { + $v = json_decode($value, true); + } else { + $v = $value; + } + if (!$v) { + return $value; + } + $res = []; + foreach ($v as $k => $chapter) { + $chapter['decoration'] = 'regular'; + $chapter['label'] = trim($chapter['label']); + if ($chapter['label'] === '----') { + $chapter['label'] = ''; + $chapter['decoration'] = 'separator'; + } else if ($chapter['label'] === '--') { + $chapter['label'] = ''; + $chapter['decoration'] = 'forcecut'; + } else if ($chapter['label'] === '++') { + $chapter['label'] = ''; + $chapter['decoration'] = 'nocut'; + } else if (str_starts_with($chapter['label'], '!!!')) { + $chapter['label'] = substr($chapter['label'], 3); + $chapter['decoration'] = 'column_head'; + } + $res[$k] = $chapter; + } + + return $res; + } } diff --git a/app/Fields/FluidbookChapters.php b/app/Fields/FluidbookChapters.php index b300d23ea..9d197ab0b 100644 --- a/app/Fields/FluidbookChapters.php +++ b/app/Fields/FluidbookChapters.php @@ -17,40 +17,5 @@ class FluidbookChapters extends BunchOfFieldsMultiple return array_merge(parent::getDefaultAttributes(), ["add_label" => __('Nouveau chapitre')]); } - public function filterValue($value) - { - if (!$value) { - return $value; - } - if (is_string($value)) { - $v = json_decode($value, true); - } else { - $v = $value; - } - if (!$v) { - return $value; - } - $res = []; - foreach ($v as $k => $chapter) { - $chapter['decoration'] = 'regular'; - $chapter['label'] = trim($chapter['label']); - if ($chapter['label'] === '----') { - $chapter['label'] = ''; - $chapter['decoration'] = 'separator'; - } else if ($chapter['label'] === '--') { - $chapter['label'] = ''; - $chapter['decoration'] = 'forcecut'; - } else if ($chapter['label'] === '++') { - $chapter['label'] = ''; - $chapter['decoration'] = 'nocut'; - } else if (str_starts_with($chapter['label'], '!!!')) { - $chapter['label'] = substr($chapter['label'], 3); - $chapter['decoration'] = 'column_head'; - } - $res[$k] = $chapter; - } - - return parent::filterValue(json_encode($res)); - } } diff --git a/app/SubForms/FluidbookChapter.php b/app/SubForms/FluidbookChapter.php index f97a74651..7e3987055 100644 --- a/app/SubForms/FluidbookChapter.php +++ b/app/SubForms/FluidbookChapter.php @@ -29,6 +29,5 @@ class FluidbookChapter extends SubForm ] ]); $this->addField('level', FluidbookChapterLevel::class, __('Niveau'), ['default' => 1, 'min' => 0, 'max' => 3]); - } } diff --git a/resources/views/fields/fluidbook_chapters.blade.php b/resources/views/fields/fluidbook_chapters.blade.php index 95a712ca4..32e4358dc 100644 --- a/resources/views/fields/fluidbook_chapters.blade.php +++ b/resources/views/fields/fluidbook_chapters.blade.php @@ -68,8 +68,8 @@ @endif @php - $additionalButtons=' '.__('Remplacer par le contenu d\'un fichier excel').''; - $additionalButtons.=' '.__('Exporter au format excel').''; + $additionalButtons=' '.__('Remplacer par le contenu d\'un fichier excel').''; + $additionalButtons.=' '.__('Exporter au format excel').''; @endphp @include('cubist_back::fields.bunch_oneline_multiple') @php -- 2.39.5