Exemplo n.º 1
0
 public function actionIndex()
 {
     $searchModel = new Rate();
     $dataProvider = new ActiveDataProvider(['query' => Rate::find()]);
     if (Yii::$app->request->post('hasEditable')) {
         $itemID = Yii::$app->request->post('editableKey');
         $model = Rate::findOne($itemID);
         $out = Json::encode(['output' => '', 'message' => '']);
         $post = [];
         $posted = current($_POST['Rate']);
         $post['Rate'] = $posted;
         if ($model->load($post)) {
             $model->save();
             $output = '';
             if (isset($posted['Rate'])) {
                 $output = Yii::$app->formatter->asDecimal($model->speed, 1);
             }
             $out = Json::encode(['output' => $output, 'message' => '']);
         }
         echo $out;
         return;
     }
     // non-ajax - render the grid by default
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
Exemplo n.º 2
0
 public function actionGetRate()
 {
     $from_currency_id = Yii::$app->request->post('from_currency_id');
     $to_currency_id = Yii::$app->request->post('to_currency_id');
     if ($from_currency_id !== null and $to_currency_id !== null) {
         $rate = Rate::find()->where("from_currency_id = :from_currency_id", [':from_currency_id' => $from_currency_id])->andWhere("to_currency_id = :to_currency_id", [':to_currency_id' => $to_currency_id])->asArray()->one();
         if ((bool) $rate) {
             $result = 'success';
         } else {
             $result = 'Для выбранной пары валют нет возможности конвертации';
         }
     } else {
         $result = ['result' => 'Методу не передан обязательный набор параметров'];
         $rate = '';
     }
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['rate' => $rate, 'result' => $result, 'from_currency_id' => $from_currency_id, 'to_currency_id' => $to_currency_id];
 }
Exemplo n.º 3
0
 /**
  * Lists all Rate models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Rate::find()->with('fromCurrency', 'toCurrency')]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }