@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | * @var mixed The value to set for removed model. |
31 | 31 | * Default is 1. |
32 | 32 | */ |
33 | - public $removedFlag=1; |
|
33 | + public $removedFlag = 1; |
|
34 | 34 | /** |
35 | 35 | * @var mixed The value to set for restored model. |
36 | 36 | * Default is 0. |
37 | 37 | */ |
38 | - public $restoredFlag=0; |
|
38 | + public $restoredFlag = 0; |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @var callable the value that will be assigned to the attributes. This should be a valid |
@@ -57,18 +57,18 @@ discard block |
||
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
60 | - public function events(){ |
|
60 | + public function events() { |
|
61 | 61 | return ArrayHelper::merge([ |
62 | 62 | ActiveRecord::EVENT_BEFORE_INSERT => 'checkNewRecord', |
63 | 63 | ], parent::events()); |
64 | 64 | } |
65 | 65 | |
66 | - public function checkNewRecord($events){ |
|
66 | + public function checkNewRecord($events) { |
|
67 | 67 | /* @var $owner BaseActiveRecord */ |
68 | 68 | $owner = $this->owner; |
69 | 69 | |
70 | - if($owner->hasAttribute($this->trashAttribute)) |
|
71 | - if(empty($owner->{$this->trashAttribute})||is_null($owner->{$this->trashAttribute})) |
|
70 | + if ($owner->hasAttribute($this->trashAttribute)) |
|
71 | + if (empty($owner->{$this->trashAttribute})||is_null($owner->{$this->trashAttribute})) |
|
72 | 72 | $owner->{$this->trashAttribute} = $this->restoredFlag; |
73 | 73 | } |
74 | 74 | |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | /* @var $owner BaseActiveRecord */ |
78 | 78 | $owner = $this->owner; |
79 | 79 | |
80 | - if ($this->value === null) { |
|
81 | - if($owner->{$this->trashAttribute}==$this->restoredFlag) |
|
80 | + if ($this->value===null) { |
|
81 | + if ($owner->{$this->trashAttribute}==$this->restoredFlag) |
|
82 | 82 | { |
83 | 83 | $event->isValid = false; |
84 | - $owner->{$this->trashAttribute}=$this->removedFlag; |
|
84 | + $owner->{$this->trashAttribute} = $this->removedFlag; |
|
85 | 85 | $owner->save(false); |
86 | 86 | |
87 | 87 | return $this->removedFlag; |
88 | - }else{ |
|
88 | + } else { |
|
89 | 89 | return true; |
90 | 90 | } |
91 | 91 | return false; |
@@ -99,22 +99,22 @@ discard block |
||
99 | 99 | /* @var $owner BaseActiveRecord */ |
100 | 100 | $owner = $this->owner; |
101 | 101 | |
102 | - $owner->{$this->trashAttribute}=$this->restoredFlag; |
|
102 | + $owner->{$this->trashAttribute} = $this->restoredFlag; |
|
103 | 103 | |
104 | 104 | $owner->save(false); |
105 | 105 | } |
106 | 106 | |
107 | - public function getIsRemoved(){ |
|
107 | + public function getIsRemoved() { |
|
108 | 108 | return $this->owner->{$this->trashAttribute}==$this->removedFlag; |
109 | 109 | } |
110 | 110 | |
111 | - public function trashAttribute(){ |
|
111 | + public function trashAttribute() { |
|
112 | 112 | $owner = $this->owner->className(); |
113 | 113 | |
114 | 114 | return $owner::tableName().'.'.$this->trashAttribute; |
115 | 115 | } |
116 | 116 | |
117 | - public function fullTrashAttribute($removed=false){ |
|
118 | - return [$this->trashAttribute()=>($removed?$this->removedFlag:$this->restoredFlag)]; |
|
117 | + public function fullTrashAttribute($removed = false) { |
|
118 | + return [ $this->trashAttribute()=>($removed ? $this->removedFlag : $this->restoredFlag) ]; |
|
119 | 119 | } |
120 | 120 | } |