@@ -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 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | curl_setopt($ch, CURLOPT_HEADER, 0); |
| 157 | 157 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 158 | 158 | curl_setopt($ch, CURLOPT_URL, 'https://api.github.com/repos/dynamikaweb/yii2-dynamika-api/releases/latest'); |
| 159 | - curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); |
|
| 159 | + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); |
|
| 160 | 160 | $response = curl_exec($ch); |
| 161 | 161 | curl_close($ch); |
| 162 | 162 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | $last_data = ArrayHelper::getValue($githubApi, 'published_at'); |
| 169 | 169 | |
| 170 | 170 | // verificar se foi possivel buscar por atualizações |
| 171 | - if (!$githubApi || $last_version === null){ |
|
| 171 | + if (!$githubApi || $last_version === null) { |
|
| 172 | 172 | throw new \yii\base\Exception('Não foi possível buscar por atualizações'); |
| 173 | 173 | } |
| 174 | 174 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $local_data = new \DateTime(static::LOCAL_UPDATE['date']); |
| 178 | 178 | |
| 179 | 179 | // comparar se api está atualizada |
| 180 | - if ($local_data < $last_data){ |
|
| 180 | + if ($local_data < $last_data) { |
|
| 181 | 181 | throw new \yii\base\Exception('API está desatualizada!'); |
| 182 | 182 | } |
| 183 | 183 | } catch (\yii\base\Exception $e) { |
@@ -215,52 +215,52 @@ discard block |
||
| 215 | 215 | $this->count = $dataProvider->getCount(); |
| 216 | 216 | |
| 217 | 217 | // Verifica foi encontrado registros |
| 218 | - if($this->count == 0){ |
|
| 219 | - throw new HttpException(404,'Nenhum registro foi encontrado!'); |
|
| 218 | + if ($this->count == 0) { |
|
| 219 | + throw new HttpException(404, 'Nenhum registro foi encontrado!'); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // incluir arquivos junto ao registro? |
| 223 | - if ($files){ |
|
| 223 | + if ($files) { |
|
| 224 | 224 | // instanciado data |
| 225 | 225 | $data = array(); |
| 226 | 226 | |
| 227 | 227 | // Adiciona arquivos aos registros |
| 228 | 228 | foreach ($models as $key => $model) { |
| 229 | 229 | // convert model to array |
| 230 | - $data []= ArrayHelper::toArray($model); |
|
| 230 | + $data [] = ArrayHelper::toArray($model); |
|
| 231 | 231 | |
| 232 | 232 | // modulo possui arquivo unico |
| 233 | - if ($model->canGetProperty('arquivo')){ |
|
| 233 | + if ($model->canGetProperty('arquivo')) { |
|
| 234 | 234 | // adicionar arquivo unico |
| 235 | - if($arquivo = $model->arquivo){ |
|
| 235 | + if ($arquivo = $model->arquivo) { |
|
| 236 | 236 | //importar arquivo para o registro |
| 237 | 237 | self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'arquivo'); |
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | // modulo possui arquivo unico |
| 242 | - if ($model->canGetProperty('id_banner')){ |
|
| 242 | + if ($model->canGetProperty('id_banner')) { |
|
| 243 | 243 | // adicionar arquivo unico |
| 244 | - if($arquivo = $model->banner){ |
|
| 244 | + if ($arquivo = $model->banner) { |
|
| 245 | 245 | //importar arquivo para o registro |
| 246 | 246 | self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'banner'); |
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | // modulo possui arquivo unico |
| 251 | - if ($model->canGetProperty('id_capa')){ |
|
| 251 | + if ($model->canGetProperty('id_capa')) { |
|
| 252 | 252 | // adicionar arquivo unico |
| 253 | - if($arquivo = $model->capa){ |
|
| 253 | + if ($arquivo = $model->capa) { |
|
| 254 | 254 | //importar arquivo para o registro |
| 255 | 255 | self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'capa'); |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // modulo possui arquivos multiplos |
| 260 | - if ($model->canGetProperty('arquivos')){ |
|
| 260 | + if ($model->canGetProperty('arquivos')) { |
|
| 261 | 261 | // adicionar arquivos multiplos |
| 262 | - if($arquivos = $model->arquivos){ |
|
| 263 | - foreach($arquivos as $arquivo){ |
|
| 262 | + if ($arquivos = $model->arquivos) { |
|
| 263 | + foreach ($arquivos as $arquivo) { |
|
| 264 | 264 | // importar arquivo para o registro |
| 265 | 265 | self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'arquivos'); |
| 266 | 266 | } |
@@ -295,22 +295,22 @@ discard block |
||
| 295 | 295 | $this->count = $dataProvider->getCount(); |
| 296 | 296 | |
| 297 | 297 | // Verifica foi encontrado registros |
| 298 | - if($this->count == 0){ |
|
| 299 | - throw new HttpException(404,'Nenhum registro foi encontrado!'); |
|
| 298 | + if ($this->count == 0) { |
|
| 299 | + throw new HttpException(404, 'Nenhum registro foi encontrado!'); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | $model = array_shift($models); |
| 303 | 303 | $arquivos = array(); |
| 304 | 304 | |
| 305 | - if ($model->canGetProperty('arquivo')){ |
|
| 306 | - if($arquivo = $model->arquivo){ |
|
| 305 | + if ($model->canGetProperty('arquivo')) { |
|
| 306 | + if ($arquivo = $model->arquivo) { |
|
| 307 | 307 | self::importFile($arquivos, $arquivo, $modulo, $size, 'arquivo'); |
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - if ($model->canGetProperty('arquivos')){ |
|
| 312 | - if($arquivos = $model->arquivos){ |
|
| 313 | - foreach($arquivos as $arquivo){ |
|
| 311 | + if ($model->canGetProperty('arquivos')) { |
|
| 312 | + if ($arquivos = $model->arquivos) { |
|
| 313 | + foreach ($arquivos as $arquivo) { |
|
| 314 | 314 | self::importFile($arquivos, $arquivo, $modulo, $size, 'arquivos'); |
| 315 | 315 | } |
| 316 | 316 | } |
@@ -321,8 +321,8 @@ discard block |
||
| 321 | 321 | |
| 322 | 322 | |
| 323 | 323 | // Verifica foi encontrado registros |
| 324 | - if($this->count == 0){ |
|
| 325 | - throw new HttpException(404,'Nenhum arquivo foi encontrado!'); |
|
| 324 | + if ($this->count == 0) { |
|
| 325 | + throw new HttpException(404, 'Nenhum arquivo foi encontrado!'); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | |
@@ -351,8 +351,8 @@ discard block |
||
| 351 | 351 | $this->count = $dataProvider->getCount(); |
| 352 | 352 | |
| 353 | 353 | // Verifica foi encontrado registros |
| 354 | - if($this->count == 0){ |
|
| 355 | - throw new HttpException(404,'Nenhum Banner foi encontrado!'); |
|
| 354 | + if ($this->count == 0) { |
|
| 355 | + throw new HttpException(404, 'Nenhum Banner foi encontrado!'); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | $arquivos = array(); |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | private static function importFile(&$arquivos, $arquivo, $modulo, $size, $local = 'desconhecido') |
| 404 | 404 | { |
| 405 | 405 | // não executar quando não houver arquivo para importar |
| 406 | - if($arquivo === null){ |
|
| 406 | + if ($arquivo === null) { |
|
| 407 | 407 | return false; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - $prefix = $arquivo->tipo == $arquivo::TIPO_IMAGEM ? $size:''; // prefixo tamano da imagem |
|
| 410 | + $prefix = $arquivo->tipo == $arquivo::TIPO_IMAGEM ? $size : ''; // prefixo tamano da imagem |
|
| 411 | 411 | $url = Url::to($arquivo->getFileUrl($modulo, $prefix), true); // Url Absoluta |
| 412 | 412 | |
| 413 | - $arquivos []= [ |
|
| 413 | + $arquivos [] = [ |
|
| 414 | 414 | 'local' => $local, |
| 415 | 415 | 'url' => $url |
| 416 | 416 | ]; |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | */ |
| 432 | 432 | private static function can($modulo) |
| 433 | 433 | { |
| 434 | - if( array_search($modulo, static::modulos()) === false ){ |
|
| 434 | + if (array_search($modulo, static::modulos()) === false) { |
|
| 435 | 435 | throw new HttpException(403, 'Não autorizado!'); |
| 436 | 436 | } |
| 437 | 437 | } |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | $url = Url::base(true).'/'; |
| 452 | 452 | |
| 453 | 453 | // não tem o que substituir |
| 454 | - if(!isset($database[0]['descricao'])){ |
|
| 454 | + if (!isset($database[0]['descricao'])) { |
|
| 455 | 455 | return $database; |
| 456 | 456 | } |
| 457 | 457 | |