示例#1
2
 public function update(AdminAction $adminAction)
 {
     /**
      * @var $model CmsTree
      */
     $model = $this->model;
     $relatedModel = $model->relatedPropertiesModel;
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         return \yii\widgets\ActiveForm::validateMultiple([$model, $relatedModel]);
     }
     if ($rr->isRequestPjaxPost()) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         if ($model->save() && $relatedModel->save()) {
             \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/cms', 'Saved'));
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->redirect($this->indexUrl);
             }
             $model->refresh();
         } else {
             $errors = [];
             if ($model->getErrors()) {
                 foreach ($model->getErrors() as $error) {
                     $errors[] = implode(', ', $error);
                 }
             }
             \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/cms', 'Could not save') . $errors);
         }
     }
     return $this->render('_form', ['model' => $model, 'relatedModel' => $relatedModel]);
 }
示例#2
1
 public function update(AdminAction $adminAction)
 {
     /**
      * @var $model CmsUser
      */
     $model = $this->model;
     $relatedModel = $model->relatedPropertiesModel;
     $passwordChange = new PasswordChangeForm(['user' => $model]);
     $passwordChange->scenario = PasswordChangeForm::SCENARION_NOT_REQUIRED;
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         $passwordChange->load(\Yii::$app->request->post());
         return \yii\widgets\ActiveForm::validateMultiple([$model, $relatedModel, $passwordChange]);
     }
     if ($rr->isRequestPjaxPost()) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         $passwordChange->load(\Yii::$app->request->post());
         if ($model->save() && $relatedModel->save()) {
             \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/cms', 'Saved'));
             if ($passwordChange->new_password) {
                 if (!$passwordChange->changePassword()) {
                     \Yii::$app->getSession()->setFlash('error', "Пароль не изменен");
                 }
             }
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->redirect($this->indexUrl);
             }
             $model->refresh();
         } else {
             $errors = [];
             if ($model->getErrors()) {
                 foreach ($model->getErrors() as $error) {
                     $errors[] = implode(', ', $error);
                 }
             }
             \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/cms', 'Could not save') . ". " . implode($errors));
         }
     }
     return $this->render('_form', ['model' => $model, 'relatedModel' => $relatedModel, 'passwordChange' => $passwordChange]);
 }
 public function update()
 {
     /**
      * @var $model SourceMessage
      */
     $model = $this->model;
     $model->initMessages();
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         Model::loadMultiple($model->messages, \Yii::$app->getRequest()->post());
         return Model::validateMultiple($model->messages);
         //return $rr->ajaxValidateForm($model);
     }
     if ($rr->isRequestPjaxPost()) {
         if (Model::loadMultiple($model->messages, \Yii::$app->getRequest()->post()) && Model::validateMultiple($model->messages)) {
             $model->saveMessages();
             //\Yii::$app->getSession()->setFlash('success', \Yii::t('app','Saved'));
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->redirect($this->indexUrl);
             }
         } else {
             //\Yii::$app->getSession()->setFlash('error', \Yii::t('app','Could not save'));
         }
     }
     return $this->render('_form', ['model' => $model]);
 }
