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

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