Пример #1
0
 /**
  * @param ActiveRecord $model
  * @param array $actions Custom actions array in the form of
  * ```php
  * 'name' => function() {
  *
  * }
  * ```
  * @param bool $addDefaultActions If true default actions will be added
  * @return \yii\web\Response
  * @throws BadRequestHttpException
  */
 protected function getCreateUpdateResponse($model, $actions = [], $addDefaultActions = true)
 {
     $defaultActions = [AdminHtml::ACTION_SAVE_AND_STAY => function () use($model) {
         /** @var Controller | CrudControllerTrait $this */
         return $this->redirect(['update', 'id' => $model->getPrimaryKey()]);
     }, AdminHtml::ACTION_SAVE_AND_CREATE => function () use($model) {
         /** @var Controller | CrudControllerTrait $this */
         if ($url = Url::previous($this->createUrlParam)) {
             Url::remember(null, $this->createUrlParam);
             return $this->redirect($url);
         }
         return $this->redirect(['create']);
     }, AdminHtml::ACTION_SAVE_AND_LEAVE => function () use($model) {
         /** @var Controller | CrudControllerTrait $this */
         if ($url = \Yii::$app->request->get('return')) {
             return $this->redirect($url);
         }
         if ($url = Url::previous($this->indexUrlParam)) {
             Url::remember(null, $this->indexUrlParam);
             return $this->redirect($url);
         }
         return $this->redirect(['index']);
     }];
     if ($addDefaultActions) {
         $actions = array_merge($defaultActions, $actions);
     }
     $actionName = \Yii::$app->request->post(AdminHtml::ACTION_BUTTON_NAME, AdminHtml::ACTION_SAVE_AND_LEAVE);
     if (isset($actions[$actionName])) {
         return call_user_func($actions[$actionName]);
     } else {
         throw new BadRequestHttpException('Unknown action: ' . $actionName);
     }
 }
 public function oAuthSuccess($client)
 {
     // get user data from client
     $userAttributes = $client->getUserAttributes();
     $email = $userAttributes['emails'][0]['value'];
     $player = Player::findByEmail($email);
     if ($player == null) {
         $player = new Player();
         $player->email = $email;
         if (isset($userAttributes['image']) && isset($userAttributes['image']['url'])) {
             $photo = explode('?', $userAttributes['image']['url'])[0];
             $player->photo = $photo;
         }
         if (isset($userAttributes['name'])) {
             $player->first_name = $userAttributes['name']['givenName'];
             $player->last_name = $userAttributes['name']['familyName'];
         }
         $player->generateAuthKey();
         $player->generateAccessToken();
         $player->save();
     }
     if (Yii::$app->user->login($player, 3600 * 24 * 30)) {
         return $this->redirect(Url::previous());
     }
 }
 /**
  * Deletes an existing Employee model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $model->setScenario('change_status');
     $model->delete();
     return $this->redirect(Url::previous());
 }
 public function actionIndex($lang = 'id')
 {
     Yii::$app->language = $lang;
     $cookie = new \yii\web\Cookie(['name' => 'lang', 'value' => $lang]);
     \Yii::$app->getResponse()->getCookies()->add($cookie);
     return $this->redirect(Url::previous());
 }
 /**
  * Deletes an existing Message model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     Message::deleteAll(['id' => $id]);
     Yii::$app->getSession()->setFlash('success', Yii::t('admin', 'Entry has been deleted successfully'));
     return $this->redirect(Url::previous());
 }
Пример #6
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!isset($this->redirectUrl)) {
         $this->redirectUrl = Url::previous();
     }
 }
Пример #7
0
 public function actionIndex()
 {
     if (yii::$app->user->isGuest == true) {
         return $this->render('index');
     } else {
         $this->redirect(Url::previous('safe_url'));
     }
 }
Пример #8
0
 /**
  * Updates an existing Books model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(Url::previous());
     }
     return $this->render('update', ['model' => $model]);
 }
Пример #9
0
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     if (!Yii::$app->user->can('isOwner', ['model' => $model])) {
         throw new ForbiddenHttpException('Access denied');
     }
     $model->delete();
     return $this->redirect(Url::previous());
 }
Пример #10
0
 /** 跳转回上一个记住的网页 */
 public function actionPrevious()
 {
     $previous = Url::previous();
     if ($previous) {
         return $this->redirect($previous);
     } else {
         return $this->redirect(['user-aaa/index']);
     }
 }
 public function actionDelete($id)
 {
     $this->getModule()->detachFile($id);
     if (\Yii::$app->request->isAjax) {
         return json_encode([]);
     } else {
         return $this->redirect(Url::previous());
     }
 }
 /**
  * Updates an existing I18nMessage model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @param string $language
  * @return mixed
  */
 public function actionUpdate($id, $language)
 {
     $model = $this->findModel($id, $language);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(Url::previous('i18n-messages-filter') ?: ['index']);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
Пример #13
0
 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (!$this->redirectUrl) {
         $this->redirectUrl = Url::previous(self::URL_NAME_INDEX_ACTION);
     }
     if (!is_subclass_of($this->modelClass, BaseActiveRecord::className())) {
         throw new InvalidConfigException("Property 'modelClass': given class extend '" . BaseActiveRecord::className() . "'");
     }
 }
