guild/common/models/ProjectColumn.php

129 lines
2.7 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
*
* @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',
'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'],
[['project_id', 'status'], 'integer'],
[['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' => 'Статус',
];
}
/**
* @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');
}
2023-04-20 02:07:19 +03:00
}