Merge branch 'master' of https://gitlab.deblan.org/deblan/lpwd-php-portfolio
This commit is contained in:
commit
73f83a653c
|
@ -43,7 +43,7 @@ Un commentaire est composé de :
|
|||
|
||||
La date est générée automatiquement.
|
||||
Tous les champs sont obligatoires à l'exception du site web.
|
||||
Il faudra afficher l'avatar de l'auteur en utilisant le service [gravatar](https://fr.gravatar.com/site/implement/images/php/). *Ne pas réutiliser ce code source merci ne vous génez par pour vous en inspirer.*
|
||||
Il faudra afficher l'avatar de l'auteur en utilisant le service [gravatar](https://fr.gravatar.com/site/implement/images/php/). *Ne pas réutiliser ce code source mais ne vous génez par pour vous en inspirer.*
|
||||
|
||||
Flux
|
||||
----
|
||||
|
|
40
index.php
40
index.php
|
@ -18,6 +18,7 @@ if ($page > $numberOfPages) {
|
|||
}
|
||||
|
||||
$projects = getProjects($page, $limit);
|
||||
$pager = getProjectsPager($page, $numberOfPages);
|
||||
|
||||
$prev = $page - 1;
|
||||
$next = $page + 1;
|
||||
|
@ -34,6 +35,18 @@ $next = $page + 1;
|
|||
</head>
|
||||
<body>
|
||||
<h1>Mon super portfolio</h1>
|
||||
|
||||
<?php if (count($pager) > 1): ?>
|
||||
<ul class="pager">
|
||||
<?php foreach ($pager as $p): ?>
|
||||
<li <?php if ($p['current'] === true): ?>class="active"<?php endif ?>>
|
||||
<a href="?page=<?php echo $p['page'] ?>">
|
||||
<?php echo $p['title'] ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
|
||||
<section>
|
||||
<?php foreach($projects as $project): ?>
|
||||
|
@ -62,22 +75,17 @@ $next = $page + 1;
|
|||
</article>
|
||||
<?php endforeach ?>
|
||||
</section>
|
||||
|
||||
<ul class="pagination-container">
|
||||
<?php if ($page != 1) { ?>
|
||||
<li><a href="index.php?page=1">Première page</a></li>
|
||||
<?php } ?>
|
||||
<li><a href="index.php?page=<?php echo $prev; ?>">Précédent</a></li>
|
||||
<li><a href=""></a></li>
|
||||
<li><a href="index.php?page=<?php echo $next; ?>">Suivant</a></li>
|
||||
</ul>
|
||||
|
||||
<!--
|
||||
Générer la pagination :
|
||||
|
||||
Première page | Précédent | 1 | 2 | 3 ... | Suivant | Dernière page
|
||||
|
||||
Mettre en avant la page courrante
|
||||
-->
|
||||
<?php if (count($pager) > 1): ?>
|
||||
<ul class="pager">
|
||||
<?php foreach ($pager as $p): ?>
|
||||
<li <?php if ($p['current'] === true): ?>class="active"<?php endif ?>>
|
||||
<a href="?page=<?php echo $p['page'] ?>">
|
||||
<?php echo $p['title'] ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* Retourne une liste de projets en fonction d'une pagination
|
||||
*
|
||||
* @param int $page La page courrante
|
||||
* @param int $limit Nombre de projet par page
|
||||
* @param int $limit Nombre de projets par page
|
||||
* @return array Les projets
|
||||
*/
|
||||
function getProjects($page = 1, $limit = 5)
|
||||
|
@ -79,7 +79,7 @@ function getProjectNumberOfPages($maxPerPage)
|
|||
* Returne les commentaires d'un projet
|
||||
*
|
||||
* @param int $id L'id du projet
|
||||
* @return array Les commentaire du projet
|
||||
* @return array Les commentaires du projet
|
||||
*/
|
||||
function getCommentsByProject($id)
|
||||
{
|
||||
|
@ -87,3 +87,56 @@ function getCommentsByProject($id)
|
|||
}
|
||||
|
||||
// Prévoir une fonction pour enregistrer un commentaire
|
||||
|
||||
function getProjectsPager($page, $numberOfPages)
|
||||
{
|
||||
$pages = [];
|
||||
|
||||
if ($numberOfPages > 1) {
|
||||
$pages[] = array(
|
||||
'title' => 'Première page',
|
||||
'page' => 1,
|
||||
'current' => $page === 1,
|
||||
);
|
||||
}
|
||||
|
||||
if ($page > 1) {
|
||||
$pages[] = array(
|
||||
'title' => 'Précédent',
|
||||
'page' => $page - 1,
|
||||
'current' => false,
|
||||
);
|
||||
}
|
||||
|
||||
if ($numberOfPages > 1) {
|
||||
for ($i = 1; $i <= $numberOfPages; $i++) {
|
||||
$pages[] = array(
|
||||
'title' => $i,
|
||||
'page' => $i,
|
||||
'current' => $page === $i,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($page < $numberOfPages) {
|
||||
$pages[] = array(
|
||||
'title' => 'Suivant',
|
||||
'page' => $page + 1,
|
||||
'current' => false,
|
||||
);
|
||||
}
|
||||
|
||||
if ($numberOfPages > 1) {
|
||||
$pages[] = array(
|
||||
'title' => 'Dernière page',
|
||||
'page' => $numberOfPages,
|
||||
'current' => $page === $numberOfPages,
|
||||
);
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue