2023-09-12
This commit is contained in:
@ -15,27 +15,39 @@ class Propiedad extends Ideal\Repository
|
||||
$this->setTable('propiedad');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta\Propiedad
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('unidad_principal', (new Implement\Repository\Mapper())
|
||||
->setProperty('unidades')
|
||||
->setFunction(function($data) {
|
||||
return $this->unidadService->getByPropiedad($data['id']);
|
||||
if (isset($data['id'])) {
|
||||
return $this->unidadService->getByPropiedad($data['id']);
|
||||
}
|
||||
return [$this->unidadService->getById($data['unidad_principal'])];
|
||||
}))
|
||||
->register('estado', new Implement\Repository\Mapper\Boolean('estado'));
|
||||
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Venta\Propiedad
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['unidad_principal', 'estacionamientos', 'bodegas', 'estado'],
|
||||
[$model->departamentos()[0]->id, null, null, 1]
|
||||
[$model->departamentos()[0]->id,
|
||||
implode(',', array_map(function(Model\Venta\Unidad $unidad) {return $unidad->id;}, $model->estacionamientos())),
|
||||
implode(',', array_map(function(Model\Venta\Unidad $unidad) {return $unidad->id;}, $model->bodegas())),
|
||||
1]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\Propiedad
|
||||
{
|
||||
return $this->update($model, ['unidad_principal', 'estacionamientos', 'bodegas', 'estado'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchVigenteByUnidad(int $unidad_id): Model\Venta\Propiedad
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `unidad_principal` = ?";
|
||||
return $this->fetchOne($query, [$unidad_id]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user