add project statistic to api

This commit is contained in:
iIronside 2023-11-21 11:23:38 +03:00
parent 91607cc99b
commit 75329a8835
24 changed files with 929 additions and 25 deletions

View File

@ -0,0 +1,127 @@
<?php
namespace backend\modules\project\controllers;
use Yii;
use backend\modules\project\models\ProjectRole;
use backend\modules\project\models\ProjectRoleSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* ProjectRoleController implements the CRUD actions for ProjectRole model.
*/
class ProjectRoleController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'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.');
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace backend\modules\project\models;
class ProjectRole extends \common\models\ProjectRole
{
}

View File

@ -0,0 +1,68 @@
<?php
namespace backend\modules\project\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\project\models\ProjectRole;
/**
* ProjectRoleSearch represents the model behind the search form of `backend\modules\project\models\ProjectRole`.
*/
class ProjectRoleSearch extends ProjectRole
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id'], 'integer'],
[['title'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = ProjectRole::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $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;
}
}

View File

@ -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;

View File

@ -0,0 +1,23 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\project\models\ProjectRole */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="project-role-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<div class="form-group">
<?= Html::submitButton('Создать', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,29 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\project\models\ProjectRoleSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="project-role-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'title') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,18 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\project\models\ProjectRole */
$this->title = 'Создать новую роль';
$this->params['breadcrumbs'][] = ['label' => 'Роли сотрудников на проекте ', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="project-role-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,30 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\project\models\ProjectRoleSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Роли сотрудников на проекте';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="project-role-index">
<p>
<?= Html::a('Создать роль', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'title',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>

View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\project\models\ProjectRole */
$this->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';
?>
<div class="project-role-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,36 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model backend\modules\project\models\ProjectRole */
$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Роли сотрудников на проекте', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="project-role-view">
<p>
<?= 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',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'title',
],
]) ?>
</div>

View File

@ -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' => 'Выберите'
]
) ?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div>

View File

@ -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'],
],

View File

@ -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 ),
],
],
]) ?>

View File

@ -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(

View File

@ -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()
{

View File

@ -0,0 +1,53 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "project_role".
*
* @property int $id
* @property string $title
*
* @property ProjectUser[] $projectUsers
*/
class ProjectRole extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'project_role';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['title'], 'string', 'max' => 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']);
}
}

View File

@ -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']],

View File

@ -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

View File

@ -0,0 +1,28 @@
<?php
use yii\db\Migration;
/**
* Handles the creation of table `{{%project_role}}`.
*/
class m231120_121208_create_project_role_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('{{%project_role}}', [
'id' => $this->primaryKey(),
'title' => $this->string(),
]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('{{%project_role}}');
}
}

View File

@ -0,0 +1,38 @@
<?php
use yii\db\Migration;
/**
* Class m231120_122131_add_project_role_id_to_project_user_table
*/
class m231120_122131_add_project_role_id_to_project_user_table extends Migration
{
private const TABLE_NAME = 'project_user';
private const TABLE_COLUMN = 'project_role_id';
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->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 );
}
}

View File

@ -0,0 +1,27 @@
<?php
use yii\db\Migration;
/**
* Handles adding columns to table `{{%project_user}}`.
*/
class m231120_134302_add_status_column_to_project_user_table extends Migration
{
private const TABLE_NAME = 'project_user';
private const TABLE_COLUMN = 'status';
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn(self::TABLE_NAME, self::TABLE_COLUMN, $this->integer()->defaultValue(null));
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn(self::TABLE_NAME, self::TABLE_COLUMN);
}
}

View File

@ -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();
}
}

View File

@ -0,0 +1,142 @@
<?php
namespace frontend\modules\api\models\project;
/**
*
* @OA\Schema(
* schema="ProjectParticipants",
* @OA\Property(
* property="avatar",
* type="string",
* example="/hbfhdb/b4.png",
* description="Ссылка на аватар профиля"
* ),
* @OA\Property(
* property="username",
* type="string",
* example="username",
* description="ФИО пользователя"
* ),
* @OA\Property(
* property="email",
* type="string",
* example="test@email.com",
* description="Email пользователя"
* ),
* @OA\Property(
* property="role",
* type="string",
* example="Разработчик",
* description="Роль пользователя на проекте"
* ),
* @OA\Property(
* property="status",
* type="int",
* example="0",
* description="Статус (0 - не активен, 1 - активен)"
* ),
*)
*
* @OA\Schema(
* schema="ProjectParticipantsExample",
* type="array",
* example={"avatar": "/hbfhdb/b4.png", "username": "username", "email": "test@email.com", "role": "Разработчик", "status": 0},
* @OA\Items(
* type="object",
* @OA\Property(
* property="avatar",
* type="string",
* example="/hbfhdb/b4.png",
* ),
* @OA\Property(
* property="username",
* type="string",
* example="username",
* ),
* @OA\Property(
* property="email",
* type="string",
* example="test@email.com",
* ),
* @OA\Property(
* property="role",
* type="string",
* example="Разработчик",
* ),
* @OA\Property(
* property="status",
* type="int",
* example="0",
* ),
* ),
* )
*
*
*
*
* @OA\Schema(
* schema="ProjectParticipantsExampleArr",
* type="array",
* example={
* {"avatar": "/hbfhdb/b4.png", "username": "username", "email": "test@email.com", "role": "Разработчик", "status": 0},
* {"avatar": "/hbfhdb/b4.png", "username": "username", "email": "test@email.com", "role": "Разработчик", "status": 1},
* },
* @OA\Items(
* type="object",
* @OA\Property(
* property="avatar",
* type="string",
* example="/hbfhdb/b4.png",
* ),
* @OA\Property(
* property="username",
* type="string",
* example="username",
* ),
* @OA\Property(
* property="email",
* type="string",
* example="test@email.com",
* ),
* @OA\Property(
* property="role",
* type="string",
* example="Разработчик",
* ),
* @OA\Property(
* property="status",
* type="int",
* example="0",
* ),
* ),
*)
*
*/
class ProjectParticipants extends ProjectUser
{
/**
* @return string[]
*/
public function fields(): array
{
return [
'avatar' => 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;
},
];
}
}

View File

@ -0,0 +1,139 @@
<?php
namespace frontend\modules\api\models\project;
use frontend\modules\api\models\Company;
use yii\db\ActiveQuery;
use yii\helpers\Url;
use yii\web\Link;
/**
*
* @OA\Schema(
* schema="ProjectStatistic",
* @OA\Property(
* property="creator",
* ref="#/components/schemas/ProjectParticipants",
* ),
* @OA\Property(
* property="open_tasks_count",
* type="int",
* example="10",
* ),
* @OA\Property(
* property="task_on_work_count",
* type="int",
* example="15",
* ),
* @OA\Property(
* property="closed_task_count",
* type="int",
* example="234",
* ),
* @OA\Property(
* property="participants",
* ref="#/components/schemas/ProjectParticipants",
* ),
*)
*
* @OA\Schema(
* schema="ProjectStatisticExample",
* type="array",
* @OA\Items(
* type="object",
* @OA\Property(
* property="creator",
* ref="#/components/schemas/ProjectParticipantsExample",
* ),
* @OA\Property(
* property="open_tasks_count",
* type="int",
* example="10"
* ),
* @OA\Property(
* property="task_on_work_count",
* type="int",
* example="15"
* ),
* @OA\Property(
* property="closed_task_count",
* type="integer",
* example="324"
* ),
* @OA\Property(
* property="participants",
* ref="#/components/schemas/ProjectParticipantsExampleArr",
* ),
* ),
*)
*
*
* @property Company $company
* @property ProjectParticipants $owner
* @property ProjectUser[] $participants
*/
class ProjectStatistic extends \common\models\Project
{
public function fields(): array
{
return [
'creator' => 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']);
}
}