From 9eba04cae2f8b665c7790b361d9a1960df8c7f53 Mon Sep 17 00:00:00 2001 From: iIronside Date: Mon, 23 Jan 2023 11:40:45 +0300 Subject: [PATCH] rename task to project_task and task_user to project_task_user; create project_task_category, fix bug in create project method --- .../controllers/ProjectUserController.php | 21 +++ .../project/views/project-user/_form.php | 47 ++++--- .../ProjectTaskCategoryController.php | 127 ++++++++++++++++++ .../task/models/ProjectTaskCategory.php | 9 ++ .../task/models/ProjectTaskCategorySearch.php | 69 ++++++++++ .../views/project-task-category/_form.php | 32 +++++ .../views/project-task-category/_search.php | 31 +++++ .../views/project-task-category/create.php | 18 +++ .../views/project-task-category/index.php | 51 +++++++ .../views/project-task-category/update.php | 21 +++ .../task/views/project-task-category/view.php | 40 ++++++ .../modules/task/views/task-user/index.php | 4 +- backend/views/layouts/left.php | 1 + common/models/ProjectTaskCategory.php | 57 ++++++++ common/models/ProjectUser.php | 11 ++ 15 files changed, 521 insertions(+), 18 deletions(-) create mode 100644 backend/modules/task/controllers/ProjectTaskCategoryController.php create mode 100644 backend/modules/task/models/ProjectTaskCategory.php create mode 100644 backend/modules/task/models/ProjectTaskCategorySearch.php create mode 100644 backend/modules/task/views/project-task-category/_form.php create mode 100644 backend/modules/task/views/project-task-category/_search.php create mode 100644 backend/modules/task/views/project-task-category/create.php create mode 100644 backend/modules/task/views/project-task-category/index.php create mode 100644 backend/modules/task/views/project-task-category/update.php create mode 100644 backend/modules/task/views/project-task-category/view.php create mode 100644 common/models/ProjectTaskCategory.php diff --git a/backend/modules/project/controllers/ProjectUserController.php b/backend/modules/project/controllers/ProjectUserController.php index 0e60acd..5eb31c6 100644 --- a/backend/modules/project/controllers/ProjectUserController.php +++ b/backend/modules/project/controllers/ProjectUserController.php @@ -166,4 +166,25 @@ class ProjectUserController extends Controller return $this->redirect(['index']); } + + public function actionUsersNotOnProject(): array + { + Yii::$app->response->format = Response::FORMAT_JSON; + + if (isset($_POST['depdrop_parents'])) { + $parents = $_POST['depdrop_parents']; + if ($parents != null) { + $project_id = $parents[0]; + $categories = ProjectUser::getUsersNotOnProject($project_id); + + $formattedCatArr = array(); + foreach ($categories as $key => $value){ + $formattedCatArr[] = array('id' => $key, 'name' => $value); + } + + return ['output'=>$formattedCatArr, 'selected'=>'']; + } + } + return ['output'=>'', 'selected'=>'']; + } } diff --git a/backend/modules/project/views/project-user/_form.php b/backend/modules/project/views/project-user/_form.php index cd8b064..8713a51 100644 --- a/backend/modules/project/views/project-user/_form.php +++ b/backend/modules/project/views/project-user/_form.php @@ -1,10 +1,9 @@ - field($model, 'project_id')->widget(Select2::className(), + field($model, 'project_id')->dropDownList( + Project::find()->select(['name', 'id'])->indexBy('id')->column(), [ - 'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(), - 'options' => ['placeholder' => '...','class' => 'form-control'], - 'pluginOptions' => [ - 'allowClear' => true - ], + 'id' => 'project-id', + 'prompt' => 'Выберите' ] - ) ?> + ); + ?> - field($model, 'card_id')->widget(Select2::className(), + field($model, 'card_id')->widget(DepDrop::className(), [ - 'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(), - 'options' => ['placeholder' => '...','class' => 'form-control'], + 'options' => ['id' => 'card_id'], 'pluginOptions' => [ - 'allowClear' => true, - 'multiple' => true, + 'depends' => ['project-id'], + 'placeholder' => 'Выберите', + 'url' => Url::to(['/project/project-user/users-not-on-project']) + ,'initialize' => false, + ], + + 'type' => DepDrop::TYPE_SELECT2, + 'select2Options' => [ + 'hideSearch' => false, + 'pluginOptions' => [ + 'allowClear' => true, + 'closeOnSelect' => false, + 'multiple' => true, + 'hideSearch' => false + ], + 'showToggleAll' => false, ], ] - ) ?> + ); + echo "

