guild/common/models/Company.php

108 lines
2.5 KiB
PHP
Raw Normal View History

2018-10-11 17:24:47 +03:00
<?php
namespace common\models;
use Yii;
2018-10-11 17:38:49 +03:00
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
2018-10-11 17:24:47 +03:00
/**
* This is the model class for table "company".
*
* @property int $id
* @property string $name
* @property string $description
* @property int $status_id
2018-12-03 12:10:39 +03:00
* @property int $projectId
2018-10-11 17:24:47 +03:00
* @property string $created_at
* @property string $updated_at
*
* @property Status $status
* @property FieldsValue[] $fieldsValues
*/
class Company extends \yii\db\ActiveRecord
{
2018-12-03 12:10:39 +03:00
public $projectId;
2018-10-11 17:24:47 +03:00
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'company';
}
2018-10-11 17:38:49 +03:00
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
];
}
2018-10-11 17:24:47 +03:00
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name'], 'required'],
[['description'], 'string'],
2018-12-03 12:10:39 +03:00
[['status_id', 'projectId'], 'integer'],
2018-10-11 17:24:47 +03:00
[['created_at', 'updated_at'], 'safe'],
[['name'], 'string', 'max' => 255],
[['status_id'], 'exist', 'skipOnError' => true, 'targetClass' => Status::className(), 'targetAttribute' => ['status_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Название',
'description' => 'Описание',
'status_id' => 'Статус',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getStatus()
{
return $this->hasOne(Status::className(), ['id' => 'status_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getFieldsValues()
{
2019-06-27 15:41:58 +03:00
return $this->hasMany(FieldsValueNew::class, ['item_id' => 'id'])->where(['item_type' => FieldsValueNew::TYPE_COMPANY])->with('field');
2018-10-11 17:24:47 +03:00
}
2018-12-03 12:10:39 +03:00
/**
* @return \yii\db\ActiveQuery
*/
public function getStatus0()
{
return $this->hasOne(Status::class, ['id' => 'status']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProject()
{
return $this->hasOne(Project::class, ['company_id' => 'id']);
}
2018-10-11 17:24:47 +03:00
}