Added option to set default application within a group
authorAlexander Ebert <ebert@woltlab.com>
Tue, 6 Nov 2012 20:50:54 +0000 (21:50 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 6 Nov 2012 20:50:54 +0000 (21:50 +0100)
wcfsetup/install/files/acp/templates/applicationGroupAdd.tpl
wcfsetup/install/files/acp/templates/applicationManagement.tpl
wcfsetup/install/files/lib/acp/form/ApplicationGroupAddForm.class.php
wcfsetup/install/files/lib/acp/form/ApplicationGroupEditForm.class.php
wcfsetup/install/files/lib/data/application/ApplicationAction.class.php
wcfsetup/install/files/lib/data/application/group/ApplicationGroupAction.class.php
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/lang/de.xml

index 5554d8c87eba48982807f945b43c3a826dfb33af..d9b5a5b0976135424bc06cdc91531f5f34e1b656 100644 (file)
@@ -65,6 +65,7 @@
                                                <thead>
                                                        <tr>
                                                                <th class="columnID columnPackageID" colspan="3">{lang}wcf.global.objectID{/lang}</th>
+                                                               <th class="columnMark columnPrimaryApplication">{lang}wcf.acp.application.primaryApplication{/lang}</th>
                                                                <th class="columnText columnPackageName">{lang}wcf.acp.package.name{/lang}</th>
                                                                <th class="columnText columnDomainName">{lang}wcf.acp.application.domainName{/lang}</th>
                                                                <th class="columnText columnDomainPath">{lang}wcf.acp.application.domainPath{/lang}</th>
@@ -81,6 +82,7 @@
                                                                        <td class="columnMark"><input type="checkbox" name="applications[]" value="{@$application->packageID}"{if $application->packageID|in_array:$applications} checked="checked"{/if} /></td>
                                                                        <td class="columnIcon"><a href="{link controller='ApplicationEdit' id=$application->packageID}{/link}"><img src="{@RELATIVE_WCF_DIR}icon/edit.svg" alt="" class="icon16 jsTooltip" title="{lang}wcf.global.button.edit{/lang}" /></a></td>
                                                                        <td class="columnID columnPackageID">{#$application->packageID}</td>
+                                                                       <td class="columnMark columnPrimaryApplication"><input type="radio" name="primaryApplication" value="{@$application->packageID}" required="required"{if $primaryApplication == $application->packageID} checked="checked"{/if} /></td>
                                                                        <td class="columnText columnPackageName"><a href="{link controller='PackageView' id=$application->packageID}{/link}">{lang}{$application->getPackage()->getName()}{/lang}</a></td>
                                                                        <td class="columnText columnDomainName">{$application->domainName}</td>
                                                                        <td class="columnText columnDomainPath">{$application->domainPath}</td>
index c9b91a755be2b7952bde8853bb013d9233698594..639821f0a8e46e3c7669b092c9c846b26d9da40c 100644 (file)
                                        <tr>
                                                <td class="columnIcon"><a href="{link controller='ApplicationEdit' id=$application->packageID}{/link}"><img src="{@RELATIVE_WCF_DIR}icon/edit.svg" alt="" class="icon16 jsTooltip" title="{lang}wcf.global.button.edit{/lang}" /></a></td>
                                                <td class="columnID columnPackageID">{#$application->packageID}</td>
-                                               <td class="columnText columnPackageName"><a href="{link controller='PackageView' id=$application->packageID}{/link}">{lang}{$application->getPackage()->getName()}{/lang}</a></td>
+                                               <td class="columnText columnPackageName">
+                                                       <a href="{link controller='PackageView' id=$application->packageID}{/link}">{lang}{$application->getPackage()->getName()}{/lang}</a>
+                                                       
+                                                       {if $application->isPrimary}
+                                                               <aside class="statusDisplay">
+                                                                       <ul class="statusIcons">
+                                                                               <li><img src="{@RELATIVE_WCF_DIR}icon/check.svg" alt="" class="icon16 jsTooltip" title="{lang}{lang}wcf.acp.application.primaryApplication{/lang}{/lang}" /></li>
+                                                                       </ul>
+                                                               </aside>
+                                                       {/if}
+                                               </td>
                                                <td class="columnText columnDomainName">{$application->domainName}</td>
                                                <td class="columnText columnDomainPath">{$application->domainPath}</td>
                                                <td class="columnText columnCookieDomain">{$application->cookieDomain}</td>
index aed21ff54d44e67e6d14e69959ec6f9232177319..58c395aef81175820afd57dba604238687bcfd7a 100644 (file)
@@ -46,6 +46,12 @@ class ApplicationGroupAddForm extends ACPForm {
         */
        public $neededPermissions = array('admin.system.canManageApplication');
        
+       /**
+        * primary application's package id
+        * @var integer
+        */
+       public $primaryApplication = 0;
+       
        /**
         * @see wcf\page\IPage::readParameters()
         */
@@ -75,6 +81,7 @@ class ApplicationGroupAddForm extends ACPForm {
                
                if (isset($_POST['applications']) && is_array($_POST['applications'])) $this->applications = ArrayUtil::toIntegerArray($_POST['applications']);
                if (isset($_POST['groupName'])) $this->groupName = StringUtil::trim($_POST['groupName']);
+               if (isset($_POST['primaryApplication'])) $this->primaryApplication = intval($_POST['primaryApplication']);
        }
        
        /**
@@ -115,6 +122,15 @@ class ApplicationGroupAddForm extends ACPForm {
                                $packages[] = $application->getPackage()->package;
                        }
                }
+               
+               if ($this->primaryApplication == 0) {
+                       throw new UserInputException('applications', 'primaryApplication.empty');
+               }
+               else {
+                       if (!in_array($this->primaryApplication, $this->applications)) {
+                               throw new UserInputException('applications', 'primaryApplication.notValid');
+                       }
+               }
        }
        
        /**
@@ -149,7 +165,8 @@ class ApplicationGroupAddForm extends ACPForm {
                        'applications' => $this->applications,
                        'data' => array(
                                'groupName' => $this->groupName
-                       )
+                       ),
+                       'primaryApplication' => $this->primaryApplication
                ));
                $this->objectAction->executeAction();
                $this->saved();
@@ -157,6 +174,7 @@ class ApplicationGroupAddForm extends ACPForm {
                // reset values
                $this->applications = array();
                $this->groupName = '';
+               $this->primaryApplication = 0;
                
                // reload available applications
                $this->readAvailableApplications();
@@ -177,7 +195,8 @@ class ApplicationGroupAddForm extends ACPForm {
                        'action' => 'add',
                        'applications' => $this->applications,
                        'availableApplications' => $this->availableApplications,
-                       'groupName' => $this->groupName
+                       'groupName' => $this->groupName,
+                       'primaryApplication' => $this->primaryApplication,
                ));
        }
 }
index 0baa76619f3b652348a63f7cee0bed46834b454d..6eac29954573821af9f256938e6e6b45648d61f6 100644 (file)
@@ -93,6 +93,13 @@ class ApplicationGroupEditForm extends ApplicationGroupAddForm {
                
                if (empty($_POST)) {
                        $this->groupName = $this->applicationGroup->groupName;
+                       
+                       foreach ($this->availableApplications as $application) {
+                               if ($application->isPrimary) {
+                                       $this->primaryApplication = $application->packageID;
+                                       break;
+                               }
+                       }
                }
        }
        
@@ -107,7 +114,8 @@ class ApplicationGroupEditForm extends ApplicationGroupAddForm {
                        'applications' => $this->applications,
                        'data' => array(
                                'groupName' => $this->groupName
-                       )
+                       ),
+                       'primaryApplication' => $this->primaryApplication
                ));
                $this->objectAction->executeAction();
                $this->saved();
index 7a16d1880b2fb4de5c92eeb5b50784547078f0ef..8e4f888188f914e29056c482257b7eb03aec2697 100644 (file)
@@ -34,7 +34,8 @@ class ApplicationAction extends AbstractDatabaseObjectAction {
                $sql = "UPDATE  wcf".WCF_N."_application
                        SET     groupID = ?,
                                cookieDomain = ?,
-                               cookiePath = ?
+                               cookiePath = ?,
+                               isPrimary = ?
                        WHERE   packageID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                
@@ -75,10 +76,13 @@ class ApplicationAction extends AbstractDatabaseObjectAction {
                        $path = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash(implode('/', $path)));
                        
                        foreach (array_keys($data) as $packageID) {
+                               $isPrimary = ($this->parameters['primaryApplication'] == $packageID) ? 1 : 0;
+                               
                                $statement->execute(array(
                                        $this->parameters['groupID'],
                                        $domainName,
                                        $path,
+                                       $isPrimary,
                                        $packageID
                                ));
                        }
@@ -99,7 +103,8 @@ class ApplicationAction extends AbstractDatabaseObjectAction {
                $sql = "UPDATE  wcf".WCF_N."_application
                        SET     groupID = ?,
                                cookieDomain = domainName,
-                               cookiePath = domainPath
+                               cookiePath = domainPath,
+                               isPrimary = 0
                        WHERE   packageID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                
index c57de1a275e12ff93c9d483f342fa970762561dd..e72438448899051d5088a3bc94237054e882e7cc 100644 (file)
@@ -33,10 +33,11 @@ class ApplicationGroupAction extends AbstractDatabaseObjectAction {
        public function create() {
                $applicationGroup = parent::create();
                
-               if (isset($this->parameters['applications'])) {
-                       $applicationAction = new ApplicationAction($this->parameters['applications'], 'group', array('groupID' => $applicationGroup->groupID));
-                       $applicationAction->executeAction();
-               }
+               $applicationAction = new ApplicationAction($this->parameters['applications'], 'group', array(
+                       'groupID' => $applicationGroup->groupID,
+                       'primaryApplication' => $this->parameters['primaryApplication']
+               ));
+               $applicationAction->executeAction();
                
                return $applicationGroup;
        }
@@ -48,7 +49,7 @@ class ApplicationGroupAction extends AbstractDatabaseObjectAction {
                parent::update();
                
                // read list of currently associated applications
-               $applicationGroup = current($this->objects);
+               $applicationGroup = current(reset($this->objects));
                $applicationList = new ApplicationList();
                $applicationList->getConditionBuilder()->add("application.groupID = ?", array($applicationGroup->groupID));
                $applicationList->sqlLimit = 0;
@@ -76,7 +77,10 @@ class ApplicationGroupAction extends AbstractDatabaseObjectAction {
                }
                
                // rebuild current group
-               $applicationAction = new ApplicationAction($updateApplications, 'group', array('groupID' => $applicationGroup->groupID));
+               $applicationAction = new ApplicationAction($updateApplications, 'group', array(
+                       'groupID' => $applicationGroup->groupID,
+                       'primaryApplication' => $this->parameters['primaryApplication']
+               ));
                $applicationAction->executeAction();
                
                // remove applications from group
index 14dd4f24241efd682c8739c7901d190de155b070..e1009882998ac7fd921b6103ab6a35e91a463979 100644 (file)
@@ -425,8 +425,10 @@ class WCF {
                }
                
                // step 2) run each application
-               foreach ($loadedApplications as $application) {
-                       $application->__run();
+               if (!class_exists('wcf\system\WCFACP', false)) {
+                       foreach ($loadedApplications as $application) {
+                               $application->__run();
+                       }
                }
        }
        
index 5826c3a18ee9fb7395c08000ce008dac7140db16..6bd7fccee16e826e88f3360e446e3eb1c9bbb948 100644 (file)
@@ -36,6 +36,7 @@
                <item name="wcf.acp.application.group.title"><![CDATA[Anwendungsgruppe: &bdquo;{$applicationGroup->groupName}&ldquo;]]></item>
                <item name="wcf.acp.application.independentApplications"><![CDATA[Unabhängige Anwendungen]]></item>
                <item name="wcf.acp.application.management"><![CDATA[Anwendungen verwalten]]></item>
+               <item name="wcf.acp.application.primaryApplication"><![CDATA[Primäre Anwendung]]></item>
        </category>
        
        <category name="wcf.acp.cache">