Closed (fixed)
Project:
Currency
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
12 Apr 2008 at 22:01 UTC
Updated:
5 Dec 2010 at 23:12 UTC
Right now I'm fetching the symbols from the api and then using a function to find the correct one in the hash. This seems like a ghetto way of doing it. Do you have a better way or is it something that needs to be coded?
Comments
Comment #1
kbahey commentedRight now, it is two function calls.
Seems that we need to combine the currency_api_get_symbols() and currency_api_get_list() in one function that returns one array with the symbols and names, then have a lookup function like currency_api_get_info() using the currency code, and returning both the description and symbol.
At a later stage, we can have that in a database table.
Can you work on a patch for that?
Comment #2
drupalninja99 commentedOK, here's my first attempt of patching anything in my life so here we go. All I did was get a hash of the currency names and a hash of the currency symbols and then do a lookup in both and return the values in yet another hash. Also you might think about moving the symbols to a text file bc eclipse complains when you try to edit this file, I had to edit it in notepad. -Jay
### Eclipse Workspace Patch 1.0
#P currency
Index: currency_api/currency_api.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/currency/currency_api/currency_api.module,v
retrieving revision 1.6
diff -u -r1.6 currency_api.module
--- currency_api/currency_api.module 29 Oct 2007 22:32:49 -0000 1.6
+++ currency_api/currency_api.module 15 Apr 2008 23:36:50 -0000
@@ -1,4 +1,4 @@
-<?php
+<?php
//$Id: currency_api.module,v 1.6 2007/10/29 22:32:49 wimleers Exp $
@@ -538,6 +538,14 @@
return $currency;
}
+function currency_api_get_info($acronym) {
+ $currency_list = currency_api_get_list();
+ $currency_symbols = currency_api_get_symbols();
+
+ if ($currency_list[$acronym])
+ return array('name' => $currency_list[$acronym], 'symbol' => $currency_symbols[$acronym]);
+}
+
function currency_api_get_fields($array) {
while (list($field, $header) = each($array)) {
$field_string = $field_string . $field;
Comment #3
kbahey commentedJay
This is not the optimal way to handle this.
Why don't we combine both functions in one, i.e. symbols and description?
Now, both are indexed by the currency code, and we can get either from one function.
We could take that a step further to a currency table with 3 columns (code, symbol, description), and it gets populated in the _install() hook. We then have the function above do a lookup on the table by the code using SQL.
Regarding Eclipse, check its settings for how to handle Unicode UTF-8 correctly.
Comment #4
johnhanley commentedHere's a little wrapper function I created to return a currency symbol. It also caches the symbols array returned by currency_api_get_symbols(). Note: change function name prefix to suit.
Comment #5
johnhanley commentedBTW, I would not recommend putting the codes, descriptions and symbols in the database. Since these do not change very often it just creates unnecessary overhead.
Comment #6
amateescu commentedThis is fixed in the 6.x branch and 5.x is not maintained anymore.