示例#4
0
 public function run()
 {
     $model = $this->controller->model;
     $scenarios = $model->scenarios();
     if ($scenarios && $this->modelScenario) {
         if (isset($scenarios[$this->modelScenario])) {
             $model->scenario = $this->modelScenario;
         }
     }
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         return $rr->ajaxValidateForm($model);
     }
     if ($rr->isRequestPjaxPost()) {
         if ($model->load(\Yii::$app->request->post()) && $model->save($this->modelValidate)) {
             \Yii::$app->getSession()->setFlash('success', \Yii::t('app', 'Saved'));
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->controller->redirect($this->controller->indexUrl);
             }
             $model->refresh();
         } else {
             \Yii::$app->getSession()->setFlash('error', \Yii::t('app', 'Could not save'));
         }
     }
     $this->viewParams = ['model' => $model];
     return parent::run();
 }
 public function run()
 {
     $modelClassName = $this->controller->modelClassName;
     $model = new $modelClassName();
     $scenarios = $model->scenarios();
     if ($scenarios && $this->modelScenario) {
         if (isset($scenarios[$this->modelScenario])) {
             $model->scenario = $this->modelScenario;
         }
     }
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         return $rr->ajaxValidateForm($model);
     }
     if ($rr->isRequestPjaxPost()) {
         if ($model->load(\Yii::$app->request->post()) && $model->save($this->modelValidate)) {
             \Yii::$app->getSession()->setFlash('success', \Yii::t('app', 'Saved'));
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
                 return $this->controller->redirect(UrlHelper::constructCurrent()->setCurrentRef()->enableAdmin()->setRoute($this->controller->modelDefaultAction)->normalizeCurrentRoute()->addData([$this->controller->requestPkParamName => $model->{$this->controller->modelPkAttribute}])->toString());
             } else {
                 return $this->controller->redirect($this->controller->indexUrl);
             }
         } else {
             \Yii::$app->getSession()->setFlash('error', \Yii::t('app', 'Could not save'));
         }
     }
     $this->viewParams = ['model' => $model];
     return parent::run();
 }
 public function actionIndex()
 {
     $rr = new RequestResponse();
     $classComponent = \Yii::$app->request->get('component');
     $classComponentSettings = (string) \Yii::$app->request->get('settings');
     if ($classComponentSettings) {
         $classComponentSettings = unserialize(StringHelper::base64DecodeUrl($classComponentSettings));
     }
     /**
      * @var $component \skeeks\cms\relatedProperties\PropertyType;
      */
     $component = new $classComponent();
     try {
         $component->attributes = $classComponentSettings;
     } catch (\Exception $e) {
     }
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         return $rr->ajaxValidateForm($component);
     }
     $forSave = "";
     if ($rr->isRequestPjaxPost()) {
         if ($component->load(\Yii::$app->request->post())) {
             \Yii::$app->session->setFlash('success', 'Сохранено');
             $forSave = StringHelper::base64EncodeUrl(serialize($component->attributes));
         } else {
             \Yii::$app->session->setFlash('error', 'Ошибка');
         }
     }
     return $this->render($this->action->id, ["component" => $component, "forSave" => $forSave]);
 }
 public function update()
 {
     $rr = new RequestResponse();
     $model = $this->model;
     if ($post = \Yii::$app->request->post()) {
         $model->load($post);
     }
     $handler = $model->handler;
     if ($handler) {
         if ($post = \Yii::$app->request->post()) {
             $handler->load($post);
         }
     }
     if ($rr->isRequestPjaxPost()) {
         if (!\Yii::$app->request->post($this->notSubmitParam)) {
             if ($rr->isRequestPjaxPost()) {
                 $model->component_settings = $handler->toArray();
                 $handler->load(\Yii::$app->request->post());
                 if ($model->load(\Yii::$app->request->post()) && $model->validate() && $handler->validate()) {
                     $model->save();
                     \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/cms', 'Saved'));
                     if (\Yii::$app->request->post('submit-btn') == 'apply') {
                     } else {
                         return $this->redirect($this->indexUrl);
                     }
                     $model->refresh();
                 }
             }
         }
     }
     return $this->render('_form', ['model' => $model, 'handler' => $handler]);
 }
示例#8
0
 public function actionCheckTest()
 {
     $rr = new RequestResponse();
     if ($rr->isRequestAjaxPost()) {
         if (\Yii::$app->request->post('className')) {
             $className = \Yii::$app->request->post('className');
             if (!class_exists($className)) {
                 $rr->message = \Yii::t('app', 'Test is not found');
                 return (array) $rr;
             }
             if (!is_subclass_of($className, CheckComponent::className())) {
                 $rr->message = \Yii::t('app', 'Incorrect test');
                 return (array) $rr;
             }
             /**
              * @var $checkTest CheckComponent
              */
             try {
                 $checkTest = new $className();
                 if ($lastValue = \Yii::$app->request->post('lastValue')) {
                     $checkTest->lastValue = $lastValue;
                 }
                 $checkTest->run();
                 $rr->success = true;
                 $rr->data = (array) $checkTest;
             } catch (\Exception $e) {
                 $rr->message = \Yii::t('app', 'Test is not done') . ': ' . $e->getMessage();
             }
         }
     }
     return (array) $rr;
 }
 public function run()
 {
     /**
      * @var $contentElement CmsContentElement
      */
     $contentElement = $this->controller->model;
     $model = ShopProduct::find()->where(['id' => $contentElement->id])->one();
     $productPrices = [];
     if (!$model) {
         $model = new ShopProduct(['id' => $contentElement->id]);
     } else {
         if ($typePrices = ShopTypePrice::find()->where(['!=', 'def', Cms::BOOL_Y])->all()) {
             foreach ($typePrices as $typePrice) {
                 $productPrice = ShopProductPrice::find()->where(['product_id' => $model->id, 'type_price_id' => $typePrice->id])->one();
                 if (!$productPrice) {
                     $productPrice = new ShopProductPrice(['product_id' => $model->id, 'type_price_id' => $typePrice->id]);
                 }
                 if ($post = \Yii::$app->request->post()) {
                     $data = ArrayHelper::getValue($post, 'prices.' . $typePrice->id);
                     $productPrice->load($data, "");
                 }
                 $productPrices[] = $productPrice;
             }
         }
     }
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         return $rr->ajaxValidateForm($model);
     }
     if ($rr->isRequestPjaxPost()) {
         /**
          * @var $productPrice ShopProductPrice
          */
         foreach ($productPrices as $productPrice) {
             if ($productPrice->save()) {
             } else {
                 \Yii::$app->getSession()->setFlash('error', \skeeks\cms\shop\Module::t('app', 'Check the correctness of the prices'));
             }
         }
         if ($model->load(\Yii::$app->request->post()) && $model->save()) {
             \Yii::$app->getSession()->setFlash('success', 'Saved');
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->controller->redirect($this->controller->indexUrl);
             }
             $model->refresh();
         } else {
             \Yii::$app->getSession()->setFlash('error', \skeeks\cms\shop\Module::t('app', 'Failed to save'));
         }
     }
     $this->viewParams = ['model' => $model, 'productPrices' => $productPrices];
     return parent::run();
 }
