1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\models; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use app\models\File; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* This is the model class for table "user_profile". |
10
|
|
|
* |
11
|
|
|
* @property integer $user_id |
12
|
|
|
* @property string $full_name |
13
|
|
|
* @property string $photo |
14
|
|
|
* @property string $birth_day |
15
|
|
|
*/ |
16
|
|
|
class UserProfile extends \yii\db\ActiveRecord |
17
|
|
|
{ |
18
|
15 |
|
public function __construct($config = []) |
19
|
|
|
{ |
20
|
15 |
|
$this->attachBehavior('fileManager', require __DIR__ . '/behaviors/user-profile/filemanager.php'); |
21
|
15 |
|
parent::__construct($config); |
22
|
15 |
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @inheritdoc |
26
|
|
|
*/ |
27
|
72 |
|
public static function tableName() |
28
|
|
|
{ |
29
|
72 |
|
return 'user_profile'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc |
34
|
|
|
*/ |
35
|
|
|
public function rules() |
36
|
|
|
{ |
37
|
|
|
return [ |
38
|
|
|
[ |
39
|
|
|
['birth_day', 'photo'], 'safe', |
40
|
|
|
], |
41
|
|
|
|
42
|
|
|
['birth_day', 'date', 'format' => 'php:Y-m-d'], |
43
|
|
|
|
44
|
|
|
['full_name', 'string', 'max' => 40], |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @inheritdoc |
50
|
|
|
*/ |
51
|
|
|
public function attributeLabels() |
52
|
|
|
{ |
53
|
|
|
return [ |
54
|
|
|
'user_id' => Yii::t('app', 'User'), |
55
|
|
|
'full_name' => Yii::t('app', 'Full Name'), |
56
|
|
|
'photo' => Yii::t('app', 'Photo'), |
57
|
|
|
'birth_day' => Yii::t('app', 'Birth Day'), |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return \yii\db\ActiveQuery |
63
|
|
|
*/ |
64
|
1 |
|
public function getUser() |
65
|
|
|
{ |
66
|
1 |
|
return $this->hasOne(User::class, ['id' => 'user_id']); |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
public function getFiles($callable = null) |
70
|
|
|
{ |
71
|
|
|
return $this |
72
|
1 |
|
->hasMany(File::class, ['id' => 'file_id']) |
73
|
1 |
|
->viaTable('user_profiles_files', ['user_id' => 'user_id'], $callable); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|