diff --git a/appbrowse.php b/appbrowse.php index ac44bb6..3f3afcc 100644 --- a/appbrowse.php +++ b/appbrowse.php @@ -65,18 +65,18 @@ if($subs) //set row color $bgcolor = ($i % 2) ? "color0" : "color1"; - //get number of apps - $appcount = sizeof($oSubCat->aApplicationsIds); + //get number of apps in this sub-category + $appcount = $oSubCat->getApplicationCount(); - //format desc - $desc = substr(stripslashes($oSubCat->sDescription),0,70); + //format desc + $desc = substr(stripslashes($oSubCat->sDescription),0,70); - //display row - echo "\n"; - echo " ".$oSubCat->sName."\n"; - echo " $desc  \n"; - echo " $appcount  \n"; - echo "\n\n"; + //display row + echo "\n"; + echo " ".$oSubCat->sName."\n"; + echo " $desc  \n"; + echo " $appcount  \n"; + echo "\n\n"; } echo "\n\n"; @@ -106,11 +106,11 @@ if($apps) { $oApp = new Application($iAppId); - //set row color - $bgcolor = ($i % 2) ? "color0" : "color1"; + //set row color + $bgcolor = ($i % 2) ? "color0" : "color1"; //format desc - $desc = trim_description($oApp->sDescription); + $desc = trim_description($oApp->sDescription); //display row echo "\n"; diff --git a/include/category.php b/include/category.php index b1dd916..2ec41c2 100644 --- a/include/category.php +++ b/include/category.php @@ -167,6 +167,37 @@ class Category { $path[] = array(0, "ROOT"); return array_reverse($path); } + + /* return the total number of applications in this category */ + function getApplicationCount($depth = null) + { + $MAX_DEPTH = 5; + + if($depth) + $depth++; + else + $depth = 0; + + /* if we've reached our max depth, just return 0 and stop recursing */ + if($depth >= $MAX_DEPTH) + return 0; + + $totalApps = 0; + + /* add on all apps in each category this category includes */ + if($this->aSubcatsIds) + { + while(list($i, $iSubcatId) = each($this->aSubcatsIds)) + { + $subCat = new Category($iSubcatId); + $totalApps += $subCat->getApplicationCount($depth); + } + } + + $totalApps += sizeof($this->aApplicationsIds); /* add on the apps at this category level */ + + return $totalApps; + } }