diff --git a/README b/README index c6b3937..ff7edbf 100644 --- a/README +++ b/README @@ -9,7 +9,7 @@ Sam Minnée (Nickname: sminnee) Requirements ----------------------------------------------- -- genericdataadmin Module +- SilverStripe 2.3.0 or higher Documentation ----------------------------------------------- diff --git a/_config.php b/_config.php index a165e7a..e59da04 100644 --- a/_config.php +++ b/_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); -} ?> \ No newline at end of file diff --git a/code/Subsite.php b/code/Subsite.php index 476f77a..27eb964 100644 --- a/code/Subsite.php +++ b/code/Subsite.php @@ -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); diff --git a/code/SubsiteAdmin.php b/code/SubsiteAdmin.php index 7bd358e..fbd1786 100644 --- a/code/SubsiteAdmin.php +++ b/code/SubsiteAdmin.php @@ -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 = "
Name | Domain |
---|---|
ID}\">$prefix{$intranet->Title} | ID}\">{$intranet->domain()} |