@@ -72,13 +72,13 @@ discard block |
||
| 72 | 72 | public function init() |
| 73 | 73 | { |
| 74 | 74 | parent::init(); |
| 75 | - Logger::log(get_called_class() . ' init', LOG_DEBUG); |
|
| 75 | + Logger::log(get_called_class().' init', LOG_DEBUG); |
|
| 76 | 76 | $this->domain = $this->getDomain(); |
| 77 | 77 | $this->hydrateRequestData(); |
| 78 | 78 | $this->hydrateOrders(); |
| 79 | 79 | $this->createConnection($this->getTableMap()); |
| 80 | 80 | $this->setLoaded(true); |
| 81 | - Logger::log(get_called_class() . ' loaded', LOG_DEBUG); |
|
| 81 | + Logger::log(get_called_class().' loaded', LOG_DEBUG); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | private function hydrateOrders() |
| 88 | 88 | { |
| 89 | 89 | if (count($this->query)) { |
| 90 | - Logger::log(get_called_class() . ' gathering query string', LOG_DEBUG); |
|
| 90 | + Logger::log(get_called_class().' gathering query string', LOG_DEBUG); |
|
| 91 | 91 | foreach ($this->query as $key => $value) { |
| 92 | 92 | if ($key === self::API_ORDER_FIELD) { |
| 93 | 93 | foreach ($value as $field => $direction) { |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | protected function extractPagination() |
| 106 | 106 | { |
| 107 | - Logger::log(get_called_class() . ' extract pagination start', LOG_DEBUG); |
|
| 107 | + Logger::log(get_called_class().' extract pagination start', LOG_DEBUG); |
|
| 108 | 108 | $page = (array_key_exists(self::API_PAGE_FIELD, $this->query)) ? $this->query[self::API_PAGE_FIELD] : 1; |
| 109 | 109 | $limit = (array_key_exists(self::API_LIMIT_FIELD, $this->query)) ? $this->query[self::API_LIMIT_FIELD] : 100; |
| 110 | - Logger::log(get_called_class() . ' extract pagination end', LOG_DEBUG); |
|
| 110 | + Logger::log(get_called_class().' extract pagination end', LOG_DEBUG); |
|
| 111 | 111 | return array($page, $limit); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @param ModelCriteria $query |
| 118 | 118 | */ |
| 119 | - private function addOrders(ModelCriteria &$query) |
|
| 119 | + private function addOrders(ModelCriteria & $query) |
|
| 120 | 120 | { |
| 121 | - Logger::log(get_called_class() . ' extract orders start ', LOG_DEBUG); |
|
| 121 | + Logger::log(get_called_class().' extract orders start ', LOG_DEBUG); |
|
| 122 | 122 | $orderAdded = FALSE; |
| 123 | 123 | $tableMap = $this->getTableMap(); |
| 124 | 124 | foreach ($this->order->getOrders() as $field => $direction) { |
@@ -126,17 +126,17 @@ discard block |
||
| 126 | 126 | $orderAdded = TRUE; |
| 127 | 127 | if ($direction === Order::ASC) { |
| 128 | 128 | $query->addAscendingOrderByColumn($column->getPhpName()); |
| 129 | - } else { |
|
| 129 | + }else { |
|
| 130 | 130 | $query->addDescendingOrderByColumn($column->getPhpName()); |
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | if (!$orderAdded) { |
| 135 | - foreach($this->getPkDbName() as $pk => $phpName) { |
|
| 135 | + foreach ($this->getPkDbName() as $pk => $phpName) { |
|
| 136 | 136 | $query->addAscendingOrderByColumn($pk); |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | - Logger::log(get_called_class() . ' extract orders end', LOG_DEBUG); |
|
| 139 | + Logger::log(get_called_class().' extract orders end', LOG_DEBUG); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -144,14 +144,14 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @param ModelCriteria $query |
| 146 | 146 | */ |
| 147 | - protected function addFilters(ModelCriteria &$query) |
|
| 147 | + protected function addFilters(ModelCriteria & $query) |
|
| 148 | 148 | { |
| 149 | 149 | if (count($this->query) > 0) { |
| 150 | 150 | $tableMap = $this->getTableMap(); |
| 151 | 151 | foreach ($this->query as $field => $value) { |
| 152 | 152 | if (self::API_COMBO_FIELD === $field) { |
| 153 | 153 | ApiHelper::composerComboField($tableMap, $query, $this->extraColumns, $value); |
| 154 | - } elseif(!preg_match('/^__/', $field)) { |
|
| 154 | + } elseif (!preg_match('/^__/', $field)) { |
|
| 155 | 155 | ApiHelper::addModelField($tableMap, $query, $field, $value); |
| 156 | 156 | } |
| 157 | 157 | } |
@@ -172,10 +172,10 @@ discard block |
||
| 172 | 172 | list($page, $limit) = $this->extractPagination(); |
| 173 | 173 | if ($limit == -1) { |
| 174 | 174 | $this->list = $query->find($this->con); |
| 175 | - } else { |
|
| 175 | + }else { |
|
| 176 | 176 | $this->list = $query->paginate($page, $limit, $this->con); |
| 177 | 177 | } |
| 178 | - } catch (\Exception $e) { |
|
| 178 | + }catch (\Exception $e) { |
|
| 179 | 179 | Logger::log($e->getMessage(), LOG_ERR); |
| 180 | 180 | } |
| 181 | 181 | } |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | $code = 200; |
| 195 | 195 | list($return, $total, $pages) = $this->getList(); |
| 196 | 196 | $message = null; |
| 197 | - if(!$total) { |
|
| 197 | + if (!$total) { |
|
| 198 | 198 | $message = _('No se han encontrado elementos para la búsqueda'); |
| 199 | 199 | } |
| 200 | 200 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $pages = 1; |
| 221 | 221 | $message = null; |
| 222 | 222 | list($code, $return) = $this->getSingleResult($pk); |
| 223 | - if($code !== 200) { |
|
| 223 | + if ($code !== 200) { |
|
| 224 | 224 | $message = _('No se ha encontrado el elemento solicitado'); |
| 225 | 225 | } |
| 226 | 226 | |
@@ -249,11 +249,11 @@ discard block |
||
| 249 | 249 | $status = 200; |
| 250 | 250 | $saved = TRUE; |
| 251 | 251 | $model = $this->model->toArray(); |
| 252 | - } else { |
|
| 252 | + }else { |
|
| 253 | 253 | $message = _('No se ha podido guardar el modelo seleccionado'); |
| 254 | 254 | } |
| 255 | - } catch (\Exception $e) { |
|
| 256 | - $message = _('Ha ocurrido un error intentando guardar el elemento: ') .'<br>'. $e->getMessage(); |
|
| 255 | + }catch (\Exception $e) { |
|
| 256 | + $message = _('Ha ocurrido un error intentando guardar el elemento: ').'<br>'.$e->getMessage(); |
|
| 257 | 257 | Logger::log($e->getMessage(), LOG_ERR); |
| 258 | 258 | } |
| 259 | 259 | |
@@ -287,14 +287,14 @@ discard block |
||
| 287 | 287 | $updated = TRUE; |
| 288 | 288 | $status = 200; |
| 289 | 289 | $model = $this->model->toArray(); |
| 290 | - } else { |
|
| 290 | + }else { |
|
| 291 | 291 | $message = _('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs'); |
| 292 | 292 | } |
| 293 | - } catch (\Exception $e) { |
|
| 293 | + }catch (\Exception $e) { |
|
| 294 | 294 | $message = $e->getMessage(); |
| 295 | 295 | Logger::getInstance(get_class($this->model))->errorLog($e->getMessage()); |
| 296 | 296 | } |
| 297 | - } else { |
|
| 297 | + }else { |
|
| 298 | 298 | $message = _('No se ha encontrado el modelo al que se hace referencia para actualizar'); |
| 299 | 299 | } |
| 300 | 300 | |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | $this->model->delete($this->con); |
| 325 | 325 | $deleted = TRUE; |
| 326 | 326 | } |
| 327 | - } catch (\Exception $e) { |
|
| 327 | + }catch (\Exception $e) { |
|
| 328 | 328 | $message = _('Ha ocurrido un error intentando eliminar el elemento, por favor verifica que no tenga otros elementos relacionados'); |
| 329 | 329 | Logger::getInstance(get_class($this->model))->errorLog($e->getMessage()); |
| 330 | 330 | } |
@@ -358,8 +358,8 @@ discard block |
||
| 358 | 358 | $total = $this->list->getNbResults(); |
| 359 | 359 | $pages = $this->list->getLastPage(); |
| 360 | 360 | } |
| 361 | - } catch (\Exception $e) { |
|
| 362 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
| 361 | + }catch (\Exception $e) { |
|
| 362 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | return array($return, $total, $pages); |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | $return = array(); |
| 378 | 378 | if (NULL === $model || !method_exists($model, 'toArray')) { |
| 379 | 379 | $code = 404; |
| 380 | - } else { |
|
| 380 | + }else { |
|
| 381 | 381 | $return = $model->toArray(); |
| 382 | 382 | } |
| 383 | 383 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | public function __construct($hydrate = true) |
| 18 | 18 | { |
| 19 | 19 | parent::__construct(); |
| 20 | - if($hydrate) { |
|
| 20 | + if ($hydrate) { |
|
| 21 | 21 | $this->fromArray(Request::getInstance()->getData()); |
| 22 | 22 | } |
| 23 | 23 | } |
@@ -45,15 +45,15 @@ discard block |
||
| 45 | 45 | /** @var \ReflectionProperty $property */ |
| 46 | 46 | foreach ($properties as $property) { |
| 47 | 47 | $value = $property->getValue($this); |
| 48 | - if(is_object($value) && method_exists($value, 'toArray')) { |
|
| 48 | + if (is_object($value) && method_exists($value, 'toArray')) { |
|
| 49 | 49 | $dto[$property->getName()] = $value->toArray(); |
| 50 | - } else { |
|
| 50 | + }else { |
|
| 51 | 51 | $dto[$property->getName()] = $property->getValue($this); |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | - } catch (\Exception $e) { |
|
| 56 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
| 55 | + }catch (\Exception $e) { |
|
| 56 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
| 57 | 57 | } |
| 58 | 58 | return $dto; |
| 59 | 59 | } |
@@ -75,28 +75,28 @@ discard block |
||
| 75 | 75 | protected function parseDtoField(array $properties, $key, $value = null) { |
| 76 | 76 | $type = 'string'; |
| 77 | 77 | $is_array = false; |
| 78 | - if(array_key_exists($key, $properties)) { |
|
| 78 | + if (array_key_exists($key, $properties)) { |
|
| 79 | 79 | $type = $properties[$key]; |
| 80 | - if(preg_match('/(\[\]|Array)/i', $type)) { |
|
| 80 | + if (preg_match('/(\[\]|Array)/i', $type)) { |
|
| 81 | 81 | $type = preg_replace('/(\[\]|Array)/i', '', $type); |
| 82 | 82 | $is_array = true; |
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | $reflector = (class_exists($type)) ? new \ReflectionClass($type) : null; |
| 86 | - if(null !== $reflector && $reflector->isSubclassOf(Dto::class)) { |
|
| 87 | - if($is_array) { |
|
| 86 | + if (null !== $reflector && $reflector->isSubclassOf(Dto::class)) { |
|
| 87 | + if ($is_array) { |
|
| 88 | 88 | $this->$key = []; |
| 89 | - foreach($value as $data) { |
|
| 89 | + foreach ($value as $data) { |
|
| 90 | 90 | $dto = new $type(false); |
| 91 | 91 | $dto->fromArray($data); |
| 92 | 92 | array_push($this->$key, $dto); |
| 93 | 93 | } |
| 94 | - } else { |
|
| 94 | + }else { |
|
| 95 | 95 | $this->$key = new $type(false); |
| 96 | 96 | $this->$key->fromArray($value); |
| 97 | 97 | } |
| 98 | - } else { |
|
| 99 | - switch($type) { |
|
| 98 | + }else { |
|
| 99 | + switch ($type) { |
|
| 100 | 100 | default: |
| 101 | 101 | case 'string': |
| 102 | 102 | $this->$key = $value; |