diff --git a/backend/modules/project/controllers/ProjectMarkController.php b/backend/modules/project/controllers/ProjectMarkController.php new file mode 100644 index 0000000..9484c88 --- /dev/null +++ b/backend/modules/project/controllers/ProjectMarkController.php @@ -0,0 +1,165 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all ProjectMark models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new ProjectMarkSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single ProjectMark 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 ProjectMark model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $marks = \Yii::$app->request->post('ProjectMark'); + + if (!empty($marks)) { + $mark_id_arr = ArrayHelper::getValue($marks, 'mark_id'); + $project_id = $marks['project_id']; + + foreach ($mark_id_arr as $mark_id) { + $emtModel = new ProjectMark(); + $emtModel->project_id = $project_id; + $emtModel->mark_id = $mark_id; + + if (!$emtModel->save()) { + return $this->render('create', [ + 'model' => $emtModel, + ]); + } + } + return $this->redirect(['index']); + } + + $model = new ProjectMark(); + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing ProjectMark 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 ProjectMark 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 ProjectMark model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return ProjectMark the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = ProjectMark::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + + 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 = ProjectMark::getMarkNotAtProject($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/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/models/Project.php b/backend/modules/project/models/Project.php index c56b7f8..41608de 100755 --- a/backend/modules/project/models/Project.php +++ b/backend/modules/project/models/Project.php @@ -2,12 +2,10 @@ namespace backend\modules\project\models; -use common\classes\Debug; -use common\models\FieldsValue; use common\models\FieldsValueNew; use common\models\ProjectUser; -use yii\helpers\ArrayHelper; use Yii; +use yii\helpers\ArrayHelper; class Project extends \common\models\Project { @@ -59,13 +57,14 @@ class Project extends \common\models\Project public function behaviors() { - return [ - 'log' => [ - 'class' => \common\behaviors\LogBehavior::class, - ] + $behaviors = parent::behaviors(); + $behaviors['log'] = [ + 'class' => \common\behaviors\LogBehavior::class, ]; + return $behaviors; } + public function afterSave($insert, $changedAttributes) { $post = \Yii::$app->request->post('Project'); diff --git a/backend/modules/project/models/ProjectMark.php b/backend/modules/project/models/ProjectMark.php new file mode 100644 index 0000000..817d2ca --- /dev/null +++ b/backend/modules/project/models/ProjectMark.php @@ -0,0 +1,8 @@ + $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, + 'mark_id' => $this->mark_id, + ]); + + return $dataProvider; + } +} diff --git a/backend/modules/project/views/project-mark/_form.php b/backend/modules/project/views/project-mark/_form.php new file mode 100644 index 0000000..60e733c --- /dev/null +++ b/backend/modules/project/views/project-mark/_form.php @@ -0,0 +1,58 @@ + + +
+ + + + field($model, 'project_id')->dropDownList( + Project::find()->select(['name', 'id'])->indexBy('id')->column(), + [ + 'id' => 'project-id', + 'placeholder' => 'Выберите', + 'prompt' => 'Выберите' + ] + ) ?> + + field($model, 'mark_id')->widget(DepDrop::className(), + [ + 'options' => ['id' => 'mark_id'], + 'pluginOptions' => [ + 'depends' => ['project-id'], + 'url' => Url::to(['/project/project-mark/users-not-on-project']) + ,'initialize' => false, + ], + + 'type' => DepDrop::TYPE_SELECT2, + 'select2Options' => [ + 'hideSearch' => false, + 'pluginOptions' => [ + 'placeholder' => 'Вводите название метки', + 'allowClear' => true, + 'closeOnSelect' => false, + 'multiple' => true, + 'hideSearch' => false + ], + 'showToggleAll' => true, + ], + ] + ); + ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/backend/modules/project/views/project-mark/_form_update.php b/backend/modules/project/views/project-mark/_form_update.php new file mode 100644 index 0000000..e7e6af3 --- /dev/null +++ b/backend/modules/project/views/project-mark/_form_update.php @@ -0,0 +1,41 @@ + + +
+ + + + field($model, 'project_id')->dropDownList( + Project::find()->select(['name', 'id'])->indexBy('id')->column(), + [ + 'id' => 'project-id', + 'placeholder' => 'Выберите', + 'prompt' => 'Выберите' + ] + ) ?> + + field($model, 'mark_id')->dropDownList( + Mark::find()->select(['title', 'id']) + ->indexBy('id') + ->column(), + [ + 'placeholder' => 'Выберите', + ] + ) ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/backend/modules/project/views/project-mark/_search.php b/backend/modules/project/views/project-mark/_search.php new file mode 100644 index 0000000..8db608c --- /dev/null +++ b/backend/modules/project/views/project-mark/_search.php @@ -0,0 +1,31 @@ + + + diff --git a/backend/modules/project/views/project-mark/create.php b/backend/modules/project/views/project-mark/create.php new file mode 100644 index 0000000..b6d34a5 --- /dev/null +++ b/backend/modules/project/views/project-mark/create.php @@ -0,0 +1,18 @@ +title = 'Добавление проекту метки'; +$this->params['breadcrumbs'][] = ['label' => 'Project Marks', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/project/views/project-mark/index.php b/backend/modules/project/views/project-mark/index.php new file mode 100644 index 0000000..35c152d --- /dev/null +++ b/backend/modules/project/views/project-mark/index.php @@ -0,0 +1,61 @@ +title = 'Метки проектов'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

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

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + [ + 'attribute' => 'project_id', + 'value' => function($model){ + return $model->project->name; + }, + 'filter' => kartik\select2\Select2::widget([ + 'model' => $searchModel, + 'attribute' => 'project_id', + 'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(), + 'options' => ['placeholder' => 'Начните вводить...','class' => 'form-control'], + 'pluginOptions' => [ + 'allowClear' => true + ], + ]), + ], + [ + 'attribute' => 'mark_id', + 'value' => function($model){ + return $model->mark->title; + }, + 'filter' => kartik\select2\Select2::widget([ + 'model' => $searchModel, + 'attribute' => 'mark_id', + 'data' => Mark::find()->select(['title', 'id'])->indexBy('id')->column(), + 'options' => ['placeholder' => 'Начните вводить...','class' => 'form-control'], + 'pluginOptions' => [ + 'allowClear' => true + ], + ]), + ], + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/backend/modules/project/views/project-mark/update.php b/backend/modules/project/views/project-mark/update.php new file mode 100644 index 0000000..b708116 --- /dev/null +++ b/backend/modules/project/views/project-mark/update.php @@ -0,0 +1,19 @@ +title = 'Изменение метки для проекта: ' . $model->project->name; +$this->params['breadcrumbs'][] = ['label' => 'Project Marks', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ + render('_form_update', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/project/views/project-mark/view.php b/backend/modules/project/views/project-mark/view.php new file mode 100644 index 0000000..ae1462c --- /dev/null +++ b/backend/modules/project/views/project-mark/view.php @@ -0,0 +1,44 @@ +title = 'Проект: ' . $model->project->name . '; Метка: ' . $model->mark->title; +$this->params['breadcrumbs'][] = ['label' => 'Project Marks', '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' => [ + 'id', + [ + 'attribute' => 'project_id', + 'value' => ArrayHelper::getValue($model, 'project.name' ), + ], + [ + 'attribute' => 'mark_id', + 'value' => ArrayHelper::getValue($model, 'mark.title' ), + ] + ], + ]) ?> + +
diff --git a/backend/modules/project/views/project-user/_form.php b/backend/modules/project/views/project-user/_form.php index cd8b064..d540d68 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'], + 'url' => Url::to(['/project/project-user/users-not-on-project']) + ,'initialize' => false, + ], + + 'type' => DepDrop::TYPE_SELECT2, + 'select2Options' => [ + 'pluginOptions' => [ + 'placeholder' => 'Вводите фио', + 'allowClear' => true, + 'closeOnSelect' => false, + 'multiple' => true, + ], + 'showToggleAll' => true, ], ] - ) ?> + ); + echo "

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

"; + ?>
'btn btn-success']) ?> diff --git a/backend/modules/settings/controllers/MarkController.php b/backend/modules/settings/controllers/MarkController.php new file mode 100644 index 0000000..7b4362f --- /dev/null +++ b/backend/modules/settings/controllers/MarkController.php @@ -0,0 +1,127 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Mark models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new MarkSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Mark 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 Mark model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Mark(); + + 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 Mark 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 Mark 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 Mark model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Mark the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Mark::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/backend/modules/settings/models/Mark.php b/backend/modules/settings/models/Mark.php new file mode 100644 index 0000000..96c0766 --- /dev/null +++ b/backend/modules/settings/models/Mark.php @@ -0,0 +1,8 @@ + $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, + ]); + + $query->andFilterWhere(['like', 'title', $this->title]); + + return $dataProvider; + } +} diff --git a/backend/modules/settings/views/mark/_form.php b/backend/modules/settings/views/mark/_form.php new file mode 100644 index 0000000..ef68109 --- /dev/null +++ b/backend/modules/settings/views/mark/_form.php @@ -0,0 +1,23 @@ + + +
+ + + + field($model, 'title')->textInput(['maxlength' => true]) ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/backend/modules/settings/views/mark/_search.php b/backend/modules/settings/views/mark/_search.php new file mode 100644 index 0000000..a83e9bb --- /dev/null +++ b/backend/modules/settings/views/mark/_search.php @@ -0,0 +1,29 @@ + + + diff --git a/backend/modules/settings/views/mark/create.php b/backend/modules/settings/views/mark/create.php new file mode 100644 index 0000000..12b8a40 --- /dev/null +++ b/backend/modules/settings/views/mark/create.php @@ -0,0 +1,18 @@ +title = 'Создание метки'; +$this->params['breadcrumbs'][] = ['label' => 'Marks', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/settings/views/mark/index.php b/backend/modules/settings/views/mark/index.php new file mode 100644 index 0000000..ddbe0f6 --- /dev/null +++ b/backend/modules/settings/views/mark/index.php @@ -0,0 +1,30 @@ +title = 'Метки'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

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

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'title', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/backend/modules/settings/views/mark/update.php b/backend/modules/settings/views/mark/update.php new file mode 100644 index 0000000..62125af --- /dev/null +++ b/backend/modules/settings/views/mark/update.php @@ -0,0 +1,19 @@ +title = 'Изменение метки: ' . $model->title; +$this->params['breadcrumbs'][] = ['label' => 'Marks', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/settings/views/mark/view.php b/backend/modules/settings/views/mark/view.php new file mode 100644 index 0000000..2c525fa --- /dev/null +++ b/backend/modules/settings/views/mark/view.php @@ -0,0 +1,36 @@ +title = $model->title; +$this->params['breadcrumbs'][] = ['label' => 'Marks', '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' => [ + 'id', + 'title', + ], + ]) ?> + +
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/controllers/TaskController.php b/backend/modules/task/controllers/TaskController.php index 6629f55..52e48e2 100644 --- a/backend/modules/task/controllers/TaskController.php +++ b/backend/modules/task/controllers/TaskController.php @@ -3,11 +3,11 @@ namespace backend\modules\task\controllers; use backend\modules\project\models\ProjectUser; -use backend\modules\task\models\TaskUser; +use backend\modules\task\models\ProjectTaskUser; use yii\data\ActiveDataProvider; use yii\web\Response; use Yii; -use backend\modules\task\models\Task; +use backend\modules\task\models\ProjectTask; use backend\modules\task\models\TaskSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; @@ -80,7 +80,7 @@ class TaskController extends Controller */ public function actionCreate() { - $model = new Task(); + $model = new ProjectTask(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); @@ -129,12 +129,12 @@ class TaskController extends Controller * Finds the Task model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id - * @return Task the loaded model + * @return ProjectTask the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { - if (($model = Task::findOne($id)) !== null) { + if (($model = ProjectTask::findOne($id)) !== null) { return $model; } diff --git a/backend/modules/task/controllers/TaskUserController.php b/backend/modules/task/controllers/TaskUserController.php index 7ee8865..47d15f6 100644 --- a/backend/modules/task/controllers/TaskUserController.php +++ b/backend/modules/task/controllers/TaskUserController.php @@ -7,7 +7,7 @@ use yii\base\Model; use yii\helpers\ArrayHelper; use yii\web\Response; use Yii; -use backend\modules\task\models\TaskUser; +use backend\modules\task\models\ProjectTaskUser; use backend\modules\task\models\TaskUserSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; @@ -78,7 +78,7 @@ class TaskUserController extends Controller $project_user_id_arr = ArrayHelper::getValue($post, 'project_user_id'); foreach ($project_user_id_arr as $project_user_id) { - $emtModel = new TaskUser(); + $emtModel = new ProjectTaskUser(); $emtModel->task_id = $post['task_id']; $emtModel->project_user_id = $project_user_id; @@ -99,7 +99,7 @@ class TaskUserController extends Controller } - $model = new TaskUser(); + $model = new ProjectTaskUser(); return $this->render('create', [ 'model' => $model, 'task_id' => $task_id, @@ -156,12 +156,12 @@ class TaskUserController extends Controller * Finds the TaskUser model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id - * @return TaskUser the loaded model + * @return ProjectTaskUser the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { - if (($model = TaskUser::findOne($id)) !== null) { + if (($model = ProjectTaskUser::findOne($id)) !== null) { return $model; } diff --git a/backend/modules/task/models/ProjectTask.php b/backend/modules/task/models/ProjectTask.php new file mode 100644 index 0000000..ad07041 --- /dev/null +++ b/backend/modules/task/models/ProjectTask.php @@ -0,0 +1,8 @@ + $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/models/ProjectTaskUser.php b/backend/modules/task/models/ProjectTaskUser.php new file mode 100644 index 0000000..11728d9 --- /dev/null +++ b/backend/modules/task/models/ProjectTaskUser.php @@ -0,0 +1,8 @@ +joinWith(['user_card', 'project']); + $query = ProjectTask::find();//->joinWith(['user_card', 'project']); // add conditions that should always apply here diff --git a/backend/modules/task/models/TaskUser.php b/backend/modules/task/models/TaskUser.php deleted file mode 100644 index 81eb21e..0000000 --- a/backend/modules/task/models/TaskUser.php +++ /dev/null @@ -1,8 +0,0 @@ -joinWith(['task', 'projectUser', 'projectUser.project', 'projectUser.user']); + $query = ProjectTaskUser::find()->joinWith(['task', 'projectUser', 'projectUser.project', 'projectUser.user']); // add conditions that should always apply here 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/_form.php b/backend/modules/task/views/task-user/_form.php index f6484e0..1400066 100644 --- a/backend/modules/task/views/task-user/_form.php +++ b/backend/modules/task/views/task-user/_form.php @@ -1,6 +1,6 @@ @@ -18,7 +18,7 @@ use yii\widgets\ActiveForm; field($model, 'task_id')->widget(Select2::className(),[ - 'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(), + 'data' => ProjectTask::find()->select(['title', 'id'])->indexBy('id')->column(), 'options' => ['placeholder' => 'Выберите проект', 'value' => $task_id, 'id' => 'task-id',], 'pluginOptions' => [ 'allowClear' => false, diff --git a/backend/modules/task/views/task-user/_form_update.php b/backend/modules/task/views/task-user/_form_update.php index f2fd752..5cc5a9a 100644 --- a/backend/modules/task/views/task-user/_form_update.php +++ b/backend/modules/task/views/task-user/_form_update.php @@ -1,6 +1,6 @@ @@ -18,7 +18,7 @@ use yii\widgets\ActiveForm; field($model, 'task_id')->widget(Select2::className(),[ - 'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(), + 'data' => ProjectTask::find()->select(['title', 'id'])->indexBy('id')->column(), 'options' => ['placeholder' => 'Выберите проект', 'value' => $task_id, 'id' => 'task-id',], 'pluginOptions' => [ 'allowClear' => false, diff --git a/backend/modules/task/views/task-user/create.php b/backend/modules/task/views/task-user/create.php index 18eca3e..8d0411d 100644 --- a/backend/modules/task/views/task-user/create.php +++ b/backend/modules/task/views/task-user/create.php @@ -2,7 +2,7 @@ /* @var $this yii\web\View */ -/* @var $model backend\modules\task\models\TaskUser */ +/* @var $model backend\modules\task\models\ProjectTaskUser */ /* @var $task_id */ $this->title = 'Назначить сотрудника'; diff --git a/backend/modules/task/views/task-user/index.php b/backend/modules/task/views/task-user/index.php index 6aab952..bd3f6f7 100644 --- a/backend/modules/task/views/task-user/index.php +++ b/backend/modules/task/views/task-user/index.php @@ -1,8 +1,8 @@ params['breadcrumbs'][] = $this->title; 'filter' => Select2::widget([ 'model' => $searchModel, 'attribute' => 'task_id', - 'data' => TaskUser::find()->joinWith('task') - ->select(['task.title', 'task.id'])->indexBy('task.id')->column(), + 'data' => ProjectTaskUser::find()->joinWith('task') + ->select(['project_task.title', 'project_task.id'])->indexBy('project_task.id')->column(), 'pluginOptions' => [ 'allowClear' => true, 'width' => '250px', @@ -54,8 +54,8 @@ $this->params['breadcrumbs'][] = $this->title; 'filter' => Select2::widget([ 'model' => $searchModel, 'attribute' => 'project_user_id', - 'data' => TaskUser::find()->joinWith('projectUser.card') - ->select(['user_card.fio', 'task_user.id'])->column(), + 'data' => ProjectTaskUser::find()->joinWith('projectUser.card') + ->select(['user_card.fio', 'project_task_user.id'])->column(), 'pluginOptions' => [ 'allowClear' => true, 'width' => '250px', diff --git a/backend/modules/task/views/task-user/update.php b/backend/modules/task/views/task-user/update.php index 2db4aa9..be3e2e8 100644 --- a/backend/modules/task/views/task-user/update.php +++ b/backend/modules/task/views/task-user/update.php @@ -2,7 +2,7 @@ /* @var $this yii\web\View */ -/* @var $model backend\modules\task\models\TaskUser */ +/* @var $model backend\modules\task\models\ProjectTaskUser */ /* @var $task_id */ $this->title = 'Изменить назначение'; diff --git a/backend/modules/task/views/task-user/view.php b/backend/modules/task/views/task-user/view.php index 79b0f98..fd4fa54 100644 --- a/backend/modules/task/views/task-user/view.php +++ b/backend/modules/task/views/task-user/view.php @@ -5,7 +5,7 @@ use yii\helpers\Html; use yii\widgets\DetailView; /* @var $this yii\web\View */ -/* @var $model backend\modules\task\models\TaskUser */ +/* @var $model backend\modules\task\models\ProjectTaskUser */ $this->title = 'Изменить назначение сотрудника'; $this->params['breadcrumbs'][] = ['label' => 'Task Users', 'url' => ['index']]; diff --git a/backend/modules/task/views/task/_form.php b/backend/modules/task/views/task/_form.php index d61b040..8c47482 100644 --- a/backend/modules/task/views/task/_form.php +++ b/backend/modules/task/views/task/_form.php @@ -8,7 +8,7 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ -/* @var $model backend\modules\task\models\Task */ +/* @var $model backend\modules\task\models\ProjectTask */ /* @var $form yii\widgets\ActiveForm */ ?> diff --git a/backend/modules/task/views/task/create.php b/backend/modules/task/views/task/create.php index 4ee1ea6..2336a86 100644 --- a/backend/modules/task/views/task/create.php +++ b/backend/modules/task/views/task/create.php @@ -1,7 +1,7 @@ title = 'Создать задачу'; $this->params['breadcrumbs'][] = ['label' => 'Tasks', 'url' => ['index']]; diff --git a/backend/modules/task/views/task/index.php b/backend/modules/task/views/task/index.php index 8623242..812c9a5 100644 --- a/backend/modules/task/views/task/index.php +++ b/backend/modules/task/views/task/index.php @@ -3,7 +3,7 @@ use backend\modules\card\models\UserCard; use backend\modules\project\models\Project; use backend\modules\project\models\ProjectUser; -use backend\modules\task\models\Task; +use backend\modules\task\models\ProjectTask; use common\helpers\StatusHelper; use common\models\User; use kartik\select2\Select2; @@ -36,7 +36,7 @@ $this->params['breadcrumbs'][] = $this->title; 'filter' => Select2::widget([ 'model' => $searchModel, 'attribute' => 'project_id', - 'data' => Task::find()->joinWith('project') + 'data' => ProjectTask::find()->joinWith('project') ->select(['project.name', 'project.id'])->indexBy('project.id')->column(), 'pluginOptions' => [ 'allowClear' => true, @@ -55,7 +55,7 @@ $this->params['breadcrumbs'][] = $this->title; 'filter' => Select2::widget([ 'model' => $searchModel, 'attribute' => 'card_id_creator', - 'data' => Task::find()->joinWith('userCardCreator') + 'data' => ProjectTask::find()->joinWith('userCardCreator') ->select(['user_card.fio', 'user_card.id'])->indexBy('user_card.id')->column(), 'pluginOptions' => [ 'allowClear' => true, @@ -73,7 +73,7 @@ $this->params['breadcrumbs'][] = $this->title; 'filter' => Select2::widget([ 'model' => $searchModel, 'attribute' => 'card_id', - 'data' => Task::find()->joinWith('userCard') + 'data' => ProjectTask::find()->joinWith('userCard') ->select(['user_card.fio', 'user_card.id'])->indexBy('user_card.id')->column(), 'pluginOptions' => [ 'allowClear' => true, diff --git a/backend/modules/task/views/task/update.php b/backend/modules/task/views/task/update.php index 305e332..f94878c 100644 --- a/backend/modules/task/views/task/update.php +++ b/backend/modules/task/views/task/update.php @@ -3,7 +3,7 @@ use yii\helpers\Html; /* @var $this yii\web\View */ -/* @var $model backend\modules\task\models\Task */ +/* @var $model backend\modules\task\models\ProjectTask */ $this->title = 'Исполнители задачи: ' . $model->title; $this->params['breadcrumbs'][] = ['label' => 'Tasks', 'url' => ['index']]; diff --git a/backend/modules/task/views/task/view.php b/backend/modules/task/views/task/view.php index 693f824..61c6da6 100644 --- a/backend/modules/task/views/task/view.php +++ b/backend/modules/task/views/task/view.php @@ -8,7 +8,7 @@ use yii\web\YiiAsset; use yii\widgets\DetailView; /* @var $this yii\web\View */ -/* @var $model backend\modules\task\models\Task */ +/* @var $model backend\modules\task\models\ProjectTask */ /* @var $taskDataProvider yii\data\ActiveDataProvider */ $this->title = 'Задача: ' . $model->title; diff --git a/backend/views/layouts/left.php b/backend/views/layouts/left.php index bf973f5..556f5f4 100755 --- a/backend/views/layouts/left.php +++ b/backend/views/layouts/left.php @@ -18,6 +18,7 @@ $projectItems[] = ['label' => $status, 'icon' => 'user', 'url' => ['/project/project?ProjectSearch[status]=' . $key, 'active' => \Yii::$app->controller->id == 'project']]; } $projectItems[] = ['label' => 'Сотрудники на проектах', 'icon' => 'users', 'url' => ['/project/project-user'], 'active' => \Yii::$app->controller->id == 'project-user']; + $projectItems[] = ['label' => 'метки проектов', 'icon' => 'tags', 'url' => ['/project/project-mark'], 'active' => \Yii::$app->controller->id == 'project-mark']; ?> 'Доп. поля', 'icon' => 'file-text-o', 'url' => ['/settings/additional-fields'], 'active' => \Yii::$app->controller->id == 'additional-fields', 'visible' => Yii::$app->user->can('settings')], ['label' => 'Должность', 'icon' => 'spotify', 'url' => ['/settings/position'], 'active' => \Yii::$app->controller->id == 'position', 'visible' => Yii::$app->user->can('settings')], ['label' => 'Навыки', 'icon' => 'flask', 'url' => ['/settings/skill'], 'active' => \Yii::$app->controller->id == 'skill', 'visible' => Yii::$app->user->can('settings/skill')], + ['label' => 'Метки', 'icon' => 'tag', 'url' => ['/settings/mark'], 'active' => \Yii::$app->controller->id == 'mark', 'visible' => Yii::$app->user->can('settings/mark')], ['label' => 'Шаблоны резюме', 'icon' => 'address-card ', 'url' => ['/card/resume-template'], 'active' => \Yii::$app->controller->id == 'resume-template', 'visible' => Yii::$app->user->can('card')], ['label' => 'Шаблоны документов', 'icon' => 'file', 'url' => ['/document/document-template'], 'active' => \Yii::$app->controller->id == 'document-template', 'visible' => Yii::$app->user->can('document')], ['label' => 'Поля документов', 'icon' => 'file-text', 'url' => ['/document/document-field'], 'active' => \Yii::$app->controller->id == 'document-field', 'visible' => Yii::$app->user->can('document')], @@ -68,6 +70,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/Mark.php b/common/models/Mark.php new file mode 100644 index 0000000..8b66053 --- /dev/null +++ b/common/models/Mark.php @@ -0,0 +1,53 @@ + 255], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'title' => 'Название', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProjectMarks() + { + return $this->hasMany(ProjectMark::className(), ['mark_id' => 'id']); + } +} diff --git a/common/models/Project.php b/common/models/Project.php index 9ec01d3..f1c499d 100755 --- a/common/models/Project.php +++ b/common/models/Project.php @@ -52,6 +52,7 @@ class Project extends \yii\db\ActiveRecord public function rules() { return [ + ['name', 'unique'], [['name', 'status'], 'required'], [['description'], 'string'], [['created_at', 'updated_at'], 'safe'], diff --git a/common/models/ProjectMark.php b/common/models/ProjectMark.php new file mode 100644 index 0000000..197f3a6 --- /dev/null +++ b/common/models/ProjectMark.php @@ -0,0 +1,80 @@ + ['project_id', 'mark_id']], + [['mark_id'], 'exist', 'skipOnError' => true, 'targetClass' => Mark::className(), 'targetAttribute' => ['mark_id' => 'id']], + [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'project_id' => 'Проект', + 'mark_id' => 'Метка', + 'title' => 'Название', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getMark() + { + return $this->hasOne(Mark::className(), ['id' => 'mark_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProject() + { + return $this->hasOne(Project::className(), ['id' => 'project_id']); + } + + public static function getMarkNotAtProject($project_id): array + { + $markIdList = ProjectMark::find()->where(['project_id' => $project_id])->select('mark_id')->column(); + + $marks = Mark::find() + ->where(['not in', 'id', $markIdList]) + ->all(); + return ArrayHelper::map($marks, 'id', 'title'); + } +} diff --git a/common/models/Task.php b/common/models/ProjectTask.php similarity index 94% rename from common/models/Task.php rename to common/models/ProjectTask.php index e80ca3d..249cf12 100644 --- a/common/models/Task.php +++ b/common/models/ProjectTask.php @@ -24,16 +24,16 @@ use yii\helpers\ArrayHelper; * @property Project $project * @property UserCard $card * @property UserCard $cardIdCreator - * @property TaskUser[] $taskUsers + * @property ProjectTaskUser[] $taskUsers */ -class Task extends ActiveRecord +class ProjectTask extends ActiveRecord { /** * {@inheritdoc} */ public static function tableName() { - return 'task'; + return 'project_task'; } public function behaviors() @@ -123,7 +123,7 @@ class Task extends ActiveRecord */ public function getTaskUsers() { - return $this->hasMany(TaskUser::className(), ['task_id' => 'id']); + return $this->hasMany(ProjectTaskUser::className(), ['task_id' => 'id']); } public static function usersByTaskArr($task_id): array diff --git a/common/models/ProjectTaskCategory.php b/common/models/ProjectTaskCategory.php new file mode 100644 index 0000000..94475ef --- /dev/null +++ b/common/models/ProjectTaskCategory.php @@ -0,0 +1,59 @@ + ['project_id', 'title']], + [['project_id'], 'integer'], + [['title'], 'string', 'max' => 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/TaskUser.php b/common/models/ProjectTaskUser.php similarity index 82% rename from common/models/TaskUser.php rename to common/models/ProjectTaskUser.php index b276ab4..30cb621 100644 --- a/common/models/TaskUser.php +++ b/common/models/ProjectTaskUser.php @@ -2,8 +2,6 @@ namespace common\models; -use Yii; -use yii\base\InvalidConfigException; use yii\db\ActiveQuery; /** @@ -14,16 +12,16 @@ use yii\db\ActiveQuery; * @property int $project_user_id * * @property ProjectUser $projectUser - * @property Task $task + * @property ProjectTask $task */ -class TaskUser extends \yii\db\ActiveRecord +class ProjectTaskUser extends \yii\db\ActiveRecord { /** * {@inheritdoc} */ public static function tableName() { - return 'task_user'; + return 'project_task_user'; } /** @@ -35,7 +33,7 @@ class TaskUser extends \yii\db\ActiveRecord [['task_id', 'project_user_id'], 'required'], ['project_user_id', 'unique', 'targetAttribute' => ['task_id', 'project_user_id'], 'message'=>'Уже закреплён(ы) за задачей'], [['project_user_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectUser::className(), 'targetAttribute' => ['project_user_id' => 'id']], - [['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => Task::className(), 'targetAttribute' => ['task_id' => 'id']], + [['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectTask::className(), 'targetAttribute' => ['task_id' => 'id']], ]; } @@ -64,6 +62,6 @@ class TaskUser extends \yii\db\ActiveRecord */ public function getTask() { - return $this->hasOne(Task::className(), ['id' => 'task_id']); + return $this->hasOne(ProjectTask::className(), ['id' => 'task_id']); } } diff --git a/common/models/ProjectUser.php b/common/models/ProjectUser.php index 7974f18..c753696 100644 --- a/common/models/ProjectUser.php +++ b/common/models/ProjectUser.php @@ -18,7 +18,7 @@ use yii\helpers\ArrayHelper; * @property Project $project * @property UserCard $card * @property User $user - * @property TaskUser[] $taskUsers + * @property ProjectTaskUser[] $taskUsers */ class ProjectUser extends \yii\db\ActiveRecord { @@ -88,7 +88,7 @@ class ProjectUser extends \yii\db\ActiveRecord */ public function getTasks() { - return $this->hasMany(Task::className(), ['project_user_id' => 'id']); + return $this->hasMany(ProjectTask::className(), ['project_user_id' => 'id']); } /** @@ -96,7 +96,7 @@ class ProjectUser extends \yii\db\ActiveRecord */ public function getTasksByProject() { - return $this->hasMany(Task::className(), ['project_id' => 'project_id']); + return $this->hasMany(ProjectTask::className(), ['project_id' => 'project_id']); } /** @@ -104,7 +104,7 @@ class ProjectUser extends \yii\db\ActiveRecord */ public function getTaskUsers() { - return $this->hasMany(TaskUser::className(), ['project_user_id' => 'id']); + return $this->hasMany(ProjectTaskUser::className(), ['project_user_id' => 'id']); } public static function usersByProjectArr($project_id): array @@ -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'); + } } diff --git a/common/services/TaskService.php b/common/services/TaskService.php index f837a62..bbe373e 100644 --- a/common/services/TaskService.php +++ b/common/services/TaskService.php @@ -2,36 +2,36 @@ namespace common\services; -use common\models\Task; +use common\models\ProjectTask; class TaskService { public static function createTask($taskParams) { - $task = new Task(); + $task = new ProjectTask(); $task->load($taskParams, ''); $task->save(); return $task; } - public static function getTask($task_id): ?Task + public static function getTask($task_id): ?ProjectTask { - return Task::findOne($task_id); + return ProjectTask::findOne($task_id); } public static function getTaskList($task_id): array { - return Task::find()->asArray()->all(); + return ProjectTask::find()->asArray()->all(); } public static function getTaskListByProject($project_id): array { - return Task::find()->where(['project_id' => $project_id])->asArray()->all(); + return ProjectTask::find()->where(['project_id' => $project_id])->asArray()->all(); } - public static function updateTask($task_params): ?Task + public static function updateTask($task_params): ?ProjectTask { - $modelTask = Task::findOne($task_params['task_id']); + $modelTask = ProjectTask::findOne($task_params['task_id']); $modelTask->load($task_params, ''); $modelTask->save(); @@ -41,6 +41,6 @@ class TaskService public static function taskExists($task_id): bool { - return Task::find()->where(['id' => $task_id])->exists(); + return ProjectTask::find()->where(['id' => $task_id])->exists(); } } \ No newline at end of file diff --git a/console/controllers/RbacController.php b/console/controllers/RbacController.php index 33d84e1..e1caf88 100755 --- a/console/controllers/RbacController.php +++ b/console/controllers/RbacController.php @@ -92,106 +92,154 @@ class RbacController extends Controller $admin = $auth->getRole('admin'); $profileEditor = $auth->getRole('profileEditor'); - $test = $auth->createPermission('test'); - $test->description = 'Модуль "Тестовые задания"'; - $auth->add($test); - $auth->addChild($admin, $test); + if(!$auth->getPermission('test')) { + $test = $auth->createPermission('test'); + $test->description = 'Модуль "Тестовые задания"'; + $auth->add($test); + $auth->addChild($admin, $test); + } - $questionnaire = $auth->createPermission('questionnaire'); - $questionnaire->description = 'Модуль "Анкеты": Создание, редактирование анкет, категорий анкет, вопросов, проверка ответов пользователей'; - $auth->add($questionnaire); - $auth->addChild($admin, $questionnaire); + if(!$auth->getPermission('questionnaire')) { + $questionnaire = $auth->createPermission('questionnaire'); + $questionnaire->description = 'Модуль "Анкеты": Создание, редактирование анкет, категорий анкет, вопросов, проверка ответов пользователей'; + $auth->add($questionnaire); + $auth->addChild($admin, $questionnaire); + } - $interview = $auth->createPermission('interview'); - $interview->description = 'Модуль "Запрос интервью"'; - $auth->add($interview); - $auth->addChild($admin, $interview); + if(!$auth->getPermission('interview')) { + $interview = $auth->createPermission('interview'); + $interview->description = 'Модуль "Запрос интервью"'; + $auth->add($interview); + $auth->addChild($admin, $interview); + } - $options = $auth->createPermission('options'); - $options->description = 'Модуль "Опции"'; - $auth->add($options); - $auth->addChild($admin, $options); + if(!$auth->getPermission('options')) { + $options = $auth->createPermission('options'); + $options->description = 'Модуль "Опции"'; + $auth->add($options); + $auth->addChild($admin, $options); + } - $reports = $auth->createPermission('reports'); - $reports->description = 'Модуль "Отчёты"'; - $auth->add($reports); - $auth->addChild($admin, $reports); + if(!$auth->getPermission('reports')) { + $reports = $auth->createPermission('reports'); + $reports->description = 'Модуль "Отчёты"'; + $auth->add($reports); + $auth->addChild($admin, $reports); + } + if(!$auth->getPermission('calendar')) { + $calendar = $auth->createPermission('calendar'); + $calendar->description = 'Модуль "Календарь ДР"'; + $auth->add($calendar); + $auth->addChild($admin, $calendar); + } - $calendar = $auth->createPermission('calendar'); - $calendar->description = 'Модуль "Календарь ДР"'; - $auth->add($calendar); - $auth->addChild($admin, $calendar); + if(!$auth->getPermission('notes')) { + $notes = $auth->createPermission('notes'); + $notes->description = 'Модуль "Заметки"'; + $auth->add($notes); + $auth->addChild($admin, $notes); + } - $notes = $auth->createPermission('notes'); - $notes->description = 'Модуль "Заметки"'; - $auth->add($notes); - $auth->addChild($admin, $notes); + if(!$auth->getPermission('accesses')) { + $accesses = $auth->createPermission('accesses'); + $accesses->description = 'Модуль "Доступы"'; + $auth->add($accesses); + $auth->addChild($admin, $accesses); + } - $accesses = $auth->createPermission('accesses'); - $accesses->description = 'Модуль "Доступы"'; - $auth->add($accesses); - $auth->addChild($admin, $accesses); + if(!$auth->getPermission('achievements')) { + $achievements = $auth->createPermission('achievements'); + $achievements->description = 'Модуль "Достижения"'; + $auth->add($achievements); + $auth->addChild($admin, $achievements); + } - $achievements = $auth->createPermission('achievements'); - $achievements->description = 'Модуль "Достижения"'; - $auth->add($achievements); - $auth->addChild($admin, $achievements); + if(!$auth->getPermission('holiday')) { + $holiday = $auth->createPermission('holiday'); + $holiday->description = 'Модуль "Отпуска"'; + $auth->add($holiday); + $auth->addChild($admin, $holiday); + } + if(!$auth->getPermission('balance')) { + $balance = $auth->createPermission('balance'); + $balance->description = 'Модуль "Баланс"'; + $auth->add($balance); + $auth->addChild($admin, $balance); + } - $holiday = $auth->createPermission('holiday'); - $holiday->description = 'Модуль "Отпуска"'; - $auth->add($holiday); - $auth->addChild($admin, $holiday); + if(!$auth->getPermission('hh')) { + $hh = $auth->createPermission('hh'); + $hh->description = 'Модуль "Hh.ru"'; + $auth->add($hh); + $auth->addChild($admin, $hh); + } - $balance = $auth->createPermission('balance'); - $balance->description = 'Модуль "Баланс"'; - $auth->add($balance); - $auth->addChild($admin, $balance); + if(!$auth->getPermission('company')) { + $company = $auth->createPermission('company'); + $company->description = 'Модуль "Компании"'; + $auth->add($company); + $auth->addChild($admin, $company); + } - $hh = $auth->createPermission('hh'); - $hh->description = 'Модуль "Hh.ru"'; - $auth->add($hh); - $auth->addChild($admin, $hh); + if(!$auth->getPermission('task')) { + $task = $auth->createPermission('task'); + $task->description = 'Модуль "Задачи"'; + $auth->add($task); + $auth->addChild($admin, $task); + } - $company = $auth->createPermission('company'); - $company->description = 'Модуль "Компании"'; - $auth->add($company); - $auth->addChild($admin, $company); + if(!$auth->getPermission('project')) { + $project = $auth->createPermission('project'); + $project->description = 'Модуль "Проекты"'; + $auth->add($project); + $auth->addChild($admin, $project); + } - $task = $auth->createPermission('task'); - $task->description = 'Модуль "Задачи"'; - $auth->add($task); - $auth->addChild($admin, $task); + if(!$auth->getPermission('document')) { + $documents = $auth->createPermission('document'); + $documents->description = 'Модуль "Документы": Создание, редактирование документов, их полей и шаблонов'; + $auth->add($documents); + $auth->addChild($admin, $documents); + } - $project = $auth->createPermission('project'); - $project->description = 'Модуль "Проекты"'; - $auth->add($project); - $auth->addChild($admin, $project); + if(!$auth->getPermission('employee')) { + $employee = $auth->createPermission('employee'); + $employee->description = 'Модуль "Сотрудники"'; + $auth->add($employee); + $auth->addChild($admin, $employee); + } - $documents = $auth->createPermission('document'); - $documents->description = 'Модуль "Документы": Создание, редактирование документов, их полей и шаблонов'; - $auth->add($documents); - $auth->addChild($admin, $documents); + if(!$auth->getPermission('card')) { + $card = $auth->createPermission('card'); + $card->description = 'Модуль "Профили"'; + $auth->add($card); + $auth->addChild($admin, $card); + $auth->addChild($profileEditor, $card); + } - $employee = $auth->createPermission('employee'); - $employee->description = 'Модуль "Сотрудники"'; - $auth->add($employee); - $auth->addChild($admin, $employee); + if(!$auth->getPermission('settings')) { + $settings = $auth->createPermission('settings'); + $settings->description = 'Модуль "Настройки"'; + $auth->add($settings); + $auth->addChild($admin, $settings); + } - $card = $auth->createPermission('card'); - $card->description = 'Модуль "Профили"'; - $auth->add($card); - $auth->addChild($admin, $card); - $auth->addChild($profileEditor, $card); + if(!$auth->getPermission('settings/skill')) { + $skills = $auth->createPermission('settings/skill'); + $skills->description = 'Навыки'; + $auth->add($skills); + $auth->addChild($admin, $skills); + $auth->addChild($profileEditor, $skills); + } - $settings = $auth->createPermission('settings'); - $settings->description = 'Модуль "Настройки"'; - $auth->add($settings); - $auth->addChild($admin, $settings); + if(!$auth->getPermission('settings/mark')) { + $mark = $auth->createPermission('settings/mark'); + $mark->description = 'Метки'; + $auth->add($mark); + $auth->addChild($admin, $mark); + } + + var_dump($auth->getPermission('settings/mark')); - $skills = $auth->createPermission('settings/skill'); - $skills->description = 'Навыки'; - $auth->add($skills); - $auth->addChild($admin, $skills); - $auth->addChild($profileEditor, $skills); } } \ No newline at end of file diff --git a/console/migrations/m230118_120338_rename_task_table_to_project_task.php b/console/migrations/m230118_120338_rename_task_table_to_project_task.php new file mode 100644 index 0000000..d332b25 --- /dev/null +++ b/console/migrations/m230118_120338_rename_task_table_to_project_task.php @@ -0,0 +1,40 @@ +renameTable('task', 'project_task'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->renameTable('project_task', 'task'); + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m230118_120338_rename_task_table_to_project_task cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/console/migrations/m230118_120405_rename_task_user_table_to_project_task_user.php b/console/migrations/m230118_120405_rename_task_user_table_to_project_task_user.php new file mode 100644 index 0000000..b823d2c --- /dev/null +++ b/console/migrations/m230118_120405_rename_task_user_table_to_project_task_user.php @@ -0,0 +1,40 @@ +renameTable('task_user', 'project_task_user'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->renameTable('project_task_user', 'task_user'); + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m230118_120405_rename_task_user_table_to_project_task_user cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/console/migrations/m230123_084421_create_mark_table.php b/console/migrations/m230123_084421_create_mark_table.php new file mode 100644 index 0000000..34fac02 --- /dev/null +++ b/console/migrations/m230123_084421_create_mark_table.php @@ -0,0 +1,28 @@ +createTable('{{%mark}}', [ + 'id' => $this->primaryKey(), + 'title' => $this->string() + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('{{%mark}}'); + } +} diff --git a/console/migrations/m230123_084629_create_project_mark_table.php b/console/migrations/m230123_084629_create_project_mark_table.php new file mode 100644 index 0000000..60dd2ed --- /dev/null +++ b/console/migrations/m230123_084629_create_project_mark_table.php @@ -0,0 +1,33 @@ +createTable('{{%project_mark}}', [ + 'id' => $this->primaryKey(), + 'project_id' => $this->integer(), + 'mark_id' => $this->integer(), + ]); + $this->addForeignKey('project_mark_project', 'project_mark', 'project_id', 'project', 'id'); + $this->addForeignKey('project_mark_mark', 'project_mark', 'mark_id', 'mark', 'id'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('project_mark_project', 'project_mark'); + $this->dropForeignKey('project_mark_mark', 'project_mark'); + $this->dropTable('{{%project_mark}}'); + } +} diff --git a/docs/api/projects_and_tasks.md b/docs/api/projects_and_tasks.md new file mode 100644 index 0000000..68c353c --- /dev/null +++ b/docs/api/projects_and_tasks.md @@ -0,0 +1,1189 @@ +## Проекты + +## Методы + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Метод + + Описание +
+ project + + Получить проект +
+ project-list + + Получить список проектов +
+ status-list + + Получить список статусов для проекта +
+ project task category list + + список категорий задач проекта +
+ create project category task + + создать категорию задач проекта +
+ update project category task + + изменить категорию задач проекта +
+ create + + Создать проект +
+ update + + Изменить проект +
+ +### Получить проект +`https://guild.craft-group.xyz/api/project/get-project` +

+ Для получения проекта необходимо отправить GET запрос на URL https://guild.craft-group.xyz/api/project/get-project +

+ +

+ Требуемые параметры: +

+ + + + + + + + + +
+ Параметры + + Значение +
+ project_id + + ID проекта +
+ +

+ Пример запроса: +

+ +`https://guild.craft-group.xyz/api/project/get-project?project_id=1` + +

+ Возвращает объект проекта имеющий такой вид: +

+ +```json5 +{ + "id": 1, + "name": "проект название", + "budget": "333", + "status": 5, + "hh_id": { + "id": 1, + "hh_id": null, + "url": "knkjsefnejkdbvjfdbv", + "title": null, + "dt_add": null, + "photo": null + }, + "company": { + "id": 1, + "name": "Рога и копыта", + "description": "Живодёрня" + }, + "_links": { + "self": { + "href": "http://guild.loc/api/project/index?project_id=1" + } + } +} +``` + +### Получить список проектов +`https://guild.craft-group.xyz/api/project/project-list` +

+ Для получения списка проектов необходимо отправить GET запрос на URL https://guild.craft-group.xyz/api/project/project-list +

+ +

+ Параметры: +

+ + + + + + + + + +
+ Параметры + + Значение +
+ card_id + + ID профиля пользователя (При передаче этого параметра будет возвращён список проектов в которых задействован конкретный пользователь, без него будет возвращён список всех проектов) +
+ +

+ Пример запроса: +

+ +`https://guild.craft-group.xyz/api/project/project-list?card_id=1` + +

+ Возвращает массив объектов проект имеющий такой вид: +

+ +```json5 +{ + "projects": [ + { + "id": 1, + "name": "проект название", + "budget": "333", + "status": 5, + "hh_id": { + "id": 1, + "hh_id": null, + "url": "knkjsefnejkdbvjfdbv", + "title": null, + "dt_add": null, + "photo": null + }, + "company": { + "id": 1, + "name": "Рога и копыта", + "description": "Живодёрня" + }, + "_links": { + "self": { + "href": "http://guild.loc/api/project/index?project_id=1" + } + } + }, + { + "id": 3, + "name": "тестовый проект", + "budget": "333", + "status": 5, + "hh_id": { + "id": 1, + "hh_id": null, + "url": "knkjsefnejkdbvjfdbv", + "title": null, + "dt_add": null, + "photo": null + }, + "company": null, + "_links": { + "self": { + "href": "http://guild.loc/api/project/index?project_id=3" + } + } + } + ], + "_links": { + "self": { + "href": "http://guild.loc/api/project/project-list?card_id=1&page=1" + }, + "first": { + "href": "http://guild.loc/api/project/project-list?card_id=1&page=1" + }, + "last": { + "href": "http://guild.loc/api/project/project-list?card_id=1&page=1" + } + }, + "_meta": { + "totalCount": 2, + "pageCount": 1, + "currentPage": 1, + "perPage": 20 + } +} +``` + +### Получить список статусов для проекта +`https://guild.craft-group.xyz/api/project/status-list` +

+ Для получения списка статусов проекта необходимо отправить GET запрос на URL https://guild.craft-group.xyz/api/project/status-list +

+ +

+ Требуемые параметры: не требуются +

+ +

+ Пример запроса: +

+ +`https://guild.craft-group.xyz/api/project/status-list` + +

+ Возвращает массив объектов статус имеющий такой вид: +

+ +```json5 +[ + { + "id": 5, + "name": "проект" + }, + { + "id": 6, + "name": "проект статус 2" + } +] +``` + +### Список категорий задач проекта +`https://guild.craft-group.xyz/api/project/project-task-category-list` +

+ Для получения списка категорий задач проекта необходимо отправить GET запрос на URL https://guild.craft-group.xyz/api/project/project-task-category-list +

+ +

+ Требуемые параметры: +

+ + + + + + + + + + +
+ Параметры + + Значение +
+ project_id + + ID проекта +
+ +

+ Пример запроса: +

+ +`https://guild.craft-group.xyz/api/project/project-task-category-list?project_id=1` + +

+ Возвращает массив категорий задач проекта имеющий такой вид: +

+ +```json5 +[ + { + "id": 1, + "title": "mlkmld", + "project_id": 1 + }, + { + "id": 2, + "title": "тест", + "project_id": 1 + } +] +``` + +### Создать категорию задач проекта +`https://guild.craft-group.xyz/api/project/create-project-task-category` +

+ Для для создания категории задач проекта необходимо отправить POST запрос на URL https://guild.craft-group.xyz/api/project/create-project-task-category +

+ +

+ Требуемые параметры: +

+ + + + + + + + + + + + + + +
+ Параметры + + Значение +
+ project_id + + ID проекта +
+ title + + название категории +
+ +

+ Пример запроса: +

+ +`https://guild.craft-group.xyz/api/project/create-project-task-category` + +

+ Возвращает категорию задач проекта имеющий такой вид: +

+ +```json5 +{ + "project_id": "1", + "title": "test333", + "id": 4 +} +``` + +### Изменить категорию задач проекта +`https://guild.craft-group.xyz/api/project/update-project-task-category` +

+ Для для создания категории задач проекта необходимо отправить POST запрос на URL https://guild.craft-group.xyz/api/project/update-project-task-category +

+ +

+ Возможные параметры: +

+ + + + + + + + + + + + + + + + + + +
+ Параметры + + Значение +
+ project_id + + ID проекта +
+ title + + название категории +
+ new_title + + новое название категории +
+ +

+ Пример запроса: +

+ +`https://guild.craft-group.xyz/api/project/update-project-task-category` + +

+ Возвращает категорию задач проекта имеющий такой вид: +

+ +```json5 +{ + "id": 1, + "title": "hfbvhdfbv3", + "project_id": 1 +} +``` + +### Создать проект + +`https://guild.craft-group.xyz/api/project/create` + +

+ Для создания нового проекта необходимо отправить POST запрос на URL https://guild.craft-group.xyz/api/project/create +

+ +

+ Параметры: +

+* - обязательные параметры + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Параметры + + Значение +
+ * name + + название проекта +
+ * status + + статус проекта +
+ description + + описание проекта +
+ budget + + бюджет проекта +
+ company_id + + ID компании +
+ $hh_id + + ID hh +
+ +

+ Пример запроса: +

+ +`https://guild.craft-group.xyz/api/project/create` + +

+ Возвращает массив объектов статус имеющий такой вид: +

+ +```json5 +{ + "id": 10, + "name": "test", + "budget": "333", + "status": "5", + "hh_id": null, + "company": null, + "_links": { + "self": { + "href": "http://guild.loc/api/project/index?project_id=10" + } + } +} +``` + +### Обновить проект + +`https://guild.craft-group.xyz/api/project/update` + +

+ Для создания нового проекта необходимо отправить POST запрос на URL https://guild.craft-group.xyz/api/project/update +

+ +

+ Параметры: +

+* - обязательные параметры + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Параметры + + Значение +
+ * project_id + + ID проекта +
+ status + + статус проекта +
+ name + + название +
+ description + + описание проекта +
+ budget + + бюджет проекта +
+ company_id + + ID компании +
+ hh_id + + ID hh +
+ +

+ Пример запроса: +

+ +`https://guild.craft-group.xyz/api/project/update` + +

+ Возвращает массив объектов статус имеющий такой вид: +

+ +```json5 +{ + "id": 7, + "name": "777nnknkfg666", + "budget": "333", + "status": "5", + "hh_id": { + "id": 1, + "hh_id": null, + "url": "knkjsefnejkdbvjfdbv", + "title": null, + "dt_add": null, + "photo": null + }, + "company": { + "id": 1, + "name": "Рога и копыта", + "description": "Живодёрня" + }, + "_links": { + "self": { + "href": "http://guild.loc/api/project/index?project_id=7" + } + } +} +``` + +# Задачи + +## Методы + + + + + + + + + + + + + + + + + + + + + +
+ Метод + + Описание +
+ get-task-list + + Возвращает список задач +
+ get-task + + Возвращает задачу +
+ create-task + + Создаёт задачу +
+ update + + Обновить задачу +
+ +## Список задач + +`https://guild.craft-group.xyz/api/task/get-task-list?project_id=1` +

+ Параметры: +

+ + + + + + + + + +
+ Параметры + + Значение +
+ project_id + + Id проекта +
+

+ Без передачи параметра возвращает массив объектов Задача . С параметром project_id, +метод возвращает объекты Задача определённого проекта. +

+ +

+ Возвращает массив объектов Задача.
+ Каждый объект Задача имеет такой вид: +

+ +```json5 +[ + { + "id": "6", + "project_id": "74", + "title": "Название задачи", + "status": "1", + "created_at": "2021-12-20 16:29:39", + "updated_at": "2021-12-20 17:35:04", + "description": "Описание задачи", + "card_id_creator": "1", + "card_id": "3" + }, + '...' +] +``` + +## Получить документ + +`https://guild.craft-group.xyz/api/task/get-task?task_id=15` +

+ Параметры: +

+ + + + + + + + + +
+ Параметры + + Значение +
+ task_id + + Id задачи +
+ +

+ Возвращает объект Задача.
+ Каждый объект Задача имеет такой вид: +

+ +```json5 +{ + "id": 15, + "project_id": 74, + "title": "4324238888", + "status": 1, + "created_at": "2022-01-05 17:37:37", + "updated_at": "2022-01-05 17:46:10", + "description": "888", + "card_id_creator": 1, + "card_id": null +} +``` +

+ Пример ошибки: +

+ +```json5 +{ + "name": "Not Found", + "message": "The task does not exist", + "code": 0, + "status": 404, + "type": "yii\\web\\NotFoundHttpException" +} +``` + +## Создать документ + +`https://guild.craft-group.xyz/api/document/create-document` +

+ Параметры: +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Параметры + + Значение +
+ title + + Название задачи +
+ project_id + + Id проекта +
+ status + + статус задачи +
+ card_id_creator + + Id профиля создателя +
+ card_id + + Id профиля наблюдателя(не обязательный параметр) +
+ description + + Описание +
+ +

+ Создаёт Задача. Требует передачи POST запроса с соответствующими +параметрами +

+ +

+ В случае указания не верных параметров буде возвращена соответствующая ошибка. Пример ошибки: +

+ +```json5 +{ + "name": "Internal Server Error", + "message": "{\"project_id\":[\"\П\р\о\е\к\т is invalid.\"]}", + "code": 0, + "status": 500, + "type": "yii\\web\\ServerErrorHttpException" +} +``` + +## Обновить задачу + +`https://guild.craft-group.xyz/api/task/update` +

+ Параметры: +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Параметры + + Значение +
+ title + + Название задачи +
+ project_id + + Id проекта +
+ status + + статус задачи +
+ card_id_creator + + Id профиля создателя +
+ card_id + + Id профиля наблюдателя(не обязательный параметр) +
+ description + + Описание +
+ +

+ Обновляет объект Задача. Требует передачи POST запроса с соответствующими +параметрами +

+ +

+ В случае указания не верных параметров буде возвращена соответствующая ошибка. Пример ошибки: +

+ +```json5 +{ + "name": "Not Found", + "message": "The task does not exist", + "code": 0, + "status": 404, + "type": "yii\\web\\NotFoundHttpException" +} +``` + +## Исполнители задачи +## Методы + + + + + + + + + + + + + +
+ Метод + + Описание +
+ get-task-users + + Список исплнителей задачи +
+ set-task-users + + Назначить исполнителя на задачу +
+ +### Список исполнителей задачи +`https://guild.craft-group.xyz/api/task-user/get-task-users` +

+ Для получения списка исполнителей необходимо отправить GET запрос на URL https://guild.craft-group.xyz/api/task-user/get-task-users +

+ +

+ Требуемые параметры: +

+ + + + + + + + + +
+ Параметры + + Значение +
+ task_id + + ID задачи +
+ +

+ Пример запроса: +

+ +`https://guild.craft-group.xyz/api/task-user/get-task-users?task_id=10` + +

+ Возвращает массив сотрудников проекта закреплённых за задачей.
+ Каждый ответ имеет такой вид: +

+ +```json5 +[ + { + "id": 5, + "task_id": 10, + "project_user_id": 1 + }, + { + "id": 7, + "task_id": 10, + "project_user_id": 5 + } +] +``` +

+ Параметры объекта Исполнитель: +

+ + + + + + + + + + + + + + + + + +
+ Параметры + + Значение +
+ id + + ID исполнителя задачи(int) +
+ task_id + + ID задачи(int) +
+ project_user_id + + ID сотрудника на проекте(int) +
+

+ Если задача не найдена будет отправлено следующее сообщение: +

+ +```json5 +{ + "name": "Not Found", + "message": "The task does not exist or there are no employees for it", + "code": 0, + "status": 404, + "type": "yii\\web\\NotFoundHttpException" +} +``` +### Назначить сотрудника на задачу +`https://guild.craft-group.xyz/api/task-user/set-task-users` +

+ Для назначения исполнителя необходимо отправить POST запрос на URL https://guild.craft-group.xyz/api/task-user/set-task-user +

+ +

+ Требуемые параметры: +

+ + + + + + + + + + + + + +
+ Параметры + + Значение +
+ task_id + + ID задачи +
+ project_user_id + + ID сотрудника на проекте +
+ +

+ Пример запроса: +

+ +`https://guild.craft-group.xyz/api/task-user/set-task-user` + +

+ Возвращает объект Исполнителя задачи.
+ Каждый ответ имеет такой вид: +

+ +```json5 +{ + "task_id": "10", + "project_user_id": "5", + "id": 8 +} +``` + +

+ Если задача не найдена будет отправлено следующее сообщение: +

+ +```json5 +{ + "name": "Bad Request", + "message": "{\"task_id\":[\"\З\а\д\а\ч\а is invalid.\"]}", + "code": 0, + "status": 400, + "type": "yii\\web\\BadRequestHttpException" +} +``` \ No newline at end of file diff --git a/docs/api/task-user.md b/docs/api/task-user.md deleted file mode 100644 index a21e905..0000000 --- a/docs/api/task-user.md +++ /dev/null @@ -1,200 +0,0 @@ -## Исполнители задачи -## Методы - - - - - - - - - - - - - -
- Метод - - Описание -
- get-task-users - - Список исплнителей задачи -
- set-task-users - - Назначить исполнителя на задачу -
- -### Список исполнителей задачи -`https://guild.craft-group.xyz/api/task-user/get-task-users` -

- Для получения списка исполнителей необходимо отправить GET запрос на URL https://guild.craft-group.xyz/api/task-user/get-task-users -

- -

- Требуемые параметры: -

- - - - - - - - - -
- Параметры - - Значение -
- task_id - - ID задачи -
- -

- Пример запроса: -

- -`https://guild.craft-group.xyz/api/task-user/get-task-users?task_id=10` - -

- Возвращает массив сотрудников проекта закреплённых за задачей.
- Каждый ответ имеет такой вид: -

- -```json5 -[ - { - "id": 5, - "task_id": 10, - "project_user_id": 1 - }, - { - "id": 7, - "task_id": 10, - "project_user_id": 5 - } -] -``` -

- Параметры объекта Исполнитель: -

- - - - - - - - - - - - - - - - - -
- Параметры - - Значение -
- id - - ID исполнителя задачи(int) -
- task_id - - ID задачи(int) -
- project_user_id - - ID сотрудника на проекте(int) -
-

- Если задача не найдена будет отправлено следующее сообщение: -

- -```json5 -{ - "name": "Not Found", - "message": "The task does not exist or there are no employees for it", - "code": 0, - "status": 404, - "type": "yii\\web\\NotFoundHttpException" -} -``` -### Назначить сотрудника на задачу -`https://guild.craft-group.xyz/api/task-user/set-task-users` -

- Для назначения исполнителя необходимо отправить POST запрос на URL https://guild.craft-group.xyz/api/task-user/set-task-user -

- -

- Требуемые параметры: -

- - - - - - - - - - - - - -
- Параметры - - Значение -
- task_id - - ID задачи -
- project_user_id - - ID сотрудника на проекте -
- -

- Пример запроса: -

- -`https://guild.craft-group.xyz/api/task-user/set-task-user` - -

- Возвращает объект Исполнителя задачи.
- Каждый ответ имеет такой вид: -

- -```json5 -{ - "task_id": "10", - "project_user_id": "5", - "id": 8 -} -``` - -

- Если задача не найдена будет отправлено следующее сообщение: -

- -```json5 -{ - "name": "Bad Request", - "message": "{\"task_id\":[\"\З\а\д\а\ч\а is invalid.\"]}", - "code": 0, - "status": 400, - "type": "yii\\web\\BadRequestHttpException" -} -``` \ No newline at end of file diff --git a/docs/api/task.md b/docs/api/task.md deleted file mode 100644 index 2e84803..0000000 --- a/docs/api/task.md +++ /dev/null @@ -1,321 +0,0 @@ -# Задачи - -## Методы - - - - - - - - - - - - - - - - - - - - - -
- Метод - - Описание -
- get-task-list - - Возвращает список задач -
- get-task - - Возвращает задачу -
- create-task - - Создаёт задачу -
- update - - Обновить задачу -
- -## Список задач - -`https://guild.craft-group.xyz/api/task/get-task-list?project_id=1` -

- Параметры: -

- - - - - - - - - -
- Параметры - - Значение -
- project_id - - Id проекта -
-

- Без передачи параметра возвращает массив объектов Задача . С параметром project_id, -метод возвращает объекты Задача определённого проекта. -

- -

- Возвращает массив объектов Задача.
- Каждый объект Задача имеет такой вид: -

- -```json5 -[ - { - "id": "6", - "project_id": "74", - "title": "Название задачи", - "status": "1", - "created_at": "2021-12-20 16:29:39", - "updated_at": "2021-12-20 17:35:04", - "description": "Описание задачи", - "card_id_creator": "1", - "card_id": "3" - }, - '...' -] -``` - -## Получить документ - -`https://guild.craft-group.xyz/api/task/get-task?task_id=15` -

- Параметры: -

- - - - - - - - - -
- Параметры - - Значение -
- task_id - - Id задачи -
- -

- Возвращает объект Задача.
- Каждый объект Задача имеет такой вид: -

- -```json5 -{ - "id": 15, - "project_id": 74, - "title": "4324238888", - "status": 1, - "created_at": "2022-01-05 17:37:37", - "updated_at": "2022-01-05 17:46:10", - "description": "888", - "card_id_creator": 1, - "card_id": null -} -``` -

- Пример ошибки: -

- -```json5 -{ - "name": "Not Found", - "message": "The task does not exist", - "code": 0, - "status": 404, - "type": "yii\\web\\NotFoundHttpException" -} -``` - -## Создать документ - -`https://guild.craft-group.xyz/api/document/create-document` -

- Параметры: -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Параметры - - Значение -
- title - - Название задачи -
- project_id - - Id проекта -
- status - - статус задачи -
- card_id_creator - - Id профиля создателя -
- card_id - - Id профиля наблюдателя(не обязательный параметр) -
- description - - Описание -
- -

- Создаёт Задача. Требует передачи POST запроса с соответствующими -параметрами -

- -

- В случае указания не верных параметров буде возвращена соответствующая ошибка. Пример ошибки: -

- -```json5 -{ - "name": "Internal Server Error", - "message": "{\"project_id\":[\"\П\р\о\е\к\т is invalid.\"]}", - "code": 0, - "status": 500, - "type": "yii\\web\\ServerErrorHttpException" -} -``` - -## Обновить задачу - -`https://guild.craft-group.xyz/api/task/update` -

- Параметры: -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Параметры - - Значение -
- title - - Название задачи -
- project_id - - Id проекта -
- status - - статус задачи -
- card_id_creator - - Id профиля создателя -
- card_id - - Id профиля наблюдателя(не обязательный параметр) -
- description - - Описание -
- -

- Обновляет объект Задача. Требует передачи POST запроса с соответствующими -параметрами -

- -

- В случае указания не верных параметров буде возвращена соответствующая ошибка. Пример ошибки: -

- -```json5 -{ - "name": "Not Found", - "message": "The task does not exist", - "code": 0, - "status": 404, - "type": "yii\\web\\NotFoundHttpException" -} -``` \ No newline at end of file diff --git a/frontend/modules/api/Api.php b/frontend/modules/api/Api.php index df9e98a..a39e878 100755 --- a/frontend/modules/api/Api.php +++ b/frontend/modules/api/Api.php @@ -18,7 +18,5 @@ class Api extends \yii\base\Module public function init() { parent::init(); - - // custom initialization code goes here } } diff --git a/frontend/modules/api/controllers/ProjectController.php b/frontend/modules/api/controllers/ProjectController.php new file mode 100644 index 0000000..73192e6 --- /dev/null +++ b/frontend/modules/api/controllers/ProjectController.php @@ -0,0 +1,133 @@ + 'yii\rest\Serializer', + 'collectionEnvelope' => 'projects', + ]; + + public function behaviors(): array + { + return ArrayHelper::merge(parent::behaviors(), [ + + 'verbs' => [ + 'class' => \yii\filters\VerbFilter::class, + 'actions' => [ + 'get-project' => ['GET', 'OPTIONS'], + 'project-list' => ['GET', 'OPTIONS'], + 'status-list' => ['GET', 'OPTIONS'], + 'project-task-category-list' => ['GET', 'OPTIONS'], + 'create' => ['POST', 'OPTIONS'], + 'update' => ['POST', 'OPTIONS'] + ], + ] + ]); + } + + public function actionGetProject($project_id): ?Project + { + return Project::findOne($project_id); + } + + public function actionProjectList($card_id = null): ActiveDataProvider + { + if (!empty($card_id)) { + $projectIdList = ProjectUser::find()->where(['card_id' => $card_id])->select('project_id')->column(); + $query = Project::find()->where([ 'IN', 'id', $projectIdList]); + } else { + $query = Project::find(); + } + + return new ActiveDataProvider([ + 'query' => $query, + ]); + } + + public function actionStatusList(): array + { + return Status::find() + ->joinWith('useStatuses') + ->where(['`use_status`.`use`' => UseStatus::USE_PROJECT])->all(); + } + + public function actionProjectTaskCategoryList($project_id): array + { + return ProjectTaskCategory::find()->where(['project_id' => $project_id])->all(); + } + + public function actionCreateProjectTaskCategory() + { + $projectTaskCategory = new ProjectTaskCategory(); + $projectTaskCategory->attributes = \yii::$app->request->post(); + + if($projectTaskCategory->validate()) { + $projectTaskCategory->save(false); + return $projectTaskCategory; + } + return $projectTaskCategory->errors; + } + + public function actionUpdateProjectTaskCategory() + { + $projectTaskCategory = ProjectTaskCategory::find() + ->where(['project_id' => Yii::$app->request->post('project_id')]) + ->andWhere(['title' => Yii::$app->request->post('title')]) + ->one(); + + if(empty($projectTaskCategory)) { + throw new NotFoundHttpException('The project not found'); + } + + $projectTaskCategory->title = Yii::$app->request->post('new_title'); + if (!$projectTaskCategory->update() && $projectTaskCategory->hasErrors()) { + return $projectTaskCategory->errors; + } + return $projectTaskCategory; + } + + public function actionCreate() + { + $project = new Project(); + $project->attributes = \yii::$app->request->post(); + + if($project->validate()) { + $project->save(false); + return $project; + } + return $project->errors; + } + + /** + * @throws \Throwable + * @throws \yii\base\InvalidConfigException + * @throws \yii\db\StaleObjectException + * @throws NotFoundHttpException + */ + public function actionUpdate() + { + $project = Project::findOne(Yii::$app->request->post('project_id')); + if(empty($project)) { + throw new NotFoundHttpException('The project not found'); + } + + $project->load(Yii::$app->request->getBodyParams(), ''); + if (!$project->update()) { + return $project->errors; + } + return $project; + } +} \ No newline at end of file diff --git a/frontend/modules/api/controllers/TaskController.php b/frontend/modules/api/controllers/TaskController.php index dd9a3ef..4bd1642 100644 --- a/frontend/modules/api/controllers/TaskController.php +++ b/frontend/modules/api/controllers/TaskController.php @@ -2,7 +2,7 @@ namespace frontend\modules\api\controllers; -use common\models\Task; +use common\models\ProjectTask; use common\services\TaskService; use Yii; use yii\base\InvalidConfigException; @@ -25,7 +25,7 @@ class TaskController extends ApiController * @throws InvalidConfigException * @throws ServerErrorHttpException */ - public function actionCreateTask(): Task + public function actionCreateTask(): ProjectTask { $taskModel = TaskService::createTask(Yii::$app->getRequest()->getBodyParams()); if ($taskModel->errors) { @@ -59,7 +59,7 @@ class TaskController extends ApiController /** * @throws NotFoundHttpException */ - public function actionGetTask($task_id): Task + public function actionGetTask($task_id): ProjectTask { if (empty($task_id) or !is_numeric($task_id)) { throw new NotFoundHttpException('Incorrect task ID'); @@ -78,7 +78,7 @@ class TaskController extends ApiController * @throws ServerErrorHttpException * @throws NotFoundHttpException */ - public function actionUpdate(): ?Task + public function actionUpdate(): ?ProjectTask { $params = Yii::$app->request->getBodyParams(); if (empty ($params['task_id']) or !TaskService::taskExists($params['task_id'])) { diff --git a/frontend/modules/api/controllers/TaskUserController.php b/frontend/modules/api/controllers/TaskUserController.php index 60951a8..066709e 100644 --- a/frontend/modules/api/controllers/TaskUserController.php +++ b/frontend/modules/api/controllers/TaskUserController.php @@ -2,7 +2,7 @@ namespace frontend\modules\api\controllers; -use common\models\TaskUser; +use common\models\ProjectTaskUser; use Yii; use yii\filters\auth\HttpBearerAuth; use yii\rest\Controller; @@ -21,7 +21,7 @@ class TaskUserController extends ApiController public function actionSetTaskUser() { - $taskUserModel = new TaskUser(); + $taskUserModel = new ProjectTaskUser(); $params = Yii::$app->request->post(); $taskUserModel->attributes = $params; @@ -57,6 +57,6 @@ class TaskUserController extends ApiController private function findUsers($project_id): array { - return TaskUser::find()->where(['task_id' => $project_id])->all(); + return ProjectTaskUser::find()->where(['task_id' => $project_id])->all(); } } \ No newline at end of file diff --git a/frontend/modules/api/models/Company.php b/frontend/modules/api/models/Company.php new file mode 100644 index 0000000..c844201 --- /dev/null +++ b/frontend/modules/api/models/Company.php @@ -0,0 +1,20 @@ + function() { + return $this->hh; + }, + 'company' => function() { + return $this->company; + } + ]; + } + + public function extraFields(): array + { + return []; + } + + public function getLinks(): array + { + return [ + Link::REL_SELF => Url::to(['index', 'project_id' => $this->id], true), + ]; + } + + public function getCompany(): ActiveQuery + { + return $this->hasOne(Company::className(), ['id' => 'company_id']); + } +}