commit
a45a584ed4
@ -43,7 +43,6 @@ class UserCardController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function actionIndex()
|
public function actionIndex()
|
||||||
{
|
{
|
||||||
$status = new Status();
|
|
||||||
$searchModel = new UserCardSearch();
|
$searchModel = new UserCardSearch();
|
||||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
|
|
||||||
@ -107,7 +106,6 @@ class UserCardController extends Controller
|
|||||||
public function actionUpdate($id)
|
public function actionUpdate($id)
|
||||||
{
|
{
|
||||||
$model = $this->findModel($id);
|
$model = $this->findModel($id);
|
||||||
// Debug::dd($model);
|
|
||||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||||
return $this->redirect(['view', 'id' => $model->id]);
|
return $this->redirect(['view', 'id' => $model->id]);
|
||||||
}
|
}
|
||||||
|
@ -74,9 +74,6 @@ class UserCard extends \common\models\UserCard
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if($post['skill']){
|
if($post['skill']){
|
||||||
CardSkill::deleteAll(['card_id' => $this->id]);
|
CardSkill::deleteAll(['card_id' => $this->id]);
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace backend\modules\card\models;
|
namespace backend\modules\card\models;
|
||||||
|
|
||||||
|
use common\classes\Debug;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\base\Model;
|
use yii\base\Model;
|
||||||
use yii\data\ActiveDataProvider;
|
use yii\data\ActiveDataProvider;
|
||||||
@ -12,6 +13,7 @@ use backend\modules\card\models\UserCard;
|
|||||||
*/
|
*/
|
||||||
class UserCardSearch extends UserCard
|
class UserCardSearch extends UserCard
|
||||||
{
|
{
|
||||||
|
public $skills;
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -20,6 +22,7 @@ class UserCardSearch extends UserCard
|
|||||||
return [
|
return [
|
||||||
[['id', 'gender', 'status'], 'integer'],
|
[['id', 'gender', 'status'], 'integer'],
|
||||||
[['fio', 'passport', 'photo', 'email', 'dob', 'created_at', 'updated_at'], 'safe'],
|
[['fio', 'passport', 'photo', 'email', 'dob', 'created_at', 'updated_at'], 'safe'],
|
||||||
|
['skills', 'each', 'rule' => ['integer']],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,9 +45,12 @@ class UserCardSearch extends UserCard
|
|||||||
public function search($params)
|
public function search($params)
|
||||||
{
|
{
|
||||||
$query = UserCard::find();
|
$query = UserCard::find();
|
||||||
|
|
||||||
// add conditions that should always apply here
|
// 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([
|
$dataProvider = new ActiveDataProvider([
|
||||||
'query' => $query,
|
'query' => $query,
|
||||||
]);
|
]);
|
||||||
@ -74,6 +80,8 @@ class UserCardSearch extends UserCard
|
|||||||
->andFilterWhere(['like', 'photo', $this->photo])
|
->andFilterWhere(['like', 'photo', $this->photo])
|
||||||
->andFilterWhere(['like', 'email', $this->email]);
|
->andFilterWhere(['like', 'email', $this->email]);
|
||||||
|
|
||||||
|
$query->andFilterWhere(['skill.id' => $this->skills]);
|
||||||
|
|
||||||
return $dataProvider;
|
return $dataProvider;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
backend/modules/card/views/user-card/_additional.php
Normal file
1
backend/modules/card/views/user-card/_additional.php
Normal file
@ -0,0 +1 @@
|
|||||||
|
<?= $model->skill->name; ?>
|
@ -3,6 +3,7 @@
|
|||||||
use yii\helpers\Html;
|
use yii\helpers\Html;
|
||||||
use yii\grid\GridView;
|
use yii\grid\GridView;
|
||||||
use yii\helpers\Url;
|
use yii\helpers\Url;
|
||||||
|
use yii\widgets\ListView;
|
||||||
|
|
||||||
/* @var $this yii\web\View */
|
/* @var $this yii\web\View */
|
||||||
/* @var $searchModel backend\modules\card\models\UserCardSearch */
|
/* @var $searchModel backend\modules\card\models\UserCardSearch */
|
||||||
@ -56,6 +57,29 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
],
|
],
|
||||||
//'created_at',
|
//'created_at',
|
||||||
//'updated_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' => 'skills',
|
||||||
|
'model' => $searchModel,
|
||||||
|
'data' => \common\models\UserCard::getNameSkills(),
|
||||||
|
'options' => ['multiple' => true,'placeholder' => 'Выбрать параметр','class' => 'form-control'],
|
||||||
|
'pluginOptions' => [
|
||||||
|
'allowClear' => true
|
||||||
|
],
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
|
||||||
['class' => 'yii\grid\ActionColumn'],
|
['class' => 'yii\grid\ActionColumn'],
|
||||||
],
|
],
|
||||||
|
@ -5,6 +5,7 @@ namespace common\models;
|
|||||||
use Yii;
|
use Yii;
|
||||||
use yii\behaviors\TimestampBehavior;
|
use yii\behaviors\TimestampBehavior;
|
||||||
use yii\db\Expression;
|
use yii\db\Expression;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the model class for table "user_card".
|
* This is the model class for table "user_card".
|
||||||
@ -140,4 +141,14 @@ class UserCard extends \yii\db\ActiveRecord
|
|||||||
{
|
{
|
||||||
return $this->genders[$this->gender];
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user