示例#10
0
 /**
  * Updates an existing Game model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionChangePassword()
 {
     $model = $this->model;
     $modelForm = new PasswordChangeForm(['user' => $model]);
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         return $rr->ajaxValidateForm($modelForm);
     }
     if ($modelForm->load(\Yii::$app->request->post()) && $modelForm->changePassword()) {
         \Yii::$app->getSession()->setFlash('success', 'Успешно сохранено');
     } else {
         if (\Yii::$app->request->isPost) {
             \Yii::$app->getSession()->setFlash('error', 'Не удалось изменить пароль');
         }
     }
     return $this->render($this->action->id, ['model' => $modelForm]);
 }
示例#11
0
 public function actionViewFileEdit()
 {
     $rootViewFile = \Yii::$app->request->get('root-file');
     $model = new ViewFileEditModel(['rootViewFile' => $rootViewFile]);
     $rr = new RequestResponse();
     if ($rr->isRequestAjaxPost()) {
         if ($model->load(\Yii::$app->request->post())) {
             if (!$model->saveFile()) {
                 $rr->success = false;
                 $rr->message = "Не удалось сохранить файл.";
             }
             $rr->message = "Сохранено";
             $rr->success = true;
         }
         return $rr;
     }
     return $this->render($this->action->id, ['model' => $model]);
 }
    public function run()
    {
        $rr = new RequestResponse();
        $errors = [];
        if ($post = \Yii::$app->request->post()) {
            $this->shopFuser->load($post);
            $this->shopFuser->save();
        }
        $this->shopBuyer = $this->shopFuser->personType->createModelShopBuyer();
        $shopBuyer = $this->shopBuyer;
        if ($shopBuyer) {
            if ($post = \Yii::$app->request->post()) {
                $this->shopBuyer->load($post);
                $this->shopBuyer->relatedPropertiesModel->load($post);
            }
        }
        if ($rr->isRequestPjaxPost()) {
            if (!\Yii::$app->request->post($this->notSubmitParam)) {
                if ($this->shopFuser->validate() && $this->shopBuyer->validate() && $this->shopBuyer->relatedPropertiesModel->validate()) {
                    if ($this->shopBuyer->isNewRecord) {
                        if (!$this->shopBuyer->save()) {
                            throw new Exception('Not save buyer');
                        }
                    }
                    if (!$this->shopBuyer->relatedPropertiesModel->save()) {
                        throw new Exception('Not save buyer data');
                    }
                    $this->shopFuser->buyer_id = $this->shopBuyer->id;
                    $newOrder = ShopOrder::createOrderByFuser($this->shopFuser);
                    $orderUrl = $newOrder->publicUrl;
                    $this->view->registerJs(<<<JS
location.href='{$orderUrl}';
JS
);
                } else {
                    /*print_r($this->shopFuser->firstErrors);
                      print_r($this->shopBuyer->firstErrors);
                      print_r($this->shopBuyer->relatedPropertiesModel->firstErrors);*/
                }
            }
        }
        return $this->render($this->viewFile);
    }
示例#13
0
 public function actionBackup()
 {
     $rr = new RequestResponse();
     if ($rr->isRequestAjaxPost()) {
         try {
             ob_start();
             \Yii::$app->dbDump->dumpRun();
             $result = ob_get_clean();
             $rr->success = true;
             $rr->message = \Yii::t('app', "A copy created successfully");
             $rr->data = ['result' => $result];
         } catch (\Exception $e) {
             $rr->success = false;
             $rr->message = $e->getMessage();
         }
         return $rr;
     }
     return $rr;
 }
