From 402595a678366946bf124308d51b3c4611478e34 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 28 Jan 2016 12:06:35 +0100 Subject: [PATCH] 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); ?>