3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2013-2014 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
30 * @author Guillaume Rousse <guillomovitch@gmail.com>
31 * @copyright 2013-2014 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @link http://galette.tuxfamily.org
34 * @since Available since 0.7.5dev - 2013-07-07
40 use Galette\Core\Preferences
;
41 use Galette\DynamicFields\DynamicField
;
42 use Galette\Entity\Adherent
;
43 use Galette\Entity\PdfModel
;
44 use Galette\Entity\PdfAdhesionFormModel
;
45 use Galette\Entity\DynamicFieldsHandle
;
55 * @abstract Class for expanding TCPDF.
56 * @author Guillaume Rousse <guillomovitch@gmail.com>
57 * @copyright 2013-2014 The Galette Team
58 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
59 * @link http://galette.tuxfamily.org
60 * @since Available since 0.7.5dev - 2013-07-07
63 class PdfAdhesionForm
extends Pdf
74 * @param Adherent $adh Adherent
75 * @param Db $zdb Database instance
76 * @param Preferences $prefs Preferences instance
78 public function __construct(Adherent
$adh = null, Db
$zdb, Preferences
$prefs)
82 $this->prefs
= $prefs;
84 $model = $this->getModel();
85 parent
::__construct($prefs, $model);
87 $this->filename
= $adh ?
88 __("adherent_form") . '.' . $adh->id
. '.pdf' : __("adherent_form") . '.pdf';
93 if ($model !== null) {
104 protected function getModel()
108 $model = new PdfAdhesionFormModel($this->zdb
, $this->prefs
, PdfModel
::ADHESION_FORM_MODEL
);
109 $dynamic_patterns = $model->extractDynamicPatterns();
113 'adh_title' => '/{TITLE_ADH}/',
114 'adh_id' => '/{ID_ADH}/',
115 'adh_name' => '/{NAME_ADH}/',
116 'adh_last_name' => '/{LAST_NAME_ADH}/',
117 'adh_first_name' => '/{FIRST_NAME_ADH}/',
118 'adh_nick_name' => '/{NICKNAME_ADH}/',
119 'adh_gender' => '/{GENDER_ADH}/',
120 'adh_birth_date' => '/{ADH_BIRTH_DATE}/',
121 'adh_birth_place' => '/{ADH_BIRTH_PLACE}/',
122 'adh_profession' => '/{PROFESSION_ADH}/',
123 'adh_company' => '/{COMPANY_ADH}/',
124 'adh_address' => '/{ADDRESS_ADH}/',
125 'adh_zip' => '/{ZIP_ADH}/',
126 'adh_town' => '/{TOWN_ADH}/',
127 'adh_country' => '/{COUNTRY_ADH}/',
128 'adh_phone' => '/{PHONE_ADH}/',
129 'adh_mobile' => '/{MOBILE_ADH}/',
130 'adh_email' => '/{EMAIL_ADH}/',
131 'adh_login' => '/{LOGIN_ADH}/',
132 'adh_main_group' => '/{GROUP_ADH}/',
133 'adh_groups' => '/{GROUPS_ADH}/'
137 foreach ($dynamic_patterns as $pattern) {
138 $key = strtolower($pattern);
139 $model->setPatterns(array($key => "/\{$pattern\}/"));
140 Analog
::log("adding dynamic pattern $key => {" . $pattern . "}", Analog
::DEBUG
);
143 if ($this->adh
!== null) {
144 $address = $this->adh
->address
;
145 if ($this->adh
->address_continuation
!= '') {
146 $address .= '<br/>' . $this->adh
->address_continuation
;
149 if ($this->adh
->isMan()) {
151 } elseif ($this->adh
->isWoman()) {
152 $gender = _T("Woman");
154 $gender = _T("Unspecified");
157 $member_groups = $this->adh
->groups
;
158 $main_group = _T("None");
159 $group_list = _T("None");
160 if (is_array($member_groups) && count($member_groups) > 0) {
161 $main_group = $member_groups[0]->getName();
162 $group_list = '<ul>';
163 foreach ($member_groups as $group) {
164 $group_list .= '<li>' . $group->getName() . '</li>';
166 $group_list .= '</ul>';
169 $model->setReplacements(
171 'adh_title' => $this->adh
->stitle
,
172 'adh_id' => $this->adh
->id
,
173 'adh_name' => $this->adh
->sfullname
,
174 'adh_last_name' => $this->adh
->surname
,
175 'adh_first_name' => $this->adh
->name
,
176 'adh_nickname' => $this->adh
->nickname
,
177 'adh_gender' => $gender,
178 'adh_birth_date' => $this->adh
->birthdate
,
179 'adh_birth_place' => $this->adh
->birth_place
,
180 'adh_profession' => $this->adh
->job
,
181 'adh_company' => $this->adh
->company_name
,
182 'adh_address' => $address,
183 'adh_zip' => $this->adh
->zipcode
,
184 'adh_town' => $this->adh
->town
,
185 'adh_country' => $this->adh
->country
,
186 'adh_phone' => $this->adh
->phone
,
187 'adh_mobile' => $this->adh
->gsm
,
188 'adh_email' => $this->adh
->email
,
189 'adh_login' => $this->adh
->login
,
190 'adh_main_group' => $main_group,
191 'adh_groups' => $group_list
196 /** the list of all dynamic fields */
198 new \Galette\Repository\
DynamicFieldsSet($this->zdb
, $login);
199 $dynamic_fields = $fields->getList('adh');
201 foreach ($dynamic_patterns as $pattern) {
202 $key = strtolower($pattern);
204 if (preg_match('/^DYNFIELD_([0-9]+)_ADH$/', $pattern, $match)) {
205 /** dynamic field first value */
206 $field_id = $match[1];
207 if ($this->adh
!== null) {
208 $values = $this->adh
->getDynamicFields()->getValues($field_id);
212 if (preg_match('/^LABEL_DYNFIELD_([0-9]+)_ADH$/', $pattern, $match)) {
213 /** dynamic field label */
214 $field_id = $match[1];
215 $value = $dynamic_fields[$field_id]->getName();
217 if (preg_match('/^INPUT_DYNFIELD_([0-9]+)_ADH$/', $pattern, $match)) {
218 /** dynamic field input form element */
219 $field_id = $match[1];
220 $field_name = $dynamic_fields[$field_id]->getName();
221 $field_type = $dynamic_fields[$field_id]->getType();
222 $field_value = ['field_val' => ''];
223 if ($this->adh
!== null) {
224 $field_values = $this->adh
->getDynamicFields()->getValues($field_id);
225 $field_value = $field_values[0];
227 switch ($field_type) {
228 case DynamicField
::TEXT
:
229 $value .= '<textarea' .
230 ' id="' . $field_name . '"' .
231 ' name="' . $field_name . '"' .
232 ' value="' . $field_value['field_val'] . '"' .
235 case DynamicField
::LINE
:
236 $value .= '<input type="text"' .
237 ' id="' . $field_name . '"' .
238 ' name="' . $field_name . '"' .
239 ' value="' . $field_value['field_val'] . '"' .
240 ' size="20" maxlength="30"/>';
242 case DynamicField
::CHOICE
:
243 $choice_values = $dynamic_fields[$field_id]->getValues();
244 foreach ($choice_values as $choice_idx => $choice_value) {
245 $value .= '<input type="radio"' .
246 ' id="' . $field_name . '"' .
247 ' name="' . $field_name . '"' .
248 ' value="' . $choice_value . '"';
249 if ($choice_idx == $field_values[0]['field_val']) {
250 $value .= ' checked="checked"';
253 $value .= $choice_value;
257 case DynamicField
::DATE
:
258 $value .= '<input type="text" name="' .
259 $field_name . '" value="' .
260 $field_value . '" />';
262 case DynamicField
::BOOLEAN
:
263 $value .= '<input type="checkbox"' .
264 ' name="' . $field_name . '"' .
266 if ($field_value['field_val'] == 1) {
267 $value .= ' checked="checked"';
271 case DynamicField
::FILE
:
272 $value .= '<input type="text" name="' .
273 $field_name . '" value="' .
274 $field_value['field_val'] . '" />';
279 $model->setReplacements(array($key => $value));
280 Analog
::log("adding dynamic replacement $key => $value", Analog
::DEBUG
);
289 * @param string $path Path
293 public function store($path)
295 if (file_exists($path) && is_dir($path) && is_writeable($path)) {
296 $this->path
= $path . '/' . $this->filename
;
297 $this->Output($this->path
, 'F');
301 __METHOD__
. ' ' . $path .
302 ' does not exists or is not a directory or is not writeable.',
314 public function getPath()
316 return realpath($this->path
);