72 lines
2.3 KiB
PHP
72 lines
2.3 KiB
PHP
<?php
|
|
namespace Incoviba\Model\Proyecto;
|
|
|
|
use Incoviba\Common\Ideal;
|
|
use Incoviba\Model;
|
|
|
|
class ProyectoTipoUnidad extends Ideal\Model
|
|
{
|
|
public Model\Proyecto $proyecto;
|
|
public Model\Proyecto\TipoUnidad $tipoUnidad;
|
|
public string $nombre;
|
|
public string $abreviacion;
|
|
public float $util;
|
|
public float $logia;
|
|
public float $terraza;
|
|
public string $descripcion;
|
|
|
|
public array $tipologias;
|
|
|
|
public function superficie(): float
|
|
{
|
|
return array_reduce([$this->util, $this->logia, $this->terraza], function($sum, $item) {return $sum + $item;}, 0);
|
|
}
|
|
public function vendible(): float
|
|
{
|
|
return array_reduce([$this->util, $this->logia, $this->terraza / 2], function($sum, $item) {return $sum + $item;}, 0);
|
|
}
|
|
public function tipologia(): string
|
|
{
|
|
if (isset($this->tipologias) and count($this->tipologias) > 0) {
|
|
$temp = [...$this->tipologias];
|
|
usort($temp, function(Tipologia $a, Tipologia $b) {
|
|
$el = $a->elemento->orden - $b->elemento->orden;
|
|
if ($el === 0) {
|
|
return strcmp($a->elemento->abreviacion, $b->elemento->abreviacion);
|
|
}
|
|
return $el;
|
|
});
|
|
return implode('/', array_map(function(Tipologia $tipologia) {
|
|
return $tipologia->cantidad . $tipologia->elemento->abreviacion;
|
|
}, $temp));
|
|
}
|
|
return $this->abreviacion;
|
|
}
|
|
|
|
protected array $unidades;
|
|
public function unidades(): array
|
|
{
|
|
if (!isset($this->unidades)) {
|
|
$this->unidades = $this->runFactory('unidades');
|
|
}
|
|
return $this->unidades;
|
|
}
|
|
|
|
public function jsonSerialize(): mixed
|
|
{
|
|
return array_merge(parent::jsonSerialize(), [
|
|
'proyecto' => $this->proyecto,
|
|
'tipo_unidad' => $this->tipoUnidad,
|
|
'nombre' => $this->nombre,
|
|
'abreviacion' => $this->abreviacion,
|
|
'util' => $this->util,
|
|
'logia' => $this->logia,
|
|
'terraza' => $this->terraza,
|
|
'superficie' => $this->superficie(),
|
|
'vendible' => $this->vendible(),
|
|
'descripcion' => $this->descripcion,
|
|
'tipologia' => $this->tipologia()
|
|
]);
|
|
}
|
|
}
|