Listado proyectos
This commit is contained in:
@ -8,7 +8,11 @@ use Incoviba\Model;
|
||||
|
||||
class Proyecto extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Inmobiliaria $inmobiliariaRepository, protected Direccion $direccionRepository)
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected Inmobiliaria $inmobiliariaRepository,
|
||||
protected Direccion $direccionRepository
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('proyecto');
|
||||
|
@ -14,12 +14,12 @@ class Elemento extends Ideal\Repository
|
||||
$this->setTable('tipo_elemento');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Proyecto\Elemento
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion', 'abreviacion', 'orden']));
|
||||
$map = new Implement\Repository\MapperParser(['descripcion', 'abreviacion', 'orden']);
|
||||
return $this->parseData(new Model\Proyecto\Elemento(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Proyecto\Elemento
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'abreviacion', 'orden'],
|
||||
@ -27,7 +27,7 @@ class Elemento extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Proyecto\Elemento
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'abreviacion', 'orden'], $new_data);
|
||||
}
|
||||
|
73
app/src/Repository/Proyecto/EstadoProyecto.php
Normal file
73
app/src/Repository/Proyecto/EstadoProyecto.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class EstadoProyecto extends Ideal\Repository
|
||||
{
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected Repository\Proyecto $proyectoRepository,
|
||||
protected TipoEstadoProyecto $tipoEstadoProyectoRepository
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('estado_proyecto');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Proyecto\EstadoProyecto
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('proyecto', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->proyectoRepository, 'fetchById'])
|
||||
->setArgs([$data['proyecto']])))
|
||||
->register('estado', (new Implement\Repository\Mapper())
|
||||
->setProperty('tipoEstadoProyecto')
|
||||
->setFunction(function($data) {
|
||||
return $this->tipoEstadoProyectoRepository->fetchById($data['estado']);
|
||||
}))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||
;
|
||||
return $this->parseData(new Model\Proyecto\EstadoProyecto(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Proyecto\EstadoProyecto
|
||||
{
|
||||
$model->id = $this->saveNew(['proyecto', 'estado', 'fecha'], [
|
||||
$model->proyecto()->id,
|
||||
$model->tipoEstadoProyecto()->id,
|
||||
$model->fecha->format('Y-m-d')
|
||||
]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Proyecto\EstadoProyecto
|
||||
{
|
||||
return $this->update($model, ['proyecto', 'estado', 'fecha'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `proyecto` = ?";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchCurrentByProyecto(int $proyecto_id): Model\Proyecto\EstadoProyecto
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT MAX(`id`) AS 'id', `proyecto` FROM `{$this->getTable()}` GROUP BY `proyecto`) e0 ON e0.`id` = a.`id`
|
||||
WHERE a.`proyecto` = ?";
|
||||
return $this->fetchOne($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchFirstByProyecto(int $proyecto_id): Model\Proyecto\EstadoProyecto
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT MIN(`id`) AS 'id', `proyecto` FROM `{$this->getTable()}` GROUP BY `proyecto`) e0 ON e0.`id` = a.`id`
|
||||
WHERE a.`proyecto` = ?";
|
||||
return $this->fetchOne($query, [$proyecto_id]);
|
||||
}
|
||||
}
|
31
app/src/Repository/Proyecto/Etapa.php
Normal file
31
app/src/Repository/Proyecto/Etapa.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Etapa extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('etapa_proyecto');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Proyecto\Etapa
|
||||
{
|
||||
$map = new Implement\Repository\MapperParser(['descripcion', 'orden']);
|
||||
return $this->parseData(new Model\Proyecto\Etapa(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Proyecto\Etapa
|
||||
{
|
||||
$model->id = $this->saveNew(['descripcion', 'orden'], [$model->descripcion, $model->orden]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Proyecto\Etapa
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'orden'], $new_data);
|
||||
}
|
||||
}
|
36
app/src/Repository/Proyecto/TipoEstadoProyecto.php
Normal file
36
app/src/Repository/Proyecto/TipoEstadoProyecto.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoProyecto extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Etapa $etapaRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_estado_proyecto');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Proyecto\TipoEstadoProyecto
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion', 'orden']))
|
||||
->register('etapa', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->etapaRepository->fetchById($data['etapa']);
|
||||
}));
|
||||
return $this->parseData(new Model\Proyecto\TipoEstadoProyecto(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Proyecto\TipoEstadoProyecto
|
||||
{
|
||||
$model->id = $this->saveNew(['descripcion', 'orden', 'etapa'], [$model->descripcion, $model->orden, $model->etapa->id]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Proyecto\TipoEstadoProyecto
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'orden', 'etapa'], $new_data);
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ class EstadoVenta extends Ideal\Repository
|
||||
$this->setTable('estado_venta');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Venta\EstadoVenta
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('venta', (new Implement\Repository\Mapper())
|
||||
@ -32,7 +32,7 @@ class EstadoVenta extends Ideal\Repository
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
|
||||
return $this->parseData(new Model\Venta\EstadoVenta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Venta\EstadoVenta
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['venta', 'estado', 'fecha'],
|
||||
@ -40,7 +40,7 @@ class EstadoVenta extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\EstadoVenta
|
||||
{
|
||||
return $this->update($model, ['venta', 'estado', 'fecha'], $new_data);
|
||||
}
|
||||
@ -50,7 +50,7 @@ class EstadoVenta extends Ideal\Repository
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `venta` = ?";
|
||||
return $this->fetchMany($query, [$venta_id]);
|
||||
}
|
||||
public function fetchCurrentByVenta(int $venta_id): Define\Model
|
||||
public function fetchCurrentByVenta(int $venta_id): Model\Venta\EstadoVenta
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
|
Reference in New Issue
Block a user