@@ -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 | $this->setLanguageSettings(); |
@@ -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 $languageSettings */ |
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,10 +125,10 @@ 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 | 133 | } else { |
134 | 134 | $model = Yii::createObject([ |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | class BaseLanguageSetting extends MyActiveRecord implements SettingInterface { |
22 | 22 | |
23 | 23 | /** @var string $typeColumn the column containing setting type id */ |
24 | - protected static $typeColumn = "key"; |
|
24 | + protected static $typeColumn = "key"; |
|
25 | 25 | /** @var string */ |
26 | 26 | public $keyColumn = "key"; |
27 | 27 | |
@@ -36,11 +36,11 @@ discard block |
||
36 | 36 | public function init() |
37 | 37 | { |
38 | 38 | parent::init(); |
39 | - if($this->insert()){ |
|
40 | - if(!$this->parent){ |
|
39 | + if ($this->insert()) { |
|
40 | + if (!$this->parent) { |
|
41 | 41 | throw new InvalidConfigException('Parent Model must be defined while initiating languages-settings'); |
42 | 42 | } |
43 | - if(!$this->parent instanceof WithLanguageInterface){ |
|
43 | + if (!$this->parent instanceof WithLanguageInterface) { |
|
44 | 44 | throw new InvalidConfigException('Parent Model must implement ModelWithLanguages'); |
45 | 45 | } |
46 | 46 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | [['language_id', 'value'], 'required'], |
58 | 58 | [['value'], 'string'], |
59 | 59 | [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::class, 'targetAttribute' => ['language_id' => 'language_id']], |
60 | - ], parent::rules()); |
|
60 | + ], parent::rules()); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,37 +66,37 @@ discard block |
||
66 | 66 | * @param string $key |
67 | 67 | * @return bool|static|array |
68 | 68 | */ |
69 | - public static function getSetting($parent, $language, $key){ |
|
69 | + public static function getSetting($parent, $language, $key) { |
|
70 | 70 | |
71 | 71 | /** @var TypeInterface $typeClass */ |
72 | 72 | $typeClass = static::$typeClass; |
73 | 73 | /** @var TypeInterface $type */ |
74 | 74 | $type = $typeClass::getByKey($key); |
75 | 75 | |
76 | - if(!empty($type)){ |
|
76 | + if (!empty($type)) { |
|
77 | 77 | /** @var BaseLanguageSetting $model */ |
78 | 78 | $query = static::find(); |
79 | - if(!empty($parent)){ |
|
79 | + if (!empty($parent)) { |
|
80 | 80 | $query->andWhere([$parent->primaryKeySingle() =>$parent->primaryKey]); |
81 | 81 | } |
82 | - $model =$query->andWhere(['language_id'=>$language->primaryKey]) |
|
82 | + $model = $query->andWhere(['language_id'=>$language->primaryKey]) |
|
83 | 83 | ->andWhere([$type->primaryKeySingle()=>$type->{$type->primaryKeySingle()}]) |
84 | 84 | ->one(); |
85 | 85 | |
86 | - if(empty($model)){ |
|
86 | + if (empty($model)) { |
|
87 | 87 | /** @var BaseLanguageSetting $model */ |
88 | 88 | $model = \Yii::createObject(['class'=>static::class]); |
89 | 89 | $model->language_id = $language->primaryKey; |
90 | - if(!empty($parent)){ |
|
90 | + if (!empty($parent)) { |
|
91 | 91 | $model->{$parent->primaryKeySingle()} = $parent->primaryKey; |
92 | 92 | } |
93 | - $model->{$type->primaryKeySingle()}=$type->{$type->primaryKeySingle()}; |
|
93 | + $model->{$type->primaryKeySingle()} = $type->{$type->primaryKeySingle()}; |
|
94 | 94 | |
95 | 95 | } |
96 | 96 | return $model; |
97 | 97 | } |
98 | 98 | |
99 | - throw new InvalidConfigException('Undefined type key: ' . $key); |
|
99 | + throw new InvalidConfigException('Undefined type key: '.$key); |
|
100 | 100 | |
101 | 101 | } |
102 | 102 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @param $key string |
137 | 137 | * @return static |
138 | 138 | */ |
139 | - public function findOneByKey($key){ |
|
139 | + public function findOneByKey($key) { |
|
140 | 140 | /** @var static $model */ |
141 | 141 | $model = static::find() |
142 | 142 | ->andWhere([static::$typeColumn => $key]) |
@@ -48,12 +48,12 @@ |
||
48 | 48 | } |
49 | 49 | |
50 | 50 | /** {@inheritdoc} */ |
51 | - public function save($runValidation = true, $attributeNames = NULL){ |
|
52 | - if(!empty($this->settings)){ |
|
51 | + public function save($runValidation = true, $attributeNames = NULL) { |
|
52 | + if (!empty($this->settings)) { |
|
53 | 53 | foreach ($this->settings as $key => $setting) { |
54 | 54 | // delete empty |
55 | - if($setting->value === null || $setting->value === ''){ |
|
56 | - if(!$setting->isNewRecord){ |
|
55 | + if ($setting->value === null || $setting->value === '') { |
|
56 | + if (!$setting->isNewRecord) { |
|
57 | 57 | $setting->delete(); |
58 | 58 | } |
59 | 59 | } else { |