#81 Directory : Count of subcategories links

open
nobody
None
5
2004-01-10
2003-09-15
No

I have never submitted a patch for anything, so I hope not to
embarrass myself too much...

When a category is viewed in the tracker, there is a number next
to any subcategory which shows how many sites there are in that
subcategory. For complex category structures this number is
misleading (as subcategories can have more subcategories with
more sites). I wrote a function to get ALL of the subcategories'
sites:

for class: DirLib
in file: lib/directory/dirlib.php
input: category id
output: number of ALL sites within that category (recursive)

function get_cats_subcat_sites($catid)
{
//get all direct child id's of this category
$query_childids = "select categId from
tiki_directory_categories where par
ent=" . $catid;
$result_childids = $this->query($query_childids);
$childret = Array();
$subsites = 0;
while($childret =
$result_childids->fetchRow(DB_FETCHMODE_ASSOC)){
$subsites += $this->db->getOne("select count(*) from
tiki_category_sites
where categId=".$childret["categId"]);
//recursive call to all subcats
$subsites +=
$this->get_cats_subcat_sites($childret["categId"]);
}
return $subsites;
}

to tack the result onto the number that is displayed, just add on
this line to the while loop in the function "dir_list_categories" in the
same class and file:
$res["sites"]+=$this->get_cats_subcat_sites($res["categId"]);

I hope this helps somehow!

Serge

Discussion

  • Philippe Cloutier

    Logged In: YES
    user_id=738765

    Good, I don't want to check that code but it will be good to
    adjust the template too to show something like
    "currentnumber (patchednumber total)

     
  • Philippe Cloutier

    • summary: show all subsites for tracker --> Directory : Count of subcategories links
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks