function currency_views_preload in Currency 6
Same name and namespace in other branches
- 7 includes/views/currency.views.inc \currency_views_preload()
Calls currency_api_convert for every exchange rate that should be displayed according to filter and argument settings to ensure that rates are in the database when views performs it's query.
2 calls to currency_views_preload()
- currency_handler_argument_currency::query in views/
handlers/ currency_handler_argument_currency.inc - currency_handler_filter_currency::query in views/
handlers/ currency_handler_filter_currency.inc
File
- views/
currency.views.inc, line 93 - Register all of the basic handlers that views uses.
Code
function currency_views_preload($view) {
static $processed = FALSE;
if (!$processed) {
// $this->value for keyed array of selected currencies
if ($view->filter['currency_from']) {
$selected_from = _currency_views_get_selected_options($view->filter['currency_from']->value);
}
elseif ($view->argument['currency_from'] && ($currency_from = $view->argument['currency_from']
->get_value())) {
// process argument
$selected_from = array(
$currency_from,
);
}
if ($view->filter['currency_to']) {
$selected_to = _currency_views_get_selected_options($view->filter['currency_to']->value);
}
elseif ($view->argument['currency_to'] && ($currency_to = $view->argument['currency_to']
->get_value())) {
$selected_to = array(
$currency_to,
);
}
if ($selected_from && $selected_to) {
// selected currencies - make sure exchange rates are in database by calling currency_api for each from/to currency combination
foreach ($selected_from as $currency_from) {
foreach ($selected_to as $currency_to) {
currency_api_convert($currency_from, $currency_to);
}
}
}
$processed = TRUE;
}
}