Ajoute la vérification des dates
This commit is contained in:
@@ -10,6 +10,7 @@ use Silex\Http\HttpResponse;
|
|||||||
use Silex\Model\Comment;
|
use Silex\Model\Comment;
|
||||||
use Silex\Util\Pagination;
|
use Silex\Util\Pagination;
|
||||||
use Silex\Validation\CommentValidation;
|
use Silex\Validation\CommentValidation;
|
||||||
|
use Silex\Validation\NewsValidation;
|
||||||
|
|
||||||
class VisitorController {
|
class VisitorController {
|
||||||
|
|
||||||
@@ -17,6 +18,8 @@ class VisitorController {
|
|||||||
|
|
||||||
public function index(DI $di, array $params): HttpResponse
|
public function index(DI $di, array $params): HttpResponse
|
||||||
{
|
{
|
||||||
|
$errors = [];
|
||||||
|
|
||||||
$gw = $di->getNewsGateway();
|
$gw = $di->getNewsGateway();
|
||||||
$gwc = $di->getCommentGateway();
|
$gwc = $di->getCommentGateway();
|
||||||
$user = $di->getSecurity()->getCurrentUser();
|
$user = $di->getSecurity()->getCurrentUser();
|
||||||
@@ -25,7 +28,7 @@ class VisitorController {
|
|||||||
$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'])) {
|
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);
|
||||||
} else {
|
} else {
|
||||||
$news = $gw->getPaginatedRecentNews($page , self::PER_PAGE);
|
$news = $gw->getPaginatedRecentNews($page , self::PER_PAGE);
|
||||||
@@ -36,7 +39,7 @@ class VisitorController {
|
|||||||
} else {
|
} else {
|
||||||
$nbCommentsByUser = 0;
|
$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
|
public function viewPost(DI $di, array $params): HttpResponse
|
||||||
|
@@ -22,4 +22,21 @@ final class NewsValidation
|
|||||||
$post['content'] = htmlspecialchars($post['content']);
|
$post['content'] = htmlspecialchars($post['content']);
|
||||||
return empty($errors);
|
return empty($errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function isValidDate(array &$get, array &$errors): bool
|
||||||
|
{
|
||||||
|
if(!isset($get['dateDeb']) || !isset($get['dateFin'])){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(strtotime($get['dateDeb']) === false){
|
||||||
|
$errors[] = 'Date début invalide';
|
||||||
|
}
|
||||||
|
if(strtotime($get['dateFin']) === false){
|
||||||
|
$errors[] = 'Date fin invalide';
|
||||||
|
}
|
||||||
|
if($get['dateDeb'] > $get['dateFin']){
|
||||||
|
$errors[] = 'Date début supérieur à date fin';
|
||||||
|
}
|
||||||
|
return empty($errors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
<?php require 'errors.php' ?>
|
||||||
<?php $params['title'] = 'Home';
|
<?php $params['title'] = 'Home';
|
||||||
$get = $_SERVER['QUERY_STRING'] ?? '';
|
$get = $_SERVER['QUERY_STRING'] ?? '';
|
||||||
?>
|
?>
|
||||||
|
Reference in New Issue
Block a user