Пример #14
0
 /**
  * Updates an existing Book model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $file = UploadedFile::getInstance($model, 'preview');
         if ($model->upload($file) && $model->save()) {
             return $this->redirect(Url::previous());
         }
     }
     return $this->render('update', ['model' => $model, 'authors' => Author::find()->all()]);
 }
Пример #15
0
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (empty($this->gridId) || empty($this->gridManager)) {
         throw new InvalidConfigException('Property "gridId" and "gridManager" must be specified.');
     }
     $this->gridManager = Instance::ensure($this->gridManager, 'bupy7\\grid\\interfaces\\ManagerInterface');
     if (!isset($this->redirectUrl)) {
         $this->redirectUrl = Url::previous();
     }
 }
Пример #16
0
 /**
  * Updates an existing Address model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->addFlash('success', "Запись \"{$model->fullName}\" успешно сохранена.");
         return $this->redirect(Url::previous() != Yii::$app->homeUrl ? Url::previous() : ['view', 'id' => $model->id]);
     } else {
         if (Yii::$app->request->referrer != Yii::$app->request->absoluteUrl) {
             Url::remember(Yii::$app->request->referrer ? Yii::$app->request->referrer : null);
         }
         return $this->render('update', ['model' => $model]);
     }
 }
 public function actionUrl()
 {
     $urls = [];
     $urls[] = Url::base();
     $urls[] = Url::current();
     $urls[] = Url::previous();
     // use before Url::remember()
     $urls[] = Url::home();
     $urls[] = Url::to('/');
     $urls[] = Url::to('/test');
     $urls[] = Url::to(['book']);
     return VarDumper::dumpAsString($urls, 10, true);
 }
Пример #18
0
 public function actionSubscribe()
 {
     $app = \Yii::$app;
     $model = new SubscribersRecord();
     if (\Yii::$app->request->isAjax && $model->load($_POST)) {
         \Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(\Yii::$app->request->post()) && $model->save()) {
         \Yii::$app->session->setFlash('subscribeFormSubmitted');
         return $this->redirect(Url::previous());
     }
 }
Пример #19
0
 public function actionSubscribe()
 {
     $app = \Yii::$app;
     $model = new SubscribersRecord();
     if (\Yii::$app->request->isAjax && $model->load($_POST)) {
         \Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(\Yii::$app->request->post()) && $model->save()) {
         \Yii::$app->session->setFlash('success', Language::t('flash', 'Вы успешно подписанны на обновления.'));
         return $this->redirect(Url::previous());
     }
 }
Пример #20
0
 public function actionDeleteTemp($filename)
 {
     $userTempDir = $this->getModule()->getUserDirPath();
     $filePath = $userTempDir . DIRECTORY_SEPARATOR . $filename;
     unlink($filePath);
     if (!count(FileHelper::findFiles($userTempDir))) {
         rmdir($userTempDir);
     }
     if (Yii::$app->request->isAjax) {
         return json_encode([]);
     } else {
         return $this->redirect(Url::previous());
     }
 }
 /**
  * Creates a new OrderAttribute model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new OrderAttribute();
     try {
         if ($model->load($_POST) && $model->save()) {
             return $this->redirect(Url::previous());
         } elseif (!\Yii::$app->request->isPost) {
             $model->load($_GET);
         }
     } catch (\Exception $e) {
         $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage();
         $model->addError('_exception', $msg);
     }
     return $this->render('create', ['model' => $model]);
 }
 /**
  * Updates an existing SeasonDetails model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     //        var_dump($model->load(Yii::$app->request->post()));
     //        var_dump(Yii::$app->request->post());
     //        var_dump($model->save());
     //        var_dump($model->errors);
     //        die;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //            return $this->redirect(['view', 'id' => $model->id]);
         return $this->redirect(Url::previous());
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
Пример #23
0
 public function actionDelete($id)
 {
     // Find Model
     $model = ProvinceService::findById($id);
     // Delete/Render if exist
     if (isset($model)) {
         if ($model->load(Yii::$app->request->post(), 'Province') && $model->validate()) {
             try {
                 ProvinceService::delete($model);
                 return $this->redirect(Url::previous('provinces'));
             } catch (Exception $e) {
                 throw new HttpException(409, Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_DEPENDENCY));
             }
         }
         return $this->render('delete', ['model' => $model, 'returnUrl' => Url::previous("provinces")]);
     }
     // Model not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }
Пример #24
0
 public function actionDelete($id)
 {
     // Find Model
     $model = OptionService::findById($id);
     // Delete/Render if exist
     if (isset($model)) {
         if ($model->load(Yii::$app->request->post(), 'Option') && $model->validate()) {
             try {
                 OptionService::delete($model);
                 return $this->redirect(Url::previous('options'));
             } catch (Exception $e) {
                 throw new HttpException(409, Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_DEPENDENCY));
             }
         }
         return $this->render('@cmsgears/module-core/admin/views/category/option/delete', ['model' => $model, 'returnUrl' => Url::previous("options")]);
     }
     // Model not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }
Пример #25
0
 /**
  * Updates an existing Books model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         if ($model->imageFile = UploadedFile::getInstance($model, 'imageFile')) {
             $model->upload();
         }
         $model->date_update = date('Y-m-d H:i:s');
         if ($model->save(false)) {
             if (Url::previous()) {
                 return $this->redirect(Url::previous());
             }
             return $this->redirect(Url::toRoute('index'));
         }
     } else {
         Url::remember($_SERVER['HTTP_REFERER']);
         return $this->render('update', ['model' => $model]);
     }
 }
Пример #26
0
 /**
  * Обработка формы
  * Добавления комментария
  * @return bool
  */
 public function actionCreate()
 {
     $commentForm = new CommentForm();
     if (Yii::$app->user->isGuest) {
         $commentForm->scenario = CommentForm::SCENARIO_GUEST;
     }
     if (isset($_POST['CommentForm'])) {
         $commentForm->attributes = $_POST['CommentForm'];
         if ($commentForm->validate()) {
             $comment = new $commentForm->namespace();
             $comment->attributes = $commentForm->attributes;
             // Статус модерации по умолчанию
             // если не установлен, ставим требует проверки
             // Комментарии зарегистрированных пользователей публикуем без модерации
             // COMMENT_MODER_PENDING - требуется модерация
             // COMMENT_MODER_ALLOWED - без модерации
             // COMMENT_MODER_DISALLOWED - запрещена публикация
             $userModelNamespace = Yii::$app->getModule(Module::$name)->userModelNamespace;
             if (Yii::$app->user->can($userModelNamespace::ROLE_USER)) {
                 $comment->moder = Comment::COMMENT_MODER_ALLOWED;
             } else {
                 $comment->moder = $comment->moder ? $comment->moder : Comment::COMMENT_MODER_PENDING;
             }
             //$moderStatus = $comment->moder;
             /* @var $comment \app\modules\comment\models\Comment */
             if ($comment->validate()) {
                 if ($comment->save()) {
                     // Формируем сообщение
                     $comment->moderStatusMessage($comment->moder);
                     // Формируем ссылку
                     $url = $comment->id && $comment->moder == Comment::COMMENT_MODER_ALLOWED ? Url::previous() . '#comment_' . $comment->id : Url::previous();
                     // Перенаправляем на предыдущую страницу
                     return $this->redirect($url);
                 } else {
                     // Формируем сообщение
                     Yii::$app->session->setFlash('error', Module::t('module', 'FLASH_SUBMIT_COMMENT_ERROR'));
                     // Перенаправляем на предыдущую страницу
                     return $this->redirect(Url::previous());
                 }
             }
         }
     }
 }
 /**
  * Blocks the user.
  * @param  integer $id
  * @return Response
  */
 public function actionRevertToggle($id)
 {
     $model = $this->findModel($id);
     if ($model->CancelAccountID != 0) {
         //Была отменена! Нужно применить
         Yii::warning('Повторное применение ' . Html::a('операции id:' . $model->id, ['/finances/person', 'id' => $model->ContractorID]) . "\n" . Html::a("кассир №:" . Yii::$app->user->id, ['/user/admin/update', 'id' => Yii::$app->user->id]), 'info');
         if (($result = $model->apply()) === true) {
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Record was applied'));
         } else {
             Yii::$app->getSession()->setFlash('error', VarDumper::dumpAsString($model->errors));
         }
     } else {
         //Отменяем
         Yii::warning('Отмена ' . Html::a('операции id:' . $model->id, ['/finances/person', 'id' => $model->ContractorID]) . "\n" . Html::a("кассир №:" . Yii::$app->user->id, ['/user/admin/update', 'id' => Yii::$app->user->id]), 'info');
         if (($result = $model->cancel()) === true) {
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Record was reverted'));
         } else {
             Yii::$app->getSession()->setFlash('error', VarDumper::dumpAsString($model->errors));
         }
     }
     return $this->redirect(Url::previous('actions-redirect'));
 }
Пример #28
0
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     if ($model->load(\Yii::$app->request->post())) {
         $previewImage = UploadedFile::getInstance($model, 'file');
         if (!empty($previewImage) && $previewImage->tempName) {
             if ($model->validate()) {
                 $dir = $model->previewUploadPath();
                 $fileName = $model->previewFileName() . '.' . $previewImage->extension;
                 if (!empty($model->preview) && is_file($model->getPreviewPath())) {
                     unlink($model->getPreviewPath());
                 }
                 $previewImage->saveAs($dir . $fileName);
                 $model->preview = $fileName;
                 $isSaved = $model->save();
                 if (!$isSaved) {
                     \Yii::$app->session->setFlash('message', 'Ошибка сохранения');
                 }
                 return $this->redirect(Url::previous('returnUrl'));
             }
         }
     }
     return $this->render('update', ['model' => $model]);
 }
Пример #29
0
 /**
  * Deletes an existing Book model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     return $this->redirect(Url::previous('books'));
 }
Пример #30
0
 /**
  * Deletes an existing Role model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     try {
         $this->findModel($id)->delete();
     } catch (\Exception $e) {
         $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage();
         \Yii::$app->getSession()->setFlash('error', $msg);
         return $this->redirect(Url::previous());
     }
     // TODO: improve detection
     $isPivot = strstr('$id', ',');
     if ($isPivot == true) {
         return $this->redirect(Url::previous());
     } elseif (isset(\Yii::$app->session['__crudReturnUrl']) && \Yii::$app->session['__crudReturnUrl'] != '/') {
         Url::remember(null);
         $url = \Yii::$app->session['__crudReturnUrl'];
         \Yii::$app->session['__crudReturnUrl'] = null;
         return $this->redirect($url);
     } else {
         return $this->redirect(['index']);
     }
 }