cashwarden /
api
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace app\core\models; |
||||
| 4 | |||||
| 5 | use app\core\types\AuthClientType; |
||||
| 6 | use Yii; |
||||
| 7 | use yii\behaviors\TimestampBehavior; |
||||
| 8 | use yiier\helpers\DateHelper; |
||||
| 9 | |||||
| 10 | /** |
||||
| 11 | * This is the model class for table "{{%auth_client}}". |
||||
| 12 | * |
||||
| 13 | * @property int $id |
||||
| 14 | * @property int $user_id |
||||
| 15 | * @property int $type |
||||
| 16 | * @property string $client_id |
||||
| 17 | * @property string|null $client_username |
||||
| 18 | * @property string|null $data |
||||
| 19 | * @property int $status |
||||
| 20 | * @property string|null $created_at |
||||
| 21 | * @property string|null $updated_at |
||||
| 22 | * @property-read User $user |
||||
| 23 | */ |
||||
| 24 | class AuthClient extends \yii\db\ActiveRecord |
||||
| 25 | { |
||||
| 26 | /** |
||||
| 27 | * {@inheritdoc} |
||||
| 28 | */ |
||||
| 29 | public static function tableName() |
||||
| 30 | { |
||||
| 31 | return '{{%auth_client}}'; |
||||
| 32 | } |
||||
| 33 | |||||
| 34 | /** |
||||
| 35 | * @inheritdoc |
||||
| 36 | * @throws \yii\base\InvalidConfigException |
||||
| 37 | */ |
||||
| 38 | public function behaviors() |
||||
| 39 | { |
||||
| 40 | return [ |
||||
| 41 | [ |
||||
| 42 | 'class' => TimestampBehavior::class, |
||||
| 43 | 'value' => Yii::$app->formatter->asDatetime('now') |
||||
| 44 | ], |
||||
| 45 | ]; |
||||
| 46 | } |
||||
| 47 | |||||
| 48 | /** |
||||
| 49 | * {@inheritdoc} |
||||
| 50 | */ |
||||
| 51 | public function rules() |
||||
| 52 | { |
||||
| 53 | return [ |
||||
| 54 | [['user_id', 'type', 'client_id', 'status'], 'required'], |
||||
| 55 | [['user_id', 'type', 'status'], 'integer'], |
||||
| 56 | [['data'], 'string'], |
||||
| 57 | [['created_at', 'updated_at'], 'safe'], |
||||
| 58 | [['client_id', 'client_username'], 'string', 'max' => 255], |
||||
| 59 | [['user_id', 'type'], 'unique', 'targetAttribute' => ['user_id', 'type']], |
||||
| 60 | [['type', 'client_id'], 'unique', 'targetAttribute' => ['type', 'client_id']], |
||||
| 61 | ]; |
||||
| 62 | } |
||||
| 63 | |||||
| 64 | /** |
||||
| 65 | * {@inheritdoc} |
||||
| 66 | */ |
||||
| 67 | public function attributeLabels() |
||||
| 68 | { |
||||
| 69 | return [ |
||||
| 70 | 'id' => Yii::t('app', 'ID'), |
||||
| 71 | 'user_id' => Yii::t('app', 'User ID'), |
||||
| 72 | 'type' => Yii::t('app', 'Type'), |
||||
| 73 | 'client_id' => Yii::t('app', 'Client ID'), |
||||
| 74 | 'client_username' => Yii::t('app', 'Client Username'), |
||||
| 75 | 'data' => Yii::t('app', 'Data'), |
||||
| 76 | 'status' => Yii::t('app', 'Status'), |
||||
| 77 | 'created_at' => Yii::t('app', 'Created At'), |
||||
| 78 | 'updated_at' => Yii::t('app', 'Updated At'), |
||||
| 79 | ]; |
||||
| 80 | } |
||||
| 81 | |||||
| 82 | public function getUser() |
||||
| 83 | { |
||||
| 84 | return $this->hasOne(User::class, ['id' => 'user_id']); |
||||
| 85 | } |
||||
| 86 | |||||
| 87 | /** |
||||
| 88 | * @return array |
||||
| 89 | */ |
||||
| 90 | public function fields() |
||||
| 91 | { |
||||
| 92 | $fields = parent::fields(); |
||||
| 93 | unset($fields['status'], $fields['data'], $fields['user_id'], $fields['client_id']); |
||||
| 94 | |||||
| 95 | $fields['type'] = function (self $model) { |
||||
| 96 | return AuthClientType::getName($model->type); |
||||
| 97 | }; |
||||
| 98 | |||||
| 99 | $fields['created_at'] = function (self $model) { |
||||
| 100 | return DateHelper::datetimeToIso8601($model->created_at); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 101 | }; |
||||
| 102 | |||||
| 103 | $fields['updated_at'] = function (self $model) { |
||||
| 104 | return DateHelper::datetimeToIso8601($model->updated_at); |
||||
|
0 ignored issues
–
show
It seems like
$model->updated_at can also be of type null; however, parameter $dateStr of yiier\helpers\DateHelper::datetimeToIso8601() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 105 | }; |
||||
| 106 | |||||
| 107 | return $fields; |
||||
| 108 | } |
||||
| 109 | } |
||||
| 110 |