2023-10-24 13:34:23 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace common\models;
|
|
|
|
|
2023-10-25 14:37:29 +03:00
|
|
|
use yii\behaviors\TimestampBehavior;
|
2023-10-24 13:34:23 +03:00
|
|
|
use yii\db\ActiveQuery;
|
2023-10-25 14:37:29 +03:00
|
|
|
use yii\db\Expression;
|
2023-10-24 13:34:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the model class for table "user_tg_bot_token".
|
|
|
|
*
|
|
|
|
* @property int $id
|
|
|
|
* @property int $user_id
|
|
|
|
* @property string $token
|
|
|
|
* @property string $created_at
|
|
|
|
* @property string $updated_at
|
|
|
|
* @property string $expired_at
|
|
|
|
*
|
|
|
|
* @property User $user
|
|
|
|
*/
|
|
|
|
class UserTgBotToken extends \yii\db\ActiveRecord
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public static function tableName()
|
|
|
|
{
|
|
|
|
return 'user_tg_bot_token';
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:37:29 +03:00
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'class' => TimestampBehavior::class,
|
|
|
|
'createdAtAttribute' => 'created_at',
|
|
|
|
'updatedAtAttribute' => 'updated_at',
|
|
|
|
'value' => new Expression('NOW()'),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-10-24 13:34:23 +03:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[['user_id'], 'integer'],
|
|
|
|
[['token'], 'required'],
|
|
|
|
[['created_at', 'updated_at', 'expired_at'], 'safe'],
|
|
|
|
[['token'], 'string', 'max' => 255],
|
|
|
|
[['token'], 'unique'],
|
|
|
|
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function attributeLabels()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => 'ID',
|
|
|
|
'user_id' => 'User ID',
|
|
|
|
'token' => 'Token',
|
|
|
|
'created_at' => 'Created At',
|
|
|
|
'updated_at' => 'Updated At',
|
|
|
|
'expired_at' => 'Expired At',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ActiveQuery
|
|
|
|
*/
|
|
|
|
public function getUser()
|
|
|
|
{
|
|
|
|
return $this->hasOne(User::className(), ['id' => 'user_id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $tokenValue
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function checkExistsByToken(string $tokenValue): bool
|
|
|
|
{
|
|
|
|
return self::find()->where(['token' => $tokenValue])->exists();
|
|
|
|
}
|
|
|
|
}
|