Se agregan los campos por segmento

This commit is contained in:
2020-06-03 21:59:11 -04:00
parent 2d2eccb600
commit 080ed4553e
14 changed files with 486 additions and 174 deletions

View File

@ -27,25 +27,7 @@ class Producto extends Model {
}
$this->valor = number_format($valor, 0, ',', '.');
}
public function tamaños(int $min = -1, int $max = -1) {
if ($min == -1) {
return $this->tamaños;
}
if ($max == -1) {
$max = $min;
}
$this->tamaños = $min . ' - ' . $max . ' m²';
}
public function entrega(\DataTime $fecha = null) {
if ($fecha === null) {
return Carbon::parse(implode('-', array_reverse(explode('/', $this->entrega))) . '-01');
}
$this->entrega = $fecha->format('%m/%Y');
}
public function publicacion(\DateTime $fecha = null) {
if ($fecha === null) {
return Carbon::parse($this->publicacion);
}
public function setPublicacion(\DateTime $fecha) {
$this->publicacion = implode(' ', [
$fecha->day,
'de',
@ -53,6 +35,9 @@ class Producto extends Model {
$fecha->year
]);
}
public function getPublicacion() {
return Carbon::parse($this->publicacion);
}
protected $destacado;
public function destacado(bool $destacado = null) {
if ($destacado === null) {
@ -140,35 +125,40 @@ class Producto extends Model {
$this->direccion = new Direccion();
$this->direccion->map($data);
$this->valor($data->valor);
$this->bono = $data->bono;
$this->rentabilidad = $data->rentabilidad;
$this->cuota = $data->cuota;
$this->entrega = $data->entrega;
$this->estado = $data->estado;
$this->unidades = $data->unidades;
$this->modelos = $data->modelos;
$this->tamaños = $data->tamaños;
$this->descripcion = $data->descripcion;
$this->publicacion = $data->publicacion;
foreach ($this->properties as $property) {
$this->$property = $data->$property ?? '';
}
return $this;
}
public function __get(string $name) {
if (method_exists($this, $name)) {
return $this->$name();
}
if (!property_exists($this, $name) and array_search($name, $this->properties) === false) {
throw new \InvalidArgumentException($name . ' no es una propiedad de ' . get_called_class());
}
return $this->$name;
}
public function __set(string $name, $value) {
if (!property_exists($this, $name) and array_search($name, $this->properties) === false) {
throw new \InvalidArgumentException($name . ' no es una propiedad de ' . get_called_class());
}
$this->$name = $value;
}
public function jsonSerialize() {
$arr = [
'id' => $this->id,
'nombre' => $this->nombre,
'segmento' => $this->segmento,
'valor' => $this->valor,
'bono' => $this->bono,
'rentabilidad' => $this->rentabilidad,
'cuota' => $this->cuota,
'entrega' => $this->entrega,
'estado' => $this->estado,
'unidades' => $this->unidades,
'modelos' => $this->modelos,
'tamaños' => $this->tamaños,
'descripcion' => $this->descripcion,
'publicacion' => $this->publicacion
];
foreach ($this->properties as $property) {
$arr[$property] = $this->$property;
}
$arr = array_merge($arr, $this->direccion->jsonSerialize());
return $arr;
}
@ -230,4 +220,15 @@ class Producto extends Model {
file_put_contents($filename, json_encode($destacados));
}
}
public function getProperties(): array {
$properties = [];
foreach ($this->properties as $property) {
$p = (object) [
'label' => ucwords($property),
'name' => $property
];
$properties []= $p;
}
return $properties;
}
}