Commit b96b6861b245b53f231a03d11e9b6cab63b39e3f

Authored by Mihail
1 parent f6c3dc95

fixed bugs for currency pages

backend/controllers/CurrencyController.php
... ... @@ -5,6 +5,7 @@ namespace backend\controllers;
5 5 use Yii;
6 6 use common\models\Currency;
7 7 use common\models\CurrencySearch;
  8 +use yii\data\ActiveDataProvider;
8 9 use yii\web\Controller;
9 10 use yii\web\NotFoundHttpException;
10 11 use yii\filters\VerbFilter;
... ... @@ -50,11 +51,13 @@ class CurrencyController extends Controller
50 51 */
51 52 public function actionIndex()
52 53 {
53   - $searchModel = new CurrencySearch();
54   - $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  54 + $dataProvider = new ActiveDataProvider([
  55 + 'query' => Currency::find(),
  56 + 'sort' => false,
  57 +
  58 + ]);
55 59  
56 60 return $this->render('index', [
57   - 'searchModel' => $searchModel,
58 61 'dataProvider' => $dataProvider,
59 62 ]);
60 63 }
... ...
backend/models/Currency.php deleted
1   -<?php
2   -
3   -namespace backend\models;
4   -
5   -use Yii;
6   -
7   -/**
8   - * This is the model class for table "w_currency".
9   - *
10   - * @property integer $id
11   - * @property string $name
12   - * @property double $rate
13   - * @property integer $is_default
14   - * @property string $timestamp
15   - */
16   -class Currency extends \yii\db\ActiveRecord
17   -{
18   - /**
19   - * @inheritdoc
20   - */
21   - public static function tableName()
22   - {
23   - return 'w_currency';
24   - }
25   -
26   - /**
27   - * @inheritdoc
28   - */
29   - public function rules()
30   - {
31   - return [
32   - [['name', 'rate'], 'required'],
33   - [['rate'], 'number'],
34   - [['is_default'], 'integer'],
35   - [['timestamp'], 'safe'],
36   - [['name'], 'string', 'max' => 50],
37   - [['name'], 'unique'],
38   - [['is_default'], 'unique']
39   - ];
40   - }
41   -
42   - /**
43   - * @inheritdoc
44   - */
45   - public function attributeLabels()
46   - {
47   - return [
48   - 'id' => 'ID',
49   - 'name' => 'Name',
50   - 'rate' => 'Rate',
51   - 'is_default' => 'Is Default',
52   - 'timestamp' => 'Timestamp',
53   - ];
54   - }
55   -}
backend/views/currency/_form.php
... ... @@ -17,7 +17,7 @@ use yii\widgets\ActiveForm;
17 17 <?= $form->field($model, 'rate')->textInput() ?>
18 18  
19 19 <div class="form-group">
20   - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
  20 + <?= Html::submitButton($model->isNewRecord ? 'Добавить' : 'Обновить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
21 21 </div>
22 22  
23 23 <?php ActiveForm::end(); ?>
... ...
backend/views/currency/create.php
... ... @@ -6,7 +6,7 @@ use yii\helpers\Html;
6 6 /* @var $this yii\web\View */
7 7 /* @var $model common\models\Currency */
8 8  
9   -$this->title = 'Create Currency';
  9 +$this->title = 'Добавить валюту';
10 10 $this->params['breadcrumbs'][] = ['label' => 'Currencies', 'url' => ['index']];
11 11 $this->params['breadcrumbs'][] = $this->title;
12 12 ?>
... ... @@ -18,4 +18,5 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
18 18 'model' => $model,
19 19 ]) ?>
20 20  
  21 + <?= Html::a('Вернуться', ['index'], ['class' => 'btn btn-primary']) ?>
21 22 </div>
... ...
backend/views/currency/index.php
... ... @@ -7,7 +7,7 @@ use yii\grid\GridView;
7 7 /* @var $searchModel common\models\CurrencySearch */
8 8 /* @var $dataProvider yii\data\ActiveDataProvider */
9 9  
10   -$this->title = 'Currencies';
  10 +$this->title = 'Курс валют';
11 11 $this->params['breadcrumbs'][] = $this->title;
12 12 ?>
13 13 <div class="currency-index">
... ... @@ -16,20 +16,18 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
16 16 <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
17 17  
18 18 <p>
19   - <?= Html::a('Create Currency', ['create'], ['class' => 'btn btn-success']) ?>
  19 + <?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
20 20 </p>
21 21  
22 22 <?= GridView::widget([
23 23 'dataProvider' => $dataProvider,
24   - 'filterModel' => $searchModel,
25 24 'columns' => [
26 25 ['class' => 'yii\grid\SerialColumn'],
27   -
28 26 'name',
29 27 'rate',
30 28 'timestamp',
31   -
32   - ['class' => 'yii\grid\ActionColumn'],
  29 + ['class' => 'yii\grid\ActionColumn',
  30 + 'template' => '{update}'],
33 31 ],
34 32 ]); ?>
35 33  
... ...
backend/views/currency/update.php
... ... @@ -5,7 +5,7 @@ use yii\helpers\Html;
5 5 /* @var $this yii\web\View */
6 6 /* @var $model common\models\Currency */
7 7  
8   -$this->title = 'Update Currency: ' . ' ' . $model->name;
  8 +$this->title = 'Обновить валюту: ' . ' ' . $model->name;
9 9 $this->params['breadcrumbs'][] = ['label' => 'Currencies', 'url' => ['index']];
10 10 $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
11 11 $this->params['breadcrumbs'][] = 'Update';
... ... @@ -18,4 +18,5 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = &#39;Update&#39;;
18 18 'model' => $model,
19 19 ]) ?>
20 20  
  21 + <?= Html::a('Вернуться', ['index'], ['class' => 'btn btn-primary']) ?>
21 22 </div>
... ...
backend/views/importers/_form.php
... ... @@ -3,7 +3,7 @@
3 3 use yii\helpers\Html;
4 4 use yii\widgets\ActiveForm;
5 5 use yii\helpers\ArrayHelper;
6   -use backend\models\Currency;
  6 +use common\models\Currency;
7 7  
8 8 /* @var $this yii\web\View */
9 9 /* @var $model backend\models\Importers */
... ...
backend/views/layouts/column.php
... ... @@ -325,7 +325,6 @@ $this-&gt;beginContent(&#39;@app/views/layouts/main.php&#39;);
325 325 ['label' => 'Vin коды', 'url' => ['currency/index']],
326 326 ['label' => 'Запросы по номеру', 'url' => ['currency/index']],
327 327 ['label' => 'Офисы', 'url' => ['offices/index']],
328   - ['label' => 'Валюты', 'url' => ['currency/index']],
329 328 ],
330 329 ],
331 330 ['label' => 'Анализ', 'url' => ['#'], 'items' => [
... ...
common/models/Currency.php
... ... @@ -30,7 +30,9 @@ class Currency extends \yii\db\ActiveRecord
30 30 {
31 31 return [
32 32 [['name', 'rate'], 'required'],
33   - [['rate'], 'number'],
  33 + [['rate'], 'filter','filter' => function($value){
  34 + return (float) str_replace( ',', '.', $value );}
  35 + ],
34 36 [['is_default'], 'integer'],
35 37 [['timestamp'], 'safe'],
36 38 [['name'], 'string', 'max' => 50],
... ...