-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adegoke Obasa
committed
Jun 13, 2017
1 parent
7c34815
commit 1163ed6
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* @author Adegoke Obasa <goke@cottacush.com> | ||
*/ | ||
|
||
namespace CottaCush\Yii2\Action; | ||
|
||
use CottaCush\Yii2\Controller\BaseController; | ||
use yii\base\Action; | ||
|
||
class DeleteAction extends Action | ||
{ | ||
public $returnUrl = ''; | ||
public $successMessage = ''; | ||
public $model; | ||
|
||
const STATUS_ACTIVE = 1; | ||
const STATUS_INACTIVE = 0; | ||
|
||
/** | ||
* @author Akinwunmi Taiwo <taiwo@cottacush.com> | ||
* @return \yii\web\Response | ||
*/ | ||
public function run() | ||
{ | ||
/** @var BaseController $controller */ | ||
$controller = $this->controller; | ||
|
||
$referrerUrl = $controller->getRequest()->referrer; | ||
$controller->isPostCheck($referrerUrl); | ||
$modelToDelete = $this->model; | ||
|
||
if (!$modelToDelete) { | ||
$controller->flashError('Record not found'); | ||
} else { | ||
$modelToDelete->is_active = self::STATUS_INACTIVE; | ||
if (!$modelToDelete->update()) { | ||
$controller->flashError($modelToDelete->getErrors()); | ||
} else { | ||
$controller->flashSuccess($this->successMessage); | ||
} | ||
} | ||
|
||
return $controller->redirect($this->returnUrl); | ||
} | ||
} |