From f4fb7899669264265bae1dc3ecafc5235970dd81 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 24 May 2014 00:25:39 +0200 Subject: [PATCH] Fix TemplateGroup::getSelectList() and add parameter to specify initial depth --- .../template/group/TemplateGroup.class.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/lib/data/template/group/TemplateGroup.class.php b/wcfsetup/install/files/lib/data/template/group/TemplateGroup.class.php index ff227b685a..46fd18f9dd 100644 --- a/wcfsetup/install/files/lib/data/template/group/TemplateGroup.class.php +++ b/wcfsetup/install/files/lib/data/template/group/TemplateGroup.class.php @@ -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 $ignore + * @param array $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 -- 2.20.1