|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
|
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
|
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
|
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
|
8
|
|
|
* @link http://vistart.name/ |
|
9
|
|
|
* @copyright Copyright (c) 2016 vistart |
|
10
|
|
|
* @license http://vistart.name/license/ |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace vistart\Models\models; |
|
14
|
|
|
|
|
15
|
|
|
use vistart\Models\queries\BaseBlameableQuery; |
|
16
|
|
|
use vistart\Models\traits\BlameableTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* BaseBlameableModel automatically fills the specified attributes with |
|
20
|
|
|
* the current user's GUID. |
|
21
|
|
|
* For example:<br/> |
|
22
|
|
|
* ~~~php |
|
23
|
|
|
* * @property string $comment |
|
24
|
|
|
* class Comment extends BaseBlameableModel |
|
25
|
|
|
* { |
|
26
|
|
|
* public $contentAttribute = 'commment'; |
|
27
|
|
|
* public $contentAttributeRule = ['string', 'max' => 140]; |
|
28
|
|
|
* public static function tableName() |
|
29
|
|
|
* { |
|
30
|
|
|
* return <table_name>; |
|
31
|
|
|
* } |
|
32
|
|
|
* public function rules() |
|
33
|
|
|
* { |
|
34
|
|
|
* $rules = <Your Rules>; |
|
35
|
|
|
* return array_merge(parent::rules(), $rules); |
|
36
|
|
|
* } |
|
37
|
|
|
* public function behaviors() |
|
38
|
|
|
* { |
|
39
|
|
|
* $behaviors = <Your Behaviors>; |
|
40
|
|
|
* return array_merge(parent::behaviors(), $behaviors); |
|
41
|
|
|
* } |
|
42
|
|
|
* public function attributeLabels() |
|
43
|
|
|
* { |
|
44
|
|
|
* return [ |
|
45
|
|
|
* ... |
|
46
|
|
|
* ]; |
|
47
|
|
|
* } |
|
48
|
|
|
* } |
|
49
|
|
|
* ~~~ |
|
50
|
|
|
* Well, when you're signed-in, you can create and save a new `Comment` instance: |
|
51
|
|
|
* ~~~php |
|
52
|
|
|
* $comment = new Comment(); |
|
53
|
|
|
* $comment->comment = 'New Comment.'; |
|
54
|
|
|
* $comment->save(); |
|
55
|
|
|
* ~~~ |
|
56
|
|
|
* or update an existing one: |
|
57
|
|
|
* ~~~php |
|
58
|
|
|
* $comment = Comment::findByIdentity()->one(); |
|
59
|
|
|
* if ($comment) |
|
60
|
|
|
* { |
|
61
|
|
|
* $comment->comment = 'Updated Comment.'; |
|
62
|
|
|
* $comment->save(); |
|
63
|
|
|
* } |
|
64
|
|
|
* ~~~ |
|
65
|
|
|
* @property array createdByAttributeRules the whole validation rules of |
|
66
|
|
|
* creator attribute only, except of combination rules. |
|
67
|
|
|
* @property array updatedByAttributeRules the whole validation rules of |
|
68
|
|
|
* creator attribute only, except of combination rules. |
|
69
|
|
|
* @since 1.1 |
|
70
|
|
|
* @version 2.0 |
|
71
|
|
|
* @author vistart <[email protected]> |
|
72
|
|
|
*/ |
|
73
|
|
|
abstract class BaseBlameableModel extends BaseEntityModel |
|
74
|
|
|
{ |
|
75
|
|
|
use BlameableTrait; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Initialize the blameable model. |
|
79
|
|
|
* If query class is not specified, [[BaseBlameableQuery]] will be taken. |
|
80
|
|
|
*/ |
|
81
|
32 |
|
public function init() |
|
82
|
|
|
{ |
|
83
|
32 |
|
if (!is_string($this->queryClass)) { |
|
84
|
16 |
|
$this->queryClass = BaseBlameableQuery::className(); |
|
85
|
16 |
|
} |
|
86
|
32 |
|
if ($this->skipInit) { |
|
87
|
15 |
|
return; |
|
88
|
|
|
} |
|
89
|
32 |
|
$this->initBlameableEvents(); |
|
90
|
32 |
|
parent::init(); |
|
91
|
32 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get the query class with specified identity. |
|
95
|
|
|
* @param BaseUserModel $identity |
|
96
|
|
|
* @return BaseBlameableQuery |
|
97
|
|
|
*/ |
|
98
|
|
|
public static function findByIdentity($identity = null) |
|
99
|
|
|
{ |
|
100
|
|
|
return static::find()->byIdentity($identity); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: