Test commit

This commit is contained in:
Sam Minnee 2007-08-18 11:38:11 +00:00
parent 1b333df297
commit 13aa9894b8
2 changed files with 421 additions and 421 deletions

View File

@ -1,307 +1,307 @@
<?php <?php
/** /**
* A dynamically created subdomain. SiteTree objects can now belong to a subdomain * A dynamically created subdomain. SiteTree objects can now belong to a subdomain
*/ */
class Subsite extends DataObject { class Subsite extends DataObject {
static $default_sort = 'Title'; static $default_sort = 'Title';
static $use_domain = false; static $use_domain = false;
static $db = array( static $db = array(
'Subdomain' => 'Varchar', 'Subdomain' => 'Varchar',
'Title' => 'Varchar(255)', 'Title' => 'Varchar(255)',
'RedirectURL' => 'Varchar(255)', 'RedirectURL' => 'Varchar(255)',
'DefaultSite' => 'Boolean', 'DefaultSite' => 'Boolean',
'Theme' => 'Varchar', 'Theme' => 'Varchar',
'Domain' => 'Varchar', 'Domain' => 'Varchar',
'IsPublic' => 'Boolean' 'IsPublic' => 'Boolean'
); );
static $indexes = array( static $indexes = array(
'Subdomain' => true, 'Subdomain' => true,
'Domain' => true 'Domain' => true
); );
static $base_domain, $default_subdomain; static $base_domain, $default_subdomain;
static $cached_subsite = null; static $cached_subsite = null;
/** /**
* Return the base domain for this set of subsites. * Return the base domain for this set of subsites.
* You can set this by setting Subsite::$Base_domain, otherwise it defaults to HTTP_HOST * You can set this by setting Subsite::$Base_domain, otherwise it defaults to HTTP_HOST
*/ */
static function base_domain() { static function base_domain() {
if(self::$base_domain) return self::$base_domain; if(self::$base_domain) return self::$base_domain;
else return $_SERVER['HTTP_HOST']; else return $_SERVER['HTTP_HOST'];
} }
/** /**
* Return the default domain of this set of subsites. Generally this will be the base domain, * Return the default domain of this set of subsites. Generally this will be the base domain,
* but hyou can also set Subsite::$default_subdomain to add a default prefix to this * but hyou can also set Subsite::$default_subdomain to add a default prefix to this
*/ */
static function default_domain() { static function default_domain() {
if(self::$default_subdomain) return self::$default_subdomain . '.' . self::base_domain(); if(self::$default_subdomain) return self::$default_subdomain . '.' . self::base_domain();
else return self::base_domain(); else return self::base_domain();
} }
/** /**
* Return the domain of this site * Return the domain of this site
*/ */
function domain() { function domain() {
$base = $this->Domain ? $this->Domain : self::base_domain(); $base = $this->Domain ? $this->Domain : self::base_domain();
$sub = $this->Subdomain ? $this->Subdomain : self::$default_subdomain; $sub = $this->Subdomain ? $this->Subdomain : self::$default_subdomain;
if($sub) return "$sub.$base"; if($sub) return "$sub.$base";
else return $base; else return $base;
} }
// Show the configuration fields for each subsite // Show the configuration fields for each subsite
function getCMSFields() { function getCMSFields() {
$fields = new FieldSet( $fields = new FieldSet(
new TabSet('Root', new TabSet('Root',
new Tab('Configuration', new Tab('Configuration',
new HeaderField($this->getClassName() . ' configuration', 2), new HeaderField($this->getClassName() . ' configuration', 2),
new TextField('Title', 'Name of subsite:', $this->Title), new TextField('Title', 'Name of subsite:', $this->Title),
$this->domainField(), $this->domainField(),
// new TextField('RedirectURL', 'Redirect to URL', $this->RedirectURL), // new TextField('RedirectURL', 'Redirect to URL', $this->RedirectURL),
new CheckboxField('DefaultSite', 'Use this subsite as the default site', $this->DefaultSite), new CheckboxField('DefaultSite', 'Use this subsite as the default site', $this->DefaultSite),
new CheckboxField('IsPublic', 'Can access this subsite publicly?', $this->IsPublic) new CheckboxField('IsPublic', 'Can access this subsite publicly?', $this->IsPublic)
) )
), ),
new HiddenField('ID', '', $this->ID), new HiddenField('ID', '', $this->ID),
new HiddenField('IsSubsite', '', 1) new HiddenField('IsSubsite', '', 1)
); );
// This code needs to be updated to reference the new SS 2.0.3 theme system // This code needs to be updated to reference the new SS 2.0.3 theme system
/* if($themes = SSViewer::getThemes(false)) /* if($themes = SSViewer::getThemes(false))
$fields->addFieldsToTab('Root.Configuration', new DropdownField('Theme', 'Theme:', $themes, $this->Theme)); $fields->addFieldsToTab('Root.Configuration', new DropdownField('Theme', 'Theme:', $themes, $this->Theme));
*/ */
return $fields; return $fields;
} }
function domainField() { function domainField() {
return new FieldGroup('Subsite domain', return new FieldGroup('Subsite domain',
new TextField('Subdomain',"", $this->Subdomain), new TextField('Subdomain',"", $this->Subdomain),
new TextField('Domain','.', $this->Domain) new TextField('Domain','.', $this->Domain)
); );
} }
function getClassName() { function getClassName() {
return $this->class; return $this->class;
} }
function getCMSActions() { function getCMSActions() {
return new FieldSet( return new FieldSet(
new FormAction('savesubsite', 'Save') new FormAction('savesubsite', 'Save')
); );
} }
static function currentSubsite() { static function currentSubsite() {
if(!self::$cached_subsite) self::$cached_subsite = DataObject::get_by_id('Subsite', self::currentSubsiteID()); if(!self::$cached_subsite) self::$cached_subsite = DataObject::get_by_id('Subsite', self::currentSubsiteID());
return self::$cached_subsite; return self::$cached_subsite;
} }
/** /**
* This function gets the current subsite ID from the session. It used in the backend so Ajax requests * This function gets the current subsite ID from the session. It used in the backend so Ajax requests
* use the correct subsite. The frontend handles subsites differently. It calls getSubsiteIDForDomain * use the correct subsite. The frontend handles subsites differently. It calls getSubsiteIDForDomain
* directly from ModelAsController::getNestedController. * directly from ModelAsController::getNestedController.
*/ */
static function currentSubsiteID() { static function currentSubsiteID() {
$id = Session::get('SubsiteID'); $id = Session::get('SubsiteID');
if($id === null) Session::set('SubsiteID', $id = self::getSubsiteIDForDomain()); if($id === null) Session::set('SubsiteID', $id = self::getSubsiteIDForDomain());
return (int)$id; return (int)$id;
} }
static function create($name) { static function create($name) {
$newSubsite = Object::create('Subsite'); $newSubsite = Object::create('Subsite');
$newSubsite->Title = $name; $newSubsite->Title = $name;
$newSubsite->Subdomain = str_replace(' ', '-', preg_replace('/[^0-9A-Za-z\s]/', '', strtolower(trim($name)))); $newSubsite->Subdomain = str_replace(' ', '-', preg_replace('/[^0-9A-Za-z\s]/', '', strtolower(trim($name))));
$newSubsite->write(); $newSubsite->write();
$newSubsite->createInitialRecords(); $newSubsite->createInitialRecords();
return $newSubsite; return $newSubsite;
} }
/** /**
* Switch to another subsite * Switch to another subsite
* @param $subsite Either the ID of the subsite, or the subsite object itself * @param $subsite Either the ID of the subsite, or the subsite object itself
*/ */
static function changeSubsite($subsite) { static function changeSubsite($subsite) {
// Debug::backtrace(); // Debug::backtrace();
if(!$subsite) { if(!$subsite) {
Session::set('SubsiteID', 0); Session::set('SubsiteID', 0);
return; return;
} }
if(is_object($subsite)) if(is_object($subsite))
$subsite = $subsite->ID; $subsite = $subsite->ID;
Session::set('SubsiteID', $subsite); Session::set('SubsiteID', $subsite);
/*if(!is_object($subsite) && is_numeric($subsite)) /*if(!is_object($subsite) && is_numeric($subsite))
$subsite = DataObject::get_by_id('Subsite', $subsite); $subsite = DataObject::get_by_id('Subsite', $subsite);
if($subsite) if($subsite)
Session::set('SubsiteID', $subsite->ID);*/ Session::set('SubsiteID', $subsite->ID);*/
} }
function canEdit() { function canEdit() {
return true; return true;
} }
static function getSubsiteIDForDomain() { static function getSubsiteIDForDomain() {
$domainNameParts = explode('.', $_SERVER['HTTP_HOST']); $domainNameParts = explode('.', $_SERVER['HTTP_HOST']);
if($domainNameParts[0] == 'www') return 0; if($domainNameParts[0] == 'www') return 0;
$SQL_subdomain = Convert::raw2sql(array_shift($domainNameParts)); $SQL_subdomain = Convert::raw2sql(array_shift($domainNameParts));
$SQL_domain = join('.', Convert::raw2sql($domainNameParts)); $SQL_domain = join('.', Convert::raw2sql($domainNameParts));
// $_REQUEST['showqueries'] = 1; // $_REQUEST['showqueries'] = 1;
if(self::$use_domain) { if(self::$use_domain) {
$subsite = DataObject::get_one('Subsite',"`Subdomain` = '$SQL_subdomain' AND `Domain`='$SQL_domain' AND `IsPublic`=1"); $subsite = DataObject::get_one('Subsite',"`Subdomain` = '$SQL_subdomain' AND `Domain`='$SQL_domain' AND `IsPublic`=1");
} else { } else {
$subsite = DataObject::get_one('Subsite',"`Subdomain` = '$SQL_subdomain' AND `IsPublic`=1"); $subsite = DataObject::get_one('Subsite',"`Subdomain` = '$SQL_subdomain' AND `IsPublic`=1");
} }
if($subsite) { if($subsite) {
// This will need to be updated to use the current theme system // This will need to be updated to use the current theme system
// SSViewer::setCurrentTheme($subsite->Theme); // SSViewer::setCurrentTheme($subsite->Theme);
return $subsite->ID; return $subsite->ID;
} }
} }
function getMembersByPermission($permissionCodes = array('ADMIN')){ function getMembersByPermission($permissionCodes = array('ADMIN')){
if(!is_array($permissionCodes)) if(!is_array($permissionCodes))
user_error('Permissions must be passed to Subsite::getMembersByPermission as an array', E_USER_ERROR); user_error('Permissions must be passed to Subsite::getMembersByPermission as an array', E_USER_ERROR);
$SQL_permissionCodes = Convert::raw2sql($permissionCodes); $SQL_permissionCodes = Convert::raw2sql($permissionCodes);
$SQL_permissionCodes = join("','", $SQL_permissionCodes); $SQL_permissionCodes = join("','", $SQL_permissionCodes);
$join = <<<SQL $join = <<<SQL
LEFT JOIN `Group_Members` ON `Member`.`ID` = `Group_Members`.`MemberID` LEFT JOIN `Group_Members` ON `Member`.`ID` = `Group_Members`.`MemberID`
LEFT JOIN `Group` ON `Group`.`ID` = `Group_Members`.`GroupID` LEFT JOIN `Group` ON `Group`.`ID` = `Group_Members`.`GroupID`
LEFT JOIN `Permission` ON `Permission`.`GroupID` = `Group`.`ID` LEFT JOIN `Permission` ON `Permission`.`GroupID` = `Group`.`ID`
SQL; SQL;
return DataObject::get('Member', "`Group`.`SubsiteID` = $this->ID AND `Permission`.`Code` IN ('$SQL_permissionCodes')", '', $join); return DataObject::get('Member', "`Group`.`SubsiteID` = $this->ID AND `Permission`.`Code` IN ('$SQL_permissionCodes')", '', $join);
} }
static function getSubsitesForMember( $member = null, $permissionCodes = array('ADMIN')) { static function getSubsitesForMember( $member = null, $permissionCodes = array('ADMIN')) {
if(!is_array($permissionCodes)) if(!is_array($permissionCodes))
user_error('Permissions must be passed to Subsite::getSubsitesForMember as an array', E_USER_ERROR); user_error('Permissions must be passed to Subsite::getSubsitesForMember as an array', E_USER_ERROR);
if(!$member) if(!$member)
$member = Member::currentMember(); $member = Member::currentMember();
$memberID = (int)$member->ID; $memberID = (int)$member->ID;
$SQLa_permissionCodes = Convert::raw2sql($permissionCodes); $SQLa_permissionCodes = Convert::raw2sql($permissionCodes);
$SQLa_permissionCodes = join("','", $SQLa_permissionCodes); $SQLa_permissionCodes = join("','", $SQLa_permissionCodes);
if(self::hasMainSitePermission($member, $permissionCodes)) if(self::hasMainSitePermission($member, $permissionCodes))
return DataObject::get('Subsite'); return DataObject::get('Subsite');
else else
return DataObject::get('Subsite', "`MemberID` = {$memberID}" . ($permissionCodes ? " AND `Permission`.`Code` IN ('$SQLa_permissionCodes')" : ''), '', "LEFT JOIN `Group` ON `Subsite`.`ID` = `SubsiteID` LEFT JOIN `Permission` ON `Group`.`ID` = `Permission`.`GroupID` LEFT JOIN `Group_Members` ON `Group`.`ID` = `Group_Members`.`GroupID`"); return DataObject::get('Subsite', "`MemberID` = {$memberID}" . ($permissionCodes ? " AND `Permission`.`Code` IN ('$SQLa_permissionCodes')" : ''), '', "LEFT JOIN `Group` ON `Subsite`.`ID` = `SubsiteID` LEFT JOIN `Permission` ON `Group`.`ID` = `Permission`.`GroupID` LEFT JOIN `Group_Members` ON `Group`.`ID` = `Group_Members`.`GroupID`");
} }
static function hasMainSitePermission($member = null, $permissionCodes = array('ADMIN')) { static function hasMainSitePermission($member = null, $permissionCodes = array('ADMIN')) {
if(!is_array($permissionCodes)) if(!is_array($permissionCodes))
user_error('Permissions must be passed to Subsite::hasMainSitePermission as an array', E_USER_ERROR); user_error('Permissions must be passed to Subsite::hasMainSitePermission as an array', E_USER_ERROR);
if(!$member) if(!$member)
$member = Member::currentMember(); $member = Member::currentMember();
$SQLa_perm = Convert::raw2sql($permissionCodes); $SQLa_perm = Convert::raw2sql($permissionCodes);
$SQL_perms = join("','", $SQLa_perm); $SQL_perms = join("','", $SQLa_perm);
$memberID = (int)$member->ID; $memberID = (int)$member->ID;
return DB::query("SELECT COUNT(`Permission`.`ID`) FROM `Permission` LEFT JOIN `Group` ON `Group`.`ID` = `Permission`.`GroupID` LEFT JOIN `Group_Members` USING(`GroupID`) WHERE `Permission`.`Code` IN ('$SQL_perms') AND `SubsiteID` = 0 AND `MemberID` = {$memberID}")->value(); return DB::query("SELECT COUNT(`Permission`.`ID`) FROM `Permission` LEFT JOIN `Group` ON `Group`.`ID` = `Permission`.`GroupID` LEFT JOIN `Group_Members` USING(`GroupID`) WHERE `Permission`.`Code` IN ('$SQL_perms') AND `SubsiteID` = 0 AND `MemberID` = {$memberID}")->value();
} }
function createInitialRecords() { function createInitialRecords() {
} }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CMS ADMINISTRATION HELPERS // CMS ADMINISTRATION HELPERS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** /**
* Return the FieldSet that will build the search form in the CMS * Return the FieldSet that will build the search form in the CMS
*/ */
function adminSearchFields() { function adminSearchFields() {
return new FieldSet( return new FieldSet(
new TextField('Name', 'Sub-site name') new TextField('Name', 'Sub-site name')
); );
} }
} }
/** /**
* An instance of subsite that can be duplicated to provide a quick way to create new subsites. * An instance of subsite that can be duplicated to provide a quick way to create new subsites.
*/ */
class Subsite_Template extends Subsite { class Subsite_Template extends Subsite {
function duplicate($args = null) { function duplicate($args = null) {
if(!$args) if(!$args)
$args = array(); $args = array();
// create the subsite // create the subsite
$subsite = Subsite::create(''); $subsite = Subsite::create('');
// Apply arguments to field values // Apply arguments to field values
$subsite->write(); $subsite->write();
} }
/** /**
* Create an instance of this template, with the given title & subdomain * Create an instance of this template, with the given title & subdomain
*/ */
function createInstance($title, $subdomain) { function createInstance($title, $subdomain) {
$intranet = Object::create('Subsite'); $intranet = Object::create('Subsite');
$intranet->Title = $title; $intranet->Title = $title;
$intranet->Domain = $this->Domain; $intranet->Domain = $this->Domain;
$intranet->Subdomain = $subdomain; $intranet->Subdomain = $subdomain;
$intranet->TemplateID = $this->ID; $intranet->TemplateID = $this->ID;
$intranet->write(); $intranet->write();
$oldSubsiteID = Session::get('SubsiteID'); $oldSubsiteID = Session::get('SubsiteID');
self::changeSubsite($this->ID); self::changeSubsite($this->ID);
/* /*
* Copy data from this template to the given subsite. Does this using an iterative depth-first search. * Copy data from this template to the given subsite. Does this using an iterative depth-first search.
* This will make sure that the new parents on the new subsite are correct, and there are no funny * This will make sure that the new parents on the new subsite are correct, and there are no funny
* issues with having to check whether or not the new parents have been added to the site tree * issues with having to check whether or not the new parents have been added to the site tree
* when a page, etc, is duplicated * when a page, etc, is duplicated
*/ */
$stack = array(array(0,0)); $stack = array(array(0,0));
while(count($stack) > 0) { while(count($stack) > 0) {
list($sourceParentID, $destParentID) = array_pop($stack); list($sourceParentID, $destParentID) = array_pop($stack);
$children = Versioned::get_by_stage('Page', 'Live', "`ParentID`=$sourceParentID", ''); $children = Versioned::get_by_stage('Page', 'Live', "`ParentID`=$sourceParentID", '');
if($children) { if($children) {
foreach($children as $child) { foreach($children as $child) {
$childClone = $child->duplicateToSubsite($intranet, 'Stage'); $childClone = $child->duplicateToSubsite($intranet, 'Stage');
$childClone->ParentID = $destParentID; $childClone->ParentID = $destParentID;
$childClone->writeToStage('Stage'); $childClone->writeToStage('Stage');
$childClone->publish('Stage', 'Live'); $childClone->publish('Stage', 'Live');
array_push($stack, array($child->ID, $childClone->ID)); array_push($stack, array($child->ID, $childClone->ID));
} }
} }
} }
self::changeSubsite($oldSubsiteID); self::changeSubsite($oldSubsiteID);
return $intranet; return $intranet;
} }
} }
?> ?>

