Subversion Repositories currency_converter

Rev

Rev 8 | Rev 21 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8 Rev 16
Line 125... Line 125...
125
        public function get_supported_currencies() {
125
        public function get_supported_currencies() {
126
                return array_keys($this->get_exchange_rates_ary());
126
                return array_keys($this->get_exchange_rates_ary());
127
        }
127
        }
128
 
128
 
129
        public function convert_cur($value, $from_cur, $to_cur) {
129
        public function convert_cur($value, $from_cur, $to_cur) {
130
                $exchange_rates_ary = $this->get_exchange_rates_ary();
-
 
131
 
-
 
132
                $from_cur = strtoupper(trim($from_cur));
130
                $from_cur = strtoupper(trim($from_cur));
133
                $to_cur = strtoupper(trim($to_cur));
131
                $to_cur = strtoupper(trim($to_cur));
134
 
132
               
-
 
133
                if ($from_cur == $to_cur) return $value;
-
 
134
 
-
 
135
                $exchange_rates_ary = $this->get_exchange_rates_ary();
-
 
136
 
135
                if (!isset($exchange_rates_ary[$from_cur])) throw new CurCalcException('Source curreny $from_cur not found in exchange data.');
137
                if (!isset($exchange_rates_ary[$from_cur])) throw new CurCalcException('Source curreny $from_cur not found in exchange data.');
136
                if (!isset($exchange_rates_ary[$to_cur])) throw new CurCalcException('Destination curreny $to_cur not found in exchange data.');
138
                if (!isset($exchange_rates_ary[$to_cur])) throw new CurCalcException('Destination curreny $to_cur not found in exchange data.');
137
 
139
 
138
                return $value * $exchange_rates_ary[$to_cur]/$exchange_rates_ary[$from_cur];
140
                return $value * $exchange_rates_ary[$to_cur]/$exchange_rates_ary[$from_cur];
139
        }
141
        }