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