示例#14
0
 public function actionIndex()
 {
     $clearDirs = [['label' => 'common ' . \Yii::t('app', 'temporary files'), 'dir' => new Dir(\Yii::getAlias('@common/runtime'), false)], ['label' => 'console ' . \Yii::t('app', 'temporary files'), 'dir' => new Dir(\Yii::getAlias('@console/runtime'), false)], ['label' => 'runtime (' . \Yii::t('app', 'current site') . ')', 'dir' => new Dir(\Yii::getAlias('@runtime'), false)], ['label' => \Yii::t('app', 'Cache files') . ' (' . \Yii::t('app', 'current site') . ')', 'dir' => new Dir(\Yii::getAlias('@runtime/cache'), false)], ['label' => \Yii::t('app', 'Files debug information') . ' (' . \Yii::t('app', 'current site') . ')', 'dir' => new Dir(\Yii::getAlias('@runtime/debug'), false)], ['label' => \Yii::t('app', 'Log files') . ' (' . \Yii::t('app', 'current site') . ')', 'dir' => new Dir(\Yii::getAlias('@runtime/logs'), false)]];
     $rr = new RequestResponse();
     if ($rr->isRequestAjaxPost()) {
         foreach ($clearDirs as $data) {
             $dir = ArrayHelper::getValue($data, 'dir');
             if ($dir instanceof Dir) {
                 if ($dir->isExist()) {
                     $dir->clear();
                 }
             }
         }
         \Yii::$app->db->getSchema()->refresh();
         \Yii::$app->cache->flush();
         \Yii::$app->cms->generateModulesConfigFile();
         $rr->success = true;
         $rr->message = \Yii::t('app', 'Cache cleared');
         return $rr;
     }
     return $this->render('index', ['clearDirs' => $clearDirs]);
 }
 /**
  * Валидация данных с формы
  * @return array
  */
 public function actionValidate()
 {
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         if (\Yii::$app->request->post('sx-model') && \Yii::$app->request->post('sx-model-value')) {
             $modelClass = \Yii::$app->request->post('sx-model');
             $modelValue = \Yii::$app->request->post('sx-model-value');
             /**
              * @var $modelForm Form2Form
              */
             $modelForm = $modelClass::find()->where(['id' => $modelValue])->one();
             $modelHasRelatedProperties = $modelForm->createModelFormSend();
             if (method_exists($modelHasRelatedProperties, "createPropertiesValidateModel")) {
                 $model = $modelHasRelatedProperties->createPropertiesValidateModel();
             } else {
                 $model = $modelHasRelatedProperties->getRelatedPropertiesModel();
             }
             return $rr->ajaxValidateForm($model);
         }
     }
 }
 public function update(AdminAction $adminAction)
 {
     /**
      * @var $model CmsContentElement
      */
     $model = $this->model;
     $relatedModel = $model->relatedPropertiesModel;
     $shopProduct = ShopProduct::find()->where(['id' => $model->id])->one();
     $productPrices = [];
     if (!$shopProduct) {
         $shopProduct = new ShopProduct(['id' => $model->id]);
         $shopProduct->save();
     } else {
         if ($typePrices = ShopTypePrice::find()->where(['!=', 'def', Cms::BOOL_Y])->all()) {
             foreach ($typePrices as $typePrice) {
                 $productPrice = ShopProductPrice::find()->where(['product_id' => $shopProduct->id, 'type_price_id' => $typePrice->id])->one();
                 if (!$productPrice) {
                     $productPrice = new ShopProductPrice(['product_id' => $shopProduct->id, 'type_price_id' => $typePrice->id]);
                 }
                 if ($post = \Yii::$app->request->post()) {
                     $data = ArrayHelper::getValue($post, 'prices.' . $typePrice->id);
                     $productPrice->load($data, "");
                 }
                 $productPrices[] = $productPrice;
             }
         }
     }
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         $shopProduct->load(\Yii::$app->request->post());
         return \yii\widgets\ActiveForm::validateMultiple([$model, $relatedModel, $shopProduct]);
     }
     if ($rr->isRequestPjaxPost()) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         $shopProduct->load(\Yii::$app->request->post());
         /**
          * @var $productPrice ShopProductPrice
          */
         foreach ($productPrices as $productPrice) {
             if ($productPrice->save()) {
             } else {
                 \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/shop/app', 'Check the correctness of the prices'));
             }
         }
         if ($model->save() && $relatedModel->save() && $shopProduct->save()) {
             \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/shop/app', 'Saved'));
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->redirect($this->indexUrl);
             }
             $model->refresh();
         } else {
             $errors = [];
             if ($model->getErrors()) {
                 foreach ($model->getErrors() as $error) {
                     $errors[] = implode(', ', $error);
                 }
             }
             \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/shop/app', 'Could not save') . $errors);
         }
     }
     if (!$shopProduct->baseProductPrice) {
         $baseProductPrice = new ShopProductPrice(['type_price_id' => \Yii::$app->shop->baseTypePrice->id, 'currency_code' => \Yii::$app->money->currencyCode, 'product_id' => $model->id]);
         $baseProductPrice->save();
     }
     return $this->render('_form', ['model' => $model, 'relatedModel' => $relatedModel, 'shopProduct' => $shopProduct, 'productPrices' => $productPrices, 'baseProductPrice' => $shopProduct->getBaseProductPrice()->one()]);
 }
