From def33f55c2b3787a67593fe6c12f20798045d3d4 Mon Sep 17 00:00:00 2001 From: SoHardKI Date: Wed, 3 Jul 2019 13:55:32 +0300 Subject: [PATCH 1/4] add_skill_column_inuser_index --- .../card/controllers/UserCardController.php | 2 ++ backend/modules/card/models/UserCard.php | 3 --- .../modules/card/models/UserCardSearch.php | 9 +++++++ .../card/views/user-card/_additional.php | 1 + .../modules/card/views/user-card/index.php | 24 +++++++++++++++++++ common/models/UserCard.php | 11 +++++++++ 6 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 backend/modules/card/views/user-card/_additional.php diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index 139417b..c379f65 100755 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -46,10 +46,12 @@ class UserCardController extends Controller $status = new Status(); $searchModel = new UserCardSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); +// $skills = CardSkill::find()->where(['card_id' => 'id'])->with('skill')->all(); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, +// 'skills' => $skills, ]); } diff --git a/backend/modules/card/models/UserCard.php b/backend/modules/card/models/UserCard.php index ae2e498..9f6719e 100755 --- a/backend/modules/card/models/UserCard.php +++ b/backend/modules/card/models/UserCard.php @@ -74,9 +74,6 @@ class UserCard extends \common\models\UserCard } } - - - if($post['skill']){ CardSkill::deleteAll(['card_id' => $this->id]); diff --git a/backend/modules/card/models/UserCardSearch.php b/backend/modules/card/models/UserCardSearch.php index 29a2ebe..806d412 100755 --- a/backend/modules/card/models/UserCardSearch.php +++ b/backend/modules/card/models/UserCardSearch.php @@ -2,6 +2,7 @@ namespace backend\modules\card\models; +use common\classes\Debug; use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; @@ -12,6 +13,7 @@ use backend\modules\card\models\UserCard; */ class UserCardSearch extends UserCard { + public $skill_name; /** * {@inheritdoc} */ @@ -20,6 +22,7 @@ class UserCardSearch extends UserCard return [ [['id', 'gender', 'status'], 'integer'], [['fio', 'passport', 'photo', 'email', 'dob', 'created_at', 'updated_at'], 'safe'], + [['skill_name'],'string'], ]; } @@ -45,6 +48,10 @@ class UserCardSearch extends UserCard // add conditions that should always apply here + //try join 3 tables + $query->leftJoin('card_skill', 'card_skill.card_id=user_card.id'); + $query->leftJoin('skill', 'skill.id=card_skill.skill_id'); + $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); @@ -74,6 +81,8 @@ class UserCardSearch extends UserCard ->andFilterWhere(['like', 'photo', $this->photo]) ->andFilterWhere(['like', 'email', $this->email]); + $query->andFilterWhere(['skill.id' => $this->skill_name]); + return $dataProvider; } } diff --git a/backend/modules/card/views/user-card/_additional.php b/backend/modules/card/views/user-card/_additional.php new file mode 100644 index 0000000..4b53d2d --- /dev/null +++ b/backend/modules/card/views/user-card/_additional.php @@ -0,0 +1 @@ +skill->name; ?> diff --git a/backend/modules/card/views/user-card/index.php b/backend/modules/card/views/user-card/index.php index 2778005..f69ff42 100755 --- a/backend/modules/card/views/user-card/index.php +++ b/backend/modules/card/views/user-card/index.php @@ -3,6 +3,7 @@ use yii\helpers\Html; use yii\grid\GridView; use yii\helpers\Url; +use yii\widgets\ListView; /* @var $this yii\web\View */ /* @var $searchModel backend\modules\card\models\UserCardSearch */ @@ -56,6 +57,29 @@ $this->params['breadcrumbs'][] = $this->title; ], //'created_at', //'updated_at', + [ + 'label' => 'Навыки', + 'format' => 'raw', + 'value' => function($model){ + $dataProvider = new \yii\data\ActiveDataProvider([ + 'query' => $model->getSkillValues(), + ]); + return ListView::widget([ + 'dataProvider' => $dataProvider, + 'itemView' => '_additional', + 'layout' => "{items}", + ]); + }, + 'filter' => kartik\select2\Select2::widget([ + 'attribute' => 'skill_name', + 'model' => $searchModel, + 'data' => \common\models\UserCard::getNameSkills(), + 'options' => ['placeholder' => 'Выбрать параметр','class' => 'form-control'], + 'pluginOptions' => [ + 'allowClear' => true + ], + ]), + ], ['class' => 'yii\grid\ActionColumn'], ], diff --git a/common/models/UserCard.php b/common/models/UserCard.php index de772fe..47c946f 100755 --- a/common/models/UserCard.php +++ b/common/models/UserCard.php @@ -5,6 +5,7 @@ namespace common\models; use Yii; use yii\behaviors\TimestampBehavior; use yii\db\Expression; +use yii\helpers\ArrayHelper; /** * This is the model class for table "user_card". @@ -140,4 +141,14 @@ class UserCard extends \yii\db\ActiveRecord { return $this->genders[$this->gender]; } + + public function getSkillValues() + { + return $this->hasMany(CardSkill::class, ['card_id' => 'id'])->with('skill'); + } + + public static function getNameSkills() + { + return ArrayHelper::map(Skill::find()->all(),'id', 'name'); + } } From c7ea822e2d1ac8e50d62b660a6386d02db5ba07b Mon Sep 17 00:00:00 2001 From: SoHardKI Date: Wed, 3 Jul 2019 16:06:11 +0300 Subject: [PATCH 2/4] add_skills --- backend/modules/card/models/UserCardSearch.php | 9 ++++----- backend/modules/card/views/user-card/index.php | 5 +++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/modules/card/models/UserCardSearch.php b/backend/modules/card/models/UserCardSearch.php index 806d412..26d6e62 100755 --- a/backend/modules/card/models/UserCardSearch.php +++ b/backend/modules/card/models/UserCardSearch.php @@ -13,7 +13,7 @@ use backend\modules\card\models\UserCard; */ class UserCardSearch extends UserCard { - public $skill_name; + public $skills; /** * {@inheritdoc} */ @@ -22,7 +22,7 @@ class UserCardSearch extends UserCard return [ [['id', 'gender', 'status'], 'integer'], [['fio', 'passport', 'photo', 'email', 'dob', 'created_at', 'updated_at'], 'safe'], - [['skill_name'],'string'], + ['skills', 'each', 'rule' => ['integer']], ]; } @@ -45,7 +45,6 @@ class UserCardSearch extends UserCard public function search($params) { $query = UserCard::find(); - // add conditions that should always apply here //try join 3 tables @@ -80,8 +79,8 @@ class UserCardSearch extends UserCard ->andFilterWhere(['like', 'passport', $this->passport]) ->andFilterWhere(['like', 'photo', $this->photo]) ->andFilterWhere(['like', 'email', $this->email]); - - $query->andFilterWhere(['skill.id' => $this->skill_name]); + + $query->andFilterWhere(['skill.id' => $this->skills]); return $dataProvider; } diff --git a/backend/modules/card/views/user-card/index.php b/backend/modules/card/views/user-card/index.php index f69ff42..6caa45a 100755 --- a/backend/modules/card/views/user-card/index.php +++ b/backend/modules/card/views/user-card/index.php @@ -71,10 +71,11 @@ $this->params['breadcrumbs'][] = $this->title; ]); }, 'filter' => kartik\select2\Select2::widget([ - 'attribute' => 'skill_name', + 'attribute' => 'skills', 'model' => $searchModel, 'data' => \common\models\UserCard::getNameSkills(), - 'options' => ['placeholder' => 'Выбрать параметр','class' => 'form-control'], +// 'maintainOrder' => true, + 'options' => ['multiple' => true,'placeholder' => 'Выбрать параметр','class' => 'form-control'], 'pluginOptions' => [ 'allowClear' => true ], From 3f482475699479d1ae67ea79cde2df194e1e7b31 Mon Sep 17 00:00:00 2001 From: SoHardKI Date: Wed, 3 Jul 2019 16:09:10 +0300 Subject: [PATCH 3/4] add_skills --- backend/modules/card/views/user-card/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/modules/card/views/user-card/index.php b/backend/modules/card/views/user-card/index.php index 6caa45a..bca1464 100755 --- a/backend/modules/card/views/user-card/index.php +++ b/backend/modules/card/views/user-card/index.php @@ -74,7 +74,6 @@ $this->params['breadcrumbs'][] = $this->title; 'attribute' => 'skills', 'model' => $searchModel, 'data' => \common\models\UserCard::getNameSkills(), -// 'maintainOrder' => true, 'options' => ['multiple' => true,'placeholder' => 'Выбрать параметр','class' => 'form-control'], 'pluginOptions' => [ 'allowClear' => true From 1a3a0aa5f86ca9fd472feec03f8bfb93c5de3693 Mon Sep 17 00:00:00 2001 From: SoHardKI Date: Wed, 3 Jul 2019 16:17:20 +0300 Subject: [PATCH 4/4] small_fixes --- backend/modules/card/controllers/UserCardController.php | 4 ---- backend/modules/card/models/UserCardSearch.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index c379f65..6ea86c5 100755 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -43,15 +43,12 @@ class UserCardController extends Controller */ public function actionIndex() { - $status = new Status(); $searchModel = new UserCardSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); -// $skills = CardSkill::find()->where(['card_id' => 'id'])->with('skill')->all(); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, -// 'skills' => $skills, ]); } @@ -109,7 +106,6 @@ class UserCardController extends Controller public function actionUpdate($id) { $model = $this->findModel($id); -// Debug::dd($model); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } diff --git a/backend/modules/card/models/UserCardSearch.php b/backend/modules/card/models/UserCardSearch.php index 26d6e62..98f7a7c 100755 --- a/backend/modules/card/models/UserCardSearch.php +++ b/backend/modules/card/models/UserCardSearch.php @@ -79,7 +79,7 @@ class UserCardSearch extends UserCard ->andFilterWhere(['like', 'passport', $this->passport]) ->andFilterWhere(['like', 'photo', $this->photo]) ->andFilterWhere(['like', 'email', $this->email]); - + $query->andFilterWhere(['skill.id' => $this->skills]); return $dataProvider;