(feat): filter and direction dropdown
This commit is contained in:
@@ -53,14 +53,53 @@ class FacilityDataSet {
|
|||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
return !($stmt->rowCount() == 0);
|
return !($stmt->rowCount() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $filterArray
|
* @param $filterArray
|
||||||
|
* @param $sortArray
|
||||||
* @return array
|
* @return array
|
||||||
* Function to allow fetching of facility data. Data objects are created and held in an 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.
|
* Count of rows for pagination returned alongside data objects.
|
||||||
*/
|
*/
|
||||||
public function fetchAll($filterArray): array
|
public function fetchAll($filterArray, $sortArray): array
|
||||||
{
|
{
|
||||||
|
$direction = '';
|
||||||
|
// Set direction, if not found in array, set to ascending.
|
||||||
|
(in_array('desc', $sortArray)) ? $direction = 'DESC' : $direction = 'ASC';
|
||||||
|
// Default to title
|
||||||
|
// Note: I am very sorry, i am well aware this is horrible, im running out of time
|
||||||
|
$sortBy = 1;
|
||||||
|
var_dump($sortArray);
|
||||||
|
switch (array_search('desc', $sortArray) ?? array_search('asc', $sortArray)) {
|
||||||
|
case (0) :
|
||||||
|
$sortBy = 'ecoFacilityStatus.statusComment';
|
||||||
|
break;
|
||||||
|
case (1) :
|
||||||
|
$sortBy = 'ecoFacilities.title';
|
||||||
|
break;
|
||||||
|
case (2) :
|
||||||
|
$sortBy = 'ecoCategories.name';
|
||||||
|
break;
|
||||||
|
case (3) :
|
||||||
|
$sortBy = 'ecoFacilities.description';
|
||||||
|
break;
|
||||||
|
case (4) :
|
||||||
|
$sortBy = 'ecoFacilities.streetName';
|
||||||
|
break;
|
||||||
|
case (5) :
|
||||||
|
$sortBy = 'ecoFacilities.county';
|
||||||
|
break;
|
||||||
|
case (6) :
|
||||||
|
$sortBy = 'ecoFacilities.town';
|
||||||
|
break;
|
||||||
|
case (7) :
|
||||||
|
$sortBy = 'ecoFacilities.postcode';
|
||||||
|
break;
|
||||||
|
case (8) :
|
||||||
|
$sortBy = 'ecoUser.username';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* COUNT(DISTINCT ecoFacilities.id) required due to multiple status comments possible.
|
* COUNT(DISTINCT ecoFacilities.id) required due to multiple status comments possible.
|
||||||
*/
|
*/
|
||||||
@@ -109,12 +148,15 @@ class FacilityDataSet {
|
|||||||
* GROUP BY required to ensure status comments are displayed under the same ID
|
* 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
|
* Named parameters used here for prior reasoning, columns can be added above without
|
||||||
* effecting the bindIndex.
|
* effecting the bindIndex.
|
||||||
|
* I unfortunately HAVE to do the ORDER BY statement like this, since PDO doesn't allow
|
||||||
|
* binding of column names to placeholders for some reason. I could have used the column
|
||||||
|
* order and passed an integer, but its too much hassle and I have enough sanitisation,
|
||||||
|
* this is fine.
|
||||||
*/
|
*/
|
||||||
$sqlLimits = "
|
$sqlLimits = "
|
||||||
GROUP BY ecoFacilities.id
|
GROUP BY ecoFacilities.id, ecoFacilities.title, ecoCategories.name, ecoFacilities.description, ecoFacilities.streetName,
|
||||||
LIMIT :limit OFFSET :offset;";
|
ecoFacilities.county, ecoFacilities.town, ecoFacilities.postcode, ecoUser.username
|
||||||
$sqlLimits = "
|
ORDER BY {$sortBy} {$direction}
|
||||||
GROUP BY ecoFacilities.id
|
|
||||||
;";
|
;";
|
||||||
|
|
||||||
// Concatenate query snippets for data and row count
|
// Concatenate query snippets for data and row count
|
||||||
@@ -122,7 +164,7 @@ class FacilityDataSet {
|
|||||||
$countQuery = $sqlCount . $sqlWhere . ";";
|
$countQuery = $sqlCount . $sqlWhere . ";";
|
||||||
|
|
||||||
// Prepare, bind and execute data query
|
// Prepare, bind and execute data query
|
||||||
$stmt = $this->populateFields($dataQuery, $filterArray);
|
$stmt = $this->populateFields($dataQuery, $filterArray, $sortBy, $direction);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|
||||||
// Create data objects
|
// Create data objects
|
||||||
@@ -132,7 +174,7 @@ class FacilityDataSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepare, bind then execute count query
|
// Prepare, bind then execute count query
|
||||||
$stmt = $this->populateFields($countQuery, $filterArray);
|
$stmt = $this->populateFields($countQuery, $filterArray, null, null);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$totalCount = $stmt->fetch()['total'];
|
$totalCount = $stmt->fetch()['total'];
|
||||||
|
|
||||||
@@ -145,11 +187,13 @@ class FacilityDataSet {
|
|||||||
/**
|
/**
|
||||||
* @param $sqlQuery
|
* @param $sqlQuery
|
||||||
* @param $filterArray
|
* @param $filterArray
|
||||||
|
* @param $sortBy
|
||||||
|
* @param $direction
|
||||||
* @return false|PDOStatement
|
* @return false|PDOStatement
|
||||||
* Function for fetchAll() to de-dupe code. Performs binding on PDO statements to facilitate
|
* Function for fetchAll() to de-dupe code. Performs binding on PDO statements to facilitate
|
||||||
* filtering of facilities. Returns a bound PDO statement.
|
* filtering of facilities. Returns a bound PDO statement.
|
||||||
*/
|
*/
|
||||||
private function populateFields($sqlQuery, $filterArray)
|
private function populateFields($sqlQuery, $filterArray, $sortBy, $direction)
|
||||||
{
|
{
|
||||||
$stmt = $this->_dbHandle->prepare($sqlQuery);
|
$stmt = $this->_dbHandle->prepare($sqlQuery);
|
||||||
// Ensures only one value is returned per column name
|
// Ensures only one value is returned per column name
|
||||||
@@ -162,6 +206,13 @@ class FacilityDataSet {
|
|||||||
$statusComment = !empty($filterArray[0]) ? "%" . $filterArray[0] . "%" : null;
|
$statusComment = !empty($filterArray[0]) ? "%" . $filterArray[0] . "%" : null;
|
||||||
$stmt->bindValue($bindIndex++, $statusComment ?? "%", \PDO::PARAM_STR); // First ?
|
$stmt->bindValue($bindIndex++, $statusComment ?? "%", \PDO::PARAM_STR); // First ?
|
||||||
$stmt->bindValue($bindIndex++, $statusComment, $statusComment === null ? \PDO::PARAM_NULL : \PDO::PARAM_STR); // Second ?
|
$stmt->bindValue($bindIndex++, $statusComment, $statusComment === null ? \PDO::PARAM_NULL : \PDO::PARAM_STR); // Second ?
|
||||||
|
// 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);
|
||||||
|
// }
|
||||||
|
|
||||||
// Bind other filters
|
// Bind other filters
|
||||||
for ($i = 1; $i <= 8; $i++) { // Assuming 8 other filters
|
for ($i = 1; $i <= 8; $i++) { // Assuming 8 other filters
|
||||||
@@ -171,6 +222,7 @@ class FacilityDataSet {
|
|||||||
return $stmt;
|
return $stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UNUSED REPLACED
|
||||||
public function setFilterUri($term, $category)
|
public function setFilterUri($term, $category)
|
||||||
{
|
{
|
||||||
$uri = $_SERVER['REQUEST_URI'];
|
$uri = $_SERVER['REQUEST_URI'];
|
||||||
|
@@ -7,8 +7,6 @@
|
|||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<meta name="author" content="">
|
<meta name="author" content="">
|
||||||
<link rel="icon" type="image/x-icon" href="/images/ecoBuddy_x32.png"
|
<link rel="icon" type="image/x-icon" href="/images/ecoBuddy_x32.png"
|
||||||
|
|
||||||
|
|
||||||
<!-- Bootstrap core CSS -->
|
<!-- Bootstrap core CSS -->
|
||||||
<link href="/css/bootstrap.css" rel="stylesheet">
|
<link href="/css/bootstrap.css" rel="stylesheet">
|
||||||
<!-- Bootstrap theme -->
|
<!-- Bootstrap theme -->
|
||||||
@@ -35,32 +33,54 @@
|
|||||||
<a class="nav-link" href="#">Link</a>
|
<a class="nav-link" href="#">Link</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</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="col">
|
||||||
<div class="form-floating input-group">
|
<div class="form-floating input-group">
|
||||||
<select name="filter" class="form-select border-3 border-success-subtle" id="filter">
|
<select name="sort" class="form-select border-3 border-success-subtle" id="sort">
|
||||||
<option selected></option>
|
<option value="1" <?php if(isset($_GET['sort']) && $_GET['sort'] == '1') echo 'selected'; ?>>Title</option>
|
||||||
<option value="1">Title</option>
|
<option value="2" <?php if(isset($_GET['sort']) && $_GET['sort'] == '2') echo 'selected'; ?>>Category</option>
|
||||||
<option value="2">Category</option>
|
<option value="0" <?php if(isset($_GET['sort']) && $_GET['sort'] == '0') echo 'selected'; ?>>Status</option>
|
||||||
<option value="0">Status</option>
|
<option value="3" <?php if(isset($_GET['sort']) && $_GET['sort'] == '3') echo 'selected'; ?>>Description</option>
|
||||||
<option value="3">Description</option>
|
<option value="4" <?php if(isset($_GET['sort']) && $_GET['sort'] == '4') echo 'selected'; ?>>Street Name</option>
|
||||||
<option value="4">Street Name</option>
|
<option value="5" <?php if(isset($_GET['sort']) && $_GET['sort'] == '5') echo 'selected'; ?>>County</option>
|
||||||
<option value="5">County</option>
|
<option value="6" <?php if(isset($_GET['sort']) && $_GET['sort'] == '6') echo 'selected'; ?>>Town</option>
|
||||||
<option value="6">Town</option>
|
<option value="7" <?php if(isset($_GET['sort']) && $_GET['sort'] == '7') echo 'selected'; ?>>Postcode</option>
|
||||||
<option value="7">Postcode</option>
|
<option value="8" <?php if(isset($_GET['sort']) && $_GET['sort'] == '8') echo 'selected'; ?>>Contributor</option>
|
||||||
<option value="8">Contributor</option>
|
|
||||||
</select>
|
</select>
|
||||||
<span class="input-group-text bi bi-filter-circle bg-success-subtle border-0 rounded-end" id="filter"></span>
|
<span class="form-floating input-group">
|
||||||
<label for="filter">Column Filter</label>
|
<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>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="form-floating input-group">
|
<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">
|
<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>
|
<button class="btn bg-light bg-success-subtle" type="submit"><span class="bi bi-search"></span></button>
|
||||||
</span>
|
</span>
|
||||||
<label for="search">Search</label>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="row mb-2">
|
<div class="row mb-2">
|
||||||
<!-- Form for Pagination -->
|
<!-- Form for Pagination -->
|
||||||
<div id="paginationButtons" class="col-auto m-auto btn-group">
|
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST" id="paginatorButton" class="col-auto m-auto btn-group">
|
||||||
<!-- Start Button -->
|
<!-- 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="?page=0" <?= $view->pageNumber <= 0 ? 'disabled' : '' ?>><i class="bi bi-chevron-double-left"></i> Start</a>
|
||||||
<!-- Back Button -->
|
<!-- Back Button -->
|
||||||
@@ -9,20 +9,19 @@
|
|||||||
<!-- Dynamic Page Buttons -->
|
<!-- Dynamic Page Buttons -->
|
||||||
<?php
|
<?php
|
||||||
$totalPages = $view->paginator->getTotalPages();
|
$totalPages = $view->paginator->getTotalPages();
|
||||||
var_dump($totalPages);
|
|
||||||
for ($i = $view->pageNumber - 2; $i <= $view->pageNumber + 2; $i++) {
|
for ($i = $view->pageNumber - 2; $i <= $view->pageNumber + 2; $i++) {
|
||||||
if ($i >= 0 && $i < $totalPages): ?>
|
if ($i >= 0 && $i < $totalPages): ?>
|
||||||
<a href="?page=<?= $i ?>"
|
<input name="paginatorButton" type="submit" value='<?= $i ?>'
|
||||||
class="btn <?= $i === $view->pageNumber ? 'btn-dark' : 'btn-outline-primary' ?>"
|
class="btn <?= $i === $view->pageNumber ? 'btn-dark' : 'btn-outline-primary' ?>"
|
||||||
<?= $i === $view->pageNumber ? 'disabled' : '' ?>>
|
<?= $i === $view->pageNumber ? 'disabled' : '' ?>>
|
||||||
<?= $i + 1 ?>
|
<?= $i + 1 ?>
|
||||||
</a>
|
</input>
|
||||||
<?php endif;
|
<?php endif;
|
||||||
} ?>
|
} ?>
|
||||||
<!-- Forward Button -->
|
<!-- 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="?page=<?=min($view->pageNumber + 1, $totalPages)?> " <?= $view->pageNumber >= $totalPages - 1 ? 'disabled' : '' ?>>Forward <i class="bi bi-chevron-right"></i></a>
|
||||||
<!-- End Button -->
|
<!-- 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="?page=<?= $totalPages - 1 ?>"<?= $view->pageNumber >= $totalPages - 1 ? 'disabled' : '' ?>>End <i class="bi bi-chevron-double-right"></i></a>
|
||||||
</div>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -6,6 +6,7 @@ require_once("logincontroller.php");
|
|||||||
$view = new stdClass();
|
$view = new stdClass();
|
||||||
$view->pageTitle = 'Home';
|
$view->pageTitle = 'Home';
|
||||||
|
|
||||||
|
|
||||||
//if (isset($_POST['applyAdvFilters'])) {
|
//if (isset($_POST['applyAdvFilters'])) {
|
||||||
// array_push($filterArray, $_POST['titlFilter'], $_POST['cateFilter'],
|
// array_push($filterArray, $_POST['titlFilter'], $_POST['cateFilter'],
|
||||||
// $description = $_POST['descFilter'], $status = $_POST['statFilter'],
|
// $description = $_POST['descFilter'], $status = $_POST['statFilter'],
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once('Models/FacilityDataSet.php');
|
require_once('Models/FacilityDataSet.php');
|
||||||
require_once("Models/Paginator.php");
|
require_once("Models/Paginator.php");
|
||||||
|
// If page loads empty, set initial headers
|
||||||
if(!isset($_GET['page'])) {
|
if(!isset($_GET['page']) || !(isset($_GET['dir'])) || !(isset($_GET['sort'])) || !(isset($_GET['category']))) {
|
||||||
header("location: ?page=0");
|
header("Location: ?page=0&sort=1&dir=asc&category=1");
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$filterArray = [
|
$filterArray = [
|
||||||
@@ -17,20 +18,35 @@ $filterArray = [
|
|||||||
7 => "",
|
7 => "",
|
||||||
8 => ""
|
8 => ""
|
||||||
];
|
];
|
||||||
|
$sortArray = [
|
||||||
|
0 => "",
|
||||||
|
1 => "",
|
||||||
|
2 => "",
|
||||||
|
3 => "",
|
||||||
|
4 => "",
|
||||||
|
5 => "",
|
||||||
|
6 => "",
|
||||||
|
7 => "",
|
||||||
|
8 => ""
|
||||||
|
];
|
||||||
|
|
||||||
$rowLimit = 5; //$_POST['rowCount'];
|
$rowLimit = 5;
|
||||||
|
|
||||||
$facilityDataSet = new FacilityDataSet();
|
$facilityDataSet = new FacilityDataSet();
|
||||||
|
var_dump($_POST);
|
||||||
if (isset($_POST['applyFilters']) && isset($_POST['filter'])) {
|
if (isset($_POST['filter']) && isset($_POST['filterCat']) && (isset($_POST['dir'])) && (isset($_POST['sort'])) && (isset($_POST['paginationButton']))) {
|
||||||
var_dump($_POST);
|
$filter = filter_input(INPUT_POST, 'filter', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '';
|
||||||
$applyFilters = filter_input(INPUT_POST, 'applyFilters', FILTER_SANITIZE_STRING);
|
$filterKey = filter_input(INPUT_POST, 'filterCat', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '';
|
||||||
$filterKey = filter_input(INPUT_POST, 'filter', FILTER_SANITIZE_STRING);
|
$direction = filter_input(INPUT_POST, 'dir', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? 'asc'; // Default to 'asc'
|
||||||
$filterArray[$filterKey] = $applyFilters;
|
$sortKey = filter_input(INPUT_POST, 'sort', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '1'; // Default to 'title'
|
||||||
|
$page = filter_input(INPUT_POST,'paginationButton', FILTER_SANITIZE_NUMBER_INT) ?? 0; // Default page to 0 on new filter
|
||||||
|
$filterArray[$filterKey] = $filter;
|
||||||
|
$sortArray[$sortKey] = $direction;
|
||||||
// Set the filter and generate the new URI
|
// Set the filter and generate the new URI
|
||||||
$filterSet = $facilityDataSet->setFilterUri($applyFilters, array_search($applyFilters, $filterArray));
|
//$filterSet = $facilityDataSet->setFilterUri($applyFilters, array_search($applyFilters, $filterArray));
|
||||||
|
$filterSet = setUri($filter, array_search($filter, $filterArray), $direction, array_search($direction, $sortArray), $page);
|
||||||
// Parse the existing query string
|
// Parse the existing query string
|
||||||
|
$queryParams = [];
|
||||||
parse_str($filterSet["newUri"], $queryParams);
|
parse_str($filterSet["newUri"], $queryParams);
|
||||||
|
|
||||||
// Add or overwrite the 'page' parameter
|
// Add or overwrite the 'page' parameter
|
||||||
@@ -42,14 +58,16 @@ if (isset($_POST['applyFilters']) && isset($_POST['filter'])) {
|
|||||||
$newQueryString = http_build_query($queryParams);
|
$newQueryString = http_build_query($queryParams);
|
||||||
|
|
||||||
// Redirect with the updated URI
|
// Redirect with the updated URI
|
||||||
|
//var_dump("Redirecting to: {$filterSet["path"]}?{$newQueryString}");
|
||||||
header("Location: {$filterSet["path"]}?{$newQueryString}");
|
header("Location: {$filterSet["path"]}?{$newQueryString}");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$filterArray[$_GET['category'] ?? null] = $_GET['term'] ?? null;
|
$filterArray[$_GET['category'] ?? null] = $_GET['term'] ?? null;
|
||||||
|
$sortArray[$_GET['sort'] ?? null] = $_GET['dir'] ?? null;
|
||||||
|
|
||||||
$view->pageData = $facilityDataSet->fetchAll($filterArray);
|
$view->pageData = $facilityDataSet->fetchAll($filterArray, $sortArray);
|
||||||
$view->paginator = new Paginator($rowLimit, $view->pageData);
|
$view->paginator = new Paginator($rowLimit, $view->pageData);
|
||||||
|
|
||||||
// Initialize paginator
|
// Initialize paginator
|
||||||
@@ -60,3 +78,52 @@ $view->pageData = $view->paginator->getPage($view->pageNumber);
|
|||||||
$view->dbMessage = $view->paginator->countPageResults($view->pageNumber) == 0
|
$view->dbMessage = $view->paginator->countPageResults($view->pageNumber) == 0
|
||||||
? "No results"
|
? "No results"
|
||||||
: $view->paginator->countPageResults($view->pageNumber) . " result(s)";
|
: $view->paginator->countPageResults($view->pageNumber) . " result(s)";
|
||||||
|
|
||||||
|
function setUri($filter, $category, $direction, $sort, $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 sort and filter is already correct
|
||||||
|
if (
|
||||||
|
(isset($params['sort']) && $params['sort'] === (string)$sort && isset($params['dir']) && $params['dir'] === $direction) &&
|
||||||
|
(isset($params['category']) && $params['category'] === (string)$category && isset($params['term']) && $params['term'] === $filter)
|
||||||
|
) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update parameters
|
||||||
|
if (!empty($category)) {
|
||||||
|
$params['category'] = $category;
|
||||||
|
}
|
||||||
|
if (!empty($filter)) {
|
||||||
|
$params['term'] = $filter;
|
||||||
|
}
|
||||||
|
if (!empty($sort)) {
|
||||||
|
$params['sort'] = $sort;
|
||||||
|
}
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$params['dir'] = $direction;
|
||||||
|
}
|
||||||
|
if (!empty($filter)) {
|
||||||
|
$params['page'] = $page;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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'] ?? '/'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user