protected function addToCollection($currencyParams, $currencyCollection) { $currencyObj = new Currency(); $currencyObj->setSource($currencyParams['source']); $currencyObj->setType($currencyParams['type']); $currencyObj->setCode($currencyParams['code']); $currencyObj->setName($currencyParams['name']); $currencyObj->setPrice(floatval(str_replace(',', '.', $currencyParams['price']))); $currencyCollection->add($currencyObj); }
public function readUnits() { $con = self::openConnection(); $currencies = new Currencies(); mysqli_begin_transaction($con); $sql = "SELECT * FROM currency WHERE 1"; $res = mysqli_query($con, $sql); while ($arrRes = mysqli_fetch_assoc($res)) { $currency = new Currency(); $currency->setId($arrRes['id']); $currency->setCode($arrRes['code']); $currencies->setUnit($currency); } return $currencies; }
protected function getCurrencies() { $wikipedia = $this->web->get(sfConfig::get('app_source_currencies'), null, array('User-Agent' => 'Steve Lacey <*****@*****.**>', 'Cache-Control' => 'no-cache')); $xml = new SimpleXMLElement($wikipedia->getResponseText()); $article = $xml->page->revision->text; $table = substr($article, strpos($article, '{|'), strpos($article, '|}') - strpos($article, '{|')); foreach (explode('-| ', str_replace(array('[', ']', "\n"), '', $table)) as $row) { $row = explode(' || ', trim($row, '| ')); if (isset($row[2], $row[4]) && is_numeric($row[2])) { $currency = new Currency(); $currency->setCode(sfConfig::get('app_currency_alias_' . $row[0], $row[0])); $currency->setNumber($row[1]); $currency->setDigits(ceil($row[2])); $currency->setName($row[3]); $currency->save(); } } }
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; }