Files
This commit is contained in:
39
common/Controller/Sociedades.php
Normal file
39
common/Controller/Sociedades.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\API\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Incoviba\API\Common\Define\Controller\Json;
|
||||
use Incoviba\API\Common\Factory\Model as Factory;
|
||||
use Incoviba\Inmobiliaria\TipoSociedad;
|
||||
|
||||
class Sociedades {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$sociedades = $factory->find(TipoSociedad::class)->array();
|
||||
$base_url = str_replace('/sociedades', '{URL}', $request->getUri());
|
||||
array_walk($sociedades, function (&$item) use ($base_url) {
|
||||
$link = [
|
||||
'rel' => 'sociedad',
|
||||
'title' => $item['descripcion'],
|
||||
'href' => str_replace('{URL}', "/sociedad/{$item['id']}", $base_url)
|
||||
];
|
||||
$item['link'] = $link;
|
||||
});
|
||||
return $this->withJson($response, compact('sociedades'));
|
||||
}
|
||||
public function show(Request $request, Response $response, Factory $factory, $sociedad_id): Response {
|
||||
$sociedad = $factory->find(TipoSociedad::class)->one($sociedad_id);
|
||||
$output = [
|
||||
'input' => $sociedad_id,
|
||||
'sociedad' => $sociedad->toArray(),
|
||||
'link' => [
|
||||
'rel' => 'sociedades',
|
||||
'title' => 'Sociedades',
|
||||
'href' => str_replace("/sociedad/{$sociedad_id}", '/sociedades', $request->getUri())
|
||||
]
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user