to filter by amount, add the following code:
case 'filters':
$currencies = _money_parse_currencies($field['allowed_currencies']);
$options = array_combine($currencies, $currencies);
$filters = array(
'currency'=> array(
'name' => t('Filter by currency'),
// It seems Views requires your operator handler to contain at least
// an "OR" operator if you want the multiple select to mark the
// selected currencies as selected when a user revisits the form. It's
// stored correctly in the DB though. So, as a work-around, I opted to
// use "OR" and "NOR" and then use the desired operators in the actual
// filter handler.
'operator' => array('OR' => t('Is One Of'), 'NOR' => t('Is None Of')),
'value' => array(
'#type' => 'select',
'#multiple' => TRUE,
'#options' => $options,
),
'handler' => 'money_views_handler_filter_currency',
'help' => t('This filter allows you to filter by currency (or multiple currencies).'),
),
'amount' => array(
'name' => t('Filter by amount'),
'operator' => 'views_handler_operator_gtlt',
),
);
return $filters;
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | money-filter-amount.patch | 1.81 KB | john morahan |
Comments
Comment #1
M. P. commentedThanks for the start, here is the whole code - works for me so far.
NOTE: Not tested with multiple currencies and it has no support of filtering amount ranges
Modifing the Views filter:
And added the Views filter handler:
Comment #2
wim leersThat's what I was about to say... Anyway, I'll add this in. I'd appreciate it if you could roll a patch. See http://drupal.org/patch/create.
Comment #3
sleven commentedNice but stupid.
Is that much complicated to say where to put this code?
Witch file, where.
It's not problem I am new here. Problem is that everybody is smrat guy.
This is incomplete.
Comment #4
john morahan commentedJust rolled a patch from the above, haven't reviewed this or anything
Comment #5
Gidgidonihah commentedI've applied the patch and it appears to be working correctly. Haven't noticed any flaws yet.
Comment #6
wim leersImplemented.
Thanks for the start, but there were several issues:
- the separators were not being picked up properly (by calling those functions you ensure that the default ones are used, but if you used custom ones it wouldn't work)
- preg_quote() was used where it shouldn't
- code duplication, I've abstracted the amount conversion into a separate function.
Comment #7
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.