Пример #1
1
 /**
  * Creates a new model.
  * @return \yii\db\ActiveRecordInterface the model newly created
  * @throws \Exception if there is any error when creating the model
  */
 public function run()
 {
     if ($this->checkAccess) {
         call_user_func($this->checkAccess, $this->id);
     }
     /**
      * @var \yii\db\ActiveRecord $model
      */
     $model = new $this->modelClass(['scenario' => $this->scenario]);
     $model->load(Yii::$app->getRequest()->getBodyParams(), '');
     $model->on('afterInsert', array('backend\\eventListener\\SaveRelatedListener', 'saveRelated'));
     $model->on('beforeValidate', array('backend\\eventListener\\SaveRelatedListener', 'beforeValidate'));
     if ($model->validate()) {
         $transaction = $model->getDb()->beginTransaction();
         try {
             $model->insert(false);
             $transaction->commit();
         } catch (\Exception $e) {
             $transaction->rollback();
             throw $e;
         }
     }
     if (!$model->hasErrors()) {
         $response = Yii::$app->getResponse();
         $response->setStatusCode(201);
         $id = implode(',', array_values($model->getPrimaryKey(true)));
         $response->getHeaders()->set('Location', Url::toRoute([$this->viewAction, 'id' => $id], true));
     }
     $model->refresh();
     return $model;
 }
Пример #2
0
 public function run()
 {
     if (empty($this->name) && (!empty($this->model) && !empty($this->attribute))) {
         $this->name = Html::getInputName($this->model, $this->attribute);
     }
     if (empty($this->url)) {
         $this->url = Url::toRoute(['site/upload']);
     }
     $options = ['url' => $this->url, 'paramName' => $this->name, 'params' => []];
     if (Yii::$app->request->enableCsrfValidation) {
         $options['params'][Yii::$app->request->csrfParam] = Yii::$app->request->getCsrfToken();
     }
     if (!empty($this->message)) {
         $message = Html::tag('div', $this->message, $this->messageOptions);
     } else {
         $message = '';
     }
     $this->htmlOptions['id'] = $this->id;
     $this->options = ArrayHelper::merge($this->options, $options);
     echo Html::tag('div', $message, $this->htmlOptions);
     $this->registerAssets();
     $this->createDropzone();
     foreach ($this->eventHandlers as $event => $handler) {
         $handler = new \yii\web\JsExpression($handler);
         $this->getView()->registerJs($this->dropzoneName . ".on('{$event}', {$handler})");
     }
     $this->addFiles($this->storedFiles);
     $this->decrementMaxFiles(count($this->storedFiles));
     if ($this->sortable) {
         $options = Json::encode($this->sortableOptions);
         $this->getView()->registerJs("jQuery('#{$this->id}').sortable(" . $options . ");");
     }
 }
Пример #3
0
 /**
  * Creates a new model.
  * @return \yii\db\ActiveRecordInterface the model newly created
  * @throws \Exception if there is any error when creating the model
  */
 public function run()
 {
     if ($this->checkAccess) {
         call_user_func($this->checkAccess, $this->id);
     }
     /**
      * @var \yii\db\ActiveRecord $model
      */
     $model = new $this->modelClass(['scenario' => $this->scenario]);
     $model->load(Yii::$app->getRequest()->getBodyParams(), '');
     $folder = \Yii::$app->getRequest()->getQueryParam('folder');
     $isPrivate = \Yii::$app->getRequest()->getQueryParam('is_private');
     $model->setAttribute('folder', $folder);
     $storageId = Yii::$app->get('settings')->get('File.storageId');
     /** @var StorageInterface $storage */
     $storage = $this->controller->module->getStorage($storageId);
     $storage->upload($model, 'file', $isPrivate);
     $model->on('afterInsert', array('backend\\eventListener\\SaveRelatedListener', 'saveRelated'));
     $model->on('beforeValidate', array('backend\\eventListener\\SaveRelatedListener', 'beforeValidate'));
     $model->on('afterInsert', array('backend\\modules\\file\\eventListener\\ResizeLogoFIle', 'createSpecialLogo'));
     $model->on('afterUpdate', array('backend\\modules\\file\\eventListener\\ResizeLogoFIle', 'createSpecialLogo'));
     $model->save();
     $model->afterFind();
     if (!$model->hasErrors()) {
         $response = Yii::$app->getResponse();
         $response->setStatusCode(201);
         $id = implode(',', array_values($model->getPrimaryKey(true)));
         $response->getHeaders()->set('Location', Url::toRoute([$this->viewAction, 'id' => $id], true));
     }
     return $model;
 }
