Exemplo n.º 1
0
 public function actionSetStatus($id, $status = null, $visibility = null)
 {
     if (Yii::$app->request->isAjax) {
         $modelName = $this->getModelName();
         $model = new $modelName();
         $model = $model->findOne($id);
         if ($status !== null) {
             $model->status = $status;
             $view = AdminHelper::itemStatusLabel($model);
         } elseif ($visibility !== null) {
             $model->visibility = $visibility;
             $view = AdminHelper::itemVisibilityLabel($model);
         }
         if (isset($model->delete_at)) {
             if ($status == IStatus::STATUS_DELETED) {
                 $model->delete_at = date('Y-m-d H:i:s');
             } else {
                 $model->delete_at = null;
             }
         }
         return Json::encode(['result' => $model->save() ? 1 : 0, 'errors' => $model->errors, 'view' => $view]);
     }
     throw new BadRequestHttpException();
 }