2024-06-18
This commit is contained in:
49
app/src/Repository/Persona.php
Normal file
49
app/src/Repository/Persona.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Persona extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('personas');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Persona
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['rut', 'digito', 'nombres']))
|
||||
->register('apellido_paterno', (new Implement\Repository\Mapper())->setProperty('apellidoPaterno'))
|
||||
->register('apellido_materno', (new Implement\Repository\Mapper())->setProperty('apellidoMaterno'))
|
||||
;
|
||||
return $this->parseData(new Model\Persona(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Persona
|
||||
{
|
||||
$this->saveNew(['rut', 'digito', 'nombres', 'apellido_paterno', 'apellido_materno'],
|
||||
[$model->rut, $model->digito, $model->nombres, $model->apellidoPaterno, $model->apellidoMaterno]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Persona
|
||||
{
|
||||
return $this->update($model, $new_data, ['rut', 'digito', 'nombres', 'apellido_paterno', 'apellido_materno']);
|
||||
}
|
||||
|
||||
public function fetchByRut(int $rut): Model\Persona
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('rut = ?');
|
||||
return $this->fetchOne($query, [$rut]);
|
||||
}
|
||||
|
||||
protected function getKey(): string
|
||||
{
|
||||
return 'rut';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user