|
|
@ -8,6 +8,7 @@ use DateTime;
|
|
|
|
use Silex\DI\DI;
|
|
|
|
use Silex\DI\DI;
|
|
|
|
use Silex\Http\HttpResponse;
|
|
|
|
use Silex\Http\HttpResponse;
|
|
|
|
use Silex\Model\Comment;
|
|
|
|
use Silex\Model\Comment;
|
|
|
|
|
|
|
|
use Silex\Util\CommentCounter;
|
|
|
|
use Silex\Util\Pagination;
|
|
|
|
use Silex\Util\Pagination;
|
|
|
|
use Silex\Validation\CommentValidation;
|
|
|
|
use Silex\Validation\CommentValidation;
|
|
|
|
use Silex\Validation\NewsValidation;
|
|
|
|
use Silex\Validation\NewsValidation;
|
|
|
@ -26,7 +27,7 @@ class VisitorController {
|
|
|
|
|
|
|
|
|
|
|
|
$page = intval($params['page'] ?? 1);
|
|
|
|
$page = intval($params['page'] ?? 1);
|
|
|
|
$total = $gw->getCount();
|
|
|
|
$total = $gw->getCount();
|
|
|
|
|
|
|
|
|
|
|
|
$nbPages = Pagination::getNbPages($total, self::PER_PAGE);
|
|
|
|
$nbPages = Pagination::getNbPages($total, self::PER_PAGE);
|
|
|
|
if(!empty($_GET['dateDeb']) && !empty($_GET['dateFin']) && NewsValidation::isValidDate($_GET,$errors)) {
|
|
|
|
if(!empty($_GET['dateDeb']) && !empty($_GET['dateFin']) && NewsValidation::isValidDate($_GET,$errors)) {
|
|
|
|
$news = $gw->getLike($_GET['dateDeb'], $_GET['dateFin'], $page , self::PER_PAGE);
|
|
|
|
$news = $gw->getLike($_GET['dateDeb'], $_GET['dateFin'], $page , self::PER_PAGE);
|
|
|
@ -37,7 +38,7 @@ class VisitorController {
|
|
|
|
if ($user !== null) {
|
|
|
|
if ($user !== null) {
|
|
|
|
$nbCommentsByUser = $gwc->getCommentNumberFromUser($user->getId());
|
|
|
|
$nbCommentsByUser = $gwc->getCommentNumberFromUser($user->getId());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$nbCommentsByUser = 0;
|
|
|
|
$nbCommentsByUser = $_COOKIE['comments'] ?? '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new HttpResponse(200, 'home', ['news' => $news, 'page' => $page, 'nbPages' => $nbPages, 'nbComments' => $nbComments, 'nbCommentsByUser' => $nbCommentsByUser, 'errors' => $errors]);
|
|
|
|
return new HttpResponse(200, 'home', ['news' => $news, 'page' => $page, 'nbPages' => $nbPages, 'nbComments' => $nbComments, 'nbCommentsByUser' => $nbCommentsByUser, 'errors' => $errors]);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -76,6 +77,7 @@ class VisitorController {
|
|
|
|
$comment->setAuthorName($_POST['name']);
|
|
|
|
$comment->setAuthorName($_POST['name']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$di->getCommentGateway()->insert($comment);
|
|
|
|
$di->getCommentGateway()->insert($comment);
|
|
|
|
|
|
|
|
CommentCounter::incrementCommentCounter();
|
|
|
|
HttpResponse::redirect($di->getRouter()->url($news->getSlugRedirect()));
|
|
|
|
HttpResponse::redirect($di->getRouter()->url($news->getSlugRedirect()));
|
|
|
|
exit();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|