added functionality for CRUD
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user