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
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.7.5dev - 2013-07-07
41 use Galette\Core\Preferences
;
42 use Galette\DynamicFields\DynamicField
;
43 use Galette\Entity\Adherent
;
44 use Galette\Entity\PdfModel
;
45 use Galette\Entity\PdfAdhesionFormModel
;
46 use Galette\Entity\DynamicFieldsHandle
;
56 * @abstract Class for expanding TCPDF.
57 * @author Guillaume Rousse <guillomovitch@gmail.com>
58 * @copyright 2013-2014 The Galette Team
59 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
60 * @link http://galette.tuxfamily.org
61 * @since Available since 0.7.5dev - 2013-07-07
64 class PdfAdhesionForm
extends Pdf
75 * @param Adherent $adh Adherent
76 * @param Db $zdb Database instance
77 * @param Preferences $prefs Preferences instance
79 public function __construct(Adherent
$adh = null, Db
$zdb, Preferences
$prefs)
83 $this->prefs
= $prefs;
85 $model = $this->getModel();
86 parent
::__construct($prefs, $model);
88 $this->filename
= $adh ?
89 __("adherent_form") . '.' . $adh->id
. '.pdf' : __("adherent_form") . '.pdf';
94 if ($model !== null) {
105 protected function getModel()
109 $model = new PdfAdhesionFormModel($this->zdb
, $this->prefs
, PdfModel
::ADHESION_FORM_MODEL
);
110 $dynamic_patterns = $model->extractDynamicPatterns();
114 'adh_title' => '/{TITLE_ADH}/',
115 'adh_id' => '/{ID_ADH}/',
116 'adh_name' => '/{NAME_ADH}/',
117 'adh_last_name' => '/{LAST_NAME_ADH}/',
118 'adh_first_name' => '/{FIRST_NAME_ADH}/',
119 'adh_nick_name' => '/{NICKNAME_ADH}/',
120 'adh_gender' => '/{GENDER_ADH}/',
121 'adh_birth_date' => '/{ADH_BIRTH_DATE}/',
122 'adh_birth_place' => '/{ADH_BIRTH_PLACE}/',
123 'adh_profession' => '/{PROFESSION_ADH}/',
124 'adh_company' => '/{COMPANY_ADH}/',
125 'adh_address' => '/{ADDRESS_ADH}/',
126 'adh_zip' => '/{ZIP_ADH}/',
127 'adh_town' => '/{TOWN_ADH}/',
128 'adh_country' => '/{COUNTRY_ADH}/',
129 'adh_phone' => '/{PHONE_ADH}/',
130 'adh_mobile' => '/{MOBILE_ADH}/',
131 'adh_email' => '/{EMAIL_ADH}/',
132 'adh_login' => '/{LOGIN_ADH}/',
133 'adh_main_group' => '/{GROUP_ADH}/',
134 'adh_groups' => '/{GROUPS_ADH}/'
138 foreach ($dynamic_patterns as $pattern) {
139 $key = strtolower($pattern);
140 $model->setPatterns(array($key => "/\{$pattern\}/"));
141 Analog
::log("adding dynamic pattern $key => {" . $pattern . "}", Analog
::DEBUG
);
144 if ($this->adh
!== null) {
145 $address = $this->adh
->address
;
146 if ($this->adh
->address_continuation
!= '') {
147 $address .= '<br/>' . $this->adh
->address_continuation
;
150 if ($this->adh
->isMan()) {
152 } elseif ($this->adh
->isWoman()) {
153 $gender = _T("Woman");
155 $gender = _T("Unspecified");
158 $member_groups = $this->adh
->groups
;
159 $main_group = _T("None");
160 $group_list = _T("None");
161 if (is_array($member_groups) && count($member_groups) > 0) {
162 $main_group = $member_groups[0]->getName();
163 $group_list = '<ul>';
164 foreach ($member_groups as $group) {
165 $group_list .= '<li>' . $group->getName() . '</li>';
167 $group_list .= '</ul>';
170 $model->setReplacements(
172 'adh_title' => $this->adh
->stitle
,
173 'adh_id' => $this->adh
->id
,
174 'adh_name' => $this->adh
->sfullname
,
175 'adh_last_name' => $this->adh
->surname
,
176 'adh_first_name' => $this->adh
->name
,
177 'adh_nickname' => $this->adh
->nickname
,
178 'adh_gender' => $gender,
179 'adh_birth_date' => $this->adh
->birthdate
,
180 'adh_birth_place' => $this->adh
->birth_place
,
181 'adh_profession' => $this->adh
->job
,
182 'adh_company' => $this->adh
->company_name
,
183 'adh_address' => $address,
184 'adh_zip' => $this->adh
->zipcode
,
185 'adh_town' => $this->adh
->town
,
186 'adh_country' => $this->adh
->country
,
187 'adh_phone' => $this->adh
->phone
,
188 'adh_mobile' => $this->adh
->gsm
,
189 'adh_email' => $this->adh
->email
,
190 'adh_login' => $this->adh
->login
,
191 'adh_main_group' => $main_group,
192 'adh_groups' => $group_list
197 /** the list of all dynamic fields */
199 new \Galette\Repository\
DynamicFieldsSet($this->zdb
, $login);
200 $dynamic_fields = $fields->getList('adh');
202 foreach ($dynamic_patterns as $pattern) {
203 $key = strtolower($pattern);
205 if (preg_match('/^DYNFIELD_([0-9]+)_ADH$/', $pattern, $match)) {
206 /** dynamic field first value */
207 $field_id = $match[1];
208 if ($this->adh
!== null) {
209 $values = $this->adh
->getDynamicFields()->getValues($field_id);
213 if (preg_match('/^LABEL_DYNFIELD_([0-9]+)_ADH$/', $pattern, $match)) {
214 /** dynamic field label */
215 $field_id = $match[1];
216 $value = $dynamic_fields[$field_id]->getName();
218 if (preg_match('/^INPUT_DYNFIELD_([0-9]+)_ADH$/', $pattern, $match)) {
219 /** dynamic field input form element */
220 $field_id = $match[1];
221 $field_name = $dynamic_fields[$field_id]->getName();
222 $field_type = $dynamic_fields[$field_id]->getType();
223 $field_value = ['field_val' => ''];
224 if ($this->adh
!== null) {
225 $field_values = $this->adh
->getDynamicFields()->getValues($field_id);
226 $field_value = $field_values[0];
228 switch ($field_type) {
229 case DynamicField
::TEXT
:
230 $value .= '<textarea' .
231 ' id="' . $field_name . '"' .
232 ' name="' . $field_name . '"' .
233 ' value="' . $field_value['field_val'] . '"' .
236 case DynamicField
::LINE
:
237 $value .= '<input type="text"' .
238 ' id="' . $field_name . '"' .
239 ' name="' . $field_name . '"' .
240 ' value="' . $field_value['field_val'] . '"' .
241 ' size="20" maxlength="30"/>';
243 case DynamicField
::CHOICE
:
244 $choice_values = $dynamic_fields[$field_id]->getValues();
245 foreach ($choice_values as $choice_idx => $choice_value) {
246 $value .= '<input type="radio"' .
247 ' id="' . $field_name . '"' .
248 ' name="' . $field_name . '"' .
249 ' value="' . $choice_value . '"';
250 if ($choice_idx == $field_values[0]['field_val']) {
251 $value .= ' checked="checked"';
254 $value .= $choice_value;
258 case DynamicField
::DATE
:
259 $value .= '<input type="text" name="' .
260 $field_name . '" value="' .
261 $field_value . '" />';
263 case DynamicField
::BOOLEAN
:
264 $value .= '<input type="checkbox"' .
265 ' name="' . $field_name . '"' .
267 if ($field_value['field_val'] == 1) {
268 $value .= ' checked="checked"';
272 case DynamicField
::FILE
:
273 $value .= '<input type="text" name="' .
274 $field_name . '" value="' .
275 $field_value['field_val'] . '" />';
280 $model->setReplacements(array($key => $value));
281 Analog
::log("adding dynamic replacement $key => $value", Analog
::DEBUG
);
290 * @param string $path Path
294 public function store($path)
296 if (file_exists($path) && is_dir($path) && is_writeable($path)) {
297 $this->path
= $path . '/' . $this->filename
;
298 $this->Output($this->path
, 'F');
302 __METHOD__
. ' ' . $path .
303 ' does not exists or is not a directory or is not writeable.',
315 public function getPath()
317 return realpath($this->path
);