Descripcion extensa de unidad

This commit is contained in:
2020-03-13 10:25:37 -03:00
parent f1363fa4c1
commit 1a3e9d7bd6

View File

@ -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;
}
}