From 6b875be47ff4c2dd1c3ccbb63b5d5ef30c62bda4 Mon Sep 17 00:00:00 2001 From: muskie9 Date: Fri, 23 Jan 2015 11:09:54 -0600 Subject: [PATCH] Revert locator to non-relation (single locator page) --- code/Location.php | 11 ++--------- code/Locator.php | 22 +++++----------------- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/code/Location.php b/code/Location.php index ec8bfbf..503e022 100644 --- a/code/Location.php +++ b/code/Location.php @@ -12,8 +12,7 @@ class Location extends DataObject implements PermissionProvider{ ); static $has_one = array( - 'Category' => 'LocationCategory', - 'Locator' => 'Locator' + 'Category' => 'LocationCategory' ); static $casting = array( @@ -121,9 +120,7 @@ public function getCMSFields() { public function validate() { $result = parent::validate(); - if(Locator::getMultipleLocators() && $this->LocatorID == 0) { - $result->error('You must associate this location with a locator page. Add the location from the desired locator page.'); - } + return $result; } @@ -159,10 +156,6 @@ public function providePermissions() { public function onBeforeWrite(){ - if(Locator::get()->count() == 1){ - $this->LocatorID = Locator::get()->first()->ID; - } - parent::onBeforeWrite(); } diff --git a/code/Locator.php b/code/Locator.php index 6cf15e5..d9ae953 100644 --- a/code/Locator.php +++ b/code/Locator.php @@ -8,9 +8,7 @@ class Locator extends Page { 'Unit' => 'Enum("km,m","m")' ); - private static $has_many = array( - 'Locations' => 'Location' - ); + private static $has_many = array(); private static $defaults = array( 'AutoGeocode' => true @@ -24,9 +22,8 @@ public function getCMSFields() { $fields = parent::getCMSFields(); // Locations Grid Field - $config = (self::getMultipleLocators()) - ? GridFieldConfig_RelationEditor::create() : GridFieldConfig_RecordEditor::create(); - $locations = (self::getMultipleLocators()) ? $this->Locations() : Location::get(); + $config = GridFieldConfig_RecordEditor::create(); + $locations = Location::get(); $fields->addFieldToTab("Root.Locations", GridField::create("Locations", "Locations", $locations, $config)); // Location categories @@ -59,10 +56,6 @@ public function getAreLocations(){ return self::getLocations(); } - public static function getMultipleLocators(){ - return (Locator::get()->count() > 1) ? true : false; - } - public function getAllCategories(){ return LocationCategory::get(); } @@ -116,7 +109,6 @@ public function init() { $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; $link = $this->Link() . "xml.xml"; - $link .= (Locator::getMultipleLocators()) ? "?locatorID=" . $this->data()->ID : "" ; // init map if(Locator::getLocations()) { @@ -153,14 +145,10 @@ public function init() { * @access public * @return XML file * @todo rename/refactor to allow for json/xml + * @todo allow $filter to run off of getVars key/val pair */ public function xml(SS_HTTPRequest $request) { $filter = array(); - if(Locator::getMultipleLocators()){//only checks published locators - if($request->getVar('locatorID')){ - $filter['LocatorID'] = $request->getVar('locatorID'); - } - } $Locations = Locator::getLocations($filter); return $this->customise(array( @@ -186,7 +174,7 @@ public function LocationSearch() { if (LocationCategory::get()->Count() > 0) { - $filter = ($this->data()->getMultipleLocators()) ? array('LocatorID' => $this->data()->ID) : array(); + $filter = array(); $locals = Locator::getLocations($filter, $exclude = array('CategoryID' => 0)); //debug::show($locals); $categories = ArrayList::create();