@@ -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; |