mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
This commit is contained in:
parent
ae2c8c094f
commit
761493f64e
@ -16,5 +16,6 @@ Object::add_extension('Group', 'GroupSubsites');
|
|||||||
Object::add_extension('Member', 'MemberSubsites');
|
Object::add_extension('Member', 'MemberSubsites');
|
||||||
Object::add_extension('File', 'FileSubsites');
|
Object::add_extension('File', 'FileSubsites');
|
||||||
Object::add_extension('ErrorPage', 'ErrorPageSubsite');
|
Object::add_extension('ErrorPage', 'ErrorPageSubsite');
|
||||||
|
if (class_exists('SiteConfig')) Object::add_extension('SiteConfig', 'SiteConfigSubsites');
|
||||||
|
|
||||||
?>
|
?>
|
38
code/SiteConfigSubsites.php
Normal file
38
code/SiteConfigSubsites.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extension for the SiteConfig object to add subsites support
|
||||||
|
*/
|
||||||
|
class SiteConfigSubsites extends DataObjectDecorator {
|
||||||
|
function extraStatics() {
|
||||||
|
return array(
|
||||||
|
'has_one' => array(
|
||||||
|
'Subsite' => 'Subsite', // The subsite that this page belongs to
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update any requests to limit the results to the current site
|
||||||
|
*/
|
||||||
|
function augmentSQL(SQLQuery &$query) {
|
||||||
|
if(Subsite::$disable_subsite_filter) return;
|
||||||
|
|
||||||
|
// If you're querying by ID, ignore the sub-site - this is a bit ugly...
|
||||||
|
if (!$query->where || (!preg_match('/\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]))) {
|
||||||
|
|
||||||
|
if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
|
||||||
|
else $subsiteID = (int)Subsite::currentSubsiteID();
|
||||||
|
|
||||||
|
$tableName = array_shift(array_keys($query->from));
|
||||||
|
if($tableName != 'SiteConfig') return;
|
||||||
|
$query->where[] = "`$tableName`.SubsiteID IN ($subsiteID)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function augmentBeforeWrite() {
|
||||||
|
if((!is_numeric($this->owner->ID) || !$this->owner->ID) && !$this->owner->SubsiteID) {
|
||||||
|
$this->owner->SubsiteID = Subsite::currentSubsiteID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user