Affiche un extrait de news sur la page d'accueil

This commit is contained in:
2022-11-22 09:40:36 +01:00
parent b4f9d31c2e
commit cd27eea76e
2 changed files with 17 additions and 2 deletions

View File

@@ -10,6 +10,8 @@ use Silex\Model\News;
class NewsGateway
{
private const EXCERPT_LENGTH = 180;
private PDO $pdo;
public function __construct(PDO $pdo)
@@ -22,7 +24,7 @@ class NewsGateway
*/
public function getPaginatedRecentNews(int $page = 1, int $limit = 10): array
{
$req = $this->pdo->prepare('SELECT * FROM news ORDER BY publication_date DESC LIMIT :limit OFFSET :offset;');
$req = $this->pdo->prepare('SELECT title, LEFT(content, ' . self::EXCERPT_LENGTH . ') content, publication_date FROM news ORDER BY publication_date DESC LIMIT :limit OFFSET :offset;');
$req->bindValue('limit', $limit, PDO::PARAM_INT);
$req->bindValue('offset', ($page - 1) * $limit, PDO::PARAM_INT);
if (!$req->execute()) {