@@ -5,7 +5,7 @@ |
||
| 5 | 5 | |
| 6 | 6 | $this->title = Yii::t('app', 'Update {modelClass}: ', [ |
| 7 | 7 | 'modelClass' => 'Language', |
| 8 | -]) . ' ' . $model->name; |
|
| 8 | +]).' '.$model->name; |
|
| 9 | 9 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Languages'), 'url' => ['index']]; |
| 10 | 10 | $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'language_id' => $model->primaryKey]]; |
| 11 | 11 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | $this->tableName = $model; |
| 17 | 17 | |
| 18 | 18 | if ($model === 'language') { |
| 19 | - $this->columns =[ |
|
| 19 | + $this->columns = [ |
|
| 20 | 20 | 'language', 'name' |
| 21 | 21 | ]; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if ($model === 'language_translation') { |
| 25 | - $this->columns =[ |
|
| 25 | + $this->columns = [ |
|
| 26 | 26 | 'model_class', 'model_field_name', 'model_id' |
| 27 | 27 | ]; |
| 28 | 28 | } |
@@ -53,15 +53,15 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | |
| 56 | - private function createIndexes(){ |
|
| 56 | + private function createIndexes() { |
|
| 57 | 57 | foreach ($this->columns as $column) { |
| 58 | - $this->createIndex($this->indexPrefix.$column,$this->tableName, $column); |
|
| 58 | + $this->createIndex($this->indexPrefix.$column, $this->tableName, $column); |
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - private function dropIndexes(){ |
|
| 62 | + private function dropIndexes() { |
|
| 63 | 63 | foreach ($this->columns as $column) { |
| 64 | - $this->dropIndex($this->indexPrefix.$column,$this->tableName); |
|
| 64 | + $this->dropIndex($this->indexPrefix.$column, $this->tableName); |
|
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | public $tableName = 'language_translation'; |
| 8 | 8 | public function safeUp() |
| 9 | 9 | { |
| 10 | - $this->createTable($this->tableName,[ |
|
| 10 | + $this->createTable($this->tableName, [ |
|
| 11 | 11 | 'language_translation_id' => $this->primaryKey()->comment('ID'), |
| 12 | 12 | 'language_id' => $this->integer()->notNull()->comment('Language'), |
| 13 | 13 | 'model_class' => $this->string(255)->notNull()->comment('Translated model class name'), |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | 'model_id' => $this->integer()->notNull()->comment('Translated model ID'), |
| 16 | 16 | 'value' => $this->text()->notNull()->comment('Translated model class name'), |
| 17 | 17 | ]); |
| 18 | - $this->addForeignKey('fk_language_translation_language_id','language_translation','language_id','language','language_id'); |
|
| 18 | + $this->addForeignKey('fk_language_translation_language_id', 'language_translation', 'language_id', 'language', 'language_id'); |
|
| 19 | 19 | |
| 20 | 20 | } |
| 21 | 21 | |
@@ -8,18 +8,18 @@ |
||
| 8 | 8 | |
| 9 | 9 | public function safeUp() |
| 10 | 10 | { |
| 11 | - $this->createTable($this->tableName,[ |
|
| 11 | + $this->createTable($this->tableName, [ |
|
| 12 | 12 | 'language_id' => $this->primaryKey()->comment('ID'), |
| 13 | 13 | 'language' => $this->string(16)->notNull()->comment('language code'), |
| 14 | 14 | 'name' => $this->string(255)->notNull()->comment('Language name'), |
| 15 | 15 | |
| 16 | 16 | ]); |
| 17 | - $this->insert($this->tableName,['language_id'=>1, 'language'=>'en-US','name'=>'English']); |
|
| 18 | - $this->insert($this->tableName,['language_id'=>2, 'language'=>'et','name'=>'Estonian']); |
|
| 19 | - $this->insert($this->tableName,['language_id'=>3, 'language'=>'ru','name'=>'Russian']); |
|
| 20 | - $this->insert($this->tableName,['language_id'=>4, 'language'=>'fi','name'=>'Finnish']); |
|
| 21 | - $this->insert($this->tableName,['language_id'=>5, 'language'=>'lv','name'=>'Latvian']); |
|
| 22 | - $this->insert($this->tableName,['language_id'=>6, 'language'=>'lt','name'=>'Lithuanian']); |
|
| 17 | + $this->insert($this->tableName, ['language_id'=>1, 'language'=>'en-US', 'name'=>'English']); |
|
| 18 | + $this->insert($this->tableName, ['language_id'=>2, 'language'=>'et', 'name'=>'Estonian']); |
|
| 19 | + $this->insert($this->tableName, ['language_id'=>3, 'language'=>'ru', 'name'=>'Russian']); |
|
| 20 | + $this->insert($this->tableName, ['language_id'=>4, 'language'=>'fi', 'name'=>'Finnish']); |
|
| 21 | + $this->insert($this->tableName, ['language_id'=>5, 'language'=>'lv', 'name'=>'Latvian']); |
|
| 22 | + $this->insert($this->tableName, ['language_id'=>6, 'language'=>'lt', 'name'=>'Lithuanian']); |
|
| 23 | 23 | |
| 24 | 24 | } |
| 25 | 25 | |
@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | { |
| 31 | 31 | parent::init(); |
| 32 | 32 | |
| 33 | - if(!$this->parent){ |
|
| 33 | + if (!$this->parent) { |
|
| 34 | 34 | throw new yii\base\InvalidConfigException('Parent Model must be defined while initiating languages-settings'); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - if(!$this->parent instanceof WithLanguagesInterface){ |
|
| 37 | + if (!$this->parent instanceof WithLanguagesInterface) { |
|
| 38 | 38 | throw new yii\base\InvalidConfigException('Parent Model must implement WithLanguagesInterface'); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | protected function setLanguageSettings() { |
| 45 | - if(!empty($this->parent->languages)){ |
|
| 46 | - foreach ($this->parent->languages as $language){ |
|
| 45 | + if (!empty($this->parent->languages)) { |
|
| 46 | + foreach ($this->parent->languages as $language) { |
|
| 47 | 47 | /* @var BaseLanguageSettings */ |
| 48 | 48 | $languageSettings = Yii::createObject([ |
| 49 | 49 | 'class' => $this->languageSettingsClass, |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - public function save($runValidation = true,$attributeNames=null){ |
|
| 59 | - if(!empty($this->languageSettings)){ |
|
| 58 | + public function save($runValidation = true, $attributeNames = null) { |
|
| 59 | + if (!empty($this->languageSettings)) { |
|
| 60 | 60 | // language by language |
| 61 | - foreach ($this->languageSettings as $key => $languageSetting){ |
|
| 62 | - $languageSetting->save($runValidation,$attributeNames); |
|
| 61 | + foreach ($this->languageSettings as $key => $languageSetting) { |
|
| 62 | + $languageSetting->save($runValidation, $attributeNames); |
|
| 63 | 63 | $this->addErrors($languageSetting->errors); |
| 64 | 64 | $this->languageSettings[$key] = $languageSetting; |
| 65 | 65 | } |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | * @param string $key |
| 76 | 76 | * @return bool|string |
| 77 | 77 | */ |
| 78 | - public function getSettingByLanguageAndKey($language, $key){ |
|
| 78 | + public function getSettingByLanguageAndKey($language, $key) { |
|
| 79 | 79 | $setting = $this->getSettingByKeyAndLanguage($language, $key); |
| 80 | - if(!$setting){ |
|
| 80 | + if (!$setting) { |
|
| 81 | 81 | $setting = $this->getSettingByKeyInAnyLanguage($key); |
| 82 | 82 | } |
| 83 | 83 | return $setting; |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | * @param string $key |
| 91 | 91 | * @return bool|string |
| 92 | 92 | */ |
| 93 | - public function getSettingByKeyAndLanguage($language, $key){ |
|
| 94 | - if(isset($this->languageSettings[$language->primaryKey])){ |
|
| 93 | + public function getSettingByKeyAndLanguage($language, $key) { |
|
| 94 | + if (isset($this->languageSettings[$language->primaryKey])) { |
|
| 95 | 95 | $languageSettings = $this->languageSettings[$language->primaryKey]; |
| 96 | - if($languageSettings->{$key} && $languageSettings->{$key} != ''){ |
|
| 96 | + if ($languageSettings->{$key} && $languageSettings->{$key} != '') { |
|
| 97 | 97 | return $languageSettings->{$key}; |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -107,10 +107,10 @@ discard block |
||
| 107 | 107 | * @param string $key |
| 108 | 108 | * @return bool|string |
| 109 | 109 | */ |
| 110 | - public function getSettingByKeyInAnyLanguage($key){ |
|
| 111 | - if(!empty($this->languageSettings)){ |
|
| 112 | - foreach ($this->languageSettings as $language_id => $languageSettings){ |
|
| 113 | - if($languageSettings->{$key} && $languageSettings->{$key} != ''){ |
|
| 110 | + public function getSettingByKeyInAnyLanguage($key) { |
|
| 111 | + if (!empty($this->languageSettings)) { |
|
| 112 | + foreach ($this->languageSettings as $language_id => $languageSettings) { |
|
| 113 | + if ($languageSettings->{$key} && $languageSettings->{$key} != '') { |
|
| 114 | 114 | return $languageSettings->{$key}; |
| 115 | 115 | } |
| 116 | 116 | } |
@@ -125,12 +125,12 @@ discard block |
||
| 125 | 125 | { |
| 126 | 126 | $scope = yii\helpers\StringHelper::basename($this->languageSettingsClass); |
| 127 | 127 | if (isset($data[$scope])) { |
| 128 | - foreach ($data[$scope] as $language_id => $attributes){ |
|
| 128 | + foreach ($data[$scope] as $language_id => $attributes) { |
|
| 129 | 129 | $language = Language::findOne($language_id); |
| 130 | 130 | /** @var BaseLanguageSettings $model */ |
| 131 | - if(isset($this->languageSettings[$language_id])){ |
|
| 131 | + if (isset($this->languageSettings[$language_id])) { |
|
| 132 | 132 | $model = $this->languageSettings[$language_id]; |
| 133 | - }else{ |
|
| 133 | + } else { |
|
| 134 | 134 | $model = Yii::createObject([ |
| 135 | 135 | 'class' => $this->languageSettingsClass, |
| 136 | 136 | 'parent'=>$this->parent, |
@@ -130,7 +130,7 @@ |
||
| 130 | 130 | /** @var BaseLanguageSettings $model */ |
| 131 | 131 | if(isset($this->languageSettings[$language_id])){ |
| 132 | 132 | $model = $this->languageSettings[$language_id]; |
| 133 | - }else{ |
|
| 133 | + } else{ |
|
| 134 | 134 | $model = Yii::createObject([ |
| 135 | 135 | 'class' => $this->languageSettingsClass, |
| 136 | 136 | 'parent'=>$this->parent, |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param string $language As in language\Language->language |
| 63 | 63 | * @return string The county / flag code that matches the county code. If no match is found then the initial country code is returned |
| 64 | 64 | */ |
| 65 | - public static function getFlagCode($language){ |
|
| 65 | + public static function getFlagCode($language) { |
|
| 66 | 66 | $map = [ |
| 67 | 67 | 'en-US'=>'GB', |
| 68 | 68 | 'et'=>'EE', |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | 'pl'=>'PL', |
| 75 | 75 | ]; |
| 76 | 76 | |
| 77 | - if(isset($map[$language])){ |
|
| 77 | + if (isset($map[$language])) { |
|
| 78 | 78 | return $map[$language]; |
| 79 | 79 | } |
| 80 | 80 | return strtoupper($language); |
@@ -84,18 +84,18 @@ discard block |
||
| 84 | 84 | * @param string $languageCode language code |
| 85 | 85 | * @return array|null|Language |
| 86 | 86 | */ |
| 87 | - public static function getByCode($languageCode){ |
|
| 88 | - if($languageCode === 'en'){ |
|
| 87 | + public static function getByCode($languageCode) { |
|
| 88 | + if ($languageCode === 'en') { |
|
| 89 | 89 | $languageCode = 'en-US'; |
| 90 | 90 | } |
| 91 | 91 | /* @var Language $language */ |
| 92 | - $language =Language::find()->andWhere(['language'=>$languageCode])->one(); ; |
|
| 92 | + $language = Language::find()->andWhere(['language'=>$languageCode])->one(); ; |
|
| 93 | 93 | return $language; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - public static function getByCodes($languageCodes){ |
|
| 96 | + public static function getByCodes($languageCodes) { |
|
| 97 | 97 | return Language::find() |
| 98 | - ->andWhere(['in','language',$languageCodes]) |
|
| 98 | + ->andWhere(['in', 'language', $languageCodes]) |
|
| 99 | 99 | ->all(); |
| 100 | 100 | } |
| 101 | 101 | |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | public function rules() |
| 18 | 18 | { |
| 19 | 19 | return [ |
| 20 | - [['language_id','language', 'name'], 'safe'], |
|
| 20 | + [['language_id', 'language', 'name'], 'safe'], |
|
| 21 | 21 | ]; |
| 22 | 22 | } |
| 23 | 23 | |
@@ -44,12 +44,12 @@ |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** {@inheritdoc} */ |
| 47 | - public function save($runValidation = true, $attributeNames = NULL){ |
|
| 48 | - if(!empty($this->settings)){ |
|
| 49 | - foreach ($this->settings as $key=> $setting){ |
|
| 47 | + public function save($runValidation = true, $attributeNames = NULL) { |
|
| 48 | + if (!empty($this->settings)) { |
|
| 49 | + foreach ($this->settings as $key=> $setting) { |
|
| 50 | 50 | // delete empty |
| 51 | - if($setting->value === null || $setting->value === ''){ |
|
| 52 | - if(!$setting->isNewRecord){ |
|
| 51 | + if ($setting->value === null || $setting->value === '') { |
|
| 52 | + if (!$setting->isNewRecord) { |
|
| 53 | 53 | $setting->delete(); |
| 54 | 54 | } |
| 55 | 55 | } else { |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | public function rules() |
| 35 | 35 | { |
| 36 | 36 | return array_merge([ |
| 37 | - [['language_id', 'model_class', 'model_id', 'value','model_field_name'], 'required'], |
|
| 37 | + [['language_id', 'model_class', 'model_id', 'value', 'model_field_name'], 'required'], |
|
| 38 | 38 | [['language_id', 'model_id'], 'integer'], |
| 39 | 39 | [['value'], 'string'], |
| 40 | 40 | [['model_class'], 'string', 'max' => 255], |
| 41 | 41 | [['model_field_name'], 'string', 'max' => 128], |
| 42 | 42 | [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::class, 'targetAttribute' => ['language_id' => 'language_id']] |
| 43 | - ], parent::rules()); |
|
| 43 | + ], parent::rules()); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | * @param string $column |
| 66 | 66 | * @return LanguageTranslation[] |
| 67 | 67 | */ |
| 68 | - public static function findTranslations($class, $id, $column){ |
|
| 68 | + public static function findTranslations($class, $id, $column) { |
|
| 69 | 69 | /** @var LanguageTranslation $model */ |
| 70 | 70 | $query = self::find()->andWhere([ |
| 71 | 71 | 'model_class'=>$class, |
| 72 | 72 | 'model_id'=>$id, |
| 73 | - 'model_field_name'=>$column,]) |
|
| 73 | + 'model_field_name'=>$column, ]) |
|
| 74 | 74 | ->indexBy('language_id'); |
| 75 | 75 | |
| 76 | 76 | return $query->all(); |