merge
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,
|
||||
]);
|
||||
@ -86,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', [
|
||||
@ -124,4 +151,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'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
@ -30,7 +30,8 @@ use yii\widgets\ActiveForm;
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
'allowClear' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
]
|
||||
) ?>
|
||||
|
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>
|
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
@ -16,6 +18,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([
|
||||
@ -26,13 +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',
|
||||
'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,
|
||||
]) ?>
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
namespace backend\modules\task\controllers;
|
||||
|
||||
use backend\modules\project\models\ProjectUser;
|
||||
use yii\base\Model;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\Response;
|
||||
use Yii;
|
||||
use backend\modules\task\models\TaskUser;
|
||||
@ -63,41 +65,39 @@ class TaskUserController extends Controller
|
||||
* Creates a new TaskUser model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function actionCreate($task_id = null)
|
||||
{
|
||||
$model = new TaskUser();
|
||||
$post = \Yii::$app->request->post('TaskUser');
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
if (!empty($post)) {
|
||||
$project_user_id_arr = ArrayHelper::getValue($post, 'project_user_id');
|
||||
|
||||
foreach ($project_user_id_arr as $project_user_id) {
|
||||
$emtModel = new TaskUser();
|
||||
$emtModel->task_id = $post['task_id'];
|
||||
$emtModel->project_user_id = $project_user_id;
|
||||
|
||||
if (!$emtModel->save()) {
|
||||
return $this->render('create', [
|
||||
'model' => $emtModel,
|
||||
'task_id' => $task_id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($task_id !== null)
|
||||
{
|
||||
return $this->redirect(['task/view', 'id' => $task_id]);
|
||||
}
|
||||
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
'task_id' => $task_id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new TaskUser model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreateForCurrentTask($task_id = null)
|
||||
{
|
||||
$model = new TaskUser();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['task/view', 'id' => $task_id]);
|
||||
}
|
||||
|
||||
return $this->render('create_for_current_task', [
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
'task_id' => $task_id,
|
||||
]);
|
||||
@ -185,4 +185,9 @@ class TaskUserController extends Controller
|
||||
}
|
||||
return ['output'=>'', 'selected'=>''];
|
||||
}
|
||||
|
||||
public function actionDynamicProjectUser()
|
||||
{
|
||||
var_dump('hhh'); die;
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class TaskUserSearch extends TaskUser
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = TaskUser::find()->joinWith(['task', 'projectUser', 'projectUser.project']);
|
||||
$query = TaskUser::find()->joinWith(['task', 'projectUser', 'projectUser.project', 'projectUser.user']);
|
||||
|
||||
// add conditions that should always apply here
|
||||
|
||||
|
@ -21,19 +21,27 @@ use yii\widgets\ActiveForm;
|
||||
'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => 'Выберите проект', 'value' => $task_id, 'id' => 'task-id',],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'allowClear' => false,
|
||||
],
|
||||
]);
|
||||
?>
|
||||
|
||||
<?= $form->field($model, 'project_user_id')->widget(DepDrop::className(),
|
||||
[
|
||||
'options' => ['id' => 'project-user-id'],
|
||||
'type' => DepDrop::TYPE_SELECT2,
|
||||
'options' => ['id' => 'project-user-id', 'allowClear' => true, 'multiple' => true], // , 'multiple' => true
|
||||
'select2Options' => [
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'closeOnSelect' => false,
|
||||
],
|
||||
'showToggleAll' => false,
|
||||
],
|
||||
'pluginOptions' => [
|
||||
'depends' => ['task-id'],
|
||||
'placeholder' => 'Выберите',
|
||||
'initialize' => true,
|
||||
'url' => Url::to(['/task/task-user/executor'])
|
||||
'url' => Url::to(['/task/task-user/executor']),
|
||||
]
|
||||
]
|
||||
); ?>
|
||||
|
47
backend/modules/task/views/task-user/_form_update.php
Normal file
47
backend/modules/task/views/task-user/_form_update.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\task\models\Task;
|
||||
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 */
|
||||
/* @var $model backend\modules\task\models\TaskUser */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
/* @var $task_id */
|
||||
?>
|
||||
|
||||
<div class="task-user-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'task_id')->widget(Select2::className(),[
|
||||
'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => 'Выберите проект', 'value' => $task_id, 'id' => 'task-id',],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => false,
|
||||
],
|
||||
]);
|
||||
?>
|
||||
|
||||
<?= $form->field($model, 'project_user_id')->widget(DepDrop::className(),
|
||||
[
|
||||
'options' => ['id' => 'project-user-id', 'allowClear' => true],
|
||||
'pluginOptions' => [
|
||||
'depends' => ['task-id'],
|
||||
'placeholder' => 'Выберите',
|
||||
'initialize' => true,
|
||||
'url' => Url::to(['/task/task-user/executor']),
|
||||
]
|
||||
]
|
||||
); ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Назначить', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
@ -2,6 +2,7 @@
|
||||
|
||||
use backend\modules\project\models\ProjectUser;
|
||||
use backend\modules\task\models\Task;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
@ -30,14 +31,38 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
[
|
||||
'attribute' => 'task_id',
|
||||
'filter' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'task.title'
|
||||
'value' => 'task.title',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'task_id',
|
||||
'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '250px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
[
|
||||
'attribute' => 'project_user_id',
|
||||
'filter' => ProjectUser::find()->select(['user.username', 'project_user.id'])
|
||||
->joinWith('user')->indexBy('project_user.id')->column(),
|
||||
'value' => 'projectUser.user.username'
|
||||
'value' => 'projectUser.user.username',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'project_user_id',
|
||||
'data' => ProjectUser::find()->select(['user.username', 'project_user.id'])
|
||||
->joinWith('user')->indexBy('project_user.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="task-user-update">
|
||||
|
||||
<?= $this->render('_form', [
|
||||
<?= $this->render('_form_update', [
|
||||
'model' => $model,
|
||||
'task_id' => $task_id,
|
||||
]) ?>
|
||||
|
@ -30,7 +30,7 @@ use yii\widgets\ActiveForm;
|
||||
<?= $form->field($model, 'user_id_creator')->widget(Select2::class,
|
||||
[
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'options' => ['placeholder' => '...','class' => 'form-control', 'value' => Yii::$app->user->id],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'prompt' => 'Выберите'
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
use backend\modules\project\models\Project;
|
||||
use backend\modules\project\models\ProjectUser;
|
||||
use backend\modules\task\models\Task;
|
||||
use common\helpers\StatusHelper;
|
||||
use common\models\User;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
@ -29,19 +31,55 @@ $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' => '150px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
'title',
|
||||
[
|
||||
'attribute' => 'user_id_creator',
|
||||
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'userIdCreator.username'
|
||||
'value' => 'userIdCreator.username',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'user_id_creator',
|
||||
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '150px',
|
||||
],
|
||||
'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' => '150px',
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
'description',
|
||||
[
|
||||
@ -58,7 +96,6 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
],
|
||||
[
|
||||
'attribute' => 'updated_at',
|
||||
'filter' => User::find()->select(['updated_at', 'updated_at'])->indexBy('updated_at')->column(),
|
||||
'format' => ['datetime', 'php:d.m.Y H:i']
|
||||
],
|
||||
|
||||
|
Reference in New Issue
Block a user