pagination

This commit is contained in:
Theo 2024-01-12 11:06:07 +01:00
parent c990aed3d3
commit e6b8c87744
5 changed files with 111 additions and 69 deletions

View File

@ -3,7 +3,9 @@
class Class_gestionFiche class Class_gestionFiche
{ {
private $pdo = null; private $pdo = null;
public $NB_LIGNES_PAGINATION = 12; public static $NB_LIGNES_PAGINATION = 12;
public static $NB_LIGNES_FICHEAVALIDER = 15;
public function __construct(PdoGsb $pDO) public function __construct(PdoGsb $pDO)
{ {
@ -19,40 +21,41 @@ class Class_gestionFiche
return $result->fetchAll(); return $result->fetchAll();
} }
public function get_ListesFiches(string $idUtilisateur): array
{
$req = 'SELECT "rMois", "rEtat", "rNbJustificatifs", ROUND("rMontantValide", 2) as "rMontantValide", "eLibelle"
FROM remboursement
INNER JOIN etat ON etat."eId"=remboursement."rEtat"
WHERE "rVisiteur"= :userId
ORDER BY "rMois" DESC';
$result = $this->pdo->prepare($req);
$result->bindParam("userId", $idUtilisateur);
$result->execute();
return $result->fetchAll();
}
public function dateComplete(string $date): string public function dateComplete(string $date): string
{ {
return substr($date, 0, 4) . '-' . substr($date, 4); return substr($date, 0, 4) . '-' . substr($date, 4);
} }
public function get_ficheAvalider(): array public function get_ficheAvalider(int $nPage): array
{ {
$req = 'SELECT "rMois", "rVisiteur", "rEtat", ROUND("rMontantValide", 2) as "rMontantValide", "eLibelle", "uNom", "uPrenom" $decalage = ($nPage - 1) * $this::$NB_LIGNES_FICHEAVALIDER;
$req = 'SELECT "rMois", "rVisiteur", "rEtat", ROUND("rMontantValide", 2)
as "rMontantValide", "eLibelle", "uNom", "uPrenom"
from remboursement from remboursement
INNER JOIN utilisateur ON utilisateur."uId"=remboursement."rVisiteur" INNER JOIN utilisateur ON utilisateur."uId"=remboursement."rVisiteur"
INNER JOIN etat ON etat."eId"=remboursement."rEtat" INNER JOIN etat ON etat."eId"=remboursement."rEtat"
where "rEtat"=\'CL\' where "rEtat"=\'CL\'
ORDER BY "rMois" ASC'; ORDER BY "rMois" ASC
LIMIT :nbLignes offset :decalage;';
$result = $this->pdo->prepare($req); $result = $this->pdo->prepare($req);
$result->bindParam('nbLignes', $this::$NB_LIGNES_FICHEAVALIDER);
$result->bindParam('decalage', $decalage);
$result->execute(); $result->execute();
return $result->fetchAll(); return $result->fetchAll();
} }
public function get_nbFicheAvalider(): int
{
$req = 'SELECT COUNT(*) as "nbFicheAvalider" from remboursement
where "rEtat"=\'CL\'';
$result = $this->pdo->prepare($req);
$result->execute();
$result = $result->fetch();
return (int) $result['nbFicheAvalider'];
}
public function get_nbRemboursement(string $idUtilisateur): int public function get_nbRemboursement(string $idUtilisateur): int
{ {
$req = 'SELECT COUNT(*) as "nbRemboursement" from remboursement WHERE "rVisiteur"= :userId;'; $req = 'SELECT COUNT(*) as "nbRemboursement" from remboursement WHERE "rVisiteur"= :userId;';
@ -64,14 +67,21 @@ class Class_gestionFiche
return (int) $result['nbRemboursement']; return (int) $result['nbRemboursement'];
} }
public function get_nbPage(int $decalage): array public function get_Page(int $nPage, string $idUtilisateur): array
{ {
$req = 'SELECT * FROM remboursement ORDER BY "rDateModif" DESC LIMIT :nbLignes offset :decalage;'; $decalage = ($nPage - 1) * $this::$NB_LIGNES_PAGINATION;
$req = 'SELECT "rMois", "rVisiteur", "rEtat", ROUND("rMontantValide", 2)
as "rMontantValide", "eLibelle"
FROM remboursement
INNER JOIN etat ON etat."eId"=remboursement."rEtat"
WHERE "rVisiteur"= :userId
ORDER BY "rDateModif" DESC LIMIT :nbLignes offset :decalage;';
$result = $this->pdo->prepare($req); $result = $this->pdo->prepare($req);
$result->bindParam('nbLigne', $this->NB_LIGNES_PAGINATION); $result->bindParam('nbLignes', $this::$NB_LIGNES_PAGINATION);
$result->bindParam('decalage', $decalage); $result->bindParam('decalage', $decalage);
$result->bindParam('userId', $idUtilisateur);
$result->execute(); $result->execute();
return $result->fetchAll(PDO::FETCH_ASSOC); return $result->fetchAll(PDO::FETCH_ASSOC);
} }
} }

View File

@ -16,7 +16,16 @@ if ($_SESSION["typeU"] == "comptable") {
$userId = $_SESSION['uId']; $userId = $_SESSION['uId'];
} }
$lesFiches = $gestionFiche->get_ficheAvalider(); //Pagination
if(isset($_GET['page']) && !empty($_GET['page'])){
$currentPage = (int) strip_tags($_GET['page']);
}else{
$currentPage = 1;
}
$pages = ceil($gestionFiche->get_nbFicheAvalider() / $gestionFiche::$NB_LIGNES_FICHEAVALIDER);
$lesFiches = $gestionFiche->get_ficheAvalider($currentPage);
include("vues/v_fichesAvalider.php"); include("vues/v_fichesAvalider.php");

