Compare commits
4 Commits
e3a42f4ba3
...
214bfe20ac
Author | SHA1 | Date | |
---|---|---|---|
|
214bfe20ac | ||
|
00a29b9db7 | ||
|
6430dc6904 | ||
|
c650dbce01 |
@@ -10,6 +10,49 @@ class FacilityDataSet {
|
||||
$this->_dbHandle = $this->_dbInstance->getDbConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function addFacility($data) : bool {
|
||||
$sqlQuery = "
|
||||
INSERT INTO ecoFacilities
|
||||
(title,
|
||||
category,
|
||||
description,
|
||||
houseNumber,
|
||||
streetName,
|
||||
county,
|
||||
town,
|
||||
postcode,
|
||||
lng,
|
||||
lat,
|
||||
contributor)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
;";
|
||||
$stmt = $this->_dbHandle->prepare($sqlQuery);
|
||||
// Ensures only one value is returned per column name
|
||||
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
|
||||
|
||||
// Initialize index for binding
|
||||
$bindIndex = 1;
|
||||
|
||||
// Bind other filters
|
||||
for ($i = 1; $i <= 8; $i++) { // Assuming 8 other filters
|
||||
$value = !empty($data[$i]) ? "%" . $data[$i] . "%" : "%";
|
||||
$stmt->bindValue($bindIndex++, $value, \PDO::PARAM_STR);
|
||||
}
|
||||
return !($stmt->rowCount());
|
||||
}
|
||||
|
||||
public function deleteFacility($id) : bool {
|
||||
$sqlQuery = "DELETE FROM ecoFacilities WHERE id = ?";
|
||||
$stmt = $this->_dbHandle->prepare($sqlQuery);
|
||||
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
|
||||
$stmt->bindValue(1, $id, \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
return !($stmt->rowCount() == 0);
|
||||
}
|
||||
/**
|
||||
* @param $filterArray
|
||||
* @return array
|
||||
|
@@ -40,39 +40,6 @@ class Paginator {
|
||||
]);
|
||||
}
|
||||
|
||||
public function setPageUri($page)
|
||||
{
|
||||
$uri = $_SERVER['REQUEST_URI'];
|
||||
$uriComp = parse_url($uri);
|
||||
$params = [];
|
||||
|
||||
// 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) {
|
||||
exit; // Do nothing if already on the correct page
|
||||
}
|
||||
|
||||
// Update the 'page' parameter
|
||||
$params['page'] = $page;
|
||||
|
||||
// Rebuild the query string
|
||||
$newUri = http_build_query($params);
|
||||
|
||||
// Redirect to the updated URI
|
||||
// Use the current path or root
|
||||
return
|
||||
[
|
||||
'newUri' => $newUri,
|
||||
'path' => $uriComp['path'] ?? '/'
|
||||
];
|
||||
}
|
||||
|
||||
public function getPage(int $pageNumber): array {
|
||||
|
||||
if ($pageNumber < 0 || $pageNumber >= $this->_totalPages) {
|
||||
|
@@ -1,65 +1,28 @@
|
||||
<div>
|
||||
<div class="row mb-2">
|
||||
<!-- Form for Pagination -->
|
||||
<form class="col-auto m-auto" method="POST" action="">
|
||||
<div class="btn-group">
|
||||
<!-- Start Button -->
|
||||
<button type="submit" name="pageButtons" value="0"
|
||||
class="btn btn-outline-primary"
|
||||
<?= $view->pageNumber <= 0 ? 'disabled' : '' ?>>
|
||||
<i class="bi bi-chevron-double-left"></i> Start
|
||||
</button>
|
||||
|
||||
<!-- Back Button -->
|
||||
<button type="submit" name="pageButtons" value="<?= max($view->pageNumber - 1, 0) ?>"
|
||||
class="btn btn-outline-primary"
|
||||
<?= $view->pageNumber <= 0 ? 'disabled' : '' ?>>
|
||||
<i class="bi bi-chevron-left"></i> Back
|
||||
</button>
|
||||
|
||||
<!-- Dynamic Page Buttons -->
|
||||
<?php
|
||||
$totalPages = $view->paginator->getTotalPages();
|
||||
for ($i = $view->pageNumber - 2; $i <= $view->pageNumber + 2; $i++) {
|
||||
if ($i >= 0 && $i < $totalPages): ?>
|
||||
<button type="submit" name="pageButtons" value="<?= $i ?>"
|
||||
class="btn <?= $i === $view->pageNumber ? 'btn-dark' : 'btn-outline-primary' ?>"
|
||||
<?= $i === $view->pageNumber ? 'disabled' : '' ?>>
|
||||
<?= $i + 1 ?>
|
||||
</button>
|
||||
<?php endif;
|
||||
} ?>
|
||||
|
||||
<!-- Forward Button -->
|
||||
<button type="submit" name="pageButtons" value="<?= min($view->pageNumber + 1, $totalPages - 1) ?>"
|
||||
class="btn btn-outline-primary"
|
||||
<?= $view->pageNumber >= $totalPages - 1 ? 'disabled' : '' ?>>
|
||||
Forward <i class="bi bi-chevron-right"></i>
|
||||
</button>
|
||||
|
||||
<!-- End Button -->
|
||||
<button type="submit" name="pageButtons" value="<?= $totalPages - 1 ?>"
|
||||
class="btn btn-outline-primary"
|
||||
<?= $view->pageNumber >= $totalPages - 1 ? 'disabled' : '' ?>>
|
||||
End <i class="bi bi-chevron-double-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<!-- div class="row">
|
||||
<div class="col-1 me-auto ms-auto">
|
||||
<form class="form-floating" method="POST" action="">
|
||||
<select name='pageDown' class="form-select" onchange="this.form.submit()">
|
||||
<?php for($i=0; $i<=$view->paginator->getTotalPages()-1; $i++): ?>
|
||||
<?php if($i == $view->paginator->getPageFromUri()): ?>
|
||||
<?= "<option selected value='" . $i . "'>" . ($i+1) . "</option>" ?>
|
||||
<?php else : ?>
|
||||
<?= "<option value='" . $i . "'>" . ($i+1) . "</option>" ?>
|
||||
<?php endif; ?>
|
||||
<?php endfor; ?>
|
||||
</select>
|
||||
<label for="pageDown">Page</label>
|
||||
</form>
|
||||
<div id="paginationButtons" class="col-auto m-auto btn-group">
|
||||
<!-- Start Button -->
|
||||
<a class="btn btn-outline-primary" href="?page=0" <?= $view->pageNumber <= 0 ? 'disabled' : '' ?>><i class="bi bi-chevron-double-left"></i> Start</a>
|
||||
<!-- Back Button -->
|
||||
<a class="btn btn-outline-primary" href="?page=<?=max($view->pageNumber - 1, 0)?> " <?= $view->pageNumber <= 0 ? 'disabled' : '' ?>><i class="bi bi-chevron-left"></i> Back</a>
|
||||
<!-- Dynamic Page Buttons -->
|
||||
<?php
|
||||
$totalPages = $view->paginator->getTotalPages();
|
||||
var_dump($totalPages);
|
||||
for ($i = $view->pageNumber - 2; $i <= $view->pageNumber + 2; $i++) {
|
||||
if ($i >= 0 && $i < $totalPages): ?>
|
||||
<a href="?page=<?= $i ?>"
|
||||
class="btn <?= $i === $view->pageNumber ? 'btn-dark' : 'btn-outline-primary' ?>"
|
||||
<?= $i === $view->pageNumber ? 'disabled' : '' ?>>
|
||||
<?= $i + 1 ?>
|
||||
</a>
|
||||
<?php endif;
|
||||
} ?>
|
||||
<!-- Forward Button -->
|
||||
<a class="btn btn-outline-primary" href="?page=<?=min($view->pageNumber + 1, $totalPages)?> " <?= $view->pageNumber >= $totalPages - 1 ? 'disabled' : '' ?>>Forward <i class="bi bi-chevron-right"></i></a>
|
||||
<!-- End Button -->
|
||||
<a class="btn btn-outline-primary" href="?page=<?= $totalPages - 1 ?>"<?= $view->pageNumber >= $totalPages - 1 ? 'disabled' : '' ?>>End <i class="bi bi-chevron-double-right"></i></a>
|
||||
</div>
|
||||
</div -->
|
||||
</div>
|
||||
</div>
|
||||
|
BIN
images/ecoBuddy_x128.jpg
Normal file
BIN
images/ecoBuddy_x128.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
images/ecoBuddy_x128.png
Normal file
BIN
images/ecoBuddy_x128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
BIN
images/ecoBuddy_x32.jpg
Normal file
BIN
images/ecoBuddy_x32.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
BIN
images/ecoBuddy_x32.png
Normal file
BIN
images/ecoBuddy_x32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.9 KiB |
BIN
images/ecoBuddy_x64.jpg
Normal file
BIN
images/ecoBuddy_x64.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
BIN
images/ecoBuddy_x64.png
Normal file
BIN
images/ecoBuddy_x64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@@ -2,6 +2,10 @@
|
||||
require_once('Models/FacilityDataSet.php');
|
||||
require_once("Models/Paginator.php");
|
||||
|
||||
if(!isset($_GET['page'])) {
|
||||
header("location: ?page=0");
|
||||
}
|
||||
|
||||
$filterArray = [
|
||||
0 => "",
|
||||
1 => "",
|
||||
@@ -18,20 +22,13 @@ $rowLimit = 5; //$_POST['rowCount'];
|
||||
|
||||
$facilityDataSet = new FacilityDataSet();
|
||||
|
||||
if (isset($_POST['pageButtons'])) {
|
||||
$currentPage = (int)$_POST['pageButtons'];
|
||||
} elseif (isset($_POST['pageDown'])) {
|
||||
$currentPage = (int)$_POST['pageDown'];
|
||||
} else {
|
||||
$currentPage = 0; // Default to the first page
|
||||
}
|
||||
|
||||
if (isset($_POST['applyFilters']) && isset($_POST['filter'])) {
|
||||
var_dump($_POST);
|
||||
$applyFilters = filter_input(INPUT_POST, 'applyFilters', FILTER_SANITIZE_STRING);
|
||||
$filterKey = filter_input(INPUT_POST, 'filter', FILTER_SANITIZE_STRING);
|
||||
|
||||
$filterArray[$filterKey] = $applyFilters;
|
||||
// Set the filter and generate the new URI
|
||||
$filterSet = $facilityDataSet->setFilterUri($applyFilters, $filterArray[$filterKey]);
|
||||
$filterSet = $facilityDataSet->setFilterUri($applyFilters, array_search($applyFilters, $filterArray));
|
||||
|
||||
// Parse the existing query string
|
||||
parse_str($filterSet["newUri"], $queryParams);
|
||||
@@ -56,8 +53,6 @@ $view->pageData = $facilityDataSet->fetchAll($filterArray);
|
||||
$view->paginator = new Paginator($rowLimit, $view->pageData);
|
||||
|
||||
// Initialize paginator
|
||||
$view->paginator->setPageUri($currentPage);
|
||||
|
||||
$view->pageNumber = $view->paginator->getPageFromUri();
|
||||
$view->pageData = $view->paginator->getPage($view->pageNumber);
|
||||
|
||||
|
Reference in New Issue
Block a user