guild/common/models/ProjectColumn.php

135 lines
2.9 KiB
PHP
Raw Normal View History

2023-04-20 02:07:19 +03:00
<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
/**
* This is the model class for table "project_column".
*
* @property int $id
* @property string $title
* @property int $project_id
* @property string $created_at
* @property string $updated_at
* @property int $status
2023-05-11 01:18:40 +03:00
* @property int $priority
2023-04-20 02:07:19 +03:00
*
* @property Project $project
*/
class ProjectColumn extends \yii\db\ActiveRecord
{
const STATUS_ACTIVE = 1;
const STATUS_DISABLE = 0;
2023-04-25 01:32:15 +03:00
2023-04-20 02:07:19 +03:00
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'project_column';
}
2023-04-25 01:32:15 +03:00
/**
* @return string[]
*/
public function fields(): array
{
return [
'id',
'title',
'created_at',
'updated_at',
'project_id',
'status',
2023-05-11 01:18:40 +03:00
'priority',
2023-04-25 01:32:15 +03:00
'tasks',
];
}
/**
* @return string[]
*/
public function extraFields(): array
{
return [];
}
2023-04-20 02:07:19 +03:00
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['title', 'project_id'], 'required'],
2023-05-11 01:18:40 +03:00
[['project_id', 'status', 'priority'], 'integer'],
2023-04-20 02:07:19 +03:00
[['created_at', 'updated_at'], 'safe'],
[['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' => 'Проект',
'created_at' => 'Дата создания',
'updated_at' => 'Дата редактирования',
'status' => 'Статус',
2023-05-11 01:18:40 +03:00
'priority' => 'Приоритет',
2023-04-20 02:07:19 +03:00
];
}
/**
* @return array[]
*/
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
];
}
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::STATUS_ACTIVE => 'Активен',
self::STATUS_DISABLE => 'Выключен'
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProject()
{
return $this->hasOne(Project::className(), ['id' => 'project_id']);
}
2023-04-25 01:32:15 +03:00
/**
* @return \yii\db\ActiveQuery
*/
public function getTasks()
{
return $this->hasMany(ProjectTask::class, ['column_id' => 'id'])
->with('taskUsers')
->where(['status' => ProjectTask::STATUS_ACTIVE])
->orderBy('priority');
2023-04-25 01:32:15 +03:00
}
2023-04-20 02:07:19 +03:00
}