Auth, Login, Home, Venta->Listados->Precios
This commit is contained in:
51
app/src/Repository/Comuna.php
Normal file
51
app/src/Repository/Comuna.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Comuna extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Provincia $provinciaRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('comuna');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'provincia' => [
|
||||
'function' => function($data) {
|
||||
return $this->provinciaRepository->fetchById($data['provincia']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Comuna(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'provincia'],
|
||||
[$model->descripcion, $model->provincia->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'provincia'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $descripcion): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
|
||||
return $this->fetchOne($query, [$descripcion]);
|
||||
}
|
||||
public function fetchByProvincia(int $provincia_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `provincia` = ?";
|
||||
return $this->fetchMany($query, [$provincia_id]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user