|
|
|
@ -4,8 +4,10 @@ declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Silex\Controller;
|
|
|
|
|
|
|
|
|
|
use DateTime;
|
|
|
|
|
use Silex\DI\DI;
|
|
|
|
|
use Silex\Http\HttpResponse;
|
|
|
|
|
use Silex\Model\Comment;
|
|
|
|
|
use Silex\Util\Pagination;
|
|
|
|
|
|
|
|
|
|
class UserController
|
|
|
|
@ -38,13 +40,15 @@ class UserController
|
|
|
|
|
if($news->getSlug() !== $params['slug']){
|
|
|
|
|
HttpResponse::redirect($di->getRouter()->url($news->getSlugRedirect()));
|
|
|
|
|
}
|
|
|
|
|
return new HttpResponse(200, 'newsView', ['news' => $news]);
|
|
|
|
|
$comments = $di->getCommentGateway()->getByNewsId($newsId);
|
|
|
|
|
return new HttpResponse(200, 'newsView', ['news' => $news, 'comments' => $comments]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function viewPostComments(DI $di, array $params): HttpResponse
|
|
|
|
|
public function comment(DI $di, array $params): void
|
|
|
|
|
{
|
|
|
|
|
$newsId = intval($params['id']);
|
|
|
|
|
$comments = $di->getCommentGateway()->getByNewsId($newsId);
|
|
|
|
|
return new HttpResponse(200, 'comment', ['comments' => $comments]);
|
|
|
|
|
$news = $di->getNewsGateway()->getById($newsId);
|
|
|
|
|
$di->getCommentGateway()->insert(new Comment(-1, $newsId, new DateTime(), $_POST['content'], $di->getSecurity()->getCurrentUserId()));
|
|
|
|
|
HttpResponse::redirect($di->getRouter()->url($news->getSlugRedirect()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|