Implemented repository mapper, and venta show
This commit is contained in:
@ -3,8 +3,8 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Proyecto extends Ideal\Repository
|
||||
{
|
||||
@ -16,40 +16,31 @@ class Proyecto extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'inmobiliaria' => [
|
||||
'function' => function($data) {
|
||||
return $this->inmobiliariaRepository->fetchById($data['inmobiliaria']);
|
||||
}
|
||||
],
|
||||
'descripcion' => [],
|
||||
'direccion' => [
|
||||
'function' => function($data) {
|
||||
return $this->direccionRepository->fetchById($data['direccion']);
|
||||
}
|
||||
],
|
||||
'superficie_terreno' => [
|
||||
'property' => 'terreno',
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion', 'corredor', 'pisos', 'subterraneos']))
|
||||
->register('inmobiliaria', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->inmobiliariaRepository, 'fetchById'])
|
||||
->setArgs([$data['inmobiliaria']])))
|
||||
->register('direccion', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->inmobiliariaRepository, 'fetchById'])
|
||||
->setArgs([$data['inmobiliaria']])))
|
||||
->register('superficie_terreno', (new Implement\Repository\Mapper())
|
||||
->setProperty('terreno')
|
||||
->setFunction(function($data) {
|
||||
$terreno = new Model\Proyecto\Terreno();
|
||||
$terreno->superficie = $data['superficie_terreno'];
|
||||
$terreno->valor = $data['valor_terreno'];
|
||||
return $terreno;
|
||||
}
|
||||
],
|
||||
'superficie_sobre_nivel' => [
|
||||
'property' => 'superficie',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('superficie_sobre_nivel', (new Implement\Repository\Mapper())
|
||||
->setProperty('superficie')
|
||||
->setFunction(function($data) {
|
||||
$superficie = new Model\Proyecto\Superficie();
|
||||
$superficie->sobre_nivel = $data['superficie_sobre_nivel'];
|
||||
$superficie->bajo_nivel = $data['superficie_bajo_nivel'];
|
||||
return $superficie;
|
||||
}
|
||||
],
|
||||
'corredor' => [],
|
||||
'pisos' => [],
|
||||
'subterraneos' => []
|
||||
];
|
||||
}));
|
||||
return $this->parseData(new Model\Proyecto(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
@ -57,7 +48,7 @@ class Proyecto extends Ideal\Repository
|
||||
$model->id = $this->saveNew(
|
||||
['inmobiliaria', 'descripcion', 'direccion', 'superficie_terreno', 'valor_terreno', 'corredor',
|
||||
'superficie_sobre_nivel', 'superficie_bajo_nivel', 'pisos', 'subterraneos'],
|
||||
[$model->inmobiliaria->rut, $model->descripcion, $model->direccion->id, $model->terreno->superficie,
|
||||
[$model->inmobiliaria()->rut, $model->descripcion, $model->direccion()->id, $model->terreno->superficie,
|
||||
$model->terreno->valor, $model->corredor, $model->superficie->sobre_nivel,
|
||||
$model->superficie->bajo_nivel, $model->pisos, $model->subterraneos]
|
||||
);
|
||||
|
Reference in New Issue
Block a user