From 1a3e9d7bd646eefe0b1c22d1631c90618e599e9a Mon Sep 17 00:00:00 2001 From: Aldarien Date: Fri, 13 Mar 2020 10:25:37 -0300 Subject: [PATCH] Descripcion extensa de unidad --- src/old/Venta/Unidad.php | 71 +++++++++------------------------------- 1 file changed, 16 insertions(+), 55 deletions(-) diff --git a/src/old/Venta/Unidad.php b/src/old/Venta/Unidad.php index 5c4a102..5202c8f 100644 --- a/src/old/Venta/Unidad.php +++ b/src/old/Venta/Unidad.php @@ -31,65 +31,13 @@ class Unidad extends Model { $this->proyecto_obj = $this->setRelationship(Proyecto::class, 'id', 'proyecto')->one(); } return $this->proyecto_obj; - /*$proyecto = $this->belongs_to(Proyecto::class, 'proyecto')->findOne(); - $proyecto->setContainer($this->container); - return $proyecto;*/ } protected $propiedad; public function propiedad() { if ($this->propiedad === null) { $this->propiedad = $this->setRelationship(PropiedadUnidad::class, 'unidad', 'id')->one(); - //$this->propiedad = $this->hasMany(PropiedadUnidad::class, 'unidad')->findOne(); } return $this->propiedad; - - /*if ($this->tipo()->descripcion == 'departamento') { - $propiedad = $this->has_one(Propiedad::class, 'unidad_principal'); - if ($propiedad) { - return $propiedad->findOne(); - } - return null; - } - if ($this->tipo()->descripcion == 'estacionamiento') { - // id | id; | ;id | ;id; - $propiedad = model(Propiedad::class)->whereLike('estacionamientos', $this->id)->findOne(); - if ($propiedad) { - return $propiedad; - } - $propiedad = model(Propiedad::class)->whereLike('estacionamientos', '%;' . $this->id)->findOne(); - if ($propiedad) { - return $propiedad; - } - $propiedad = model(Propiedad::class)->whereLike('estacionamientos', $this->id . ';%')->findOne(); - if ($propiedad) { - return $propiedad; - } - $propiedad = model(Propiedad::class)->whereLike('estacionamientos', '%;' . $this->id . ';%')->findOne(); - if ($propiedad) { - return $propiedad; - } - return null; - } - if ($this->tipo()->descripcion == 'bodega') { - // id | id; | ;id | ;id; - $propiedad = model(Propiedad::class)->whereLike('bodegas', $this->id)->findOne(); - if ($propiedad) { - return $propiedad; - } - $propiedad = model(Propiedad::class)->whereLike('bodegas', '%;' . $this->id)->findOne(); - if ($propiedad) { - return $propiedad; - } - $propiedad = model(Propiedad::class)->whereLike('bodegas', $this->id . ';%')->findOne(); - if ($propiedad) { - return $propiedad; - } - $propiedad = model(Propiedad::class)->whereLike('bodegas', '%;' . $this->id . ';%')->findOne(); - if ($propiedad) { - return $propiedad; - } - return null; - }*/ } protected $tipo_obj; public function tipo() { @@ -97,7 +45,6 @@ class Unidad extends Model { $this->tipo_obj = $this->setRelationship(TipoUnidad::class, 'id', 'tipo')->one(); } return $this->tipo_obj; - //return $this->belongs_to(TipoUnidad::class, 'tipo')->findOne(); } private $venta = null; public function venta() { @@ -132,7 +79,6 @@ class Unidad extends Model { $this->precios = $this->setRelationship(Precio::class, 'unidad', 'id')->many(); } return $this->precios; - //return $this->hasMany(Precio::class, 'unidad')->findMany(); } public function precio($fecha = null) { if ($fecha == null) { @@ -188,7 +134,6 @@ class Unidad extends Model { $this->tipologia = $this->setRelationship(ProyectoTipoUnidad::class, 'id', 'pt')->one(); } return $this->tipologia; - //return $this->belongsTo(ProyectoTipoUnidad::class, 'pt')->findOne(); } protected $is_vendida; public function isVendida() { @@ -251,4 +196,20 @@ class Unidad extends Model { } return $this->linea; } + protected $descripcion_full; + public function descripcion() { + if ($this->descripcion_full === null) { + $desc = [$this->descripcion]; + $id = $this->id; + $unidades = array_filter($this->propiedad()->propiedad()->unidades(), function($item) use ($id) { + return ($item->unidad()->tipo()->descripcion == 'departamento' and $item->unidad()->id != $id); + }); + foreach ($unidades as $unidad) { + $desc []= $unidad->unidad()->descripcion; + } + sort($desc); + $this->descripcion_full = implode(' - ', $desc); + } + return $this->descripcion_full; + } }