View File

@ -1,114 +1,114 @@
<?php <?php
class SubsiteAdmin extends GenericDataAdmin { class SubsiteAdmin extends GenericDataAdmin {
static $tree_class = "Subsite"; static $tree_class = "Subsite";
static $subitem_class = "Subsite"; static $subitem_class = "Subsite";
static $data_type = 'Subsite'; static $data_type = 'Subsite';
function performSearch() { function performSearch() {
} }
function getSearchFields() { function getSearchFields() {
return singleton('Subsite')->adminSearchFields(); return singleton('Subsite')->adminSearchFields();
} }
function getLink() { function getLink() {
return 'admin/intranets/'; return 'admin/intranets/';
} }
function Link() { function Link() {
return $this->getLink(); return $this->getLink();
} }
function Results($data, $form) { function Results($data, $form) {
$where = ''; $where = '';
if(isset($data['Name']) && $data['Name']) { if(isset($data['Name']) && $data['Name']) {
$SQL_name = Convert::raw2sql($data['Name']); $SQL_name = Convert::raw2sql($data['Name']);
$where = "`Title` LIKE '%$SQL_name%'"; $where = "`Title` LIKE '%$SQL_name%'";
} }
$intranets = DataObject::get('Subsite', $where); $intranets = DataObject::get('Subsite', $where);
if(!$intranets) if(!$intranets)
return null; return null;
$html = "<table class=\"ResultTable\"><thead><tr><th>Name</th><th>Domain</th></tr></thead><tbody>"; $html = "<table class=\"ResultTable\"><thead><tr><th>Name</th><th>Domain</th></tr></thead><tbody>";
$numIntranets = 0; $numIntranets = 0;
foreach($intranets as $intranet) { foreach($intranets as $intranet) {
$numIntranets++; $numIntranets++;
$evenOdd = ($numIntranets % 2) ? 'odd':'even'; $evenOdd = ($numIntranets % 2) ? 'odd':'even';
$html .= "<tr class=\"$evenOdd\"><td><a href=\"admin/intranets/show/{$intranet->ID}\">{$intranet->Title}</a></td><td>{$intranet->Subdomain}.{$intranet->Domain}</td></tr>"; $html .= "<tr class=\"$evenOdd\"><td><a href=\"admin/intranets/show/{$intranet->ID}\">{$intranet->Title}</a></td><td>{$intranet->Subdomain}.{$intranet->Domain}</td></tr>";
} }
$html .= "</tbody></table>"; $html .= "</tbody></table>";
return $html; return $html;
} }
function AddSubsiteForm() { function AddSubsiteForm() {
$templates = $this->getIntranetTemplates(); $templates = $this->getIntranetTemplates();
if($templates) { if($templates) {
$templateArray = $templates->map('ID', 'Domain'); $templateArray = $templates->map('ID', 'Domain');
} }
return new Form($this, 'AddIntranetForm', new FieldSet( return new Form($this, 'AddIntranetForm', new FieldSet(
new TextField('Name', 'Name:'), new TextField('Name', 'Name:'),
new TextField('Subdomain', 'Subdomain:'), new TextField('Subdomain', 'Subdomain:'),
new DropdownField('TemplateID', 'Use template:', $templateArray), new DropdownField('TemplateID', 'Use template:', $templateArray),
new TextField('AdminName', 'Admin name:'), new TextField('AdminName', 'Admin name:'),
new EmailField('AdminEmail', 'Admin email:') new EmailField('AdminEmail', 'Admin email:')
), ),
new FieldSet( new FieldSet(
new FormAction('addintranet', 'Add') new FormAction('addintranet', 'Add')
)); ));
} }
public function getIntranetTemplates() { public function getIntranetTemplates() {
return DataObject::get('Subsite_Template', '', 'Domain DESC'); return DataObject::get('Subsite_Template', '', 'Domain DESC');
} }
function addintranet($data, $form) { function addintranet($data, $form) {
$SQL_email = Convert::raw2sql($data['AdminEmail']); $SQL_email = Convert::raw2sql($data['AdminEmail']);
$member = DataObject::get_one('Member', "`Email`='$SQL_email'"); $member = DataObject::get_one('Member', "`Email`='$SQL_email'");
if(!$member) { if(!$member) {
$member = Object::create('Member'); $member = Object::create('Member');
$nameParts = explode(' ', $data['AdminName']); $nameParts = explode(' ', $data['AdminName']);
$member->FirstName = array_shift($nameParts); $member->FirstName = array_shift($nameParts);
$member->Surname = join(' ', $nameParts); $member->Surname = join(' ', $nameParts);
$member->Email = $data['AdminEmail']; $member->Email = $data['AdminEmail'];
$member->write(); $member->write();
} }
// Create intranet from existing template // Create intranet from existing template
// TODO Change template based on the domain selected. // TODO Change template based on the domain selected.
$intranet = Intranet::createFromTemplate($data['Name'], $data['Subdomain'], $data['TemplateID']); $intranet = Intranet::createFromTemplate($data['Name'], $data['Subdomain'], $data['TemplateID']);
$groupObjects = array(); $groupObjects = array();
// create Staff, Management and Administrator groups // create Staff, Management and Administrator groups
$groups = array( $groups = array(
'Administrators' => array('CL_ADMIN', 'CMS_ACCESS_CMSMain', 'CMS_ACCESS_AssetAdmin', 'CMS_ACCESS_SecurityAdmin', 'CMS_ACCESS_IntranetAdmin'), 'Administrators' => array('CL_ADMIN', 'CMS_ACCESS_CMSMain', 'CMS_ACCESS_AssetAdmin', 'CMS_ACCESS_SecurityAdmin', 'CMS_ACCESS_IntranetAdmin'),
'Management' => array('CL_MGMT'), 'Management' => array('CL_MGMT'),
'Staff' => array('CL_STAFF') 'Staff' => array('CL_STAFF')
); );
foreach($groups as $name => $perms) { foreach($groups as $name => $perms) {
$group = new Group(); $group = new Group();
$group->SubsiteID = $intranet->ID; $group->SubsiteID = $intranet->ID;
$group->Title = $name; $group->Title = $name;
$group->write(); $group->write();
foreach($perms as $perm) { foreach($perms as $perm) {
Permission::grant($group->ID, $perm); Permission::grant($group->ID, $perm);
} }
$groupObjects[$name] = $group; $groupObjects[$name] = $group;
} }
$member->Groups()->add($groupObjects['Administrators']); $member->Groups()->add($groupObjects['Administrators']);
Director::redirect('admin/intranets/show/' . $intranet->ID); Director::redirect('admin/intranets/show/' . $intranet->ID);
} }
} }
?> ?>