add multi-assignment to tasks and projects
This commit is contained in:
@ -2,12 +2,16 @@
|
||||
|
||||
namespace backend\modules\project\controllers;
|
||||
|
||||
use common\models\UserCard;
|
||||
use Exception;
|
||||
use Yii;
|
||||
use backend\modules\project\models\ProjectUser;
|
||||
use backend\modules\project\models\ProjectUserSearch;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\web\Response;
|
||||
|
||||
/**
|
||||
* ProjectUserController implements the CRUD actions for ProjectUser model.
|
||||
@ -60,16 +64,35 @@ class ProjectUserController extends Controller
|
||||
/**
|
||||
* Creates a new ProjectUser model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
* @return string|Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new ProjectUser();
|
||||
$post = \Yii::$app->request->post('ProjectUser');
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
if (!empty($post)) {
|
||||
$user_id_arr = ArrayHelper::getValue($post, 'user_id');
|
||||
$project_id = $post['project_id'];
|
||||
|
||||
foreach ($user_id_arr as $user_id) {
|
||||
$emtModel = new ProjectUser();
|
||||
$emtModel->project_id = $project_id;
|
||||
$emtModel->user_id = $user_id;
|
||||
$emtModel->card_id = UserCard::getIdByUserId($user_id);
|
||||
|
||||
$emtModel->save();
|
||||
|
||||
// if (!$emtModel->save()) {
|
||||
// return $this->render('create', [
|
||||
// 'model' => $emtModel,
|
||||
// ]);
|
||||
// }
|
||||
}
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
$model = new ProjectUser();
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
@ -124,4 +147,18 @@ class ProjectUserController extends Controller
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
|
||||
public function actionSetUserFields(): Response
|
||||
{
|
||||
ProjectUser::setUsersByCardId();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
public function actionSetCardFields(): Response
|
||||
{
|
||||
ProjectUser::setCardsByUsersId();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
}
|
||||
|
@ -96,6 +96,7 @@ class Project extends \common\models\Project
|
||||
$prUser = new ProjectUser();
|
||||
$prUser->project_id = $this->id;
|
||||
$prUser->card_id = $item;
|
||||
$prUser->user_id = $prUser->card->user->id;
|
||||
|
||||
$prUser->save();
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class ProjectUserSearch extends ProjectUser
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'project_id', 'user_id'], 'integer'],
|
||||
[['id', 'project_id', 'user_id', 'card_id'], 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -60,6 +60,7 @@ class ProjectUserSearch extends ProjectUser
|
||||
'id' => $this->id,
|
||||
'project_id' => $this->project_id,
|
||||
'user_id' => $this->user_id,
|
||||
'card_id' => $this->card_id,
|
||||
]);
|
||||
|
||||
return $dataProvider;
|
||||
|
@ -31,7 +31,7 @@ use yii\widgets\ActiveForm;
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'multiple' => false,//true,
|
||||
'multiple' => true,
|
||||
],
|
||||
]
|
||||
) ?>
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\card\models\UserCard;
|
||||
use backend\modules\project\models\Project;
|
||||
use common\models\User;
|
||||
use yii\helpers\Html;
|
||||
@ -16,6 +17,8 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
<p>
|
||||
<?= Html::a('Назначить сотрудника на проект', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
<?= Html::a('Установить значения поля "Сотрудник"', ['set-user-fields'], ['class' => 'btn btn-secondary']) ?>
|
||||
<?= Html::a('Установить значения поля "Карточка"', ['set-card-fields'], ['class' => 'btn btn-secondary']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
@ -34,6 +37,11 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'user.username'
|
||||
],
|
||||
[
|
||||
'attribute' => 'card_id',
|
||||
'filter' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'card.fio'
|
||||
],
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
],
|
||||
|
Reference in New Issue
Block a user