@@ -105,13 +105,13 @@ |
||
| 105 | 105 | * Duplicate entries in the table. |
| 106 | 106 | * @return $this|null |
| 107 | 107 | */ |
| 108 | - public function duplicate(){ |
|
| 109 | - $this->isNewRecord=true; |
|
| 108 | + public function duplicate() { |
|
| 109 | + $this->isNewRecord = true; |
|
| 110 | 110 | |
| 111 | - foreach($this->primaryKey() as $key) |
|
| 111 | + foreach ($this->primaryKey() as $key) |
|
| 112 | 112 | $this->$key = null; |
| 113 | 113 | |
| 114 | - if($this->save()){ |
|
| 114 | + if ($this->save()) { |
|
| 115 | 115 | return $this; |
| 116 | 116 | } |
| 117 | 117 | 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,16 +71,18 @@ 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 | 'attributes' => [ |
| 80 | 81 | ActiveRecord::EVENT_BEFORE_INSERT => [$this->createdByAttribute, $this->updatedByAttribute], |
| 81 | 82 | ActiveRecord::EVENT_BEFORE_UPDATE => $this->updatedByAttribute, |
| 82 | 83 | ], |
| 83 | 84 | ]; |
| 85 | + } |
|
| 84 | 86 | |
| 85 | 87 | //Check trash |
| 86 | 88 | if ($this->hasAttribute($this->removedAttribute)) { |
@@ -108,8 +110,9 @@ discard block |
||
| 108 | 110 | public function duplicate(){ |
| 109 | 111 | $this->isNewRecord=true; |
| 110 | 112 | |
| 111 | - foreach($this->primaryKey() as $key) |
|
| 112 | - $this->$key = null; |
|
| 113 | + foreach($this->primaryKey() as $key) { |
|
| 114 | + $this->$key = null; |
|
| 115 | + } |
|
| 113 | 116 | |
| 114 | 117 | if($this->save()){ |
| 115 | 118 | return $this; |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Created by PhpStorm. |
|
| 4 | - * User: vadim |
|
| 5 | - * Date: 05.02.16 |
|
| 6 | - * Time: 12:57 |
|
| 7 | - */ |
|
| 3 | + * Created by PhpStorm. |
|
| 4 | + * User: vadim |
|
| 5 | + * Date: 05.02.16 |
|
| 6 | + * Time: 12:57 |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | namespace sibds\components; |
| 10 | 10 | |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | ]; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - public function getDefaultValue( $event ) |
|
| 28 | + public function getDefaultValue($event) |
|
| 29 | 29 | { |
| 30 | 30 | $owner = $this->owner; |
| 31 | 31 | if ($owner->hasAttribute($this->lockedAttribute)) |
@@ -28,9 +28,10 @@ |
||
| 28 | 28 | public function getDefaultValue( $event ) |
| 29 | 29 | { |
| 30 | 30 | $owner = $this->owner; |
| 31 | - if ($owner->hasAttribute($this->lockedAttribute)) |
|
| 32 | - if (empty($owner->{$this->lockedAttribute}) || is_null($owner->{$this->lockedAttribute})) |
|
| 31 | + if ($owner->hasAttribute($this->lockedAttribute)) { |
|
| 32 | + if (empty($owner->{$this->lockedAttribute}) || is_null($owner->{$this->lockedAttribute})) |
|
| 33 | 33 | $owner->{$this->lockedAttribute} = $this->valueUnlock; |
| 34 | + } |
|
| 34 | 35 | } |
| 35 | 36 | |
| 36 | 37 | public function lock() |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function init() |
| 19 | 19 | { |
| 20 | - if(is_null($this->userClass)) |
|
| 20 | + if (is_null($this->userClass)) |
|
| 21 | 21 | $this->userClass = \Yii::$app->user->className(); |
| 22 | 22 | } |
| 23 | 23 | |
@@ -17,8 +17,9 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function init() |
| 19 | 19 | { |
| 20 | - if(is_null($this->userClass)) |
|
| 21 | - $this->userClass = \Yii::$app->user->className(); |
|
| 20 | + if(is_null($this->userClass)) { |
|
| 21 | + $this->userClass = \Yii::$app->user->className(); |
|
| 22 | + } |
|
| 22 | 23 | } |
| 23 | 24 | |
| 24 | 25 | /** |
@@ -30,8 +31,9 @@ discard block |
||
| 30 | 31 | /* @var $owner BaseActiveRecord */ |
| 31 | 32 | $owner = $this->owner; |
| 32 | 33 | |
| 33 | - if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) |
|
| 34 | - return $owner->hasOne($this->userClass, ['id' => $this->createdByAttribute]); |
|
| 34 | + if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) { |
|
| 35 | + return $owner->hasOne($this->userClass, ['id' => $this->createdByAttribute]); |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | return null; |
| 37 | 39 | } |
@@ -45,8 +47,9 @@ discard block |
||
| 45 | 47 | /* @var $owner BaseActiveRecord */ |
| 46 | 48 | $owner = $this->owner; |
| 47 | 49 | |
| 48 | - if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) |
|
| 49 | - return $this->createUser ? $this->createUser->username : '- no user -'; |
|
| 50 | + if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) { |
|
| 51 | + return $this->createUser ? $this->createUser->username : '- no user -'; |
|
| 52 | + } |
|
| 50 | 53 | |
| 51 | 54 | return null; |
| 52 | 55 | } |
@@ -60,8 +63,9 @@ discard block |
||
| 60 | 63 | /* @var $owner BaseActiveRecord */ |
| 61 | 64 | $owner = $this->owner; |
| 62 | 65 | |
| 63 | - if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) |
|
| 64 | - return $this->hasOne($this->userClass, ['id' => $this->updatedByAttribute]); |
|
| 66 | + if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) { |
|
| 67 | + return $this->hasOne($this->userClass, ['id' => $this->updatedByAttribute]); |
|
| 68 | + } |
|
| 65 | 69 | |
| 66 | 70 | return null; |
| 67 | 71 | } |
@@ -75,8 +79,9 @@ discard block |
||
| 75 | 79 | /* @var $owner BaseActiveRecord */ |
| 76 | 80 | $owner = $this->owner; |
| 77 | 81 | |
| 78 | - if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) |
|
| 79 | - return $this->createUser ? $this->updateUser->username : '- no user -'; |
|
| 82 | + if ($owner->hasAttribute($this->createdByAttribute) && $owner->hasAttribute($this->updatedByAttribute)) { |
|
| 83 | + return $this->createUser ? $this->updateUser->username : '- no user -'; |
|
| 84 | + } |
|
| 80 | 85 | |
| 81 | 86 | return null; |
| 82 | 87 | } |