Skip to content

Commit

Permalink
Merge pull request #53 from muskie9/locatorRevert
Browse files Browse the repository at this point in the history
Revert locator to non-relation (single locator page)
  • Loading branch information
muskie9 committed Jan 23, 2015
2 parents f2262d4 + 6b875be commit 7742e23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
11 changes: 2 additions & 9 deletions code/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class Location extends DataObject implements PermissionProvider{
);

static $has_one = array(
'Category' => 'LocationCategory',
'Locator' => 'Locator'
'Category' => 'LocationCategory'
);

static $casting = array(
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -159,10 +156,6 @@ public function providePermissions() {

public function onBeforeWrite(){

if(Locator::get()->count() == 1){
$this->LocatorID = Locator::get()->first()->ID;
}

parent::onBeforeWrite();
}

Expand Down
22 changes: 5 additions & 17 deletions code/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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(
Expand All @@ -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();
Expand Down

0 comments on commit 7742e23

Please sign in to comment.