diff --git a/backend/modules/project/controllers/ProjectRoleController.php b/backend/modules/project/controllers/ProjectRoleController.php
new file mode 100644
index 0000000..e620245
--- /dev/null
+++ b/backend/modules/project/controllers/ProjectRoleController.php
@@ -0,0 +1,127 @@
+ [
+ 'class' => VerbFilter::className(),
+ 'actions' => [
+ 'delete' => ['POST'],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * Lists all ProjectRole models.
+ * @return mixed
+ */
+ public function actionIndex()
+ {
+ $searchModel = new ProjectRoleSearch();
+ $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
+
+ return $this->render('index', [
+ 'searchModel' => $searchModel,
+ 'dataProvider' => $dataProvider,
+ ]);
+ }
+
+ /**
+ * Displays a single ProjectRole 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 ProjectRole model.
+ * If creation is successful, the browser will be redirected to the 'view' page.
+ * @return mixed
+ */
+ public function actionCreate()
+ {
+ $model = new ProjectRole();
+
+ 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 ProjectRole 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 ProjectRole 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 ProjectRole model based on its primary key value.
+ * If the model is not found, a 404 HTTP exception will be thrown.
+ * @param integer $id
+ * @return ProjectRole the loaded model
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ protected function findModel($id)
+ {
+ if (($model = ProjectRole::findOne($id)) !== null) {
+ return $model;
+ }
+
+ throw new NotFoundHttpException('The requested page does not exist.');
+ }
+}
diff --git a/backend/modules/project/models/ProjectRole.php b/backend/modules/project/models/ProjectRole.php
new file mode 100644
index 0000000..4666069
--- /dev/null
+++ b/backend/modules/project/models/ProjectRole.php
@@ -0,0 +1,7 @@
+ $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/project/models/ProjectUserSearch.php b/backend/modules/project/models/ProjectUserSearch.php
index 631067b..a201f84 100644
--- a/backend/modules/project/models/ProjectUserSearch.php
+++ b/backend/modules/project/models/ProjectUserSearch.php
@@ -4,7 +4,6 @@ namespace backend\modules\project\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
-use backend\modules\project\models\ProjectUser;
/**
* ProjectUserSearch represents the model behind the search form of `backend\modules\project\models\ProjectUser`.
@@ -17,7 +16,7 @@ class ProjectUserSearch extends ProjectUser
public function rules()
{
return [
- [['id', 'project_id', 'user_id', 'card_id'], 'integer'],
+ [['id', 'project_id', 'user_id', 'card_id', 'project_role_id'], 'integer'],
];
}
@@ -61,6 +60,7 @@ class ProjectUserSearch extends ProjectUser
'project_id' => $this->project_id,
'user_id' => $this->user_id,
'card_id' => $this->card_id,
+ 'project_role_id' => $this->project_role_id,
]);
return $dataProvider;
diff --git a/backend/modules/project/views/project-role/_form.php b/backend/modules/project/views/project-role/_form.php
new file mode 100644
index 0000000..7e3ee8d
--- /dev/null
+++ b/backend/modules/project/views/project-role/_form.php
@@ -0,0 +1,23 @@
+
+
+
diff --git a/backend/modules/project/views/project-role/_search.php b/backend/modules/project/views/project-role/_search.php
new file mode 100644
index 0000000..a269286
--- /dev/null
+++ b/backend/modules/project/views/project-role/_search.php
@@ -0,0 +1,29 @@
+
+
+
+
+ ['index'],
+ 'method' => 'get',
+ ]); ?>
+
+ = $form->field($model, 'id') ?>
+
+ = $form->field($model, 'title') ?>
+
+
+ = Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
+ = Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
+
+
+
+
+
diff --git a/backend/modules/project/views/project-role/create.php b/backend/modules/project/views/project-role/create.php
new file mode 100644
index 0000000..29a6fde
--- /dev/null
+++ b/backend/modules/project/views/project-role/create.php
@@ -0,0 +1,18 @@
+title = 'Создать новую роль';
+$this->params['breadcrumbs'][] = ['label' => 'Роли сотрудников на проекте ', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+ = $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+
diff --git a/backend/modules/project/views/project-role/index.php b/backend/modules/project/views/project-role/index.php
new file mode 100644
index 0000000..4f7b13a
--- /dev/null
+++ b/backend/modules/project/views/project-role/index.php
@@ -0,0 +1,30 @@
+title = 'Роли сотрудников на проекте';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
+ = Html::a('Создать роль', ['create'], ['class' => 'btn btn-success']) ?>
+
+
+ = GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'filterModel' => $searchModel,
+ 'columns' => [
+ ['class' => 'yii\grid\SerialColumn'],
+
+ 'title',
+
+ ['class' => 'yii\grid\ActionColumn'],
+ ],
+ ]); ?>
+
diff --git a/backend/modules/project/views/project-role/update.php b/backend/modules/project/views/project-role/update.php
new file mode 100644
index 0000000..9151e91
--- /dev/null
+++ b/backend/modules/project/views/project-role/update.php
@@ -0,0 +1,21 @@
+title = 'Update Project Role: ' . $model->title;
+$this->params['breadcrumbs'][] = ['label' => 'Project Roles', 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
+$this->params['breadcrumbs'][] = 'Update';
+?>
+
+
+
= Html::encode($this->title) ?>
+
+ = $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+
diff --git a/backend/modules/project/views/project-role/view.php b/backend/modules/project/views/project-role/view.php
new file mode 100644
index 0000000..6f8e1da
--- /dev/null
+++ b/backend/modules/project/views/project-role/view.php
@@ -0,0 +1,36 @@
+title = $model->title;
+$this->params['breadcrumbs'][] = ['label' => 'Роли сотрудников на проекте', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+\yii\web\YiiAsset::register($this);
+?>
+
+
+
+ = Html::a('Список', ['index', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
+ = Html::a('Изменить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
+ = Html::a('Удалить', ['delete', 'id' => $model->id], [
+ 'class' => 'btn btn-danger',
+ 'data' => [
+ 'confirm' => 'Are you sure you want to delete this item?',
+ 'method' => 'post',
+ ],
+ ]) ?>
+
+
+ = DetailView::widget([
+ 'model' => $model,
+ 'attributes' => [
+ 'id',
+ 'title',
+ ],
+ ]) ?>
+
+
diff --git a/backend/modules/project/views/project-user/_form_update.php b/backend/modules/project/views/project-user/_form_update.php
index 440d1d5..91f5977 100644
--- a/backend/modules/project/views/project-user/_form_update.php
+++ b/backend/modules/project/views/project-user/_form_update.php
@@ -2,7 +2,8 @@
use backend\modules\card\models\UserCard;
use backend\modules\project\models\Project;
-use common\models\User;
+use backend\modules\project\models\ProjectRole;
+use backend\modules\project\models\ProjectUser;
use kartik\select2\Select2;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
@@ -37,6 +38,23 @@ use yii\widgets\ActiveForm;
]
) ?>
+ = $form->field($model, 'project_role_id')->widget(Select2::className(),
+ [
+ 'data' => ProjectRole::find()->select(['title', 'id'])->indexBy('id')->column(),
+ 'options' => ['placeholder' => '...','class' => 'form-control'],
+ 'pluginOptions' => [
+ 'allowClear' => true,
+ 'multiple' => false,
+ ],
+ ]
+ ) ?>
+
+ = $form->field($model, 'status')->dropDownList(ProjectUser::statusList(),
+ [
+ 'prompt' => 'Выберите'
+ ]
+ ) ?>
+
= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
diff --git a/backend/modules/project/views/project-user/index.php b/backend/modules/project/views/project-user/index.php
index e0f5dee..15f5ed4 100644
--- a/backend/modules/project/views/project-user/index.php
+++ b/backend/modules/project/views/project-user/index.php
@@ -2,6 +2,7 @@
use backend\modules\card\models\UserCard;
use backend\modules\project\models\Project;
+use backend\modules\project\models\ProjectRole;
use common\models\User;
use kartik\select2\Select2;
use yii\helpers\Html;
@@ -79,6 +80,23 @@ $this->params['breadcrumbs'][] = $this->title;
],
])
],
+ [
+ 'attribute' => 'project_role_id',
+ 'value' => 'projectRole.title',
+ 'filter' => Select2::widget([
+ 'model' => $searchModel,
+ 'attribute' => 'project_role_id',
+ 'data' => ProjectRole::find()->select(['title', 'id'])->indexBy('id')->column(),
+ 'pluginOptions' => [
+ 'allowClear' => true,
+ 'width' => '250px',
+ ],
+ 'options' => [
+ 'class' => 'form-control',
+ 'placeholder' => 'Выберите значение'
+ ],
+ ])
+ ],
['class' => 'yii\grid\ActionColumn'],
],
diff --git a/backend/modules/project/views/project-user/view.php b/backend/modules/project/views/project-user/view.php
index 8de549c..d843a66 100644
--- a/backend/modules/project/views/project-user/view.php
+++ b/backend/modules/project/views/project-user/view.php
@@ -43,6 +43,14 @@ YiiAsset::register($this);
'attribute' => 'card_id',
'value' => ArrayHelper::getValue($model, 'card.fio' ),
],
+ [
+ 'attribute' => 'project_role_id',
+ 'value' => ArrayHelper::getValue($model, 'projectRole.title' ),
+ ],
+ [
+ 'attribute' => 'status',
+ 'value' => ArrayHelper::getValue($model->statusList(),$model->status ),
+ ],
],
]) ?>
diff --git a/backend/views/layouts/left.php b/backend/views/layouts/left.php
index defc4e0..cf19730 100755
--- a/backend/views/layouts/left.php
+++ b/backend/views/layouts/left.php
@@ -18,7 +18,8 @@
$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'];
+ $projectItems[] = ['label' => 'Метки проектов', 'icon' => 'tags', 'url' => ['/project/project-mark'], 'active' => \Yii::$app->controller->id == 'project-mark'];
+ $projectItems[] = ['label' => 'Роли на проекте', 'icon' => 'user-o', 'url' => ['/project/project-role'], 'active' => \Yii::$app->controller->id == 'project-role'];
?>
= dmstr\widgets\Menu::widget(
diff --git a/common/models/Project.php b/common/models/Project.php
index 8f59342..ce8b7ab 100755
--- a/common/models/Project.php
+++ b/common/models/Project.php
@@ -2,9 +2,8 @@
namespace common\models;
-use common\classes\Debug;
-use Yii;
use yii\behaviors\TimestampBehavior;
+use yii\db\ActiveQuery;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
@@ -27,6 +26,7 @@ use yii\helpers\ArrayHelper;
* @property ProjectUser[] $projectUsers
* @property Mark[] $mark
* @property MarkEntity[] $markEntity
+ * @property ProjectTask[] $projectTask
*/
class Project extends \yii\db\ActiveRecord
{
@@ -89,7 +89,7 @@ class Project extends \yii\db\ActiveRecord
}
/**
- * @return \yii\db\ActiveQuery
+ * @return ActiveQuery
*/
public function getFieldsValues()
{
@@ -97,7 +97,7 @@ class Project extends \yii\db\ActiveRecord
}
/**
- * @return \yii\db\ActiveQuery
+ * @return ActiveQuery
*/
public function getCompany()
{
@@ -105,7 +105,7 @@ class Project extends \yii\db\ActiveRecord
}
/**
- * @return \yii\db\ActiveQuery
+ * @return ActiveQuery
*/
public function getColumns()
{
@@ -115,7 +115,15 @@ class Project extends \yii\db\ActiveRecord
}
/**
- * @return \yii\db\ActiveQuery
+ * @return ActiveQuery
+ */
+ public function getProjectTask(): ActiveQuery
+ {
+ return $this->hasMany(ProjectTask::class, ['project_id' => 'id']);
+ }
+
+ /**
+ * @return ActiveQuery
*/
public function getOwner()
{
@@ -123,7 +131,7 @@ class Project extends \yii\db\ActiveRecord
}
/**
- * @return \yii\db\ActiveQuery
+ * @return ActiveQuery
*/
public function getHh()
{
@@ -131,7 +139,7 @@ class Project extends \yii\db\ActiveRecord
}
/**
- * @return \yii\db\ActiveQuery
+ * @return ActiveQuery
*/
public function getProjectUsers()
{
@@ -139,7 +147,7 @@ class Project extends \yii\db\ActiveRecord
}
/**
- * @return \yii\db\ActiveQuery
+ * @return ActiveQuery
*/
public function getMark()
{
@@ -148,7 +156,7 @@ class Project extends \yii\db\ActiveRecord
}
/**
- * @return \yii\db\ActiveQuery
+ * @return ActiveQuery
*/
public function getMarkEntity()
{
diff --git a/common/models/ProjectRole.php b/common/models/ProjectRole.php
new file mode 100644
index 0000000..7c32021
--- /dev/null
+++ b/common/models/ProjectRole.php
@@ -0,0 +1,53 @@
+ 255],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'id' => 'ID',
+ 'title' => 'Название роли',
+ ];
+ }
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getProjectUsers()
+ {
+ return $this->hasMany(ProjectUser::className(), ['project_role_id' => 'id']);
+ }
+}
diff --git a/common/models/ProjectTask.php b/common/models/ProjectTask.php
index a3a541f..991a24c 100644
--- a/common/models/ProjectTask.php
+++ b/common/models/ProjectTask.php
@@ -41,6 +41,7 @@ class ProjectTask extends ActiveRecord
const STATUS_DISABLE = 0;
const STATUS_ACTIVE = 1;
const STATUS_ARCHIVE = 2;
+ const STATUS_AT_WORK = 3;
const PRIORITY_LOW = 0;
const PRIORITY_MEDIUM = 1;
@@ -102,7 +103,7 @@ class ProjectTask extends ActiveRecord
['execution_priority', 'in', 'range' => [self::PRIORITY_LOW, self::PRIORITY_MEDIUM, self::PRIORITY_HIGH]],
['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'],
[['title'], 'string', 'max' => 255],
- ['status', 'in', 'range' => [self::STATUS_DISABLE, self::STATUS_ACTIVE, self::STATUS_ARCHIVE]],
+ ['status', 'in', 'range' => [self::STATUS_DISABLE, self::STATUS_ACTIVE, self::STATUS_ARCHIVE, self::STATUS_AT_WORK]],
[['description'], 'string', 'max' => 1500],
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
diff --git a/common/models/ProjectUser.php b/common/models/ProjectUser.php
index c753696..232c782 100644
--- a/common/models/ProjectUser.php
+++ b/common/models/ProjectUser.php
@@ -14,14 +14,28 @@ use yii\helpers\ArrayHelper;
* @property int $card_id
* @property int $project_id
* @property int $user_id
+ * @property int $project_role_id
+ * @property int $status
*
* @property Project $project
* @property UserCard $card
* @property User $user
+ * @property ProjectRole $projectRole
* @property ProjectTaskUser[] $taskUsers
*/
class ProjectUser extends \yii\db\ActiveRecord
{
+ public const STATUS_INACTIVE = 0;
+ public const STATUS_ACTIVE = 1;
+
+ public static function statusList() :array
+ {
+ return [
+ self::STATUS_INACTIVE => 'Не активен',
+ self::STATUS_ACTIVE => 'Активен',
+ ];
+ }
+
/**
* {@inheritdoc}
*/
@@ -39,10 +53,13 @@ class ProjectUser extends \yii\db\ActiveRecord
[['user_id', 'project_id', 'card_id'], 'required'],
['user_id', 'unique', 'targetAttribute' => ['user_id', 'project_id'], 'message'=>'Сотрудник уже назначен на этот проект'],
['card_id', 'unique', 'targetAttribute' => ['card_id', 'project_id'], 'message'=>'Сотрудник уже назначен на этот проект'],
- [['card_id', 'project_id', 'user_id'], 'integer'],
- [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
- [['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id' => 'id']],
- [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
+ [['card_id', 'project_id', 'user_id', 'project_role_id', 'status'], 'integer'],
+ [['status'], 'default', 'value'=> self::STATUS_ACTIVE],
+ ['status', 'in', 'range' => [self::STATUS_INACTIVE, self::STATUS_ACTIVE]],
+ [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::class, 'targetAttribute' => ['project_id' => 'id']],
+ [['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::class, 'targetAttribute' => ['card_id' => 'id']],
+ [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']],
+ [['project_role_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectRole::class, 'targetAttribute' => ['project_role_id' => 'id']],
];
}
@@ -56,6 +73,8 @@ class ProjectUser extends \yii\db\ActiveRecord
'card_id' => 'Карточка',
'project_id' => 'Проект',
'user_id' => 'Сотрудник',
+ 'project_role_id' => 'Роль на проекте',
+ 'status' => 'Статус'
];
}
@@ -64,7 +83,7 @@ class ProjectUser extends \yii\db\ActiveRecord
*/
public function getProject()
{
- return $this->hasOne(Project::className(), ['id' => 'project_id']);
+ return $this->hasOne(Project::class, ['id' => 'project_id']);
}
/**
@@ -72,7 +91,7 @@ class ProjectUser extends \yii\db\ActiveRecord
*/
public function getCard()
{
- return $this->hasOne(UserCard::className(), ['id' => 'card_id']);
+ return $this->hasOne(UserCard::class, ['id' => 'card_id']);
}
/**
@@ -80,7 +99,7 @@ class ProjectUser extends \yii\db\ActiveRecord
*/
public function getUser()
{
- return $this->hasOne(User::className(), ['id' => 'user_id']);
+ return $this->hasOne(User::class, ['id' => 'user_id']);
}
/**
@@ -88,7 +107,7 @@ class ProjectUser extends \yii\db\ActiveRecord
*/
public function getTasks()
{
- return $this->hasMany(ProjectTask::className(), ['project_user_id' => 'id']);
+ return $this->hasMany(ProjectTask::class, ['project_user_id' => 'id']);
}
/**
@@ -96,7 +115,15 @@ class ProjectUser extends \yii\db\ActiveRecord
*/
public function getTasksByProject()
{
- return $this->hasMany(ProjectTask::className(), ['project_id' => 'project_id']);
+ return $this->hasMany(ProjectTask::class, ['project_id' => 'project_id']);
+ }
+
+ /**
+ * @return ActiveQuery
+ */
+ public function getProjectRole(): ActiveQuery
+ {
+ return $this->hasOne(ProjectRole::class, ['id' => 'project_role_id']);
}
/**
@@ -104,7 +131,7 @@ class ProjectUser extends \yii\db\ActiveRecord
*/
public function getTaskUsers()
{
- return $this->hasMany(ProjectTaskUser::className(), ['project_user_id' => 'id']);
+ return $this->hasMany(ProjectTaskUser::class, ['project_user_id' => 'id']);
}
public static function usersByProjectArr($project_id): array
diff --git a/console/migrations/m231120_121208_create_project_role_table.php b/console/migrations/m231120_121208_create_project_role_table.php
new file mode 100644
index 0000000..7d86a86
--- /dev/null
+++ b/console/migrations/m231120_121208_create_project_role_table.php
@@ -0,0 +1,28 @@
+createTable('{{%project_role}}', [
+ 'id' => $this->primaryKey(),
+ 'title' => $this->string(),
+ ]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropTable('{{%project_role}}');
+ }
+}
diff --git a/console/migrations/m231120_122131_add_project_role_id_to_project_user_table.php b/console/migrations/m231120_122131_add_project_role_id_to_project_user_table.php
new file mode 100644
index 0000000..b17aa6c
--- /dev/null
+++ b/console/migrations/m231120_122131_add_project_role_id_to_project_user_table.php
@@ -0,0 +1,38 @@
+addColumn(self::TABLE_NAME, self::TABLE_COLUMN, $this->integer()->defaultValue(null));
+
+ $this->addForeignKey(
+ 'project_role_project_user',
+ self::TABLE_NAME,
+ self::TABLE_COLUMN,
+ 'project_role',
+ 'id'
+ );
+
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropForeignKey('project_role_project_user', self::TABLE_NAME);
+ $this->dropColumn(self::TABLE_NAME, self::TABLE_COLUMN );
+ }
+}
diff --git a/console/migrations/m231120_134302_add_status_column_to_project_user_table.php b/console/migrations/m231120_134302_add_status_column_to_project_user_table.php
new file mode 100644
index 0000000..e86311b
--- /dev/null
+++ b/console/migrations/m231120_134302_add_status_column_to_project_user_table.php
@@ -0,0 +1,27 @@
+addColumn(self::TABLE_NAME, self::TABLE_COLUMN, $this->integer()->defaultValue(null));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropColumn(self::TABLE_NAME, self::TABLE_COLUMN);
+ }
+}
diff --git a/frontend/modules/api/controllers/ProjectController.php b/frontend/modules/api/controllers/ProjectController.php
index 68692f6..a59da02 100644
--- a/frontend/modules/api/controllers/ProjectController.php
+++ b/frontend/modules/api/controllers/ProjectController.php
@@ -7,6 +7,7 @@ use common\models\Status;
use common\models\UseStatus;
use frontend\modules\api\models\Manager;
use frontend\modules\api\models\project\Project;
+use frontend\modules\api\models\project\ProjectStatistic;
use frontend\modules\api\models\project\ProjectUser;
use Yii;
use yii\base\InvalidConfigException;
@@ -501,4 +502,40 @@ class ProjectController extends ApiController
return $project;
}
+
+ /**
+ *
+ * @OA\Get(path="/project/statistic",
+ * summary="Получить статистику проекта",
+ * description="Метод для получения статистики проета",
+ * security={
+ * {"bearerAuth": {}}
+ * },
+ * tags={"TaskManager"},
+ * @OA\Parameter(
+ * name="project_id",
+ * in="query",
+ * required=true,
+ * @OA\Schema(
+ * type="integer",
+ * default=null
+ * )
+ * ),
+ * @OA\Response(
+ * response=200,
+ * description="Возвращает объект статистики проекта",
+ * @OA\MediaType(
+ * mediaType="application/json",
+ * @OA\Schema(ref="#/components/schemas/ProjectStatisticExample"),
+ * ),
+ * ),
+ * )
+ *
+ * @param $project_id
+ * @return array|ActiveRecord|null
+ */
+ public function actionStatistic($project_id): array|ActiveRecord|null
+ {
+ return ProjectStatistic::find()->where(['id' => $project_id])->one();
+ }
}
\ No newline at end of file
diff --git a/frontend/modules/api/models/project/ProjectParticipants.php b/frontend/modules/api/models/project/ProjectParticipants.php
new file mode 100644
index 0000000..3fbe0ed
--- /dev/null
+++ b/frontend/modules/api/models/project/ProjectParticipants.php
@@ -0,0 +1,142 @@
+ function () {
+ return $this->user->userCard->photo ?? '';
+ },
+ 'username' => function () {
+ return $this->card->fio ?? null;
+ },
+ 'email' => function () {
+ return $this->card->email ?? $this->user->email;
+ },
+ 'role' => function () {
+ return $this->projectRole->title ?? null;
+ },
+ 'status' => function () {
+ return $this->status ?? null;
+ },
+ ];
+ }
+}
\ No newline at end of file
diff --git a/frontend/modules/api/models/project/ProjectStatistic.php b/frontend/modules/api/models/project/ProjectStatistic.php
new file mode 100644
index 0000000..e91dd61
--- /dev/null
+++ b/frontend/modules/api/models/project/ProjectStatistic.php
@@ -0,0 +1,139 @@
+ function () {
+ return $this->owner;
+ },
+ 'open_tasks_count'=> function () {
+ return $this->getProjectTask()->where(['status' => ProjectTask::STATUS_ACTIVE])->count();
+ },
+ 'task_on_work_count'=> function () {
+ return $this->getProjectTask()->where(['status' => ProjectTask::STATUS_AT_WORK])->count();
+ },
+ 'closed_task_count'=> function () {
+ return $this->getProjectTask()->where(['status' => ProjectTask::STATUS_ARCHIVE])->count();
+ },
+ 'participants'=> function () {
+ return $this->participants;
+ },
+ ];
+ }
+
+ /**
+ * @return string[]
+ */
+ public function extraFields(): array
+ {
+ return [];
+ }
+
+ /**
+ * @return ActiveQuery
+ */
+ public function getOwner()
+ {
+ return $this->hasOne(ProjectParticipants::class, ['id' => 'owner_id']);
+ }
+
+ /**
+ * @return ActiveQuery
+ */
+ public function getProjectUsers()
+ {
+ return $this->hasMany(ProjectUser::class, ['project_id' => 'id']);
+ }
+
+ public function getLinks(): array
+ {
+ return [
+ Link::REL_SELF => Url::to(['index', 'project_id' => $this->id], true),
+ ];
+ }
+
+ public function getCompany(): ActiveQuery
+ {
+ return $this->hasOne(Company::class, ['id' => 'company_id']);
+ }
+
+ public function getParticipants()
+ {
+ return $this->hasMany(ProjectParticipants::class, ['project_id' => 'id']);
+ }
+}