Implemented repository mapper, and venta show
This commit is contained in:
@ -3,6 +3,7 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Comuna extends Ideal\Repository
|
||||
@ -15,14 +16,10 @@ class Comuna extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'provincia' => [
|
||||
'function' => function($data) {
|
||||
return $this->provinciaRepository->fetchById($data['provincia']);
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion']))
|
||||
->register('provincia', (new Implement\Repository\Mapper())->setFunction(function($data) {
|
||||
return $this->provinciaRepository->fetchById($data['provincia']);
|
||||
}));
|
||||
return $this->parseData(new Model\Comuna(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
@ -48,4 +45,12 @@ class Comuna extends Ideal\Repository
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `provincia` = ?";
|
||||
return $this->fetchMany($query, [$provincia_id]);
|
||||
}
|
||||
public function fetchByDireccion(string $direccion): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `direccion` ON `direccion`.`comuna` = a.`id`
|
||||
WHERE TRIM(CONCAT_WS(' ', `direccion`.`calle`, `direccion`.`numero`, `direccion`.`extra`)) LIKE ?";
|
||||
return $this->fetchMany($query, ["%{$direccion}%"]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user