示例#17
0
 /**
  * @param $username
  * @return string
  */
 public function actionEditInfo()
 {
     $model = $this->user;
     $rr = new RequestResponse();
     if ($rr->isRequestOnValidateAjaxForm()) {
         return $rr->ajaxValidateForm($model);
     }
     if ($rr->isRequestAjaxPost()) {
         if ($model->load(\Yii::$app->request->post()) && $model->save()) {
             $rr->success = true;
             $rr->message = 'Данные успешно сохранены';
         } else {
             $rr->message = 'Не получилось сохранить данные';
         }
         return $rr;
     }
     return $this->render($this->action->id);
 }
 public function createOrder()
 {
     $cmsUser = null;
     if ($userId = \Yii::$app->request->get('cmsUserId')) {
         $cmsUser = CmsUser::findOne($userId);
     }
     if ($cmsUser) {
         /**
          * @var $shopFuser ShopFuser
          */
         $shopFuser = ShopFuser::getInstanceByUser($cmsUser);
         $model = $shopFuser;
         $rr = new RequestResponse();
         if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
             $model->scenario = ShopFuser::SCENARIO_CREATE_ORDER;
             return $rr->ajaxValidateForm($model);
         }
         if ($rr->isRequestPjaxPost()) {
             try {
                 if ($model->load(\Yii::$app->request->post()) && $model->save()) {
                     $model->scenario = ShopFuser::SCENARIO_CREATE_ORDER;
                     if ($model->validate()) {
                         $order = ShopOrder::createOrderByFuser($model);
                         if (!$order->isNewRecord) {
                             \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/shop/app', 'The order #{order_id} created successfully', ['order_id' => $order->id]));
                             if (\Yii::$app->request->post('submit-btn') == 'apply') {
                                 return $this->redirect(UrlHelper::constructCurrent()->setCurrentRef()->enableAdmin()->setRoute($this->modelDefaultAction)->normalizeCurrentRoute()->addData([$this->requestPkParamName => $order->id])->toString());
                             } else {
                                 return $this->redirect($this->indexUrl);
                             }
                         } else {
                             throw new Exception(\Yii::t('skeeks/shop/app', 'Incorrect data of the new order') . ": " . array_shift($order->getFirstErrors()));
                         }
                     } else {
                         throw new Exception(\Yii::t('skeeks/shop/app', 'Not enogh data for ordering') . ": " . array_shift($model->getFirstErrors()));
                     }
                 } else {
                     throw new Exception(\Yii::t('skeeks/shop/app', 'Could not save'));
                 }
             } catch (\Exception $e) {
                 \Yii::$app->getSession()->setFlash('error', $e->getMessage());
             }
         }
         return $this->render($this->action->id, ['cmsUser' => $cmsUser, 'shopFuser' => $model]);
     } else {
         return $this->render($this->action->id . "-select-user");
     }
 }
示例#19
0
 /**
  * Валидация данных с формы
  * @return array
  */
 public function actionShopPersonTypeValidate()
 {
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         if (\Yii::$app->request->post('shop_person_type_id')) {
             $shop_person_type_id = \Yii::$app->request->post('shop_person_type_id');
             /**
              * @var $shopPersonType ShopPersonType
              */
             $shopPersonType = ShopPersonType::find()->active()->andWhere(['id' => $shop_person_type_id])->one();
             if (!$shopPersonType) {
                 $rr->message = \skeeks\cms\shop\Module::t('app', 'This payer is disabled or deleted. Refresh the page.');
                 $rr->success = false;
                 return $rr;
             }
             $modelHasRelatedProperties = $shopPersonType->createModelShopBuyer();
             if (method_exists($modelHasRelatedProperties, "createPropertiesValidateModel")) {
                 $model = $modelHasRelatedProperties->createPropertiesValidateModel();
             } else {
                 $model = $modelHasRelatedProperties->getRelatedPropertiesModel();
             }
             return $rr->ajaxValidateForm($model);
         }
     }
 }
示例#20
0
 /**
  * @return array
  */
 public function actionPayValidate()
 {
     $rr = new RequestResponse();
     return $rr->ajaxValidateForm($this->model);
 }
示例#21
0
 /**
  * @return RequestResponse
  */
 public function actionFormValidate()
 {
     $v3toysMessage = new V3toysMessage();
     $v3toysMessage->loadDefaultValues();
     if ($elementId = \Yii::$app->request->post('element_id')) {
         $v3toysMessage->addProduct($elementId);
     }
     $rr = new RequestResponse();
     return $rr->ajaxValidateForm($v3toysMessage);
 }
 public function actionSubmit()
 {
     $rr = new RequestResponse();
     $model = new Reviews2Message();
     if ($rr->isRequestOnValidateAjaxForm()) {
         return $rr->ajaxValidateForm($model);
     }
     if ($rr->isRequestAjaxPost()) {
         $model->scenario = Reviews2Message::SCENARIO_SITE_INSERT;
         $model->page_url = \Yii::$app->request->referrer;
         if ($model->load(\Yii::$app->request->post())) {
             //Проверка на максимальное количество отзывов к одному посту от одного пользователя.
             $messagesFind = Reviews2Message::find();
             if (\Yii::$app->user->isGuest) {
                 $messagesFind->andWhere(['ip' => \Yii::$app->request->userIP])->andWhere(['or', ['created_by' => null], ['created_by' => '']]);
             } else {
                 $messagesFind->andWhere(['created_by' => \Yii::$app->user->identity->id]);
             }
             $messagesFind2 = clone $messagesFind;
             $messagesFind->andWhere(['status' => Reviews2Message::STATUS_ALLOWED])->andWhere(['element_id' => $model->element_id]);
             if (\Yii::$app->reviews2->maxCountMessagesForUser != 0) {
                 if ($messagesFind->count() >= \Yii::$app->reviews2->maxCountMessagesForUser) {
                     $rr->success = false;
                     $rr->message = \Yii::t('skeeks/reviews2', "You have already added a review for this post earlier.");
                     return $rr;
                 }
             }
             //Проверка частоты добавления отзывов
             if (\Yii::$app->reviews2->securityEnabledRateLimit == Cms::BOOL_Y) {
                 $messagesFind2 = Reviews2Message::find();
                 if (\Yii::$app->user->isGuest) {
                     $messagesFind2->andWhere(['ip' => \Yii::$app->request->userIP]);
                 } else {
                     $messagesFind2->andWhere(['created_by' => \Yii::$app->user->identity->id]);
                 }
                 $lastTime = \Yii::$app->formatter->asTimestamp(time()) - (int) \Yii::$app->reviews2->securityRateLimitTime;
                 $messagesFind2->andWhere(['>=', 'created_at', $lastTime]);
                 //print_r($messagesFind2->createCommand()->rawSql);die;
                 if ($messagesFind2->count() >= \Yii::$app->reviews2->securityRateLimitRequests) {
                     $rr->success = false;
                     $rr->message = \Yii::t('skeeks/reviews2', "You too often add reviews.");
                     return $rr;
                 }
             }
             if ($model->save()) {
                 $rr->success = true;
                 if (\Yii::$app->reviews2->enabledBeforeApproval == Cms::BOOL_Y) {
                     $rr->message = \Yii::$app->reviews2->messageSuccessBeforeApproval;
                 } else {
                     $rr->message = \Yii::$app->reviews2->messageSuccess;
                     //Отключена предмодерация, сразу публикуем
                     $model->status = Reviews2Message::STATUS_ALLOWED;
                     $model->save();
                 }
                 $model->notifyCreate();
             } else {
                 $rr->success = false;
                 $rr->message = \Yii::t('skeeks/reviews2', "Review not added") . ": " . implode(",", $model->getFirstErrors());
             }
         } else {
             $rr->success = false;
             $rr->message = \Yii::t('skeeks/reviews2', "Review not added") . ": " . implode(",", $model->getFirstErrors());
         }
     }
     return $rr;
 }
