@@ -78,17 +78,17 @@ discard block |
||
| 78 | 78 | Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
| 79 | 79 | |
| 80 | 80 | // Formato de estrura em ['sucess','count','data] |
| 81 | - Yii::$app->response->on(\yii\web\Response::EVENT_BEFORE_SEND, function ($event) { |
|
| 81 | + Yii::$app->response->on(\yii\web\Response::EVENT_BEFORE_SEND, function($event) { |
|
| 82 | 82 | // yii\web\Response |
| 83 | 83 | $response = $event->sender; |
| 84 | 84 | |
| 85 | 85 | // Dados |
| 86 | - $count = $response->isSuccessful? $this->count: 0; |
|
| 86 | + $count = $response->isSuccessful ? $this->count : 0; |
|
| 87 | 87 | $success = $response->isSuccessful; |
| 88 | 88 | $data = $response->data; |
| 89 | 89 | |
| 90 | 90 | // Esconder classe do erro |
| 91 | - if (!$success) { |
|
| 91 | + if (!$success) { |
|
| 92 | 92 | \yii\helpers\ArrayHelper::remove($data, 'type'); |
| 93 | 93 | } else { |
| 94 | 94 | // Ajustes de dados |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Suprimir o status code |
| 99 | - if (Yii::$app->request->get('suppress_response_code')){ |
|
| 99 | + if (Yii::$app->request->get('suppress_response_code')) { |
|
| 100 | 100 | $response->statusCode = 200; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | // Verificar autorização do modulo |
| 115 | - if( $modulo = Yii::$app->request->get('modulo') ){ |
|
| 115 | + if ($modulo = Yii::$app->request->get('modulo')) { |
|
| 116 | 116 | self::can($modulo); |
| 117 | 117 | } |
| 118 | 118 | |
@@ -152,52 +152,52 @@ discard block |
||
| 152 | 152 | $this->count = $dataProvider->getCount(); |
| 153 | 153 | |
| 154 | 154 | // Verifica foi encontrado registros |
| 155 | - if($this->count == 0){ |
|
| 156 | - throw new HttpException(404,'Nenhum registro foi encontrado!'); |
|
| 155 | + if ($this->count == 0) { |
|
| 156 | + throw new HttpException(404, 'Nenhum registro foi encontrado!'); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // incluir arquivos junto ao registro? |
| 160 | - if ($files){ |
|
| 160 | + if ($files) { |
|
| 161 | 161 | // instanciado data |
| 162 | 162 | $data = array(); |
| 163 | 163 | |
| 164 | 164 | // Adiciona arquivos aos registros |
| 165 | 165 | foreach ($models as $key => $model) { |
| 166 | 166 | // convert model to array |
| 167 | - $data []= ArrayHelper::toArray($model); |
|
| 167 | + $data [] = ArrayHelper::toArray($model); |
|
| 168 | 168 | |
| 169 | 169 | // modulo possui arquivo unico |
| 170 | - if ($model->canGetProperty('arquivo')){ |
|
| 170 | + if ($model->canGetProperty('arquivo')) { |
|
| 171 | 171 | // adicionar arquivo unico |
| 172 | - if($arquivo = $model->arquivo){ |
|
| 172 | + if ($arquivo = $model->arquivo) { |
|
| 173 | 173 | //importar arquivo para o registro |
| 174 | 174 | self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'arquivo'); |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // modulo possui arquivo unico |
| 179 | - if ($model->canGetProperty('id_banner')){ |
|
| 179 | + if ($model->canGetProperty('id_banner')) { |
|
| 180 | 180 | // adicionar arquivo unico |
| 181 | - if($arquivo = $model->banner){ |
|
| 181 | + if ($arquivo = $model->banner) { |
|
| 182 | 182 | //importar arquivo para o registro |
| 183 | 183 | self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'banner'); |
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // modulo possui arquivo unico |
| 188 | - if ($model->canGetProperty('id_capa')){ |
|
| 188 | + if ($model->canGetProperty('id_capa')) { |
|
| 189 | 189 | // adicionar arquivo unico |
| 190 | - if($arquivo = $model->capa){ |
|
| 190 | + if ($arquivo = $model->capa) { |
|
| 191 | 191 | //importar arquivo para o registro |
| 192 | 192 | self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'capa'); |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | // modulo possui arquivos multiplos |
| 197 | - if ($model->canGetProperty('arquivos')){ |
|
| 197 | + if ($model->canGetProperty('arquivos')) { |
|
| 198 | 198 | // adicionar arquivos multiplos |
| 199 | - if($arquivos = $model->arquivos){ |
|
| 200 | - foreach($arquivos as $arquivo){ |
|
| 199 | + if ($arquivos = $model->arquivos) { |
|
| 200 | + foreach ($arquivos as $arquivo) { |
|
| 201 | 201 | // importar arquivo para o registro |
| 202 | 202 | self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'arquivos'); |
| 203 | 203 | } |
@@ -232,22 +232,22 @@ discard block |
||
| 232 | 232 | $this->count = $dataProvider->getCount(); |
| 233 | 233 | |
| 234 | 234 | // Verifica foi encontrado registros |
| 235 | - if($this->count == 0){ |
|
| 236 | - throw new HttpException(404,'Nenhum registro foi encontrado!'); |
|
| 235 | + if ($this->count == 0) { |
|
| 236 | + throw new HttpException(404, 'Nenhum registro foi encontrado!'); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | $model = array_shift($models); |
| 240 | 240 | $arquivos = array(); |
| 241 | 241 | |
| 242 | - if ($model->canGetProperty('arquivo')){ |
|
| 243 | - if($arquivo = $model->arquivo){ |
|
| 242 | + if ($model->canGetProperty('arquivo')) { |
|
| 243 | + if ($arquivo = $model->arquivo) { |
|
| 244 | 244 | self::importFile($arquivos, $arquivo, $modulo, $size, 'arquivo'); |
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - if ($model->canGetProperty('arquivos')){ |
|
| 249 | - if($arquivos = $model->arquivos){ |
|
| 250 | - foreach($arquivos as $arquivo){ |
|
| 248 | + if ($model->canGetProperty('arquivos')) { |
|
| 249 | + if ($arquivos = $model->arquivos) { |
|
| 250 | + foreach ($arquivos as $arquivo) { |
|
| 251 | 251 | self::importFile($arquivos, $arquivo, $modulo, $size, 'arquivos'); |
| 252 | 252 | } |
| 253 | 253 | } |
@@ -258,8 +258,8 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | |
| 260 | 260 | // Verifica foi encontrado registros |
| 261 | - if($this->count == 0){ |
|
| 262 | - throw new HttpException(404,'Nenhum arquivo foi encontrado!'); |
|
| 261 | + if ($this->count == 0) { |
|
| 262 | + throw new HttpException(404, 'Nenhum arquivo foi encontrado!'); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -306,14 +306,14 @@ discard block |
||
| 306 | 306 | private static function importFile(&$arquivos, $arquivo, $modulo, $size, $local = 'desconhecido') |
| 307 | 307 | { |
| 308 | 308 | // não executar quando não houver arquivo para importar |
| 309 | - if($arquivo === null){ |
|
| 309 | + if ($arquivo === null) { |
|
| 310 | 310 | return false; |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - $prefix = $arquivo->tipo == $arquivo::TIPO_IMAGEM ? $size:''; // prefixo tamano da imagem |
|
| 313 | + $prefix = $arquivo->tipo == $arquivo::TIPO_IMAGEM ? $size : ''; // prefixo tamano da imagem |
|
| 314 | 314 | $url = Url::to($arquivo->getFileUrl($modulo, $prefix), true); // Url Absoluta |
| 315 | 315 | |
| 316 | - $arquivos []= [ |
|
| 316 | + $arquivos [] = [ |
|
| 317 | 317 | 'local' => $local, |
| 318 | 318 | 'url' => $url |
| 319 | 319 | ]; |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | */ |
| 335 | 335 | private static function can($modulo) |
| 336 | 336 | { |
| 337 | - if( array_search($modulo, static::modulos()) === false ){ |
|
| 337 | + if (array_search($modulo, static::modulos()) === false) { |
|
| 338 | 338 | throw new HttpException(403, 'Não autorizado!'); |
| 339 | 339 | } |
| 340 | 340 | } |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | $url = Url::base(true).'/'; |
| 355 | 355 | |
| 356 | 356 | // não tem o que substituir |
| 357 | - if(!isset($database[0]['descricao'])){ |
|
| 357 | + if (!isset($database[0]['descricao'])) { |
|
| 358 | 358 | return $database; |
| 359 | 359 | } |
| 360 | 360 | |