2 /***************************************************/
3 /* this class represents a category + its children */
4 /***************************************************/
7 * Category class for handling categories.
14 var $aApplicationsIds; // an array that contains the appId of every application linked to this category
15 var $aSubcatsIds; // an array that contains the appId of every application linked to this category
19 * constructor, fetches the data.
21 function Category($iCatId = null)
23 // we are working on an existing category
24 if($iCatId=="0" ||
$iCatId)
27 * We fetch the data related to this vendor.
31 WHERE catId = '?' ORDER BY catName;";
32 if($hResult = query_parameters($sQuery, $iCatId))
34 $oRow = query_fetch_object($hResult);
37 $this->iCatId
= $iCatId;
38 $this->iParentId
= $oRow->catParent
;
39 $this->sName
= $oRow->catName
;
40 $this->sDescription
= $oRow->catDescription
;
45 * We fetch applicationsIds.
47 $sQuery = "SELECT appId
50 AND state = 'accepted' ORDER BY appName";
51 if($hResult = query_parameters($sQuery, $iCatId))
53 while($oRow = query_fetch_object($hResult))
55 $this->aApplicationsIds
[] = $oRow->appId
;
62 $sQuery = "SELECT catId
64 WHERE catParent = '?' ORDER BY catName;";
65 if($hResult = query_parameters($sQuery, $iCatId))
67 while($oRow = query_fetch_object($hResult))
69 $this->aSubcatsIds
[] = $oRow->catId
;
77 * Creates a new category.
81 $hResult = query_parameters("INSERT INTO appCategory (catName, catDescription, catParent) ".
82 "VALUES('?', '?', '?')",
83 $this->sName
, $this->sDescription
, $this->iParentId
);
86 $this->iCatId
= query_appdb_insert_id();
87 $this->category($this->iCatId
);
96 * Returns true on success and false on failure.
100 if(!query_parameters("UPDATE appCategory SET catName = '?', catDescription = '?', catParent = '?' WHERE catId = '?'",
101 $this->sName
, $this->sDescription
, $this->iParentId
, $this->iCatId
))
109 * Deletes the category from the database.
113 if(!$this->canEdit())
116 if(sizeof($this->aApplicationsIds
)>0)
119 $sQuery = "DELETE FROM appCategory
122 query_parameters($sQuery, $this->iCatId
);
127 function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction)
129 return new mailOptions();
132 function objectGetChildren()
134 /* We don't have any (or we do, sort of, but we don't use them for anything at the moment) */
138 /* Get a category's subcategory objects. Names are indented according
139 to subcategory level */
140 function getSubCatList($iLevel)
143 $iId = $this->iCatId ?
$this->iCatId
: 0;
146 for($i = 0; $i < $iLevel; $i++
)
147 $sIndent .= ' ';
149 $hResult = query_parameters("SELECT * FROM appCategory WHERE catParent = '?'
150 ORDER BY catName", $iId);
152 while($oRow = mysql_fetch_object($hResult))
154 $oCat = new category($oRow->catId
);
155 $oCat->sName
= $sIndent.$oCat->sName
;
157 $aOut = array_merge($aOut, $oCat->getSubCatList($iLevel +
1));
162 /* Get all category objects, ordered and with category names indented
163 according to subcategory level */
164 static function getOrderedList()
166 $oCat = new category();
167 return $oCat->getSubCatList(0);
170 function objectGetMail($sAction, $bMailSubmitter, $bParentAction)
172 /* We don't send notification mails */
173 return array(null, null, null);
177 * returns a path like:
179 * { ROOT, Games, Simulation }
181 function getCategoryPath()
184 $iCatId = $this->iCatId
;
186 /* loop, working up through categories until we have no parent */
189 $hResult = query_parameters("SELECT catName, catId, catParent FROM appCategory WHERE catId = '?'",
191 if(!$hResult ||
query_num_rows($hResult) != 1)
193 $oCatRow = query_fetch_object($hResult);
194 $aPath[] = array($oCatRow->catId
, $oCatRow->catName
);
195 $iCatId = $oCatRow->catParent
;
197 $aPath[] = array(0, "ROOT");
198 return array_reverse($aPath);
201 /* return the total number of applications in this category */
202 function getApplicationCount($depth = null)
211 /* if we've reached our max depth, just return 0 and stop recursing */
212 if($depth >= $MAX_DEPTH)
217 /* add on all apps in each category this category includes */
218 if($this->aSubcatsIds
)
220 while(list($i, $iSubcatId) = each($this->aSubcatsIds
))
222 $subCat = new Category($iSubcatId);
223 $totalApps +
= $subCat->getApplicationCount($depth);
227 $totalApps +
= sizeof($this->aApplicationsIds
); /* add on the apps at this category level */
233 * create the Category: line at the top of appdb pages$
235 function make_cat_path($path, $appId = '', $versionId = '')
239 while(list($iCatIdx, list($iCatId, $name)) = each($path))
246 if ($catCount > 0) $str .= " > ";
247 $str .= html_ahref($catname,"appbrowse.php?catId=$iCatId");
253 $oApp = new Application($appId);
254 if(!empty($versionId))
256 $oVersion = new Version($versionId);
257 $str .= " > ".$oApp->objectMakeLink();
258 $str .= " > ".$oVersion->sName
;
261 $str .= " > ".$oApp->sName
;
268 function objectGetId()
270 return $this->iCatId
;
273 function objectGetSubmitterId()
275 /* We don't log that */
279 function outputEditor()
281 $sQuery = "SELECT catId, catName FROM appCategory WHERE catId!='?'";
282 $hResult = query_parameters($sQuery, $this->iCatId
);
284 /* Add the virtual 'Main' category */
286 $aCatNames = array('Main');
288 /* Add the rest from the database */
289 while($oRow = query_fetch_object($hResult))
291 $aCatIds[] = $oRow->catId
;
292 $aCatNames[] = $oRow->catName
;
295 echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">
297 <td width=\"15%\" class=\"box-label\"><b>Category name</b></td>
298 <td class=\"box-body\">
299 <input type=\"text\" size=\"50\" name=\"sName\" value=\"".$this->sName
."\">
303 <td width=\"15%\" class=\"box-label\"><b>Description</b></td>
304 <td class=\"box-body\">
305 <input type=\"text\" size=\"50\" name=\"sDescription\" value=\"".$this->sDescription
."\">
309 <td width=\"15%\" class=\"box-label\"><b>Parent</b></td>
310 <td class=\"box-body\">
311 ".html_select("iParentId",$aCatIds,$this->iParentId
, $aCatNames)."
317 function allowAnonymousSubmissions()
322 function getOutputEditorValues($aClean)
324 $this->sName
= $aClean['sName'];
325 $this->iParentId
= $aClean['iParentId'];
326 $this->sDescription
= $aClean['sDescription'];
329 function mustBeQueued()
331 return $_SESSION['current']->hasPriv('admin');
336 return $_SESSION['current']->hasPriv('admin');
340 * display the full path of the Category we are looking at
342 function display($appId, $versionId = '')
344 $sCatFullPath = Category
::make_cat_path($this->getCategoryPath(), $appId, $versionId);
345 echo html_frame_start("",'98%','',2);
346 echo "<p><b>Category: ". $sCatFullPath ."</b><br>\n";
347 echo html_frame_end();