40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?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 {
|
|
public function do_edit(Request $request, Response $response, Filemanager $filemanager): Response {
|
|
$post = $request->getParsedBody();
|
|
$filename = 'aviso.yml';
|
|
$notificacion = $filemanager->folder('data')->load($filename);
|
|
if (!$notificacion) {
|
|
$notificacion = (object) [
|
|
'titulo' => '',
|
|
'contenido' => '',
|
|
'activo' => false
|
|
];
|
|
}
|
|
if (isset($post['titulo'])) {
|
|
$notificacion->titulo = trim($post['titulo']);
|
|
$notificacion->contenido = trim($post['contenido']);
|
|
}
|
|
if (isset($post['activo'])) {
|
|
$notificacion->activo = json_decode($post['activo']);
|
|
}
|
|
$status = $filemanager->folder('data')->save($filename, $notificacion);
|
|
|
|
$output = [
|
|
'informacion' => $post,
|
|
'editado' => $notificacion,
|
|
'estado' => ($status !== false) ? 'ok' : 'error'
|
|
];
|
|
$response->getBody()->write(json_encode($output));
|
|
return $response
|
|
->withHeader('Content-Type', 'application/json')
|
|
->withStatus(201);
|
|
}
|
|
}
|