update foreign key in task in task
This commit is contained in:
@ -72,22 +72,20 @@ class ProjectUserController extends Controller
|
||||
$post = \Yii::$app->request->post('ProjectUser');
|
||||
|
||||
if (!empty($post)) {
|
||||
$user_id_arr = ArrayHelper::getValue($post, 'user_id');
|
||||
$card_id_arr = ArrayHelper::getValue($post, 'card_id');
|
||||
$project_id = $post['project_id'];
|
||||
|
||||
foreach ($user_id_arr as $user_id) {
|
||||
foreach ($card_id_arr as $card_id) {
|
||||
$emtModel = new ProjectUser();
|
||||
$emtModel->project_id = $project_id;
|
||||
$emtModel->user_id = $user_id;
|
||||
$emtModel->card_id = UserCard::getIdByUserId($user_id);
|
||||
$emtModel->card_id = $card_id;
|
||||
$emtModel->user_id = UserCard::getUserIdByCardId($card_id);
|
||||
|
||||
$emtModel->save();
|
||||
|
||||
// if (!$emtModel->save()) {
|
||||
// return $this->render('create', [
|
||||
// 'model' => $emtModel,
|
||||
// ]);
|
||||
// }
|
||||
if (!$emtModel->save()) {
|
||||
return $this->render('create', [
|
||||
'model' => $emtModel,
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
@ -110,7 +108,7 @@ class ProjectUserController extends Controller
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) ) {
|
||||
$model->card_id = UserCard::getIdByUserId($model->user_id);
|
||||
$model->user_id = UserCard::getUserIdByCardId($model->card_id);//UserCard::getIdByUserId($model->user_id);
|
||||
if ($model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\card\models\UserCard;
|
||||
use backend\modules\project\models\Project;
|
||||
use common\models\User;
|
||||
use kartik\select2\Select2;
|
||||
@ -25,9 +26,9 @@ use yii\widgets\ActiveForm;
|
||||
]
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'user_id')->widget(Select2::className(),
|
||||
<?= $form->field($model, 'card_id')->widget(Select2::className(),
|
||||
[
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\card\models\UserCard;
|
||||
use backend\modules\project\models\Project;
|
||||
use common\models\User;
|
||||
use kartik\select2\Select2;
|
||||
@ -25,9 +26,9 @@ use yii\widgets\ActiveForm;
|
||||
]
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'user_id')->widget(Select2::className(),
|
||||
<?= $form->field($model, 'card_id')->widget(Select2::className(),
|
||||
[
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\web\YiiAsset;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
@ -10,7 +11,7 @@ use yii\widgets\DetailView;
|
||||
$this->title = 'Сотрудник проекта: ' . $model->project->name;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Project Users', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
YiiAsset::register($this);
|
||||
?>
|
||||
<div class="project-user-view">
|
||||
|
||||
@ -38,6 +39,10 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'attribute' => 'user_id',
|
||||
'value' => ArrayHelper::getValue($model, 'user.username' ),
|
||||
],
|
||||
[
|
||||
'attribute' => 'card_id',
|
||||
'value' => ArrayHelper::getValue($model, 'card.fio' ),
|
||||
],
|
||||
],
|
||||
]) ?>
|
||||
|
||||
|
@ -18,7 +18,7 @@ class TaskSearch extends Task
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'project_id', 'status', 'user_id_creator', 'user_id'], 'integer'],
|
||||
[['id', 'project_id', 'status', 'card_id_creator', 'card_id'], 'integer'], // 'card_id_creator', 'card_id'
|
||||
[['title', 'created_at', 'updated_at', 'description'], 'safe'],
|
||||
];
|
||||
}
|
||||
@ -41,10 +41,7 @@ class TaskSearch extends Task
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = Task::find()->joinWith(['user', 'project']);
|
||||
// => function($query){
|
||||
// $query->from(ProjectUser::tableName() . ' pt');
|
||||
// }]); //,
|
||||
$query = Task::find();//->joinWith(['user_card', 'project']);
|
||||
|
||||
// add conditions that should always apply here
|
||||
|
||||
@ -67,8 +64,8 @@ class TaskSearch extends Task
|
||||
'task.status' => $this->status,
|
||||
'task.created_at' => $this->created_at,
|
||||
'task.updated_at' => $this->updated_at,
|
||||
'user_id_creator' => $this->user_id_creator,
|
||||
'task.user_id' => $this->user_id,
|
||||
'task.card_id_creator' => $this->card_id_creator,
|
||||
'task.card_id' => $this->card_id,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'title', $this->title])
|
||||
|
@ -1,13 +1,10 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\card\models\UserCard;
|
||||
use backend\modules\project\models\Project;
|
||||
use backend\modules\project\models\ProjectUser;
|
||||
use common\helpers\StatusHelper;
|
||||
use common\models\User;
|
||||
use kartik\depdrop\DepDrop;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
@ -27,9 +24,9 @@ use yii\widgets\ActiveForm;
|
||||
);
|
||||
?>
|
||||
|
||||
<?= $form->field($model, 'user_id_creator')->widget(Select2::class,
|
||||
<?= $form->field($model, 'card_id_creator')->widget(Select2::class,
|
||||
[
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control', 'value' => Yii::$app->user->id],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
@ -47,9 +44,9 @@ use yii\widgets\ActiveForm;
|
||||
]
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'user_id')->widget(Select2::class,
|
||||
<?= $form->field($model, 'card_id')->widget(Select2::class,
|
||||
[
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\card\models\UserCard;
|
||||
use backend\modules\project\models\Project;
|
||||
use backend\modules\project\models\ProjectUser;
|
||||
use backend\modules\task\models\Task;
|
||||
@ -35,7 +36,8 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'project_id',
|
||||
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
'data' => Task::find()->joinWith('project')
|
||||
->select(['project.name', 'project.id'])->indexBy('project.id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '150px',
|
||||
@ -48,12 +50,13 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
],
|
||||
'title',
|
||||
[
|
||||
'attribute' => 'user_id_creator',
|
||||
'value' => 'userIdCreator.username',
|
||||
'attribute' => 'card_id_creator',
|
||||
'value' => 'userCardCreator.fio',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'user_id_creator',
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'attribute' => 'card_id_creator',
|
||||
'data' => Task::find()->joinWith('userCardCreator')
|
||||
->select(['user_card.fio', 'user_card.id'])->indexBy('user_card.id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '150px',
|
||||
@ -65,12 +68,13 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
])
|
||||
],
|
||||
[
|
||||
'attribute' => 'user_id',
|
||||
'value' => 'user.username',
|
||||
'attribute' => 'card_id',
|
||||
'value' => 'userCard.fio',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'user_id',
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'attribute' => 'card_id',
|
||||
'data' => Task::find()->joinWith('userCard')
|
||||
->select(['user_card.fio', 'user_card.id'])->indexBy('user_card.id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '150px',
|
||||
|
@ -47,12 +47,12 @@ YiiAsset::register($this);
|
||||
'created_at',
|
||||
'updated_at',
|
||||
[
|
||||
'attribute' => 'project_user_id',
|
||||
'value' => ArrayHelper::getValue($model, 'projectUser.user.username'),
|
||||
'attribute' => 'card_id_creator',
|
||||
'value' => ArrayHelper::getValue($model, 'userCardCreator.fio'),
|
||||
],
|
||||
[
|
||||
'attribute' => 'user_id',
|
||||
'value' => ArrayHelper::getValue($model, 'user.username'),
|
||||
'attribute' => 'card_id',
|
||||
'value' => ArrayHelper::getValue($model, 'userCard.fio'),
|
||||
],
|
||||
'description',
|
||||
],
|
||||
|
Reference in New Issue
Block a user