add new fields

This commit is contained in:
king199025 2018-10-11 17:38:49 +03:00
parent 5e2bc02bb5
commit 43557838ac
5 changed files with 160 additions and 0 deletions

View File

@ -3,6 +3,8 @@
namespace common\models; namespace common\models;
use Yii; use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
/** /**
* This is the model class for table "company". * This is the model class for table "company".
@ -27,6 +29,18 @@ class Company extends \yii\db\ActiveRecord
return 'company'; return 'company';
} }
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
];
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -14,6 +14,12 @@ use yii\db\Expression;
* @property string $description * @property string $description
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
* @property string $budget
* @property int $company_id
*
* @property FieldsValue[] $fieldsValues
* @property Company $company
* @property ProjectUser[] $projectUsers
*/ */
class Project extends \yii\db\ActiveRecord class Project extends \yii\db\ActiveRecord
{ {
@ -47,6 +53,8 @@ class Project extends \yii\db\ActiveRecord
[['description'], 'string'], [['description'], 'string'],
[['created_at', 'updated_at'], 'safe'], [['created_at', 'updated_at'], 'safe'],
[['name'], 'string', 'max' => 255], [['name'], 'string', 'max' => 255],
[['budget'], 'string', 'max' => 100],
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
]; ];
} }
@ -61,6 +69,32 @@ class Project extends \yii\db\ActiveRecord
'description' => 'Описание', 'description' => 'Описание',
'created_at' => 'Дата создания', 'created_at' => 'Дата создания',
'updated_at' => 'Дата редактирования', 'updated_at' => 'Дата редактирования',
'budget' => 'Бюджет',
'company_id' => 'Компания',
]; ];
} }
/**
* @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']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProjectUsers()
{
return $this->hasMany(ProjectUser::class, ['project_id' => 'id']);
}
} }

View File

@ -20,6 +20,7 @@ use yii\db\Expression;
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
* @property string $resume * @property string $resume
* @property string $salary
* *
* @property array $genders * @property array $genders
* @property string $gendersText * @property string $gendersText
@ -62,6 +63,7 @@ class UserCard extends \yii\db\ActiveRecord
[['gender'], 'in', 'range' => array_keys($this->genders)], [['gender'], 'in', 'range' => array_keys($this->genders)],
[['dob', 'created_at', 'updated_at'], 'safe'], [['dob', 'created_at', 'updated_at'], 'safe'],
[['fio', 'passport', 'photo', 'email', 'resume'], 'string', 'max' => 255], [['fio', 'passport', 'photo', 'email', 'resume'], 'string', 'max' => 255],
[['salary'], 'string', 'max' => 100],
[['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']], [['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']],
]; ];
} }
@ -83,9 +85,26 @@ class UserCard extends \yii\db\ActiveRecord
'created_at' => 'Дата создания', 'created_at' => 'Дата создания',
'updated_at' => 'Дата редактирование', 'updated_at' => 'Дата редактирование',
'resume' => 'Резюме', 'resume' => 'Резюме',
'salary' => 'Зарплата',
]; ];
} }
/**
* @return \yii\db\ActiveQuery
*/
public function getFieldsValues()
{
return $this->hasMany(FieldsValue::class, ['card_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProjectUsers()
{
return $this->hasMany(ProjectUser::class, ['card_id' => 'id']);
}
/** /**
* @return \yii\db\ActiveQuery * @return \yii\db\ActiveQuery
*/ */

View File

@ -0,0 +1,42 @@
<?php
use yii\db\Migration;
/**
* Class m181011_142555_add_column_to_user_card
*/
class m181011_142555_add_column_to_user_card extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('user_card', 'salary', $this->string(100));
$this->addColumn('project', 'budget', $this->string(100));
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('user_card', 'salary');
$this->dropColumn('project', 'budget');
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m181011_142555_add_column_to_user_card cannot be reverted.\n";
return false;
}
*/
}

View File

@ -0,0 +1,51 @@
<?php
use yii\db\Migration;
/**
* Class m181011_143349_add_column_company_id_to_project_table
*/
class m181011_143349_add_column_company_id_to_project_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('project', 'company_id', $this->integer(11));
$this->addForeignKey(
'project_ibfk_company',
'project',
'company_id',
'company',
'id',
'RESTRICT',
'CASCADE'
);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('project_ibfk_company', 'project');
$this->dropColumn('project', 'company_id');
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m181011_143349_add_column_company_id_to_project_table cannot be reverted.\n";
return false;
}
*/
}