public function getCurrencyRate(Currency $from, Currency $to)
 {
     $currency_rate = $this->findOneByFromCodeAndToCode($from, $to);
     if (!$currency_rate instanceof CurrencyRate) {
         $currency_rate = new CurrencyRate();
         $currency_rate->setFromCode($from->getCode());
         $currency_rate->setToCode($to->getCode());
     }
     return $currency_rate;
 }
Example #2
0
 protected function saveRates($currencies, $rates)
 {
     $currency_model = new Currency();
     foreach ($rates as $rate) {
         $code_from = substr($rate['id'], 0, 3);
         $currency_from = $currencies[$code_from];
         $currency_to = $currency_model->getCurrencyByCode($this->currency_to);
         // getting GMT datetime.
         $date = date('Y-m-d H:i:s', strtotime($rate['Date'] . ' ' . $rate['Time'] . ' -1 hour'));
         $currency_rate_model = new CurrencyRate();
         $data = array('curr_from_id' => $currency_from->id, 'curr_to_id' => $currency_to->id, 'rate' => floatval($rate['Rate']), 'date' => $date, 'source_url' => 'http://query.yahooapis.com/v1/public/yql', 'created' => date('Y-m-d H:i:s'));
         $currency_rate_model->insert($data);
     }
 }
	/**
	 * Delete rate in database 
	 * 
	 * @param double	$rate	rate value
	 * 
	 * @return bool false if KO, true if OK
	 */
	 public function addRate($rate)
	 {
	 	$currencyRate = new CurrencyRate($this->db);
		$currencyRate->rate = $rate;
		
		if ($currencyRate->create($this->id) > 0) 
		{
			$this->rate = $currencyRate;
			return 1;
		}
		else 
		{
			$this->rate = null;
			return -1;
		}
	 }