guild/common/models/Project.php

133 lines
3.2 KiB
PHP
Raw Normal View History

2018-10-11 11:15:09 +03:00
<?php
namespace common\models;
2018-12-03 12:10:39 +03:00
use common\classes\Debug;
2018-10-11 11:15:09 +03:00
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
2018-12-03 12:10:39 +03:00
use yii\helpers\ArrayHelper;
2018-10-11 11:15:09 +03:00
/**
* This is the model class for table "project".
*
* @property int $id
* @property string $name
* @property string $description
* @property string $created_at
* @property string $updated_at
2018-10-11 17:38:49 +03:00
* @property string $budget
* @property int $company_id
2018-11-21 17:02:14 +03:00
* @property int $hh_id
2018-10-11 17:38:49 +03:00
*
* @property FieldsValue[] $fieldsValues
* @property Company $company
* @property ProjectUser[] $projectUsers
2018-10-11 11:15:09 +03:00
*/
class Project extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'project';
}
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
];
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name'], 'required'],
[['description'], 'string'],
[['created_at', 'updated_at'], 'safe'],
[['name'], 'string', 'max' => 255],
2018-10-11 17:38:49 +03:00
[['budget'], 'string', 'max' => 100],
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
2018-11-21 17:02:14 +03:00
[['hh_id'], 'exist', 'skipOnError' => true, 'targetClass' => Hh::class, 'targetAttribute' => ['hh_id' => 'id']],
2018-10-11 11:15:09 +03:00
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Название',
'description' => 'Описание',
'created_at' => 'Дата создания',
'updated_at' => 'Дата редактирования',
2018-10-11 17:38:49 +03:00
'budget' => 'Бюджет',
'company_id' => 'Компания',
2018-11-21 17:02:14 +03:00
'hh_id' => 'Проект на hh.ru',
2018-10-11 11:15:09 +03:00
];
}
2018-10-11 17:38:49 +03:00
/**
* @return \yii\db\ActiveQuery
*/
public function getFieldsValues()
{
return $this->hasMany(FieldsValue::class, ['project_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCompany()
{
return $this->hasOne(Company::class, ['id' => 'company_id']);
}
2018-11-21 17:02:14 +03:00
/**
* @return \yii\db\ActiveQuery
*/
public function getHh()
{
return $this->hasOne(Hh::class, ['id' => 'hh_id']);
}
2018-10-11 17:38:49 +03:00
/**
* @return \yii\db\ActiveQuery
*/
public function getProjectUsers()
{
return $this->hasMany(ProjectUser::class, ['project_id' => 'id']);
}
2018-12-03 12:10:39 +03:00
/**
* @return array
*/
public static function getList()
{
return ArrayHelper::map(self::find()->all(), 'id', 'name');
}
public static function getListName()
{
return ArrayHelper::map(self::find()->all(), 'name', 'name');
}
public function getUsersNameList()
{
$model = $this->getProjectUsers()->with('card')->all();
return ArrayHelper::getColumn($model, 'card.fio');
}
2018-10-11 11:15:09 +03:00
}