guild/common/models/UserCard.php

155 lines
3.9 KiB
PHP
Raw Normal View History

2018-10-11 11:15:09 +03:00
<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
2019-07-03 13:55:32 +03:00
use yii\helpers\ArrayHelper;
2018-10-11 11:15:09 +03:00
/**
* This is the model class for table "user_card".
*
* @property int $id
* @property string $fio
* @property string $passport
* @property string $photo
* @property string $email
* @property int $gender
* @property string $dob
* @property int $status
* @property string $created_at
* @property string $updated_at
2018-11-06 11:44:27 +03:00
* @property string $deleted_at
2018-10-11 11:15:09 +03:00
* @property string $resume
2018-10-11 17:38:49 +03:00
* @property string $salary
2018-10-12 14:52:08 +03:00
* @property int $position_id
2018-10-11 11:15:09 +03:00
*
2018-10-12 14:52:08 +03:00
* @property FieldsValue[] $fieldsValues
* @property ProjectUser[] $projectUsers
* @property Position $position
2018-10-11 11:15:09 +03:00
* @property Status $status0
*/
class UserCard extends \yii\db\ActiveRecord
{
const GENDER_M = 0;
const GENDER_W = 1;
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
];
}
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'user_card';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
2018-11-06 11:44:27 +03:00
[['fio', 'status', 'gender'], 'required'],
2018-10-12 14:52:08 +03:00
[['gender', 'status', 'position_id'], 'integer'],
2018-11-06 11:44:27 +03:00
[['dob', 'created_at', 'updated_at', 'deleted_at'], 'safe'],
2018-10-11 11:15:09 +03:00
[['fio', 'passport', 'photo', 'email', 'resume'], 'string', 'max' => 255],
2018-10-11 17:38:49 +03:00
[['salary'], 'string', 'max' => 100],
2018-10-12 14:52:08 +03:00
[['position_id'], 'exist', 'skipOnError' => true, 'targetClass' => Position::class, 'targetAttribute' => ['position_id' => 'id']],
2018-10-11 11:15:09 +03:00
[['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'fio' => 'ФИО',
'passport' => 'Паспорт',
'photo' => 'Фото',
'email' => 'Email',
'gender' => 'Пол',
'dob' => 'Дата рождения',
'status' => 'Статус',
'created_at' => 'Дата создания',
'updated_at' => 'Дата редактирование',
2018-11-06 11:44:27 +03:00
'deleted_at' => 'Дата удаления',
2018-10-11 11:15:09 +03:00
'resume' => 'Резюме',
2018-10-11 17:38:49 +03:00
'salary' => 'Зарплата',
2018-10-12 14:52:08 +03:00
'position_id' => 'Должность',
2018-10-11 11:15:09 +03:00
];
}
2018-10-11 17:38:49 +03:00
/**
* @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_PROFILE])->with('field');
2018-10-11 17:38:49 +03:00
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProjectUsers()
{
return $this->hasMany(ProjectUser::class, ['card_id' => 'id']);
}
2018-10-12 14:52:08 +03:00
/**
* @return \yii\db\ActiveQuery
*/
public function getPosition()
{
return $this->hasOne(Position::class, ['id' => 'position_id']);
}
2018-10-11 11:15:09 +03:00
/**
* @return \yii\db\ActiveQuery
*/
public function getStatus0()
{
return $this->hasOne(Status::class, ['id' => 'status']);
}
public function getGenders()
{
return [
self::GENDER_M => 'Мужчина',
self::GENDER_W => 'Женщина'
];
}
/**
* @return string status text label
*/
public function getGendersText()
{
return $this->genders[$this->gender];
}
2019-07-03 13:55:32 +03:00
public function getSkillValues()
{
return $this->hasMany(CardSkill::class, ['card_id' => 'id'])->with('skill');
}
public static function getNameSkills()
{
return ArrayHelper::map(Skill::find()->all(),'id', 'name');
}
2018-10-11 11:15:09 +03:00
}