]> _ Git - fluidbook-toolbox.git/commitdiff
fix #6585 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 20 Dec 2023 10:01:40 +0000 (11:01 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 20 Dec 2023 10:01:40 +0000 (11:01 +0100)
app/Fluidbook/Compiler/Compiler.php
app/Models/FluidbookHealthIssues.php

index c34a0b78c2a5e455d6c8a031be6cdc6f4e70f3af..f2e3449c9af8a1ae386c07e5e998ec741c0389a6 100644 (file)
@@ -555,6 +555,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
 
         $this->checkConfig();
         $this->checkPageLabels();
+        $this->checkChapters();
 
         // We need to be able to reference both navOrder and navOrderH so convert both to arrays
         // We also make sure there are no empty items in the arrays (see: http://php.net/manual/en/function.array-filter.php#111091)
@@ -585,6 +586,21 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
 
     }
 
+    protected function checkChapters()
+    {
+        $num = $this->_fluidbook->chaptersPagesNumber;
+        foreach ($this->_fluidbook->getChapters() as $chapter) {
+            if (in_array($chapter['decoration'], ['nocut', 'forcecut', 'column_head', 'separator'])) {
+                continue;
+            }
+            $error = ($num === 'virtual' && !$this->virtualToPhysical($chapter['page'], true)) || ($num === 'physical' && $chapter['page'] > $this->_fluidbook->getPagesNumber());
+            if ($error) {
+                FluidbookHealthIssues::addIssue($this->book_id, FluidbookHealthIssues::TYPE_CHAPTER_PAGE_NOT_EXIST, ['chapter' => $chapter['label'], 'page' => $chapter['page']]);
+            }
+
+        }
+    }
+
     protected function checkConfig()
     {
         if ($this->isMobileFirst() && $this->fluidbookSettings->mobilefirstFluidbookId) {
@@ -673,12 +689,15 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
         return $this->linkScale;
     }
 
-    public function virtualToPhysical($virtual): string|int
+    public function virtualToPhysical($virtual, $returnFalseIfNotExist = false): string|int
     {
         if (isset($this->pageLabels[$virtual])) {
             return $virtual;
         }
         if (!in_array($virtual, $this->numerotation)) {
+            if ($returnFalseIfNotExist) {
+                return false;
+            }
             return $virtual;
         }
         $p = array_search($virtual, $this->numerotation);
index e3a5988181dbdaf8b00168a4dfc542341199366b..8b3fb46c49eec493ffd91ad4c55d69e7ac3cc12a 100644 (file)
@@ -16,6 +16,7 @@ class FluidbookHealthIssues extends ToolboxModel
     const TYPE_MOBILEFIRST_CONFIG = 3;
     const TYPE_TTS_VOICE_INVALID = 4;
     const TYPE_COMPILE_FILES = 5;
+    const TYPE_CHAPTER_PAGE_NOT_EXIST=6;
 
     const CRIT_ERROR = 5;
     const CRIT_WARNING = 3;
@@ -69,6 +70,7 @@ class FluidbookHealthIssues extends ToolboxModel
          * __('Ce fluidbook mobile first a le paramètre "Identifiant du fluidbook Mobile first" défini. Ce paramètre est réservé aux fluidbooks Desktop')
          * __('La voix d\'audiodescription :voice est invalide')
          * __('L\'erreur suivante s\'est produite lors de la compilation du fluidbook : :error')
+         * __('Page introuvable pour le chapitre intitulé :chapter (Page :page). L\'élement ne sera pas affiché dans la publication')
          *
  */
         return [
@@ -107,6 +109,14 @@ class FluidbookHealthIssues extends ToolboxModel
                     'criticality' => self::CRIT_ERROR,
                     'text' => 'L\'erreur suivante s\'est produite lors de la compilation du fluidbook : :error',
                 ],
+            static::TYPE_CHAPTER_PAGE_NOT_EXIST =>
+                [
+                    'summary' => __('Page de sommaire introuvable'),
+                    'criticality' => self::CRIT_ERROR,
+                    'text' => 'Page introuvable pour le chapitre intitulé :chapter (Page :page). L\'élement ne sera pas affiché dans la publication.',
+                    'fixText' => __('Editer le sommaire'),
+                    'fixURL' => route('fluidbook-publication.edit', ['id' => $fluidbookId]) . '#s_section_chapters',
+                ],
         ];
     }