2007-08-18 13:38:11 +02:00
|
|
|
<?php
|
2008-11-24 04:22:01 +01:00
|
|
|
/**
|
|
|
|
* Admin interface to manage and create {@link Subsite} instances.
|
|
|
|
*
|
|
|
|
* @package subsites
|
|
|
|
*/
|
2010-03-01 03:53:00 +01:00
|
|
|
class SubsiteAdmin extends ModelAdmin {
|
2007-08-18 13:38:11 +02:00
|
|
|
|
2010-03-01 03:53:00 +01:00
|
|
|
static $managed_models = array('Subsite');
|
2008-11-02 23:23:01 +01:00
|
|
|
static $url_segment = 'subsites';
|
|
|
|
|
2010-03-01 03:53:00 +01:00
|
|
|
static $collection_controller_class = "SubsiteAdmin_CollectionController";
|
2007-08-18 13:38:11 +02:00
|
|
|
|
|
|
|
function Link() {
|
2010-03-01 03:53:00 +01:00
|
|
|
return 'admin/subsites/';
|
2007-08-18 13:38:11 +02:00
|
|
|
}
|
2010-03-01 03:53:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class SubsiteAdmin_CollectionController extends ModelAdmin_CollectionController {
|
|
|
|
function AddForm() {
|
|
|
|
$form = parent::AddForm();
|
|
|
|
|
|
|
|
$templates = DataObject::get('Subsite_Template', '', 'Title');
|
2008-11-20 00:25:43 +01:00
|
|
|
$templateArray = array('' => "(No template)");
|
2007-08-18 13:38:11 +02:00
|
|
|
if($templates) {
|
2008-11-20 00:25:43 +01:00
|
|
|
$templateArray = $templateArray + $templates->map('ID', 'Title');
|
2007-08-18 13:38:11 +02:00
|
|
|
}
|
2010-03-01 03:53:00 +01:00
|
|
|
|
|
|
|
$form->Fields()->addFieldsToTab('Root.Configuration', array(
|
2007-08-29 00:29:44 +02:00
|
|
|
new DropdownField('Type', 'Type', array(
|
|
|
|
'subsite' => 'New site',
|
|
|
|
'template' => 'New template',
|
|
|
|
)),
|
2010-03-01 03:53:00 +01:00
|
|
|
new DropdownField('TemplateID', 'Copy structure from:', $templateArray)
|
2007-08-18 13:38:11 +02:00
|
|
|
));
|
2009-11-02 04:00:18 +01:00
|
|
|
|
2010-03-01 03:53:00 +01:00
|
|
|
return $form;
|
2007-08-18 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2010-03-01 03:53:00 +01:00
|
|
|
function doCreate($data, $form, $request) {
|
|
|
|
if(isset($data['TemplateID']) && $data['TemplateID']) {
|
|
|
|
$template = DataObject::get_by_id('Subsite_Template', $data['TemplateID']);
|
|
|
|
} else {
|
|
|
|
$template = null;
|
|
|
|
}
|
2007-08-29 00:29:44 +02:00
|
|
|
|
2010-03-01 03:53:00 +01:00
|
|
|
// Create subsite from existing template
|
|
|
|
switch($data['Type']) {
|
|
|
|
case 'template':
|
|
|
|
if($template) $subsite = $template->duplicate();
|
|
|
|
else {
|
|
|
|
$subsite = new Subsite_Template();
|
|
|
|
$subsite->write();
|
|
|
|
}
|
|
|
|
break;
|
2010-03-01 03:48:45 +01:00
|
|
|
|
2010-03-01 03:53:00 +01:00
|
|
|
case 'subsite':
|
|
|
|
default:
|
|
|
|
if($template) $subsite = $template->createInstance($data['Title']);
|
|
|
|
else {
|
|
|
|
$subsite = new Subsite();
|
|
|
|
$subsite->Title = $data['Title'];
|
|
|
|
$subsite->write();
|
2007-11-27 02:07:54 +01:00
|
|
|
}
|
2010-03-01 03:53:00 +01:00
|
|
|
break;
|
2007-11-27 02:07:54 +01:00
|
|
|
}
|
2007-10-11 05:05:58 +02:00
|
|
|
|
2010-03-01 03:53:00 +01:00
|
|
|
$form->dataFieldByName('Domains')->setExtraData(array(
|
|
|
|
"SubsiteID" => $subsite->ID,
|
|
|
|
));
|
|
|
|
$form->saveInto($subsite);
|
|
|
|
$subsite->write();
|
2010-03-01 03:56:07 +01:00
|
|
|
|
|
|
|
if(Director::is_ajax()) {
|
|
|
|
$recordController = new ModelAdmin_RecordController($this, $request, $subsite->ID);
|
|
|
|
return new HTTPResponse(
|
|
|
|
$recordController->EditForm()->forAjaxTemplate(),
|
|
|
|
200,
|
|
|
|
sprintf(
|
|
|
|
_t('ModelAdmin.LOADEDFOREDITING', "Loaded '%s' for editing."),
|
|
|
|
$subsite->Title
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
Director::redirect(Controller::join_links($this->Link(), $subsitess->ID , 'edit'));
|
|
|
|
}
|
2007-10-11 05:05:58 +02:00
|
|
|
}
|
2007-08-18 13:38:11 +02:00
|
|
|
}
|
2010-03-01 03:53:00 +01:00
|
|
|
|
2007-08-18 13:38:11 +02:00
|
|
|
?>
|