LeftAndMainSubsites failover if map() returns an array instead of an SS_Map

This commit is contained in:
Sean Harvey 2012-10-12 11:05:00 +13:00
parent 070eaf54ae
commit 19a904d1d2

View File

@ -131,7 +131,9 @@ class LeftAndMainSubsites extends Extension {
return true; //admin can access all subsites return true; //admin can access all subsites
} }
$sites = Subsite::accessible_sites("CMS_ACCESS_{$this->owner->class}")->map('ID', 'Title')->toArray(); $sites = Subsite::accessible_sites("CMS_ACCESS_{$this->owner->class}")->map('ID', 'Title');
if(is_object($sites)) $sites = $sites->toArray();
if($sites && !isset($sites[Subsite::currentSubsiteID()])) { if($sites && !isset($sites[Subsite::currentSubsiteID()])) {
$siteIDs = array_keys($sites); $siteIDs = array_keys($sites);
Subsite::changeSubsite($siteIDs[0]); Subsite::changeSubsite($siteIDs[0]);
@ -142,20 +144,21 @@ class LeftAndMainSubsites extends Extension {
$menu = CMSMenu::get_menu_items(); $menu = CMSMenu::get_menu_items();
foreach($menu as $candidate) { foreach($menu as $candidate) {
if($candidate->controller != $this->owner->class) { if($candidate->controller != $this->owner->class) {
$sites = Subsite::accessible_sites("CMS_ACCESS_{$candidate->controller}")->map('ID', 'Title');
$sites = Subsite::accessible_sites("CMS_ACCESS_{$candidate->controller}")->map('ID', 'Title')->toArray(); if(is_object($sites)) $sites = $sites->toArray();
if($sites && !isset($sites[Subsite::currentSubsiteID()])) { if($sites && !isset($sites[Subsite::currentSubsiteID()])) {
$siteIDs = array_keys($sites); $siteIDs = array_keys($sites);
Subsite::changeSubsite($siteIDs[0]); Subsite::changeSubsite($siteIDs[0]);
$cClass = $candidate->controller; $cClass = $candidate->controller;
$cObj = new $cClass(); $cObj = new $cClass();
$this->owner->redirect($cObj->Link()); Director::redirect($cObj->Link());
return null; return null;
} }
} }
} }
// If all of those fail, you really don't have access to the CMS // If all of those fail, you really don't have access to the CMS
return null; return null;
} }
@ -169,7 +172,4 @@ class LeftAndMainSubsites extends Extension {
} }
} }
} }
?>