This commit is contained in:
Juan Pablo Vial
2024-04-02 23:02:52 -03:00
parent 5d9ac2bc51
commit 8710c8a111
12 changed files with 457 additions and 0 deletions

View File

@ -0,0 +1,47 @@
<?php
namespace Incoviba\Repository\Inmobiliaria;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
class Agente extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Direccion $direccionRepository, protected TipoAgente $tipoAgenteRepository)
{
parent::__construct($connection);
$this->setTable('agente');
}
public function create(?array $data = null): Model\Inmobiliaria\Agente
{
$map = (new Implement\Repository\MapperParser(['rut', 'descripcion', 'telefono', 'correo', 'giro', 'abreviacion']))
->register('representante', (new Implement\Repository\Mapper())
->setProperty('contacto'))
->register('direccion', (new Implement\Repository\Mapper())
->setFunction(function(?array $data) {
if ($data === null) {
return null;
}
return $this->direccionRepository->fetchById($data['direccion']);
}));
return $this->parseData(new Model\Inmobiliaria\Agente(), $data, $map);
}
public function save(Define\Model $model): Model\Inmobiliaria\Agente
{
$model->id = $this->saveNew([
'rut', 'descripcion', 'representante', 'telefono', 'correo', 'giro', 'abreviacion'
], [
$model->rut, $model->descripcion, $model->contacto, $model->telefono, $model->correo, $model->giro, $model->abreviacion
]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Inmobiliaria\Agente
{
return $this->update($model, [
'rut', 'descripcion', 'representante', 'telefono', 'correo', 'giro', 'abreviacion'
], $new_data);
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace Incoviba\Repository\Inmobiliaria;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
class AgenteTipo extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Agente $agenteRepository,
protected TipoAgente $tipoAgenteRepository)
{
parent::__construct($connection);
$this->setTable('agente_tipo');
}
public function create(?array $data = null): Model\Inmobiliaria\AgenteTipo
{
$map = (new Implement\Repository\MapperParser())
->register('agente', (new Implement\Repository\Mapper())
->setFunction(function(?array $data) {
return ($data === null) ? null : $this->agenteRepository->fetchById($data['agente']);
}))
->register('tipo', (new Implement\Repository\Mapper())
->setFunction(function(?array $data) {
return ($data === null) ? null : $this->tipoAgenteRepository->fetchById($data['tipo']);
}));
return $this->parseData(new Model\Inmobiliaria\AgenteTipo(), $data, $map);
}
public function save(Define\Model $model): Model\Inmobiliaria\AgenteTipo
{
$model->id = $this->saveNew(['agente', 'tipo'], [
$model->agente->id, $model->agenteTipo->id
]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Inmobiliaria\AgenteTipo
{
return $this->update($model, ['agente', 'tipo'], $new_data);
}
public function fetchByAgente(int $agente_id): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('agente = ?');
return $this->fetchMany($query, [$agente_id]);
}
public function fetchByTipo(int $tipo_agente_id): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('tipo = ?');
return $this->fetchMany($query, [$tipo_agente_id]);
}
public function fetchByAgenteAndTipo(int $agente_id, int $tipo_agente_id): Model\Inmobiliaria\AgenteTipo
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('agente = ? AND tipo = ?');
return $this->fetchOne($query, [$agente_id, $tipo_agente_id]);
}
}

View File

@ -0,0 +1,105 @@
<?php
namespace Incoviba\Repository\Inmobiliaria;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
class SociedadAgente extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Inmobiliaria $inmobiliariaRepository,
protected AgenteTipo $agenteRepository)
{
parent::__construct($connection);
$this->setTable('sociedad_agente');
}
public function create(?array $data = null): Model\Inmobiliaria\SociedadAgente
{
$map = (new Implement\Repository\MapperParser())
->register('sociedad_rut', (new Implement\Repository\Mapper())
->setProperty('sociedad')
->setFunction(function(?array $data) {
return ($data === null) ? null : $this->inmobiliariaRepository->fetchById($data['sociedad_rut']);
}))
->register('agente_tipo_id', (new Implement\Repository\Mapper())
->setProperty('agenteTipo')
->setFunction(function(?array $data) {
return ($data === null) ? null : $this->agenteRepository->fetchById($data['agente_tipo_id']);
}));
return $this->parseData(new Model\Inmobiliaria\SociedadAgente(), $data, $map);
}
public function save(Define\Model $model): Model\Inmobiliaria\SociedadAgente
{
$model->id = $this->saveNew([
'sociedad_rut', 'agente_tipo_id'
], [
$model->sociedad->rut, $model->agenteTipo->id
]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Inmobiliaria\SociedadAgente
{
return $this->update($model, ['sociedad_rut', 'agente_tipo_id'], $new_data);
}
public function load(array $data_row): Define\Model
{
$model = $this->create($data_row);
return $model;
}
public function fetchBySociedad(int $sociedad_rut): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('sociedad_rut = ?');
return $this->fetchMany($query, [$sociedad_rut]);
}
public function fetchByAgente(int $agente_id): array
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN agente_tipo at ON a.agente_tipo_id = at.id')
->where('at.agente = ?');
return $this->fetchMany($query, [$agente_id]);
}
public function fetchByTipo(int $tipo_agente_id): array
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN agente_tipo at ON a.agente_tipo_id = at.id')
->where('at.tipo = ?');
return $this->fetchMany($query, [$tipo_agente_id]);
}
public function fetchBySociedadAndTipo(int $sociedad_rut, int $tipo_agente_id): array
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN agente_tipo at ON a.agente_tipo_id = at.id')
->where('sociedad_rut = ? AND at.tipo = ?');
return $this->fetchMany($query, [$sociedad_rut, $tipo_agente_id]);
}
public function fetchBySociedadAndAgente(int $sociedad_rut, int $agente_id): array
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN agente_tipo at ON a.agente_tipo_id = at.id')
->where('sociedad_rut = ? AND at.agente = ?');
return $this->fetchMany($query, [$sociedad_rut, $agente_id]);
}
public function fetchBySociedadAndAgenteAndTipo(int $sociedad_rut, int $agente_id, int $tipo_agente_id): array
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN agente_tipo at ON a.agente_tipo_id = at.id')
->where('sociedad_rut = ? AND at.agente = ? AND at.tipo = ?');
return $this->fetchMany($query, [$sociedad_rut, $agente_id, $tipo_agente_id]);
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Incoviba\Repository\Inmobiliaria;
use Incoviba\Common\Define;
use Incoviba\Model;
use Incoviba\Repository;
class TipoAgente extends Repository\Tipo
{
public function __construct(Define\Connection $connection)
{
parent::__construct($connection);
$this->setTable('tipo_agente');
}
protected function getBlank(): Model\Inmobiliaria\TipoAgente
{
return new Model\Inmobiliaria\TipoAgente();
}
}