PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.7.2
VikBooking Hotel Booking Engine & PMS v1.7.2
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / admin / helpers / src / checkin / paxfields / italy.php

italy.php in VikBooking Hotel Booking Engine & PMS 1.7.2, at admin/helpers/src/checkin/paxfields/italy.php

384 lines 11.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author Alessio Gaggii - E4J s.r.l.
6 * @copyright Copyright (C) 2022 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Helper class to support custom pax fields data collection types for Italy.
16 *
17 * @since 1.15.0 (J) - 1.5.0 (WP)
18 */
19 final class VBOCheckinPaxfieldsItaly extends VBOCheckinAdapter
20 {
21 /**
22 * The ID of this pax data collector class.
23 *
24 * @var string
25 */
26 protected $collector_id = 'italy';
27
28 /**
29 * Returns the name of the current pax data driver.
30 *
31 * @return string the name of this driver.
32 */
33 public function getName()
34 {
35 return '"Italia"';
36 }
37
38 /**
39 * Tells whether children should be registered.
40 *
41 * @override this driver requires children to be registered (back-end only).
42 *
43 * @param bool $precheckin true if requested for front-end pre check-in.
44 *
45 * @return bool true to also register the children.
46 *
47 * @since 1.16.3 (J) - 1.6.3 (WP) added $precheckin argument.
48 */
49 public function registerChildren($precheckin = false)
50 {
51 // children are registered only during back-end guests check-in
52 return $precheckin ? false : true;
53 }
54
55 /**
56 * Returns the list of field labels. The count and keys
57 * of the labels should match with the attributes.
58 *
59 * @see All fields ending with "_b" stand for "birth",
60 * all fields ending with "_s" stand for "stay",
61 * all fields ending with "_c" stand for "citizenship".
62 * Keep the ending char intact as some fields act differently
63 * depending on the number and type of guest we are parsing.
64 *
65 * @return array associative list of field labels.
66 */
67 public function getLabels()
68 {
69 return [
70 'guest_type' => JText::translate('VBO_GUEST_TYPE'),
71 'first_name' => JText::translate('VBCUSTOMERFIRSTNAME'),
72 'last_name' => JText::translate('VBCUSTOMERLASTNAME'),
73 'gender' => JText::translate('VBOCUSTGENDER'),
74 'date_birth' => JText::translate('ORDER_DBIRTH'),
75 'country_b' => JText::translate('VBO_BIRTH_STATE'),
76 'comune_b' => JText::translate('VBO_BIRTH_MUNICIPALITY'),
77 'province_b' => JText::translate('VBO_STATE_PROVINCE'),
78 'zip_b' => JText::translate('ORDER_ZIP'),
79 'country_s' => JText::translate('VBO_STAY_STATE'),
80 'comune_s' => JText::translate('VBO_STAY_MUNICIPALITY'),
81 'province_s' => JText::translate('VBO_STATE_PROVINCE'),
82 'zip_s' => JText::translate('ORDER_ZIP'),
83 'country_c' => JText::translate('VBOCUSTNATIONALITY'),
84 'doctype' => JText::translate('VBOCUSTDOCTYPE'),
85 'docnum' => JText::translate('VBOCUSTDOCNUM'),
86 'docplace' => JText::translate('VBO_ID_ISSUE_PLACE'),
87 'extranotes' => JText::translate('VBOGUESTEXTRANOTES'),
88 ];
89 }
90
91 /**
92 * Returns the list of field attributes. The count and keys
93 * of the attributes should match with the labels.
94 *
95 * @see All fields ending with "_b" stand for "birth",
96 * all fields ending with "_s" stand for "stay",
97 * all fields ending with "_c" stand for "citizenship".
98 * Keep the ending char intact as some fields act differently
99 * depending on the number and type of guest we are parsing.
100 *
101 * @return array associative list of field attributes.
102 */
103 public function getAttributes()
104 {
105 return [
106 'guest_type' => 'italy_guesttype',
107 'first_name' => 'text',
108 'last_name' => 'text',
109 'gender' => 'italy_gender',
110 'date_birth' => 'calendar',
111 'country_b' => 'italy_country',
112 'comune_b' => 'italy_comune',
113 'province_b' => 'italy_province',
114 'zip_b' => 'italy_cap',
115 'country_s' => 'italy_country',
116 'comune_s' => 'italy_comune',
117 'province_s' => 'italy_province',
118 'zip_s' => 'italy_cap',
119 'country_c' => 'italy_country',
120 'doctype' => 'italy_doctype',
121 'docnum' => 'italy_docnum',
122 'docplace' => 'italy_country',
123 'extranotes' => 'textarea',
124 ];
125 }
126
127 /**
128 * @inheritDoc
129 *
130 * @since 1.17.2 (J) - 1.7.2 (WP)
131 */
132 public function listPrecheckinFields(array $def_fields)
133 {
134 // use the same fields for the back-end guests registration
135 $labels = $this->getLabels();
136 $attributes = $this->getAttributes();
137
138 // for pre-checkin we keep any default field of type "file" for uploading IDs
139 foreach (($def_fields[1] ?? []) as $field_key => $field_type) {
140 if (!is_string($field_type)) {
141 // not looking for a list of options
142 continue;
143 }
144 if (!strcasecmp($field_type, 'file') && ($def_fields[0][$field_key] ?? null)) {
145 // append this pax field of type "file" for uploading IDs
146 $labels[$field_key] = $def_fields[0][$field_key];
147 $attributes[$field_key] = $field_type;
148 }
149 }
150
151 // return the list of pre-checkin pax fields
152 return [$labels, $attributes];
153 }
154
155 /**
156 * Parses the file Nazioni.csv and returns an associative
157 * array with the code and name of the "Nazione" (country).
158 *
159 * Public and internal method, not part of the interface.
160 * Useful for all the implementor fields that need it.
161 *
162 * @param bool $normalize Whether to normalize the country names into localised values.
163 *
164 * @return array
165 *
166 * @since 1.17.2 (J) - 1.7.2 (WP) added argument $normalize and related behaviour.
167 */
168 public function loadNazioni($normalize = true)
169 {
170 // always try access the registry instance data
171 $collect_registry = VBOCheckinPax::getInstanceData();
172
173 // check if the registry instance of this collection type has cached values
174 if ($collect_registry) {
175 $prev_country_codes = $collect_registry->get('nazioni');
176 if (is_array($prev_country_codes) && $prev_country_codes) {
177 // another field of this collection must have loaded already the "Nazioni"
178 return $prev_country_codes;
179 }
180 }
181
182 // container
183 $country_codes = [];
184
185 $csv = VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'report' . DIRECTORY_SEPARATOR . 'Nazioni.csv';
186 $rows = file($csv);
187 foreach ($rows as $row) {
188 if (empty($row)) {
189 continue;
190 }
191
192 $v = explode(';', $row);
193 if (count($v) != 3) {
194 continue;
195 }
196
197 // remove unwanted chars
198 $v[0] = trim($v[0]);
199
200 if (!isset($country_codes[$v[0]])) {
201 $country_codes[$v[0]] = [];
202 }
203
204 // push values
205 $country_codes[$v[0]]['name'] = trim($v[1]);
206 $country_codes[$v[0]]['three_code'] = trim($v[2]);
207 }
208
209 /**
210 * Apply translations based on country 3-char ISO code, if not in Italian or denied.
211 *
212 * @since 1.17.2 (J) - 1.7.2 (WP)
213 */
214 if ($normalize && strtolower(substr(JFactory::getLanguage()->getTag(), 0, 2)) !== 'it') {
215 // get the translated countries list
216 $tn_countries = VikBooking::getCountriesArray();
217
218 $country_codes = array_map(function($country_vals) use ($tn_countries) {
219 if (!($tn_countries[$country_vals['three_code']] ?? null)) {
220 // unknown country
221 return $country_vals;
222 }
223
224 // replace country name
225 $country_vals['name'] = $tn_countries[$country_vals['three_code']]['country_name'];
226
227 // return the modified country values array
228 return $country_vals;
229 }, $country_codes);
230 }
231
232 // try to cache the country codes for other fields that may need them later
233 if ($collect_registry) {
234 // cache array for other fields
235 $collect_registry->set('nazioni', $country_codes);
236 }
237
238 return $country_codes;
239 }
240
241 /**
242 * Parses the file Comuni.csv and returns two associative
243 * arrays: one for the Comuni and one for the Province.
244 * Every line of the CSV is composed of: Codice, Comune, Provincia.
245 *
246 * Public and internal method, not part of the interface.
247 * Useful for all the implementor fields that need it.
248 *
249 * @return array
250 */
251 public function loadComuniProvince()
252 {
253 // always try access the registry instance data
254 $collect_registry = VBOCheckinPax::getInstanceData();
255
256 // check if the registry instance of this collection type has cached values
257 if ($collect_registry) {
258 $prev_comprov_codes = $collect_registry->get('comuni_province');
259 if (is_array($prev_comprov_codes) && $prev_comprov_codes) {
260 // another field of this collection must have loaded already the "Comuni"
261 return $prev_comprov_codes;
262 }
263 }
264
265 // container
266 $comprov_codes = [
267 'comuni' => [],
268 'province' => [],
269 ];
270
271 $csv = VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'report' . DIRECTORY_SEPARATOR . 'Comuni.csv';
272 $rows = file($csv);
273 foreach ($rows as $row) {
274 if (empty($row)) {
275 continue;
276 }
277
278 $v = explode(';', $row);
279 if (count($v) != 3) {
280 continue;
281 }
282
283 // trim values
284 $v[0] = trim($v[0]);
285 $v[1] = trim($v[1]);
286 $v[2] = trim($v[2]);
287
288 if (!isset($comprov_codes['comuni'][$v[0]])) {
289 $comprov_codes['comuni'][$v[0]] = [];
290 }
291
292 // push values
293 $comprov_codes['comuni'][$v[0]]['name'] = $v[1];
294 $comprov_codes['comuni'][$v[0]]['province'] = $v[2];
295 $comprov_codes['province'][$v[2]] = $v[2];
296 }
297
298 // try to cache the comuni-province codes for other fields that may need them later
299 if ($collect_registry) {
300 // cache array for other fields
301 $collect_registry->set('comuni_province', $comprov_codes);
302 }
303
304 return $comprov_codes;
305 }
306
307 /**
308 * Parses the file Documenti.csv and returns an associative
309 * array with the code and name of the Documento.
310 * Every line of the CSV is composed of: Codice, Documento.
311 *
312 * Public and internal method, not part of the interface.
313 * Useful for all the implementor fields that need it.
314 *
315 * @param bool $normalize Whether to display values relevant to non-italian guests.
316 *
317 * @return array
318 *
319 * @since 1.17.2 (J) - 1.7.2 (WP) added argument $normalize and related behaviour.
320 */
321 public function loadDocumenti($normalize = false)
322 {
323 // always try access the registry instance data
324 $collect_registry = VBOCheckinPax::getInstanceData();
325
326 // check if the registry instance of this collection type has cached values
327 if ($collect_registry) {
328 $prev_documenti = $collect_registry->get('documenti');
329 if (is_array($prev_documenti) && $prev_documenti) {
330 // another field of this collection must have loaded already the "Comuni"
331 return $prev_documenti;
332 }
333 }
334
335 // container
336 $documenti = [];
337
338 $csv = VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'report' . DIRECTORY_SEPARATOR . 'Documenti.csv';
339 $rows = file($csv);
340 foreach ($rows as $row) {
341 if (empty($row)) {
342 continue;
343 }
344
345 $v = explode(';', $row);
346 if (count($v) != 2) {
347 continue;
348 }
349
350 // trim values
351 $v[0] = trim($v[0]);
352 $v[1] = trim($v[1]);
353
354 // push values
355 $documenti[$v[0]] = $v[1];
356 }
357
358 if ($normalize === true) {
359 // we expect these values to be displayed to non-italian guests
360 $known_documents = [
361 'PASOR' => JText::translate('VBO_PASSPORT'),
362 'PATEN' => JText::translate('VBO_DRIVING_LICENSE'),
363 'IDENT' => JText::translate('VBO_IDENTITY_DOCUMENT'),
364 ];
365
366 // filter documents by foreign types
367 $documenti = array_filter($documenti, function($doc_type) use ($known_documents) {
368 return isset($known_documents[$doc_type]);
369 }, ARRAY_FILTER_USE_KEY);
370
371 // normalize known document names
372 $documenti = array_merge($documenti, $known_documents);
373 }
374
375 // try to cache the documenti codes for other fields that may need them later
376 if ($collect_registry) {
377 // cache array for other fields
378 $collect_registry->set('documenti', $documenti);
379 }
380
381 return $documenti;
382 }
383 }
384