1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
8
|
|
|
* @link https://vistart.me/ |
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
10
|
|
|
* @license https://vistart.me/license/ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace rhosocial\organization; |
14
|
|
|
|
15
|
|
|
use rhosocial\base\models\models\BaseBlameableModel; |
16
|
|
|
use rhosocial\user\User; |
17
|
|
|
use rhosocial\organization\queries\OrganizationQuery; |
18
|
|
|
use rhosocial\organization\queries\MemberQuery; |
19
|
|
|
use Yii; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Organization member. |
23
|
|
|
* |
24
|
|
|
* @property string $organization_guid |
25
|
|
|
* @property string $user_guid store guid of user who represents this member. |
26
|
|
|
* @property string $nickname |
27
|
|
|
* @property string $role |
28
|
|
|
* @property string $description |
29
|
|
|
* |
30
|
|
|
* @property string $department_guid |
31
|
|
|
* @property string $member_guid |
32
|
|
|
* @property User $memberUser |
33
|
|
|
* |
34
|
|
|
* @version 1.0 |
35
|
|
|
* @author vistart <[email protected]> |
36
|
|
|
*/ |
37
|
|
|
class Member extends BaseBlameableModel |
38
|
|
|
{ |
39
|
|
|
public $createdByAttribute = 'organization_guid'; |
40
|
|
|
public $updatedByAttribute = false; |
41
|
|
|
public $hostClass = Organization::class; |
42
|
|
|
|
43
|
|
|
public $memberAttribute = 'user_guid'; |
44
|
|
|
public $memberUserClass = User::class; |
45
|
|
|
public $contentAttribute = 'nickname'; |
46
|
|
|
private $noInitMemberUser; |
47
|
|
|
/** |
48
|
|
|
* @return User |
49
|
|
|
*/ |
50
|
6 |
|
protected function getNoInitMemberUser() |
51
|
|
|
{ |
52
|
6 |
|
if (!$this->noInitMemberUser) { |
53
|
6 |
|
$class = $this->memberUserClass; |
54
|
6 |
|
$this->noInitMemberUser = $class::buildNoInitModel(); |
55
|
|
|
} |
56
|
6 |
|
return $this->noInitMemberUser; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritdoc |
61
|
|
|
*/ |
62
|
16 |
|
public function init() |
63
|
|
|
{ |
64
|
16 |
|
if (!is_string($this->queryClass)) { |
65
|
16 |
|
$this->queryClass = MemberQuery::class; |
66
|
|
|
} |
67
|
16 |
|
if ($this->skipInit) { |
68
|
16 |
|
return; |
69
|
|
|
} |
70
|
16 |
|
parent::init(); |
71
|
16 |
|
} |
72
|
|
|
|
73
|
|
|
public $descriptionAttribute = 'description'; |
74
|
|
|
|
75
|
16 |
|
public function getMemberUserRules() |
76
|
|
|
{ |
77
|
|
|
return [ |
78
|
16 |
|
[$this->memberAttribute, 'required'], |
79
|
16 |
|
[$this->memberAttribute, 'string', 'max' => 36], |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
16 |
|
public function getMemberRoleRules() |
84
|
|
|
{ |
85
|
|
|
return [ |
86
|
16 |
|
['role', 'string', 'max' => 255], |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Set member user. |
92
|
|
|
* @param User|string|integer $user |
93
|
|
|
*/ |
94
|
16 |
|
public function setMemberUser($user) |
95
|
|
|
{ |
96
|
16 |
|
$class = $this->memberUserClass; |
97
|
16 |
|
if (is_int($user)) { |
98
|
|
|
$user = $class::find()->id($user)->one(); |
99
|
|
|
} |
100
|
16 |
|
if ($user instanceof $class) { |
101
|
16 |
|
$user = $user->getGUID(); |
102
|
|
|
} |
103
|
16 |
|
$this->user_guid = $user; |
104
|
16 |
|
} |
105
|
|
|
|
106
|
6 |
|
public function getMemberUser() |
107
|
|
|
{ |
108
|
6 |
|
return $this->hasOne($this->memberUserClass, [$this->getNoInitMemberUser()->guidAttribute => $this->memberAttribute]); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get Organization Query. |
113
|
|
|
* Alias of `getHost` method. |
114
|
|
|
* @return OrganizationQuery |
115
|
|
|
*/ |
116
|
5 |
|
public function getOrganization() |
117
|
|
|
{ |
118
|
5 |
|
return $this->getHost(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Set Organization. |
123
|
|
|
* @param BaseOrganization $organization |
124
|
|
|
* @return boolean |
125
|
|
|
*/ |
126
|
16 |
|
public function setOrganization($organization) |
127
|
|
|
{ |
128
|
16 |
|
return $this->setHost($organization); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function assignRole($role) |
|
|
|
|
132
|
|
|
{ |
133
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function removeRole($role) |
|
|
|
|
137
|
|
|
{ |
138
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
16 |
|
public function rules() |
142
|
|
|
{ |
143
|
16 |
|
return array_merge($this->getMemberUserRules(), $this->getMemberRoleRules(), parent::rules()); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @inheritdoc |
148
|
|
|
*/ |
149
|
16 |
|
public static function tableName() |
150
|
|
|
{ |
151
|
16 |
|
return '{{%organization_member}}'; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @inheritdoc |
156
|
|
|
*/ |
157
|
|
|
public function attributeLabels() |
158
|
|
|
{ |
159
|
|
|
return [ |
160
|
|
|
'guid' => Yii::t('app', 'GUID'), |
161
|
|
|
'id' => Yii::t('app', 'ID'), |
162
|
|
|
'organization_guid' => Yii::t('app', 'Organization GUID'), |
163
|
|
|
'user_guid' => Yii::t('app', 'User GUID'), |
164
|
|
|
'nickname' => Yii::t('app', 'Nickname'), |
165
|
|
|
'description' => Yii::t('app', 'Description'), |
166
|
|
|
'ip' => Yii::t('app', 'IP'), |
167
|
|
|
'ip_type' => Yii::t('app', 'IP Address Type'), |
168
|
|
|
'created_at' => Yii::t('app', 'Create Time'), |
169
|
|
|
'updated_at' => Yii::t('app', 'Update Time'), |
170
|
|
|
]; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.