示例#23
0
 /**
  * Deletes an existing Game model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @return mixed
  */
 public function actionDelete()
 {
     $rr = new RequestResponse();
     if ($rr->isRequestAjaxPost()) {
         try {
             if ($this->model->delete()) {
                 $rr->message = \Yii::t('app', 'Record deleted successfully');
                 $rr->success = true;
             } else {
                 $rr->message = \Yii::t('app', 'Record deleted unsuccessfully');
                 $rr->success = false;
             }
         } catch (\Exception $e) {
             $rr->message = $e->getMessage();
             $rr->success = false;
         }
         return (array) $rr;
     }
 }
 public function actionSubmit()
 {
     $rr = new RequestResponse();
     $model = new Comments2Message();
     if ($rr->isRequestOnValidateAjaxForm()) {
         return $rr->ajaxValidateForm($model);
     }
     if ($rr->isRequestAjaxPost()) {
         $model->scenario = Comments2Message::SCENARIO_SITE_INSERT;
         $model->page_url = \Yii::$app->request->referrer;
         if ($model->load(\Yii::$app->request->post())) {
             //Проверка на максимальное количество комментариев к одному посту от одного пользователя.
             $messagesFind = Comments2Message::find();
             if (\Yii::$app->user->isGuest) {
                 $messagesFind->andWhere(['ip' => Request::getRealUserIp()]);
             } else {
                 $messagesFind->andWhere(['created_by' => \Yii::$app->user->identity->id]);
             }
             $messagesFind2 = clone $messagesFind;
             $messagesFind->andWhere(['status' => Comments2Message::STATUS_ALLOWED])->andWhere(['element_id' => $model->element_id]);
             if (\Yii::$app->comments2->maxCountMessagesForUser != 0) {
                 if ($messagesFind->count() >= \Yii::$app->comments2->maxCountMessagesForUser) {
                     $rr->success = false;
                     $rr->message = \skeeks\cms\comments2\Module::t('app', 'You have already added a comment on this post before.');
                     return $rr;
                 }
             }
             //Проверка частоты добавления комментариев
             if (\Yii::$app->comments2->securityEnabledRateLimit == Cms::BOOL_Y) {
                 $messagesFind2 = Comments2Message::find();
                 if (\Yii::$app->user->isGuest) {
                     $messagesFind2->andWhere(['ip' => Request::getRealUserIp()]);
                 } else {
                     $messagesFind2->andWhere(['created_by' => \Yii::$app->user->identity->id]);
                 }
                 $lastTime = \Yii::$app->formatter->asTimestamp(time()) - (int) \Yii::$app->comments2->securityRateLimitTime;
                 $messagesFind2->andWhere(['>=', 'created_at', $lastTime]);
                 //print_r($messagesFind2->createCommand()->rawSql);die;
                 if ($messagesFind2->count() >= \Yii::$app->comments2->securityRateLimitRequests) {
                     $rr->success = false;
                     $rr->message = \skeeks\cms\comments2\Module::t('app', 'You too often add comments.');
                     return $rr;
                 }
             }
             if ($model->save()) {
                 $rr->success = true;
                 if (\Yii::$app->comments2->enabledBeforeApproval == Cms::BOOL_Y) {
                     $rr->message = \Yii::$app->comments2->messageSuccessBeforeApproval;
                 } else {
                     $rr->message = \Yii::$app->comments2->messageSuccess;
                     //Отключена предмодерация, сразу публикуем
                     $model->status = Comments2Message::STATUS_ALLOWED;
                     $model->scenario = ActiveRecord::SCENARIO_DEFAULT;
                     $model->save();
                 }
                 $model->notifyCreate();
             } else {
                 $rr->success = false;
                 $rr->message = \skeeks\cms\comments2\Module::t('app', 'You comments not added') . ": " . implode(",", $model->getFirstErrors());
             }
         } else {
             $rr->success = false;
             $rr->message = \skeeks\cms\comments2\Module::t('app', 'You comments not added') . ": " . implode(",", $model->getFirstErrors());
         }
     }
     return $rr;
 }
