This commit is contained in:
Tom Rix 2010-03-01 03:01:50 +00:00
parent 3bde3f1f60
commit 48e92f4e39
4 changed files with 91 additions and 3 deletions

View File

@ -124,6 +124,12 @@ class LeftAndMainSubsites extends Extension {
function augmentNewSiteTreeItem(&$item) {
$item->SubsiteID = Subsite::currentSubsiteID();
}
function onAfterSave($record) {
if($record->hasMethod('RelatedPages') && $record->RelatedPages()) {
FormResponse::status_message('Saved, please update related pages.', 'good');
}
}
}

62
code/RelatedPageLink.php Normal file
View File

@ -0,0 +1,62 @@
<?php
/**
* This DataObject only exists to provide a link between related pages.
* Unfortunately, there is no way to provide a decent GUI otherwise.
*/
class RelatedPageLink extends DataObject {
static $db = array(
);
static $has_one = array(
'MasterPage' => 'SiteTree',
'RelatedPage' => 'SiteTree'
);
function getCMSFields() {
$subsites = Subsite::getSubsitesForMember();
if(!$subsites) $subsites = new DataObjectSet();
if(Subsite::hasMainSitePermission()) {
$subsites->push(new ArrayData(array('Title' => 'Main site', 'ID' => 0)));
}
if($subsites->Count()) {
$subsiteSelectionField = new DropdownField(
"CopyContentFromID_SubsiteID",
"Subsite",
$subsites->toDropdownMap('ID', 'Title'),
($this->CopyContentFromID) ? $this->CopyContentFrom()->SubsiteID : Session::get('SubsiteID')
);
}
// Setup the linking to the original page.
$pageSelectionField = new SubsitesTreeDropdownField(
"RelatedPageID",
_t('VirtualPage.CHOOSE', "Choose a page to link to"),
"SiteTree",
"ID",
"MenuTitle"
);
$pageSelectionField->setFilterFunction(create_function('$item', 'return $item->ClassName != "VirtualPage";'));
if($subsites->Count()) {
$fields = new FieldSet(
$subsiteSelectionField,
$pageSelectionField
);
} else {
$fields = new FieldSet(
$pageSelectionField
);
}
return $fields;
}
function RelatedPageAdminLink() {
return '<a href="admin/show/' . $this->RelatedPage()->ID . '" class="externallink" >' . Convert::raw2xml($this->RelatedPage()->Title) . '</a>';
}
}
?>

View File

@ -34,7 +34,10 @@ class SiteTreeSubsites extends SiteTreeDecorator {
return array(
'has_one' => array(
'Subsite' => 'Subsite', // The subsite that this page belongs to
'MasterPage' => 'SiteTree', // Optional; the page that is the content master
'MasterPage' => 'SiteTree',// Optional; the page that is the content master
),
'has_many' => array(
'RelatedPages' => 'SiteTree'
)
);
}
@ -150,6 +153,23 @@ class SiteTreeSubsites extends SiteTreeDecorator {
'URLSegment'
);
}
// Related pages
$fields->addFieldToTab(
'Root.Related',
new LiteralField('RelatedNote', '<p>You can list pages here that are related to this page.<br />When this page is updated, you will get a reminder to check whether these related pages need to be updated as well.</p>')
);
$fields->addFieldToTab(
'Root.Related',
$related = new ComplexTableField(
$this,
'RelatedPages',
'RelatedPageLink',
array(
'RelatedPageAdminLink' => 'Page'
)
)
);
}
/**

View File

@ -464,8 +464,8 @@ JS;
return DataObject::get(
'Subsite',
"{$q}Group_Members{$q}.{$q}MemberID{$q} = $member->ID
AND {$q}Permission{$q}.{$q}Code{$q} IN ($SQL_codes, 'ADMIN')
AND ({$q}Subdomain{$q} IS NOT NULL OR {$q}Subsite{$q}.{$q}ClassName{$q} IN ($templateClassList)) AND {$q}Subsite{$q}.{$q}Title{$q} != ''",
AND {$q}Permission{$q}.{$q}Code{$q} IN ($SQL_codes, 'ADMIN', 'SUBSITE_ACCESS_ALL')
AND {$q}Subsite{$q}.{$q}Title{$q} != ''",
'',
"LEFT JOIN {$q}Group{$q} ON ({$q}SubsiteID{$q} = {$q}Subsite{$q}.{$q}ID{$q} OR {$q}SubsiteID{$q} = 0)
LEFT JOIN {$q}Group_Members{$q} ON {$q}Group_Members{$q}.{$q}GroupID{$q} = {$q}Group{$q}.{$q}ID{$q}