/** * Creates a new Access 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 Access(); if ($request->isAjax) { /* * Process for ajax request */ Yii::$app->response->format = Response::FORMAT_JSON; if ($request->isGet) { return ['title' => "Create new Access", 'content' => $this->renderPartial('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' => 'true', 'title' => "Create new Access", 'content' => '<span class="text-success">Create Access 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 Access", 'content' => $this->renderPartial('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]); } } }
/** * Creates a new Access model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Access(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Access model. * If creation is successful, the browser will be redirected to the 'view' page. * @param $id * @return string|\yii\web\Response * @throws ForbiddenHttpException */ public function actionCreate($id) { $note = Note::findOne($id); if ($note->creator == Yii::$app->user->id) { $model = new Access(); $model->load(Yii::$app->request->post()); $model->note_id = $id; if ($model->validate() && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } throw new ForbiddenHttpException("Not allowed share notes other people!"); }
/** * Creates a new Access model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Access(); $model->user_owner = Yii::$app->user->id; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { $all_mynotes = Calendar::getDates(Yii::$app->user->id); $all_users = User::find()->where('id !=' . Yii::$app->user->id)->asArray()->all(); // print_r($all_mynotes); // print_r($all_users); // exit(); if ($all_mynotes) { return $this->render('create', ['model' => $model, 'all_users' => $all_users, 'all_mynotes' => $all_mynotes]); } else { return $this->redirect('calendar/create'); } } }
/** * Creates a new Access model. * If creation is successful, the browser will be redirected to the 'view' page. * @param $id * @return string|\yii\web\Response * @throws BadRequestHttpException * @throws ForbiddenHttpException */ public function actionCreate($id) { $note = Note::findOne($id); if (!$note) { throw new BadRequestHttpException("Not exists note!"); } if ($note->creator == Yii::$app->user->id) { $model = new Access(); $usersForAutocomplete = User::find()->selectForAutocomplite()->notCurrent()->asArray()->all(); $model->load(Yii::$app->request->post()); $model->note_id = $id; if ($model->validate() && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'usersForAutocomplete' => $usersForAutocomplete]); } } throw new ForbiddenHttpException("Not allowed share notes other people!"); }
public function actionAddmodule() { $data = []; $exist = Access::find()->where(["module_id" => $_POST['module_id'], "profile_id" => $_POST['profile_id']])->all(); if (count($exist) === 0) { $access = new Access(); $access->module_id = $_POST['module_id']; $access->profile_id = $_POST['profile_id']; $access->save(); } $data['message'] = "Module Granted"; $dataProvider = new ActiveDataProvider(['query' => Access::find()->where(["profile_id" => $_POST['profile_id']])->orderBy('id DESC'), 'pagination' => ['pageSize' => 20]]); $data['gridmodules'] = GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'module', 'value' => 'module.label'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{deletemodule}', 'buttons' => ['deletemodule' => function () { return Html::a('<span class="glyphicon glyphicon-trash"></span>', null, ['data-confirm' => 'Are you sure you want to delete this item?', 'class' => "deletemoduleajax"]); }]]], 'options' => ['class' => '', 'id' => 'grid-accesses']]); Yii::$app->response->format = Response::FORMAT_JSON; return $data; }