+ * в списке отображаются только пользователи у которых присудствует запись в таблице user (в user_card есть id_user) +

"; + ?>
'btn btn-success']) ?> diff --git a/backend/modules/task/controllers/ProjectTaskCategoryController.php b/backend/modules/task/controllers/ProjectTaskCategoryController.php new file mode 100644 index 0000000..04f22db --- /dev/null +++ b/backend/modules/task/controllers/ProjectTaskCategoryController.php @@ -0,0 +1,127 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all ProjectTaskCategory models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new ProjectTaskCategorySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single ProjectTaskCategory model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new ProjectTaskCategory model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new ProjectTaskCategory(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing ProjectTaskCategory model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing ProjectTaskCategory model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the ProjectTaskCategory model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return ProjectTaskCategory the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = ProjectTaskCategory::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/backend/modules/task/models/ProjectTaskCategory.php b/backend/modules/task/models/ProjectTaskCategory.php new file mode 100644 index 0000000..4a6a272 --- /dev/null +++ b/backend/modules/task/models/ProjectTaskCategory.php @@ -0,0 +1,9 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'project_id' => $this->project_id, + ]); + + $query->andFilterWhere(['like', 'title', $this->title]); + + return $dataProvider; + } +} diff --git a/backend/modules/task/views/project-task-category/_form.php b/backend/modules/task/views/project-task-category/_form.php new file mode 100644 index 0000000..6916101 --- /dev/null +++ b/backend/modules/task/views/project-task-category/_form.php @@ -0,0 +1,32 @@ + + +
+ + + + field($model, 'title')->textInput(['maxlength' => true]) ?> + + field($model, 'project_id')->dropDownList( + Project::find()->select(['name', 'id'])->indexBy('id')->column(), + [ + 'id' => 'project_id', + 'prompt' => 'Выберите' + ] + ); ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/backend/modules/task/views/project-task-category/_search.php b/backend/modules/task/views/project-task-category/_search.php new file mode 100644 index 0000000..43a11ae --- /dev/null +++ b/backend/modules/task/views/project-task-category/_search.php @@ -0,0 +1,31 @@ + + + diff --git a/backend/modules/task/views/project-task-category/create.php b/backend/modules/task/views/project-task-category/create.php new file mode 100644 index 0000000..54face3 --- /dev/null +++ b/backend/modules/task/views/project-task-category/create.php @@ -0,0 +1,18 @@ +title = 'Создание категории задач'; +$this->params['breadcrumbs'][] = ['label' => 'Project Task Categories', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/task/views/project-task-category/index.php b/backend/modules/task/views/project-task-category/index.php new file mode 100644 index 0000000..0ebf8ad --- /dev/null +++ b/backend/modules/task/views/project-task-category/index.php @@ -0,0 +1,51 @@ +title = 'Категории задач проекта'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'title', + [ + 'attribute' => 'project_id', + 'value' => 'project.name', + 'filter' => Select2::widget([ + 'model' => $searchModel, + 'attribute' => 'project_id', + 'data' => Project::find()->select(['project.name', 'project.id']) + ->indexBy('project.id')->column(), + 'pluginOptions' => [ + 'allowClear' => true, + ], + 'options' => [ + 'class' => 'form-control', + 'placeholder' => 'Выберите значение' + ], + ]) + ], + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/backend/modules/task/views/project-task-category/update.php b/backend/modules/task/views/project-task-category/update.php new file mode 100644 index 0000000..8e02600 --- /dev/null +++ b/backend/modules/task/views/project-task-category/update.php @@ -0,0 +1,21 @@ +title = 'Update Project Task Category: ' . $model->title; +$this->params['breadcrumbs'][] = ['label' => 'Project Task Categories', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/task/views/project-task-category/view.php b/backend/modules/task/views/project-task-category/view.php new file mode 100644 index 0000000..9bb0493 --- /dev/null +++ b/backend/modules/task/views/project-task-category/view.php @@ -0,0 +1,40 @@ +title = $model->title; +$this->params['breadcrumbs'][] = ['label' => 'Project Task Categories', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'title', + [ + 'attribute' => 'project_id', + 'value' => ArrayHelper::getValue($model, 'project.name'), + ], + ], + ]) ?> + +
diff --git a/backend/modules/task/views/task-user/index.php b/backend/modules/task/views/task-user/index.php index 7ea484f..bd3f6f7 100644 --- a/backend/modules/task/views/task-user/index.php +++ b/backend/modules/task/views/task-user/index.php @@ -37,7 +37,7 @@ $this->params['breadcrumbs'][] = $this->title; 'model' => $searchModel, 'attribute' => 'task_id', 'data' => ProjectTaskUser::find()->joinWith('task') - ->select(['task.title', 'task.id'])->indexBy('task.id')->column(), + ->select(['project_task.title', 'project_task.id'])->indexBy('project_task.id')->column(), 'pluginOptions' => [ 'allowClear' => true, 'width' => '250px', @@ -55,7 +55,7 @@ $this->params['breadcrumbs'][] = $this->title; 'model' => $searchModel, 'attribute' => 'project_user_id', 'data' => ProjectTaskUser::find()->joinWith('projectUser.card') - ->select(['user_card.fio', 'task_user.id'])->column(), + ->select(['user_card.fio', 'project_task_user.id'])->column(), 'pluginOptions' => [ 'allowClear' => true, 'width' => '250px', diff --git a/backend/views/layouts/left.php b/backend/views/layouts/left.php index bf973f5..f9b39db 100755 --- a/backend/views/layouts/left.php +++ b/backend/views/layouts/left.php @@ -68,6 +68,7 @@ 'items' => [ ['label' => 'Задачи', 'icon' => 'minus', 'url' => ['/task/task'], 'active' => \Yii::$app->controller->id == 'task'], ['label' => 'Исполнители задачи', 'icon' => 'users', 'url' => ['/task/task-user'], 'active' => \Yii::$app->controller->id == 'task-user'], + ['label' => 'Категории задач', 'icon' => 'users', 'url' => ['/task/project-task-category'], 'active' => \Yii::$app->controller->id == 'project-task-category'], ], 'visible' => Yii::$app->user->can('task') ], diff --git a/common/models/ProjectTaskCategory.php b/common/models/ProjectTaskCategory.php new file mode 100644 index 0000000..c2212ee --- /dev/null +++ b/common/models/ProjectTaskCategory.php @@ -0,0 +1,57 @@ + 255], + [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'title' => 'Название', + 'project_id' => 'Проект', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProject() + { + return $this->hasOne(Project::className(), ['id' => 'project_id']); + } +} diff --git a/common/models/ProjectUser.php b/common/models/ProjectUser.php index 6b4bcf8..c753696 100644 --- a/common/models/ProjectUser.php +++ b/common/models/ProjectUser.php @@ -150,4 +150,15 @@ class ProjectUser extends \yii\db\ActiveRecord } } } + + public static function getUsersNotOnProject($project_id): array + { + $usersIdList = ProjectUser::find()->where(['project_id' => $project_id])->select('card_id')->column(); + + $userCards = UserCard::find() + ->where(['not in', 'id', $usersIdList]) + ->andWhere(['not', ['id_user' => null]]) + ->all(); + return ArrayHelper::map($userCards, 'id', 'fio'); + } }