ad_categorization_widget

one of the documented procedures in this installation of the ACS
Usage:
ad_categorization_widget {-db 0 -which_table "" -what_id 0 -name "category_id_list" -multiple_p 1 -size 0}
What it does:
Given a specific row in the database, return a select widget that contains the entire category hierarchy. Categories already mapped to the database row will be pre-selected.
Defined in: /web/philip/tcl/ad-categories.tcl

Source code:

arg_parser_for_ad_categorization_widget $args


    # Validate that all mandatory arguments have been supplied.
    #
    set missing_args [list]

    if { $db == 0 } {
	lappend missing_args "db"
    }

    if { [empty_string_p $which_table] } {
	lappend missing_args "which_table"
    }

    if { $what_id == 0 } {
	lappend missing_args "what_id"
    }

    set n_missing_args [llength $missing_args]

    if { $n_missing_args > 0 } {
	error "missing $n_missing_args arg(s): [join $missing_args ", "]"
    }

    # Format the <select> tag.
    #
    set widget "<select name=\"$name\""

    if { $multiple_p } {
	append widget " multiple"
    }

    if { $size > 0 } {
	append widget " size=$size"
    }

    append widget ">\n"

    # Fetch the list of categories to which this table row is already mapped.
    #
    set mapped_categories [database_to_tcl_list $db "select category_id
    from site_wide_category_map
    where on_which_table = '$which_table'
    and on_what_id = '$what_id'"]

    # Fetch the entire category hierarchy.
    #
    set selection [ns_db select $db "select c.category_id, lpad(' ', 12*(ch.tree_level - 1),'&nbsp;') as indent, c.category, c.category_type
from categories c,
(select child_category_id, rownum as tree_rownum, level as tree_level
 from category_hierarchy
 start with parent_category_id is null
 connect by prior child_category_id = parent_category_id) ch
 where c.category_id = ch.child_category_id
 order by ch.tree_rownum"]

    while { [ns_db getrow $db $selection] } {
	set_variables_after_query

	append widget "<option value=$category_id"

	# If the category is already mapped to this database row, then
	# pre-select it.
	#
	# lsearch is slow for long lists so we may want to store
	# mapped categories as array keys.
	#
	if { [lsearch $mapped_categories $category_id] != -1 } {
	    append widget " selected"
	}

	append widget ">${indent}${category}"

	if { ![empty_string_p $category_type] } {
	    append widget " ($category_type)"
	}

	append widget "\n"
    }

    append widget "</select>"

    return $widget


philg@mit.edu