本文整理匯總了PHP中app\models\Currency::updateCurrency方法的典型用法代碼示例。如果您正苦於以下問題:PHP Currency::updateCurrency方法的具體用法?PHP Currency::updateCurrency怎麽用?PHP Currency::updateCurrency使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Currency
的用法示例。
在下文中一共展示了Currency::updateCurrency方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: updatingcbr
public function updatingcbr(Currency $currencyModel, History $historyModel)
{
$currency_bank = array();
//$today = date("d/m/Y");
$ch = curl_init();
/*curl_setopt($ch, CURLOPT_URL,
'http://www.cbr.ru/scripts/XML_daily.asp?date_req='.$today);*/
curl_setopt($ch, CURLOPT_URL, 'http://www.cbr.ru/scripts/XML_daily.asp');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);
if ($xml) {
$sxml = simplexml_load_string($xml);
foreach ($sxml->Valute as $item) {
$charCode = (string) $item->CharCode;
$rate = (string) $item->Value;
$nominal = (string) $item->Nominal;
if ($nominal > 1) {
$rate = $rate / $nominal;
}
$rate = (double) str_replace(',', '.', $rate);
$currency_bank[$charCode] = array('rate' => $rate);
}
unset($sxml);
}
if (count($currency_bank) < 1) {
Session::flash('message', GetMessages("ERROR"));
return redirect()->route('currency.index');
}
$currenciesList = $currencyModel->getListCurrencies();
if (isset($_REQUEST['user_id'])) {
$user_id = $_REQUEST['user_id'];
} else {
$user_id = 1;
}
foreach ($currenciesList as $currency) {
if (array_key_exists($currency->currency, $currency_bank)) {
$arFields = array('currency_id' => $currency->id, 'rate' => $currency_bank[$currency->currency]['rate'], 'old_rate' => $currencyModel->getRateById($currency->id), 'user_id' => $user_id);
$currencyModel->updateCurrency($arFields);
}
}
$historyModel->saveHistory('auto_update_currency', $user_id);
if (isset($_REQUEST['user_id'])) {
Session::flash('message', GetMessages("SUCCESS_AUTO_UPDATING_CURR"));
return redirect()->route('currency.index');
} else {
return "success updating";
}
}