diff --git a/common/models/Company.php b/common/models/Company.php index 00a74b7..f7fe48a 100644 --- a/common/models/Company.php +++ b/common/models/Company.php @@ -3,6 +3,8 @@ namespace common\models; use Yii; +use yii\behaviors\TimestampBehavior; +use yii\db\Expression; /** * This is the model class for table "company". @@ -27,6 +29,18 @@ class Company extends \yii\db\ActiveRecord return 'company'; } + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::class, + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => new Expression('NOW()'), + ], + ]; + } + /** * {@inheritdoc} */ diff --git a/common/models/Project.php b/common/models/Project.php index 2751f00..68eeca1 100644 --- a/common/models/Project.php +++ b/common/models/Project.php @@ -14,6 +14,12 @@ use yii\db\Expression; * @property string $description * @property string $created_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 { @@ -47,6 +53,8 @@ class Project extends \yii\db\ActiveRecord [['description'], 'string'], [['created_at', 'updated_at'], 'safe'], [['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' => 'Описание', 'created_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']); + } } diff --git a/common/models/UserCard.php b/common/models/UserCard.php index c0a3f7c..6efb8e4 100644 --- a/common/models/UserCard.php +++ b/common/models/UserCard.php @@ -20,6 +20,7 @@ use yii\db\Expression; * @property string $created_at * @property string $updated_at * @property string $resume + * @property string $salary * * @property array $genders * @property string $gendersText @@ -62,6 +63,7 @@ class UserCard extends \yii\db\ActiveRecord [['gender'], 'in', 'range' => array_keys($this->genders)], [['dob', 'created_at', 'updated_at'], 'safe'], [['fio', 'passport', 'photo', 'email', 'resume'], 'string', 'max' => 255], + [['salary'], 'string', 'max' => 100], [['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']], ]; } @@ -83,9 +85,26 @@ class UserCard extends \yii\db\ActiveRecord 'created_at' => 'Дата создания', 'updated_at' => 'Дата редактирование', '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 */ diff --git a/console/migrations/m181011_142555_add_column_to_user_card.php b/console/migrations/m181011_142555_add_column_to_user_card.php new file mode 100644 index 0000000..2e906f7 --- /dev/null +++ b/console/migrations/m181011_142555_add_column_to_user_card.php @@ -0,0 +1,42 @@ +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; + } + */ +} diff --git a/console/migrations/m181011_143349_add_column_company_id_to_project_table.php b/console/migrations/m181011_143349_add_column_company_id_to_project_table.php new file mode 100644 index 0000000..7e10f70 --- /dev/null +++ b/console/migrations/m181011_143349_add_column_company_id_to_project_table.php @@ -0,0 +1,51 @@ +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; + } + */ +}