Exemplo n.º 1
0
 /**
  * Resolve
  * Resolves the current request into a route and the associated parameters.
  * Sets default application language
  * @return array the first element is the route, and the second is the associated parameters.
  * @throws \yii\web\NotFoundHttpException if the request cannot be resolved.
  */
 public function resolve()
 {
     $resolve = parent::resolve();
     $languages = Language::getDb()->cache(function ($db) {
         return Language::find()->where(['is_active' => true])->asArray()->all();
     });
     Yii::$app->params['languages'] = ArrayHelper::map($languages, 'code', 'code');
     Yii::$app->language = $this->getCurrentLang();
     return $resolve;
 }
 public function validateKeyCodePair($attribute)
 {
     $existValidator = \Yii::createObject(['class' => ExistValidator::className(), 'targetClass' => Language::className(), 'targetAttribute' => 'code']);
     $errorLangExists = null;
     $existValidator->validate($this->lang_code, $errorLangExists);
     if (!empty($errorLangExists)) {
         $this->addError('lang_code', $errorLangExists);
     } else {
         if (($testItem = $this->findOne(['key' => $this->key, 'lang_code' => $this->lang_code])) && $testItem->id != $this->id) {
             $this->addError($attribute, \Yii::t('support', 'Key must be unique for selected language'));
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Render block content
  * @return string
  */
 public function run()
 {
     $languages = Language::getDb()->cache(function ($db) {
         $query = Language::find();
         if (!$this->showDisabled) {
             $query->where(['is_active' => true]);
         }
         return $query->asArray()->all();
     });
     $list = [];
     foreach ($languages as $lang) {
         if ($lang['code'] == Yii::$app->language) {
             $current = $lang;
         } else {
             $list[] = ['code' => $lang['code'], 'name' => $lang['name'], 'flag' => $lang['flag'], 'url' => Url::toRoute(['/multilang/change/set', 'lang' => $lang['code']])];
         }
     }
     return $this->render($this->layout, ['languages' => $list, 'current' => $current]);
 }
Exemplo n.º 4
0
 public function run()
 {
     $list = [];
     $listKeys = $this->query->select(['key', 'lang_code'])->asArray()->all();
     $listLangs = \jarrus90\Multilang\Models\Language::listMap();
     foreach ($listKeys as $item) {
         if (empty($list[$item['key']])) {
             $list[$item['key']] = [];
         }
         $list[$item['key']][$item['lang_code']] = $item['lang_code'];
     }
     foreach ($list as $key => $elem) {
         $res = array_diff_key($listLangs, $elem);
         if (count($res) == 0) {
             unset($list[$key]);
         } else {
             $list[$key] = $res;
         }
     }
     return Yii::$app->controller->render('check', ['list' => $list]);
 }
Exemplo n.º 5
0
<?php

use yii\web\View;
use yii\helpers\Url;
use yii\helpers\Html;
use kartik\grid\GridView;
use yii\data\ActiveDataProvider;
use jarrus90\Multilang\Models\Language;
/**
 * @var View $this
 * @var ActiveDataProvider $dataProvider
 */
$this->beginContent('@jarrus90/Support/views/_adminFaqLayout.php');
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $filterModel, 'pjax' => true, 'hover' => true, 'export' => false, 'id' => 'list-table', 'toolbar' => [['content' => Html::a('<i class="glyphicon glyphicon-plus"></i>', Url::toRoute(['create']), ['data-pjax' => 0, 'class' => 'btn btn-default', 'title' => \Yii::t('support', 'New category')]) . ' ' . Html::a('<i class="glyphicon glyphicon-repeat"></i>', Url::toRoute(['index']), ['data-pjax' => 0, 'class' => 'btn btn-default', 'title' => Yii::t('support', 'Reset filter')]) . ' ' . Html::a('<i class="glyphicon glyphicon-list-alt"></i>', Url::toRoute(['check']), ['data-pjax' => 0, 'class' => 'btn btn-default', 'title' => Yii::t('support', 'Check filling')])]], 'panel' => ['type' => \kartik\grid\GridView::TYPE_DEFAULT], 'layout' => "{toolbar}{items}{pager}", 'pager' => ['options' => ['class' => 'pagination pagination-sm no-margin']], 'columns' => [['attribute' => 'lang_code', 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['theme' => 'default', 'data' => Language::listMap(), 'options' => ['placeholder' => Yii::t('support', 'Language')], 'pluginOptions' => ['allowClear' => true]], 'width' => '10%'], ['attribute' => 'key', 'width' => '40%'], ['attribute' => 'title', 'width' => '40%'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]);
$this->endContent();
Exemplo n.º 6
0
use yii\helpers\Url;
use yii\helpers\Html;
use yii\web\JsExpression;
use yii\bootstrap\ActiveForm;
use kartik\select2\Select2;
use jarrus90\Multilang\Models\Language;
$this->params['breadcrumbs'][] = $this->title;
$this->beginContent('@jarrus90/Content/views/_adminLayout.php');
?>

<?php 
$form = ActiveForm::begin(['layout' => 'horizontal', 'enableAjaxValidation' => true, 'enableClientValidation' => false, 'fieldConfig' => ['horizontalCssClasses' => ['wrapper' => 'col-sm-9']]]);
?>

<?php 
echo $form->field($model, 'key');
echo $form->field($model, 'lang_code')->widget(Select2::className(), ['theme' => 'default', 'data' => Language::listMap(), 'pluginEvents' => ["change" => "function() { \$('#page-category_key').val('').trigger('change'); }"], 'options' => ['placeholder' => Yii::t('content', 'Select language')]]);
echo $form->field($model, 'title');
echo $form->field($model, 'content')->widget(\jarrus90\Content\Widgets\Redactor::className(), ['clientOptions' => ['lang' => Yii::$app->language, 'minHeight' => 200, 'plugins' => ['fontsize', 'fontcolor', 'fontfamily', 'table', 'counter', 'fullscreen', 'imagemanager']]]);
echo $form->field($model, 'category_key')->widget(Select2::className(), ['theme' => 'default', 'pluginOptions' => ['ajax' => ['url' => Url::toRoute('/content/category/list'), 'dataType' => 'json', 'delay' => 50, 'data' => new JsExpression('function(params) { return {lang: $(\'#page-lang_code\').val()}; }')], 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), 'templateResult' => new JsExpression('function (procedure) { return procedure.text; }'), 'templateSelection' => new JsExpression('function (procedure) { return procedure.text; }')], 'options' => ['placeholder' => Yii::t('support', 'Select category')]]);
echo $form->field($model, 'meta_keywords');
echo $form->field($model, 'meta_description');
?>

<?php 
echo Html::submitButton(Yii::t('content', 'Save'), ['class' => 'btn btn-success btn-block']);
?>

<?php 
ActiveForm::end();
$this->endContent();
Exemplo n.º 7
0
 /** @inheritdoc */
 public function rules()
 {
     return ['usernameRequired' => ['username', 'required', 'on' => ['register', 'create', 'connect', 'update']], 'usernameMatch' => ['username', 'match', 'pattern' => static::$usernameRegexp], 'usernameLength' => ['username', 'string', 'min' => 3, 'max' => 255], 'usernameUnique' => ['username', 'unique', 'message' => Yii::t('user', 'This username has already been taken')], 'usernameTrim' => ['username', 'trim'], 'emailRequired' => ['email', 'required', 'on' => ['register', 'connect', 'create', 'update']], 'emailPattern' => ['email', 'email'], 'emailLength' => ['email', 'string', 'max' => 255], 'emailUnique' => ['email', 'unique', 'message' => Yii::t('user', 'This email address has already been taken')], 'emailTrim' => ['email', 'trim'], 'passwordRequired' => ['password', 'required', 'on' => ['register']], 'passwordLength' => ['password', 'string', 'min' => 6, 'on' => ['register', 'create']], 'langExists' => ['lang', 'exist', 'targetClass' => \jarrus90\Multilang\Models\Language::className(), 'targetAttribute' => 'code']];
 }
Exemplo n.º 8
0
 /**
  * Validation rules
  * @return array
  */
 public function rules()
 {
     return ['required' => [['key', 'title', 'content', 'lang_code'], 'required', 'on' => ['create', 'update']], 'keyValid' => ['key', 'validateKeyCodePair', 'on' => ['create', 'update']], 'langExists' => ['lang_code', 'exist', 'targetClass' => Language::className(), 'targetAttribute' => 'code'], 'safeSearch' => [['key', 'title', 'lang_code'], 'safe', 'on' => ['search']]];
 }
Exemplo n.º 9
0
<?php

/**
 * @var $this  yii\web\View
 * @var $model jarrus90\User\models\Role
 */
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use kartik\select2\Select2;
use jarrus90\Multilang\Models\Language;
$this->params['breadcrumbs'][] = $this->title;
$this->beginContent('@jarrus90/Content/views/_adminLayout.php');
?>

<?php 
$form = ActiveForm::begin(['layout' => 'horizontal', 'enableAjaxValidation' => true, 'enableClientValidation' => false, 'fieldConfig' => ['horizontalCssClasses' => ['wrapper' => 'col-sm-9']]]);
echo $form->field($model, 'key');
echo $form->field($model, 'lang_code')->widget(Select2::className(), ['theme' => 'default', 'data' => Language::listMap(), 'options' => ['placeholder' => Yii::t('content', 'Select language')]]);
echo $form->field($model, 'title');
echo $form->field($model, 'content')->widget(\jarrus90\Content\Widgets\Redactor::className(), ['clientOptions' => ['lang' => Yii::$app->language, 'minHeight' => 200, 'plugins' => ['fontsize', 'fontcolor', 'fontfamily', 'table', 'counter', 'fullscreen', 'imagemanager']]]);
?>

<?php 
echo Html::submitButton(Yii::t('content', 'Save'), ['class' => 'btn btn-success btn-block']);
?>

<?php 
ActiveForm::end();
$this->endContent();
Exemplo n.º 10
0
 /**
  * Validation rules
  * @return array
  */
 public function rules()
 {
     return ['processRequired' => [['code', 'name', 'flag', 'is_active'], 'required', 'on' => ['create', 'update']], 'searchSafe' => [['code', 'name', 'is_active'], 'safe', 'on' => ['search']], 'codeUnique' => ['code', 'unique', 'targetClass' => Language::className(), 'message' => Yii::t('multilang', 'Code must be unique'), 'when' => function ($model) {
         return $model->code != $model->_model->code;
     }, 'on' => ['create', 'update']]];
 }
Exemplo n.º 11
0
 /**
  * Finds the Language model based on its code value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param string $code
  *
  * @return Language the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findLanguage($code)
 {
     $language = Language::findOne($code);
     if ($language === null) {
         throw new \yii\web\NotFoundHttpException('The requested language does not exist');
     }
     return $language;
 }