Load dashboard boxes in two steps internally
authorMatthias Schmidt <gravatronics@live.com>
Sun, 24 May 2015 09:43:06 +0000 (11:43 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 24 May 2015 09:48:33 +0000 (11:48 +0200)
First, initialize all boxes and only after that, compile the templates.
This change allows to cache object ids in init() in factories which
fetch all required objects at once when getting the required objects
in the render() method.

wcfsetup/install/files/lib/system/dashboard/DashboardHandler.class.php

index ecb8aead2cc5d2706f5b3c1b9d33c9fb0a7f1064..b73c317699c153647d38a5a06f8c4ca2120ebd05 100644 (file)
@@ -60,7 +60,11 @@ class DashboardHandler extends SingletonFactory {
                        }
                }
                
-               $contentTemplate = $sidebarTemplate = '';
+               // 1. initialize all boxes first
+               $boxObjects = array(
+                       'content' => array(),
+                       'sidebar' => array()
+               );
                foreach ($boxIDs as $boxID) {
                        $className = $this->boxCache[$boxID]->className;
                        if (!ClassUtil::isInstanceOf($className, 'wcf\system\dashboard\box\IDashboardBox')) {
@@ -70,12 +74,16 @@ class DashboardHandler extends SingletonFactory {
                        $boxObject = new $className();
                        $boxObject->init($this->boxCache[$boxID], $page);
                        
-                       if ($this->boxCache[$boxID]->boxType == 'content') {
-                               $contentTemplate .= $boxObject->getTemplate();
-                       }
-                       else {
-                               $sidebarTemplate .= $boxObject->getTemplate();
-                       }
+                       $boxObjects[$this->boxCache[$boxID]->boxType][] = $boxObject;
+               }
+               
+               // 2. fetch all templates
+               $contentTemplate = $sidebarTemplate = '';
+               foreach ($boxObjects['content'] as $box) {
+                       $contentTemplate .= $box->getTemplate();
+               }
+               foreach ($boxObjects['sidebar'] as $box) {
+                       $sidebarTemplate .= $box->getTemplate();
                }
                
                WCF::getTPL()->assign(array(