category_tree::get_multirow (public)
category_tree::get_multirow [ -tree_id tree_id ] \ [ -subtree_id subtree_id ] [ -assign_single_p assign_single_p ] \ [ -require_category_p require_category_p ] \ [ -container_id container_id ] \ [ -category_counts category_counts ] [ -append ] \ [ -datasource datasource ]
Defined in packages/categories/tcl/category-trees-procs.tcl
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 child_sum where:
Here is an example of how to use this in adp:
- mapped_p indicates the category_id was found in the list mapped_ids.
- child_sum is the naive sum of items mapped to children (may double count)
- count is the number of items mapped directly to the given category
- pad is a stupid hard coded pad for the tree (I think trees should use nested lists and css)
<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>
- Switches:
- -tree_id (optional)
- tree_id or container_id must be provided.
- -subtree_id (optional)
- -assign_single_p (optional, defaults to
"f"
)- -require_category_p (optional, defaults to
"f"
)- -container_id (optional)
- returns all mapped trees for the given container_id
- -category_counts (optional)
- list of category_id and counts {catid count cat count ... }
- -append (optional, boolean)
- -datasource (optional)
- the name of the datasource to create.
- Author:
- Jeff Davis davis@xarg.net
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- category_crud
Source code: if { $tree_id eq "" } { if { $container_id eq "" } { error "must provide either tree_id or container_id" } set mapped_trees [category_tree::get_mapped_trees $container_id] } else { set mapped_trees [list [list $tree_id [category_tree::get_name $tree_id] $subtree_id $assign_single_p $require_category_p]] } if { $mapped_trees ne "" && [llength $category_counts] > 1} { array set counts $category_counts } else { array set counts [list] } # If we should append, then don't create the datasource if it already exists if {$append_p && [template::multirow exists $datasource]} { # do nothing } else { template::multirow create $datasource tree_id tree_name category_id category_name level pad deprecated_p count child_sum } foreach mapped_tree $mapped_trees { lassign $mapped_tree tree_id tree_name subtree_id assign_single_p require_category_p foreach category [category_tree::get_tree -subtree_id $subtree_id $tree_id] { lassign $category category_id category_name deprecated_p level if { $level > 1 } { set pad "[string repeat " " [expr {2 * $level - 4}]].." } else { set pad {} } if {[info exists counts($category_id)]} { set count $counts($category_id) } else { set count 0 } template::multirow append $datasource $tree_id $tree_name $category_id $category_name $level $pad $deprecated_p $count 0 } } # 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 }XQL Not present: Generic PostgreSQL XQL file: packages/categories/tcl/category-trees-procs-postgresql.xql
Oracle XQL file: packages/categories/tcl/category-trees-procs-oracle.xql