Improvements

This commit is contained in:
Matteo Gheza 2021-05-04 15:31:10 +02:00
parent c10da0dacc
commit 59c24857a2
2 changed files with 30 additions and 2 deletions

View File

@ -270,6 +270,25 @@ class tools
}
return $place;
}
public function savePlaceReverse($place){
if(strpos($place, ";") === false) return 0;
$lat = explode(";", $place)[0];
$lng = explode("#", explode(";", $place)[1])[0];
$url = sprintf("https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=%s&lon=%s", $lat, $lng);
$options = ['http' => [
'user_agent' => 'AllertaVVF dev version (place info downloader)'
]];
$context = stream_context_create($options);
$data = file_get_contents($url, false, $context);
$this->db->insert(
DB_PREFIX."_places_info",
["reverse_json" => $data]
);
return $this->db->getLastInsertId();
}
}
class options
@ -713,7 +732,7 @@ class crud
$date = date('Y-m-d H:i:s', strtotime($date));
$this->db->insert(
DB_PREFIX."_services",
["date" => $date, "code" => $code, "beginning" => $beginning, "end" => $end, "chief" => $chief, "drivers" => $drivers, "crew" => $crew, "place" => $place, "notes" => $notes, "type" => $type, "increment" => $increment, "inserted_by" => $inserted_by]
["date" => $date, "code" => $code, "beginning" => $beginning, "end" => $end, "chief" => $chief, "drivers" => $drivers, "crew" => $crew, "place" => $place, "place_reverse" => $this->tools->savePlaceReverse($place), "notes" => $notes, "type" => $type, "increment" => $increment, "inserted_by" => $inserted_by]
);
$this->increment_services($increment);
$this->user->log("Service added");
@ -746,7 +765,7 @@ class crud
$date = date('Y-m-d H:i:s', strtotime($date));
$this->db->insert(
DB_PREFIX."_trainings",
["date" => $date, "name" => $name, "beginning" => $start_time, "end" => $end_time, "chief" => $chief, "crew" => $crew, "place" => $place, "notes" => $notes, "increment" => $increment, "inserted_by" => $inserted_by]
["date" => $date, "name" => $name, "beginning" => $start_time, "end" => $end_time, "chief" => $chief, "crew" => $crew, "place" => $place, "place_reverse" => $this->tools->savePlaceReverse($place), "notes" => $notes, "increment" => $increment, "inserted_by" => $inserted_by]
);
$this->increment_trainings($increment);
$this->user->log("Training added");

View File

@ -270,6 +270,7 @@ CREATE TABLE IF NOT EXISTS `{$prefix}_trainings` (
`crew` text NOT NULL,
`chief` text NOT NULL,
`place` text NOT NULL,
`place_reverse` int(11) NOT NULL,
`notes` text NOT NULL,
`increment` varchar(999) NOT NULL,
`inserted_by` varchar(200) NOT NULL,
@ -287,6 +288,7 @@ CREATE TABLE IF NOT EXISTS `{$prefix}_services` (
`drivers` varchar(999) NOT NULL,
`crew` varchar(999) NOT NULL,
`place` varchar(999) NOT NULL,
`place_reverse` int(11) NOT NULL,
`notes` varchar(999) NOT NULL,
`type` text NOT NULL,
`increment` varchar(999) NOT NULL,
@ -467,6 +469,13 @@ CREATE TABLE `{$prefix}_schedules` (
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET=latin1;
EOL);
$db->exec(<<<"EOL"
CREATE TABLE `{$prefix}_places_info` (
`id` INT NOT NULL AUTO_INCREMENT,
`reverse_json` VARCHAR(20000) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET=latin1;
EOL);
$db->exec("INSERT INTO `{$prefix}_dbversion` (`version`, `timestamp`) VALUES('1', current_timestamp());");
} catch (Exception $e) {
if(is_cli()) {