@@ -72,22 +72,22 @@ discard block |
||
| 72 | 72 | Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
| 73 | 73 | |
| 74 | 74 | // Formato de estrura em ['sucess','count','data] |
| 75 | - Yii::$app->response->on(\yii\web\Response::EVENT_BEFORE_SEND, function ($event) { |
|
| 75 | + Yii::$app->response->on(\yii\web\Response::EVENT_BEFORE_SEND, function($event) { |
|
| 76 | 76 | // yii\web\Response |
| 77 | 77 | $response = $event->sender; |
| 78 | 78 | |
| 79 | 79 | // Dados |
| 80 | - $count = $response->isSuccessful? $this->count: 0; |
|
| 80 | + $count = $response->isSuccessful ? $this->count : 0; |
|
| 81 | 81 | $success = $response->isSuccessful; |
| 82 | 82 | $data = $response->data; |
| 83 | 83 | |
| 84 | 84 | // Esconder classe do erro |
| 85 | - if (!$success) { |
|
| 85 | + if (!$success) { |
|
| 86 | 86 | \yii\helpers\ArrayHelper::remove($data, 'type'); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // Suprimir o status code |
| 90 | - if (Yii::$app->request->get('suppress_response_code')){ |
|
| 90 | + if (Yii::$app->request->get('suppress_response_code')) { |
|
| 91 | 91 | $response->statusCode = 200; |
| 92 | 92 | } |
| 93 | 93 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | |
| 105 | 105 | // Verificar autorização do modulo |
| 106 | - if( $modulo = Yii::$app->request->get('modulo') ){ |
|
| 106 | + if ($modulo = Yii::$app->request->get('modulo')) { |
|
| 107 | 107 | self::can($modulo); |
| 108 | 108 | } |
| 109 | 109 | |
@@ -142,52 +142,52 @@ discard block |
||
| 142 | 142 | $this->count = $dataProvider->getCount(); |
| 143 | 143 | |
| 144 | 144 | // Verifica foi encontrado registros |
| 145 | - if($this->count == 0){ |
|
| 146 | - throw new HttpException(404,'Nenhum registro foi encontrado!'); |
|
| 145 | + if ($this->count == 0) { |
|
| 146 | + throw new HttpException(404, 'Nenhum registro foi encontrado!'); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | // incluir arquivos junto ao registro? |
| 150 | - if ($files){ |
|
| 150 | + if ($files) { |
|
| 151 | 151 | // instanciado data |
| 152 | 152 | $data = array(); |
| 153 | 153 | |
| 154 | 154 | // Adiciona arquivos aos registros |
| 155 | 155 | foreach ($models as $key => $model) { |
| 156 | 156 | // convert model to array |
| 157 | - $data []= ArrayHelper::toArray($model); |
|
| 157 | + $data [] = ArrayHelper::toArray($model); |
|
| 158 | 158 | |
| 159 | 159 | // modulo possui arquivo unico |
| 160 | - if ($model->canGetProperty('arquivo')){ |
|
| 160 | + if ($model->canGetProperty('arquivo')) { |
|
| 161 | 161 | // adicionar arquivo unico |
| 162 | - if($arquivo = $model->arquivo){ |
|
| 162 | + if ($arquivo = $model->arquivo) { |
|
| 163 | 163 | //importar arquivo para o registro |
| 164 | 164 | self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'arquivo'); |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // modulo possui arquivo unico |
| 169 | - if ($model->canGetProperty('id_banner')){ |
|
| 169 | + if ($model->canGetProperty('id_banner')) { |
|
| 170 | 170 | // adicionar arquivo unico |
| 171 | - if($arquivo = $model->banner){ |
|
| 171 | + if ($arquivo = $model->banner) { |
|
| 172 | 172 | //importar arquivo para o registro |
| 173 | 173 | self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'banner'); |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | // modulo possui arquivo unico |
| 178 | - if ($model->canGetProperty('id_capa')){ |
|
| 178 | + if ($model->canGetProperty('id_capa')) { |
|
| 179 | 179 | // adicionar arquivo unico |
| 180 | - if($arquivo = $model->capa){ |
|
| 180 | + if ($arquivo = $model->capa) { |
|
| 181 | 181 | //importar arquivo para o registro |
| 182 | 182 | self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'capa'); |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // modulo possui arquivos multiplos |
| 187 | - if ($model->canGetProperty('arquivos')){ |
|
| 187 | + if ($model->canGetProperty('arquivos')) { |
|
| 188 | 188 | // adicionar arquivos multiplos |
| 189 | - if($arquivos = $model->arquivos){ |
|
| 190 | - foreach($arquivos as $arquivo){ |
|
| 189 | + if ($arquivos = $model->arquivos) { |
|
| 190 | + foreach ($arquivos as $arquivo) { |
|
| 191 | 191 | // importar arquivo para o registro |
| 192 | 192 | self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'arquivos'); |
| 193 | 193 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | // Output |
| 200 | - return $files? $data: $models; |
|
| 200 | + return $files ? $data : $models; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -220,22 +220,22 @@ discard block |
||
| 220 | 220 | $this->count = $dataProvider->getCount(); |
| 221 | 221 | |
| 222 | 222 | // Verifica foi encontrado registros |
| 223 | - if($this->count == 0){ |
|
| 224 | - throw new HttpException(404,'Nenhum registro foi encontrado!'); |
|
| 223 | + if ($this->count == 0) { |
|
| 224 | + throw new HttpException(404, 'Nenhum registro foi encontrado!'); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | $model = array_shift($models); |
| 228 | 228 | $arquivos = array(); |
| 229 | 229 | |
| 230 | - if ($model->canGetProperty('arquivo')){ |
|
| 231 | - if($arquivo = $model->arquivo){ |
|
| 230 | + if ($model->canGetProperty('arquivo')) { |
|
| 231 | + if ($arquivo = $model->arquivo) { |
|
| 232 | 232 | self::importFile($arquivos, $arquivo, $modulo, $size, 'arquivo'); |
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - if ($model->canGetProperty('arquivos')){ |
|
| 237 | - if($arquivos = $model->arquivos){ |
|
| 238 | - foreach($arquivos as $arquivo){ |
|
| 236 | + if ($model->canGetProperty('arquivos')) { |
|
| 237 | + if ($arquivos = $model->arquivos) { |
|
| 238 | + foreach ($arquivos as $arquivo) { |
|
| 239 | 239 | self::importFile($arquivos, $arquivo, $modulo, $size, 'arquivos'); |
| 240 | 240 | } |
| 241 | 241 | } |
@@ -246,8 +246,8 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | |
| 248 | 248 | // Verifica foi encontrado registros |
| 249 | - if($this->count == 0){ |
|
| 250 | - throw new HttpException(404,'Nenhum arquivo foi encontrado!'); |
|
| 249 | + if ($this->count == 0) { |
|
| 250 | + throw new HttpException(404, 'Nenhum arquivo foi encontrado!'); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -276,8 +276,8 @@ discard block |
||
| 276 | 276 | $this->count = $dataProvider->getCount(); |
| 277 | 277 | |
| 278 | 278 | // Verifica foi encontrado registros |
| 279 | - if($this->count == 0){ |
|
| 280 | - throw new HttpException(404,'Nenhum Banner foi encontrado!'); |
|
| 279 | + if ($this->count == 0) { |
|
| 280 | + throw new HttpException(404, 'Nenhum Banner foi encontrado!'); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | $arquivos = array(); |
@@ -328,14 +328,14 @@ discard block |
||
| 328 | 328 | private static function importFile(&$arquivos, $arquivo, $modulo, $size, $local = 'desconhecido') |
| 329 | 329 | { |
| 330 | 330 | // não executar quando não houver arquivo para importar |
| 331 | - if($arquivo === null){ |
|
| 331 | + if ($arquivo === null) { |
|
| 332 | 332 | return false; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - $prefix = $arquivo->tipo == $arquivo::TIPO_IMAGEM ? $size:''; // prefixo tamano da imagem |
|
| 335 | + $prefix = $arquivo->tipo == $arquivo::TIPO_IMAGEM ? $size : ''; // prefixo tamano da imagem |
|
| 336 | 336 | $url = Url::to($arquivo->getFileUrl($modulo, $prefix), true); // Url Absoluta |
| 337 | 337 | |
| 338 | - $arquivos []= [ |
|
| 338 | + $arquivos [] = [ |
|
| 339 | 339 | 'local' => $local, |
| 340 | 340 | 'url' => $url |
| 341 | 341 | ]; |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | */ |
| 357 | 357 | private static function can($modulo) |
| 358 | 358 | { |
| 359 | - if( array_search($modulo, static::modulos()) === false ){ |
|
| 359 | + if (array_search($modulo, static::modulos()) === false) { |
|
| 360 | 360 | throw new HttpException(403, 'Não autorizado!'); |
| 361 | 361 | } |
| 362 | 362 | } |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | $url = Url::base(true).'/'; |
| 377 | 377 | |
| 378 | 378 | // não tem o que substituir |
| 379 | - if(!isset($database[0]['descricao'])){ |
|
| 379 | + if (!isset($database[0]['descricao'])) { |
|
| 380 | 380 | return $database; |
| 381 | 381 | } |
| 382 | 382 | |