]> git.agnieray.net Git - galette.git/blob - galette/lib/Galette/IO/PdfAdhesionForm.php
b42bc31abc4bc92eba9c9791a38562987cb6157a
[galette.git] / galette / lib / Galette / IO / PdfAdhesionForm.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\Db;
25 use Galette\Core\Preferences;
26 use Galette\Entity\Adherent;
27 use Galette\Entity\PdfModel;
28 use Galette\Entity\PdfAdhesionFormModel;
29 use Galette\IO\Pdf;
30 use Analog\Analog;
31
32 /**
33 * Adhesion Form PDF
34 *
35 * @author Guillaume Rousse <guillomovitch@gmail.com>
36 * @author Johan Cwiklinski <johan@x-tnd.be>
37 */
38
39 class PdfAdhesionForm extends Pdf
40 {
41 protected Db $zdb;
42 protected Adherent $adh;
43 protected Preferences $prefs;
44 protected string $filename;
45 private string $path;
46
47 /**
48 * Main constructor
49 *
50 * @param Adherent $adh Adherent
51 * @param Db $zdb Database instance
52 * @param Preferences $prefs Preferences instance
53 */
54 public function __construct(Adherent $adh, Db $zdb, Preferences $prefs)
55 {
56 $this->zdb = $zdb;
57 $this->adh = $adh;
58 $this->prefs = $prefs;
59
60 $model = $this->getModel();
61 parent::__construct($prefs, $model);
62
63 $this->filename = $adh->id ?
64 __("adherent_form") . '.' . $adh->id . '.pdf' : __("adherent_form") . '.pdf';
65
66 $this->Open();
67
68 $this->AddPage();
69 if ($model !== null) {
70 $this->PageHeader();
71 $this->PageBody();
72 }
73 }
74
75 /**
76 * Get model
77 *
78 * @return ?PdfModel
79 */
80 protected function getModel(): ?PdfModel
81 {
82 $model = new PdfAdhesionFormModel($this->zdb, $this->prefs);
83 $model->setMember($this->adh);
84
85 return $model;
86 }
87
88 /**
89 * Store PDF
90 *
91 * @param string $path Path
92 *
93 * @return boolean
94 */
95 public function store(string $path): bool
96 {
97 if (file_exists($path) && is_dir($path) && is_writeable($path)) {
98 $this->path = $path . '/' . $this->filename;
99 $this->Output($this->path, 'F');
100 return true;
101 } else {
102 Analog::log(
103 __METHOD__ . ' ' . $path .
104 ' does not exists or is not a directory or is not writeable.',
105 Analog::ERROR
106 );
107 }
108 return false;
109 }
110
111 /**
112 * Get store path
113 *
114 * @return string
115 */
116 public function getPath(): string
117 {
118 return realpath($this->path);
119 }
120 }