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

@@ -12,13 +12,11 @@ class FacilityDataSet {
/**
* @param $filterArray
* @param $rowCount
* @param $offset
* @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, $rowCount, $offset): array
public function fetchAll($filterArray): array
{
/**
* COUNT(DISTINCT ecoFacilities.id) required due to multiple status comments possible.
@@ -81,7 +79,7 @@ class FacilityDataSet {
$countQuery = $sqlCount . $sqlWhere . ";";
// Prepare, bind and execute data query
$stmt = $this->populateFields($dataQuery, $rowCount, $offset, $filterArray);
$stmt = $this->populateFields($dataQuery, $filterArray);
$stmt->execute();
// Create data objects
@@ -91,7 +89,7 @@ class FacilityDataSet {
}
// Prepare, bind then execute count query
$stmt = $this->populateFields($countQuery, null, null, $filterArray);
$stmt = $this->populateFields($countQuery, $filterArray);
$stmt->execute();
$totalCount = $stmt->fetch()['total'];
@@ -103,14 +101,12 @@ class FacilityDataSet {
/**
* @param $sqlQuery
* @param $rowCount
* @param $offset
* @param $filterArray
* @return false|PDOStatement
* 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, $rowCount, $offset, $filterArray)
private function populateFields($sqlQuery, $filterArray)
{
$stmt = $this->_dbHandle->prepare($sqlQuery);
// Ensures only one value is returned per column name
@@ -129,13 +125,41 @@ class FacilityDataSet {
$value = !empty($filterArray[$i]) ? "%" . $filterArray[$i] . "%" : "%";
$stmt->bindValue($bindIndex++, $value, \PDO::PARAM_STR);
}
// Bind LIMIT and OFFSET
if (!$rowCount == null || !$offset == null) {
$stmt->bindValue(':limit', $rowCount, \PDO::PARAM_INT); // LIMIT ?
$stmt->bindValue(':offset', $offset, \PDO::PARAM_INT); // OFFSET ?
}
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'] ?? '/'
]; }
}