forked from sangkil/sangkilbiz3
/
UserToBranch.php
100 lines (86 loc) · 2.26 KB
/
UserToBranch.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
98
99
100
<?php
namespace biz\master\models;
use Yii;
use \app\models\User;
/**
* This is the model class for table "user_to_branch".
*
* @property integer $id_branch
* @property integer $id_user
* @property string $create_at
* @property integer $create_by
* @property string $update_at
* @property integer $update_by
*
* @property Branch $idBranch
*/
class UserToBranch extends \yii\db\ActiveRecord {
public $nm_branch;
private $_username;
/**
* @inheritdoc
*/
public static function tableName() {
return '{{%user_to_branch}}';
}
/**
* @inheritdoc
*/
public function rules() {
return [
[['nmUser'], 'in', 'range' => User::find()->select(['username'])->column()],
[['id_branch', 'id_user', 'nmUser'], 'required'],
[['id_branch', 'id_user'], 'integer'],
[['id_user'], 'exist', 'targetAttribute' => 'id', 'targetClass' => User::className()]
];
}
/**
* @inheritdoc
*/
public function attributeLabels() {
return [
'id_branch' => 'Id Branch',
'id_user' => 'Id User',
'create_at' => 'Create At',
'create_by' => 'Create By',
'update_at' => 'Update At',
'update_by' => 'Update By',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdBranch() {
return $this->hasOne(Branch::className(), ['id_branch' => 'id_branch']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getIdUser() {
return $this->hasOne(\app\models\User::className(), ['id' => 'id_user']);
}
public function setNmUser($value) {
$this->_username = $value;
$user = User::findOne(['username' => $value]);
if ($user) {
$this->id_user = $user->id;
} else {
$this->id_user = null;
}
}
public function getNmUser() {
if ($this->_username === null) {
$this->_username = $this->id_user ? $this->idUser->username : null;
}
return $this->_username;
}
/**
* @inheritdoc
*/
public function behaviors() {
return [
'BizTimestampBehavior',
'BizBlameableBehavior',
];
}
}