static function getLangByUrl($url = null) { if ($url === null) { return null; } else { $language = Lang::find()->where('url = :url', [':url' => $url])->one(); if ($language === null) { return null; } else { return $language; } } }
public function getLangUrl() { if ($this->_lang_url === null) { $this->_lang_url = $this->getUrl(); $url_list = explode('/', $this->_lang_url); $lang_url = isset($url_list[1]) ? $url_list[1] : null; Lang::setCurrent($lang_url); if ($lang_url !== null && $lang_url === Lang::getCurrent()->url && strpos($this->_lang_url, Lang::getCurrent()->url) === 1) { $this->_lang_url = substr($this->_lang_url, strlen(Lang::getCurrent()->url) + 1); } } return $this->_lang_url; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Lang::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'default' => $this->default, 'date_update' => $this->date_update, 'date_create' => $this->date_create]); $query->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'local', $this->local])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function init() { if (php_sapi_name() === 'cli') { return true; } parent::init(); $ip = $_SERVER['REMOTE_ADDR']; $browser = $_SERVER['HTTP_USER_AGENT']; $sessionId = md5($ip . $browser); if (($model = Lang::findOne(['session_id' => $sessionId])) === null) { $model = new Lang(); } $languageNew = Yii::$app->request->get('language'); if ($languageNew) { if (isset($this->languages[$languageNew])) { Yii::$app->language = $languageNew; $model->attributes = ['session_id' => $sessionId, 'lang' => $languageNew]; $model->save(); } } elseif (isset($model->lang)) { Yii::$app->language = $model->lang; } }
public function createUrl($params) { if (isset($params['lang_id'])) { //If language indetification exists, than try to find it in db //else work with default language $lang = Lang::findOne($params['lang_id']); if ($lang === null) { $lang = Lang::getDefaultLang(); } unset($params['lang_id']); } else { //If doesn't language parametr exist, than work with current language $lang = Lang::getCurrent(); } //Get formed URL (without language indentification prefix) $url = parent::createUrl($params); //Add prefix to URL - characters indentification of language if ($url == '/') { return '/' . $lang->url; } else { return '/' . $lang->url . $url; } }
public function createUrl($params) { if (isset($params['lang_id'])) { //Если указан идентификатор языка, то делаем попытку найти язык в БД, //иначе работаем с языком по умолчанию $lang = Lang::findOne($params['lang_id']); if ($lang === null) { $lang = Lang::getDefaultLang(); } unset($params['lang_id']); } else { //Если не указан параметр языка, то работаем с текущим языком $lang = Lang::getCurrent(); } //Получаем сформированный URL(без префикса идентификатора языка) $url = parent::createUrl($params); //Добавляем к URL префикс - буквенный идентификатор языка if ($url == '/') { return '/' . $lang->url; } else { return '/' . $lang->url . $url; } }
/* @var $model app\models\Brood */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="brood-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'date')->widget(DatePicker::classname(), ['options' => ['placeholder' => Yii::t('app', 'Enter birth date ...')], 'type' => DatePicker::TYPE_COMPONENT_APPEND, 'pluginOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd'], 'removeButton' => false, 'language' => \app\models\Lang::getCurrent()['local']]); ?> <?php echo $form->field($model, 'breed_id')->dropDownList(\app\models\Breed::getAll()); ?> <?php echo $form->field($model, 'common_status_id')->dropDownList(\app\models\CommonStatus::getAll()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
public function run() { return $this->render('lang/view', ['current' => Lang::getCurrent(), 'langs' => Lang::find()->where('id != :current_id', [':current_id' => Lang::getCurrent()->id])->all()]); }
public function getVeiwCountHumansAttribute() { return $this->view_count . ' ' . \Lang::choice('count.views', ru_count($this->view_count)); }
use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel app\models\MessageSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Messages'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="message-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('app', 'Create Message'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'language', 'value' => 'language', 'filter' => \yii\helpers\ArrayHelper::map(\app\models\Lang::find()->all(), 'url', 'url')], ['attribute' => 'id', 'value' => 'id0.message'], 'translation:ntext', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
public function getAnswersCountHumanAttribute() { // $count = (int) ($this->relationLoaded('answersCount') ? $this->answersCount : $this->answers->count()); $count = isset($this->answersCount) ? (int) $this->answersCount : 0; return $count . ' ' . \Lang::choice('count.answers', ru_count($count)); }
public function columnTable() { $array = array("aboutus_id" => array("label" => \Lang::get('core.table_aboutus_id'), "type" => "text", "name" => "aboutus_id", "value" => ""), "aboutus_name" => array("label" => \Lang::get('core.table_name'), "type" => "text", "name" => "aboutus_name", "value" => ""), "status" => array("label" => \Lang::get('core.table_status'), "type" => "radio", "name" => "status", "value" => "", "option" => array("0" => \Lang::get('core.disable'), "1" => \Lang::get('core.enable'))), "created" => array("label" => \Lang::get('core.table_created'), "type" => "date", "name" => "created", "value" => "")); return $array; }
public function getRoleName() { return \Lang::get(\Config::get('admin_user.roles.' . $this->role . '.name')); }
<?php use yii\helpers\Html; use app\components\widgets\ratingStars; use app\components\widgets\internetStatus; use app\models\Lang; $image = Html::img(Yii::getAlias('@web') . '/images/' . $model->id . '/image.png', ['alt' => 'some', 'class' => 'thing']); $stars = ratingStars::widget(['starsCount' => $model->stars]); $internet = internetStatus::widget(['internet' => $model->internet]); $currentLang = Lang::getCurrent()->url; $output = <<<HTML <br><br> <div class="panel panel-info" onMouseOver="((this.className=='panel panel-info')?this.className='panel panel-primary':this.className='panel panel-info')" onMouseOut="((this.className=='panel panel-info')?this.className='panel panel-primary':this.className='panel panel-info')" onClick="(this.className='panel panel-success')" > <div class="panel-heading"> <h3 class="panel-title">{$model->{'name_' . $currentLang}}</h3> </div> <div class="panel-body"> <div class="row"> <div class="col-lg-5"> {$stars} <br> {$image} <br>
/** * Finds the Lang model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Lang the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Lang::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }