diff --git a/common/Controller/Web/Admin/Documentos.php b/common/Controller/Web/Admin/Documentos.php index c72d730..0b19b05 100644 --- a/common/Controller/Web/Admin/Documentos.php +++ b/common/Controller/Web/Admin/Documentos.php @@ -4,9 +4,31 @@ namespace ProVM\NotariaRaby\Common\Controller\Web\Admin; use Psr\Container\ContainerInterface as Container; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ResponseInterface as Response; +use Slim\Views\Blade as View; +use Carbon\Carbon; use ProVM\Common\Service\Filemanager; class Documentos { + public function __invoke(Request $request, Response $response, Container $container, View $view, $tipo): Response { + $glob = implode(DIRECTORY_SEPARATOR, [ + $container->get('folders.upload'), + $tipo . '*.pdf' + ]); + $files = glob($glob); + $archivos = []; + foreach ($files as $filename) { + $file = new \SplFileInfo($filename); + $archivos []= $file; + } + $titulo = $tipo; + $months = (object) ['full' => [], 'short' => []]; + $m = Carbon::createFromDate(0, 1, 1); + for ($i = 0; $i < 12; $i ++) { + $months->full []= ucwords($m->copy()->addMonths($i)->locale('es_ES')->isoFormat('MMMM')); + $months->short []= ucwords($m->copy()->addMonths($i)->locale('es_ES')->isoFormat('MMM')); + } + return $view->render($response, 'admin.archivos.list', compact('titulo', 'archivos', 'months')); + } public function upload(Request $request, Response $response, Filemanager $filemanager, Container $container): Response { $post = $request->getParsedBody(); $files = $request->getUploadedFiles(); @@ -33,4 +55,21 @@ class Documentos { ->withHeader('Content-Type', 'application/json') ->withStatus(201); } + public function delete(Request $request, Response $response, Container $container): Response { + $post = $request->getParsedBody(); + $filename = implode(DIRECTORY_SEPARATOR, [ + $container->get('folders.upload'), + $post['archivo'] . '.pdf' + ]); + $status = unlink($filename); + $output = [ + 'informacion' => $post, + 'estado' => $status, + 'archivo' => $filename + ]; + $response->getBody()->write(json_encode($output)); + return $response + ->withHeader('Content-Type', 'application/json') + ->withStatus(201); + } } diff --git a/common/Controller/Web/Documentos.php b/common/Controller/Web/Documentos.php new file mode 100644 index 0000000..1f50fd5 --- /dev/null +++ b/common/Controller/Web/Documentos.php @@ -0,0 +1,25 @@ +get('folders.upload'), + $documento . '.pdf' + ]); + $existe = file_exists($filename); + $output = [ + 'informacion' => $documento, + 'archivo' => $filename, + 'existe' => $existe + ]; + $response->getBody()->write(json_encode($output)); + return $response + ->withHeader('Content-Type', 'application/json') + ->withStatus(201); + } +} diff --git a/public/assets/styles/home.css b/public/assets/styles/home.css index ca6f9c6..656d336 100644 --- a/public/assets/styles/home.css +++ b/public/assets/styles/home.css @@ -129,7 +129,7 @@ #indice .img, #indice .img img { max-height: 20rem !important; - min-height: 10rem !important; + min-height: 20rem !important; } #indice .contenido { padding-top: 5rem !important; diff --git a/resources/routes/web/admin/documentos.php b/resources/routes/web/admin/documentos.php index 625887e..199f9e4 100644 --- a/resources/routes/web/admin/documentos.php +++ b/resources/routes/web/admin/documentos.php @@ -2,5 +2,7 @@ use ProVM\NotariaRaby\Common\Controller\Web\Admin\Documentos; $app->group('/documentos', function($app) { + $app->post('/delete', [Documentos::class, 'delete']); + $app->get('/{tipo}', Documentos::class); $app->post('[/]', [Documentos::class, 'upload']); }); diff --git a/resources/routes/web/documentos.php b/resources/routes/web/documentos.php new file mode 100644 index 0000000..3b4170b --- /dev/null +++ b/resources/routes/web/documentos.php @@ -0,0 +1,6 @@ +group('/documentos', function($app) { + $app->get('/existe/{documento}', [Documentos::class, 'existe']); +}); diff --git a/resources/views/admin/archivos/list.blade.php b/resources/views/admin/archivos/list.blade.php new file mode 100644 index 0000000..7473971 --- /dev/null +++ b/resources/views/admin/archivos/list.blade.php @@ -0,0 +1,147 @@ +@extends('admin.layout.base') + +@section('page_content') +
Documento | ++ |
---|---|
+ + {{str_replace([$titulo, '_'], ['', ' '], $archivo->getBasename('.' . $archivo->getExtension()))}} + + | ++ + | +