From 672ca490464d39bda9574e712c3aeead4bc49d48 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 28 Jan 2016 11:22:33 +0100 Subject: [PATCH 1/2] typo --- lib/project.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/project.php b/lib/project.php index 228f506..b23d125 100644 --- a/lib/project.php +++ b/lib/project.php @@ -10,11 +10,11 @@ function getProjects($page = 1, $limit = 5) { if (!is_integer($page)) { - throw new InvalidArgumentException('The argument "page" must be an interger.'); + throw new InvalidArgumentException('The argument "page" must be an integer.'); } if (!is_integer($limit)) { - throw new InvalidArgumentException('The argument "limit" must be an interger.'); + throw new InvalidArgumentException('The argument "limit" must be an integer.'); } $from = ($page - 1) * $limit; @@ -40,7 +40,7 @@ function getProjects($page = 1, $limit = 5) function getProject($id) { if (!is_integer($id)) { - throw new InvalidArgumentException('The argument "id" must be an interger.'); + throw new InvalidArgumentException('The argument "id" must be an integer.'); } $pdo = getDatabaseConnection(); @@ -61,7 +61,7 @@ function getProject($id) function getProjectNumberOfPages($maxPerPage) { if (!is_integer($maxPerPage)) { - throw new InvalidArgumentException('The argument "maxPerPage" must be an interger.'); + throw new InvalidArgumentException('The argument "maxPerPage" must be an integer.'); } $pdo = getDatabaseConnection(); @@ -98,11 +98,11 @@ function getCommentsByProject($id) function getProjectsPager($page, $numberOfPages) { if (!is_integer($page)) { - throw new InvalidArgumentException('The argument "page" must be an interger.'); + throw new InvalidArgumentException('The argument "page" must be an integer.'); } if (!is_integer($numberOfPages)) { - throw new InvalidArgumentException('The argument "numberOfPages" must be an interger.'); + throw new InvalidArgumentException('The argument "numberOfPages" must be an integer.'); } $pages = []; From 402595a678366946bf124308d51b3c4611478e34 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 28 Jan 2016 12:06:35 +0100 Subject: [PATCH 2/2] comments --- lib/project.php | 29 ++++++++++++++++++++++++++++- project.php | 9 +++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/project.php b/lib/project.php index b23d125..87d170a 100644 --- a/lib/project.php +++ b/lib/project.php @@ -86,7 +86,34 @@ function getCommentsByProject($id) // À réaliser } -// Prévoir une fonction pour enregistrer un commentaire +/** + * Enregistre un nouveau commentaire + * + * @param string $name Nom de l'auteur + * @param string $email Email de l'auteur + * @param string $website Site web de l'auteur + * @param string $content Contenu du commentaire + * @param DateTime $date Date du commentaire + * @param int $projectId L'id du projet associé + */ +function createComment($name, $email, $website, $content, DateTime $date, $projectId) +{ + $pdo = getDatabaseConnection(); + + $query = $pdo->prepare( + 'insert into comment(name, email, website, content, date, project_id) + value(:name, :email, :website, :content, :date, :project_id)' + ); + + $query->execute([ + ':name' => $name, + ':email' => $email, + ':website' => $website, + ':content' => $content, + ':date' => $date->format('Y-m-d H:i:s'), + ':project_id' => $projectId, + ]); +} /** * Génère et retourne une pagination diff --git a/project.php b/project.php index 080545f..fdf96be 100644 --- a/project.php +++ b/project.php @@ -17,6 +17,15 @@ if (false === $project) { die; } +// createComment( +// 'Simon', +// 'simon@deblan.fr', +// 'https://www.deblan.io/', +// 'Mon second super commentaire !', +// new DateTime('now'), +// $id +// ); + $comments = getCommentsByProject($id); ?>