new-support.webeffector.ru/common/components/user/models/UserEmployee.php

104 lines
3.6 KiB
PHP
Raw Permalink Normal View History

2024-07-04 06:42:20 +03:00
<?php
namespace common\components\user\models;
use Yii;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use yii\behaviors\AttributeBehavior;
/**
* This is the model class for table "{{%user_employee}}".
*
* @property int $id
* @property int $user_id
* @property string $first_name
* @property string|null $last_name
* @property string|null $middle_name
* @property string|null $full_name
* @property string|null $about
* @property string|null $nick_name
* @property string|null $web
* @property string|null $telegram
* @property int|null $birthday
* @property string|null $avatar
* @property string|null $location
* @property string|null $phone
* @property int|null $test_try_count
* @property int|null $test_result
* @property int|null $test_at
* @property int|null $verified_at
* @property int|null $blocked_at
*
* @property User $user
*/
class UserEmployee extends ActiveRecord
{
public static function tableName(): string
{
return '{{%user_employee}}';
}
public function rules()
{
return [
[['user_id', 'first_name'], 'required'],
[['user_id', 'birthday', 'test_try_count', 'test_result', 'test_at', 'verified_at', 'blocked_at'], 'integer'],
[['first_name', 'last_name', 'middle_name', 'full_name', 'about', 'nick_name', 'web', 'telegram', 'avatar', 'location', 'phone'], 'string', 'max' => 255],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']],
];
}
public function attributeLabels(): array
{
return [
'id' => Yii::t('user', 'ID'),
'user_id' => Yii::t('user', 'Пользователь'),
'first_name' => Yii::t('user', 'Имя'),
'last_name' => Yii::t('user', 'Фамилия'),
'middle_name' => Yii::t('user', 'Отчество'),
'full_name' => Yii::t('user', 'Полное имя'),
'about' => Yii::t('user', ''),
'nick_name' => Yii::t('user', 'Ник'),
'web' => Yii::t('user', 'Соцсеть'),
'telegram' => Yii::t('user', 'Телеграм'),
'birthday' => Yii::t('user', 'День рождения'),
'avatar' => Yii::t('user', 'Аватар'),
'location' => Yii::t('user', 'Локация'),
'phone' => Yii::t('user', 'Телефон'),
'test_try_count' => Yii::t('user', 'Попыток тестирования'),
'test_result' => Yii::t('user', 'Результат тестирования'),
'test_at' => Yii::t('user', 'Дата тестирования'),
'verified_at' => Yii::t('user', 'Аккаунт подтверждён'),
'blocked_at' => Yii::t('user', 'Заблокирован'),
];
}
public function getUser(): ActiveQuery
{
return $this->hasOne(User::class, ['id' => 'user_id']);
}
public function getFullName(): string
{
return implode(' ', [$this->last_name, $this->first_name, $this->middle_name]);
}
// todo refactor all usersTypes
public function behaviors(): array
{
return [
[
'class' => AttributeBehavior::class,
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => 'full_name',
ActiveRecord::EVENT_BEFORE_UPDATE => 'full_name',
],
'value' => function ($event) {
return self::getFullName();
},
],
];
}
}