Merge branch 'master' of https://gitlab.deblan.org/deblan/lpwd-php-portfolio
This commit is contained in:
commit
943a276820
|
@ -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) {
|
||||
|
|
27
project.php
27
project.php
|
@ -56,6 +56,33 @@ $comments = getCommentsByProject($id);
|
|||
|
||||
<h2>Commentaires</h2>
|
||||
|
||||
<?php if (count($comments)): ?>
|
||||
<?php foreach ($comments as $comment): ?>
|
||||
<p>Posté par : <?php echo $comment['name'] ?></p>
|
||||
<p>Email : <?php echo $comment['email'] ?></p>
|
||||
<p>Site web : <?php echo $comment['website'] ?></p>
|
||||
<span>Commentaire :</span>
|
||||
<p class="comment-content"><?php echo $comment['content'] ?></p>
|
||||
<p class="date"><?php echo $comment['date'] ?></p>
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
|
||||
|
||||
|
||||
<form method="post" action="lib/comment.php">
|
||||
<label for="name">Nom :</label>
|
||||
<input type="text" name="name" id="name">
|
||||
<label for="email">Email :</label>
|
||||
<input type="text" name="email" id="email">
|
||||
<label for="website">Votre site web</label>
|
||||
<input type="text" name="website" id="website">
|
||||
<label for="content">Votre message</label>
|
||||
<input type="text" name="content" id="content">
|
||||
<input type="hidden" name="project_id" value="<?php echo $id ?>">
|
||||
<input type="submit" value="Envoyer">
|
||||
</form>
|
||||
|
||||
|
||||
<!--
|
||||
Afficher la liste des commentaires
|
||||
|
||||
|
|
Loading…
Reference in a new issue