vikappointments
/
modules
/
mod_vikappointments_currencyconverter
/
libraries
/
fields
/
currencies.php
vikappointments
/
modules
/
mod_vikappointments_currencyconverter
/
libraries
/
fields
Last commit date
currencies.php
1 month ago
currencies.php
88 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage mod_vikappointments_currencyconverter |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2024 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 to this file |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | jimport('joomla.form.formfield.list'); |
| 15 | |
| 16 | /** |
| 17 | * Form field override to display a list of supported currencies. |
| 18 | * |
| 19 | * @since 1.0 |
| 20 | */ |
| 21 | class JFormFieldCurrencies extends JFormFieldList |
| 22 | { |
| 23 | /** |
| 24 | * The type of the field. |
| 25 | * MUST be equal to the definition in the XML file. |
| 26 | * |
| 27 | * @var string |
| 28 | */ |
| 29 | protected $type = 'currencies'; |
| 30 | |
| 31 | /** |
| 32 | * Method to get the options to populate the list. |
| 33 | * |
| 34 | * @return array The field option objects. |
| 35 | */ |
| 36 | public function getOptions() |
| 37 | { |
| 38 | $options = []; |
| 39 | |
| 40 | if (defined('JPATH_SITE') && JPATH_SITE !== 'JPATH_SITE') |
| 41 | { |
| 42 | // autoload VAP |
| 43 | $success = require_once JPath::clean(JPATH_SITE . '/components/com_vikappointments/helpers/libraries/autoload.php'); |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | // WP platform, VAP should be already loaded |
| 48 | $success = defined('VIKAPPOINTMENTS_SOFTWARE_VERSION'); |
| 49 | } |
| 50 | |
| 51 | if (!$success) |
| 52 | { |
| 53 | throw new Exception('VikAppointments is not installed!', 404); |
| 54 | } |
| 55 | |
| 56 | // get all currencies |
| 57 | $currencies = VAPCurrencyHelperEnum::getCurrencies(); |
| 58 | |
| 59 | // get system currency |
| 60 | $currencyName = VAPFactory::getConfig()->get('currencyname'); |
| 61 | |
| 62 | if (!isset($currencies[$currencyName])) |
| 63 | { |
| 64 | // currency not supported, manually register it |
| 65 | $options[] = JHtml::fetch('select.option', $currencyName, $currencyName); |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | // always move the default currency on top |
| 70 | $options[] = JHtml::fetch('select.option', $currencyName, $currencies[$currencyName]['currency'] . ' (' . $currencyName . ')'); |
| 71 | } |
| 72 | |
| 73 | // iterate all the supported currencies |
| 74 | foreach ($currencies as $code => $data) |
| 75 | { |
| 76 | if ($code === $currencyName) |
| 77 | { |
| 78 | // skip default currency |
| 79 | continue; |
| 80 | } |
| 81 | |
| 82 | $options[] = JHtml::fetch('select.option', $code, $data['currency'] . ' (' . $code . ')'); |
| 83 | } |
| 84 | |
| 85 | return array_merge(parent::getOptions(), $options); |
| 86 | } |
| 87 | } |
| 88 |