2018-10-11 11:15:09 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace common\models;
|
|
|
|
|
|
|
|
use yii\behaviors\TimestampBehavior;
|
2023-11-21 11:23:38 +03:00
|
|
|
use yii\db\ActiveQuery;
|
2018-10-11 11:15:09 +03:00
|
|
|
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
|
2023-04-20 02:07:19 +03:00
|
|
|
* @property int $owner_id
|
2018-10-11 17:38:49 +03:00
|
|
|
*
|
|
|
|
* @property FieldsValue[] $fieldsValues
|
|
|
|
* @property Company $company
|
2023-10-13 15:44:16 +03:00
|
|
|
* @property User $owner
|
2018-10-11 17:38:49 +03:00
|
|
|
* @property ProjectUser[] $projectUsers
|
2023-10-12 11:34:47 +03:00
|
|
|
* @property Mark[] $mark
|
|
|
|
* @property MarkEntity[] $markEntity
|
2023-11-21 11:23:38 +03:00
|
|
|
* @property ProjectTask[] $projectTask
|
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 [
|
2023-10-13 15:44:16 +03:00
|
|
|
[['name', 'owner_id', 'status'], 'required'],
|
|
|
|
[['owner_id', 'name'], 'unique', 'targetAttribute' => ['owner_id', 'name']],
|
2018-10-11 11:15:09 +03:00
|
|
|
[['description'], 'string'],
|
|
|
|
[['created_at', 'updated_at'], 'safe'],
|
2019-07-02 17:35:39 +03:00
|
|
|
[['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']],
|
2018-10-11 11:15:09 +03:00
|
|
|
[['name'], 'string', 'max' => 255],
|
2018-10-11 17:38:49 +03:00
|
|
|
[['budget'], 'string', 'max' => 100],
|
2023-04-20 02:07:19 +03:00
|
|
|
[['owner_id'], 'integer'],
|
2018-10-11 17:38:49 +03:00
|
|
|
[['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' => 'Дата создания',
|
2019-07-02 17:35:39 +03:00
|
|
|
'status' => 'Статус',
|
2018-10-11 11:15:09 +03:00
|
|
|
'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',
|
2023-04-20 02:07:19 +03:00
|
|
|
'owner_id' => 'Владелец проекта',
|
2018-10-11 11:15:09 +03:00
|
|
|
];
|
|
|
|
}
|
2018-10-11 17:38:49 +03:00
|
|
|
|
2024-02-12 22:56:40 +03:00
|
|
|
/**
|
|
|
|
* @param $insert
|
|
|
|
* @param $changedAttributes
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function afterSave($insert, $changedAttributes): void
|
|
|
|
{
|
|
|
|
if ($insert) {
|
|
|
|
$model = new ProjectUser();
|
|
|
|
$model->user_id = $this->owner_id;
|
|
|
|
$model->project_id = $this->id;
|
|
|
|
$model->status = 1;
|
|
|
|
if ($model->save()) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parent::afterSave($insert, $changedAttributes);
|
|
|
|
}
|
|
|
|
|
2018-10-11 17:38:49 +03:00
|
|
|
/**
|
2023-11-21 11:23:38 +03:00
|
|
|
* @return ActiveQuery
|
2018-10-11 17:38:49 +03:00
|
|
|
*/
|
|
|
|
public function getFieldsValues()
|
|
|
|
{
|
2019-06-27 15:41:58 +03:00
|
|
|
return $this->hasMany(FieldsValueNew::class, ['item_id' => 'id'])->where(['item_type' => FieldsValueNew::TYPE_PROJECT])->with('field');
|
2018-10-11 17:38:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-21 11:23:38 +03:00
|
|
|
* @return ActiveQuery
|
2018-10-11 17:38:49 +03:00
|
|
|
*/
|
|
|
|
public function getCompany()
|
|
|
|
{
|
|
|
|
return $this->hasOne(Company::class, ['id' => 'company_id']);
|
|
|
|
}
|
|
|
|
|
2023-04-20 02:07:19 +03:00
|
|
|
/**
|
2023-11-21 11:23:38 +03:00
|
|
|
* @return ActiveQuery
|
2023-04-25 01:32:15 +03:00
|
|
|
*/
|
|
|
|
public function getColumns()
|
|
|
|
{
|
2023-05-23 02:11:44 +03:00
|
|
|
return $this->hasMany(ProjectColumn::class, ['project_id' => 'id'])
|
|
|
|
->with('tasks')
|
|
|
|
->where(['status' => ProjectColumn::STATUS_ACTIVE])->orderBy('priority');
|
2023-04-25 01:32:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-21 11:23:38 +03:00
|
|
|
* @return ActiveQuery
|
|
|
|
*/
|
|
|
|
public function getProjectTask(): ActiveQuery
|
|
|
|
{
|
|
|
|
return $this->hasMany(ProjectTask::class, ['project_id' => 'id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ActiveQuery
|
2023-04-20 02:07:19 +03:00
|
|
|
*/
|
|
|
|
public function getOwner()
|
|
|
|
{
|
|
|
|
return $this->hasOne(User::class, ['id' => 'owner_id']);
|
|
|
|
}
|
|
|
|
|
2018-11-21 17:02:14 +03:00
|
|
|
/**
|
2023-11-21 11:23:38 +03:00
|
|
|
* @return ActiveQuery
|
2018-11-21 17:02:14 +03:00
|
|
|
*/
|
|
|
|
public function getHh()
|
|
|
|
{
|
|
|
|
return $this->hasOne(Hh::class, ['id' => 'hh_id']);
|
|
|
|
}
|
|
|
|
|
2018-10-11 17:38:49 +03:00
|
|
|
/**
|
2023-11-21 11:23:38 +03:00
|
|
|
* @return ActiveQuery
|
2018-10-11 17:38:49 +03:00
|
|
|
*/
|
|
|
|
public function getProjectUsers()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ProjectUser::class, ['project_id' => 'id']);
|
|
|
|
}
|
2018-12-03 12:10:39 +03:00
|
|
|
|
2023-10-12 11:34:47 +03:00
|
|
|
/**
|
2023-11-21 11:23:38 +03:00
|
|
|
* @return ActiveQuery
|
2023-10-12 11:34:47 +03:00
|
|
|
*/
|
|
|
|
public function getMark()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Mark::class, ['id' => 'mark_id'])
|
|
|
|
->via('markEntity');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-21 11:23:38 +03:00
|
|
|
* @return ActiveQuery
|
2023-10-12 11:34:47 +03:00
|
|
|
*/
|
|
|
|
public function getMarkEntity()
|
|
|
|
{
|
|
|
|
return $this->hasMany(MarkEntity::class, ['entity_id' => 'id'])
|
|
|
|
->where(['entity_type' => Entity::ENTITY_TYPE_PROJECT]);
|
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
}
|
2019-07-02 17:35:39 +03:00
|
|
|
|
|
|
|
public function getStatus0()
|
|
|
|
{
|
|
|
|
return $this->hasOne(Status::class, ['id' => 'status']);
|
|
|
|
}
|
2018-10-11 11:15:09 +03:00
|
|
|
}
|