@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | |
105 | - public function lock(){ |
|
105 | + public function lock() { |
|
106 | 106 | $this->status = self::STATUS_LOCK; |
107 | 107 | $this->save(); |
108 | 108 | } |
109 | 109 | |
110 | - public function unlock(){ |
|
110 | + public function unlock() { |
|
111 | 111 | $this->status = self::STATUS_DEFAULT; |
112 | 112 | $this->save(); |
113 | 113 | } |
@@ -116,13 +116,13 @@ discard block |
||
116 | 116 | * Duplicate entries in the table. |
117 | 117 | * @return $this|null |
118 | 118 | */ |
119 | - public function duplicate(){ |
|
120 | - $this->isNewRecord=true; |
|
119 | + public function duplicate() { |
|
120 | + $this->isNewRecord = true; |
|
121 | 121 | |
122 | - foreach($this->primaryKey() as $key) |
|
122 | + foreach ($this->primaryKey() as $key) |
|
123 | 123 | $this->$key = null; |
124 | 124 | |
125 | - if($this->save()){ |
|
125 | + if ($this->save()) { |
|
126 | 126 | return $this; |
127 | 127 | } |
128 | 128 | return null; |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | // If table not have fields, then behavior not use |
63 | 63 | $behaviors = []; |
64 | 64 | //Check timestamp |
65 | - if ($this->hasAttribute($this->createdAtAttribute) && $this->hasAttribute($this->updatedAtAttribute)) |
|
66 | - $behaviors['timestamp'] = [ |
|
65 | + if ($this->hasAttribute($this->createdAtAttribute) && $this->hasAttribute($this->updatedAtAttribute)) { |
|
66 | + $behaviors['timestamp'] = [ |
|
67 | 67 | 'class' => TimestampBehavior::className(), |
68 | 68 | 'attributes' => [ |
69 | 69 | ActiveRecord::EVENT_BEFORE_INSERT => [$this->createdAtAttribute, $this->updatedAtAttribute], |
@@ -71,14 +71,16 @@ discard block |
||
71 | 71 | ], |
72 | 72 | |
73 | 73 | ]; |
74 | + } |
|
74 | 75 | |
75 | 76 | //Check blameable |
76 | - if ($this->hasAttribute($this->createdByAttribute) && $this->hasAttribute($this->updatedByAttribute)) |
|
77 | - $behaviors['blameable'] = [ |
|
77 | + if ($this->hasAttribute($this->createdByAttribute) && $this->hasAttribute($this->updatedByAttribute)) { |
|
78 | + $behaviors['blameable'] = [ |
|
78 | 79 | 'class' => UserDataBehavior::className(), |
79 | 80 | 'createdByAttribute' => $this->createdByAttribute, |
80 | 81 | 'updatedByAttribute' => $this->updatedByAttribute, |
81 | 82 | ]; |
83 | + } |
|
82 | 84 | |
83 | 85 | //Check trash |
84 | 86 | if ($this->hasAttribute($this->removedAttribute)) { |
@@ -94,9 +96,10 @@ discard block |
||
94 | 96 | public function beforeSave($insert) |
95 | 97 | { |
96 | 98 | if ($insert) { |
97 | - if ($this->hasAttribute($this->lockedAttribute)) |
|
98 | - if (empty($this->{$this->lockedAttribute}) || is_null($this->{$this->lockedAttribute})) |
|
99 | + if ($this->hasAttribute($this->lockedAttribute)) { |
|
100 | + if (empty($this->{$this->lockedAttribute}) || is_null($this->{$this->lockedAttribute})) |
|
99 | 101 | $this->{$this->lockedAttribute} = self::STATUS_UNLOCK; |
102 | + } |
|
100 | 103 | } |
101 | 104 | |
102 | 105 | return parent::beforeSave($insert); |
@@ -120,8 +123,9 @@ discard block |
||
120 | 123 | public function duplicate(){ |
121 | 124 | $this->isNewRecord=true; |
122 | 125 | |
123 | - foreach($this->primaryKey() as $key) |
|
124 | - $this->$key = null; |
|
126 | + foreach($this->primaryKey() as $key) { |
|
127 | + $this->$key = null; |
|
128 | + } |
|
125 | 129 | |
126 | 130 | if($this->save()){ |
127 | 131 | return $this; |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: vadim |
|
5 | - * Date: 26.05.15 |
|
6 | - * Time: 15:12 |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: vadim |
|
5 | + * Date: 26.05.15 |
|
6 | + * Time: 15:12 |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | namespace sibds\behaviors; |
10 | 10 |
@@ -22,8 +22,9 @@ discard block |
||
22 | 22 | /* @var $owner BaseActiveRecord */ |
23 | 23 | $owner = $this->owner; |
24 | 24 | |
25 | - if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) |
|
26 | - return $owner->hasOne(User::className(), ['id' => $this->createdByAttribute]); |
|
25 | + if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) { |
|
26 | + return $owner->hasOne(User::className(), ['id' => $this->createdByAttribute]); |
|
27 | + } |
|
27 | 28 | |
28 | 29 | return null; |
29 | 30 | } |
@@ -37,8 +38,9 @@ discard block |
||
37 | 38 | /* @var $owner BaseActiveRecord */ |
38 | 39 | $owner = $this->owner; |
39 | 40 | |
40 | - if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) |
|
41 | - return $this->createUser ? $this->createUser->username : '- no user -'; |
|
41 | + if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) { |
|
42 | + return $this->createUser ? $this->createUser->username : '- no user -'; |
|
43 | + } |
|
42 | 44 | |
43 | 45 | return null; |
44 | 46 | } |
@@ -52,8 +54,9 @@ discard block |
||
52 | 54 | /* @var $owner BaseActiveRecord */ |
53 | 55 | $owner = $this->owner; |
54 | 56 | |
55 | - if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) |
|
56 | - return $this->hasOne(User::className(), ['id' => $this->updatedByAttribute]); |
|
57 | + if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) { |
|
58 | + return $this->hasOne(User::className(), ['id' => $this->updatedByAttribute]); |
|
59 | + } |
|
57 | 60 | |
58 | 61 | return null; |
59 | 62 | } |
@@ -67,8 +70,9 @@ discard block |
||
67 | 70 | /* @var $owner BaseActiveRecord */ |
68 | 71 | $owner = $this->owner; |
69 | 72 | |
70 | - if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) |
|
71 | - return $this->createUser ? $this->updateUser->username : '- no user -'; |
|
73 | + if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) { |
|
74 | + return $this->createUser ? $this->updateUser->username : '- no user -'; |
|
75 | + } |
|
72 | 76 | |
73 | 77 | return null; |
74 | 78 | } |