2010-03-01 04:01:50 +01:00
|
|
|
<?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(
|
2010-03-01 22:26:49 +01:00
|
|
|
'RelatedPage' => 'SiteTree',
|
|
|
|
// Note: The *last* matching has_one relation to SiteTree is used as the link field for the
|
|
|
|
// has_many (RelatedPages) on SiteTree. This isn't obvious and the framework could be
|
|
|
|
// extended in a future version to allow for explicit selection of a has_one relation to
|
|
|
|
// bind a has_many to.
|
2010-03-01 04:01:50 +01:00
|
|
|
'MasterPage' => 'SiteTree',
|
|
|
|
);
|
|
|
|
|
|
|
|
function getCMSFields() {
|
2010-03-01 23:08:32 +01:00
|
|
|
$subsites = Subsite::accessible_sites("CMS_ACCESS_CMSMain");
|
2010-03-01 04:01:50 +01:00
|
|
|
if(!$subsites) $subsites = new DataObjectSet();
|
2010-03-01 22:54:36 +01:00
|
|
|
|
2010-03-01 23:08:32 +01:00
|
|
|
if(Subsite::hasMainSitePermission(null, array("CMS_ACCESS_CMSMain"))) {
|
2010-03-01 22:54:36 +01:00
|
|
|
$subsites->push(new ArrayData(array('Title' => 'Main site', "\"ID\"" => 0)));
|
|
|
|
}
|
2010-03-01 04:01:50 +01:00
|
|
|
|
|
|
|
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"
|
|
|
|
);
|
2010-03-01 04:05:13 +01:00
|
|
|
|
2010-03-31 00:50:37 +02:00
|
|
|
if (isset($_GET['RelatedPageID_SubsiteID'])) $pageSelectionField->setSubsiteID($_GET['RelatedPageID_SubsiteID']);
|
2010-03-01 04:01:50 +01:00
|
|
|
|
|
|
|
$pageSelectionField->setFilterFunction(create_function('$item', 'return $item->ClassName != "VirtualPage";'));
|
|
|
|
|
2010-03-31 00:50:37 +02:00
|
|
|
if($subsites->Count()) $fields = new FieldSet($subsiteSelectionField, $pageSelectionField);
|
|
|
|
else $fields = new FieldSet($pageSelectionField);
|
2010-03-01 04:01:50 +01:00
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
2010-03-01 22:38:38 +01:00
|
|
|
function RelatedPageAdminLink($master = false) {
|
2010-03-21 23:32:22 +01:00
|
|
|
$page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID) : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
|
|
|
|
$otherPage = $master ? Dataobject::get_by_id("SiteTree", $this->RelatedPageID) : Dataobject::get_by_id("SiteTree", $this->MasterPageID);
|
2011-08-30 08:41:13 +02:00
|
|
|
if(!$page || !$otherPage) return;
|
2010-03-01 22:38:38 +01:00
|
|
|
|
|
|
|
// Use cmsEditlink only when moving between different pages in the same subsite.
|
|
|
|
$classClause = ($page->SubsiteID == $otherPage->SubsiteID) ? ' class="cmsEditlink"' : '';
|
|
|
|
return '<a href="admin/show/' . $page->ID . "\"$classClause>" . Convert::raw2xml($page->Title) . '</a>';
|
2010-03-01 04:01:50 +01:00
|
|
|
}
|
2010-03-01 23:09:55 +01:00
|
|
|
|
2010-03-01 22:38:38 +01:00
|
|
|
function AbsoluteLink($master = false) {
|
2010-03-21 23:32:22 +01:00
|
|
|
$page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID) : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
|
2010-03-01 22:38:38 +01:00
|
|
|
if(!$page) return;
|
|
|
|
|
|
|
|
|
|
|
|
$url = $page->AbsoluteLink();
|
2010-03-01 22:38:19 +01:00
|
|
|
}
|
|
|
|
|
2010-03-01 23:21:48 +01:00
|
|
|
function canView($member = null) {
|
|
|
|
return $this->MasterPage()->canView($member);
|
|
|
|
}
|
|
|
|
function canEdit($member = null) {
|
|
|
|
return $this->MasterPage()->canView($member);
|
|
|
|
}
|
|
|
|
function canDelete($member = null) {
|
|
|
|
return $this->MasterPage()->canDelete($member);
|
|
|
|
}
|
2010-03-01 04:01:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|