Recoded how the Auto-complete subdivision search worked in php and js
This commit is contained in:
@@ -237,6 +237,7 @@ class PermitsBySubdivision extends Base {
|
||||
$statement->bindValue(":permit_permit_end_date", $permit_permit_end_date);
|
||||
}
|
||||
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$recordset = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
@@ -339,6 +340,9 @@ class PermitsBySubdivision extends Base {
|
||||
$statement->bindValue(":limit", $this->pagination_size, PDO::PARAM_INT);
|
||||
$statement->bindValue(":offset", $offset, PDO::PARAM_INT);
|
||||
|
||||
// echo $projecttype;
|
||||
// die();
|
||||
|
||||
$statement->execute();
|
||||
|
||||
$permits = $this->getTableXML("permits", $statement);
|
||||
@@ -427,29 +431,108 @@ class PermitsBySubdivision extends Base {
|
||||
return $this->getTable("permits", $SQL);
|
||||
}
|
||||
|
||||
// // ================================
|
||||
// // Return AutoComplete Names (ajax)
|
||||
// // ================================
|
||||
//
|
||||
// public function getAutoCompleteSubdivisions() {
|
||||
//
|
||||
// $this->debug($_GET);
|
||||
//
|
||||
// $results = array();
|
||||
//
|
||||
// $subscription_serial = filter_input(INPUT_GET, "subscription_serial") ?: "";
|
||||
//
|
||||
// $subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
||||
//
|
||||
// if ($subscription->count() == 0) {
|
||||
// $this->logError("Invalid Subscription ({$subscription_serial}). " . __METHOD__);
|
||||
// }
|
||||
//
|
||||
// $permit_area = $subscription->record->subscription_area;
|
||||
// $projecttype = $subscription->record->subscription_projecttype;
|
||||
//
|
||||
// $subdivision = filter_input(INPUT_GET, "permit_sub_div_name") ?: "";
|
||||
// $subdivision = trim(preg_replace("/\s+/", " ", $subdivision));
|
||||
// $subdivision = preg_replace("/'+/", "'", $subdivision);
|
||||
// $subdivision = preg_replace('/"+/', '"', $subdivision);
|
||||
// $subdivision = str_replace("'", "''", $subdivision);
|
||||
//
|
||||
// $SQL = "select distinct permit_sub_div_name from view_permits where permit_project_type = '{$projecttype}' and permit_sub_div_name like '%{$subdivision}%'";
|
||||
//
|
||||
// if ($permit_area != "All") {
|
||||
// $SQL .= " and view_permits.permit_county in (select county_serial from view_counties where county_area = '{$permit_area}')";
|
||||
// }
|
||||
//
|
||||
// $SQL .= "order by permit_sub_div_name limit 20 offset 0";
|
||||
//
|
||||
// $matches = $this->getTable("subdivisions", $SQL);
|
||||
//
|
||||
// foreach ($matches as $match) {
|
||||
// $results[] = (string) $match->permit_sub_div_name;
|
||||
// }
|
||||
//
|
||||
// header('Content-Type: application/json');
|
||||
// echo json_encode($results);
|
||||
// exit();
|
||||
// }
|
||||
// ================================
|
||||
// Return AutoComplete Names (ajax)
|
||||
// ================================
|
||||
|
||||
public function getAutoCompleteSubdivisions() {
|
||||
|
||||
$results = array();
|
||||
$results = [];
|
||||
|
||||
$subdivision = filter_input(INPUT_GET, "permit_sub_div_name") ?: "";
|
||||
$subdivision = trim(preg_replace("/\s+/", " ", $subdivision));
|
||||
$subdivision = preg_replace("/'+/", "'", $subdivision);
|
||||
$subdivision = preg_replace('/"+/', '"', $subdivision);
|
||||
$subdivision = str_replace("'", "''", $subdivision);
|
||||
$subscription_serial = filter_input(INPUT_GET, "subscription_serial", FILTER_SANITIZE_NUMBER_INT) ?: 0;
|
||||
$subdivision = filter_input(INPUT_GET, "permit_sub_div_name", FILTER_SANITIZE_SPECIAL_CHARS) ?: "";
|
||||
|
||||
$SQL = "select distinct permit_sub_div_name from view_permits where permit_sub_div_name like '%{$subdivision}%' order by permit_sub_div_name limit 10 offset 0";
|
||||
$subscription = (new Subscriptions())->getSubscription($subscription_serial);
|
||||
|
||||
$matches = $this->getTable("subdivisions", $SQL);
|
||||
if ($subscription->count() == 0) {
|
||||
$this->logError("Invalid Subscription ({$subscription_serial}). " . __METHOD__);
|
||||
|
||||
foreach ($matches as $match) {
|
||||
$results[] = (string) $match->permit_sub_div_name;
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode($results);
|
||||
exit();
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
$permit_area = $subscription->record->subscription_area;
|
||||
$projecttype = $subscription->record->subscription_projecttype;
|
||||
|
||||
$subdivision = trim(preg_replace("/\s+/", " ", $subdivision));
|
||||
|
||||
$SQL = "select distinct permit_sub_div_name
|
||||
from view_permits
|
||||
where permit_project_type = :projecttype
|
||||
and permit_sub_div_name like :subdivision";
|
||||
|
||||
if ($permit_area != "All") {
|
||||
$SQL .= " and permit_county in (
|
||||
select county_serial
|
||||
from view_counties
|
||||
where county_area = :permit_area
|
||||
)";
|
||||
}
|
||||
|
||||
$SQL .= " order by permit_sub_div_name limit 20 offset 0";
|
||||
|
||||
$statement = $this->connect()->prepare($SQL);
|
||||
|
||||
$statement->bindValue(":projecttype", $projecttype, PDO::PARAM_STR);
|
||||
$statement->bindValue(":subdivision", "%{$subdivision}%", PDO::PARAM_STR);
|
||||
|
||||
if ($permit_area != "All") {
|
||||
$statement->bindValue(":permit_area", $permit_area, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
$statement->execute();
|
||||
|
||||
while ($record = $statement->fetch(PDO::FETCH_OBJ)) {
|
||||
$results[] = (string) $record->permit_sub_div_name;
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode($results);
|
||||
exit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user