This commit is contained in:
Juan Pablo Vial
2023-09-07 23:03:21 -03:00
parent 59825259b6
commit fa15da1ee2
40 changed files with 1787 additions and 71 deletions

View File

@ -0,0 +1,28 @@
<?php
namespace Incoviba\Controller;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Repository;
use Incoviba\Model;
class Provincias
{
public function comunas(ServerRequestInterface $request, ResponseInterface $response, Repository\Comuna $comunaRepository, int $provincia_id): ResponseInterface
{
$output = [
'provincia_id' => $provincia_id,
'comunas' => []
];
try {
$comunas = $comunaRepository->fetchByProvincia($provincia_id);
usort($comunas, function(Model\Comuna $a, Model\Comuna $b) {
return strcmp($a->descripcion, $b->descripcion);
});
$output['comunas'] = $comunas;
} catch (EmptyResult) {}
$response->getBody()->write(json_encode($output));
return $response->withHeader('Content-Type', 'application/json');
}
}