From 4781a140a67b59802b06cb9a237c311b8132a917 Mon Sep 17 00:00:00 2001 From: Christophe Ferreboeuf Date: Thu, 14 Nov 2024 15:53:52 +0100 Subject: [PATCH] fix title display bug --- Service/PDFWriter.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Service/PDFWriter.php b/Service/PDFWriter.php index a01b0be..c7c147e 100644 --- a/Service/PDFWriter.php +++ b/Service/PDFWriter.php @@ -229,18 +229,25 @@ private function manageSubResult(array $subResults): void */ private function displaySection(string $title, array $section): void { - $translatedTitle = $this->cliTranslator->translate($title); if ($this->columnCount !== 1) { $this->setColumnCount(1); } - $this->currentPage->drawText($translatedTitle, 44, $this->y); - foreach ($section as $type => $entries) { + if ($this->shouldDisplaySectionTitle($section)) { + $translatedTitle = $this->cliTranslator->translate($title); + $this->currentPage->drawText($translatedTitle, 44, $this->y); + } else { + return; + } + foreach ($section as $entries) { if (isset($entries['specificSections'])) { $sectionName = $entries['specificSections']; unset($entries['specificSections']); if (!isset($this->specificSections[$sectionName]) || !$this->specificSections[$sectionName] instanceof SectionInterface) { throw new \InvalidArgumentException("Specific section $sectionName is not valid"); } + if ($entries['files'] === []) { + continue; + } $numberOfPages = $this->specificSections[$sectionName]->calculateSize($entries) / 800; if ($numberOfPages > 10) { $this->delegateToAnnex($numberOfPages, $entries, $title, $sectionName); @@ -253,6 +260,18 @@ private function displaySection(string $title, array $section): void } } + private function shouldDisplaySectionTitle(array $section): bool + { + $shouldDisplay = false; + foreach ($section as $entries) { + if (!empty($entries['files'])) { + $shouldDisplay = true; + break; + } + } + return $shouldDisplay; + } + /** * The generic function to write subsections. It displays the title, the explanation and the files. *