View Full Version : hierarchial system/category and forums sytem
AN-net
10-09-2004, 05:19 PM
hey well ive been trying to get something like vb's category and forum system to work but i cant:( can someone explain to me how to accomplish something like a category and then things under it. i have looked at vb's code for forming the forum list and i see its all done in one query, so i was wondering how does it determine what is a category, what is a forum, and how to place them.... can someone please help:)
peterska2
10-09-2004, 06:24 PM
In the forum editor it asks if posts can be made in the forum. It states that it will be treated as a category if no. Set it to no and save it. This will then display as a category.
Then when creating forums, set the parent forum to be the one that you have set to be your category.
AN-net
10-09-2004, 06:28 PM
im talking about how the actual functions in /includes/functions_forumlist.php detect/know if its a category and how to group them
Velocd
10-09-2004, 06:33 PM
Take a look at the vBulletin table schema for `forum`, and you will notice these columns:
childlist, parentid, parentlist, and forumid.
A hierarchical tree structure of categories composed of subcategories is possible using only the parentid & forumid, as I've done it for a project at my job (this requires a deviously complex recursive function--but only one query), but vBulletin takes an alternative route using supplemental data (parentlist and childlist), which contain the forumids of the parents and children of the current forum).
You can write SQL queries to grab threads and forums from the current forum and all its children easily using childlist. You can go upward, grabbing parent forum data, using the parentlist.
As for categories, that is forums that cannot be posted in (except for their children forums), they are denoted by a parentid of -1.
It's awkard explaining, but it's not very hard to do. The more difficult part that vBulletin places itself at is updating the parentlist and childlist everytime you change a forum into a parent or under another forum.
Dean C
10-09-2004, 06:39 PM
There are loads of algorithms and methods to generating a hiearachical category tree. The most popular is the method VelocD described above. If you're interested you may want to check out this article which outlines another (pretty useful) method too:
http://www.sitepoint.com/article/hierarchical-data-database
Velocd
10-09-2004, 07:00 PM
I posed this question on SitePoint back in August when looking for the basic algorithm:
http://www.sitepoint.com/forums/showthread.php?t=186114
The solution I ended using was heavy modifcation of stereofrog's (post#6 (http://www.sitepoint.com/forums/showpost.php?p=1339713&postcount=6)), which uses only one query and only relies on the parent ID.
AN-net
10-09-2004, 07:05 PM
well i was analyzing that article before and its very confusing. i was wondering which is easier/better to do that way or vb's.
also i was look at vb's code:
$iforumcache = array();
if ($getinvisibles) // get all forums including invisibles
{
foreach($forumcache AS $forumid => $forum)
{
$iforumcache["$forum[parentid]"]["$forum[displayorder]"]["$forumid"] = $forumid;
}
}
else // get all forums except invisibles
{
foreach($forumcache AS $forumid => $forum)
{
if ($forum['displayorder'] AND ($forum['options'] & $_FORUMOPTIONS['active']))
{
$iforumcache["$forum[parentid]"]["$forum[displayorder]"]["$forumid"] = $forumid;
}
else
{
unset($forumcache["$forumid"]);
}
}
}
// do some sorting (instead of sorting with MySQL and causing a filesort)
foreach($iforumcache AS $parentid => $devnull)
{
ksort($iforumcache["$parentid"]); // sort by display order
}
ksort($iforumcache); // sort by parentid (not actually sure if this is necessary)
i have never used ksort but ill assume its sorting it by parentid first then display?
also is childlist used at all in actually building the forum list/index?
Velocd
10-09-2004, 07:13 PM
ksorts sorts an array by its keys, so sorting $iforumcache[$parentid] sorts that array by displayorder.
I'm not certain what childlist is for. Maybe in building search indexes or something.
vBs way is fine, and probably easier to manipulate in PHP quickly. Less implementation would be using the way I explained in my previous post, since you don't have to rebuild a parentlist whenever a forum is relocated.
AN-net
10-11-2004, 12:25 PM
i was looking at that article and it says the recursion method is slow and query wasting, now the other method tree something seems better. i just wanted to know are there anyother besides recursion, tree, and vb's method to doing this?
and which did u you guys choose?
AN-net
10-14-2004, 04:51 PM
could such a system also be used in a family tree type situation?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.