Recursively compute application counts for categories so the correct number of applications is

displayed.
This commit is contained in:
Chris Morgan
2005-05-11 02:26:11 +00:00
committed by WineHQ
parent f0b02e580e
commit cdc1c129bd
2 changed files with 44 additions and 13 deletions

View File

@@ -65,18 +65,18 @@ if($subs)
//set row color //set row color
$bgcolor = ($i % 2) ? "color0" : "color1"; $bgcolor = ($i % 2) ? "color0" : "color1";
//get number of apps //get number of apps in this sub-category
$appcount = sizeof($oSubCat->aApplicationsIds); $appcount = $oSubCat->getApplicationCount();
//format desc //format desc
$desc = substr(stripslashes($oSubCat->sDescription),0,70); $desc = substr(stripslashes($oSubCat->sDescription),0,70);
//display row //display row
echo "<tr class=$bgcolor>\n"; echo "<tr class=$bgcolor>\n";
echo " <td><a href='appbrowse.php?catId=$iSubcatId'>".$oSubCat->sName."</a></td>\n"; echo " <td><a href='appbrowse.php?catId=$iSubcatId'>".$oSubCat->sName."</a></td>\n";
echo " <td>$desc &nbsp;</td>\n"; echo " <td>$desc &nbsp;</td>\n";
echo " <td>$appcount &nbsp;</td>\n"; echo " <td>$appcount &nbsp;</td>\n";
echo "</tr>\n\n"; echo "</tr>\n\n";
} }
echo "</table>\n\n"; echo "</table>\n\n";
@@ -106,11 +106,11 @@ if($apps)
{ {
$oApp = new Application($iAppId); $oApp = new Application($iAppId);
//set row color //set row color
$bgcolor = ($i % 2) ? "color0" : "color1"; $bgcolor = ($i % 2) ? "color0" : "color1";
//format desc //format desc
$desc = trim_description($oApp->sDescription); $desc = trim_description($oApp->sDescription);
//display row //display row
echo "<tr class=$bgcolor>\n"; echo "<tr class=$bgcolor>\n";

View File

@@ -167,6 +167,37 @@ class Category {
$path[] = array(0, "ROOT"); $path[] = array(0, "ROOT");
return array_reverse($path); 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;
}
} }