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
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Organization member. |
22
|
|
|
* |
23
|
|
|
* @property string $organization_guid |
24
|
|
|
* @proprtyy string $user_guid |
25
|
|
|
* @property string $nickname |
26
|
|
|
* @property string $description |
27
|
|
|
* |
28
|
|
|
* @property string $department_guid |
29
|
|
|
* @property string $member_guid |
30
|
|
|
* @property User $memberUser |
31
|
|
|
* |
32
|
|
|
* @version 1.0 |
33
|
|
|
* @author vistart <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class Member extends BaseBlameableModel |
36
|
|
|
{ |
37
|
|
|
public $createdByAttribute = 'organization_guid'; |
38
|
|
|
public $updatedByAttribute = false; |
39
|
|
|
public $hostClass = Organization::class; |
40
|
|
|
|
41
|
|
|
public $memberAttribute = 'user_guid'; |
42
|
|
|
public $memberUserClass = User::class; |
43
|
|
|
private $noInitMemberUser; |
44
|
|
|
/** |
45
|
|
|
* @return User |
46
|
|
|
*/ |
47
|
|
|
protected function getNoInitMemberUser() |
48
|
|
|
{ |
49
|
|
|
if (!$this->noInitMemberUser) { |
50
|
|
|
$class = $this->memberUserClass; |
51
|
|
|
$this->noInitMemberUser = $class::buildNoInitModel(); |
52
|
|
|
} |
53
|
|
|
return $this->noInitMemberUser; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @inheritdoc |
58
|
|
|
*/ |
59
|
|
|
public function init() |
60
|
|
|
{ |
61
|
|
|
if (!is_string($this->queryClass)) { |
62
|
|
|
$this->queryClass = MemberQuery::class; |
63
|
|
|
} |
64
|
|
|
if ($this->skipInit) { |
65
|
|
|
return; |
66
|
|
|
} |
67
|
|
|
parent::init(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public $descriptionAttribute = 'description'; |
71
|
|
|
|
72
|
|
|
public function getMemberUserRules() |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
[$this->memberAttribute, 'required'], |
76
|
|
|
[$this->memberAttribute, 'string', 'max' => 36], |
77
|
|
|
]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Set member user. |
82
|
|
|
* @param User|string|integer $user |
83
|
|
|
*/ |
84
|
|
|
public function setMemberUser($user) |
85
|
|
|
{ |
86
|
|
|
$class = $this->memberUserClass; |
87
|
|
|
if (is_int($user)) { |
88
|
|
|
$user = $class::find()->id($user)->one(); |
89
|
|
|
} |
90
|
|
|
if ($user instanceof $class) { |
91
|
|
|
$user = $user->getGUID(); |
92
|
|
|
} |
93
|
|
|
$this->user_guid = $user; |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getMemberUser() |
97
|
|
|
{ |
98
|
|
|
return $this->hasOne($this->memberUserClass, [$this->memberAttribute => $this->getNoInitMemberUser()->guidAttribute]); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get Organization Query. |
103
|
|
|
* Alias of `getHost` method. |
104
|
|
|
* @return OrganizationQuery |
105
|
|
|
*/ |
106
|
|
|
public function getOrganization() |
107
|
|
|
{ |
108
|
|
|
return $this->getHost(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Set Organization. |
113
|
|
|
* @param Organization $organization |
114
|
|
|
* @return boolean |
115
|
|
|
*/ |
116
|
|
|
public function setOrganization($organization) |
117
|
|
|
{ |
118
|
|
|
return $this->setHost($organization); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function rules() |
122
|
|
|
{ |
123
|
|
|
return array_merge($this->getMemberUserRules(), parent::rules()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @inheritdoc |
128
|
|
|
*/ |
129
|
|
|
public static function tableName() |
130
|
|
|
{ |
131
|
|
|
return '{{%organization_member}}'; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.