示例#1
0
 /**
  * Creates a new Feedback model.
  * For ajax request will return json object
  * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $request = Yii::$app->request;
     $model = new Feedback();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['title' => "Create new Feedback", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['forceReload' => '#crud-datatable-pjax', 'title' => "Create new Feedback", 'content' => '<span class="text-success">Create Feedback success</span>', 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Create More', ['create'], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])];
             } else {
                 return ['title' => "Create new Feedback", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
示例#2
0
 /**
  * save Feedback model and trigger event notifications.
  * @param integer $id proyecto
  * @return Json Feedbaack
  */
 public function actionFeedback($id)
 {
     // ajax validation
     if (Yii::$app->request->isAjax) {
         $data = json_decode($_POST['feedback']);
         //search proyecto  creaction user
         $model_proyecto = Proyecto::findOne($id);
         $model = new Feedback();
         $model->id_usuario = Yii::$app->user->identity->id;
         $model->id_usuario_destino = $model_proyecto->usuario_creacion;
         $model->mensaje = $data->note;
         $model->img = $data->img;
         if ($model->save()) {
             $model->trigger(Feedback::EVENT_NUEVO_PEDIDO);
             //Notificacion
             Yii::$app->response->format = Response::FORMAT_JSON;
             return true;
         } else {
             return false;
         }
     }
 }