Skip to content

Commit

Permalink
Merge pull request #9 from acorncom/allow-db-expressions
Browse files Browse the repository at this point in the history
Allow DB expressions for our onValue
  • Loading branch information
Aris Karageorgos committed Mar 10, 2016
2 parents a8a6902 + edff394 commit 1b210a9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion actions/ToggleAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Yii;
use yii\base\Action;
use yii\base\InvalidConfigException;
use yii\db\Expression;
use yii\web\MethodNotAllowedHttpException;

/**
Expand Down Expand Up @@ -38,7 +39,7 @@ class ToggleAction extends Action
public $andWhere;

/**
* @var string|int|boolean what to set active models to
* @var string|int|boolean|Expression what to set active models to
*/
public $onValue = 1;

Expand Down Expand Up @@ -111,6 +112,8 @@ public function run($id)

if ($model->$attribute == $this->onValue) {
$model->$attribute = $this->offValue;
} elseif ($this->onValue instanceof Expression && $model->$attribute != $this->offValue) {
$model->$attribute = $this->offValue;
} else {
$model->$attribute = $this->onValue;
}
Expand Down

0 comments on commit 1b210a9

Please sign in to comment.