示例#25
0
 public function actionAuth()
 {
     $this->view->title = \Yii::t('app', 'Authorization');
     $this->layout = '@skeeks/cms/modules/admin/views/layouts/unauthorized.php';
     $goUrl = "";
     $loginModel = new LoginFormUsernameOrEmail();
     $passwordResetModel = new PasswordResetRequestFormEmailOrLogin();
     if ($ref = UrlHelper::getCurrent()->getRef()) {
         $goUrl = $ref;
     }
     $rr = new RequestResponse();
     if (!\Yii::$app->user->isGuest) {
         return $goUrl ? $this->redirect($goUrl) : $this->goHome();
     }
     //Авторизация
     if (\Yii::$app->request->post('do') == 'login') {
         if ($rr->isRequestOnValidateAjaxForm()) {
             return $rr->ajaxValidateForm($loginModel);
         }
         if ($rr->isRequestAjaxPost()) {
             if ($loginModel->load(\Yii::$app->request->post()) && $loginModel->login()) {
                 if (!$goUrl) {
                     $goUrl = Yii::$app->getUser()->getReturnUrl($defaultUrl);
                 }
                 $rr->redirect = $goUrl;
                 $rr->success = true;
                 $rr->message = "";
                 $rr->message = "";
                 return (array) $rr;
             } else {
                 $rr->success = false;
                 $rr->message = \Yii::t('app', "Unsuccessful attempt authorization");
                 return (array) $rr;
             }
         }
     }
     //Запрос на сброс пароля
     if (\Yii::$app->request->post('do') == 'password-reset') {
         if ($rr->isRequestOnValidateAjaxForm()) {
             return $rr->ajaxValidateForm($passwordResetModel);
         }
         if ($rr->isRequestAjaxPost()) {
             if ($passwordResetModel->load(\Yii::$app->request->post()) && $passwordResetModel->sendEmail()) {
                 $rr->success = true;
                 $rr->message = \Yii::t('app', "Check your email address");
                 return (array) $rr;
             } else {
                 $rr->success = false;
                 $rr->message = \Yii::t('app', "Failed send email");
                 return (array) $rr;
             }
         }
     }
     return $this->render('auth', ['loginModel' => $loginModel, 'passwordResetModel' => $passwordResetModel, 'goUrl' => $goUrl]);
 }
示例#26
0
 /**
  * Deletes an existing Game model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @return mixed
  */
 public function actionDelete()
 {
     $rr = new RequestResponse();
     if ($rr->isRequestAjaxPost()) {
         try {
             $model = $this->model;
             $id = $model->name;
             $model = $this->findModel($id);
             if (!in_array($model->item->name, CmsManager::protectedPermissions())) {
                 if (\Yii::$app->getAuthManager()->remove($model->item)) {
                     $rr->message = \Yii::t('app', 'Record deleted successfully');
                     $rr->success = true;
                 } else {
                     $rr->message = \Yii::t('app', 'Record deleted unsuccessfully');
                     $rr->success = false;
                 }
             } else {
                 $rr->message = \Yii::t('app', 'This entry can not be deleted!');
                 $rr->success = false;
             }
         } catch (\Exception $e) {
             $rr->message = $e->getMessage();
             $rr->success = false;
         }
         return (array) $rr;
     }
 }
示例#27
0
 /**
  * Восстановлеине пароля
  * @return string|Response
  */
 public function actionRegisterByEmail()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $rr = new RequestResponse();
     $model = new SignupForm();
     $model->scenario = SignupForm::SCENARION_ONLYEMAIL;
     //Запрос на валидацию ajax формы
     if ($rr->isRequestOnValidateAjaxForm()) {
         return $rr->ajaxValidateForm($model);
     }
     //Запрос ajax post
     if ($rr->isRequestAjaxPost()) {
         if ($model->load(\Yii::$app->request->post()) && ($registeredUser = $model->signup())) {
             $rr->success = true;
             $rr->message = 'Для дальнейших действий, проверьте вашу почту.';
             return $rr;
         } else {
             $rr->message = 'Не удалось зарегистрироваться';
         }
         return (array) $rr;
     }
     return $this->render('register', ['model' => $model]);
 }
示例#28
0
 /**
  * @return string
  */
 public function actionCheckoutValidate()
 {
     $rr = new RequestResponse();
     $v3toysOrder = V3toysOrder::createCurrent();
     return $rr->ajaxValidateForm($v3toysOrder);
 }
