Files
raby/common/Controller/Web/Admin/Notificacion.php

39 lines
1.2 KiB
PHP
Raw Normal View History

2020-03-22 17:25:11 -03:00
<?php
namespace ProVM\NotariaRaby\Common\Controller\Web\Admin;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use ProVM\Common\Service\Filemanager;
class Notificacion {
2020-03-27 02:59:53 -03:00
public function do_edit(Request $request, Response $response, Filemanager $filemanager): Response {
2020-03-22 17:25:11 -03:00
$post = $request->getParsedBody();
2020-03-27 02:59:53 -03:00
$filename = 'aviso.yml';
$notificacion = $filemanager->folder('data')->load($filename);
2020-03-22 17:25:11 -03:00
if (!$notificacion) {
$notificacion = (object) [
2020-03-27 02:59:53 -03:00
'titulo' => '',
'contenido' => '',
'activo' => false
2020-03-22 17:25:11 -03:00
];
}
2020-03-27 02:59:53 -03:00
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));
2020-03-22 17:25:11 -03:00
return $response
2020-03-27 02:59:53 -03:00
->withHeader('Content-Type', 'application/json')
->withStatus(201);
2020-03-22 17:25:11 -03:00
}
}