Files
api/src/Mapper/ProyectoAgente.php
2023-06-26 10:49:25 -04:00

42 lines
1.7 KiB
PHP

<?php
namespace Incoviba\Mapper;
use Incoviba\Model\Model;
use Incoviba\Model\Proyecto\ProyectoAgente as AgenteModel;
class ProyectoAgente extends Mapper
{
protected string $table = 'proyecto_agente';
protected function load(bool|array $row, bool $lazy = false): AgenteModel|bool
{
$model = new AgenteModel();
$model->id = $row['id'];
$model->proyecto = $this->getMapper(Proyecto::class)->fetchById($row['proyecto']);
$model->agenteTipo = $this->getMapper(AgenteTipo::class)->fetchById($row['agente']);
$model->fecha = new \DateTimeImmutable($row['fecha']);
$model->comision = $row['comision'];
return $model;
}
public function save(Model $model): bool
{
// TODO: Implement save() method.
}
public function fetchOperadoresVigenteByProyecto(int $proyecto_id): array
{
$qb = $this->connection->createQueryBuilder()
->select('pa.*')
->from($this->table, 'pa')
->innerJoin('pa', 'agente_tipo', 'at', 'at.id = pa.agente')
->innerJoin('at', 'tipo_agente', 'ta', 'ta.id = at.tipo')
->innerJoin('pa', '(SELECT e1.* FROM estado_proyecto_agente e1 JOIN (SELECT MAX(id) AS id, agente FROM estado_proyecto_agente GROUP BY agente) e0 ON e0.id = e1.id)', 'ep', 'ep.agente = pa.id')
->innerJoin('ep', 'tipo_estado_proyecto_agente', 'tep', 'tep.id = ep.tipo')
->where('pa.proyecto = ?')
->andWhere('ta.descripcion = ?')
->andWhere('tep.descripcion = ?');
return array_map([$this, 'load'], $this->connection->executeQuery($qb, [$proyecto_id, 'operador', 'vigente'])->fetchAllAssociative());
}
}