diff --git a/lib/project.php b/lib/project.php index e8ca80d..2f9c6ad 100644 --- a/lib/project.php +++ b/lib/project.php @@ -37,6 +37,8 @@ function getProjects($page = 1, $limit = 5) * @param int $id id du projet * @return array|false Le projet */ + + function getProject($id) { if (!is_integer($id)) { @@ -72,7 +74,7 @@ function getProjectNumberOfPages($maxPerPage) $result = $query->fetch(); - return ceil($result['total'] / $maxPerPage); + return (int) ceil($result['total'] / $maxPerPage); } /** @@ -81,15 +83,55 @@ function getProjectNumberOfPages($maxPerPage) * @param int $id L'id du projet * @return array Les commentaires du projet */ + function getCommentsByProject($id) { - // À réaliser + $pdo = getDatabaseConnection(); + + $query = $pdo->prepare('select id, name, website, email, date, content from comment where project_id=:id'); + + $query->bindParam(':id', $id, PDO::PARAM_INT); + + $query->execute(); + + return $query->fetchAll(); } -// Prévoir une fonction pour enregistrer un commentaire +function createComment($name,$website,$email, DateTime $date, $content, $project_id) +{ + $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' => $project_id + ]); + +} + +/** + * Génère et retourne une pagination + * + * @param int $page La page courrante + * @param int $numberOfPages Le nombre de pages + * @return array Les pages + */ function getProjectsPager($page, $numberOfPages) { + if (!is_integer($page)) { + throw new InvalidArgumentException('The argument "page" must be an interger.'); + } + + if (!is_integer($numberOfPages)) { + throw new InvalidArgumentException('The argument "numberOfPages" must be an interger.'); + } + $pages = []; if ($numberOfPages > 1) { diff --git a/project.php b/project.php index 080545f..1c69a2d 100644 --- a/project.php +++ b/project.php @@ -56,6 +56,33 @@ $comments = getCommentsByProject($id);

Commentaires

+ + +

Posté par :

+

Email :

+

Site web :

+ Commentaire : +

+

+ + + + + +
+ + + + + + + + + + +
+ +