Пример #4
0
 public function run()
 {
     $this->controller->layout = empty($this->controller->updateLayoutFile) ? $this->layoutFile : $this->controller->updateLayoutFile;
     $id = Yii::$app->request->get($this->idAttribute, 0);
     if ($id == 0) {
         $this->controller->{$this->returnFailMethod}($this->returnBadParamMsg, [], $this->extraReturnParam);
     }
     $model = new $this->modelClass();
     $model = $model::findOne($id);
     $model->setScenario($this->scenarioName);
     if (!empty($model)) {
         if (!empty(Yii::$app->request->post($model->formName()))) {
             if ($model->load(Yii::$app->request->post()) && $model->validate()) {
                 $model->save();
                 $this->controller->{$this->returnSuccessMethod}($this->returnSuccessMsg, Url::toRoute($this->redirectRoute), $this->extraReturnParam);
             } else {
                 $this->controller->{$this->returnFailMethod}($this->returnFailMsg, $model->getErrors(), $this->extraReturnParam);
             }
         } else {
             return $this->controller->render($this->viewFile, ['model' => $model]);
         }
     } else {
         $this->controller->{$this->returnFailMethod}($this->returnObjectNotExistMsg);
     }
 }
 public function actionSave($languageId = null, $categoryId = null)
 {
     if (!empty($categoryId)) {
         $category = Category::findOne($categoryId);
         $category_translation = CategoryTranslation::find()->where(['category_id' => $categoryId, 'language_id' => $languageId])->one();
         if (empty($category_translation)) {
             $category_translation = new CategoryTranslation();
         }
     } else {
         $category = new Category();
         $category_translation = new CategoryTranslation();
     }
     if (Yii::$app->request->isPost) {
         $category->load(Yii::$app->request->post());
         $category_translation->load(Yii::$app->request->post());
         if ($category->validate() && $category_translation->validate()) {
             $category->save();
             $category_translation->category_id = $category->id;
             $category_translation->language_id = $languageId;
             $category_translation->save();
             Yii::$app->getSession()->setFlash('success', 'Data were successfully modified.');
             return $this->redirect(Url::toRoute('/articles/category'));
         } else {
             Yii::$app->getSession()->setFlash('danger', 'Failed to change the record.');
         }
     }
     return $this->render('edit', ['category' => $category, 'category_translation' => $category_translation, 'categories' => Category::find()->with('translations')->all(), 'selectedLanguage' => Language::findOne($languageId), 'languages' => Language::findAll(['active' => true])]);
 }
Пример #6
0
    protected static function getNavBar($items, $cur_url, $class = 'sidebar')
    {
        $count = count($items);
        $i = 0;
        $line = '<ul class="' . $class . '-menu">';
        foreach ($items as $item) {
            $icon_class = $item['icon_class'];
            if (isset($item['url']) && $item['url'] != '') {
                $active = self::checkSelected($item['url'], $cur_url);
                $url = $item['url'];
                $url = Url::toRoute($url);
                $line = $line . '<li class="' . $active . '">
								<a href="' . $url . '"><span class="fa ' . $icon_class . '"></span>' . $item['label'] . '</a>
							</li>';
            } else {
                $active = self::checkSelected($item['items'], $cur_url);
                $line = $line . '<li class="treeview ' . $active . '">
								<a href="#">
								<i class="fa ' . $icon_class . '"></i> <span>' . $item['label'] . '</span>
								<i class="fa fa-angle-left pull-right"></i>
							</a>';
                $line = $line . self::getNavBar($item['items'], $cur_url, 'treeview');
            }
            $line = $line . '</li>';
            $i++;
            if ($i == $count) {
                $line = $line . '</ul>';
            }
        }
        return $line;
    }
Пример #7
0
 /**
  * 提现操作
  * @return type
  */
 public function actionTixian()
 {
     $model = new CashForm();
     if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
         #调有存储过程冻结资金并生成订单
         try {
             $addip = \Yii::$app->request->userIP;
             $user_id = \Yii::$app->user->getId();
             $money = $model->money;
             $conn = \Yii::$app->db;
             $command = $conn->createCommand('call p_apply_Cash(:in_p_user_id,:money,:in_addip,@out_status,@out_remark)');
             $command->bindParam(":in_p_user_id", $user_id, PDO::PARAM_INT);
             $command->bindParam(":money", $money, PDO::PARAM_STR);
             $command->bindParam(":in_addip", $addip, PDO::PARAM_STR, 50);
             $command->execute();
             $fit = $conn->createCommand("select @out_status as status,@out_remark as remark")->queryOne();
         } catch (Exception $e) {
             $fit = ['remark' => '系统繁忙,暂时无法处理', 'status' => 0];
         }
         if ($fit['status'] == 0) {
             $msgtitle = '操作失败';
         } else {
             $msgtitle = '操作成功';
         }
         $notices = array('type' => 3, 'msgtitle' => $msgtitle, 'message' => $fit['remark'], 'backurl' => Url::toRoute('/member/account/tixian'), 'backtitle' => '返回', 'tourl' => Url::toRoute('/member/account/index/index'), 'totitle' => '会员中心');
         \Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
         $this->redirect(Url::toRoute('/public/notices'));
         \Yii::$app->end();
     } else {
         return $this->render('account_tixian', ['model' => $model]);
     }
 }
Пример #8
0
 public function getUrl($url)
 {
     if ($url === "") {
         $url = "/";
     }
     return Url::toRoute($url);
 }
Пример #9
0
 /**
  * Updates an existing model or creates a new one if $id is null.
  * @param string $id the primary key of the model.
  * @return \yii\db\ActiveRecordInterface the model being updated
  * @throws ServerErrorHttpException if there is any error when updating the model
  */
 public function run($id, $enable = null)
 {
     $model = $this->findModel($id);
     if ($this->checkAccess) {
         call_user_func($this->checkAccess, $this->id, $model);
     }
     if ($enable !== null) {
         $enable = (bool) $enable;
     }
     /** @var \nineinchnick\audit\behaviors\TrackableBehavior $trackable */
     if (($trackable = $model->getBehavior('trackable')) !== null) {
         $trackable->beginChangeset();
     }
     $model->toggle($enable);
     if ($trackable !== null) {
         $trackable->endChangeset();
     }
     $response = Yii::$app->getResponse();
     $response->setStatusCode($enable ? 205 : 204);
     if ($enable) {
         $message = Yii::t('app', '<strong>Success!</strong> Record has been restored.');
     } else {
         $message = Yii::t('app', '<strong>Success!</strong> Record has been disabled.');
     }
     $this->setFlash('success', $message);
     $id = $this->exportKey($model->getPrimaryKey(true));
     $response->getHeaders()->set('Location', Url::toRoute([$this->viewAction, 'id' => $id], true));
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $script = '
     $(document).ready(function(){
         function hideFirstLast() {
             $(\'.sort-up, .sort-down\').show();
             $(\'.sort-up\').first().hide();
             $(\'.sort-down\').last().hide();
         }
         function refresh() {
             $(\'#' . $this->grid->id . '\').yiiGridView("applyFilter");
             hideFirstLast();
         }
         $(\'.sort-up\').on(\'click\', function(){
             var id = $(this).parent().parent().attr(\'data-key\');
             $.post("' . Url::toRoute(['swap']) . '?id="+id+"&dir=up").always(refresh);
             return false;
         });
         $(\'.sort-down\').on(\'click\' ,function(){
             var id = $(this).parent().parent().attr(\'data-key\');
             $.post("' . Url::toRoute(['swap']) . '?id="+id+"&dir=down").always(refresh);
             return false;
         });
         hideFirstLast();
     });';
     $this->grid->getView()->registerJs($script);
 }
 /**
  * Регистрация
  * @return array|string|Response
  */
 public function actionSignup()
 {
     $user = new models\User(['scenario' => 'signup']);
     $profile = new models\Profile(['scenario' => 'signup']);
     if ($user->load(Yii::$app->request->post()) && $profile->load(Yii::$app->request->post())) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation('profile', $profile);
             if ($user->save(false)) {
                 if ($this->module->requireEmailConfirmation === true) {
                     Yii::$app->consoleRunner->run('users/control/send-email ' . $user->email . ' signup "' . Yii::t('users', 'SUBJECT_SIGNUP') . '"');
                     Yii::$app->session->setFlash('success', Yii::t('users', 'SUCCESS_SIGNUP_WITHOUT_LOGIN', ['url' => Url::toRoute('resend')]));
                 } else {
                     Yii::$app->user->login($user);
                     Yii::$app->session->setFlash('success', Yii::t('users', 'SUCCESS_SIGNUP_WITH_LOGIN'));
                 }
                 return $this->redirect(['login']);
             } else {
                 Yii::$app->session->setFlash('danger', Yii::t('users', 'FAIL_SIGNUP'));
                 return $this->refresh();
             }
         } else {
             if (Yii::$app->request->isAjax) {
                 Yii::$app->response->format = Response::FORMAT_JSON;
                 return ActiveForm::validate($user);
             }
         }
     }
     return $this->render('signup', ['user' => $user, 'profile' => $profile]);
 }
Пример #12
0
 public function getUrl()
 {
     if ($this->_ajaxUrl === null) {
         $this->_ajaxUrl = Url::toRoute($this->url);
     }
     return $this->_ajaxUrl;
 }
Пример #13
0
 public function actionBroker()
 {
     if (Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = Broker::findOne(Yii::$app->user->identity->getId());
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate() && $model->getDirtyAttributes()) {
             $mes = [];
             foreach ($model->getDirtyAttributes() as $k => $v) {
                 if ($k == 'name' && $model->type_id == 1) {
                     $mes[$k] = [Yii::t('app', 'Full name'), $model->name];
                 } else {
                     $mes[$k] = [$model->getAttributeLabel($k), $model->{$k}];
                 }
             }
             $message = "";
             foreach ($mes as $m) {
                 $message .= "<p><b>" . $m[0] . ":</b> " . $m[1] . "</p>";
             }
             $new = Broker::findOne($model->user_id);
             if ($message) {
                 $new->edit = $message;
                 Yii::$app->session->setFlash('success', Yii::t('app', 'Sent admin to verify.'));
             } else {
                 $new->edit = '';
             }
             $new->save();
             return $this->redirect(Url::toRoute('personal/index'));
         }
     }
     return $this->render('broker', ['model' => $model]);
 }
 /**
  * Updates an existing Discount model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionEdit($id = false)
 {
     $model = new Discount();
     if ($id !== false) {
         $model = Discount::findOne($id);
     } else {
         $model->loadDefaultValues();
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->save()) {
             Yii::$app->session->setFlash('info', Yii::t('app', 'Object saved'));
             $returnUrl = Yii::$app->request->get('returnUrl', ['/shop/backend-discount/index']);
             switch (Yii::$app->request->post('action', 'save')) {
                 case 'next':
                     return $this->redirect(['/shop/backend-discount/edit', 'returnUrl' => $returnUrl]);
                 case 'back':
                     return $this->redirect($returnUrl);
                 default:
                     return $this->redirect(Url::toRoute(['/shop/backend-discount/edit', 'id' => $model->id, 'returnUrl' => $returnUrl]));
             }
         }
     }
     if (Yii::$app->request->isPost && !$model->isNewRecord) {
         foreach ($model::getTypeObjects() as $object) {
             $object->discount_id = $model->id;
             if ($object->load(Yii::$app->request->post()) && $object->validate()) {
                 $object->save();
             }
         }
     }
     return $this->render('form', ['model' => $model]);
 }
Пример #15
0
 public function init()
 {
     parent::init();
     $request = AH::merge(['wrapper' => 'results', 'term' => 'search:term'], $this->uses);
     $requests = [];
     $back_request = [];
     foreach ($request as $k => $v) {
         if ($k === 'term') {
             $requests[] = $v;
         } elseif (is_array($v)) {
             $requests[] = "{$k}:" . json_encode($v);
             $back_request[] = "{$k}:" . json_encode($v);
         } else {
             $requests[] = "{$k}:'{$v}'";
             $back_request[] = "{$k}:'{$v}'";
         }
     }
     \Yii::configure($this, ['format' => 'html', 'filterInputOptions' => ['id' => 'id'], 'filter' => Select2::widget(['attribute' => 'id', 'model' => $this->grid->filterModel, 'url' => Url::toRoute(['list']), 'settings' => ['ajax' => ['data' => new JsExpression('function(term,page) { return {' . implode(', ', $requests) . '}; }')], 'initSelection' => new JsExpression('function (elem, callback) {
                     var id=$(elem).val();
                     $.ajax("' . Url::toRoute(['list']) . '?id=" + id, {
                         dataType: "json",
                         data : {' . implode(', ', $back_request) . '}
                     }).done(function(data) {
                         callback(data.results[0]);
                     });
                 }')]])]);
 }
 /**
  * Updates an existing ShippingOption model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionEdit($id = null)
 {
     if (is_null($id)) {
         $model = new ShippingOption();
     } else {
         $model = $this->findModel($id);
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Yii::$app->session->setFlash('success', Yii::t('app', 'Record has been saved'));
             $returnUrl = Yii::$app->request->get('returnUrl', ['index', 'id' => $model->id]);
             switch (Yii::$app->request->post('action', 'save')) {
                 case 'next':
                     return $this->redirect(['edit', 'returnUrl' => $returnUrl]);
                 case 'back':
                     return $this->redirect($returnUrl);
                 default:
                     return $this->redirect(Url::toRoute(['edit', 'id' => $model->id, 'returnUrl' => $returnUrl]));
             }
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot save data'));
         }
     }
     return $this->render('edit', ['model' => $model]);
 }
Пример #17
0
 public function getManagerOptions()
 {
     $options = ['url' => Url::toRoute('connect'), 'customData' => [Yii::$app->request->csrfParam => Yii::$app->request->csrfToken], 'resizable' => false];
     if (isset($_GET['CKEditor'])) {
         $options['getFileCallback'] = new JsExpression('function(file){ ' . 'window.opener.CKEDITOR.tools.callFunction(' . Json::encode($_GET['CKEditorFuncNum']) . ', file.url); ' . 'window.close(); }');
         $options['lang'] = $_GET['langCode'];
     }
     if (isset($_GET['filter'])) {
         if (is_array($_GET['filter'])) {
             $options['onlyMimes'] = $_GET['filter'];
         } else {
             $options['onlyMimes'] = [$_GET['filter']];
         }
     }
     if (isset($_GET['lang'])) {
         $options['lang'] = $_GET['lang'];
     }
     if (isset($_GET['callback'])) {
         if (isset($_GET['multiple'])) {
             $options['commandsOptions']['getfile']['multiple'] = true;
         }
         $options['getFileCallback'] = new JsExpression('function(file){ ' . 'if (window!=window.top) {var parent = window.parent;}else{var parent = window.opener;}' . 'if(parent.mihaildev.elFinder.callFunction(' . Json::encode($_GET['callback']) . ', file))' . 'window.close(); }');
     }
     if (!isset($options['lang'])) {
         $options['lang'] = ElFinder::getSupportedLanguage(Yii::$app->language);
     }
     if (!empty($this->disabledCommands)) {
         $options['commands'] = new JsExpression('ElFinderGetCommands(' . Json::encode($this->disabledCommands) . ')');
     }
     return ArrayHelper::merge($options, $this->managerOptions);
 }
Пример #18
0
 /**
  * @return string
  */
 public function run()
 {
     parent::run();
     if (null === $this->rootCategory) {
         return '';
     }
     $cacheKey = $this->className() . ':' . implode('_', [$this->viewFile, $this->rootCategory, null === $this->depth ? 'null' : intval($this->depth), intval($this->includeRoot), intval($this->fetchModels), intval($this->onlyNonEmpty), implode(',', $this->excludedCategories), \Yii::$app->request->url]) . ':' . json_encode($this->additional);
     if (false !== ($cache = \Yii::$app->cache->get($cacheKey))) {
         return $cache;
     }
     /** @var array|Category[] $tree */
     $tree = Category::getMenuItems(intval($this->rootCategory), $this->depth, boolval($this->fetchModels));
     if (true === $this->includeRoot) {
         if (null !== ($_root = Category::findById(intval($this->rootCategory)))) {
             $tree = [['label' => $_root->name, 'url' => Url::toRoute(['@category', 'category_group_id' => $_root->category_group_id, 'last_category_id' => $_root->id]), 'id' => $_root->id, 'model' => $this->fetchModels ? $_root : null, 'items' => $tree]];
         }
     }
     if (true === $this->onlyNonEmpty) {
         $_sq1 = (new Query())->select('main_category_id')->distinct()->from(Product::tableName());
         $_sq2 = (new Query())->select('category_id')->distinct()->from('{{%product_category}}');
         $_query = (new Query())->select('id')->from(Category::tableName())->andWhere(['not in', 'id', $_sq1])->andWhere(['not in', 'id', $_sq2])->all();
         $this->excludedCategories = array_merge($this->excludedCategories, array_column($_query, 'id'));
     }
     $tree = $this->filterTree($tree);
     $cache = $this->render($this->viewFile, ['tree' => $tree, 'fetchModels' => $this->fetchModels, 'additional' => $this->additional, 'activeClass' => $this->activeClass, 'activateParents' => $this->activateParents]);
     \Yii::$app->cache->set($cacheKey, $cache, 0, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Category::className()), ActiveRecordHelper::getCommonTag(Product::className())]]));
     return $cache;
 }
Пример #19
0
 public function actionConfirm()
 {
     $table = new UsuarioDB();
     if (Yii::$app->request->get()) {
         //Obtenemos el valor de los parámetros get
         $id = Html::encode($_GET["id"]);
         $authKey = $_GET["authKey"];
         if ((int) $id) {
             //Realizamos la consulta para obtener el registro
             $model = $table->find()->where("id=:id", [":id" => $id])->andWhere("authKey=:authKey", [":authKey" => $authKey]);
             //Si el registro existe
             if ($model->count() == 1) {
                 $activar = UsuarioDB::findOne($id);
                 $activar->activate = 1;
                 if ($activar->update()) {
                     echo "Felicidades, tu registro se ha llevado a cabo correctamente, redireccionando ...";
                     echo "<meta http-equiv='refresh' content='8; " . Url::toRoute("site/login") . "'>";
                 } else {
                     echo "Ha ocurrido un error al realizar el registro, redireccionando ...";
                     echo "<meta http-equiv='refresh' content='8; " . Url::toRoute("site/login") . "'>";
                 }
             } else {
                 return $this->redirect(["site/login"]);
             }
         } else {
             return $this->redirect(["site/login"]);
         }
     }
 }
Пример #20
0
 public function run()
 {
     $shippingTypesList = ShippingType::find()->orderBy('order DESC')->all();
     $shippingTypes = ['' => yii::t('order', 'Choose shipping type')];
     foreach ($shippingTypesList as $sht) {
         if ($sht->cost > 0) {
             $currency = yii::$app->getModule('order')->currency;
             $name = "{$sht->name} ({$sht->cost}{$currency})";
         } else {
             $name = $sht->name;
         }
         $shippingTypes[$sht->id] = $name;
     }
     $paymentTypes = ['' => yii::t('order', 'Choose payment type')];
     $paymentTypesList = PaymentType::find()->orderBy('order DESC')->all();
     foreach ($paymentTypesList as $pt) {
         $paymentTypes[$pt->id] = $pt->name;
     }
     $fieldFind = Field::find()->orderBy('order DESC');
     $fieldValueModel = new FieldValue();
     $orderModel = new Order();
     if (empty($orderModel->shipping_type_id) && ($orderShippingType = yii::$app->session->get('orderShippingType'))) {
         if ($orderShippingType > 0) {
             $orderModel->shipping_type_id = (int) $orderShippingType;
         }
     }
     $this->getView()->registerJs("pistol88.order.updateShippingType = '" . Url::toRoute(['/order/tools/update-shipping-type']) . "';");
     return $this->render($this->view, ['orderModel' => $orderModel, 'fieldFind' => $fieldFind, 'paymentTypes' => $paymentTypes, 'elements' => $this->elements, 'shippingTypes' => $shippingTypes, 'shippingTypesList' => $shippingTypesList, 'fieldValueModel' => $fieldValueModel]);
 }
Пример #21
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     $this->addItem(array('label' => Yii::t('AdminModule.views_user_index', 'Settings'), 'url' => Url::toRoute(['/admin/group/edit', 'id' => $this->group->id]), 'sortOrder' => 100, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'group' && Yii::$app->controller->action->id == 'edit'));
     $this->addItem(array('label' => Yii::t('AdminModule.views_groups_index', "Permissions"), 'url' => Url::toRoute(['/admin/group/manage-permissions', 'id' => $this->group->id]), 'sortOrder' => 200, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'group' && Yii::$app->controller->action->id == 'manage-permissions'));
     $this->addItem(array('label' => Yii::t('AdminModule.views_groups_index', "Members"), 'url' => Url::toRoute(['/admin/group/manage-group-users', 'id' => $this->group->id]), 'sortOrder' => 200, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'group' && Yii::$app->controller->action->id == 'manage-group-users'));
     parent::init();
 }
Пример #22
0
 public function run()
 {
     $this->genButton = Html::a(Icon::show('edit') . Yii::t('app', 'Generate'), '#', ['class' => 'btn btn-success', 'id' => 'btn-generate']);
     $parent_id = $this->model->main_category_id;
     $owner_id = $this->model->id;
     $this->addButton = Html::a(Icon::show('plus') . Yii::t('app', 'Add'), Url::toRoute(['/shop/backend-product/edit', 'parent_id' => $parent_id, 'owner_id' => $owner_id, 'returnUrl' => \app\backend\components\Helper::getReturnUrl()]), ['class' => 'btn btn-success', 'id' => 'btn-add']);
     if (!empty($this->footer)) {
         $this->footer = Html::tag('div', $this->addButton . ' ' . $this->genButton, ['class' => 'widget-footer']);
     }
     $this->object = Object::getForClass(get_class($this->model));
     $rest_pg = (new Query())->select('id, name')->from(PropertyGroup::tableName())->where(['object_id' => $this->object->id])->orderBy('sort_order')->all();
     $this->property_groups_to_add = [];
     foreach ($rest_pg as $row) {
         $this->property_groups_to_add[$row['id']] = $row['name'];
     }
     $optionGenerate = Json::decode($this->model->option_generate);
     if (null === PropertyGroup::findOne($optionGenerate['group'])) {
         $this->model->option_generate = $optionGenerate = null;
     }
     $groupModel = null;
     if (isset($optionGenerate['group'])) {
         $groupModel = PropertyGroup::findOne($optionGenerate['group']);
         $properties = Property::getForGroupId($optionGenerate['group']);
     } else {
         $group_ids = array_keys($this->property_groups_to_add);
         $group_id = array_shift($group_ids);
         $groupModel = PropertyGroup::findOne($group_id);
         $properties = Property::getForGroupId($group_id);
     }
     if (is_null($groupModel)) {
         $groupModel = new PropertyGroup();
     }
     return $this->render($this->viewFile, ['model' => $this->model, 'form' => $this->form, 'groups' => $this->property_groups_to_add, 'groupModel' => $groupModel, 'properties' => $properties, 'optionGenerate' => $optionGenerate, 'footer' => $this->footer]);
 }
