added functionality for CRUD

This commit is contained in:
boris
2024-12-02 20:33:27 +00:00
parent 00a29b9db7
commit 214bfe20ac

View File

@@ -10,6 +10,49 @@ class FacilityDataSet {
$this->_dbHandle = $this->_dbInstance->getDbConnection(); $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 * @param $filterArray
* @return array * @return array