120 lines
3.0 KiB
PHP
120 lines
3.0 KiB
PHP
<?php
|
|
namespace Incoviba\old\Venta;
|
|
|
|
use Incoviba\Common\Alias\OldModel as Model;
|
|
use Incoviba\nuevo\Venta\Propiedad as P;
|
|
use Incoviba\nuevo\Venta\UnidadPropiedad;
|
|
|
|
/**
|
|
*
|
|
* @property int id
|
|
* @property Unidad unidad_principal
|
|
* @property string estacionamientos
|
|
* @property string bodegas
|
|
* @property int estado
|
|
*
|
|
*/
|
|
class Propiedad extends Model
|
|
{
|
|
private $estacionamientos_arr = null;
|
|
private $bodegas_arr = null;
|
|
|
|
public function unidad()
|
|
{
|
|
$unidad = $this->belongs_to(Unidad::class, 'unidad_principal')->findOne();
|
|
$unidad->setContainer($this->container);
|
|
return $unidad;
|
|
}
|
|
protected $unidades;
|
|
public function unidades() {
|
|
if ($this->unidades == null) {
|
|
$this->unidades = $this->hasMany(PropiedadUnidad::class, 'propiedad')->findMany();
|
|
}
|
|
return $this->unidades;
|
|
}
|
|
protected $departamentos;
|
|
public function departamentos() {
|
|
if ($this->departamentos == null) {
|
|
$this->departamentos = array_map(function($item) {
|
|
return $item->unidad();
|
|
}, array_filter($this->unidades(), function($item) {
|
|
return ($item->unidad()->tipo()->descripcion == 'departamento');
|
|
}));
|
|
}
|
|
return $this->departamentos;
|
|
}
|
|
public function estacionamientos($mod = null)
|
|
{
|
|
if ($this->estacionamientos_arr == null) {
|
|
if (($unidades = $this->unidades()) !== false) {
|
|
$estacionamientos = array_filter($unidades, function($item) {
|
|
return ($item->unidad()->tipo()->descripcion == 'estacionamiento');
|
|
});
|
|
$this->estacionamientos_arr = array_map(function($item) {
|
|
return $item->unidad();
|
|
}, $estacionamientos);
|
|
} else {
|
|
$ests = explode(';', $this->estacionamientos);
|
|
$estacionamientos = [];
|
|
foreach ($ests as $e) {
|
|
$estacionamiento = \Model::factory(Unidad::class)->findOne($e);
|
|
if ($estacionamiento) {
|
|
$estacionamientos []= $estacionamiento;
|
|
}
|
|
}
|
|
$this->estacionamientos_arr = $estacionamientos;
|
|
}
|
|
}
|
|
if ($mod != null) {
|
|
switch ($mod) {
|
|
case 'array':
|
|
$result = [];
|
|
foreach ($this->estacionamientos_arr as $est) {
|
|
$result []= $est->descripcion;
|
|
}
|
|
return $result;
|
|
}
|
|
}
|
|
return $this->estacionamientos_arr;
|
|
}
|
|
public function bodegas($mod = null)
|
|
{
|
|
if ($this->bodegas_arr == null) {
|
|
if (($unidades = $this->unidades()) !== false) {
|
|
$bodegas = array_filter($unidades, function($item) {
|
|
return ($item->unidad()->tipo()->descripcion == 'bodega');
|
|
});
|
|
$this->bodegas_arr = array_map(function($item) {
|
|
return $item->unidad();
|
|
}, $bodegas);
|
|
} else {
|
|
$bods = explode(';', $this->bodegas);
|
|
$bodegas = [];
|
|
foreach ($bods as $b) {
|
|
$bodega = \Model::factory(Unidad::class)->findOne($b);
|
|
if ($bodega) {
|
|
$bodegas []= $bodega;
|
|
}
|
|
}
|
|
$this->bodegas_arr = $bodegas;
|
|
}
|
|
}
|
|
if ($mod != null) {
|
|
switch ($mod) {
|
|
case 'array':
|
|
$result = [];
|
|
foreach ($this->bodegas_arr as $bod) {
|
|
$result []= $bod->descripcion;
|
|
}
|
|
return $result;
|
|
}
|
|
}
|
|
return $this->bodegas_arr;
|
|
}
|
|
public function venta()
|
|
{
|
|
return $this->has_one(Venta::class, 'propiedad')->findOne();
|
|
}
|
|
}
|
|
?>
|