View File

@ -23,12 +23,9 @@ if(isset($_GET['page']) && !empty($_GET['page'])){
$currentPage = 1; $currentPage = 1;
} }
$pages = ceil($gestionFiche->get_nbRemboursement($userId) / 12); $pages = ceil($gestionFiche->get_nbRemboursement($userId) / $gestionFiche::$NB_LIGNES_PAGINATION);
$lesFiches = $gestionFiche->get_ListesFiches($userId);
$lesFiches = $gestionFiche->get_Page($currentPage, $userId);
include("vues/v_gestionFiches.php"); include("vues/v_gestionFiches.php");

View File

@ -1,3 +1,7 @@
<div class="text-center">
<br>
<h3>Fiches à valider</h3>
</div>
<div class="col-11 d-flex mx-auto"> <div class="col-11 d-flex mx-auto">
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
@ -34,20 +38,33 @@
</table> </table>
</div> </div>
<div class="col-4 d-flex mx-auto">
<nav aria-label="..."> <?php if ($pages > 0) { ?>
<ul class="pagination"> <div class="col-4 d-flex mx-auto">
<li class="page-item disabled"> <nav>
<a class="page-link">Previous</a> <ul class="pagination">
</li> <!-- Lien vers la page précédente (désactivé si on se trouve sur la 1ère page) -->
<li class="page-item"><a class="page-link" href="#">1</a></li> <li class="page-item <?= ($currentPage == 1) ? "disabled" : "" ?>">
<li class="page-item active" aria-current="page"> <a href="index.php?direction=ficheAvalider&page=<?= $currentPage - 1 ?>"
<a class="page-link" href="#">2</a> class="page-link">Précédente</a>
</li> </li>
<li class="page-item"><a class="page-link" href="#">3</a></li> <?php for ($page = 1; $page <= $pages; $page++): ?>
<li class="page-item"> <!-- Lien vers chacune des pages (activé si on se trouve sur la page correspondante) -->
<a class="page-link" href="#">Next</a> <li class="page-item <?= ($currentPage == $page) ? "active" : "" ?>">
</li> <a href="index.php?direction=ficheAvalider&page=<?= $page ?>"
</ul> class="page-link">
</nav> <?= $page ?>
</div> </a>
</li>
<?php endfor ?>
<!-- Lien vers la page suivante (désactivé si on se trouve sur la dernière page) -->
<li class="page-item <?= ($currentPage == $pages) ? "disabled" : "" ?>">
<a href="index.php?direction=ficheAvalider&page=<?= $currentPage + 1 ?>"
class="page-link">Suivante</a>
</li>
</ul>
</nav>
</div>
<?php
};
?>

View File

@ -12,9 +12,9 @@
echo '<select class="form-select" name="selVisiteur" id="">'; echo '<select class="form-select" name="selVisiteur" id="">';
foreach ($LesUtilisateurs as $key => $value) { foreach ($LesUtilisateurs as $key => $value) {
$id = $value['uId']; $id = $value['uId'];
$prenom = $value['uPrenom']; $prenom = $value['uPrenom'];
$nom = $value['uNom']; $nom = $value['uNom'];
if ($id == $userId) { if ($id == $userId) {
echo '<option value="' . $id . '" selected>' . $nom . " " . $prenom . "</option>"; echo '<option value="' . $id . '" selected>' . $nom . " " . $prenom . "</option>";
} else { } else {
@ -22,7 +22,7 @@
} }
} }
echo '</select>'; ?> echo '</select>'; ?>
<button type="submit" class="btn btn-dark m-2" >Selectionner</button> <button type="submit" class="btn btn-dark m-2">Selectionner</button>
<!-- Fin du formulaire --> <!-- Fin du formulaire -->
<?php } <?php }
?> ?>
@ -63,26 +63,35 @@
</div> </div>
<!-- <!--
PAGINATION:// NE PAS TOUCHER PAGINATION:
--> -->
<div class="col-4 d-flex mx-auto"> <?php if ($pages > 0) { ?>
<div class="col-4 d-flex mx-auto">
<nav>
<ul class="pagination">
<!-- Lien vers la page précédente (désactivé si on se trouve sur la 1ère page) -->
<li class="page-item <?= ($currentPage == 1) ? "disabled" : "" ?>">
<a href="index.php?direction=gestionFiche&page=<?= $currentPage - 1 ?>&selVisiteur=<?= $userId ?>"
class="page-link">Précédente</a>
</li>
<?php for ($page = 1; $page <= $pages; $page++): ?>
<!-- Lien vers chacune des pages (activé si on se trouve sur la page correspondante) -->
<li class="page-item <?= ($currentPage == $page) ? "active" : "" ?>">
<a href="index.php?direction=gestionFiche&page=<?= $page ?>&selVisiteur=<?= $userId ?>"
class="page-link">
<?= $page ?>
</a>
</li>
<?php endfor ?>
<!-- Lien vers la page suivante (désactivé si on se trouve sur la dernière page) -->
<li class="page-item <?= ($currentPage == $pages) ? "disabled" : "" ?>">
<a href="index.php?direction=gestionFiche&page=<?= $currentPage + 1 ?>&selVisiteur=<?= $userId ?>"
class="page-link">Suivante</a>
</li>
</ul>
</nav>
</div>
<?php <?php
};
?> ?>
<nav aria-label="...">
<ul class="pagination">
<li class="page-item disabled">
<a class="page-link">Previous</a>
</li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item active" aria-current="page">
<a class="page-link" href="#">2</a>
</li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#">Next</a>
</li>
</ul>
</nav>
</div>