/** * CategoryForm constructor * @param integer|null $item_id */ public function __construct($item_id = null) { parent::__construct(); if ($item_id) { /** @var $category Category*/ $category = Category::findOne($item_id); $this->item_id = $category->id; $this->language_id = $category->language_id; $this->title = $category->title; $this->description = $category->description; $this->category_type = $category->category_type; if ($category->main) { $this->boxes[] = self::PROPERTY_MAIN; } if ($category->public) { $this->boxes[] = self::PROPERTY_PUBLIC; } if ($category->active) { $this->boxes[] = self::PROPERTY_ACTIVE; } } else { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $this->language_id = $session['language_id']; $this->boxes[] = self::PROPERTY_PUBLIC; $this->boxes[] = self::PROPERTY_ACTIVE; } }
/** * PageForm constructor * @param integer|null $item_id */ public function __construct($item_id = null) { parent::__construct(); if ($item_id) { /** @var $page Page */ $page = Page::findOne($item_id); $this->item_id = $page->id; $this->language_id = $page->language_id; if ($page->image) { $this->imageFilename = $page->image->filename; } $this->perex = $page->perex; $this->title = $page->title; $this->description = $page->description; if ($page->active) { $this->boxes[] = self::PROPERTY_ACTIVE; } if ($page->public) { $this->boxes[] = self::PROPERTY_PUBLIC; } $this->tagValues = $page->tagValues; } else { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $this->language_id = $session['language_id']; $this->boxes[] = self::PROPERTY_ACTIVE; $this->boxes[] = self::PROPERTY_PUBLIC; } }
/** * @param integer|null $item_id */ public function __construct($item_id = null) { parent::__construct(); if ($item_id) { /** @var $poll PollRecord */ $poll = PollRecord::findOne($item_id); $this->item_id = $poll->id; $this->language_id = $poll->language_id; $this->question = $poll->question; $this->end_date = $poll->end_date ? Yii::$app->formatter->asDate($poll->end_date, 'dd.MM.y') : null; if ($poll->active) { $this->boxes[] = self::PROPERTY_ACTIVE; } if ($poll->main) { $this->boxes[] = self::PROPERTY_MAIN; } foreach ($poll->answers as $pollAnswer) { $this->answers[] = $pollAnswer->answer; } $voices = PollAnswerRecord::find()->where(['poll_id' => $poll->id])->andWhere('voices>0')->count(); $this->isAnswersEditable = !$voices; } else { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $this->language_id = $session['language_id']; $this->boxes[] = self::PROPERTY_ACTIVE; $this->answers[1] = $this->answers[0] = ''; $this->isAnswersEditable = true; } }
/** * Updates texts for file in given language * @param $id integer id of file * @return string|Response */ public function actionUpdateTexts($id) { /** @var FileRecord $file */ $file = FileRecord::findOne($id); if ($file) { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $model = FileTextRecord::find()->where(['file_id' => $id, 'language_id' => $session['language_id']])->one(); if (!$model) { $model = new FileTextRecord(); $model->title = $file->title; $model->file_id = $id; $model->language_id = $session['language_id']; } if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->file->type == FileRecord::TYPE_IMAGE) { return $this->redirect(['images']); } else { return $this->redirect(['files']); } } elseif (Yii::$app->request->isAjax) { return $this->renderAjax('_textsForm', compact('model')); } return $this->render('_textsForm', compact('model')); } else { throw new InvalidValueException(Yii::t('back', 'No file record found of this ID') . ': ' . $id); } }
public function init() { parent::init(); if ($this->dropdownId) { $this->_items = LanguageRecord::find()->activeStatus()->all(); } else { throw new InvalidConfigException(\Yii::t('front', 'No required parameter given') . ' - dropdownId'); } }
public function init() { parent::init(); $language_id = LanguageRecord::find()->select('id')->where(['acronym' => \Yii::$app->language])->scalar(); if ($this->contentId === null) { $subQuery = (new Query())->select('*')->from('tag')->where('frequency>0')->andWhere(['language_id' => $language_id])->orderBy('frequency DESC')->limit(\Yii::$app->params['defaultTagsCount']); $this->_items = (new Query())->select('*')->from(['tag' => $subQuery])->orderBy('name')->all(); } else { $this->_items = (new Query())->select('*')->from('tag, content_tag')->where('tag.id=content_tag.tag_id')->andWhere(['content_tag.content_id' => $this->contentId])->orderBy('tag.name')->all(); } }
/** * Creates data provider instance with search query applied * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = AdditionalFieldRecord::find(); if (!isset($params['sort'])) { $query->orderBy(['label' => SORT_ASC]); } $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $query->andWhere(['language_id' => $session['language_id']]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); return $dataProvider; }
public function init() { //parent::init(); $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $langValues = LanguageRecord::getLanguageValues($session['language_id']); $this->_label = Html::img('@web/images/flags/' . $langValues['acronym'] . '.gif', ['alt' => Yii::t('back', 'image - flag')]) . ' ' . $langValues['title']; $languages = LanguageRecord::getLanguages(true); foreach ($languages as $language) { /** @var LanguageRecord $language */ $this->_items[] = ['label' => Html::img('@web/images/flags/' . $language->acronym . '.gif', ['alt' => Yii::t('back', 'image - flag')]) . ' ' . $language->title, 'url' => Yii::$app->urlManager->createUrl(['site/switch-language', 'id' => $language->id])]; } Url::remember($this->routeBase); }
/** * Creates a new AdditionalField record model. * If creation is successful, the browser will be redirected to the 'index' page. * @return mixed */ public function actionCreate() { $model = new AdditionalFieldRecord(); if ($model->load(Yii::$app->request->post())) { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $model->language_id = $session['language_id']; if ($model->save()) { $session->setFlash('info', Yii::t('back', 'New additional field successfully added!')); return $this->redirect('index'); } } elseif (Yii::$app->request->isAjax) { return $this->renderAjax('_form', compact('model')); } return $this->render('_form', compact('model')); }
/** * @param integer|null $item_id */ public function __construct($item_id = null) { parent::__construct(); if ($item_id) { /** @var $email EmailRecord */ $email = EmailRecord::findOne($item_id); $this->item_id = $email->id; $this->email = $email->email; $this->language_id = $email->language_id; if ($email->active) { $this->boxes[] = self::PROPERTY_ACTIVE; } } else { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $this->language_id = $session['language_id']; $this->boxes[] = self::PROPERTY_ACTIVE; } }
/** * Creates data provider instance with search query applied * @param $params * @return ActiveDataProvider */ public function search($params) { /** @var ActiveQuery $query */ $query = PollRecord::find(); if (!isset($params['sort'])) { $query->orderBy(['updated_at' => SORT_DESC]); } $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $query->andWhere(['language_id' => $session['language_id']]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['active' => $this->active, 'main' => $this->main]); $query->andFilterWhere(['like', 'question', $this->question]); $query->andFilterWhere(['like', 'DATE_FORMAT(end_date,\'%d.%m.%Y\')', $this->end_date]); return $dataProvider; }
/** * Creates data provider instance with search query applied * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); if (!isset($params['sort'])) { $query->orderBy(['updated_at' => SORT_DESC]); } $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $query->andWhere(['language_id' => $session['language_id']]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['main' => $this->main, 'public' => $this->public, 'active' => $this->active]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * NewsletterForm constructor * @param integer|null $item_id */ public function __construct($item_id = null) { parent::__construct(); if ($item_id) { /** @var $newsletter Newsletter */ $newsletter = Newsletter::findOne($item_id); $this->item_id = $newsletter->id; $this->language_id = $newsletter->language_id; $this->title = $newsletter->title; $this->description = $newsletter->description; if ($newsletter->active) { $this->boxes[] = self::PROPERTY_ACTIVE; } $this->layout_id = $newsletter->layout_id; } else { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $this->language_id = $session['language_id']; $this->boxes[] = self::PROPERTY_ACTIVE; } }
/** * Creates data provider instance with search query applied * @param $params * @return ActiveDataProvider */ public function search($params) { /** @var ActiveQuery $query */ $query = Newsletter::find(); if (!isset($params['sort'])) { $query->orderBy(['updated_at' => SORT_DESC]); } $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $query->andWhere(['language_id' => $session['language_id']]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['active' => $this->active]); $query->andFilterWhere(['like', 'title', $this->title]); $query->andFilterWhere(['like', 'CONCAT(DATE_FORMAT(content_date,\'%d.%m.%Y\'),\' \',DATE_FORMAT(content_time,\'%H:%i\'))', $this->sendDateTime]); $dataProvider->sort->attributes['sendDateTime'] = ['asc' => ['content_date' => SORT_ASC, 'content_time' => SORT_ASC], 'desc' => ['content_date' => SORT_DESC, 'content_time' => SORT_DESC]]; return $dataProvider; }
/** * @inheritdoc */ public function init() { parent::init(); $session = Yii::$app->session; if (WebRecord::existsMoreWebRecords()) { if (!$session->has('web')) { $session->set('web', \Yii::$app->request->get('web', \Yii::$app->params['defaultWeb'])); } if (!($this->web = WebRecord::findOne(FrontEndHelper::getWebIdFromTextId($session->get('web'))))) { $session->set('web', \Yii::$app->params['defaultWeb']); throw new NotFoundHttpException(Yii::t('front', 'The requested page does not exist.')); } } else { $this->redirect(['install/default/index']); } if (!$this->web) { $this->web = WebRecord::findOne(FrontEndHelper::getWebIdFromTextId($session->get('web'))); } $session->set('web', null); $this->setWebTheme($this->web->theme); \Yii::$app->language = \Yii::$app->request->get('language', \Yii::$app->params['defaultLanguage']); $this->language = LanguageRecord::findOne(FrontEndHelper::getLanguageIdFromAcronym()); }
/** * Finds the Language record model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return LanguageRecord the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = LanguageRecord::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException(Yii::t('back', 'The requested page does not exist.')); }
/** * Returns gallery items for CKEditor gallery plugin * @return array */ public function actionGalleryItems() { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $items = ArrayHelper::map(Gallery::find()->andWhere(['language_id' => $session['language_id']])->orderBy(['updated_at' => SORT_DESC])->all(), 'title', 'id'); $response = Yii::$app->response; $response->format = Response::FORMAT_JSON; $response->data = $items; return $response; }
/* @var $form yii\bootstrap\ActiveForm */ use backend\components\LanguageButtonDropdown; use common\models\LanguageRecord; use yii\helpers\Html; use yii\widgets\ListView; $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $this->title = Yii::t('back', 'Files'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="file-index"> <?php if (LanguageRecord::existsMoreLanguageRecords(false, true)) { echo '<div class="pull-right">'; echo LanguageButtonDropdown::widget(['routeBase' => ['file/files']]); echo '</div>'; } ?> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo Html::a(Yii::t('back', 'Manage source files'), ['files-manage'], ['class' => 'btn btn-primary']); ?>
/* @var $this yii\web\View */ /* @var $model \backend\models\MenuItemForm */ /* @var $menu \common\models\MenuRecord */ /* @var $web_id integer */ /* @var $menu_id integer */ $session = Yii::$app->session; $menu = $model->getMenu(); $this->title = Yii::t('back', 'Menu Items'); $this->params['breadcrumbs'][] = $menu->web->title . ' - ' . $menu->title; $modelClass = Yii::t('back', 'Menu item'); ?> <div> <?php if ($model->language_id || LanguageRecord::existsMoreLanguageRecords(false, true)) { echo '<div class="pull-right">'; echo LanguageButtonDropdown::widget(['routeBase' => ['menu-item/index']]); echo '</div>'; } ?> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php $createUrl = ['menu-item/create', 'mid' => $model->menu_id]; echo Html::button(Yii::t('back', 'Create {modelClass}', compact('modelClass')), ['value' => Url::to($createUrl), 'title' => Yii::t('back', 'Create {modelClass}', compact('modelClass')), 'class' => 'showModalButton btn btn-success']);
/** * Returns language id from application language property * @return bool|string */ public static function getLanguageIdFromAcronym() { $id = LanguageRecord::find()->select('id')->where(['acronym' => \Yii::$app->language])->scalar(); return $id; }
/** * @return \yii\db\ActiveQuery */ public function getLanguage() { return $this->hasOne(LanguageRecord::className(), ['id' => 'language_id']); }
/** * Returns layout list options for dropdown * @return array */ public function getLayoutListOptions() { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $items = []; switch ($this->content_type) { case MenuItemRecord::CONTENT_PAGE: $items = ArrayHelper::map(LayoutRecord::find()->where(['content' => LayoutRecord::CONTENT_PAGE])->activeStatus()->orderBy(['main' => SORT_DESC])->all(), 'id', 'title'); break; case MenuItemRecord::CONTENT_CATEGORY: $items = ArrayHelper::map(LayoutRecord::find()->where(['content' => LayoutRecord::CONTENT_CATEGORY])->activeStatus()->orderBy(['main' => SORT_DESC])->all(), 'id', 'title'); break; default: break; } return $items; }
use backend\assets\FormAsset; use common\models\Gallery; use common\models\LanguageRecord; use yii\bootstrap\ActiveField; use yii\helpers\Html; use yii\bootstrap\ActiveForm; use yii\widgets\ListView; /* @var $this yii\web\View */ /* @var $model backend\models\GalleryAddPhotosForm */ /* @var $gallery common\models\Gallery */ /* @var $dataProvider yii\data\ActiveDataProvider */ /* @var $form yii\bootstrap\ActiveForm */ $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $gallery = Gallery::findOne($model->item_id); $this->title = Yii::t('back', 'add photos into gallery'); $this->params['breadcrumbs'][] = ['label' => Yii::t('back', 'Galleries'), 'url' => ['gallery/index']]; $this->params['breadcrumbs'][] = ['label' => $gallery->title . ' - ' . Yii::t('back', 'photos in gallery'), 'url' => ['gallery/photos', 'id' => $model->item_id]]; $this->params['breadcrumbs'][] = $this->title; FormAsset::register($this); ?> <div> <h1><?php echo Html::encode($this->title); ?> </h1>
/** * ArticleForm constructor * @param integer|null $item_id * @param bool $copy */ public function __construct($item_id = null, $copy = false) { parent::__construct(); if ($item_id) { /** @var $article Article */ $article = Article::find()->with('tags')->where(['id' => $item_id])->one(); if (!$copy) { $this->item_id = $article->id; } $this->language_id = $article->language_id; if ($article->image) { $this->imageFilename = $article->image->filename; } $this->perex = $article->perex; $this->title = $article->title; $this->description = $article->description; $this->content_date = $article->content_date ? Yii::$app->formatter->asDate($article->content_date, 'dd.MM.y') : null; $this->content_end_date = $article->content_end_date ? Yii::$app->formatter->asDate($article->content_end_date, 'dd.MM.y') : null; $this->content_time = $article->content_time ? Yii::$app->formatter->asTime($article->content_time, 'HH:mm') : null; if ($article->active) { $this->boxes[] = self::PROPERTY_ACTIVE; } if ($article->public) { $this->boxes[] = self::PROPERTY_PUBLIC; } $this->layout_id = $article->layout_id; $this->tagValues = $article->tagValues; } else { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $this->language_id = $session['language_id']; $this->boxes[] = self::PROPERTY_ACTIVE; $this->boxes[] = self::PROPERTY_PUBLIC; } $this->categoryBoxes = $this->getCategoryBoxes(); }
<?php /* @var $this yii\web\View */ /* @var $form frontend\utilities\MaterializeActiveForm */ /* @var $model frontend\models\SearchContent */ use common\models\LanguageRecord; use frontend\models\SearchContent; use frontend\utilities\MaterializeActiveForm; use yii\helpers\Url; $template = "\n{input}\n{label}\n{hint}\n{error}"; $model->target = SearchContent::TARGET_WEB; ?> <?php $webUrlPart = Yii::$app->request->get('web', \Yii::$app->params['defaultWeb']) == 'main' ? '' : '/' . Yii::$app->request->get('web'); $language = LanguageRecord::getLanguageValues(); $languageUrlPart = $language['main'] ? '' : '/' . $language['acronym']; $form = MaterializeActiveForm::begin(['action' => Url::toRoute(['page/search']) . $webUrlPart . $languageUrlPart, 'method' => 'get', 'id' => 'search-form']); ?> <div class="row"> <?php echo $form->field($model, 'target', ['template' => "\n{input}"])->hiddenInput(['value' => SearchContent::TARGET_WEB]); ?> <?php echo $form->field($model, 'q', ['template' => $template, 'options' => ['class' => 'input-field search-field col s12']]); ?> </div> <?php MaterializeActiveForm::end();
use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel backend\models\NewsletterSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $this->title = Yii::t('back', 'Newsletters'); $this->params['breadcrumbs'][] = $this->title; $modelClass = Yii::t('back', 'Newsletter'); ?> <div> <?php if ($session['language_id'] || LanguageRecord::existsMoreLanguageRecords(false, true)) { echo '<div class="pull-right">'; echo LanguageButtonDropdown::widget(['routeBase' => ['page/index']]); echo '</div>'; } ?> <h1><?php echo Html::encode($this->title); ?> </h1> <?php if (Yii::$app->user->can('manager')) { ?> <p>
/** * Returns dropdown content list options * @param $tid integer content type id * @return string */ public function actionContentListOptions($tid) { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $items = null; switch ($tid) { case MenuItemRecord::CONTENT_PAGE: $items = Page::find()->andWhere(['language_id' => $session['language_id']])->activeStatus()->orderBy('updated_at DESC')->all(); break; case MenuItemRecord::CONTENT_CATEGORY: $items = Category::find()->andWhere(['language_id' => $session['language_id']])->activeStatus()->orderBy('updated_at DESC')->all(); break; default: break; } $itemsOptions = ['arr' => false, 'prompt' => false]; return $this->renderPartial('_listOptions', compact('items', 'itemsOptions')); }