示例#29
0
 /**
  * Прикрепить к моделе другой файл
  * @see skeeks\cms\widgets\formInputs\StorageImage
  * @return RequestResponse
  */
 public function actionLinkToModels()
 {
     $rr = new RequestResponse();
     if ($rr->isRequestAjaxPost()) {
         try {
             if (!\Yii::$app->request->post('file_id') || !\Yii::$app->request->post('modelId') || !\Yii::$app->request->post('modelClassName') || !\Yii::$app->request->post('modelRelation')) {
                 throw new \yii\base\Exception("Не достаточно входных данных");
             }
             $file = CmsStorageFile::findOne(\Yii::$app->request->post('file_id'));
             if (!$file) {
                 throw new \yii\base\Exception("Возможно файл уже удален или не загрузился");
             }
             if (!is_subclass_of(\Yii::$app->request->post('modelClassName'), ActiveRecord::className())) {
                 throw new \yii\base\Exception("Невозможно привязать файл к этой моделе");
             }
             $className = \Yii::$app->request->post('modelClassName');
             /**
              * @var $model ActiveRecord
              */
             $model = $className::findOne(\Yii::$app->request->post('modelId'));
             if (!$model) {
                 throw new \yii\base\Exception("Модель к которой необходимо привязать файл не найдена");
             }
             if (!$model->hasProperty(\Yii::$app->request->post('modelRelation'))) {
                 throw new \yii\base\Exception("У модели не найден атрибут привязки к файлам modelRelation: " . \Yii::$app->request->post('modelRelation'));
             }
             try {
                 $model->link(\Yii::$app->request->post('modelRelation'), $file);
                 if (!$file->name) {
                     $file->name = $model->name;
                     $file->save(false);
                 }
                 $rr->success = true;
                 $rr->message = "";
             } catch (\Exception $e) {
                 $rr->success = false;
                 $rr->message = $e->getMessage();
             }
         } catch (\Exception $e) {
             $rr->success = false;
             $rr->message = $e->getMessage();
         }
     }
     return $rr;
 }
 public function actionRemove()
 {
     $component = $this->_component;
     $rr = new RequestResponse();
     if ($rr->isRequestAjaxPost()) {
         if (\Yii::$app->request->post('do') == 'all') {
             if ($settings = \skeeks\cms\models\CmsComponentSettings::baseQuery($component)->all()) {
                 /**
                  * @var $setting CmsComponentSettings
                  */
                 foreach ($settings as $setting) {
                     //TODO: добавить отладочную информацию.
                     if ($setting->delete()) {
                     }
                 }
                 $component->invalidateCache();
                 $rr->message = 'Настройки успешно удалены';
                 $rr->success = true;
             }
         } else {
             if (\Yii::$app->request->post('do') == 'default') {
                 if ($settings = \skeeks\cms\models\CmsComponentSettings::fetchByComponentDefault($component)) {
                     $settings->delete();
                     $component->invalidateCache();
                     $rr->message = 'Настройки успешно удалены';
                     $rr->success = true;
                 }
             } else {
                 if (\Yii::$app->request->post('do') == 'sites') {
                     if ($settings = \skeeks\cms\models\CmsComponentSettings::baseQuerySites($component)->all()) {
                         /**
                          * @var $setting CmsComponentSettings
                          */
                         foreach ($settings as $setting) {
                             //TODO: добавить отладочную информацию.
                             if ($setting->delete()) {
                             }
                         }
                         $component->invalidateCache();
                         $rr->message = 'Настройки успешно удалены';
                         $rr->success = true;
                     }
                 } else {
                     if (\Yii::$app->request->post('do') == 'users') {
                         if ($settings = \skeeks\cms\models\CmsComponentSettings::baseQueryUsers($component)->all()) {
                             /**
                              * @var $setting CmsComponentSettings
                              */
                             foreach ($settings as $setting) {
                                 //TODO: добавить отладочную информацию.
                                 if ($setting->delete()) {
                                 }
                             }
                             $component->invalidateCache();
                             $rr->message = 'Настройки успешно удалены';
                             $rr->success = true;
                         }
                     } else {
                         if (\Yii::$app->request->post('do') == 'site') {
                             $code = \Yii::$app->request->post('code');
                             $site = CmsSite::find()->where(['code' => $code])->one();
                             if ($site) {
                                 if ($settings = \skeeks\cms\models\CmsComponentSettings::fetchByComponentSite($component, $site)) {
                                     $settings->delete();
                                     $component->invalidateCache();
                                     $rr->message = 'Настройки успешно удалены';
                                     $rr->success = true;
                                 }
                             }
                         } else {
                             if (\Yii::$app->request->post('do') == 'user') {
                                 $id = \Yii::$app->request->post('id');
                                 $user = User::find()->where(['id' => $id])->one();
                                 if ($user) {
                                     if ($settings = \skeeks\cms\models\CmsComponentSettings::fetchByComponentUser($component, $user)) {
                                         $settings->delete();
                                         $component->invalidateCache();
                                         $rr->message = 'Настройки успешно удалены';
                                         $rr->success = true;
                                     }
                                 }
                             } else {
                                 $rr->message = 'Все настройки удалены';
                                 $rr->success = true;
                             }
                         }
                     }
                 }
             }
         }
         return (array) $rr;
     }
     return $this->render($this->action->id, ['component' => $component]);
 }