@@ -8,7 +8,6 @@ |
||
| 8 | 8 | |
| 9 | 9 | namespace sibds\components; |
| 10 | 10 | |
| 11 | -use Yii; |
|
| 12 | 11 | use yii\behaviors\TimestampBehavior; |
| 13 | 12 | use sibds\behaviors\UserDataBehavior; |
| 14 | 13 | use sibds\behaviors\TrashBehavior; |
@@ -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; |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | // If table not have fields, then behavior not use |
| 62 | 62 | $behaviors = []; |
| 63 | 63 | //Check timestamp |
| 64 | - if ($this->hasAttribute($this->createdAtAttribute) && $this->hasAttribute($this->updatedAtAttribute)) |
|
| 65 | - $behaviors['timestamp'] = [ |
|
| 64 | + if ($this->hasAttribute($this->createdAtAttribute) && $this->hasAttribute($this->updatedAtAttribute)) { |
|
| 65 | + $behaviors['timestamp'] = [ |
|
| 66 | 66 | 'class' => TimestampBehavior::className(), |
| 67 | 67 | 'attributes' => [ |
| 68 | 68 | ActiveRecord::EVENT_BEFORE_INSERT => [$this->createdAtAttribute, $this->updatedAtAttribute], |
@@ -70,14 +70,16 @@ discard block |
||
| 70 | 70 | ], |
| 71 | 71 | |
| 72 | 72 | ]; |
| 73 | + } |
|
| 73 | 74 | |
| 74 | 75 | //Check blameable |
| 75 | - if ($this->hasAttribute($this->createdByAttribute) && $this->hasAttribute($this->updatedByAttribute)) |
|
| 76 | - $behaviors['blameable'] = [ |
|
| 76 | + if ($this->hasAttribute($this->createdByAttribute) && $this->hasAttribute($this->updatedByAttribute)) { |
|
| 77 | + $behaviors['blameable'] = [ |
|
| 77 | 78 | 'class' => UserDataBehavior::className(), |
| 78 | 79 | 'createdByAttribute' => $this->createdByAttribute, |
| 79 | 80 | 'updatedByAttribute' => $this->updatedByAttribute, |
| 80 | 81 | ]; |
| 82 | + } |
|
| 81 | 83 | |
| 82 | 84 | //Check trash |
| 83 | 85 | if ($this->hasAttribute($this->removedAttribute)) { |
@@ -93,9 +95,10 @@ discard block |
||
| 93 | 95 | public function beforeSave($insert) |
| 94 | 96 | { |
| 95 | 97 | if ($insert) { |
| 96 | - if ($this->hasAttribute('status')) |
|
| 97 | - if (empty($this->status) || is_null($this->status)) |
|
| 98 | + if ($this->hasAttribute('status')) { |
|
| 99 | + if (empty($this->status) || is_null($this->status)) |
|
| 98 | 100 | $this->status = self::STATUS_DEFAULT; |
| 101 | + } |
|
| 99 | 102 | } |
| 100 | 103 | |
| 101 | 104 | return parent::beforeSave($insert); |
@@ -119,8 +122,9 @@ discard block |
||
| 119 | 122 | public function duplicate(){ |
| 120 | 123 | $this->isNewRecord=true; |
| 121 | 124 | |
| 122 | - foreach($this->primaryKey() as $key) |
|
| 123 | - $this->$key = null; |
|
| 125 | + foreach($this->primaryKey() as $key) { |
|
| 126 | + $this->$key = null; |
|
| 127 | + } |
|
| 124 | 128 | |
| 125 | 129 | if($this->save()){ |
| 126 | 130 | 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 | } |