public function getRate($date = null)
 {
     if (!isset($this->rateHistory)) {
         $this->rateHistory = CurrencyDAO::GetInstance()->getCurrencyRateHistory($this->code);
     }
     if (is_null($date)) {
         return $this->rateHistory[0];
     } else {
         foreach ($this->rateHistory as $rateDate => $rate) {
             if ((new \DateTime($date))->diff(new \DateTime($rateDate))->invert) {
                 return $rate;
             }
         }
         throw new \Exception("No currency " . $this->code . " rate found for " . $date);
     }
 }
Example #2
0
 public function parseCurrencies()
 {
     $currencies = new Currencies();
     $keyParams = array();
     foreach ($this->xmlProducts as $product) {
         $cur = $product->getCurrency();
         if (!empty($cur) && !in_array($cur, $keyParams)) {
             array_push($keyParams, $cur);
             $currency = new Currency();
             $currency->setCode($cur);
             $currencies->setUnit($currency);
         }
     }
     $currencyDAO = new CurrencyDAO();
     $currencyDAO->insertUnits($currencies);
     $currencies = $currencyDAO->readUnits();
     return $currencies;
 }