Limpieza de input de valor y filtro de datos a nivel Repo
This commit is contained in:
54
app/src/Repository/Venta/Unidad/Prorrateo.php
Normal file
54
app/src/Repository/Venta/Unidad/Prorrateo.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta\Unidad;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Prorrateo extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta\Unidad $unidadRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('unidad_prorrateo');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Venta\Unidad\Prorrateo
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['prorrateo']))
|
||||
->register('unidad_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('unidad')
|
||||
->setFunction(function($data) {
|
||||
return $this->unidadRepository->fetchById($data['unidad_id']);
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Unidad\Prorrateo(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Venta\Unidad\Prorrateo
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['unidad_id', 'prorrateo'],
|
||||
[$model->unidad->id, $model->prorrateo]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\Unidad\Prorrateo
|
||||
{
|
||||
return $this->update($model, ['unidad_id', 'prorrateo'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByUnidad(int $unidad_id): Model\Venta\Unidad\Prorrateo
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('unidad_id = ?');
|
||||
return $this->fetchOne($query, [$unidad_id]);
|
||||
}
|
||||
|
||||
public function filterData(array $data): array
|
||||
{
|
||||
return array_intersect_key($data, array_flip(['prorrateo']));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user