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