Пример #23
0
 public function init()
 {
     $paramsArr = ['offerUrl' => $this->offerUrl, 'textButton' => $this->textButton, 'type' => $this->type, 'columns' => $this->columns, 'model' => $this->model, 'showTotal' => $this->showTotal, 'showOptions' => $this->showOptions, 'showOffer' => $this->showOffer, 'showTruncate' => $this->showTruncate, 'currency' => $this->currency, 'otherFields' => $this->otherFields, 'currencyPosition' => $this->currencyPosition, 'showCountArrows' => $this->showCountArrows];
     foreach ($paramsArr as $key => $value) {
         if ($value === 'false') {
             $this->{$key} = false;
         }
     }
     $this->getView()->registerJs("pistol88.cart.elementsListWidgetParams = " . json_encode($paramsArr));
     if ($this->type == NULL) {
         $this->type = self::TYPE_FULL;
     }
     if ($this->offerUrl == NULL) {
         $this->offerUrl = Url::toRoute(['/cart/default/index']);
     }
     if ($this->cart == NULL) {
         $this->cart = yii::$app->cart;
     }
     if ($this->textButton == NULL) {
         $this->textButton = yii::t('cart', 'Cart (<span class="pistol88-cart-price">{p}</span>)', ['c' => $this->cart->getCount(), 'p' => $this->cart->getCostFormatted()]);
     }
     if ($this->currency == NULL) {
         $this->currency = yii::$app->cart->currency;
     }
     if ($this->currencyPosition == NULL) {
         $this->currencyPosition = yii::$app->cart->currencyPosition;
     }
     \app\modules\cart\assets\WidgetAsset::register($this->getView());
     return parent::init();
 }
