ajout commentaire
This commit is contained in:
parent
64cbb94829
commit
2b91fb80ac
|
@ -58,14 +58,14 @@ Petit plus
|
||||||
|
|
||||||
Les étudiants qui me proposeront une correction via des `pull-request`
|
Les étudiants qui me proposeront une correction via des `pull-request`
|
||||||
auront 1 point supplémentaire sur la note finale. Les intéressés devront
|
auront 1 point supplémentaire sur la note finale. Les intéressés devront
|
||||||
créer un compte sur [Gitlab](https://gitlab.deblan.org). Je les ajouterai
|
créer un compte sur [Gitlab](https://gitnet.fr). Je les ajouterai
|
||||||
au dépôt et vous me transmettrez votre travail dans une branche portant
|
au dépôt et vous me transmettrez votre travail dans une branche portant
|
||||||
votre nom : `nom-prenom`.
|
votre nom : `nom-prenom`.
|
||||||
|
|
||||||
#### Installation du projet
|
#### Installation du projet
|
||||||
|
|
||||||
```
|
```
|
||||||
$ git clone git@gitlab.deblan.org:deblan/lpwd-php-portfolio.git
|
$ git clone git@gitnet.fr:deblan/lpwd-php-portfolio.git
|
||||||
$ git branch nom-prenom # à modifier
|
$ git branch nom-prenom # à modifier
|
||||||
$ git checkout nom-prenom
|
$ git checkout nom-prenom
|
||||||
$ ... modifications ...
|
$ ... modifications ...
|
||||||
|
|
|
@ -78,12 +78,29 @@ function getProjectNumberOfPages($maxPerPage)
|
||||||
/**
|
/**
|
||||||
* Returne les commentaires d'un projet
|
* Returne les commentaires d'un projet
|
||||||
*
|
*
|
||||||
* @param int $id L'id du projet
|
* @param int $projectId L'id du projet
|
||||||
* @return array Les commentaires du projet
|
* @return array Les commentaires du projet
|
||||||
*/
|
*/
|
||||||
function getCommentsByProject($id)
|
function getCommentsByProject($projectId)
|
||||||
{
|
{
|
||||||
// À réaliser
|
$pdo = getDatabaseConnection();
|
||||||
|
|
||||||
|
$query = $pdo->prepare('select * from comment where project_id=:project_id');
|
||||||
|
|
||||||
|
$query->bindParam(':project_id', $projectId, PDO::PARAM_INT);
|
||||||
|
|
||||||
|
$query->execute();
|
||||||
|
|
||||||
|
$comments = $query->fetchAll();
|
||||||
|
|
||||||
|
foreach ($comments as $index => $comment) {
|
||||||
|
$comment['avatar'] = getGravatar($comment['email']);
|
||||||
|
$comment['date'] = new DateTime($comment['date']);
|
||||||
|
|
||||||
|
$comments[$index] = $comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -178,3 +195,17 @@ function getProjectsPager($page, $numberOfPages)
|
||||||
|
|
||||||
return $pages;
|
return $pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne une url gravatar en fonction d'un email
|
||||||
|
*
|
||||||
|
* @param string $email
|
||||||
|
* @param int $size
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getGravatar($email, $size = 50)
|
||||||
|
{
|
||||||
|
$hash = md5(strtolower(trim($email)));
|
||||||
|
|
||||||
|
return 'http://www.gravatar.com/avatar/'.$hash.'?r=g&s='.$size;
|
||||||
|
}
|
||||||
|
|
82
project.php
82
project.php
|
@ -17,14 +17,40 @@ if (false === $project) {
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
// createComment(
|
if (isset($_POST['name'], $_POST['email'], $_POST['website'], $_POST['content'])) {
|
||||||
// 'Simon',
|
$name = trim($_POST['name']);
|
||||||
// 'simon@deblan.fr',
|
$email = trim($_POST['email']);
|
||||||
// 'https://www.deblan.io/',
|
$website = trim($_POST['website']);
|
||||||
// 'Mon second super commentaire !',
|
$content = trim($_POST['content']);
|
||||||
// new DateTime('now'),
|
|
||||||
// $id
|
$valid = true;
|
||||||
// );
|
|
||||||
|
foreach ([$name, $email, $content] as $field) {
|
||||||
|
if (empty($field)) {
|
||||||
|
$valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($valid) {
|
||||||
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($valid) {
|
||||||
|
createComment(
|
||||||
|
$name,
|
||||||
|
$email,
|
||||||
|
$website,
|
||||||
|
$content,
|
||||||
|
new DateTime('now'),
|
||||||
|
$id
|
||||||
|
);
|
||||||
|
|
||||||
|
header('Location: project.php?id='.$id);
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$comments = getCommentsByProject($id);
|
$comments = getCommentsByProject($id);
|
||||||
|
|
||||||
|
@ -63,8 +89,48 @@ $comments = getCommentsByProject($id);
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
<h2>Commentaires</h2>
|
<h2>Commentaires</h2>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<form action="" method="POST">
|
||||||
|
<p>
|
||||||
|
<label for="form-name">Nom</label>
|
||||||
|
<input name="name" required id="form-name" type="text" />
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label for="form-mail">Email</label>
|
||||||
|
<input name="email" required id="form-mail" type="mail" />
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<label for="form-website">Site web</label>
|
||||||
|
<input name="website" id="form-website" type="website" />
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<textarea name="content" required rows="10" cols="30"></textarea>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<input type="submit" value="Go go go!" />
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php foreach ($comments as $comment): ?>
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
<img src="<?php echo $comment['avatar'] ?>" alt="" />
|
||||||
|
<?php echo $comment['name'] ?>,
|
||||||
|
posté le <?php echo $comment['date']->format('d/m/Y à H:i') ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<?php echo $comment['content'] ?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</section>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Afficher la liste des commentaires
|
Afficher la liste des commentaires
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue