mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
[Station profile] US Counties dropdown added
This commit is contained in:
@@ -135,4 +135,37 @@ class Station extends CI_Controller {
|
||||
redirect('station');
|
||||
}
|
||||
|
||||
/*
|
||||
* Function is used for autocompletion of Counties in the station profile form
|
||||
*/
|
||||
public function get_county() {
|
||||
$json = [];
|
||||
|
||||
if(!empty($this->input->get("query"))) {
|
||||
$query = isset($_GET['query']) ? $_GET['query'] : FALSE;
|
||||
$county = $this->input->get("state");
|
||||
|
||||
$file = 'assets/json/US_counties.csv';
|
||||
|
||||
if (is_readable($file)) {
|
||||
$lines = file($file, FILE_IGNORE_NEW_LINES);
|
||||
$input = preg_quote($county, '~');
|
||||
$reg = '~^'. $input .'(.*)$~';
|
||||
$result = preg_grep($reg, $lines);
|
||||
$json = [];
|
||||
$i = 0;
|
||||
foreach ($result as &$value) {
|
||||
$county = explode(',', $value);
|
||||
// Limit to 100 as to not slowdown browser too much
|
||||
if (count($json) <= 100) {
|
||||
$json[] = ["name"=>$county[1]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($json);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user