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
|
||||
-----------------------------------------------
|
||||
- genericdataadmin Module
|
||||
- SilverStripe 2.3.0 or higher
|
||||
|
||||
Documentation
|
||||
-----------------------------------------------
|
||||
|
13
_config.php
13
_config.php
@ -17,17 +17,4 @@ Object::add_extension('Member', 'MemberSubsites');
|
||||
Object::add_extension('File', 'FileSubsites');
|
||||
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);
|
||||
}
|
||||
?>
|
@ -25,14 +25,36 @@ class Subsite extends DataObject implements PermissionProvider {
|
||||
// If unset, will default to
|
||||
'IsPublic' => 'Boolean'
|
||||
);
|
||||
|
||||
|
||||
static $has_one = array(
|
||||
);
|
||||
|
||||
static $has_many = array(
|
||||
'Domains' => 'SubsiteDomain',
|
||||
);
|
||||
|
||||
static $defaults = array(
|
||||
'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()}.
|
||||
*/
|
||||
@ -94,6 +116,10 @@ class Subsite extends DataObject implements PermissionProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getPrimaryDomain() {
|
||||
return $this->domain();
|
||||
}
|
||||
|
||||
function absoluteBaseURL() {
|
||||
return "http://" . $this->domain() . Director::baseURL();
|
||||
@ -106,11 +132,7 @@ class Subsite extends DataObject implements PermissionProvider {
|
||||
$domainTable = new TableField("Domains", "SubsiteDomain",
|
||||
array("Domain" => "Domain (use * as a wildcard)", "IsPrimary" => "Primary domain?"),
|
||||
array("Domain" => "TextField", "IsPrimary" => "CheckboxField"),
|
||||
null, "SubsiteDomain.SubsiteID", $this->ID);
|
||||
|
||||
$domainTable->setExtraData(array(
|
||||
'SubsiteID' => $this->ID ? $this->ID : '$RecordID',
|
||||
));
|
||||
"SubsiteID", $this->ID);
|
||||
|
||||
$fields = new FieldSet(
|
||||
new TabSet('Root',
|
||||
@ -473,16 +495,18 @@ class Subsite_Template extends Subsite {
|
||||
/**
|
||||
* 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->Title = $title;
|
||||
$intranet->TemplateID = $this->ID;
|
||||
$intranet->write();
|
||||
|
||||
$intranetDomain = Object::create('SubsiteDomain');
|
||||
$intranetDomain->SubsiteID = $intranet->ID;
|
||||
$intranetDomain->Domain = $domain;
|
||||
$intranetDomain->write();
|
||||
if($domain) {
|
||||
$intranetDomain = Object::create('SubsiteDomain');
|
||||
$intranetDomain->SubsiteID = $intranet->ID;
|
||||
$intranetDomain->Domain = $domain;
|
||||
$intranetDomain->write();
|
||||
}
|
||||
|
||||
$oldSubsiteID = Session::get('SubsiteID');
|
||||
self::changeSubsite($this->ID);
|
||||
|
@ -4,159 +4,75 @@
|
||||
*
|
||||
* @package subsites
|
||||
*/
|
||||
class SubsiteAdmin extends GenericDataAdmin {
|
||||
|
||||
static $tree_class = "Subsite";
|
||||
static $subitem_class = "Subsite";
|
||||
static $data_type = 'Subsite';
|
||||
class SubsiteAdmin extends ModelAdmin {
|
||||
|
||||
static $managed_models = array('Subsite');
|
||||
static $url_segment = 'subsites';
|
||||
|
||||
static $url_rule = '/$Action/$ID/$OtherID';
|
||||
|
||||
static $menu_title = 'Subsites';
|
||||
|
||||
function performSearch() {
|
||||
|
||||
}
|
||||
|
||||
function getSearchFields() {
|
||||
return singleton('Subsite')->adminSearchFields();
|
||||
}
|
||||
|
||||
function getLink() {
|
||||
return 'admin/subsites/';
|
||||
}
|
||||
static $collection_controller_class = "SubsiteAdmin_CollectionController";
|
||||
|
||||
function Link() {
|
||||
return $this->getLink();
|
||||
return 'admin/subsites/';
|
||||
}
|
||||
|
||||
function Results($data = null) {
|
||||
if(!$data) $data = $this->requestParams;
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
class SubsiteAdmin_CollectionController extends ModelAdmin_CollectionController {
|
||||
function AddForm() {
|
||||
$form = parent::AddForm();
|
||||
|
||||
$templates = DataObject::get('Subsite_Template', '', 'Title');
|
||||
$templateArray = array('' => "(No template)");
|
||||
if($templates) {
|
||||
$templateArray = $templateArray + $templates->map('ID', 'Title');
|
||||
}
|
||||
|
||||
return new Form($this, 'AddSubsiteForm', new FieldSet(
|
||||
new TextField('Name', 'Name:'),
|
||||
new TextField('Domain', 'Domain name:'),
|
||||
|
||||
$form->Fields()->addFieldsToTab('Root.Configuration', array(
|
||||
new DropdownField('Type', 'Type', array(
|
||||
'subsite' => 'New site',
|
||||
'template' => 'New template',
|
||||
)),
|
||||
new DropdownField('TemplateID', 'Copy structure from:', $templateArray)//,
|
||||
/*new TextField('AdminName', 'Admin name:'),
|
||||
new EmailField('AdminEmail', 'Admin email:')*/
|
||||
),
|
||||
new FieldSet(
|
||||
new FormAction('addintranet', 'Add')
|
||||
new DropdownField('TemplateID', 'Copy structure from:', $templateArray)
|
||||
));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function getIntranetTemplates() {
|
||||
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']) {
|
||||
$template = DataObject::get_by_id('Subsite_Template', $data['TemplateID']);
|
||||
} else {
|
||||
$template = null;
|
||||
}
|
||||
|
||||
// Create intranet from existing template
|
||||
switch($data['Type']) {
|
||||
case 'template':
|
||||
if($template) $intranet = $template->duplicate();
|
||||
else $intranet = new Subsite_Template();
|
||||
|
||||
$intranet->Title = $data['Name'];
|
||||
$intranet->write();
|
||||
break;
|
||||
|
||||
case 'subsite':
|
||||
default:
|
||||
if($template) $intranet = $template->createInstance($data['Name'], $data['Domain']);
|
||||
else {
|
||||
$intranet = new Subsite();
|
||||
$intranet->Title = $data['Name'];
|
||||
$intranet->write();
|
||||
|
||||
$newSubsiteDomain = new SubsiteDomain();
|
||||
$newSubsiteDomain->SubsiteID = $intranet->ID;
|
||||
$newSubsiteDomain->write();
|
||||
$newSubsiteDomain->Domain = $data['Domain'];
|
||||
$newSubsiteDomain->write();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Director::redirect('admin/subsites/show/' . $intranet->ID);
|
||||
function doCreate($data, $form, $request) {
|
||||
if(isset($data['TemplateID']) && $data['TemplateID']) {
|
||||
$template = DataObject::get_by_id('Subsite_Template', $data['TemplateID']);
|
||||
} else {
|
||||
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.";
|
||||
$template = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this as an action handler for custom CMS buttons.
|
||||
*/
|
||||
function callPageMethod2($data, $form) {
|
||||
return $this->callPageMethod($data, $form);
|
||||
// Create subsite from existing template
|
||||
switch($data['Type']) {
|
||||
case 'template':
|
||||
if($template) $subsite = $template->duplicate();
|
||||
else {
|
||||
$subsite = new Subsite_Template();
|
||||
$subsite->write();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'subsite':
|
||||
default:
|
||||
if($template) $subsite = $template->createInstance($data['Title']);
|
||||
else {
|
||||
$subsite = new Subsite();
|
||||
$subsite->Title = $data['Title'];
|
||||
$subsite->write();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$form->dataFieldByName('Domains')->setExtraData(array(
|
||||
"SubsiteID" => $subsite->ID,
|
||||
));
|
||||
$form->saveInto($subsite);
|
||||
$subsite->write();
|
||||
|
||||
Director::redirect(Controller::join_links($this->Link(), $subsite->ID , 'edit'));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -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