From 8060eab22a49167dd290db0037df262eae56b192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Thu, 2 Jul 2009 23:27:50 +0200 Subject: [PATCH] category: Order cat list on add/edit form --- include/category.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/include/category.php b/include/category.php index c0c6bc1..dc51bd4 100644 --- a/include/category.php +++ b/include/category.php @@ -160,11 +160,20 @@ class Category { } /* Get all category objects, ordered and with category names indented - according to subcategory level */ - static function getOrderedList() + according to subcategory level. + Optionally includes the 'Main' top category. */ + static function getOrderedList($bIncludeMain = false) { $oCat = new category(); - return $oCat->getSubCatList(0); + + if(!$bIncludeMain) + return $oCat->getSubCatList(0); + + $oCat->sName = 'Main'; + $aCats = array($oCat); + $aCats += $oCat->getSubCatList(1); + + return $aCats; } function objectGetMail($sAction, $bMailSubmitter, $bParentAction) @@ -278,18 +287,14 @@ class Category { function outputEditor() { - $sQuery = "SELECT catId, catName FROM appCategory WHERE catId!='?'"; - $hResult = query_parameters($sQuery, $this->iCatId); + $aCategories = category::getOrderedList(true); + $aCatNames = array(); + $aCatIds = array(); - /* Add the virtual 'Main' category */ - $aCatIds = array(0); - $aCatNames = array('Main'); - - /* Add the rest from the database */ - while($oRow = query_fetch_object($hResult)) + foreach($aCategories as $oCategory) { - $aCatIds[] = $oRow->catId; - $aCatNames[] = $oRow->catName; + $aCatNames[] = $oCategory->sName; + $aCatIds[] = $oCategory->objectGetId(); } echo "