]> git.agnieray.net Git - galette.git/blob - galette/lib/Galette/IO/PdfGroups.php
195e2b2825af9cefc72aebd53917a4849b505baf
[galette.git] / galette / lib / Galette / IO / PdfGroups.php
1 <?php
2
3 /**
4 * Copyright © 2003-2024 The Galette Team
5 *
6 * This file is part of Galette (https://galette.eu).
7 *
8 * Galette is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * Galette is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 namespace Galette\IO;
23
24 use Galette\Core\Preferences;
25 use Galette\Core\PrintLogo;
26 use Analog\Analog;
27 use Galette\Core\Login;
28 use Galette\Entity\Group;
29
30 /**
31 * Groups list PDF
32 *
33 * @author Johan Cwiklinski <johan@x-tnd.be>
34 */
35
36 class PdfGroups extends Pdf
37 {
38 public const SHEET_FONT = self::FONT_SIZE - 2;
39
40 private string $doc_title;
41
42 /**
43 * Main constructor, set creator and author
44 *
45 * @param Preferences $prefs Preferences
46 */
47 public function __construct(Preferences $prefs)
48 {
49 parent::__construct($prefs);
50 $this->filename = __('groups_list') . '.pdf';
51 $this->init();
52 }
53
54 /**
55 * Draws PDF page Header
56 *
57 * @return void
58 */
59 public function Header(): void // phpcs:ignore PSR1.Methods.CamelCapsMethodName
60 {
61 $this->Cell(
62 0,
63 10,
64 _T("Members by groups"),
65 0,
66 0,
67 'C',
68 false,
69 '',
70 0,
71 false,
72 'M',
73 'M'
74 );
75 }
76
77 /**
78 * Initialize PDF
79 *
80 * @return void
81 */
82 private function init(): void
83 {
84 // Set document information
85 $this->doc_title = _T("Members by groups");
86 $this->SetTitle($this->doc_title);
87 $this->SetSubject(_T("Generated by Galette"));
88
89 // Enable Auto Page breaks
90 $this->SetAutoPageBreak(true, 20);
91
92 // Set colors
93 $this->SetTextColor(0, 0, 0);
94
95 // Set margins
96 $this->setMargins(10, 20);
97 $this->setHeaderMargin(10);
98
99 // Set font
100 $this->SetFont(self::FONT, '', self::SHEET_FONT);
101
102 //enable pagination
103 $this->showPagination();
104 }
105
106 /**
107 * Draw file
108 *
109 * @param array<Group> $groups Groups list
110 * @param Login $login Login instance
111 *
112 * @return void
113 */
114 public function draw(array $groups, Login $login): void
115 {
116 $this->Open();
117 $this->AddPage();
118 $this->PageHeader($this->doc_title);
119
120 $first = true;
121 foreach ($groups as $group) {
122 $id = $group->getId();
123 if (!$login->isGroupManager($id)) {
124 Analog::log(
125 'Trying to export group ' . $id . ' as PDF without appropriate permissions',
126 Analog::INFO
127 );
128 continue;
129 }
130 // Header
131 if ($first === false) {
132 $this->ln(5);
133 }
134 $this->SetFont('', 'B', self::SHEET_FONT + 1);
135 $this->Cell(190, 4, $group->getName(), 0, 1, 'C');
136 $this->SetFont('', '', self::SHEET_FONT);
137
138 $managers_list = $group->getManagers();
139 $managers = array();
140 foreach ($managers_list as $m) {
141 $managers[] = $m->sfullname;
142 }
143 if (count($managers) > 0) {
144 $this->Cell(
145 190,
146 4,
147 _T("Managers:") . ' ' . implode(', ', $managers),
148 0,
149 1,
150 ($this->i18n->isRTL() ? 'L' : 'R')
151 );
152 }
153 $this->ln(3);
154
155 $this->SetFont('', 'B');
156 $this->SetFillColor(255, 255, 255);
157 $this->Cell(80, 7, _T("Name"), 1, 0, 'C', true);
158 $this->Cell(50, 7, _T("Email"), 1, 0, 'C', true);
159 $this->Cell(30, 7, _T("Phone"), 1, 0, 'C', true);
160 $this->Cell(30, 7, _T("GSM"), 1, 1, 'C', true);
161
162 $this->SetFont('', 'B');
163
164 $members = $group->getMembers();
165
166 foreach ($members as $m) {
167 $align = ($this->i18n->isRTL() ? 'R' : 'L');
168 $this->Cell(80, 7, $m->sname, 1, 0, $align);
169 $this->Cell(50, 7, $m->email, 1, 0, $align);
170 $this->Cell(30, 7, $m->phone, 1, 0, $align);
171 $this->Cell(30, 7, $m->gsm, 1, 1, $align);
172 }
173 $this->Cell(190, 0, '', 'T');
174 $first = false;
175 }
176 }
177 }