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

46 lines
1.5 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 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 {
$post = $request->getParsedBody();
$filename = 'notificacion.yml';
$notificacion = $filemanager->load($filename);
if (!$notificacion) {
$notificacion = (object) [
'title' => '',
'text' => '',
'active' => false
];
}
$notificacion->title = $post['title'];
$notificacion->text = $post['text'];
$notificacion->active = (isset($post['active']) and $post['active'] == 'on') ? true : false;
$filemanager->save($filename, $notificacion);
return $response
->withHeader('Location', implode('/', [
$container->get('urls.base'),
'admin',
'notificacion'
]))
->withStatus(302);
}
}