Overview

Packages

  • Eabi
    • Dpd
  • None
  • PHP

Classes

  • dpdcodpayment
  • eabi_dpd_courier
  • Eabi_dpd_courierCourierModuleFrontController
  • eabi_dpd_parcelstore
  • eabi_dpd_parcelstore_data_send_executor
  • eabi_dpd_parcelstore_dpd_api
  • eabi_dpd_parcelstore_dpd_helper
  • eabi_dpd_parcelstore_html_helper
  • eabi_dpd_parcelstore_validator_helper
  • Eabi_dpd_parcelstoreCourierModuleFrontController
  • Eabi_Postoffice
  • eabi_postoffice_dialcode_helper
  • Eabi_PostofficePostofficeModuleFrontController

Functions

  • upgrade_module_0_3
  • upgrade_module_0_6
  • upgrade_module_0_8
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /*
  4:   
  5:  *
  6:  * NOTICE OF LICENSE
  7:  *
  8:  * This source file is subject to the Open Software License (OSL 3.0)
  9:  * or OpenGPL v3 license (GNU Public License V3.0)
 10:  * that is bundled with this package in the file LICENSE.txt.
 11:  * It is also available through the world-wide-web at this URL:
 12:  * http://opensource.org/licenses/osl-3.0.php
 13:  * or
 14:  * http://www.gnu.org/licenses/gpl-3.0.txt
 15:  * If you did not receive a copy of the license and are unable to
 16:  * obtain it through the world-wide-web, please send an email
 17:  * to info@e-abi.ee so we can send you a copy immediately.
 18:  *
 19:  * DISCLAIMER
 20:  *
 21:  * Do not edit or add to this file if you wish to upgrade this module to newer
 22:  * versions in the future.
 23:  *
 24:  * @category   Eabi
 25:  * @package    Eabi_Dpd
 26:  * @copyright  Copyright (c) 2014 Aktsiamaailm LLC (http://en.e-abi.ee/)
 27:  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 28:  * @license    http://www.gnu.org/licenses/gpl-3.0.txt  GNU Public License V3.0
 29:  * @author     Matis Halmann
 30:  * 
 31: 
 32:  */
 33: if (!defined('_PS_VERSION_')) {
 34:     exit;
 35: }
 36: 
 37: /**
 38:  * Description of dialcode_helper
 39:  *
 40:  * @author Matis
 41:  */
 42: class eabi_postoffice_dialcode_helper {
 43:     
 44:     protected $_countryCodes = array(
 45:         'IL' => '972',
 46:         'AF' => '93',
 47:         'AL' => '355',
 48:         'DZ' => '213',
 49:         'AS' => '1684',
 50:         'AD' => '376',
 51:         'AO' => '244',
 52:         'AI' => '1264',
 53:         'AG' => '1268',
 54:         'AR' => '54',
 55:         'AM' => '374',
 56:         'AW' => '297',
 57:         'AU' => '61',
 58:         'AT' => '43',
 59:         'AZ' => '994',
 60:         'BS' => '1242',
 61:         'BH' => '973',
 62:         'BD' => '880',
 63:         'BB' => '1246',
 64:         'BY' => '375',
 65:         'BE' => '32',
 66:         'BZ' => '501',
 67:         'BJ' => '229',
 68:         'BM' => '1441',
 69:         'BT' => '975',
 70:         'BA' => '387',
 71:         'BW' => '267',
 72:         'BR' => '55',
 73:         'IO' => '246',
 74:         'BG' => '359',
 75:         'BF' => '226',
 76:         'BI' => '257',
 77:         'KH' => '855',
 78:         'CM' => '237',
 79:         'CA' => '1',
 80:         'CV' => '238',
 81:         'KY' => '345',
 82:         'CF' => '236',
 83:         'TD' => '235',
 84:         'CL' => '56',
 85:         'CN' => '86',
 86:         'CX' => '61',
 87:         'CO' => '57',
 88:         'KM' => '269',
 89:         'CG' => '242',
 90:         'CK' => '682',
 91:         'CR' => '506',
 92:         'HR' => '385',
 93:         'CU' => '53',
 94:         'CY' => '537',
 95:         'CZ' => '420',
 96:         'DK' => '45',
 97:         'DJ' => '253',
 98:         'DM' => '1767',
 99:         'DO' => '1849',
100:         'EC' => '593',
101:         'EG' => '20',
102:         'SV' => '503',
103:         'GQ' => '240',
104:         'ER' => '291',
105:         'EE' => '372',
106:         'ET' => '251',
107:         'FO' => '298',
108:         'FJ' => '679',
109:         'FI' => '358',
110:         'FR' => '33',
111:         'GF' => '594',
112:         'PF' => '689',
113:         'GA' => '241',
114:         'GM' => '220',
115:         'GE' => '995',
116:         'DE' => '49',
117:         'GH' => '233',
118:         'GI' => '350',
119:         'GR' => '30',
120:         'GL' => '299',
121:         'GD' => '1473',
122:         'GP' => '590',
123:         'GU' => '1671',
124:         'GT' => '502',
125:         'GN' => '224',
126:         'GW' => '245',
127:         'GY' => '595',
128:         'HT' => '509',
129:         'HN' => '504',
130:         'HU' => '36',
131:         'IS' => '354',
132:         'IN' => '91',
133:         'ID' => '62',
134:         'IQ' => '964',
135:         'IE' => '353',
136:         'IT' => '39',
137:         'JM' => '1876',
138:         'JP' => '81',
139:         'JO' => '962',
140:         'KZ' => '77',
141:         'KE' => '254',
142:         'KI' => '686',
143:         'KW' => '965',
144:         'KG' => '996',
145:         'LV' => '371',
146:         'LB' => '961',
147:         'LS' => '266',
148:         'LR' => '231',
149:         'LI' => '423',
150:         'LT' => '370',
151:         'LU' => '352',
152:         'MG' => '261',
153:         'MW' => '265',
154:         'MY' => '60',
155:         'MV' => '960',
156:         'ML' => '223',
157:         'MT' => '356',
158:         'MH' => '692',
159:         'MQ' => '596',
160:         'MR' => '222',
161:         'MU' => '230',
162:         'YT' => '262',
163:         'MX' => '52',
164:         'MC' => '377',
165:         'MN' => '976',
166:         'ME' => '382',
167:         'MS' => '1664',
168:         'MA' => '212',
169:         'MM' => '95',
170:         'NA' => '264',
171:         'NR' => '674',
172:         'NP' => '977',
173:         'NL' => '31',
174:         'AN' => '599',
175:         'NC' => '687',
176:         'NZ' => '64',
177:         'NI' => '505',
178:         'NE' => '227',
179:         'NG' => '234',
180:         'NU' => '683',
181:         'NF' => '672',
182:         'MP' => '1670',
183:         'NO' => '47',
184:         'OM' => '968',
185:         'PK' => '92',
186:         'PW' => '680',
187:         'PA' => '507',
188:         'PG' => '675',
189:         'PY' => '595',
190:         'PE' => '51',
191:         'PH' => '63',
192:         'PL' => '48',
193:         'PT' => '351',
194:         'PR' => '1939',
195:         'QA' => '974',
196:         'RO' => '40',
197:         'RW' => '250',
198:         'WS' => '685',
199:         'SM' => '378',
200:         'SA' => '966',
201:         'SN' => '221',
202:         'RS' => '381',
203:         'SC' => '248',
204:         'SL' => '232',
205:         'SG' => '65',
206:         'SK' => '421',
207:         'SI' => '386',
208:         'SB' => '677',
209:         'ZA' => '27',
210:         'GS' => '500',
211:         'ES' => '34',
212:         'LK' => '94',
213:         'SD' => '249',
214:         'SR' => '597',
215:         'SZ' => '268',
216:         'SE' => '46',
217:         'CH' => '41',
218:         'TJ' => '992',
219:         'TH' => '66',
220:         'TG' => '228',
221:         'TK' => '690',
222:         'TO' => '676',
223:         'TT' => '1868',
224:         'TN' => '216',
225:         'TR' => '90',
226:         'TM' => '993',
227:         'TC' => '1649',
228:         'TV' => '688',
229:         'UG' => '256',
230:         'UA' => '380',
231:         'AE' => '971',
232:         'GB' => '44',
233:         'US' => '1',
234:         'UY' => '598',
235:         'UZ' => '998',
236:         'VU' => '678',
237:         'WF' => '681',
238:         'YE' => '967',
239:         'ZM' => '260',
240:         'ZW' => '263',
241:         'BO' => '591',
242:         'BN' => '673',
243:         'CC' => '61',
244:         'CD' => '243',
245:         'CI' => '225',
246:         'FK' => '500',
247:         'GG' => '44',
248:         'VA' => '379',
249:         'HK' => '852',
250:         'IR' => '98',
251:         'IM' => '44',
252:         'JE' => '44',
253:         'KP' => '850',
254:         'KR' => '82',
255:         'LA' => '856',
256:         'LY' => '218',
257:         'MO' => '853',
258:         'MK' => '389',
259:         'FM' => '691',
260:         'MD' => '373',
261:         'MZ' => '258',
262:         'PS' => '970',
263:         'PN' => '872',
264:         'RE' => '262',
265:         'RU' => '7',
266:         'BL' => '590',
267:         'SH' => '290',
268:         'KN' => '1869',
269:         'LC' => '1758',
270:         'MF' => '590',
271:         'PM' => '508',
272:         'VC' => '1784',
273:         'ST' => '239',
274:         'SO' => '252',
275:         'SJ' => '47',
276:         'SY' => '963',
277:         'TW' => '886',
278:         'TZ' => '255',
279:         'TL' => '670',
280:         'VE' => '58',
281:         'VN' => '84',
282:         'VG' => '1284',
283:         'VI' => '1340',
284:     );
285: 
286:     /**
287:      * Gets array of all phone country codes, where array key is country ISO-3166 code and value is numeric dial code without '+'
288:      * @return array
289:      */
290:     public function getCountryCodes() {
291:         return $this->_countryCodes;
292:     }
293: 
294: 
295:     /**
296:      * Gets numeric dialcode without '+' sign for specified country code
297:      * @param string $countryId ISO-3166 country code
298:      * @return string
299:      */
300:     public function getCountryCode($countryId) {
301:         if (isset($this->_countryCodes[$countryId])) {
302:             return $this->_countryCodes[$countryId];
303:         }
304:         return null;
305:     }
306:     
307:     
308:     
309:     /**
310:      * <p>Attempts to separate country code from phone number by supplied default country.</p>
311:      * <p>If Phone number is missing country code, then it is applied by supplied country ISO-3166 code</p>
312:      * <p>Returns array with following format</p>
313:      * <pre>
314:      *  array(
315:      *      'dial_code' => country dial code with + prefix
316:      *      'phone_number' => phone number without country code
317:      *  );
318:      * </pre>
319:      * 
320:      * @param string $phonenumber phone number that may contain country code
321:      * @param string $countryId ISO-3166 country code
322:      * @return array
323:      */
324:     public function separatePhoneNumberFromCountryCode($phonenumber, $countryId) {
325:         $result = array(
326:             'dial_code' => '',
327:             'phone_number' => '',
328:         );
329:         $defaultDialCode = $this->getCountryCode($countryId);
330:         
331:         //remove all whitespace
332:         $phonenumber = str_replace(' ', '', $phonenumber);
333:         
334:         //when country code is supplied, then it can:
335:         //start with country code
336:         //start with + sign
337:         //start with 00 (double zero)
338:         //be longer than 10 digits
339:         $containsCountryCode = strpos($phonenumber, $defaultDialCode) === 0
340:                 || strpos($phonenumber, '+') === 0
341:                 || strpos($phonenumber, '00') === 0
342:                 || strlen($phonenumber) > 10;
343:         
344:         //when country code is not supplied, then it can
345:         //start with single zero
346:         //start with any number
347:         if (!$containsCountryCode) {
348:             $result['dial_code'] = '+'.$defaultDialCode;
349:             if (strpos($phonenumber, '0') === 0) {
350:                 $result['phone_number'] = substr($phonenumber, 1);
351:             } else {
352:                 $result['phone_number'] = $phonenumber;
353:             }
354:         } else {
355:             //phone number contains country code
356:             //we need to know what country code phone number contains
357:             //remove 00 or + sign
358:             $phonenumber = ltrim($phonenumber, '+0');
359:             $dialCode = $this->_getCountryCodeFromPhonenumber($phonenumber, $defaultDialCode);
360:             $result['dial_code'] = '+'.$dialCode;
361:             $result['phone_number'] = substr($phonenumber, strlen($dialCode));
362:         }
363:         
364:         
365:         return $result;
366:     }
367:     
368: 
369:     /**
370:      * <p>Attempts to find country code from phone number, when it is known that phone number most certainly contains country code.</p>
371:      * <p>Method assumes that longest found dial code is matcing dial code for this phone number.</p>
372:      * <p>If now match is found then default code is used.</p>
373:      * @param string $phonenumber phone number that is known to contain country code
374:      * @param string $defaultCode dial code to be used if no country code is found
375:      * @return string resulting dial code without + sign
376:      */
377:     protected function _getCountryCodeFromPhonenumber($phonenumber, $defaultCode) {
378:         $matchingCountryCode = '';
379:         foreach ($this->getCountryCodes() as $countryIso => $dialCode) {
380:             if (strpos($phonenumber, $dialCode) === 0) {
381:                 if (strlen($dialCode) > $matchingCountryCode) {
382:                     $matchingCountryCode = $dialCode;
383:                 }
384:             }
385:         }
386:         //as last resort apply default dial code
387:         if ($matchingCountryCode === '') {
388:             return $defaultCode;
389:         }
390:         return $matchingCountryCode;
391:     }
392:     
393:     
394: }
395: 
API documentation generated by ApiGen 2.8.0