Index: openacs-4/packages/categories/tcl/category-trees-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/categories/tcl/category-trees-procs.tcl,v diff -u -r1.10 -r1.11 --- openacs-4/packages/categories/tcl/category-trees-procs.tcl 19 Apr 2004 16:24:22 -0000 1.10 +++ openacs-4/packages/categories/tcl/category-trees-procs.tcl 4 May 2004 17:18:25 -0000 1.11 @@ -445,17 +445,36 @@ get a multirow datasource for a given tree or for all trees mapped to a given container. datasource is: - tree_id tree_name category_id category_name level pad deprecated_p count + tree_id tree_name category_id category_name level pad deprecated_p count child_sum - where mapped_p indicates the category_id was found in the list mapped_ids. + where: +
+ <multiple name="categories"> + <h2>@categories.tree_name@</h2> + <ul> + <group column="tree_id"> + <if @categories.count@ gt 0 or @categories.child_sum@ gt 0> + <li>@categories.pad;noquote@<a href="@categories.category_id@">@categories.category_name@</a> + <if @categories.count@ gt 0>(@categories.count@)</if></li> + </if> + </group> + </multiple> ++ @parameter tree_id tree_id or container_id must be provided. @parameter container_id returns all mapped trees for the given container_id @parameter category_counts list of category_id and counts {catid count cat count ... } @parameter datasource the name of the datasource to create. @author Jeff Davis davis@xarg.net - } { if { [empty_string_p $tree_id] } { @@ -473,12 +492,12 @@ array set counts [list] } - template::multirow create $datasource tree_id tree_name category_id category_name level pad deprecated_p count + template::multirow create $datasource tree_id tree_name category_id category_name level pad deprecated_p count child_sum foreach mapped_tree $mapped_trees { foreach {tree_id tree_name subtree_id assign_single_p require_category_p} $mapped_tree { break } foreach category [category_tree::get_tree -subtree_id $subtree_id $tree_id] { foreach {category_id category_name deprecated_p level} $category { break } - if { $level>1 } { + if { $level > 1 } { set pad "[string repeat " " [expr {2 * $level - 4}]].." } else { set pad {} @@ -488,9 +507,42 @@ } else { set count 0 } - template::multirow append $datasource $tree_id $tree_name $category_id $category_name $level $pad $deprecated_p $count + + template::multirow append $datasource $tree_id $tree_name $category_id $category_name $level $pad $deprecated_p $count 0 } } - return [template::multirow size $datasource] + # Here we make the possibly incorrect assumption that the + # trees are well formed and we walk the thing in reverse to find nodes + # with children categories that are mapped (so we can display a category + # and all its parent categories if mapped. + + # all this stuff here is to maintain a list which has the count of children seen at or above a + # given level + + set size [template::multirow size $datasource] + set rollup [list] + for {set i $size} {$i > 0} {incr i -1} { + set level [template::multirow get $datasource $i level] + set count [template::multirow get $datasource $i count] + set j 1 + set nrollup [list] + foreach r $rollup { + if {$j < $level} { + lappend nrollup [expr {$r + $count}] + } + if { $j == $level } { + if { $r > 0 } { + template::multirow set $datasource $i child_sum $r + } + break + } + + incr j + } + for {} {$j < $level} {incr j} { + lappend nrollup $count + } + set rollup $nrollup + } }