diff --git a/include/application.php b/include/application.php
index b93562e..2ef6406 100644
--- a/include/application.php
+++ b/include/application.php
@@ -993,6 +993,18 @@ class Application {
$sExtraTables .= ',appData';
$sWhereFilter .= " AND appData.type = 'downloadurl' AND appData.versionId = appVersion.versionId AND appData.state = 'accepted'";
}
+ if($aOptions['appCategory'])
+ {
+ $oCategory = new Category($aOptions['appCategory']);
+ $aSubCats = $oCategory->getSubCatList();
+ $sWhereFilter .= " AND ( catId = '{$aOptions['appCategory']}' ";
+ foreach($aSubCats as $oCat)
+ {
+ $iCatId = $oCat->objectGetId();
+ $sWhereFilter .= " OR catId = '$iCatId' ";
+ }
+ $sWhereFilter .= ") ";
+ }
/* Should we add a limit clause to the query? */
if($iRows || $iStart)
{
@@ -1065,7 +1077,7 @@ class Application {
$oFilter->AddFilterInfo('appVersion.rating', 'Rating', array(FILTER_EQUALS), FILTER_VALUES_ENUM, array('Platinum', 'Gold', 'Silver', 'Bronze', 'Garbage'));
$oFilter->AddFilterInfo('versions.id', 'Wine version', array(FILTER_EQUALS,FILTER_LESS_THAN,FILTER_GREATER_THAN), FILTER_VALUES_ENUM, $aWineVersionIds, $aWineVersions);
- $oFilter->AddFilterInfo('appFamily.catId', 'Category', array(FILTER_EQUALS), FILTER_VALUES_ENUM, $aCatIds, $aCatNames);
+ $oFilter->AddFilterInfo('appCategory', 'Category', array(FILTER_OPTION_ENUM), FILTER_VALUES_OPTION_ENUM, $aCatIds, $aCatNames);
$oFilter->AddFilterInfo('appVersion.license', 'License', array(FILTER_EQUALS), FILTER_VALUES_ENUM, $aLicenses);
$oFilter->AddFilterInfo('appFamily.appName', 'Name', array(FILTER_CONTAINS, FILTER_STARTS_WITH, FILTER_ENDS_WITH), FILTER_VALUES_NORMAL);
$oFilter->AddFilterInfo('onlyDownloadable', 'Only show downloadable apps', array(FILTER_OPTION_BOOL), FILTER_VALUES_OPTION_BOOL, array('false','true'));
@@ -1237,6 +1249,18 @@ class Application {
$sExtraTables .= ',appData';
$sWhereFilter .= " AND appData.type = 'downloadurl' AND appData.versionId = appVersion.versionId";
}
+ if($aOptions['appCategory'])
+ {
+ $oCategory = new Category($aOptions['appCategory']);
+ $aSubCats = $oCategory->getSubCatList();
+ $sWhereFilter .= " AND ( catId = '{$aOptions['appCategory']}' ";
+ foreach($aSubCats as $oCat)
+ {
+ $iCatId = $oCat->objectGetId();
+ $sWhereFilter .= " OR catId = '$iCatId' ";
+ }
+ $sWhereFilter .= ") ";
+ }
if($sState != 'accepted' && !application::canEdit())
{
diff --git a/include/category.php b/include/category.php
index e6dae38..c0c6bc1 100644
--- a/include/category.php
+++ b/include/category.php
@@ -137,7 +137,7 @@ class Category {
/* Get a category's subcategory objects. Names are indented according
to subcategory level */
- function getSubCatList($iLevel)
+ function getSubCatList($iLevel = 0)
{
$aOut = array();
$iId = $this->iCatId ? $this->iCatId : 0;
diff --git a/include/db_filter.php b/include/db_filter.php
index fa5a0b7..538a534 100644
--- a/include/db_filter.php
+++ b/include/db_filter.php
@@ -18,6 +18,7 @@ define('FILTER_LESS_THAN', 7);
define('FILTER_NOT_EQUALS', 8);
define('FILTER_NOT_LIKE', 9);
define('FILTER_OPTION_BOOL', 10);
+define('FILTER_OPTION_ENUM', 11);
/* A filter as part of an SQL query, such as something = 'somevalue' */
class Filter
@@ -82,7 +83,7 @@ class Filter
public function getExpression()
{
/* We let callers handle options themselves, so don't include them in the WHERE clause */
- if($this->iType == FILTER_OPTION_BOOL)
+ if($this->isOption())
return '';
$sData = $this->sData;
@@ -105,6 +106,19 @@ class Filter
return "{$this->sColumn} $sOp '$sData'";
}
+
+ public function IsOption()
+ {
+ switch($this->iType)
+ {
+ case FILTER_OPTION_BOOL:
+ case FILTER_OPTION_ENUM:
+ return true;
+
+ default:
+ return false;
+ }
+ }
}
/* Class handling tables where the user can filter contents */
diff --git a/include/db_filter_ui.php b/include/db_filter_ui.php
index aff380c..b98b6c8 100644
--- a/include/db_filter_ui.php
+++ b/include/db_filter_ui.php
@@ -13,6 +13,7 @@ require_once('db_filter.php');
define('FILTER_VALUES_NORMAL', 1);
define('FILTER_VALUES_ENUM', 2);
define('FILTER_VALUES_OPTION_BOOL', 3);
+define('FILTER_VALUES_OPTION_ENUM', 4);
define('MAX_FILTERS', 50);
@@ -71,6 +72,19 @@ class FilterInfo
return $this->aTypes;
}
+ public function isOption()
+ {
+ switch($this->iValueType)
+ {
+ case FILTER_VALUES_OPTION_BOOL:
+ case FILTER_VALUES_OPTION_ENUM:
+ return true;
+
+ default:
+ return false;
+ }
+ }
+
public static function getOpName($iOpId)
{
switch($iOpId)
@@ -219,7 +233,7 @@ class FilterInterface
/* Printing 'equal to' sounds weird if it is the only choice */
if($aTypes[0] != FILTER_EQUALS)
$shEditor .= $oColumn->getOpName($aTypes[0]);
- } else
+ } else if ($aTypes[0] != FILTER_OPTION_ENUM)
{
$shEditor .= " ';
+ } else
+ {
+ echo "";
}
switch($oColumn->getValueType())
@@ -248,6 +265,7 @@ class FilterInterface
$shEditor .= "getData()}\" name='s{$sColumn}Data$sId' size='30' />";
break;
case FILTER_VALUES_ENUM:
+ case FILTER_VALUES_OPTION_ENUM:
$shEditor .= $this->getEnumEditor($oColumn, $oFilter, $sId);
break;
}
@@ -369,11 +387,16 @@ class FilterInterface
{
if(!array_key_exists($oOption->getColumn(), $aCounts))
$shNewItemsEditor .= $this->getOptionBoolEditor(-1, $oDummyFilter);
+ $shNewItemsEditor .= '
';
} else
{
- $shNewItemsEditor .= $this->getItemEditor(-1, $oDummyFilter);
+ /* Make necessary checks for filters that are only supposed to be shown once */
+ if($oOption->getValueType() != FILTER_VALUES_OPTION_ENUM || !array_key_exists($oOption->getColumn(), $aCounts))
+ {
+ $shNewItemsEditor .= $this->getItemEditor(-1, $oDummyFilter);
+ $shNewItemsEditor .= '
';
+ }
}
- $shNewItemsEditor .= '
';
}
return $shNewItemsEditor.$shCurrentItemsEditor;
@@ -403,14 +426,20 @@ class FilterInterface
/* Only show an option as an active filter if it has been changed
from the default */
- if($oOption->getValueType() == FILTER_VALUES_OPTION_BOOL)
+ if($oOption->getValueType() == FILTER_VALUES_OPTION_BOOL || $oOption->getValueType() == FILTER_VALUES_OPTION_ENUM)
{
- /* The default option is the first entry in the list of choices */
- $aChoices = $oOption->getValueTypeData();
- $sDefault = $aChoices[0];
- if(!$sData)
- $sData = 'false';
- if($sData == $sDefault)
+ if($oOption->getValueType() == FILTER_VALUES_OPTION_BOOL)
+ {
+ /* The default option is the first entry in the list of choices */
+ $aChoices = $oOption->getValueTypeData();
+ $sDefault = $aChoices[0];
+ if(!$sData)
+ $sData = 'false';
+
+ if($sData == $sDefault)
+ continue;
+ }
+ if($i > 0)
continue;
$bChangedOption = true;
}
@@ -485,16 +514,21 @@ class FilterInterface
$aOptions = array();
foreach($this->oFilterSet->getFilters() as $oFilter)
{
- if($oFilter->getOperatorId() == FILTER_OPTION_BOOL)
+ if($oFilter->isOption())
$aOptions[$oFilter->getColumn()] = $oFilter->getData();
}
foreach($this->aFilterInfo as $oFilterInfo)
{
- if($oFilterInfo->getValueType() == FILTER_VALUES_OPTION_BOOL &&
+ if($oFilterInfo->isOption() &&
!array_key_exists($oFilterInfo->getColumn(), $aOptions))
{
$aTypes = $oFilterInfo->getTypes();
- $sDefault = $aTypes[0];
+
+ if($oFilterInfo->getValueType() == FILTER_VALUES_OPTION_BOOL)
+ $sDefault = $aTypes[0];
+ else
+ $sDefault = '';
+
$aOptions[$oFilterInfo->getColumn()] = $sDefault;
}
}