5 Commits

6 changed files with 260 additions and 189 deletions

View File

@@ -2,10 +2,12 @@
require_once ('Database.php');
require_once ('FacilityData.php');
class FacilityDataSet {
class FacilityDataSet
{
protected $_dbHandle, $_dbInstance;
public function __construct() {
public function __construct()
{
$this->_dbInstance = Database::getInstance();
$this->_dbHandle = $this->_dbInstance->getDbConnection();
}
@@ -14,7 +16,8 @@ class FacilityDataSet {
* @param $data
* @return bool
*/
public function addFacility($data) : bool {
public function addFacility($data): bool
{
$sqlQuery = "
INSERT INTO ecoFacilities
(title,
@@ -45,7 +48,8 @@ class FacilityDataSet {
return !($stmt->rowCount());
}
public function deleteFacility($id) : bool {
public function deleteFacility($id): bool
{
$sqlQuery = "DELETE FROM ecoFacilities WHERE id = ?";
$stmt = $this->_dbHandle->prepare($sqlQuery);
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
@@ -53,93 +57,99 @@ class FacilityDataSet {
$stmt->execute();
return !($stmt->rowCount() == 0);
}
/**
* @param $filterArray
* @return array
* Function to allow fetching of facility data. Data objects are created and held in an array
* Count of rows for pagination returned alongside data objects.
*/
public function fetchAll($filterArray): array
{
/**
* COUNT(DISTINCT ecoFacilities.id) required due to multiple status comments possible.
*/
$sqlCount = "SELECT COUNT(DISTINCT ecoFacilities.id) AS total FROM ecoFacilities";
/**
* DISTINCT used again for prior reasoning, although data is handled properly regardless later.
* GROUP_CONCAT is used to handle multiple status comments under one facility. Without this, DISTINCT
* drops the additional comment.
*/
$sqlData = "SELECT DISTINCT ecoFacilities.id,
title,
public function fetchAll($filterArray, $sortArray): array
{
// Define columns for filtering and sorting
$filterColumns = [
0 => 'ecoFacilityStatus.statusComment',
1 => 'ecoFacilities.title',
2 => 'ecoCategories.name',
3 => 'ecoFacilities.description',
4 => 'ecoFacilities.streetName',
5 => 'ecoFacilities.county',
6 => 'ecoFacilities.town',
7 => 'ecoFacilities.postcode',
8 => 'ecoUser.username'
];
$sortColumns = [
0 => 'ecoFacilityStatus.statusComment',
1 => 'ecoFacilities.title',
2 => 'ecoCategories.name',
3 => 'ecoFacilities.description',
4 => 'ecoFacilities.streetName',
5 => 'ecoFacilities.county',
6 => 'ecoFacilities.town',
7 => 'ecoFacilities.postcode',
8 => 'ecoUser.username'
];
// Validate and select the filter column
$selectedFilterColumn = $filterColumns[$filterArray['category']] ?? 'ecoFacilities.title';
// Validate and select the sort column
$selectedSortColumn = $sortColumns[$sortArray['sort']] ?? 'ecoFacilities.title';
// Validate sort direction
$direction = strtolower($sortArray['dir']) === 'desc' ? 'DESC' : 'ASC';
// Base query for filtering and sorting
$baseQuery = "
FROM ecoFacilities
LEFT JOIN ecoCategories ON ecoCategories.id = ecoFacilities.category
LEFT JOIN ecoUser ON ecoUser.id = ecoFacilities.contributor
LEFT JOIN ecoFacilityStatus ON ecoFacilityStatus.facilityid = ecoFacilities.id
WHERE {$selectedFilterColumn} LIKE :term
";
// Query to count total results
$countQuery = "SELECT COUNT(DISTINCT ecoFacilities.id) AS total {$baseQuery}";
// Query to fetch filtered and sorted results
$dataQuery = "
SELECT DISTINCT ecoFacilities.id,
ecoFacilities.title,
GROUP_CONCAT(ecoFacilityStatus.statusComment, ', ') AS status,
ecoCategories.name AS category,
description,
houseNumber,
streetName,
county,
town,
postcode,
lng,
lat,
ecoFacilities.description,
ecoFacilities.houseNumber,
ecoFacilities.streetName,
ecoFacilities.county,
ecoFacilities.town,
ecoFacilities.postcode,
ecoFacilities.lng,
ecoFacilities.lat,
ecoUser.username AS contributor
FROM ecoFacilities";
{$baseQuery}
GROUP BY ecoFacilities.id, ecoFacilities.title, ecoCategories.name,
ecoFacilities.description, ecoFacilities.streetName,
ecoFacilities.county, ecoFacilities.town, ecoFacilities.postcode,
ecoUser.username
ORDER BY {$selectedSortColumn} {$direction};
";
$filterArray['term'] = '%' . $filterArray['term'] . '%' ?? '%';
var_dump($filterArray);
// Prepare and execute the count query
$countStmt = $this->_dbHandle->prepare($countQuery);
$countStmt->bindValue(':term', $filterArray['term'], PDO::PARAM_STR);
$countStmt->execute();
$totalResults = (int)$countStmt->fetchColumn();
/**
* ? Parameters used here over named parameters so logic can be modular, more
* columns can be added in the future
*/
$sqlWhere = "
LEFT JOIN ecoCategories ON ecoCategories.id = ecoFacilities.category
LEFT JOIN ecoUser ON ecoUser.id = ecoFacilities.contributor
LEFT JOIN ecoFacilityStatus ON ecoFacilityStatus.facilityid = ecoFacilities.id
WHERE (ecoFacilityStatus.statusComment LIKE ? OR ? IS NULL)
AND ecoFacilities.title LIKE ?
AND ecoCategories.name LIKE ?
AND ecoFacilities.description LIKE ?
AND ecoFacilities.streetName LIKE ?
AND ecoFacilities.county LIKE ?
AND ecoFacilities.town LIKE ?
AND ecoFacilities.postcode LIKE ?
AND ecoUser.username LIKE ?
";
// Prepare and execute the data query
$dataStmt = $this->_dbHandle->prepare($dataQuery);
$dataStmt->bindValue(':term', $filterArray['term'], PDO::PARAM_STR);
$dataStmt->execute();
/**
* GROUP BY required to ensure status comments are displayed under the same ID
* Named parameters used here for prior reasoning, columns can be added above without
* effecting the bindIndex.
*/
$sqlLimits = "
GROUP BY ecoFacilities.id
LIMIT :limit OFFSET :offset;";
$sqlLimits = "
GROUP BY ecoFacilities.id
;";
// Concatenate query snippets for data and row count
$dataQuery = $sqlData . $sqlWhere . $sqlLimits;
$countQuery = $sqlCount . $sqlWhere . ";";
// Prepare, bind and execute data query
$stmt = $this->populateFields($dataQuery, $filterArray);
$stmt->execute();
// Create data objects
// Fetch results into FacilityData objects
$dataSet = [];
while ($row = $stmt->fetch()) {
while ($row = $dataStmt->fetch()) {
$dataSet[] = new FacilityData($row);
}
// Prepare, bind then execute count query
$stmt = $this->populateFields($countQuery, $filterArray);
$stmt->execute();
$totalCount = $stmt->fetch()['total'];
return [
'dataset' => $dataSet,
'count' => $totalCount
];
'count' => $totalResults
];
}
/**
@@ -149,60 +159,57 @@ class FacilityDataSet {
* Function for fetchAll() to de-dupe code. Performs binding on PDO statements to facilitate
* filtering of facilities. Returns a bound PDO statement.
*/
// private function populateFields($sqlQuery, $filterArray, $sortBy, $direction)
// {
// $stmt = $this->_dbHandle->prepare($sqlQuery);
// $stmt->setFetchMode(\PDO::FETCH_ASSOC);
//
// // Initialize index for binding
// $bindIndex = 1;
//
// // Bind statusComment filter, required due to comments not being so.
// $statusComment = !empty($filterArray[0]) ? "%" . $filterArray[0] . "%" : null;
// $stmt->bindValue($bindIndex++, $statusComment ?? "%", \PDO::PARAM_STR); // First ?
// $stmt->bindValue($bindIndex++, $statusComment, $statusComment === null ? \PDO::PARAM_NULL : \PDO::PARAM_STR); // Second ?
//
// // Bind other filters
// for ($i = 1; $i <= 8; $i++) { // Assuming 8 other filters
// $value = !empty($filterArray[$i]) ? "%" . $filterArray[$i] . "%" : "%";
// $stmt->bindValue($bindIndex++, $value, \PDO::PARAM_STR);
// }
// return $stmt;
// }
// So i worked on trying to get this to work for 30 minutes and it turns out you
// can never bind column name values to placeholders, and must use column orders
// as integers..... what
// if(isset($sortBy) && isset($direction)) {
// $stmt->bindValue(':sortBy', $sortBy, \PDO::PARAM_STR);
// $stmt->bindValue(':direction', $direction, \PDO::PARAM_STR);
// }
private function populateFields($sqlQuery, $filterArray)
{
$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 statusComment filter, required due to comments not being so.
$statusComment = !empty($filterArray[0]) ? "%" . $filterArray[0] . "%" : null;
$stmt->bindValue($bindIndex++, $statusComment ?? "%", \PDO::PARAM_STR); // First ?
$stmt->bindValue($bindIndex++, $statusComment, $statusComment === null ? \PDO::PARAM_NULL : \PDO::PARAM_STR); // Second ?
// Bind statusComment (two placeholders required)
$statusComment = $filterArray[0] ?? '%';
$stmt->bindValue($bindIndex++, $statusComment, \PDO::PARAM_STR);
$stmt->bindValue($bindIndex++, $statusComment, \PDO::PARAM_STR);
// Bind other filters
for ($i = 1; $i <= 8; $i++) { // Assuming 8 other filters
$value = !empty($filterArray[$i]) ? "%" . $filterArray[$i] . "%" : "%";
for ($i = 1; $i < count($filterArray); $i++) {
$value = $filterArray[$i] ?? '%';
print_r($i . ":" . $value . "||\n");
$stmt->bindValue($bindIndex++, $value, \PDO::PARAM_STR);
}
// Debugging
//$stmt->debugDumpParams();
return $stmt;
}
public function setFilterUri($term, $category)
{
$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 filter is already correct
if ((isset($params['category']) && $params['category'] === $category) && (isset($params['term']) && $params['term'] === $term)) {
exit; // Do nothing if filter already applied
}
// Update the 'page' parameter
$params['category'] = $category;
$params['term'] = $term;
// Rebuild the query string
$newUri = http_build_query($params);
var_dump($newUri);
// Redirect to the updated URI
// Use the current path or root
return
[
'newUri' => $newUri,
'path' => $uriComp['path'] ?? '/'
]; }
}

View File

@@ -0,0 +1,32 @@
<button type="button" class="col btn bg-primary btn-outline-primary text-light" data-bs-toggle="modal" data-bs-target="#createModal">
<span class="bi bi-pen-fill"></span>
</button>
<div class="modal fade" id="createModal" tabindex="-1" aria-labelledby="updateModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="updateModalLabel">Add Facility</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<form class="form-inline" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?> ">
<input name="titlCreate" class="form-control rounded mb-2" placeholder="Title">
<input name="cateCreate" class="form-control rounded mb-2" placeholder="Category">
<input name="descCreate" class="form-control rounded mb-2" placeholder="Description">
<input name="statCreate" class="form-control rounded mb-2" placeholder="Status">
<input name="strtCreate" class="form-control rounded mb-2" placeholder="Street Name">
<input name="cntyCreate" class="form-control rounded mb-2" placeholder="County">
<input name="townCreate" class="form-control rounded mb-2" placeholder="Town">
<input name="postCreate" class="form-control rounded mb-2" placeholder="Postcode">
<input name="contCreate" class="form-control rounded mb-2" placeholder="Contributor">
</form>
<button type="submit" class="btn bg-primary btn-outline-primary text-light" name="updateButton">Add</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

View File

@@ -7,8 +7,6 @@
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" type="image/x-icon" href="/images/ecoBuddy_x32.png"
<!-- Bootstrap core CSS -->
<link href="/css/bootstrap.css" rel="stylesheet">
<!-- Bootstrap theme -->
@@ -35,32 +33,54 @@
<a class="nav-link" href="#">Link</a>
</li>
</ul>
<form class="row m-0 me-2 align-content-center align-content-center align-items-center" role="search" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<form class="row m-0 me-2 align-content-center align-content-center align-items-center" role="search" action="" method="POST">
<div class="col">
<div class="form-floating input-group">
<select name="filter" class="form-select border-3 border-success-subtle" id="filter">
<option selected></option>
<option value="1">Title</option>
<option value="2">Category</option>
<option value="0">Status</option>
<option value="3">Description</option>
<option value="4">Street Name</option>
<option value="5">County</option>
<option value="6">Town</option>
<option value="7">Postcode</option>
<option value="8">Contributor</option>
<select name="sort" class="form-select border-3 border-success-subtle" id="sort">
<option value="1" <?php if(isset($_GET['sort']) && $_GET['sort'] == '1') echo 'selected'; ?>>Title</option>
<option value="2" <?php if(isset($_GET['sort']) && $_GET['sort'] == '2') echo 'selected'; ?>>Category</option>
<option value="0" <?php if(isset($_GET['sort']) && $_GET['sort'] == '0') echo 'selected'; ?>>Status</option>
<option value="3" <?php if(isset($_GET['sort']) && $_GET['sort'] == '3') echo 'selected'; ?>>Description</option>
<option value="4" <?php if(isset($_GET['sort']) && $_GET['sort'] == '4') echo 'selected'; ?>>Street Name</option>
<option value="5" <?php if(isset($_GET['sort']) && $_GET['sort'] == '5') echo 'selected'; ?>>County</option>
<option value="6" <?php if(isset($_GET['sort']) && $_GET['sort'] == '6') echo 'selected'; ?>>Town</option>
<option value="7" <?php if(isset($_GET['sort']) && $_GET['sort'] == '7') echo 'selected'; ?>>Postcode</option>
<option value="8" <?php if(isset($_GET['sort']) && $_GET['sort'] == '8') echo 'selected'; ?>>Contributor</option>
</select>
<span class="input-group-text bi bi-filter-circle bg-success-subtle border-0 rounded-end" id="filter"></span>
<label for="filter">Column Filter</label>
<span class="form-floating input-group">
<select class="form-select border-3 border-start-0 rounded-end border-success-subtle" name="dir" id="dir">
<option value="asc" <?php if($_GET['dir'] == 'asc') echo 'selected'; ?>>Asc</option>
<option value="desc" <?php if($_GET['dir'] == 'desc') echo 'selected'; ?>>Desc</option>
</select>
<label for="dir">Order</label>
</span>
<label for="sort">Sort By</label>
</div>
</div>
<div class="col">
<div class="form-floating input-group">
<input class="form-control border-3 border-success-subtle" id="search" type="search" name="applyFilters" aria-label="Search">
<select name="filterCat" class="form-select border-3 border-success-subtle" id="filterCat">
<option value="1" <?php if(isset($_GET['category']) && $_GET['category'] == '1') echo 'selected'; ?>>Title</option>
<option value="2" <?php if(isset($_GET['category']) && $_GET['category'] == '2') echo 'selected'; ?>>Category</option>
<option value="0" <?php if(isset($_GET['category']) && $_GET['category'] == '0') echo 'selected'; ?>>Status</option>
<option value="3" <?php if(isset($_GET['category']) && $_GET['category'] == '3') echo 'selected'; ?>>Description</option>
<option value="4" <?php if(isset($_GET['category']) && $_GET['category'] == '4') echo 'selected'; ?>>Street Name</option>
<option value="5" <?php if(isset($_GET['category']) && $_GET['category'] == '5') echo 'selected'; ?>>County</option>
<option value="6" <?php if(isset($_GET['category']) && $_GET['category'] == '6') echo 'selected'; ?>>Town</option>
<option value="7" <?php if(isset($_GET['category']) && $_GET['category'] == '7') echo 'selected'; ?>>Postcode</option>
<option value="8" <?php if(isset($_GET['category']) && $_GET['category'] == '8') echo 'selected'; ?>>Contributor</option>
</select>
<span class="input-group-text bi bi-filter-circle bg-success-subtle border-0 rounded-end" id="filterCat"></span>
<label for="filterCat">Column Filter</label>
</div>
</div>
<div class="col">
<div class="form-floating input-group">
<label for="search"></label>
<input placeholder="<?php if(isset($_GET['filter'])) echo $_GET['filter']; ?>" class="form-control border-3 border-success-subtle" id="search" type="search" name="filter" aria-label="Search">
<span class="input-group-text bg-success-subtle border-0 rounded-end" id="search">
<button class="btn bg-light bg-success-subtle" type="submit"><span class="bi bi-search"></span></button>
</span>
<label for="search">Search</label>
</div>
</div>
</form>

View File

@@ -2,17 +2,26 @@
<div class="row mb-2">
<!-- Form for Pagination -->
<div id="paginationButtons" class="col-auto m-auto btn-group">
<?php
$params = $_GET;
unset($params['page']); // Remove the page parameter to avoid duping
function buildUrl($page, $params): string
{
$params['page'] = $page;
return '?' . http_build_query($params);
}
?>
<!-- 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>
<a class="btn btn-outline-primary" href="<?= buildUrl(0, $params) ?>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>
<a class="btn btn-outline-primary" href="<?= buildUrl(max($view->pageNumber - 1, 0), $params)?> " <?= $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 ?>"
<a href="<?= buildUrl($i, $params) ?>"
class="btn <?= $i === $view->pageNumber ? 'btn-dark' : 'btn-outline-primary' ?>"
<?= $i === $view->pageNumber ? 'disabled' : '' ?>>
<?= $i + 1 ?>
@@ -20,9 +29,9 @@
<?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>
<a class="btn btn-outline-primary" href="<?=buildUrl(min($view->pageNumber + 1, $totalPages), $params)?>" <?= $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>
<a class="btn btn-outline-primary" href="<?= buildUrl($totalPages - 1, $params) ?>"<?= $view->pageNumber >= $totalPages - 1 ? 'disabled' : '' ?>>End <i class="bi bi-chevron-double-right"></i></a>
</div>
</div>
</div>

View File

@@ -6,6 +6,7 @@ require_once("logincontroller.php");
$view = new stdClass();
$view->pageTitle = 'Home';
//if (isset($_POST['applyAdvFilters'])) {
// array_push($filterArray, $_POST['titlFilter'], $_POST['cateFilter'],
// $description = $_POST['descFilter'], $status = $_POST['statFilter'],

View File

@@ -1,58 +1,53 @@
<?php
require_once('Models/FacilityDataSet.php');
require_once("Models/Paginator.php");
// If page loads empty, set initial headers
//if(empty($_GET)) {
// header("Location: ?sort=1&dir=asc&category=1&term=&page=0");
// exit;
//}
if(!isset($_GET['page'])) {
header("location: ?page=0");
}
$filterArray = [
0 => "",
1 => "",
2 => "",
3 => "",
4 => "",
5 => "",
6 => "",
7 => "",
8 => ""
$filters = [
'category' => $_GET['category'] ?? '1', // Default category
'term' => $_GET['term'] ?? '', // Default term
'sort' => $_GET['sort'] ?? '1', // Default sort
'dir' => $_GET['dir'] ?? 'asc', // Default direction
'page' => $_GET['page'] ?? 0 // Default to first page
];
$rowLimit = 5; //$_POST['rowCount'];
$facilityDataSet = new FacilityDataSet();
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, array_search($applyFilters, $filterArray));
// Parse the existing query string
parse_str($filterSet["newUri"], $queryParams);
// Add or overwrite the 'page' parameter
$queryParams['page'] = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, [
'options' => ['default' => 0, 'min_range' => 0] // Default to 0 for the first page
]);
// Build the updated query string
$newQueryString = http_build_query($queryParams);
// Redirect with the updated URI
header("Location: {$filterSet["path"]}?{$newQueryString}");
exit;
// If no query parameters exist (initial page load), redirect to set default ones
if (empty($_GET)) {
redirectWithFilters($filters);
}
$rowLimit = 5;
$facilityDataSet = new FacilityDataSet();
$filterArray[$_GET['category'] ?? null] = $_GET['term'] ?? null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Check if filters/sorting changed
$filtersChanged = (
$filters['category'] !== ($_POST['filterCat'] ?? $filters['category']) ||
$filters['term'] !== ($_POST['filter'] ?? $filters['term']) ||
$filters['sort'] !== ($_POST['sort'] ?? $filters['sort']) ||
$filters['dir'] !== ($_POST['dir'] ?? $filters['dir'])
);
$filters['category'] = filter_input(INPUT_POST, 'filterCat', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? $filters['category'];
$filters['term'] = filter_input(INPUT_POST, 'filter', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? $filters['term'];
$filters['sort'] = filter_input(INPUT_POST, 'sort', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? $filters['sort'];
$filters['dir'] = filter_input(INPUT_POST, 'dir', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? $filters['dir'];
// Reset page if filters changed
$filters['page'] = $filtersChanged ? 0 : $_POST['paginationButton'] ?? $filters['page'];
redirectWithFilters($filters);
}
$view->pageData = $facilityDataSet->fetchAll(
['category' => $filters['category'], 'term' => $filters['term']],
['sort' => $filters['sort'], 'dir' => $filters['dir']]
);
$view->pageData = $facilityDataSet->fetchAll($filterArray);
$view->paginator = new Paginator($rowLimit, $view->pageData);
// Initialize paginator
$view->pageNumber = $view->paginator->getPageFromUri();
$view->pageData = $view->paginator->getPage($view->pageNumber);
@@ -60,3 +55,10 @@ $view->pageData = $view->paginator->getPage($view->pageNumber);
$view->dbMessage = $view->paginator->countPageResults($view->pageNumber) == 0
? "No results"
: $view->paginator->countPageResults($view->pageNumber) . " result(s)";
// Redirect function
function redirectWithFilters($filters) {
$queryString = http_build_query($filters);
header("Location: ?" . $queryString);
exit;
}