|
|
@@ -21,34 +21,37 @@ if($submit) {
|
|
|
$form_exception = new FormException;
|
|
|
|
|
|
$location->name = http::value("name", "trim");
|
|
|
- $location->address_1 = http::value("address", "trim");
|
|
|
+ $location->address_1 = http::value("address_1", "trim");
|
|
|
+ $location->address_2 = http::value("address_2", "trim");
|
|
|
+ $location->city = http::value("city", "trim");
|
|
|
+ $location->county = http::value("county", "trim");
|
|
|
+ $location->postal_code = http::value("postal_code", "trim");
|
|
|
+
|
|
|
+ $location->shop_left = http::value("shop_left", "trim");
|
|
|
+ $location->shop_right = http::value("shop_right", "trim");
|
|
|
|
|
|
if(empty($location->name)) $form_exception->addError("Name is required.");
|
|
|
- if(empty($location->address_1)) {
|
|
|
- $form_exception->addError("Full address is required.");
|
|
|
- }
|
|
|
- else {
|
|
|
- // Geocode the full address
|
|
|
- try {
|
|
|
- $results = Geolocation::geocode($location->address_1);
|
|
|
-
|
|
|
- $result = $results[0];
|
|
|
-
|
|
|
- foreach($result->address_components as $component) {
|
|
|
- $types = $component->types;
|
|
|
- if(in_array("postal_code", $types)) $location->postal_code = $component->long_name;
|
|
|
- if(in_array("route", $types)) $location->address_1 = $component->long_name;
|
|
|
- if(in_array("postal_town", $types)) $location->city = $component->long_name;
|
|
|
- if(in_array("administrative_area_level_1", $types)) $location->state = $component->long_name;
|
|
|
- if(in_array("country", $types)) $location->country = $component->long_name;
|
|
|
- }
|
|
|
-
|
|
|
- $location->latitude = $result->geometry->location->lat;
|
|
|
- $location->longitude = $result->geometry->location->lng;
|
|
|
- }
|
|
|
- catch(Exception $e) {
|
|
|
- $form_exception->addError("Failed to get location from full address: " . $e->getMessage());
|
|
|
+ if(empty($location->address_1)) $form_exception->addError("Location line 1 is required.");
|
|
|
+ if(empty($location->city)) $form_exception->addError("City is required.");
|
|
|
+ if(empty($location->postal_code)) $form_exception->addError("Postal code is required.");
|
|
|
+
|
|
|
+ // Geocode
|
|
|
+ try {
|
|
|
+ $results = Geolocation::geocode($location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]));
|
|
|
+
|
|
|
+ $result = $results[0];
|
|
|
+
|
|
|
+ foreach($result->address_components as $component) {
|
|
|
+ $types = $component->types;
|
|
|
+ if(in_array("administrative_area_level_1", $types)) $location->state = $component->long_name;
|
|
|
+ if(in_array("country", $types)) $location->country = $component->long_name;
|
|
|
}
|
|
|
+
|
|
|
+ $location->latitude = $result->geometry->location->lat;
|
|
|
+ $location->longitude = $result->geometry->location->lng;
|
|
|
+ }
|
|
|
+ catch(Exception $e) {
|
|
|
+ $form_exception->addError("Failed to get latitude/longitude from address.");
|
|
|
}
|
|
|
|
|
|
if($form_exception->hasErrors()) throw $form_exception;
|
|
|
@@ -57,7 +60,7 @@ if($submit) {
|
|
|
if(!$success) throw new Exception("Failed to add location at this time. Please try again later.");
|
|
|
|
|
|
Core::addAlert("success", "Location added successfully.");
|
|
|
- HTTP::redirect("/account/locations/$location->id");
|
|
|
+ HTTP::redirect("/account/locations/$location->id/edit");
|
|
|
}
|
|
|
catch(FormException $e) {
|
|
|
$e->generateAlerts();
|
|
|
@@ -68,7 +71,7 @@ if($submit) {
|
|
|
}
|
|
|
|
|
|
View::includeOnce("header", compact("page_title"));
|
|
|
-View::include("location_add_form", compact("location"));
|
|
|
+View::include("location_form", compact("location"));
|
|
|
View::includeOnce("footer");
|
|
|
|
|
|
?>
|