-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathProfile.php
97 lines (88 loc) · 1.96 KB
/
Profile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace amnah\yii2\user\models;
use Yii;
use yii\db\ActiveRecord;
/**
* This is the model class for table "tbl_profile".
*
* @property integer $id
* @property integer $user_id
* @property string $created_at
* @property string $updated_at
* @property string $full_name
* @property string $timezone
*
* @property User $user
*/
class Profile extends ActiveRecord
{
/**
* @var \amnah\yii2\user\Module
*/
public $module;
/**
* @inheritdoc
*/
public function init()
{
if (!$this->module) {
$this->module = Yii::$app->getModule("user");
}
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['full_name'], 'string', 'max' => 255],
[['timezone'], 'string', 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('user', 'ID'),
'user_id' => Yii::t('user', 'User ID'),
'created_at' => Yii::t('user', 'Created At'),
'updated_at' => Yii::t('user', 'Updated At'),
'full_name' => Yii::t('user', 'Full Name'),
'timezone' => Yii::t('user', 'Time zone'),
];
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'timestamp' => [
'class' => 'yii\behaviors\TimestampBehavior',
'value' => function ($event) {
return gmdate("Y-m-d H:i:s");
},
],
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
$user = $this->module->model("User");
return $this->hasOne($user::className(), ['id' => 'user_id']);
}
/**
* Set user id
* @param int $userId
* @return static
*/
public function setUser($userId)
{
$this->user_id = $userId;
return $this;
}
}