@@ -68,9 +68,11 @@ discard block |
||
68 | 68 | ] |
69 | 69 | )->execute(); |
70 | 70 | |
71 | - if ($ids) foreach ($ids as $id) { |
|
71 | + if ($ids) { |
|
72 | + foreach ($ids as $id) { |
|
72 | 73 | if (empty($id)) |
73 | 74 | continue; |
75 | + } |
|
74 | 76 | $file = File::findOne($id); |
75 | 77 | if ($file) { |
76 | 78 | $file->object_id = $this->owner->id; |
@@ -105,8 +107,9 @@ discard block |
||
105 | 107 | in_array($this->owner->scenario, $params['requiredOn']) && |
106 | 108 | !in_array($this->owner->scenario, $params['requiredExcept']) && |
107 | 109 | !isset($this->_values[$attributeIds][1]) |
108 | - ) |
|
109 | - $this->owner->addError($attributeName, $params['requiredMessage']); |
|
110 | + ) { |
|
111 | + $this->owner->addError($attributeName, $params['requiredMessage']); |
|
112 | + } |
|
110 | 113 | } |
111 | 114 | } |
112 | 115 | |
@@ -123,8 +126,8 @@ discard block |
||
123 | 126 | $validators = $owner->validators; |
124 | 127 | |
125 | 128 | // Пробегаемся по валидаторам и вычисляем, какие из них касаются наших файл-полей |
126 | - if ($validators) |
|
127 | - foreach ($validators as $key => $validator) { |
|
129 | + if ($validators) { |
|
130 | + foreach ($validators as $key => $validator) { |
|
128 | 131 | |
129 | 132 | // Сначала пробегаемся по файловым валидаторам |
130 | 133 | if ($validator::className() == 'yii\validators\FileValidator' || $validator::className() == 'floor12\files\components\ReformatValidator') { |
@@ -132,6 +135,7 @@ discard block |
||
132 | 135 | |
133 | 136 | if (is_string($params)) { |
134 | 137 | $field = $params; |
138 | + } |
|
135 | 139 | $params = []; |
136 | 140 | } |
137 | 141 | |
@@ -167,8 +171,10 @@ discard block |
||
167 | 171 | } |
168 | 172 | |
169 | 173 | // Добавляем дефолтный валидатор для прилетающих айдишников |
170 | - if ($this->attributes) foreach ($this->attributes as $fieldName => $fieldParams) { |
|
174 | + if ($this->attributes) { |
|
175 | + foreach ($this->attributes as $fieldName => $fieldParams) { |
|
171 | 176 | $validator = Validator::createValidator('safe', $owner, ["{$fieldName}_ids"]); |
177 | + } |
|
172 | 178 | $validators->append($validator); |
173 | 179 | } |
174 | 180 | } |
@@ -189,8 +195,9 @@ discard block |
||
189 | 195 | */ |
190 | 196 | public function canSetProperty($name, $checkVars = true) |
191 | 197 | { |
192 | - if (array_key_exists($this->getRealAttributeName($name), $this->attributes)) |
|
193 | - return true; |
|
198 | + if (array_key_exists($this->getRealAttributeName($name), $this->attributes)) { |
|
199 | + return true; |
|
200 | + } |
|
194 | 201 | |
195 | 202 | return parent::canSetProperty($name, $checkVars = true); |
196 | 203 | } |
@@ -216,8 +223,8 @@ discard block |
||
216 | 223 | isset($this->attributes[$att_name]['validator']) && |
217 | 224 | isset($this->attributes[$att_name]['validator']['yii\validators\FileValidator']) && |
218 | 225 | $this->attributes[$att_name]['validator']['yii\validators\FileValidator']->maxFiles > 1 |
219 | - ) |
|
220 | - $this->cachedFiles[$att_name] = File::find() |
|
226 | + ) { |
|
227 | + $this->cachedFiles[$att_name] = File::find() |
|
221 | 228 | ->where( |
222 | 229 | [ |
223 | 230 | 'object_id' => $this->owner->id, |
@@ -226,7 +233,7 @@ discard block |
||
226 | 233 | ]) |
227 | 234 | ->orderBy('ordering ASC') |
228 | 235 | ->all(); |
229 | - else { |
|
236 | + } else { |
|
230 | 237 | $this->cachedFiles[$att_name] = File::find() |
231 | 238 | ->where( |
232 | 239 | [ |
@@ -251,8 +258,9 @@ discard block |
||
251 | 258 | { |
252 | 259 | $attribute = $this->getRealAttributeName($name); |
253 | 260 | |
254 | - if (array_key_exists($attribute, $this->attributes)) |
|
255 | - $this->_values[$attribute] = $value; |
|
261 | + if (array_key_exists($attribute, $this->attributes)) { |
|
262 | + $this->_values[$attribute] = $value; |
|
263 | + } |
|
256 | 264 | } |
257 | 265 | |
258 | 266 |