ENHANCEMENT: Groups can now be associated to multiple subsites. (from r89791) (from r96313)

This commit is contained in:
Tom Rix 2010-03-01 22:17:51 +00:00
parent d399b49df4
commit e3c51b2a89
3 changed files with 6 additions and 27 deletions

View File

@ -113,20 +113,13 @@ class GroupSubsites extends DataObjectDecorator implements PermissionProvider {
if(Subsite::$disable_subsite_filter) return;
if(Cookie::get('noSubsiteFilter') == 'true') return;
$q = defined('Database::USE_ANSI_SQL') ? "\"" : "`";
// If you're querying by ID, ignore the sub-site - this is a bit ugly...
if(!$query->filtersOnID()) {
if($context = DataObject::context_obj()) $subsiteID = (int) $context->SubsiteID;
else $subsiteID = (int) Subsite::currentSubsiteID();
// The foreach is an ugly way of getting the first key :-)
foreach($query->from as $tableName => $info) {
$where = "{$q}$tableName{$q}.{$q}SubsiteID{$q} IN (0, $subsiteID)";
$query->where[] = $where;
break;
}
if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
else $subsiteID = (int)Subsite::currentSubsiteID();
// Don't filter by Group_Subsites if we've already done that
$hasGroupSubsites = false;
@ -134,7 +127,7 @@ class GroupSubsites extends DataObjectDecorator implements PermissionProvider {
$hasGroupSubsites = true;
break;
}
if(!$hasGroupSubsites) {
if($subsiteID) {
$query->leftJoin("Group_Subsites", "{$q}Group_Subsites{$q}.{$q}GroupID{$q}
@ -147,7 +140,7 @@ class GroupSubsites extends DataObjectDecorator implements PermissionProvider {
$query->where[] = "{$q}Group{$q}.{$q}AccessAllSubsites{$q} = 1";
}
}
$query->orderby = "\"SubsiteID\"" . ($query->orderby ? ', ' : '') . $query->orderby;
$query->orderby = "{$q}AccessAllSubsites{$q} DESC" . ($query->orderby ? ', ' : '') . $query->orderby;
}
}
@ -218,6 +211,7 @@ class GroupSubsites extends DataObjectDecorator implements PermissionProvider {
)
);
}
}
?>

View File

@ -9,24 +9,10 @@ class LeftAndMainSubsites extends Extension {
'changesubsite',
);
function init() {
function augmentInit() {
Requirements::css('subsites/css/LeftAndMain_Subsites.css');
Requirements::javascript('subsites/javascript/LeftAndMain_Subsites.js');
Requirements::javascript('subsites/javascript/VirtualPage_Subsites.js');
// Switch to the subsite of the current page
if ($this->owner->class == 'CMSMain' && $currentPage = $this->owner->currentPage()) {
if (Subsite::currentSubsiteID() != $currentPage->SubsiteID) {
Subsite::changeSubsite($currentPage->SubsiteID);
}
}
// Switch to a subsite that this user can actually access.
$sites = Subsite::accessible_sites("CMS_ACCESS_{$this->owner->class}")->toDropdownMap();
if($sites && !isset($sites[Subsite::currentSubsiteID()])) {
$siteIDs = array_keys($sites);
Subsite::changeSubsite($siteIDs[0]);
}
}
/**

View File

@ -635,7 +635,6 @@ class Subsite_Template extends Subsite {
* Copy groups from the template to the given subsites. Each of the groups will be created and left
* empty.
*/
$groups = $this->Groups();
if($groups) foreach($groups as $group) {
$group->duplicateToSubsite($intranet);