v0.8.0-rc

This commit is contained in:
2020-03-27 02:59:53 -03:00
parent 00f9a10cbf
commit 723040358b
51 changed files with 792 additions and 492 deletions

View File

@ -3,43 +3,36 @@ namespace ProVM\NotariaRaby\Common\Controller\Web\Admin;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Slim\Views\Blade as View;
use ProVM\Common\Service\Filemanager;
class Notificacion {
public function __invoke(Request $request, Response $response, View $view, Filemanager $filemanager): Response {
$filename = 'notificacion.yml';
$notificacion = $filemanager->load($filename);
if (!$notificacion) {
$notificacion = (object) [
'title' => '',
'text' => '',
'active' => false
];
}
return $view->render($response, 'admin.notificacion.show', compact('notificacion'));
}
public function do_edit(Request $request, Response $response, View $view, Filemanager $filemanager): Response {
public function do_edit(Request $request, Response $response, Filemanager $filemanager): Response {
$post = $request->getParsedBody();
$filename = 'notificacion.yml';
$notificacion = $filemanager->load($filename);
$filename = 'aviso.yml';
$notificacion = $filemanager->folder('data')->load($filename);
if (!$notificacion) {
$notificacion = (object) [
'title' => '',
'text' => '',
'active' => false
'titulo' => '',
'contenido' => '',
'activo' => false
];
}
$notificacion->title = $post['title'];
$notificacion->text = $post['text'];
$notificacion->active = (isset($post['active']) and $post['active'] == 'on') ? true : false;
$filemanager->save($filename, $notificacion);
if (isset($post['titulo'])) {
$notificacion->titulo = trim($post['titulo']);
$notificacion->contenido = trim($post['contenido']);
}
if (isset($post['activo'])) {
$notificacion->activo = json_decode($post['activo']);
}
$filemanager->folder('data')->save($filename, $notificacion);
$output = [
'informacion' => $post,
'editado' => $notificacion
];
$response->getBody()->write(json_encode($output));
return $response
->withHeader('Location', implode('/', [
$container->get('urls.base'),
'admin',
'notificacion'
]))
->withStatus(302);
->withHeader('Content-Type', 'application/json')
->withStatus(201);
}
}