| 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' => 'Tipo alloggiato', |
| 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' => 'Stato di nascita', |
| 76 |
'comune_b' => 'Comune di nascita', |
| 77 |
'province_b' => 'Provincia', |
| 78 |
'zip_b' => JText::translate('ORDER_ZIP'), |
| 79 |
'country_s' => 'Stato di residenza', |
| 80 |
'comune_s' => 'Comune di residenza', |
| 81 |
'province_s' => 'Provincia', |
| 82 |
'zip_s' => 'CAP (residenza)', |
| 83 |
'country_c' => 'Cittadinanza', |
| 84 |
'doctype' => 'Tipo documento', |
| 85 |
'docnum' => JText::translate('VBCUSTOMERDOCNUM'), |
| 86 |
'docplace' => 'Luogo di rilascio', |
| 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 |
* Parses the file Nazioni.csv and returns an associative |
| 129 |
* array with the code and name of the "Nazione" (country). |
| 130 |
* |
| 131 |
* Public and internal method, not part of the interface. |
| 132 |
* Useful for all the implementor fields that need it. |
| 133 |
* |
| 134 |
* @return array |
| 135 |
*/ |
| 136 |
public function loadNazioni() |
| 137 |
{ |
| 138 |
// always try access the registry instance data |
| 139 |
$collect_registry = VBOCheckinPax::getInstanceData(); |
| 140 |
|
| 141 |
// check if the registry instance of this collection type has cached values |
| 142 |
if ($collect_registry) { |
| 143 |
$prev_country_codes = $collect_registry->get('nazioni'); |
| 144 |
if (is_array($prev_country_codes) && count($prev_country_codes)) { |
| 145 |
// another field of this collection must have loaded already the "Nazioni" |
| 146 |
return $prev_country_codes; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
// container |
| 151 |
$country_codes = array(); |
| 152 |
|
| 153 |
$csv = VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'report' . DIRECTORY_SEPARATOR . 'Nazioni.csv'; |
| 154 |
$rows = file($csv); |
| 155 |
foreach ($rows as $row) { |
| 156 |
if (empty($row)) { |
| 157 |
continue; |
| 158 |
} |
| 159 |
|
| 160 |
$v = explode(';', $row); |
| 161 |
if (count($v) != 3) { |
| 162 |
continue; |
| 163 |
} |
| 164 |
|
| 165 |
if (!isset($country_codes[$v[0]])) { |
| 166 |
$country_codes[$v[0]] = []; |
| 167 |
} |
| 168 |
|
| 169 |
// push values |
| 170 |
$country_codes[$v[0]]['name'] = $v[1]; |
| 171 |
$country_codes[$v[0]]['three_code'] = $v[2]; |
| 172 |
} |
| 173 |
|
| 174 |
// try to cache the country codes for other fields that may need them later |
| 175 |
if ($collect_registry) { |
| 176 |
// cache array for other fields |
| 177 |
$collect_registry->set('nazioni', $country_codes); |
| 178 |
} |
| 179 |
|
| 180 |
return $country_codes; |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* Parses the file Comuni.csv and returns two associative |
| 185 |
* arrays: one for the Comuni and one for the Province. |
| 186 |
* Every line of the CSV is composed of: Codice, Comune, Provincia. |
| 187 |
* |
| 188 |
* Public and internal method, not part of the interface. |
| 189 |
* Useful for all the implementor fields that need it. |
| 190 |
* |
| 191 |
* @return array |
| 192 |
*/ |
| 193 |
public function loadComuniProvince() |
| 194 |
{ |
| 195 |
// always try access the registry instance data |
| 196 |
$collect_registry = VBOCheckinPax::getInstanceData(); |
| 197 |
|
| 198 |
// check if the registry instance of this collection type has cached values |
| 199 |
if ($collect_registry) { |
| 200 |
$prev_comprov_codes = $collect_registry->get('comuni_province'); |
| 201 |
if (is_array($prev_comprov_codes) && count($prev_comprov_codes)) { |
| 202 |
// another field of this collection must have loaded already the "Comuni" |
| 203 |
return $prev_comprov_codes; |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
// container |
| 208 |
$comprov_codes = [ |
| 209 |
'comuni' => [], |
| 210 |
'province' => [], |
| 211 |
]; |
| 212 |
|
| 213 |
$csv = VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'report' . DIRECTORY_SEPARATOR . 'Comuni.csv'; |
| 214 |
$rows = file($csv); |
| 215 |
foreach ($rows as $row) { |
| 216 |
if (empty($row)) { |
| 217 |
continue; |
| 218 |
} |
| 219 |
|
| 220 |
$v = explode(';', $row); |
| 221 |
if (count($v) != 3) { |
| 222 |
continue; |
| 223 |
} |
| 224 |
|
| 225 |
// trim values |
| 226 |
$v[0] = trim($v[0]); |
| 227 |
$v[1] = trim($v[1]); |
| 228 |
$v[2] = trim($v[2]); |
| 229 |
|
| 230 |
if (!isset($comprov_codes['comuni'][$v[0]])) { |
| 231 |
$comprov_codes['comuni'][$v[0]] = []; |
| 232 |
} |
| 233 |
|
| 234 |
// push values |
| 235 |
$comprov_codes['comuni'][$v[0]]['name'] = $v[1]; |
| 236 |
$comprov_codes['comuni'][$v[0]]['province'] = $v[2]; |
| 237 |
$comprov_codes['province'][$v[2]] = $v[2]; |
| 238 |
} |
| 239 |
|
| 240 |
// try to cache the comuni-province codes for other fields that may need them later |
| 241 |
if ($collect_registry) { |
| 242 |
// cache array for other fields |
| 243 |
$collect_registry->set('comuni_province', $comprov_codes); |
| 244 |
} |
| 245 |
|
| 246 |
return $comprov_codes; |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* Parses the file Documenti.csv and returns an associative |
| 251 |
* array with the code and name of the Documento. |
| 252 |
* Every line of the CSV is composed of: Codice, Documento. |
| 253 |
* |
| 254 |
* @return array |
| 255 |
*/ |
| 256 |
public function loadDocumenti() |
| 257 |
{ |
| 258 |
// always try access the registry instance data |
| 259 |
$collect_registry = VBOCheckinPax::getInstanceData(); |
| 260 |
|
| 261 |
// check if the registry instance of this collection type has cached values |
| 262 |
if ($collect_registry) { |
| 263 |
$prev_documenti = $collect_registry->get('documenti'); |
| 264 |
if (is_array($prev_documenti) && count($prev_documenti)) { |
| 265 |
// another field of this collection must have loaded already the "Comuni" |
| 266 |
return $prev_documenti; |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
// container |
| 271 |
$documenti = []; |
| 272 |
|
| 273 |
$csv = VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'report' . DIRECTORY_SEPARATOR . 'Documenti.csv'; |
| 274 |
$rows = file($csv); |
| 275 |
foreach ($rows as $row) { |
| 276 |
if (empty($row)) { |
| 277 |
continue; |
| 278 |
} |
| 279 |
|
| 280 |
$v = explode(';', $row); |
| 281 |
if (count($v) != 2) { |
| 282 |
continue; |
| 283 |
} |
| 284 |
|
| 285 |
// trim values |
| 286 |
$v[0] = trim($v[0]); |
| 287 |
$v[1] = trim($v[1]); |
| 288 |
|
| 289 |
// push values |
| 290 |
$documenti[$v[0]] = $v[1]; |
| 291 |
} |
| 292 |
|
| 293 |
// try to cache the documenti codes for other fields that may need them later |
| 294 |
if ($collect_registry) { |
| 295 |
// cache array for other fields |
| 296 |
$collect_registry->set('documenti', $documenti); |
| 297 |
} |
| 298 |
|
| 299 |
return $documenti; |
| 300 |
} |
| 301 |
} |
| 302 |
|