2023-07-28 16:22:20 -04:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Service;
|
|
|
|
|
2023-10-13 10:45:21 -03:00
|
|
|
use Incoviba\Common\Implement;
|
2023-07-28 16:22:20 -04:00
|
|
|
use Incoviba\Repository;
|
2023-10-13 10:45:21 -03:00
|
|
|
use Incoviba\Model;
|
2023-07-28 16:22:20 -04:00
|
|
|
|
|
|
|
class Proyecto
|
|
|
|
{
|
2023-10-13 10:45:21 -03:00
|
|
|
public function __construct(
|
|
|
|
protected Repository\Proyecto $proyectoRepository,
|
|
|
|
protected Repository\Proyecto\EstadoProyecto $estadoProyecto
|
|
|
|
) {}
|
2025-04-03 13:15:56 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string|array|null $orderBy
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getAll(null|string|array $orderBy = null): array
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return array_map([$this, 'process'], $this->proyectoRepository->fetchAll($orderBy));
|
|
|
|
} catch (Implement\Exception\EmptyResult) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function getVendibles(null|string|array $orderBy = null): array
|
2023-07-28 16:22:20 -04:00
|
|
|
{
|
2025-04-03 13:15:56 -03:00
|
|
|
return $this->proyectoRepository->fetchAllActive($orderBy);
|
2023-07-28 16:22:20 -04:00
|
|
|
}
|
2023-11-22 19:08:19 -03:00
|
|
|
public function getEscriturando(): array
|
|
|
|
{
|
|
|
|
return $this->proyectoRepository->fetchAllEscriturando();
|
|
|
|
}
|
2025-04-03 17:22:38 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $proyecto_id
|
|
|
|
* @return Model\Proyecto
|
|
|
|
* @throws Implement\Exception\EmptyResult
|
|
|
|
*/
|
2023-11-23 00:53:49 -03:00
|
|
|
public function getById(int $proyecto_id): Model\Proyecto
|
2023-10-13 10:45:21 -03:00
|
|
|
{
|
2023-11-23 00:53:49 -03:00
|
|
|
return $this->process($this->proyectoRepository->fetchById($proyecto_id));
|
2023-10-13 10:45:21 -03:00
|
|
|
}
|
2023-11-23 00:53:49 -03:00
|
|
|
public function getByName(string $name): Model\Proyecto
|
|
|
|
{
|
|
|
|
return $this->process($this->proyectoRepository->fetchByName($name));
|
|
|
|
}
|
2024-01-17 11:10:56 -03:00
|
|
|
public function getByInmobiliaria(int $inmobiliaria_rut): array
|
|
|
|
{
|
|
|
|
return array_map([$this, 'process'], $this->proyectoRepository->fetchByInmobiliaria($inmobiliaria_rut));
|
|
|
|
}
|
2023-11-30 18:40:15 -03:00
|
|
|
|
|
|
|
protected function process(Model\Proyecto $proyecto): Model\Proyecto
|
2023-10-13 10:45:21 -03:00
|
|
|
{
|
|
|
|
$proyecto->addFactory('estados', (new Implement\Repository\Factory())
|
|
|
|
->setCallable([$this->estadoProyecto, 'fetchByProyecto'])
|
|
|
|
->setArgs([$proyecto->id]));
|
|
|
|
$proyecto->addFactory('currentEstado', (new Implement\Repository\Factory())
|
|
|
|
->setCallable([$this->estadoProyecto, 'fetchCurrentByProyecto'])
|
|
|
|
->setArgs([$proyecto->id]));
|
|
|
|
return $proyecto;
|
|
|
|
}
|
2023-07-28 16:22:20 -04:00
|
|
|
}
|