2023-07-28 16:22:20 -04:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Repository\Venta;
|
|
|
|
|
|
|
|
use Incoviba\Common\Ideal;
|
|
|
|
use Incoviba\Common\Define;
|
2023-08-08 23:53:49 -04:00
|
|
|
use Incoviba\Common\Implement;
|
2023-07-28 16:22:20 -04:00
|
|
|
use Incoviba\Model;
|
2023-08-08 23:53:49 -04:00
|
|
|
use Incoviba\Service;
|
2023-07-28 16:22:20 -04:00
|
|
|
|
|
|
|
class Propiedad extends Ideal\Repository
|
|
|
|
{
|
2023-08-08 23:53:49 -04:00
|
|
|
public function __construct(Define\Connection $connection, protected Service\Venta\Unidad $unidadService)
|
2023-07-28 16:22:20 -04:00
|
|
|
{
|
|
|
|
parent::__construct($connection);
|
|
|
|
$this->setTable('propiedad');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create(?array $data = null): Define\Model
|
|
|
|
{
|
2023-08-08 23:53:49 -04:00
|
|
|
$map = (new Implement\Repository\MapperParser())
|
|
|
|
->register('unidad_principal', (new Implement\Repository\Mapper())
|
|
|
|
->setProperty('unidades')
|
|
|
|
->setFunction(function($data) {
|
|
|
|
return $this->unidadService->getByPropiedad($data['id']);
|
|
|
|
}))
|
|
|
|
->register('estado', new Implement\Repository\Mapper\Boolean('estado'));
|
2023-07-28 16:22:20 -04:00
|
|
|
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
|
|
|
|
}
|
|
|
|
public function save(Define\Model $model): Define\Model
|
|
|
|
{
|
|
|
|
$model->id = $this->saveNew(
|
|
|
|
['unidad_principal', 'estacionamientos', 'bodegas', 'estado'],
|
|
|
|
[$model->departamentos()[0]->id, null, null, 1]
|
|
|
|
);
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
public function edit(Define\Model $model, array $new_data): Define\Model
|
|
|
|
{
|
|
|
|
return $this->update($model, ['unidad_principal', 'estacionamientos', 'bodegas', 'estado'], $new_data);
|
|
|
|
}
|
|
|
|
}
|