2004-12-12 03:51:51 +00:00
|
|
|
<?php
|
|
|
|
|
/***************************************************/
|
2004-03-15 16:22:00 +00:00
|
|
|
/* this class represents a category + its children */
|
2004-12-12 03:51:51 +00:00
|
|
|
/***************************************************/
|
|
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
/**
|
|
|
|
|
* Category class for handling categories.
|
|
|
|
|
*/
|
2004-03-15 16:22:00 +00:00
|
|
|
class Category {
|
2005-02-09 02:20:21 +00:00
|
|
|
var $iCatId;
|
|
|
|
|
var $iParentId;
|
|
|
|
|
var $sName;
|
|
|
|
|
var $sDescription;
|
|
|
|
|
var $aApplicationsIds; // an array that contains the appId of every application linked to this category
|
|
|
|
|
var $aSubcatsIds; // an array that contains the appId of every application linked to this category
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
|
2005-02-06 17:49:48 +00:00
|
|
|
/**
|
2005-02-09 02:20:21 +00:00
|
|
|
* constructor, fetches the data.
|
2005-02-06 17:49:48 +00:00
|
|
|
*/
|
2005-02-09 02:20:21 +00:00
|
|
|
function Category($iCatId = null)
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
2005-02-09 02:20:21 +00:00
|
|
|
// we are working on an existing vendor
|
|
|
|
|
if($iCatId=="0" || $iCatId)
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
2005-02-09 02:20:21 +00:00
|
|
|
/*
|
|
|
|
|
* We fetch the data related to this vendor.
|
|
|
|
|
*/
|
|
|
|
|
$sQuery = "SELECT *
|
|
|
|
|
FROM appCategory
|
|
|
|
|
WHERE catId = ".$iCatId;
|
|
|
|
|
if($hResult = query_appdb($sQuery))
|
2005-02-06 17:49:48 +00:00
|
|
|
{
|
2005-02-09 02:20:21 +00:00
|
|
|
$oRow = mysql_fetch_object($hResult);
|
|
|
|
|
$this->iCatId = $iCatId;
|
|
|
|
|
$this->iParentId = $oRow->catParent;
|
|
|
|
|
$this->sName = $oRow->catName;
|
|
|
|
|
$this->sDescription = $oRow->catDescription;
|
2005-02-06 17:49:48 +00:00
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
}
|
2004-12-12 03:51:51 +00:00
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
/*
|
|
|
|
|
* We fetch applicationsIds.
|
|
|
|
|
*/
|
|
|
|
|
$sQuery = "SELECT appId
|
|
|
|
|
FROM appFamily
|
2005-02-19 01:21:14 +00:00
|
|
|
WHERE catId = ".$iCatId."
|
|
|
|
|
AND queued = 'false'";
|
2005-02-09 02:20:21 +00:00
|
|
|
if($hResult = query_appdb($sQuery))
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2005-02-09 02:20:21 +00:00
|
|
|
while($oRow = mysql_fetch_object($hResult))
|
|
|
|
|
{
|
|
|
|
|
$this->aApplicationsIds[] = $oRow->appId;
|
|
|
|
|
}
|
2004-12-12 03:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
/*
|
|
|
|
|
* We fetch subcatIds.
|
|
|
|
|
*/
|
|
|
|
|
$sQuery = "SELECT catId
|
|
|
|
|
FROM appCategory
|
|
|
|
|
WHERE catParent = ".$iCatId;
|
|
|
|
|
if($hResult = query_appdb($sQuery))
|
|
|
|
|
{
|
|
|
|
|
while($oRow = mysql_fetch_object($hResult))
|
|
|
|
|
{
|
|
|
|
|
$this->aSubcatsIds[] = $oRow->catId;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-12-12 03:51:51 +00:00
|
|
|
}
|
2005-02-09 02:20:21 +00:00
|
|
|
}
|
2004-12-12 03:51:51 +00:00
|
|
|
|
|
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
/**
|
|
|
|
|
* Creates a new category.
|
|
|
|
|
*/
|
|
|
|
|
function create($sName=null, $sDescription=null, $iParentId=null)
|
|
|
|
|
{
|
|
|
|
|
$aInsert = compile_insert_string(array( 'catName'=> $sName,
|
|
|
|
|
'catDescription' => $sDescription,
|
|
|
|
|
'catParent' => $iParentId ));
|
|
|
|
|
$sFields = "({$aInsert['FIELDS']})";
|
|
|
|
|
$sValues = "({$aInsert['VALUES']})";
|
|
|
|
|
|
|
|
|
|
if(query_appdb("INSERT INTO appCategory $sFields VALUES $sValues", "Error while creating a new vendor."))
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2005-02-09 02:20:21 +00:00
|
|
|
$this->iCatId = mysql_insert_id();
|
|
|
|
|
$this->category($this->iCatId);
|
|
|
|
|
return true;
|
2004-12-12 03:51:51 +00:00
|
|
|
}
|
2005-02-09 02:20:21 +00:00
|
|
|
else
|
|
|
|
|
return false;
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2005-02-09 02:20:21 +00:00
|
|
|
* Update category.
|
|
|
|
|
* Returns true on success and false on failure.
|
2004-03-15 16:22:00 +00:00
|
|
|
*/
|
2005-02-09 02:20:21 +00:00
|
|
|
function update($sName=null, $sDescription=null, $iParentId=null)
|
2004-03-15 16:22:00 +00:00
|
|
|
{
|
2005-02-09 02:20:21 +00:00
|
|
|
if(!$this->iCatId)
|
|
|
|
|
return $this->create($sName, $sDescription, $iParentId);
|
|
|
|
|
|
|
|
|
|
if($sName)
|
|
|
|
|
{
|
|
|
|
|
if (!query_appdb("UPDATE appCategory SET catName = '".$sName."' WHERE catId = ".$this->iCatId))
|
|
|
|
|
return false;
|
|
|
|
|
$this->sName = $sName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($sDescription)
|
|
|
|
|
{
|
|
|
|
|
if (!query_appdb("UPDATE appCategory SET catDescription = '".$sDescription."' WHERE catId = ".$this->iCatId))
|
|
|
|
|
return false;
|
|
|
|
|
$this->sDescription = $sDescription;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($iParentId)
|
|
|
|
|
{
|
|
|
|
|
if (!query_appdb("UPDATE appCategory SET catParent = '".$iParentId."' WHERE catId = ".$this->iCatId))
|
|
|
|
|
return false;
|
|
|
|
|
$this->iParentId = $iParentId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
/**
|
|
|
|
|
* Deletes the category from the database.
|
2004-03-15 16:22:00 +00:00
|
|
|
*/
|
2005-02-09 02:20:21 +00:00
|
|
|
function delete($bSilent=false)
|
2004-03-15 16:22:00 +00:00
|
|
|
{
|
2005-02-09 02:20:21 +00:00
|
|
|
if(sizeof($this->aApplicationsIds)>0)
|
|
|
|
|
{
|
|
|
|
|
addmsg("The category has not been deleted because there are still applications linked to it.", "red");
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
$sQuery = "DELETE FROM appCategory
|
|
|
|
|
WHERE catId = ".$this->iCatId."
|
|
|
|
|
LIMIT 1";
|
|
|
|
|
query_appdb($sQuery);
|
|
|
|
|
addmsg("The category has been deleted.", "green");
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2004-03-15 16:22:00 +00:00
|
|
|
* returns a path like:
|
|
|
|
|
*
|
|
|
|
|
* { ROOT, Games, Simulation }
|
|
|
|
|
*/
|
|
|
|
|
function getCategoryPath()
|
|
|
|
|
{
|
2004-12-12 03:51:51 +00:00
|
|
|
$path = array();
|
2005-02-09 02:20:21 +00:00
|
|
|
$iCatId = $this->iCatId;
|
|
|
|
|
while($iCatId != 0)
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2005-02-09 02:20:21 +00:00
|
|
|
$result = query_appdb("SELECT catName, catId, catParent FROM appCategory WHERE catId = $iCatId");
|
2004-12-12 03:51:51 +00:00
|
|
|
if(!$result || mysql_num_rows($result) != 1)
|
|
|
|
|
break;
|
|
|
|
|
$cat = mysql_fetch_object($result);
|
|
|
|
|
$path[] = array($cat->catId, $cat->catName);
|
2005-02-09 02:20:21 +00:00
|
|
|
$iCatId = $cat->catParent;
|
2004-12-12 03:51:51 +00:00
|
|
|
}
|
|
|
|
|
$path[] = array(0, "ROOT");
|
|
|
|
|
return array_reverse($path);
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
2005-05-11 02:26:11 +00:00
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
}
|
2005-02-09 02:20:21 +00:00
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
|
2005-02-09 02:20:21 +00:00
|
|
|
/*
|
|
|
|
|
* Application functions that are not part of the class
|
|
|
|
|
*/
|
2004-12-12 03:51:51 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* create the Category: line at the top of appdb pages$
|
|
|
|
|
*/
|
2004-12-25 20:11:13 +00:00
|
|
|
function make_cat_path($path, $appId = '', $versionId = '')
|
2004-03-15 16:22:00 +00:00
|
|
|
{
|
|
|
|
|
$str = "";
|
|
|
|
|
$catCount = 0;
|
2005-02-09 02:20:21 +00:00
|
|
|
while(list($iCatIdx, list($iCatId, $name)) = each($path))
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
|
|
|
|
if($name == "ROOT")
|
|
|
|
|
$catname = "Main";
|
|
|
|
|
else
|
|
|
|
|
$catname = $name;
|
|
|
|
|
|
|
|
|
|
if ($catCount > 0) $str .= " > ";
|
2005-02-09 02:20:21 +00:00
|
|
|
$str .= html_ahref($catname,"appbrowse.php?catId=$iCatId");
|
2004-12-12 03:51:51 +00:00
|
|
|
$catCount++;
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2004-12-25 20:11:13 +00:00
|
|
|
if(!empty($appId))
|
|
|
|
|
{
|
2005-02-07 23:21:33 +00:00
|
|
|
$oApp = new Application($appId);
|
2004-12-25 20:11:13 +00:00
|
|
|
if(!empty($versionId))
|
2005-02-02 00:35:49 +00:00
|
|
|
{
|
2005-02-07 23:21:33 +00:00
|
|
|
$oVersion = new Version($versionId);
|
|
|
|
|
$str .= " > ".html_ahref($oApp->sName,"appview.php?appId=$appId");
|
|
|
|
|
$str .= " > ".$oVersion->sName;
|
2005-02-02 00:35:49 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-02-07 23:21:33 +00:00
|
|
|
$str .= " > ".$oApp->sName;
|
2005-02-02 00:35:49 +00:00
|
|
|
}
|
2004-12-25 20:11:13 +00:00
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
return $str;
|
|
|
|
|
}
|
|
|
|
|
?>
|