Files
oficial/app/src/Repository/Venta/Propiedad.php

42 lines
1.4 KiB
PHP
Raw Normal View History

2023-07-28 16:22:20 -04:00
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
2023-07-28 16:22:20 -04:00
use Incoviba\Model;
use Incoviba\Service;
2023-07-28 16:22:20 -04:00
class Propiedad extends Ideal\Repository
{
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
{
$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);
}
}