Пример #24
0
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (!AdminUser::isLoged()) {
         if (!in_array($action->id, ['login'])) {
             if ($this->request->getIsAjax()) {
                 $this->setError('login.failed', 401);
                 $this->setResponseData('data', Url::toRoute('/admin/default/login'));
             } else {
                 $this->redirect(Url::toRoute('/admin/default/login'));
             }
         }
     } else {
         /**
          * @var $this->user \liuxy\admin\models\AdminUser
          */
         $this->user = AdminUser::getUser();
         /**
          * 校验权限
          */
         if (!AdminUser::hasPermission($this->user->id, $action->controller->route)) {
             if (!in_array($action->id, ['deny', 'login', 'logout', ''])) {
                 if ($this->request->getIsAjax()) {
                     $this->setError(Module::t('deny'), 403);
                 } else {
                     $this->redirect(Url::toRoute('/admin/default/deny'));
                 }
             }
         }
     }
     return parent::beforeAction($action);
     // TODO: Change the autogenerated stub
 }
 public function init()
 {
     $this->addItemGroup(array('id' => 'manage', 'label' => \Yii::t('AdminModule.widgets_AdminMenuWidget', '<strong>Administration</strong> menu'), 'sortOrder' => 100));
     $this->addItem(array('label' => \Yii::t('AdminModule.widgets_AdminMenuWidget', 'Users'), 'url' => Url::toRoute(['/admin/user']), 'icon' => '<i class="fa fa-user"></i>', 'group' => 'manage', 'sortOrder' => 200, 'isActive' => \Yii::$app->controller->module && \Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'user', 'isVisible' => \Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'User approval'), 'id' => 'approval', 'url' => Url::toRoute('/admin/approval'), 'icon' => '<i class="fa fa-check-circle"></i>', 'group' => 'manage', 'sortOrder' => 201, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'approval', 'isVisible' => Setting::Get('needApproval', 'authentication_internal') && Yii::$app->user->getIdentity()->canApproveUsers()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Groups'), 'id' => 'groups', 'url' => Url::toRoute('/admin/group'), 'icon' => '<i class="fa fa-group"></i>', 'group' => 'manage', 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'group', 'sortOrder' => 300, 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Spaces'), 'id' => 'spaces', 'url' => Url::toRoute('/admin/space'), 'icon' => '<i class="fa fa-inbox"></i>', 'group' => 'manage', 'sortOrder' => 400, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'space', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Modules'), 'id' => 'modules', 'url' => Url::toRoute('/admin/module'), 'icon' => '<i class="fa fa-rocket"></i>', 'sortOrder' => 500, 'group' => 'manage', 'newItemCount' => 0, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'module', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'About'), 'url' => Url::toRoute('/admin/about'), 'icon' => '<i class="fa fa-info-circle"></i>', 'sortOrder' => 10000, 'group' => 'manage', 'newItemCount' => 0, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'about', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItemGroup(array('id' => 'settings', 'label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Settings'), 'sortOrder' => 200));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Basic'), 'url' => Url::toRoute('/admin/setting/index'), 'icon' => '<i class="fa fa-cogs"></i>', 'group' => 'settings', 'sortOrder' => 100, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'basic', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Design'), 'url' => Url::toRoute('/admin/setting/design'), 'icon' => '<i class="fa fa-magic"></i>', 'group' => 'settings', 'sortOrder' => 200, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'design', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Authentication'), 'url' => Url::toRoute('/admin/setting/authentication'), 'icon' => '<i class="fa fa-lock"></i>', 'group' => 'settings', 'sortOrder' => 500, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && (Yii::$app->controller->action->id == 'authentication' || Yii::$app->controller->action->id == 'authenticationLdap'), 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'User profiles'), 'url' => Url::toRoute('/admin/user-profile/index'), 'icon' => '<i class="fa fa-wrench"></i>', 'group' => 'settings', 'sortOrder' => 500, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'user-profile', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Mailing'), 'url' => Url::toRoute('/admin/setting/mailing'), 'icon' => '<i class="fa fa-envelope"></i>', 'group' => 'settings', 'sortOrder' => 600, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'mailing', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Caching'), 'url' => Url::toRoute(['/admin/setting/caching']), 'icon' => '<i class="fa fa-dashboard"></i>', 'group' => 'settings', 'sortOrder' => 800, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'caching', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Files'), 'url' => Url::toRoute('/admin/setting/file'), 'icon' => '<i class="fa fa-file"></i>', 'group' => 'settings', 'sortOrder' => 800, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'file', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Proxy'), 'url' => Url::toRoute('/admin/setting/proxy'), 'icon' => '<i class="fa fa-sitemap"></i>', 'group' => 'settings', 'sortOrder' => 800, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'proxy', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Statistics'), 'url' => Url::toRoute('/admin/setting/statistic'), 'icon' => '<i class="fa fa-bar-chart-o"></i>', 'group' => 'settings', 'sortOrder' => 900, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'statistic', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Cron jobs'), 'url' => Url::toRoute('/admin/setting/cronjob'), 'icon' => '<i class="fa fa-history"></i>', 'group' => 'settings', 'sortOrder' => 1000, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'cronjob', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Logging'), 'url' => Url::toRoute('/admin/logging'), 'icon' => '<i class="fa fa-keyboard-o"></i>', 'group' => 'settings', 'sortOrder' => 1100, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'logging', 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'OEmbed Provider'), 'url' => Url::toRoute('/admin/setting/oembed'), 'icon' => '<i class="fa fa-cloud"></i>', 'group' => 'settings', 'sortOrder' => 1200, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && (Yii::$app->controller->action->id == 'oembed' || Yii::$app->controller->action->id == 'oembedEdit'), 'isVisible' => Yii::$app->user->isAdmin()));
     $this->addItem(array('label' => Yii::t('AdminModule.widgets_AdminMenuWidget', 'Self test & update'), 'url' => Url::toRoute('/admin/setting/self-test'), 'icon' => '<i class="fa fa-warning"></i>', 'group' => 'settings', 'sortOrder' => 1300, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'setting' && Yii::$app->controller->action->id == 'selftest', 'isVisible' => Yii::$app->user->isAdmin()));
     parent::init();
 }
