2016-04-24 00:14:10 +05:30
|
|
|
<?php
|
|
|
|
namespace common\models;
|
|
|
|
|
|
|
|
use yii\behaviors\TimestampBehavior;
|
|
|
|
use yii\db\ActiveRecord;
|
|
|
|
|
|
|
|
/**
|
2019-07-15 04:29:56 +05:30
|
|
|
* Fields:
|
2016-04-24 00:14:10 +05:30
|
|
|
* @property integer $id
|
|
|
|
* @property string $username
|
|
|
|
* @property integer $account_id
|
|
|
|
* @property integer $applied_in
|
|
|
|
*
|
2019-07-15 04:29:56 +05:30
|
|
|
* Relations:
|
2016-04-24 00:14:10 +05:30
|
|
|
* @property Account $account
|
|
|
|
*
|
2019-07-15 04:29:56 +05:30
|
|
|
* Behaviors:
|
2016-04-24 00:14:10 +05:30
|
|
|
* @mixin TimestampBehavior
|
|
|
|
*/
|
|
|
|
class UsernameHistory extends ActiveRecord {
|
|
|
|
|
|
|
|
public static function tableName() {
|
|
|
|
return '{{%usernames_history}}';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function behaviors() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'class' => TimestampBehavior::class,
|
|
|
|
'createdAtAttribute' => 'applied_in',
|
|
|
|
'updatedAtAttribute' => false,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rules() {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAccount() {
|
|
|
|
return $this->hasOne(Account::class, ['id' => 'account_id']);
|
|
|
|
}
|
|
|
|
|
2016-09-21 13:43:43 +05:30
|
|
|
/**
|
|
|
|
* @param int $afterTime
|
|
|
|
* @return UsernameHistory|null
|
|
|
|
*/
|
2019-02-26 04:56:02 +05:30
|
|
|
public function findNext(int $afterTime = null): ?self {
|
2016-09-21 13:43:43 +05:30
|
|
|
return self::find()
|
|
|
|
->andWhere(['account_id' => $this->account_id])
|
|
|
|
->andWhere(['>', 'applied_in', $afterTime ?: $this->applied_in])
|
|
|
|
->orderBy(['applied_in' => SORT_ASC])
|
|
|
|
->one();
|
|
|
|
}
|
|
|
|
|
2016-04-24 00:14:10 +05:30
|
|
|
}
|