From e556dca537901d69cc60a76fa3acc9e8cdb3d274 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 21 Oct 2015 14:32:14 +0300 Subject: [PATCH] Importers CRUD --- backend/views/art-history/index.php | 8 ++++++-- common/models/ArtHistory.php | 21 ++++++++++++++------- common/models/ArtHistorySearch.php | 18 +++++++++++++++--- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/backend/views/art-history/index.php b/backend/views/art-history/index.php index 461f5e4..772bfb5 100644 --- a/backend/views/art-history/index.php +++ b/backend/views/art-history/index.php @@ -26,10 +26,14 @@ $this->params['breadcrumbs'][] = $this->title; 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], - 'dt', 'user_id', - 'accounts.name', + [ + 'attribute' => 'name', + 'value' => 'name', + + ], 'art', + 'dt', ['class' => 'yii\grid\ActionColumn'], ], ]); ?> diff --git a/common/models/ArtHistory.php b/common/models/ArtHistory.php index 679a423..df536a7 100644 --- a/common/models/ArtHistory.php +++ b/common/models/ArtHistory.php @@ -14,6 +14,8 @@ use Yii; */ class ArtHistory extends \yii\db\ActiveRecord { + + public $name; /** * @inheritdoc */ @@ -30,7 +32,7 @@ class ArtHistory extends \yii\db\ActiveRecord return [ [['user_id', 'art', 'dt'], 'required'], [['user_id'], 'integer'], - [['art'], 'string', 'max' => 100], + [['art','name'], 'string', 'max' => 100], [['dt'], 'string', 'max' => 15], [['user_id', 'art'], 'unique', 'targetAttribute' => ['user_id', 'art'], 'message' => 'The combination of User ID and Art has already been taken.'] ]; @@ -43,15 +45,20 @@ class ArtHistory extends \yii\db\ActiveRecord { return [ 'id' => 'ID', - 'user_id' => 'User ID', - 'art' => 'Art', - 'dt' => 'Dt', + 'user_id' => '№', + 'art' => 'Нмер', + 'dt' => 'Дата', + 'name' => 'Клиент' ]; } - public function getAccounts() - { - return $this->hasOne(Accounts::className(), ['id' => 'user_id']); +// public function getAccounts() +// { +// return $this->hasOne(Accounts::className(), ['id' => 'user_id']); +// } + + public function getName(){ + return $this->user_id.'11111111'; } } diff --git a/common/models/ArtHistorySearch.php b/common/models/ArtHistorySearch.php index bb7fc55..159e014 100644 --- a/common/models/ArtHistorySearch.php +++ b/common/models/ArtHistorySearch.php @@ -12,6 +12,7 @@ use common\models\ArtHistory; */ class ArtHistorySearch extends ArtHistory { + /** * @inheritdoc */ @@ -19,7 +20,7 @@ class ArtHistorySearch extends ArtHistory { return [ [['id', 'user_id'], 'integer'], - [['art', 'dt'], 'safe'], + [['art', 'dt', 'name'], 'safe'], ]; } @@ -46,7 +47,17 @@ class ArtHistorySearch extends ArtHistory $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); - + $dataProvider->setSort([ + 'attributes' => [ + 'id', + 'user_id', + 'art', + 'dt', + 'name' => [ + 'default' => SORT_ASC + ] + ] + ]); $this->load($params); if (!$this->validate()) { @@ -54,6 +65,7 @@ class ArtHistorySearch extends ArtHistory // $query->where('0=1'); return $dataProvider; } + $query->joinWith(['accounts']); $query->andFilterWhere([ 'id' => $this->id, @@ -62,7 +74,7 @@ class ArtHistorySearch extends ArtHistory $query->andFilterWhere(['like', 'art', $this->art]) ->andFilterWhere(['like', 'dt', $this->dt]); - + //$query->andFilterWhere(['like', Accounts::tableName().'.name', $this->name]); return $dataProvider; } } -- libgit2 0.21.4