Пример #26
0
 /**
  * Возвращает массив скартой сайта
  * @return array
  * @throws InvalidConfigException
  */
 public function getElements()
 {
     $elements = [];
     foreach ($this->definition as $item) {
         if (empty($item["class"]) || empty($item["urlCreate"])) {
             throw new InvalidConfigException("Class or url create function missing");
         }
         $query = $item["class"]::find();
         $scopes = !empty($item["scopes"]) ? $item["scopes"] : [$this->defaultScope];
         $labelAttr = !empty($item["labelAttr"]) ? $item["labelAttr"] : $this->defaultLabelAttr;
         $this->applyScopes($query, $scopes);
         if ($query instanceof TActiveQuery) {
             $query->orderBy(["lft" => SORT_ASC]);
         } else {
             $query->orderBy(["id" => SORT_DESC]);
         }
         $iterator = $query->each();
         $arr = [];
         $arr['header'] = !empty($item["entityLabel"]) && is_callable($item["entityLabel"]) ? call_user_func($item["entityLabel"]) : $item["class"]::getEntityName();
         if (!empty($item["entityRoute"])) {
             $arr['entityUrl'] = Url::toRoute($item["entityRoute"]);
         }
         $arr['items'] = [];
         foreach ($iterator as $model) {
             if (empty($model->{$labelAttr}) or !empty($item["doAdd"]) and !call_user_func($item["doAdd"], $model)) {
                 continue;
             }
             $arr['items'][] = ["label" => $model->{$labelAttr}, "url" => Html::encode(call_user_func($item["urlCreate"], $model)), "date" => $model->updated_at];
         }
         $elements[] = $arr;
     }
     return $elements;
 }
Пример #27
0
 public function actionSave($id = null, $languageId = null)
 {
     $selectedLanguage = Language::findOne($languageId);
     if (!empty($id)) {
         $country = ProductCountry::find()->where(['id' => $id])->one();
         $countryTranslation = ProductCountryTranslation::find()->where(['country_id' => $id, 'language_id' => $languageId])->one();
         if (empty($countryTranslation)) {
             $countryTranslation = new ProductCountryTranslation();
         }
     } else {
         $country = new ProductCountry();
         $countryTranslation = new ProductCountryTranslation();
     }
     if (\Yii::$app->request->isPost) {
         $country->load(\Yii::$app->request->post());
         $countryTranslation->load(\Yii::$app->request->post());
         if ($countryTranslation->validate()) {
             $country->save();
             $countryTranslation->country_id = $country->id;
             $countryTranslation->language_id = $selectedLanguage->id;
             $countryTranslation->save();
             return $this->redirect(Url::toRoute('/shop/country'));
         }
     }
     return $this->render('save', ['country' => $country, 'countryTranslation' => $countryTranslation, 'languages' => Language::findAll(['active' => true]), 'selectedLanguage' => $selectedLanguage]);
 }
Пример #28
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     $groupId = Yii::$app->request->get('id');
     $this->addItem(array('label' => Yii::t('AdminModule.setting', 'General'), 'url' => Url::toRoute(['/admin/authentication']), 'sortOrder' => 100, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'authentication' && Yii::$app->controller->action->id == 'index'));
     $this->addItem(array('label' => Yii::t('AdminModule.setting', "LDAP"), 'url' => Url::toRoute(['/admin/authentication/authentication-ldap']), 'sortOrder' => 200, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'authentication' && Yii::$app->controller->action->id == 'authentication-ldap'));
     parent::init();
 }
Пример #29
-1
 /**
  * Sign Up page.
  * If record will be successful created, user will be redirected to home page.
  */
 public function actionSignup()
 {
     $user = new User(['scenario' => 'signup']);
     $profile = new Profile();
     if ($user->load(Yii::$app->request->post()) && $profile->load(Yii::$app->request->post())) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation('profile', $profile);
             if ($user->save(false)) {
                 if ($this->module->requireEmailConfirmation === true) {
                     Yii::$app->session->setFlash('success', Module::t('users', 'FRONTEND_FLASH_SUCCESS_SIGNUP_WITHOUT_LOGIN', ['url' => Url::toRoute('resend')]));
                 } else {
                     Yii::$app->user->login($user);
                     Yii::$app->session->setFlash('success', Module::t('users', 'FRONTEND_FLASH_SUCCESS_SIGNUP_WITH_LOGIN'));
                 }
                 return $this->goHome();
             } else {
                 Yii::$app->session->setFlash('danger', Module::t('users', 'FRONTEND_FLASH_FAIL_SIGNUP'));
                 return $this->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($user);
         }
     }
     return $this->render('signup', ['user' => $user, 'profile' => $profile]);
 }
Пример #30
-1
 public function afterAction($action, $result)
 {
     if (Yii::$app->request->pathInfo !== "auth/index") {
         Url::remember(Url::toRoute(["/" . Yii::$app->request->pathInfo]), 'safe_url');
     }
     return parent::afterAction($action, $result);
 }