From 72a10acc5b50b56fa007e8c81793f5d040e4b9a7 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 3 May 2024 13:17:16 +0200 Subject: [PATCH] phpcs --- galette/lib/Galette/IO/PdfMembersCards.php | 44 +++++++++++++++------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/galette/lib/Galette/IO/PdfMembersCards.php b/galette/lib/Galette/IO/PdfMembersCards.php index 380b00508..0bd3c3f4f 100644 --- a/galette/lib/Galette/IO/PdfMembersCards.php +++ b/galette/lib/Galette/IO/PdfMembersCards.php @@ -36,6 +36,9 @@ class PdfMembersCards extends Pdf { + public const PAGE_WIDTH = 210; + public const PAGE_HEIGHT = 297; + /** @var array */ private array $tcol; /** @var array */ @@ -252,7 +255,7 @@ public function drawCards(array $members): void $this->year_font_size ) / 2 ; $this->SetXY($xan_cot, $y0 + 1); - $this->writeHTML('' . $an_cot . '', false, 0); + $this->writeHTML('' . $an_cot . '', false, false); // Colored Text (Big label, id, year) $this->SetTextColor($fcol['R'], $fcol['G'], $fcol['B']); @@ -262,12 +265,12 @@ public function drawCards(array $members): void $member_id = (!empty($member->number)) ? $member->number : $member->id; $xid = $x0 + $this->wi / 2 - $this->GetStringWidth(_T("Member") . ' n° : ' . $member_id, self::FONT, 'B', 8) / 2; $this->SetXY($xid, $y0 + 8); - $this->writeHTML('' . _T("Member") . ' n° : ' . $member_id . ' ', false, 0); + $this->writeHTML('' . _T("Member") . ' n° : ' . $member_id . ' ', false, false); } $this->SetFontSize($this->year_font_size); $xan_cot = $xan_cot - 0.1; $this->SetXY($xan_cot, $y0 + 1 - 0.1); - $this->writeHTML('' . $an_cot . '', false, 0); + $this->writeHTML('' . $an_cot . '', false, false); // Abbrev: Adapt font size to text length $this->fixSize( @@ -278,7 +281,7 @@ public function drawCards(array $members): void ); $xid = $x0 + $this->wi / 2 - $this->GetStringWidth($this->abrev, self::FONT, 'B', 12) / 2; $this->SetXY($xid, $y0 + 12); - $this->writeHTML('' . $this->abrev . '', true, 0); + $this->writeHTML('' . $this->abrev . '', true, false); // Name: Adapt font size to text length $this->SetTextColor(0); @@ -290,7 +293,7 @@ public function drawCards(array $members): void ); $this->SetXY($x0 + round($this->wi / 3.5) + 2, $y0 + $this->hlogo + 3); //$this->setX($x0 + 27); - $this->writeHTML('' . $nom_adh_ext . '', true, 0); + $this->writeHTML('' . $nom_adh_ext . '', true, false); // Email (adapt too) $this->fixSize( @@ -300,7 +303,7 @@ public function drawCards(array $members): void 'B' ); $this->setX($x0 + round($this->wi / 3.5) + 2); - $this->writeHTML('' . $email . '', false, 0); + $this->writeHTML('' . $email . '', false, false); // Lower colored strip with long text $this->SetFillColor($fcol['R'], $fcol['G'], $fcol['B']); @@ -360,11 +363,18 @@ public static function getCols(): int { global $preferences; - $nbcols = round(((210 - $preferences->pref_card_marges_h * 2) / $preferences->pref_card_hsize), 0, PHP_ROUND_HALF_DOWN) ; - if ((($nbcols - 1) * $preferences->pref_card_hspace + $preferences->pref_card_marges_h * 2 + $preferences->pref_card_hsize * $nbcols) > 210) { - $nbcols = $nbcols - 1 ; + $margins = $preferences->pref_card_marges_h * 2; + + $nbcols = (int)round( + ((self::PAGE_WIDTH - $margins) / $preferences->pref_card_hsize), + 0, + PHP_ROUND_HALF_DOWN + ); + if ((($nbcols - 1) * $preferences->pref_card_hspace + $margins + $preferences->pref_card_hsize * $nbcols) > self::PAGE_WIDTH) { + --$nbcols; } - return $nbcols ; + + return $nbcols; } /** @@ -376,11 +386,17 @@ public static function getRows(): int { global $preferences; - $nbrows = round(((297 - $preferences->pref_card_marges_v * 2) / $preferences->pref_card_vsize), 0, PHP_ROUND_HALF_DOWN) ; - if ((($nbrows - 1) * $preferences->pref_card_vspace + $preferences->pref_card_marges_v * 2 + $preferences->pref_card_vsize * $nbrows) > 297) { - $nbrows = $nbrows - 1 ; + $margins = $preferences->pref_card_marges_v * 2; + + $nbrows = (int)round( + ((self::PAGE_HEIGHT - $margins) / $preferences->pref_card_vsize), + 0, + PHP_ROUND_HALF_DOWN + ); + if ((($nbrows - 1) * $preferences->pref_card_vspace + $margins + $preferences->pref_card_vsize * $nbrows) > self::PAGE_HEIGHT) { + --$nbrows; } - return $nbrows ; + return $nbrows; } }