Fix TemplateGroup::getSelectList() and add parameter to specify initial depth
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 23 May 2014 22:25:39 +0000 (00:25 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 10 Jun 2014 17:17:12 +0000 (19:17 +0200)
wcfsetup/install/files/lib/data/template/group/TemplateGroup.class.php

index ff227b685adc4c017e261665d213b94757c5c77d..46fd18f9dd1921bad74223f8520152aa22bf3c58 100644 (file)
@@ -29,28 +29,28 @@ class TemplateGroup extends DatabaseObject {
        protected static $selectList = null;
        
        /**
-        * Creates a select list.
+        * Creates a select list of all template groups.
         * 
-        * @param       array<intger>   $ignore
+        * @param       array<integer>  $ignore         Array of template group ids that should be excluded with all of their children
+        * @param       integer         $initialDepth   Specifies the initial indentation depth of the list
         * @return      array
         */
-       public static function getSelectList($ignore = array()) {
+       public static function getSelectList($ignore = array(), $initialDepth = 0) {
                if (self::$templateGroupStructure === null) {
                        self::$templateGroupStructure = array();
                        
-                       $sql = "SELECT          templateGroupID, templateGroupName, parentTemplatePackID
+                       $sql = "SELECT          templateGroupID, templateGroupName, parentTemplateGroupID
                                FROM            wcf".WCF_N."_template_group
                                ORDER BY        templateGroupName ASC";
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute();
                        while ($row = $statement->fetchArray()) {
-                               self::$templateGroupStructure[$row['parentTemplatePackID']][] = new TemplateGroup(null, $row);
+                               self::$templateGroupStructure[$row['parentTemplateGroupID'] ?: 0][] = new TemplateGroup(null, $row);
                        }
-                       
                }
                
                self::$selectList = array();
-               self::makeSelectList(0, 0, $ignore);
+               self::makeSelectList(0, $initialDepth, $ignore);
                
                return self::$selectList;
        }
@@ -63,9 +63,9 @@ class TemplateGroup extends DatabaseObject {
         * @param       array           $ignore                 list of template group ids to ignore in result
         */
        protected static function makeSelectList($parentID = 0, $depth = 0, $ignore = array()) {
-               if (!isset(self::$templateGroupStructure[$parentID])) return;
+               if (!isset(self::$templateGroupStructure[$parentID ?: 0])) return;
                
-               foreach (self::$templateGroupStructure[$parentID] as $templateGroup) {
+               foreach (self::$templateGroupStructure[$parentID ?: 0] as $templateGroup) {
                        if (!empty($ignore) && in_array($templateGroup->templateGroupID, $ignore)) continue;
                        
                        // we must encode html here because the htmloptions plugin doesn't do it