| Total Complexity | 55 |
| Total Lines | 538 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 1 | Features | 0 |
Complex classes like residentes_edificaciones often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use residentes_edificaciones, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class residentes_edificaciones extends \fs_model{ |
||
| 25 | /** |
||
| 26 | * El Id de la de edificacion |
||
| 27 | * @var integer serial |
||
| 28 | */ |
||
| 29 | public $id; |
||
| 30 | /** |
||
| 31 | * El id de la dirección almacenada en la tabla del cliente |
||
| 32 | * @var integer |
||
| 33 | */ |
||
| 34 | public $iddireccion; |
||
| 35 | /** |
||
| 36 | * Este es el id de la edificacion en el mapa de Edificaciones |
||
| 37 | * @var integer |
||
| 38 | */ |
||
| 39 | public $id_edificacion; |
||
| 40 | /** |
||
| 41 | * De cara al usuario se mostrará y buscara este código |
||
| 42 | * pero esto se generará de los valores que ingrese de |
||
| 43 | * los tipos de edificaciones |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | public $codigo; |
||
| 47 | /** |
||
| 48 | * Este codigo es en realidad una cadena para saber donde buscar |
||
| 49 | * los datos de las edificaciones, si solo manejan el tipo de edificación |
||
| 50 | * principal que es Bloque con código 1, entonces el codigo interno |
||
| 51 | * será 1:LETRA_O_NUMERO del Bloque, si por el contrario tiene Bloque y Edificio |
||
| 52 | * entonces el valor guardado será 1:1_2:1 que indicara que esta en el Bloque 1 Edificio 1 |
||
| 53 | * siendo el id de Edificio el 2. |
||
| 54 | * @var string |
||
| 55 | */ |
||
| 56 | public $codigo_interno; |
||
| 57 | /** |
||
| 58 | * Este es el número del Inmueble |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | public $numero; |
||
| 62 | /** |
||
| 63 | * @todo En un futuro si se necesita colocar la ubicación del edificio, como la calle o avenida interna |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | public $ubicacion; |
||
| 67 | /** |
||
| 68 | * Si se van a agregar las coordenadas del inmueble pueden colocarse aquí |
||
| 69 | * @var varchar(64) |
||
|
|
|||
| 70 | */ |
||
| 71 | public $coordenadas; |
||
| 72 | /** |
||
| 73 | * Si la edificación esta ocupada entonces se coloca aquí el código del Residente o Cliente |
||
| 74 | * @var string |
||
| 75 | */ |
||
| 76 | public $codcliente; |
||
| 77 | /** |
||
| 78 | * Con esto sabremos si un edificio está o no ocupado en el listado de edificios |
||
| 79 | * @var boolean |
||
| 80 | */ |
||
| 81 | public $ocupado; |
||
| 82 | /** |
||
| 83 | * |
||
| 84 | * @var string |
||
| 85 | */ |
||
| 86 | public $fecha_ocupacion; |
||
| 87 | /** |
||
| 88 | * |
||
| 89 | * @var string |
||
| 90 | */ |
||
| 91 | public $fecha_disponibilidad; |
||
| 92 | //Datos auxiliares |
||
| 93 | public $edificaciones_tipo; |
||
| 94 | public $cliente; |
||
| 95 | public $cliente_info; |
||
| 96 | public $cliente_vehiculo; |
||
| 97 | public function __construct($t = FALSE) { |
||
| 125 | } |
||
| 126 | |||
| 127 | } |
||
| 128 | |||
| 129 | public function install() |
||
| 144 | } |
||
| 145 | |||
| 146 | public function url() |
||
| 147 | { |
||
| 148 | if (!is_null($this->id)) { |
||
| 149 | return FS_PATH.'index.php?page=ver_residente&id='.$this->id; |
||
| 150 | } else { |
||
| 151 | return FS_PATH.'index.php?page=residentes'; |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | public function info($item) |
||
| 156 | { |
||
| 157 | $cliente = new cliente(); |
||
| 158 | $cliente_info = new residentes_informacion(); |
||
| 159 | $cliente_vehiculo = new residentes_vehiculos(); |
||
| 160 | if ($item->codcliente) { |
||
| 161 | $item->nombre = $cliente->get($item->codcliente)->nombre; |
||
| 162 | $item->telefono = $cliente->get($item->codcliente)->telefono1; |
||
| 163 | $item->email = $cliente->get($item->codcliente)->email; |
||
| 164 | $item->info = $cliente_info->get($item->codcliente); |
||
| 165 | $item->vehiculos = $cliente_vehiculo->get_by_field('codcliente', $item->codcliente); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | public function listaInfo($data) |
||
| 170 | { |
||
| 171 | if ($data) { |
||
| 172 | $lista = array(); |
||
| 173 | foreach ($data as $d) { |
||
| 174 | $item = new residentes_edificaciones($d); |
||
| 175 | $item->pertenencia = $this->pertenencia($item); |
||
| 176 | $this->info($item); |
||
| 177 | $lista[] = $item; |
||
| 178 | } |
||
| 179 | return $lista; |
||
| 180 | } else { |
||
| 181 | return false; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | |||
| 185 | public function all() |
||
| 186 | { |
||
| 187 | $sql = "SELECT * FROM ".$this->table_name." ORDER BY codigo_interno,numero"; |
||
| 188 | $data = $this->db->select($sql); |
||
| 189 | return $this->listaInfo($data); |
||
| 190 | } |
||
| 191 | |||
| 192 | public function all_ocupados() |
||
| 193 | { |
||
| 194 | $sql = "SELECT re.*, c.nombre FROM ".$this->table_name." as re, clientes as c ". |
||
| 195 | " WHERE ocupado = TRUE and re.codcliente != '' and re.codcliente = c.codcliente ". |
||
| 196 | " ORDER BY re.codigo_interno, re.numero"; |
||
| 197 | $data = $this->db->select($sql); |
||
| 198 | return $this->listaInfo($data); |
||
| 199 | } |
||
| 200 | |||
| 201 | public function get($id){ |
||
| 202 | $sql = "SELECT * FROM ".$this->table_name." WHERE id = ".$this->intval($id).";"; |
||
| 203 | $data = $this->db->select($sql); |
||
| 204 | if($data){ |
||
| 205 | $item = new residentes_edificaciones($data[0]); |
||
| 206 | $item->pertenencia = $this->pertenencia($item); |
||
| 207 | $this->info($item); |
||
| 208 | return $item; |
||
| 209 | }else{ |
||
| 210 | return false; |
||
| 211 | } |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * //Si queremos buscar por codigo o codigo_interno o codcliente o numero |
||
| 216 | * @param type $field string |
||
| 217 | * @param type $value string |
||
| 218 | * @return boolean|\FacturaScripts\model\residentes_edificaciones |
||
| 219 | */ |
||
| 220 | public function get_by_field($field,$value){ |
||
| 221 | $query = (is_string($value))?$this->var2str($value):$this->intval($value); |
||
| 222 | $sql = "SELECT * FROM ".$this->table_name." WHERE ".strtoupper(trim($field))." = ".$query. |
||
| 223 | " ORDER BY codigo_interno,numero;"; |
||
| 224 | $data = $this->db->select($sql); |
||
| 225 | return $this->listaInfo($data); |
||
| 226 | } |
||
| 227 | |||
| 228 | public function exists() |
||
| 229 | { |
||
| 230 | if (is_null($this->id)) { |
||
| 231 | return false; |
||
| 232 | } else { |
||
| 233 | return $this->get($this->id); |
||
| 234 | } |
||
| 235 | } |
||
| 236 | |||
| 237 | public function save() |
||
| 238 | { |
||
| 239 | if ($this->exists()) { |
||
| 240 | $sql = "UPDATE ".$this->table_name." SET ". |
||
| 241 | "fecha_ocupacion = ".$this->var2str($this->fecha_ocupacion).", ". |
||
| 242 | "fecha_disponibilidad = ".$this->var2str($this->fecha_disponibilidad).", ". |
||
| 243 | "iddireccion = ".$this->intval($this->iddireccion).", ". |
||
| 244 | "id_edificacion = ".$this->intval($this->id_edificacion).", ". |
||
| 245 | "codigo = ".$this->var2str($this->codigo).", ". |
||
| 246 | "codigo_interno = ".$this->var2str($this->codigo_interno).", ". |
||
| 247 | "numero = ".$this->var2str($this->numero).", ". |
||
| 248 | "ubicacion = ".$this->var2str($this->ubicacion).", ". |
||
| 249 | "codcliente = ".$this->var2str($this->codcliente).", ". |
||
| 250 | "coordenadas = ".$this->var2str($this->coordenadas).", ". |
||
| 251 | "ocupado = ".$this->var2str($this->ocupado)." ". |
||
| 252 | "WHERE id = ".$this->intval($this->id).";"; |
||
| 253 | return $this->db->exec($sql); |
||
| 254 | } else { |
||
| 255 | $sql = "INSERT INTO ".$this->table_name." (id_edificacion, iddireccion, codigo, codigo_interno, numero, ubicacion, coordenadas,codcliente, ocupado, fecha_ocupacion, fecha_disponibilidad) VALUES (". |
||
| 256 | $this->intval($this->id_edificacion).", ". |
||
| 257 | $this->intval($this->iddireccion).", ". |
||
| 258 | $this->var2str($this->codigo).", ". |
||
| 259 | $this->var2str($this->codigo_interno).", ". |
||
| 260 | $this->var2str($this->numero).", ". |
||
| 261 | $this->var2str($this->ubicacion).", ". |
||
| 262 | $this->var2str($this->coordenadas).", ". |
||
| 263 | $this->var2str($this->codcliente).", ". |
||
| 264 | $this->var2str($this->ocupado).", ". |
||
| 265 | $this->var2str($this->fecha_ocupacion).", ". |
||
| 266 | $this->var2str($this->fecha_disponibilidad).");"; |
||
| 267 | if ($this->db->exec($sql)) { |
||
| 268 | return $this->db->lastval(); |
||
| 269 | } else { |
||
| 270 | return false; |
||
| 271 | } |
||
| 272 | } |
||
| 273 | } |
||
| 274 | |||
| 275 | public function delete() |
||
| 276 | { |
||
| 277 | $sql = "DELETE FROM ".$this->table_name." WHERE id = ".$this->intval($this->id).";"; |
||
| 278 | return $this->db->exec($sql); |
||
| 279 | } |
||
| 280 | |||
| 281 | private function pertenencia($d) |
||
| 282 | { |
||
| 283 | $edificaciones_tipo = new residentes_edificaciones_tipo(); |
||
| 284 | $codigo_interno = $d->codigo_interno; |
||
| 285 | $piezas = \json_decode($codigo_interno, true); |
||
| 286 | $lista = array(); |
||
| 287 | foreach ($piezas as $id => $data) { |
||
| 288 | $pertenencia = new \stdClass(); |
||
| 289 | $pertenencia->id = $id; |
||
| 290 | $pertenencia->desc_id = $edificaciones_tipo->get($id)->descripcion; |
||
| 291 | $pertenencia->padre = $edificaciones_tipo->get($id)->padre; |
||
| 292 | $pertenencia->valor = $data; |
||
| 293 | $lista[] = $pertenencia; |
||
| 294 | } |
||
| 295 | return $lista; |
||
| 296 | } |
||
| 297 | |||
| 298 | public function codigo_externo() |
||
| 299 | { |
||
| 300 | $edificaciones_tipo = new residentes_edificaciones_tipo(); |
||
| 301 | $piezas = \json_decode($this->codigo_interno, true); |
||
| 302 | $codigo_externo = ''; |
||
| 303 | foreach ($piezas as $id => $data) { |
||
| 304 | $codigo_externo .= $edificaciones_tipo->get($id)->descripcion.' '.$data.' '; |
||
| 305 | } |
||
| 306 | return $codigo_externo; |
||
| 307 | } |
||
| 308 | |||
| 309 | public function buscar_ubicacion_inmueble($id, $linea) |
||
| 310 | { |
||
| 311 | $inicio_busqueda = ($linea===0)?"{\"":"{%\""; |
||
| 312 | $sql = "SELECT * FROM ".$this->table_name." WHERE codigo_interno LIKE '". |
||
| 313 | $inicio_busqueda.$id."\":%}' ORDER BY codigo;"; |
||
| 314 | $data = $this->db->select($sql); |
||
| 315 | if ($data) { |
||
| 316 | $lista = array(); |
||
| 317 | foreach ($data as $d) { |
||
| 318 | $l = new residentes_edificaciones($d); |
||
| 319 | $lista[] = $this->pertenencia($l); |
||
| 320 | } |
||
| 321 | return $lista; |
||
| 322 | } else { |
||
| 323 | return false; |
||
| 324 | } |
||
| 325 | } |
||
| 326 | |||
| 327 | public function buscar_cantidad_inmuebles($id,$linea) |
||
| 328 | { |
||
| 329 | $inicio_busqueda = ($linea===0)?"{\"":"{%\""; |
||
| 330 | $sql = "SELECT DISTINCT codigo FROM ".$this->table_name." WHERE codigo_interno LIKE '". |
||
| 331 | $inicio_busqueda.$id."\":%}' ORDER BY codigo;"; |
||
| 332 | $data = $this->db->select($sql); |
||
| 333 | if ($data) { |
||
| 334 | $lista = array(); |
||
| 335 | foreach ($data as $d) { |
||
| 336 | $l = $this->get_by_field('codigo', $d['codigo']); |
||
| 337 | $lista[] = $l; |
||
| 338 | } |
||
| 339 | return $lista; |
||
| 340 | } else { |
||
| 341 | return false; |
||
| 342 | } |
||
| 343 | } |
||
| 344 | |||
| 345 | public function cantidad_inmuebles($id_edificacion) |
||
| 346 | { |
||
| 347 | $sql = "SELECT count(*) as cantidad FROM ".$this->table_name." WHERE id_edificacion = ". |
||
| 348 | $this->intval($id_edificacion).";"; |
||
| 349 | $data = $this->db->select($sql); |
||
| 350 | if ($data) { |
||
| 351 | return $data[0]['cantidad']; |
||
| 352 | } else { |
||
| 353 | return false; |
||
| 354 | } |
||
| 355 | } |
||
| 356 | |||
| 357 | public function generar_mapa() |
||
| 358 | { |
||
| 359 | $edificaciones_tipo = new residentes_edificaciones_tipo(); |
||
| 360 | $mapa = array(); |
||
| 361 | $linea = 0; |
||
| 362 | foreach ($edificaciones_tipo->all() as $data) { |
||
| 363 | if ($linea===1) { |
||
| 364 | break; |
||
| 365 | } |
||
| 366 | $items = $this->buscar_cantidad_inmuebles($data->id, $data->padre); |
||
| 367 | foreach ($items as $inmueble) { |
||
| 368 | $mapa[$data->id][] = $inmueble; |
||
| 369 | } |
||
| 370 | $linea++; |
||
| 371 | } |
||
| 372 | return $mapa; |
||
| 373 | } |
||
| 374 | |||
| 375 | public function search($query, $type = "") |
||
| 406 | } |
||
| 407 | |||
| 408 | public function lista_residentes($where = "", $order = "", $sort = "", $limit = FS_ITEM_LIMIT, $offset = 0) |
||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * @param false $todo |
||
| 449 | * @param string $whereSQL |
||
| 450 | * @param string $sort |
||
| 451 | * @param string $order |
||
| 452 | * @param integer $limit |
||
| 453 | * @param integer $offset |
||
| 454 | * @return array |
||
| 455 | */ |
||
| 456 | public function listaResidentes( |
||
| 457 | $todo = false, |
||
| 458 | $whereSQL = '', |
||
| 459 | $sort = 'r.codigo, r.numero', |
||
| 460 | $order = 'ASC', |
||
| 461 | $limit = FS_ITEM_LIMIT, |
||
| 462 | $offset = 0 |
||
| 463 | ) |
||
| 464 | { |
||
| 465 | $sql = " select r.codcliente, c.nombre, c.cifnif, c.telefono1, c.email, codigo, numero, fecha_ocupacion ". |
||
| 466 | " from residentes_edificaciones as r, clientes as c ". |
||
| 467 | " where r.codcliente = c.codcliente ".$whereSQL. |
||
| 468 | " order by ".$sort." ".$order; |
||
| 469 | if ($todo) { |
||
| 470 | $data = $this->db->select($sql); |
||
| 471 | } else { |
||
| 472 | $data = $this->db->select_limit($sql, $limit, $offset); |
||
| 473 | } |
||
| 474 | $sql_cantidad = "select count(r.id) as total from residentes_edificaciones as r ". |
||
| 475 | " where r.codcliente != '' ".$whereSQL; |
||
| 476 | $data_cantidad = $this->db->select($sql_cantidad); |
||
| 477 | return array($data, $data_cantidad[0]['total']); |
||
| 478 | } |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @param false $todo |
||
| 482 | * @param string $whereSQL |
||
| 483 | * @param string $sort |
||
| 484 | * @param string $order |
||
| 485 | * @param integer $limit |
||
| 486 | * @param integer $offset |
||
| 487 | * @return array |
||
| 488 | */ |
||
| 489 | public function listaInmuebles( |
||
| 519 | } |
||
| 520 | |||
| 521 | /** |
||
| 522 | * @param false $todo |
||
| 523 | * @param string $whereSQL |
||
| 524 | * @param string $sort |
||
| 525 | * @param string $order |
||
| 526 | * @param integer $limit |
||
| 527 | * @param integer $offset |
||
| 528 | * @return array |
||
| 529 | */ |
||
| 530 | public function listaCobros( |
||
| 564 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths