completely flarched it

This commit is contained in:
boris
2024-11-29 17:19:08 +00:00
parent 4005328979
commit b7b5fb545b
44 changed files with 252 additions and 8730 deletions

View File

@@ -1,17 +1,18 @@
<?php
require_once('FacilityDataSet.php');
class Paginator {
protected $_pages, $_totalPages, $_rowLimit, $_offset, $_pageMatrix, $_rowCount;
protected $_pages, $_totalPages, $_rowLimit, $_pageMatrix, $_rowCount;
public function __construct($rowLimit, $offset, $dataset) {
public function __construct($rowLimit, $dataset) {
$this->_rowLimit = $rowLimit;
$this->_offset = $offset;
$this->_totalPages = $this->calculateTotalPages($dataset['count']);
$this->_rowCount = $dataset['count'];
$this->_pages = $dataset['dataset'];
$this->_pageMatrix = $this->Paginate();
}
public function getTotalPages() {
return $this->_totalPages;
}
private function calculateTotalPages(int $count): int {
return $count > 0 ? ceil($count / $this->_rowLimit) : 0;
}
@@ -32,14 +33,14 @@ class Paginator {
return $pageMatrix;
}
function getPageFromUri(): int {
public function getPageFromUri(): int {
// Retrieve 'page' parameter and default to 0 if missing or invalid
return filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, [
'options' => ['default' => 0, 'min_range' => 0] // Default to 0 if invalid or missing
'options' => ['default' => 0, 'min_range' => 0] // Default to 1 if invalid or missing
]);
}
public function setPageUri(int $page): void
public function setPageUri($page)
{
$uri = $_SERVER['REQUEST_URI'];
$uriComp = parse_url($uri);
@@ -48,11 +49,13 @@ class Paginator {
// Parse existing query parameters
if (isset($uriComp['query'])) {
parse_str($uriComp['query'], $params);
} else {
$params = array();
}
// Avoid unnecessary redirection if the page is already correct
if (isset($params['page']) && (int)$params['page'] === $page) {
return; // Do nothing if already on the correct page
exit; // Do nothing if already on the correct page
}
// Update the 'page' parameter
@@ -62,9 +65,12 @@ class Paginator {
$newUri = http_build_query($params);
// Redirect to the updated URI
$path = $uriComp['path'] ?? '/'; // Use the current path or root
header("Location: $path?$newUri");
exit;
// Use the current path or root
return
[
'newUri' => $newUri,
'path' => $uriComp['path'] ?? '/'
];
}
public function getPage(int $pageNumber): array {