本文整理汇总了PHP中app\models\Currency::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Currency::findOne方法的具体用法?PHP Currency::findOne怎么用?PHP Currency::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Currency
的用法示例。
在下文中一共展示了Currency::findOne方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addOperation
public function addOperation()
{
if ($this->currency_id != '1') {
$course = new Course();
if (!$course->checkCourse($this->currency_id)) {
$course->currency_id = $this->currency_id;
$currency = Currency::findOne($this->currency_id);
$course->course = $course->getCourse($currency->iso);
if (!$course->save()) {
throw new ErrorException('Курс не обновлен' . var_dump($course));
}
}
}
$operation = new Operation();
$operation->user_id = Yii::$app->getUser()->id;
$operation->category_id = $this->category_id === '' ? 1 : $this->category_id;
$operation->currency_id = $this->currency_id === '' ? 1 : $this->currency_id;
$operation->summ = $this->operation_type == 'income' ? $this->summ * 100 : $this->summ * -100;
$operation->description = $this->description;
return $operation->save() ? $operation : null;
}
示例2: function
$country = $result->country['Name'];
}
return $country;
}], ['attribute' => 'ContactID', 'label' => 'Туристы', 'content' => function ($data) {
$mainContact = $data->contact;
$list = "<ul>";
$list .= "<li>" . $mainContact['Name'] . " " . $mainContact['SurName'] . "</li>";
foreach ($data->participants as $value) {
$contact = Contact::findOne($value['ContactID']);
$list .= "<li>" . $contact->Name . " " . $contact->SurName . "</li>";
}
$list .= "</ul>";
return $list;
}], ['attribute' => 'CurrencyID', 'label' => 'Валюта', 'content' => function ($data) {
$currency = '';
$result = Currency::findOne($data->orderCalc['CurrencyID']);
if (is_object($result)) {
$currency = $result->Currency;
}
return $currency;
}], ['attribute' => 'Price', 'label' => 'Стоимость', 'content' => function ($data) {
return $data->orderCalc['Price'];
}], ['attribute' => 'Charges', 'label' => 'Комиссия', 'content' => function ($data) {
return $data->Charges;
}], ['attribute' => 'Sum', 'label' => 'Долг', 'content' => function ($data) {
return $data->Sum - $data->Charges;
}, 'contentOptions' => function ($model, $key, $index, $column) {
$status = '';
$debt = $model->Sum - $model->Charges;
if ($debt > 0) {
$status = 'text-danger';
示例3: findModel
/**
* Finds the Currency model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Currency the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Currency::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例4: refreshRates
/**
* @throws InvalidConfigException
*/
public static function refreshRates()
{
/** @var Currency $defaultCurrency */
$defaultCurrency = Currency::findOne(['is_default' => 1]);
if (!$defaultCurrency) {
throw new InvalidConfigException('Default currency is not set.');
}
/** @var Currency[] $currencies */
$currencies = Currency::find()->all();
foreach ($currencies as $currency) {
if ($currency->code == $defaultCurrency->code) {
$currency->rate = 1;
} else {
$url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=' . $defaultCurrency->code . $currency->code . '=X';
$handle = @fopen($url, 'r');
if ($handle === false) {
throw new Exception('Can not connect to exchange rates provider service.');
}
$result = fgets($handle, 4096);
fclose($handle);
$currencyData = explode(',', $result);
$currency->rate = $currencyData[1];
}
$currency->save();
}
}
示例5: setCourse
public function setCourse($currency_id)
{
$this->currency_id = $currency_id;
$currency = Currency::findOne($currency_id);
$this->course = $this->getCourse($currency->iso);
return $this->save() ? $this : null;
}