public function run() { SelectAsset::register($this->view); FilterAsset::register($this->view); $values = []; foreach ($this->data as $value) { $value = strval($value); $values[$value] = $value; } if (!$this->default) { $this->default = $this->multiple ? array_keys($values) : key($values); } $selected = $this->selected($this->default); // Setup options $options = ['id' => $this->name, 'name' => $this->name . '[]', 'style' => 'width: 300px;', 'class' => 'selectpicker']; $extra = ['title' => 'Not selected']; if ($this->multiple) { $extra['multiple'] = 'multiple'; } if ($this->placeholder) { $extra['title'] = strval($this->placeholder); } $options = array_merge($options, $extra); if (!$this->method) { $this->method = 'get'; } // Render echo Html::beginForm(Url::canonical(), $this->method, ['data-pjax' => '1', 'id' => $this->name]); echo Html::beginTag('select', $options, ['data-pjax' => '1']); echo Html::renderSelectOptions($selected, $values); echo Html::endTag("select"); echo Html::endForm(); parent::run(); }
/** * 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; }
public function actionIndex() { Url::remember('', 'actions-redirect'); $searchModel = Yii::createObject(UserSearch::className()); $dataProvider = $searchModel->search(Yii::$app->request->get()); return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]); }
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]); }
public function afterUpdate() { try { if ($this->seoText->load(Yii::$app->request->post())) { $this->seoText->setAttributes(['_image' => UploadedFile::getInstance($this->seoText, '_image')]); // if(!$this->seoText->isEmpty()){ if ($this->seoText->save()) { if ($this->seoText->_image) { $old = $this->seoText->ogImage; $photo = new Photo(); $photo->class = get_class($this->seoText); $photo->item_id = $this->seoText->seotext_id; $photo->image = $this->seoText->_image; if ($photo->image && $photo->validate(['image'])) { $photo->image = Image::upload($photo->image, 'photos', Photo::PHOTO_MAX_WIDTH); if ($photo->image) { if ($photo->save()) { $old->delete(); } else { @unlink(Yii::getAlias('@webroot') . str_replace(Url::base(true), '', $photo->image)); } } else { } } } } } } catch (UnknownMethodException $e) { } }
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(); }
public function actionRss() { /** @var News[] $news */ $news = News::find()->where(['status' => News::STATUS_PUBLIC])->orderBy('id DESC')->limit(50)->all(); $feed = new Feed(); $feed->title = 'YiiFeed'; $feed->link = Url::to(''); $feed->selfLink = Url::to(['news/rss'], true); $feed->description = 'Yii news'; $feed->language = 'en'; $feed->setWebMaster('*****@*****.**', 'Alexander Makarov'); $feed->setManagingEditor('*****@*****.**', 'Alexander Makarov'); foreach ($news as $post) { $item = new Item(); $item->title = $post->title; $item->link = Url::to(['news/view', 'id' => $post->id], true); $item->guid = Url::to(['news/view', 'id' => $post->id], true); $item->description = HtmlPurifier::process(Markdown::process($post->text)); if (!empty($post->link)) { $item->description .= Html::a(Html::encode($post->link), $post->link); } $item->pubDate = $post->created_at; $item->setAuthor('*****@*****.**', 'YiiFeed'); $feed->addItem($item); } $feed->render(); }
/** * @inheritdoc */ public function init() { parent::init(); // set titles $this->setCreateTitle(Yii::t('kalibao', 'create_title')); $this->setUpdateTitle(Yii::t('kalibao', 'update_title')); // models $models = $this->getModels(); // language $language = $this->getLanguage(); // get drop down list methods $dropDownList = $this->getDropDownList(); // upload config $uploadConfig['main'] = $this->uploadConfig[(new \ReflectionClass($models['main']))->getName()]; // set items $items = []; if (!$models['main']->isNewRecord) { $items[] = new SimpleValueField(['model' => $models['main'], 'attribute' => 'id', 'value' => $models['main']->id]); } $items[] = new InputField(['model' => $models['main'], 'attribute' => 'file', 'type' => 'activeFileInput', 'options' => ['maxlength' => true, 'class' => 'input-advanced-uploader', 'placeholder' => $models['main']->getAttributeLabel('file'), 'data-type-uploader' => $uploadConfig['main']['file']['type'], 'data-file-url' => $models['main']->file != '' ? $uploadConfig['main']['file']['baseUrl'] . '/' . $models['main']->file : '']]); $items[] = new InputField(['model' => $models['main'], 'attribute' => 'media_type_id', 'type' => 'activeHiddenInput', 'options' => ['class' => 'form-control input-sm input-ajax-select', 'data-action' => Url::to(['advanced-drop-down-list', 'id' => 'media_type_i18n.title']), 'data-allow-clear' => 1, 'data-placeholder' => Yii::t('kalibao', 'input_select'), 'data-text' => !empty($models['main']->media_type_id) ? MediaTypeI18n::findOne(['media_type_id' => $models['main']->media_type_id, 'i18n_id' => $language])->title : '']]); $items[] = new InputField(['model' => $models['i18n'], 'attribute' => 'title', 'type' => 'activeTextInput', 'options' => ['class' => 'form-control input-sm', 'maxlength' => true, 'placeholder' => $models['i18n']->getAttributeLabel('title')]]); if (!$models['main']->isNewRecord) { $items[] = new SimpleValueField(['model' => $models['main'], 'attribute' => 'created_at', 'value' => Yii::$app->formatter->asDatetime($models['main']->created_at, I18N::getDateFormat())]); } if (!$models['main']->isNewRecord) { $items[] = new SimpleValueField(['model' => $models['main'], 'attribute' => 'updated_at', 'value' => Yii::$app->formatter->asDatetime($models['main']->updated_at, I18N::getDateFormat())]); } $this->setItems($items); }
public function api_get($id_slug) { if (($text = $this->findText($id_slug)) === null) { return $this->notFound($id_slug); } return LIVE_EDIT ? API::liveEdit($text['text'], Url::to(['/admin/text/a/edit/', 'id' => $text['text_id']])) : $text['text']; }
public function run() { //Если данные по доставке закешированы просто рисуем их иначе делаем ajax запрос, чтобы заполнился кеш if (\Yii::$app->v3toysSettings->isCurrentShippingCache) { return $this->render($this->viewFile); } else { $js = \yii\helpers\Json::encode(['backend' => \yii\helpers\Url::to('/v3toys/cart/get-current-shipping')]); $this->view->registerJs(<<<JS (function(sx, \$, _) { sx.classes.GetShipping = sx.classes.Component.extend({ _onDomReady: function() { var self = this; _.delay(function() { sx.ajax.preparePostQuery(self.get('backend')).execute(); }, 500); } }); new sx.classes.GetShipping({$js}); })(sx, sx.\$, sx._); JS ); } }
/** * @inheritdoc */ public function getAssetUrl($bundle, $asset) { if (($actualAsset = $this->resolveAsset($bundle, $asset)) !== false) { if (strncmp($actualAsset, '@web/', 5) === 0) { $asset = substr($actualAsset, 5); $basePath = Yii::getAlias("@webroot"); $baseUrl = Yii::getAlias("@web"); } else { $asset = Yii::getAlias($actualAsset); $basePath = $this->basePath; $baseUrl = $this->baseUrl; } } else { $basePath = $bundle->basePath; $baseUrl = $bundle->baseUrl; } if (!Url::isRelative($asset) || strncmp($asset, '/', 1) === 0) { return $asset; } if ($this->appendTimestamp) { foreach (['', '.gz'] as $appendExtension) { if (($timestamp = @filemtime("{$basePath}/{$asset}{$appendExtension}")) > 0) { return "{$baseUrl}/{$asset}?v={$timestamp}"; } } } return "{$baseUrl}/{$asset}"; }
/** * Initializes the widget. */ public function init() { parent::init(); if (empty($this->id)) { $this->id = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId(); } if (empty($this->name)) { $this->name = $this->hasModel() ? Html::getInputName($this->model, $this->attribute) : $this->id; } if (empty($this->value) && $this->hasModel() && $this->model->hasAttribute($this->attribute)) { $this->value = $this->model->getAttribute($this->attribute); } if (!$this->autoHeightEnable) { if (empty($this->width)) { $this->width = '100%'; } if (empty($this->height)) { $this->height = '350'; } } $options = ['id' => $this->id, 'style' => 'width:100%;height:350px']; $this->options = array_merge($options, $this->options); $jsOptions = ['serverUrl' => Url::to(['ueditor', 'type' => 'ueditor']), 'autoHeightEnable' => $this->autoHeightEnable, 'autoFloatEnable' => true, 'textarea' => $this->name]; $this->jsOptions = array_merge($jsOptions, $this->jsOptions); }
public function up() { mb_internal_encoding("UTF-8"); $tableOptions = $this->db->driverName === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB' : null; $this->createTable('{{%wysiwyg}}', ['id' => Schema::primaryKey(), 'name' => Schema::string()->notNull(), 'class_name' => Schema::string()->notNull(), 'params' => Schema::text(), 'configuration_model' => Schema::string()], $tableOptions); $this->insert('{{%wysiwyg}}', ['name' => 'Imperavi', 'class_name' => 'vova07\\imperavi\\Widget', 'params' => Json::encode(['settings' => ['replaceDivs' => false, 'minHeight' => 200, 'paragraphize' => false, 'pastePlainText' => true, 'buttonSource' => true, 'imageManagerJson' => Url::to(['/backend/dashboard/imperavi-images-get']), 'plugins' => ['table', 'fontsize', 'fontfamily', 'fontcolor', 'video', 'imagemanager'], 'replaceStyles' => [], 'replaceTags' => [], 'deniedTags' => [], 'removeEmpty' => [], 'imageUpload' => Url::to(['/backend/dashboard/imperavi-image-upload'])]]), 'configuration_model' => 'app\\modules\\core\\models\\WysiwygConfiguration\\Imperavi']); }
public function init() { $this->controllerMap = ['elfinder' => ['class' => 'mihaildev\\elfinder\\Controller', 'access' => ['@'], 'disabledCommands' => ['netmount'], 'roots' => [['baseUrl' => $this->mediaUrl, 'basePath' => $this->mediaPath, 'path' => '', 'name' => 'Global']]]]; $this->modules = ['settings' => ['class' => 'plathir\\settings\\Module', 'modulename' => 'blog'], 'treemanager' => ['class' => '\\kartik\\tree\\Module', 'treeViewSettings' => ['nodeActions' => [\kartik\tree\Module::NODE_MANAGE => Url::to(['/blog/categorytree/manage']), \kartik\tree\Module::NODE_SAVE => Url::to(['/blog/categorytree/save']), \kartik\tree\Module::NODE_REMOVE => Url::to(['/blog/categorytree/remove']), \kartik\tree\Module::NODE_MOVE => Url::to(['/blog/categorytree/move'])], 'nodeView' => '/categorytree/_form']]]; parent::init(); // custom initialization code goes here }
/** * @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(); }
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(); }
public function actionMatrix() { $this->sidebar = ['parent' => 'sidebar-identity', 'child' => 'matrix']; // Remember return url for crud Url::remember(['permission/matrix'], 'roles'); return parent::actionMatrix(CoreGlobal::TYPE_SYSTEM); }
/** * @return string $template * @return mixed */ public function actions($template = '{update} {delete}') { $this->columns = array_merge($this->columns, [['class' => ActionColumn::className(), 'controller' => SELF::CONTROLLER, 'template' => $template, 'buttons' => ['update' => function ($url, $model, $key) { return Html::a('<i class="fa fa-pencil"></i>', false, ['value' => Url::to([SELF::CONTROLLER . '/update', 'id' => $model->id]), 'title' => 'Update', 'class' => 'showModalButton']); }], 'contentOptions' => ['class' => 'text-right']]]); return $this; }
public function init() { $url = is_array($this->route) ? Url::to($this->route) : Url::to([$this->route, 'term' => 'QUERY']); $this->dataset = [['remote' => ['url' => $url, 'wildcard' => 'QUERY'], 'templates' => ['empty' => Html::tag('span', Yii::t('app', 'Hit enter to search'), ['class' => 'empty-search']), 'suggestion' => new JsExpression("Handlebars.compile('{$this->template}')")]]]; $this->pluginOptions = ['hint' => false]; parent::init(); }
/** * * @param \yii\authclient\ClientInterface $client * @return type */ public function successCallback($client) { // TODO: Group FK's to one local user. // Otherwise, if we log in via FB and another time via google, we // end up with two local accounts. if (!$this->action instanceof \yii\authclient\AuthAction) { throw new \yii\base\InvalidCallException("successCallback is only meant to be executed by AuthAction!"); } $attributes = $client->getUserAttributes(); $externalUser = new AuthForm(); $externalUser->authProvider = $client->getName(); $externalUser->externalUserId = array_key_exists('id', $attributes) ? $attributes['id'] : null; if ($externalUser->validate()) { Yii::info('AuthForm validated.'); if ($externalUser->isRegistered()) { Yii::info('ExternalUser is registered. Logging in and redirecting to game/index.'); $externalUser->login(); return $this->action->redirect(Url::to(['site/index'], true)); } else { throw new \yii\base\InvalidCallException("Can't login non-registered user '{$externalUser->externalUserId}@{$externalUser->authProvider}'!"); } } else { // TODO error. Throw, display actionError? Yii::info('AuthForm couldn\'t be validated. Errors: ' . print_r($externalUser->errors, true)); Yii::info('Client attributes: ' . print_r($attributes, true)); } }
public static function Breadcrumbs($params) { $links = []; if (isset($params['marka'])) { $url = Url::to('/autocatalogs'); $links[] = ['label' => 'Автокаталог', 'url' => $url]; } if (isset($params['region'])) { $url .= '/' . $params['marka'] . '/' . $params['region']; $links[] = ['label' => $params['marka'], 'url' => $url]; } if (isset($params['family'])) { $url .= '/' . $params['family']; $links[] = ['label' => $params['family'], 'url' => $url]; } if (isset($params['cat_code'])) { $url .= '/' . $params['cat_code'] . '/' . base64_encode($params['option']); $links[] = ['label' => $params['cat_code'], 'url' => $url]; } if (isset($params['cat_folder'])) { $url .= '/' . $params['cat_folder']; $links[] = ['label' => $params['cat_folder'], 'url' => $url]; } if (isset($params['sect'])) { $url .= '/' . $params['sect']; $links[] = ['label' => $params['sect'], 'url' => $url]; } if (isset($params['sub_sect'])) { $url .= '/' . $params['sub_sect']; $links[] = ['label' => $params['sub_sect'], 'url' => $url]; } return $links; }
public function sendSecureLogin() { $token = $this->getUser()->getAndStoreToken(); $txt = '<h1>Luya Sicherheitscode</h1><p>Verwenden Sie den folgenden Sicherheitscode für den Zugriff auf die Administration der Website ' . Url::base(true) . ':</p><p><strong>' . $token . '</strong></p>'; Yii::$app->mail->compose('Luya Sicherheitscode', $txt)->address($this->getUser()->email)->send(); return true; }
public function actionUpload($model, $item_id, $maxWidth, $thumbWidth, $thumbHeight = null, $thumbCrop = true) { $success = null; $photo = new Photo(); $photo->model = $model; $photo->item_id = $item_id; $photo->image = UploadedFile::getInstance($photo, 'image'); if ($photo->image && $photo->validate(['image'])) { $photo->image = Image::upload($photo->image, 'photos', $maxWidth); if ($photo->image) { $photo->thumb = Image::createThumbnail($photo->image, $thumbWidth, $thumbHeight, $thumbCrop); if ($photo->save()) { $success = ['message' => Yii::t('easyii', 'Photo uploaded'), 'photo' => ['id' => $photo->primaryKey, 'thumb' => $photo->thumb, 'image' => $photo->image, 'description' => '']]; } else { @unlink(Yii::getAlias('@webroot') . str_replace(Url::base(true), '', $photo->image)); @unlink(Yii::getAlias('@webroot') . str_replace(Url::base(true), '', $photo->thumb)); $this->error = Yii::t('easyii', 'Create error. {0}', $photo->formatErrors()); } } else { $this->error = Yii::t('easyii', 'File upload error. Check uploads folder for write permissions'); } } else { $this->error = Yii::t('easyii', 'File is incorrect'); } return $this->formatResponse($success); }
public function actionApprove() { $user = User::findOne(['id' => (int) Yii::$app->request->get('id')]); if ($user == null) { throw new HttpException(404, Yii::t('AdminModule.controllers_ApprovalController', 'User not found!')); } $model = new ApproveUserForm(); $model->subject = Yii::t('AdminModule.controllers_ApprovalController', "Account Request for '{displayName}' has been approved.", array('{displayName}' => Html::encode($user->displayName))); $model->message = Yii::t('AdminModule.controllers_ApprovalController', 'Hello {displayName},<br><br> your account has been activated.<br><br> Click here to login:<br> <a href=\'{loginURL}\'>{loginURL}</a><br><br> Kind Regards<br> {AdminName}<br><br>', array('{displayName}' => Html::encode($user->displayName), '{loginURL}' => Url::to(["/user/auth/login"], true), '{AdminName}' => Yii::$app->user->getIdentity()->displayName)); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $model->send($user->email); $user->status = User::STATUS_ENABLED; $user->save(); $user->setUpApproved(); return $this->redirect(['index']); } return $this->render('approve', ['model' => $user, 'approveFormModel' => $model]); }
public function actionAdd() { $requestId = yii::$app->request->get('id'); $id = isset($requestId) ? (int) $requestId : 0; $item = $this->GetModel()->GetItem($id); if (yii::$app->request->isPost) { $pathInfo = Yii::$app->request->pathInfo; $fields = Yii::$app->request->post(); if (isset($fields["main"]["id"])) { $id = $fields["main"]["id"]; } else { $id = Yii::$app->request->get('id') ? (int) Yii::$app->request->get('id') : 0; } $model = $this->GetModel(); $model->attributes = $fields["main"]; if ($model->validate()) { $insert_id = $model->Add($id, $fields["main"]); $this->redirect(Url::to(["/{$pathInfo}", "id" => $insert_id])); } else { $errors = $model->errors; app::PrintPre($errors); } } $interace = $this->MakeInterface($item); $this->headerPage = "Новый тип страницы"; return $this->render('add', ["interface" => $interace, "id" => $id]); }
/** * @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 }
/** * Возвращает массив скартой сайта * @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; }
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]); }
public function actionAdd() { if (User::thisUser()->reputation < Event::MIN_REPUTATION_EVENT_CREATE) { return Yii::$app->getResponse()->redirect(Url::home()); } $event = new Event(); if ($event->load(Yii::$app->request->post())) { $eventPost = Yii::$app->request->post('Event'); $event->country = $eventPost['country']; $event->description = \yii\helpers\HtmlPurifier::process($event->description, []); $event->user_id = Yii::$app->user->identity->getId(); $event->date = strtotime($eventPost['date']); $event->like_count = 0; $event->show_count = 0; if ($event->save()) { // Добавляем теги $tagsArr = explode(',', Yii::$app->request->post('tags')); $tags = array_shift($tagsArr); $event->saveTags($tags); // Добавляем картинки к записи $imgs = Yii::$app->request->post('imgs'); if (!empty($imgs) && is_array($imgs)) { $event->saveImgs($imgs); } else { $event->saveImgs([]); } $event->saveLocations(Yii::$app->request->post('location')); return Yii::$app->getResponse()->redirect($event->getUrl()); } } Yii::$app->params['jsZoukVar']['tagsAll'] = Tags::getTags(Tags::TAG_GROUP_ALL); return $this->render('add', ['event' => $event]); }
/** * 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]); }