Module: appdb Branch: master Commit: 7d0469978ca35fb176f68c65b1dba90d4479dc5d URL: http://source.winehq.org/git/appdb.git/?a=commit;h=7d0469978ca35fb176f68c65b...
Author: Alexander Nicolaysen Sørnes alex@thehandofagony.com Date: Thu Jun 12 23:39:04 2008 +0200
application: Add support for filtering by app category
---
include/application.php | 12 +++++++++++- include/category.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletions(-)
diff --git a/include/application.php b/include/application.php index d663ed8..bb50fc4 100644 --- a/include/application.php +++ b/include/application.php @@ -1010,8 +1010,18 @@ class Application { public static function objectGetFilterInfo() { $oFilter = new FilterInterface(); + $aCategories = category::getOrderedList(); + $aCatNames = array(); + $aCatIds = array(); + + foreach($aCategories as $oCategory) + { + $aCatNames[] = $oCategory->sName; + $aCatIds[] = $oCategory->objectGetId(); + }
$oFilter->AddFilterInfo('appVersion.rating', 'Rating', array(FILTER_EQUALS, FILTER_LESS_THAN, FILTER_GREATER_THAN), FILTER_VALUES_ENUM, array('Platinum', 'Gold', 'Silver', 'Bronze', 'Garbage')); + $oFilter->AddFilterInfo('appFamily.catId', 'Category', array(FILTER_EQUALS), FILTER_VALUES_ENUM, $aCatIds, $aCatNames); return $oFilter; }
@@ -1138,7 +1148,7 @@ class Application { { $sExtraTables = ',appVersion'; $sWhereFilter = " AND appVersion.appId = appFamily.appId AND $sWhereFilter"; - } + }
if($sState != 'accepted' && !application::canEdit()) { diff --git a/include/category.php b/include/category.php index 5972e9e..e6dae38 100644 --- a/include/category.php +++ b/include/category.php @@ -135,6 +135,38 @@ class Category { return array(); }
+ /* Get a category's subcategory objects. Names are indented according + to subcategory level */ + function getSubCatList($iLevel) + { + $aOut = array(); + $iId = $this->iCatId ? $this->iCatId : 0; + + $sIndent = ''; + for($i = 0; $i < $iLevel; $i++) + $sIndent .= ' '; + + $hResult = query_parameters("SELECT * FROM appCategory WHERE catParent = '?' + ORDER BY catName", $iId); + + while($oRow = mysql_fetch_object($hResult)) + { + $oCat = new category($oRow->catId); + $oCat->sName = $sIndent.$oCat->sName; + $aOut[] = $oCat; + $aOut = array_merge($aOut, $oCat->getSubCatList($iLevel + 1)); + } + return $aOut; + } + + /* Get all category objects, ordered and with category names indented + according to subcategory level */ + static function getOrderedList() + { + $oCat = new category(); + return $oCat->getSubCatList(0); + } + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) { /* We don't send notification mails */