widgetName = JText::translate('VBO_W_CURRCONV_TITLE'); $this->widgetDescr = JText::translate('VBO_W_CURRCONV_DESCR'); $this->widgetId = basename(__FILE__, '.php'); // define widget and icon and style name $this->widgetIcon = ''; $this->widgetStyleName = 'violet'; // load widget's settings $this->widgetSettings = $this->loadSettings(); if (!is_object($this->widgetSettings)) { $this->widgetSettings = new stdClass; } } /** * Custom method for this widget only to exchange the rates between currencies. * The method is called by the admin controller through an AJAX request. * The visibility should be public, it should not exit the process, and * any content sent to output will be returned to the AJAX response. * In this case we return an array because this method requires "return":1. * * It's the actual rendering of the widget. */ public function exchangeRates() { $wrapper = VikRequest::getString('wrapper', '', 'request'); $from_currency = VikRequest::getString('from_currency', '', 'request'); $to_currency = VikRequest::getString('to_currency', '', 'request'); $amount = VikRequest::getFloat('amount', 1, 'request'); if (empty($from_currency) || empty($to_currency)) { // use the website default currency $from_currency = VikBooking::getCurrencyName(); // use the default to currency $to_currency = !strcasecmp($from_currency, 'EUR') ? 'USD' : 'EUR'; } if ($amount <= 0) { $amount = 1; } // import currency converter class VikBooking::import('currencyconverter'); // get numbering format data $format = VikBooking::getNumberFormatData(); // get the instance of the converter object $converter = new VboCurrencyConverter($from_currency, $to_currency, [$amount], explode(':', $format)); // collect values $converter_error = null; $exchanged = null; $exchange_rate = null; // make sure from currency is supported for conversion if (!$converter->currencyExists($from_currency)) { $converter_error = sprintf('Currency %s is not supported', $from_currency); } elseif (!$converter->currencyExists($to_currency)) { $converter_error = sprintf('Currency %s is not supported', $to_currency); } if (!$converter_error) { // exchange the given rates $exchanged = $converter->convert($get_floats = true); } if (!$converter_error && (!is_array($exchanged) || !count($exchanged))) { // something went wrong during the conversion $converter_error = $converter->getError(); $converter_error = empty($converter_error) ? 'Error while converting rates' : $converter_error; } else { // get the conversion rate $exchange_rate = $converter->getConversionRate(); // update widget's settings with the lastly used currencies $this->widgetSettings->from_currency = $from_currency; $this->widgetSettings->to_currency = $to_currency; $this->updateSettings(json_encode($this->widgetSettings)); } // start output buffering ob_start(); ?>

$html_content, 'exchanged' => $exchanged, 'exchange_rate' => $exchange_rate, ]; } /** * Preload the necessary CSS/JS assets. * * @return void */ public function preload() { // load assets $this->vbo_app->loadSelect2(); } public function render(VBOMultitaskData $data = null) { // increase widget's instance counter static::$instance_counter++; // check whether the widget is being rendered via AJAX when adding it through the customizer $is_ajax = $this->isAjaxRendering(); // generate a unique ID for the sticky notes wrapper instance $wrapper_instance = !$is_ajax ? static::$instance_counter : rand(); $wrapper_id = 'vbo-widget-currconv-' . $wrapper_instance; // import currency converter class if (!VikBooking::import('currencyconverter')) { // display nothing return; } // the website default currency $def_currency = !empty($this->widgetSettings->from_currency) ? $this->widgetSettings->from_currency : VikBooking::getCurrencyName(); // the default to currency $def_to_currency = !strcasecmp($def_currency, 'EUR') ? 'USD' : 'EUR'; if (!empty($this->widgetSettings->to_currency)) { $def_to_currency = $this->widgetSettings->to_currency; } // get numbering format data $format = VikBooking::getNumberFormatData(); // get the instance of the converter object $converter = new VboCurrencyConverter($def_currency, $def_to_currency, [1], explode(':', $format)); // grab all currency names $all_currencies = $converter->getCurrencyNames(); ?>

widgetIcon; ?> widgetName; ?>