예제 #1
0
 /**
  * Default items for render StatusAction widget.
  * 
  * @param array|string $statuses
  * @return array list of items for StatusAction widget.
  */
 public static function getStatusActions($statuses = null)
 {
     StatusAction::registerTranslation();
     $messageCategory = StatusAction::MESSAGE_CATEGORY;
     $actions = [self::STATUS_PUBLISHED => ['label' => Yii::t($messageCategory, 'Publish'), 'icon' => 'check fa-fw', 'type' => Html::TYPE_SUCCESS, 'changeTo' => Status::STATUS_UNPUBLISHED], self::STATUS_UNPUBLISHED => ['label' => Yii::t($messageCategory, 'Unpublish'), 'icon' => 'times fa-fw', 'type' => Html::TYPE_WARNING, 'changeTo' => Status::STATUS_PUBLISHED], self::STATUS_DRAFT => ['label' => Yii::t($messageCategory, 'Draft'), 'icon' => 'pencil fa-fw', 'type' => Html::TYPE_INFO, 'changeTo' => Status::STATUS_PUBLISHED], self::STATUS_ARCHIVED => ['label' => Yii::t($messageCategory, 'Archive'), 'icon' => 'archive fa-fw', 'type' => Html::TYPE_DEFAULT, 'changeTo' => Status::STATUS_PUBLISHED], self::STATUS_TRASHED => ['label' => Yii::t($messageCategory, 'Trash'), 'icon' => 'trash fa-fw', 'type' => Html::TYPE_DANGER, 'changeTo' => Status::STATUS_PUBLISHED]];
     return self::getStatuses($statuses, $actions);
 }
 /**
  * Run the action
  * 
  * @param integer $id
  * @param integer|string $status
  */
 public function run($id, $status)
 {
     StatusWidget::registerTranslation();
     $model = $this->model;
     if (in_array($status, $model::getStatuses())) {
         $model = $model::findOne($id);
         $model->status = $status;
         if ($model->save(false)) {
             Yii::$app->session->setFlash('success', Yii::t(StatusWidget::MESSAGE_CATEGORY, 'Changed status successfully!'));
         }
     }
     !Yii::$app->request->isAjax && $this->controller->redirect(Yii::$app->request->referrer);
 }