| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FirePlugins Framework |
| 4 |
* @version 1.0.27 |
| 5 |
* |
| 6 |
* @author FirePlugins <[email protected]> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2022 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FPFramework\Helpers; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class ContinentsHelper extends SearchDropdownProviderHelper |
| 20 |
{ |
| 21 |
public function __construct($provider = null) |
| 22 |
{ |
| 23 |
$this->class_name = 'Continents'; |
| 24 |
|
| 25 |
parent::__construct($provider); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Parses given data to a key,value array |
| 30 |
* |
| 31 |
* @param array $items |
| 32 |
* |
| 33 |
* @return array |
| 34 |
*/ |
| 35 |
public static function parseData($items) |
| 36 |
{ |
| 37 |
$items = (array) $items; |
| 38 |
$items = array_filter($items); |
| 39 |
|
| 40 |
if (empty($items)) |
| 41 |
{ |
| 42 |
return []; |
| 43 |
} |
| 44 |
|
| 45 |
$data = []; |
| 46 |
|
| 47 |
foreach ($items as $key => $value) |
| 48 |
{ |
| 49 |
$data[] = [ |
| 50 |
'id' => $key, |
| 51 |
'label' => $value |
| 52 |
]; |
| 53 |
} |
| 54 |
|
| 55 |
return $data; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Return a continent's code from it's name |
| 60 |
* |
| 61 |
* @param string $cont |
| 62 |
* |
| 63 |
* @return mixed |
| 64 |
*/ |
| 65 |
public static function getCode($cont) |
| 66 |
{ |
| 67 |
if (!is_string($cont) || empty(trim($cont))) |
| 68 |
{ |
| 69 |
return null; |
| 70 |
} |
| 71 |
|
| 72 |
$cont = \ucwords(strtolower(trim($cont))); |
| 73 |
|
| 74 |
foreach (self::getContinents() as $key => $value) |
| 75 |
{ |
| 76 |
if (strpos($value, $cont) !== false) |
| 77 |
{ |
| 78 |
return $key; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
return null; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Returns all continents |
| 87 |
* |
| 88 |
* @return array |
| 89 |
*/ |
| 90 |
public static function getContinents() |
| 91 |
{ |
| 92 |
return [ |
| 93 |
'af' => fpframework()->_('FPF_CONTINENT_AF'), |
| 94 |
'as' => fpframework()->_('FPF_CONTINENT_AS'), |
| 95 |
'eu' => fpframework()->_('FPF_CONTINENT_EU'), |
| 96 |
'na' => fpframework()->_('FPF_CONTINENT_NA'), |
| 97 |
'sa' => fpframework()->_('FPF_CONTINENT_SA'), |
| 98 |
'oc' => fpframework()->_('FPF_CONTINENT_OC'), |
| 99 |
'an' => fpframework()->_('FPF_CONTINENT_AN'), |
| 100 |
]; |
| 101 |
} |
| 102 |
} |