Merge pull request #107 from apuc/update_projects_and_tasks
Update projects and tasks
This commit is contained in:
53
common/models/Mark.php
Normal file
53
common/models/Mark.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "mark".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $title
|
||||
*
|
||||
* @property ProjectMark[] $projectMarks
|
||||
*/
|
||||
class Mark extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'mark';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['title'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'title' => 'Название',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getProjectMarks()
|
||||
{
|
||||
return $this->hasMany(ProjectMark::className(), ['mark_id' => 'id']);
|
||||
}
|
||||
}
|
@ -52,6 +52,7 @@ class Project extends \yii\db\ActiveRecord
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['name', 'unique'],
|
||||
[['name', 'status'], 'required'],
|
||||
[['description'], 'string'],
|
||||
[['created_at', 'updated_at'], 'safe'],
|
||||
|
80
common/models/ProjectMark.php
Normal file
80
common/models/ProjectMark.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "project_mark".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $project_id
|
||||
* @property int $mark_id
|
||||
*
|
||||
* @property Mark $mark
|
||||
* @property Project $project
|
||||
*/
|
||||
class ProjectMark extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'project_mark';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['project_id', 'mark_id'], 'integer'],
|
||||
[['project_id', 'mark_id'], 'required'],
|
||||
[['project_id', 'mark_id'], 'unique', 'targetAttribute' => ['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');
|
||||
}
|
||||
}
|
@ -24,16 +24,16 @@ use yii\helpers\ArrayHelper;
|
||||
* @property Project $project
|
||||
* @property UserCard $card
|
||||
* @property UserCard $cardIdCreator
|
||||
* @property TaskUser[] $taskUsers
|
||||
* @property ProjectTaskUser[] $taskUsers
|
||||
*/
|
||||
class Task extends ActiveRecord
|
||||
class ProjectTask extends ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'task';
|
||||
return 'project_task';
|
||||
}
|
||||
|
||||
public function behaviors()
|
||||
@ -123,7 +123,7 @@ class Task extends ActiveRecord
|
||||
*/
|
||||
public function getTaskUsers()
|
||||
{
|
||||
return $this->hasMany(TaskUser::className(), ['task_id' => 'id']);
|
||||
return $this->hasMany(ProjectTaskUser::className(), ['task_id' => 'id']);
|
||||
}
|
||||
|
||||
public static function usersByTaskArr($task_id): array
|
59
common/models/ProjectTaskCategory.php
Normal file
59
common/models/ProjectTaskCategory.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "project_task_category".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $title
|
||||
* @property int $project_id
|
||||
*
|
||||
* @property Project $project
|
||||
*/
|
||||
class ProjectTaskCategory extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'project_task_category';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['project_id', 'title'], 'required'],
|
||||
[['project_id', 'title'], 'unique', 'targetAttribute' => ['project_id', 'title']],
|
||||
[['project_id'], 'integer'],
|
||||
[['title'], 'string', 'max' => 255],
|
||||
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'title' => 'Название',
|
||||
'project_id' => 'Проект',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getProject()
|
||||
{
|
||||
return $this->hasOne(Project::className(), ['id' => 'project_id']);
|
||||
}
|
||||
}
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\db\ActiveQuery;
|
||||
|
||||
/**
|
||||
@ -14,16 +12,16 @@ use yii\db\ActiveQuery;
|
||||
* @property int $project_user_id
|
||||
*
|
||||
* @property ProjectUser $projectUser
|
||||
* @property Task $task
|
||||
* @property ProjectTask $task
|
||||
*/
|
||||
class TaskUser extends \yii\db\ActiveRecord
|
||||
class ProjectTaskUser extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'task_user';
|
||||
return 'project_task_user';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,7 +33,7 @@ class TaskUser extends \yii\db\ActiveRecord
|
||||
[['task_id', 'project_user_id'], 'required'],
|
||||
['project_user_id', 'unique', 'targetAttribute' => ['task_id', 'project_user_id'], 'message'=>'Уже закреплён(ы) за задачей'],
|
||||
[['project_user_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectUser::className(), 'targetAttribute' => ['project_user_id' => 'id']],
|
||||
[['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => Task::className(), 'targetAttribute' => ['task_id' => 'id']],
|
||||
[['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectTask::className(), 'targetAttribute' => ['task_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
@ -64,6 +62,6 @@ class TaskUser extends \yii\db\ActiveRecord
|
||||
*/
|
||||
public function getTask()
|
||||
{
|
||||
return $this->hasOne(Task::className(), ['id' => 'task_id']);
|
||||
return $this->hasOne(ProjectTask::className(), ['id' => 'task_id']);
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ use yii\helpers\ArrayHelper;
|
||||
* @property Project $project
|
||||
* @property UserCard $card
|
||||
* @property User $user
|
||||
* @property TaskUser[] $taskUsers
|
||||
* @property ProjectTaskUser[] $taskUsers
|
||||
*/
|
||||
class ProjectUser extends \yii\db\ActiveRecord
|
||||
{
|
||||
@ -88,7 +88,7 @@ class ProjectUser extends \yii\db\ActiveRecord
|
||||
*/
|
||||
public function getTasks()
|
||||
{
|
||||
return $this->hasMany(Task::className(), ['project_user_id' => 'id']);
|
||||
return $this->hasMany(ProjectTask::className(), ['project_user_id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,7 +96,7 @@ class ProjectUser extends \yii\db\ActiveRecord
|
||||
*/
|
||||
public function getTasksByProject()
|
||||
{
|
||||
return $this->hasMany(Task::className(), ['project_id' => 'project_id']);
|
||||
return $this->hasMany(ProjectTask::className(), ['project_id' => 'project_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +104,7 @@ class ProjectUser extends \yii\db\ActiveRecord
|
||||
*/
|
||||
public function getTaskUsers()
|
||||
{
|
||||
return $this->hasMany(TaskUser::className(), ['project_user_id' => 'id']);
|
||||
return $this->hasMany(ProjectTaskUser::className(), ['project_user_id' => 'id']);
|
||||
}
|
||||
|
||||
public static function usersByProjectArr($project_id): array
|
||||
@ -150,4 +150,15 @@ class ProjectUser extends \yii\db\ActiveRecord
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getUsersNotOnProject($project_id): array
|
||||
{
|
||||
$usersIdList = ProjectUser::find()->where(['project_id' => $project_id])->select('card_id')->column();
|
||||
|
||||
$userCards = UserCard::find()
|
||||
->where(['not in', 'id', $usersIdList])
|
||||
->andWhere(['not', ['id_user' => null]])
|
||||
->all();
|
||||
return ArrayHelper::map($userCards, 'id', 'fio');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user