Ajoute la vérification des dates

This commit is contained in:
cofrizot
2022-12-15 18:41:54 +01:00
parent 78c012bd33
commit a6ae685d26
3 changed files with 23 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ use Silex\Http\HttpResponse;
use Silex\Model\Comment;
use Silex\Util\Pagination;
use Silex\Validation\CommentValidation;
use Silex\Validation\NewsValidation;
class VisitorController {
@@ -17,6 +18,8 @@ class VisitorController {
public function index(DI $di, array $params): HttpResponse
{
$errors = [];
$gw = $di->getNewsGateway();
$gwc = $di->getCommentGateway();
$user = $di->getSecurity()->getCurrentUser();
@@ -25,7 +28,7 @@ class VisitorController {
$total = $gw->getCount();
$nbPages = Pagination::getNbPages($total, self::PER_PAGE);
if(!empty($_GET['dateDeb']) && !empty($_GET['dateFin'])) {
if(!empty($_GET['dateDeb']) && !empty($_GET['dateFin']) && NewsValidation::isValidDate($_GET,$errors)) {
$news = $gw->getLike($_GET['dateDeb'], $_GET['dateFin'], $page , self::PER_PAGE);
} else {
$news = $gw->getPaginatedRecentNews($page , self::PER_PAGE);
@@ -36,7 +39,7 @@ class VisitorController {
} else {
$nbCommentsByUser = 0;
}
return new HttpResponse(200, 'home', ['news' => $news, 'page' => $page, 'nbPages' => $nbPages, 'nbComments' => $nbComments, 'nbCommentsByUser' => $nbCommentsByUser]);
return new HttpResponse(200, 'home', ['news' => $news, 'page' => $page, 'nbPages' => $nbPages, 'nbComments' => $nbComments, 'nbCommentsByUser' => $nbCommentsByUser, 'errors' => $errors]);
}
public function viewPost(DI $di, array $params): HttpResponse