56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
namespace Incoviba\Repository;
|
|
|
|
use Incoviba\Common\Define;
|
|
use Incoviba\Common\Ideal;
|
|
use Incoviba\Common\Implement;
|
|
use Incoviba\Model;
|
|
|
|
class Nubox extends Ideal\Repository
|
|
{
|
|
public function __construct(Define\Connection $connection, protected Inmobiliaria $inmobiliariaRepository)
|
|
{
|
|
parent::__construct($connection);
|
|
$this->setTable('inmobiliarias_nubox');
|
|
}
|
|
|
|
public function create(?array $data = null): Model\Nubox
|
|
{
|
|
$map = (new Implement\Repository\MapperParser(['usuario', 'alias']))
|
|
->register('inmobiliaria_rut', (new Implement\Repository\Mapper())
|
|
->setProperty('inmobiliaria')
|
|
->setFunction(function(array $data) {
|
|
return $this->inmobiliariaRepository->fetchById($data['inmobiliaria_rut']);
|
|
}))
|
|
->register('contraseña', (new Implement\Repository\Mapper())
|
|
->setProperty('password'));
|
|
return $this->parseData(new Model\Nubox(), $data, $map);
|
|
}
|
|
public function save(Define\Model $model): Model\Nubox
|
|
{
|
|
$this->saveNew(
|
|
['inmobiliaria_rut', 'alias', 'usuario', 'contraseña'],
|
|
[$model->inmobiliaria->rut, $model->alias, $model->usuario, $model->password]
|
|
);
|
|
return $model;
|
|
}
|
|
public function edit(Define\Model $model, array $new_data): Model\Nubox
|
|
{
|
|
return $this->update($model, ['inmobiliaria_rut', 'alias', 'usuario', 'contraseña'], $new_data);
|
|
}
|
|
|
|
public function fetchByInmobiliaria(int $inmobiliaria_rut): Model\Nubox
|
|
{
|
|
$query = $this->connection->getQueryBuilder()
|
|
->select()
|
|
->from($this->getTable())
|
|
->where('inmobiliaria_rut = ?');
|
|
return $this->fetchOne($query, [$inmobiliaria_rut]);
|
|
}
|
|
|
|
protected function getKey(): string
|
|
{
|
|
return 'inmobiliaria_rut';
|
|
}
|
|
}
|