mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 09:05:55 +00:00
ENHANCEMENT: Updated subsite admin to use ModelAdmin, to be more in line with other parts of SilverStripe. (from r80861)
This commit is contained in:
parent
78c8d364b2
commit
68dfd71c5e
2
README
2
README
@ -9,7 +9,7 @@ Sam Minnée (Nickname: sminnee)
|
|||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
- genericdataadmin Module
|
- SilverStripe 2.3.0 or higher
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
|
13
_config.php
13
_config.php
@ -17,17 +17,4 @@ 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');
|
||||||
|
|
||||||
// Backwards compatibility with SilverStripe 2.2
|
|
||||||
if(!class_exists('CMSMenu')) {
|
|
||||||
Director::addRules(100, array(
|
|
||||||
'admin/subsites/$Action/$ID/$OtherID' => 'SubsiteAdmin',
|
|
||||||
));
|
|
||||||
Object::addStaticVars( 'LeftAndMain', array( 'extra_menu_items' => array(
|
|
||||||
'Sub-sites' => array("intranets", "admin/subsites/", 'SubsiteAdmin')
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!class_exists('GenericDataAdmin')) {
|
|
||||||
user_error('Please install the module "genericdataadmin" to use subsites', E_USER_ERROR);
|
|
||||||
}
|
|
||||||
?>
|
?>
|
@ -29,10 +29,32 @@ class Subsite extends DataObject implements PermissionProvider {
|
|||||||
static $has_one = array(
|
static $has_one = array(
|
||||||
);
|
);
|
||||||
|
|
||||||
|
static $has_many = array(
|
||||||
|
'Domains' => 'SubsiteDomain',
|
||||||
|
);
|
||||||
|
|
||||||
static $defaults = array(
|
static $defaults = array(
|
||||||
'IsPublic' => 1,
|
'IsPublic' => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
static $searchable_fields = array(
|
||||||
|
'Title' => array(
|
||||||
|
'title' => 'Subsite Name'
|
||||||
|
),
|
||||||
|
'Domains.Domain' => array(
|
||||||
|
'title' => 'Domain name'
|
||||||
|
),
|
||||||
|
'IsPublic' => array(
|
||||||
|
'title' => 'Active subsite',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
static $summary_fields = array(
|
||||||
|
'Title' => 'Subsite Name',
|
||||||
|
'PrimaryDomain' => 'Primary Domain',
|
||||||
|
'IsPublic' => 'Active subsite',
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Subsite $cached_subsite Internal cache used by {@link currentSubsite()}.
|
* @var Subsite $cached_subsite Internal cache used by {@link currentSubsite()}.
|
||||||
*/
|
*/
|
||||||
@ -95,6 +117,10 @@ class Subsite extends DataObject implements PermissionProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPrimaryDomain() {
|
||||||
|
return $this->domain();
|
||||||
|
}
|
||||||
|
|
||||||
function absoluteBaseURL() {
|
function absoluteBaseURL() {
|
||||||
return "http://" . $this->domain() . Director::baseURL();
|
return "http://" . $this->domain() . Director::baseURL();
|
||||||
}
|
}
|
||||||
@ -106,11 +132,7 @@ class Subsite extends DataObject implements PermissionProvider {
|
|||||||
$domainTable = new TableField("Domains", "SubsiteDomain",
|
$domainTable = new TableField("Domains", "SubsiteDomain",
|
||||||
array("Domain" => "Domain (use * as a wildcard)", "IsPrimary" => "Primary domain?"),
|
array("Domain" => "Domain (use * as a wildcard)", "IsPrimary" => "Primary domain?"),
|
||||||
array("Domain" => "TextField", "IsPrimary" => "CheckboxField"),
|
array("Domain" => "TextField", "IsPrimary" => "CheckboxField"),
|
||||||
null, "SubsiteDomain.SubsiteID", $this->ID);
|
"SubsiteID", $this->ID);
|
||||||
|
|
||||||
$domainTable->setExtraData(array(
|
|
||||||
'SubsiteID' => $this->ID ? $this->ID : '$RecordID',
|
|
||||||
));
|
|
||||||
|
|
||||||
$fields = new FieldSet(
|
$fields = new FieldSet(
|
||||||
new TabSet('Root',
|
new TabSet('Root',
|
||||||
@ -473,16 +495,18 @@ class Subsite_Template extends Subsite {
|
|||||||
/**
|
/**
|
||||||
* Create an instance of this template, with the given title & domain
|
* Create an instance of this template, with the given title & domain
|
||||||
*/
|
*/
|
||||||
function createInstance($title, $domain) {
|
function createInstance($title, $domain = null) {
|
||||||
$intranet = Object::create('Subsite');
|
$intranet = Object::create('Subsite');
|
||||||
$intranet->Title = $title;
|
$intranet->Title = $title;
|
||||||
$intranet->TemplateID = $this->ID;
|
$intranet->TemplateID = $this->ID;
|
||||||
$intranet->write();
|
$intranet->write();
|
||||||
|
|
||||||
|
if($domain) {
|
||||||
$intranetDomain = Object::create('SubsiteDomain');
|
$intranetDomain = Object::create('SubsiteDomain');
|
||||||
$intranetDomain->SubsiteID = $intranet->ID;
|
$intranetDomain->SubsiteID = $intranet->ID;
|
||||||
$intranetDomain->Domain = $domain;
|
$intranetDomain->Domain = $domain;
|
||||||
$intranetDomain->write();
|
$intranetDomain->write();
|
||||||
|
}
|
||||||
|
|
||||||
$oldSubsiteID = Session::get('SubsiteID');
|
$oldSubsiteID = Session::get('SubsiteID');
|
||||||
self::changeSubsite($this->ID);
|
self::changeSubsite($this->ID);
|
||||||
|
@ -4,159 +4,75 @@
|
|||||||
*
|
*
|
||||||
* @package subsites
|
* @package subsites
|
||||||
*/
|
*/
|
||||||
class SubsiteAdmin extends GenericDataAdmin {
|
class SubsiteAdmin extends ModelAdmin {
|
||||||
|
|
||||||
static $tree_class = "Subsite";
|
|
||||||
static $subitem_class = "Subsite";
|
|
||||||
static $data_type = 'Subsite';
|
|
||||||
|
|
||||||
|
static $managed_models = array('Subsite');
|
||||||
static $url_segment = 'subsites';
|
static $url_segment = 'subsites';
|
||||||
|
|
||||||
static $url_rule = '/$Action/$ID/$OtherID';
|
static $collection_controller_class = "SubsiteAdmin_CollectionController";
|
||||||
|
|
||||||
static $menu_title = 'Subsites';
|
|
||||||
|
|
||||||
function performSearch() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSearchFields() {
|
|
||||||
return singleton('Subsite')->adminSearchFields();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getLink() {
|
|
||||||
return 'admin/subsites/';
|
|
||||||
}
|
|
||||||
|
|
||||||
function Link() {
|
function Link() {
|
||||||
return $this->getLink();
|
return 'admin/subsites/';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Results($data = null) {
|
class SubsiteAdmin_CollectionController extends ModelAdmin_CollectionController {
|
||||||
if(!$data) $data = $this->requestParams;
|
function AddForm() {
|
||||||
|
$form = parent::AddForm();
|
||||||
if(defined('DB::USE_ANSI_SQL'))
|
|
||||||
$q="\"";
|
|
||||||
else $q='`';
|
|
||||||
|
|
||||||
$where = '';
|
|
||||||
if(isset($data['Name']) && $data['Name']) {
|
|
||||||
$SQL_name = Convert::raw2sql($data['Name']);
|
|
||||||
$where = "{$q}Title{$q} LIKE '%$SQL_name%'";
|
|
||||||
} else {
|
|
||||||
$where = "{$q}Title{$q} != ''";
|
|
||||||
}
|
|
||||||
|
|
||||||
$intranets = null;
|
|
||||||
$intranets = DataObject::get('Subsite_Template', $where, "{$q}Title{$q}");
|
|
||||||
$subsites = DataObject::get('Subsite', $where, "{$q}Title{$q}");
|
|
||||||
|
|
||||||
if($intranets) {
|
|
||||||
$intranets->merge($subsites);
|
|
||||||
} else {
|
|
||||||
$intranets = $subsites;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$intranets) return null;
|
|
||||||
|
|
||||||
$intranets->removeDuplicates();
|
|
||||||
|
|
||||||
$html = "<table class=\"ResultTable\"><thead><tr><th>Name</th><th>Domain</th></tr></thead><tbody>";
|
|
||||||
|
|
||||||
$numIntranets = 0;
|
|
||||||
foreach($intranets as $intranet) {
|
|
||||||
$numIntranets++;
|
|
||||||
$evenOdd = ($numIntranets % 2) ? 'odd':'even';
|
|
||||||
$prefix = ($intranet instanceof Subsite_Template) ? " * " : "";
|
|
||||||
$html .= "<tr class=\"$evenOdd\"><td><a class=\"show\" href=\"admin/subsites/show/{$intranet->ID}\">$prefix{$intranet->Title}</a></td><td><a class=\"show\" href=\"admin/subsites/show/{$intranet->ID}\">{$intranet->domain()}</a></td></tr>";
|
|
||||||
}
|
|
||||||
$html .= "</tbody></table>";
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the form for adding subsites.
|
|
||||||
* @returns Form A nerw form object
|
|
||||||
*/
|
|
||||||
function AddSubsiteForm() {
|
|
||||||
$templates = $this->getIntranetTemplates();
|
|
||||||
|
|
||||||
|
$templates = DataObject::get('Subsite_Template', '', 'Title');
|
||||||
$templateArray = array('' => "(No template)");
|
$templateArray = array('' => "(No template)");
|
||||||
if($templates) {
|
if($templates) {
|
||||||
$templateArray = $templateArray + $templates->map('ID', 'Title');
|
$templateArray = $templateArray + $templates->map('ID', 'Title');
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Form($this, 'AddSubsiteForm', new FieldSet(
|
$form->Fields()->addFieldsToTab('Root.Configuration', array(
|
||||||
new TextField('Name', 'Name:'),
|
|
||||||
new TextField('Domain', 'Domain name:'),
|
|
||||||
new DropdownField('Type', 'Type', array(
|
new DropdownField('Type', 'Type', array(
|
||||||
'subsite' => 'New site',
|
'subsite' => 'New site',
|
||||||
'template' => 'New template',
|
'template' => 'New template',
|
||||||
)),
|
)),
|
||||||
new DropdownField('TemplateID', 'Copy structure from:', $templateArray)//,
|
new DropdownField('TemplateID', 'Copy structure from:', $templateArray)
|
||||||
/*new TextField('AdminName', 'Admin name:'),
|
|
||||||
new EmailField('AdminEmail', 'Admin email:')*/
|
|
||||||
),
|
|
||||||
new FieldSet(
|
|
||||||
new FormAction('addintranet', 'Add')
|
|
||||||
));
|
));
|
||||||
|
|
||||||
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIntranetTemplates() {
|
function doCreate($data, $form, $request) {
|
||||||
if(defined('DB::USE_ANSI_SQL'))
|
|
||||||
$q="\"";
|
|
||||||
else $q='`';
|
|
||||||
|
|
||||||
return DataObject::get('Subsite_Template', '', "{$q}Title{$q}");
|
|
||||||
}
|
|
||||||
|
|
||||||
function addintranet($data, $form) {
|
|
||||||
if($data['Name'] && ($data['Domain'] || $data['Type'] == 'template')) {
|
|
||||||
if(isset($data['TemplateID']) && $data['TemplateID']) {
|
if(isset($data['TemplateID']) && $data['TemplateID']) {
|
||||||
$template = DataObject::get_by_id('Subsite_Template', $data['TemplateID']);
|
$template = DataObject::get_by_id('Subsite_Template', $data['TemplateID']);
|
||||||
} else {
|
} else {
|
||||||
$template = null;
|
$template = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create intranet from existing template
|
// Create subsite from existing template
|
||||||
switch($data['Type']) {
|
switch($data['Type']) {
|
||||||
case 'template':
|
case 'template':
|
||||||
if($template) $intranet = $template->duplicate();
|
if($template) $subsite = $template->duplicate();
|
||||||
else $intranet = new Subsite_Template();
|
else {
|
||||||
|
$subsite = new Subsite_Template();
|
||||||
$intranet->Title = $data['Name'];
|
$subsite->write();
|
||||||
$intranet->write();
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'subsite':
|
case 'subsite':
|
||||||
default:
|
default:
|
||||||
if($template) $intranet = $template->createInstance($data['Name'], $data['Domain']);
|
if($template) $subsite = $template->createInstance($data['Title']);
|
||||||
else {
|
else {
|
||||||
$intranet = new Subsite();
|
$subsite = new Subsite();
|
||||||
$intranet->Title = $data['Name'];
|
$subsite->Title = $data['Title'];
|
||||||
$intranet->write();
|
$subsite->write();
|
||||||
|
|
||||||
$newSubsiteDomain = new SubsiteDomain();
|
|
||||||
$newSubsiteDomain->SubsiteID = $intranet->ID;
|
|
||||||
$newSubsiteDomain->write();
|
|
||||||
$newSubsiteDomain->Domain = $data['Domain'];
|
|
||||||
$newSubsiteDomain->write();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Director::redirect('admin/subsites/show/' . $intranet->ID);
|
$form->dataFieldByName('Domains')->setExtraData(array(
|
||||||
} else {
|
"SubsiteID" => $subsite->ID,
|
||||||
if($data['Type'] == 'template') echo "You must provide a name for your new template.";
|
));
|
||||||
else echo "You must provide a name and domain for your new site.";
|
$form->saveInto($subsite);
|
||||||
|
$subsite->write();
|
||||||
|
|
||||||
|
Director::redirect(Controller::join_links($this->Link(), $subsite->ID , 'edit'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this as an action handler for custom CMS buttons.
|
|
||||||
*/
|
|
||||||
function callPageMethod2($data, $form) {
|
|
||||||
return $this->callPageMethod($data, $form);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
<div id="LeftPane">
|
|
||||||
<h2>Create Sub-site</h2>
|
|
||||||
<div id="AddIntranetForm_holder" style="overflow:auto">
|
|
||||||
$AddSubsiteForm
|
|
||||||
</div>
|
|
||||||
<h2>Search for Sub-sites</h2>
|
|
||||||
<div id="Search_holder" style="overflow: auto;">
|
|
||||||
<div id="SearchForm_holder" style="overflow:auto">
|
|
||||||
$SearchForm
|
|
||||||
</div>
|
|
||||||
<div id="ResultTable_holder" style="overflow:auto">
|
|
||||||
$Results
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@ -1,13 +0,0 @@
|
|||||||
<!--<% xinclude Editor_toolbar %>-->
|
|
||||||
<% if EditForm %> $EditForm <% else %>
|
|
||||||
<form id="Form_EditForm" action="{$Link}?executeForm=EditForm"
|
|
||||||
method="post" enctype="multipart/form-data">
|
|
||||||
<h1>$ApplicationName</h1>
|
|
||||||
|
|
||||||
<p>Welcome to $ApplicationName! Please choose click on one of the
|
|
||||||
entries on the left pane.</p>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
<% end_if %>
|
|
||||||
|
|
||||||
<p id="statusMessage" style="visibility:hidden"></p>
|
|
Loading…
x
Reference in New Issue
Block a user