add filters, some improvements
This commit is contained in:
@ -109,8 +109,12 @@ class ProjectUserController extends Controller
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
if ($model->load(Yii::$app->request->post()) ) {
|
||||
$model->card_id = UserCard::getIdByUserId($model->user_id);
|
||||
if ($model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->render('update', [
|
||||
|
@ -39,7 +39,7 @@ class ProjectUserSearch extends ProjectUser
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = ProjectUser::find()->joinWith(['project', 'user']);
|
||||
$query = ProjectUser::find()->joinWith(['project', 'user', 'card']);
|
||||
|
||||
// add conditions that should always apply here
|
||||
|
||||
|
45
backend/modules/project/views/project-user/_form_update.php
Normal file
45
backend/modules/project/views/project-user/_form_update.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\project\models\Project;
|
||||
use common\models\User;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\project\models\ProjectUser */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="project-user-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'project_id')->widget(Select2::className(),
|
||||
[
|
||||
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
]
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'user_id')->widget(Select2::className(),
|
||||
[
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'multiple' => false,
|
||||
],
|
||||
]
|
||||
) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
@ -3,6 +3,7 @@
|
||||
use backend\modules\card\models\UserCard;
|
||||
use backend\modules\project\models\Project;
|
||||
use common\models\User;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
@ -29,18 +30,54 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
[
|
||||
'attribute' => 'project_id',
|
||||
'filter' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'project.name'
|
||||
'value' => 'project.name',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'project_id',
|
||||
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '250px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
[
|
||||
'attribute' => 'user_id',
|
||||
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'user.username'
|
||||
'value' => 'user.username',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'user_id',
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '250px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
[
|
||||
'attribute' => 'card_id',
|
||||
'filter' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'card.fio'
|
||||
'value' => 'card.fio',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'card_id',
|
||||
'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '250px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
|
@ -12,7 +12,7 @@ $this->params['breadcrumbs'][] = 'Update';
|
||||
?>
|
||||
<div class="project-user-update">
|
||||
|
||||
<?= $this->render('_form', [
|
||||
<?= $this->render('_form_update', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
|
Reference in New Issue
Block a user