From 8a1f99c7073e91fb38c8a9cd6c0673a898c6e0c0 Mon Sep 17 00:00:00 2001 From: iIronside Date: Mon, 23 Jan 2023 17:50:38 +0300 Subject: [PATCH] add mark to project --- .../controllers/ProjectMarkController.php | 165 ++++++++++++++ .../modules/project/models/ProjectMark.php | 8 + .../project/models/ProjectMarkSearch.php | 67 ++++++ .../project/views/project-mark/_form.php | 58 +++++ .../views/project-mark/_form_update.php | 41 ++++ .../project/views/project-mark/_search.php | 31 +++ .../project/views/project-mark/create.php | 18 ++ .../project/views/project-mark/index.php | 61 +++++ .../project/views/project-mark/update.php | 19 ++ .../project/views/project-mark/view.php | 44 ++++ .../project/views/project-user/_form.php | 8 +- .../settings/controllers/MarkController.php | 127 +++++++++++ backend/modules/settings/models/Mark.php | 8 + .../modules/settings/models/MarkSearch.php | 68 ++++++ backend/modules/settings/views/mark/_form.php | 23 ++ .../modules/settings/views/mark/_search.php | 29 +++ .../modules/settings/views/mark/create.php | 18 ++ backend/modules/settings/views/mark/index.php | 30 +++ .../modules/settings/views/mark/update.php | 19 ++ backend/modules/settings/views/mark/view.php | 36 +++ backend/views/layouts/left.php | 2 + common/models/Mark.php | 53 +++++ common/models/ProjectMark.php | 80 +++++++ console/controllers/RbacController.php | 212 +++++++++++------- .../m230123_084421_create_mark_table.php | 28 +++ ...30123_084629_create_project_mark_table.php | 33 +++ 26 files changed, 1199 insertions(+), 87 deletions(-) create mode 100644 backend/modules/project/controllers/ProjectMarkController.php create mode 100644 backend/modules/project/models/ProjectMark.php create mode 100644 backend/modules/project/models/ProjectMarkSearch.php create mode 100644 backend/modules/project/views/project-mark/_form.php create mode 100644 backend/modules/project/views/project-mark/_form_update.php create mode 100644 backend/modules/project/views/project-mark/_search.php create mode 100644 backend/modules/project/views/project-mark/create.php create mode 100644 backend/modules/project/views/project-mark/index.php create mode 100644 backend/modules/project/views/project-mark/update.php create mode 100644 backend/modules/project/views/project-mark/view.php create mode 100644 backend/modules/settings/controllers/MarkController.php create mode 100644 backend/modules/settings/models/Mark.php create mode 100644 backend/modules/settings/models/MarkSearch.php create mode 100644 backend/modules/settings/views/mark/_form.php create mode 100644 backend/modules/settings/views/mark/_search.php create mode 100644 backend/modules/settings/views/mark/create.php create mode 100644 backend/modules/settings/views/mark/index.php create mode 100644 backend/modules/settings/views/mark/update.php create mode 100644 backend/modules/settings/views/mark/view.php create mode 100644 common/models/Mark.php create mode 100644 common/models/ProjectMark.php create mode 100644 console/migrations/m230123_084421_create_mark_table.php create mode 100644 console/migrations/m230123_084629_create_project_mark_table.php 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/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 8713a51..d540d68 100644 --- a/backend/modules/project/views/project-user/_form.php +++ b/backend/modules/project/views/project-user/_form.php @@ -16,7 +16,7 @@ use yii\widgets\ActiveForm; field($model, 'project_id')->dropDownList( - Project::find()->select(['name', 'id'])->indexBy('id')->column(), + Project::find()->select(['name', 'id'])->indexBy('id')->column(), [ 'id' => 'project-id', 'prompt' => 'Выберите' @@ -29,21 +29,19 @@ use yii\widgets\ActiveForm; 'options' => ['id' => 'card_id'], 'pluginOptions' => [ 'depends' => ['project-id'], - 'placeholder' => 'Выберите', 'url' => Url::to(['/project/project-user/users-not-on-project']) ,'initialize' => false, ], 'type' => DepDrop::TYPE_SELECT2, 'select2Options' => [ - 'hideSearch' => false, 'pluginOptions' => [ + 'placeholder' => 'Вводите фио', 'allowClear' => true, 'closeOnSelect' => false, 'multiple' => true, - 'hideSearch' => false ], - 'showToggleAll' => false, + 'showToggleAll' => true, ], ] ); 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/views/layouts/left.php b/backend/views/layouts/left.php index f9b39db..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')], 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/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/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/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}}'); + } +}