ad_categorize_row

one of the documented procedures in this installation of the ACS
Usage:
ad_categorize_row {-db 0 -which_table "" -what_id 0 -category_id_list "" -mapping_weight "null" -one_line_item_desc "" -mapping_comment ""}
What it does:
Maps a specific row in the database to the specified categories.
Defined in: /web/philip/tcl/ad-categories.tcl

Source code:

arg_parser_for_ad_categorize_row $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"
    }

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

    set n_missing_args [llength $missing_args]

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

    with_transaction $db {

	if { [llength $category_id_list] == 0 } {
	    ns_db dml $db "delete from site_wide_category_map
where on_which_table = '$which_table'
and on_what_id = '$what_id'"

	} else {
	    # Purge any existing mappings that have been removed.
	    #
	    ns_db dml $db "delete from site_wide_category_map
where on_which_table = '$which_table'
and on_what_id = '$what_id'
and category_id not in ([join $category_id_list ", "])"

	    # Update mapping_weight, one_line_item_desc, and mapping_comment
	    # for any remaining mappings.
	    #
	    ns_db dml $db "update site_wide_category_map
set one_line_item_desc = '[DoubleApos $one_line_item_desc]',
mapping_weight = $mapping_weight,
mapping_comment = '[DoubleApos $mapping_comment]'
where on_which_table = '$which_table'
and on_what_id = '$what_id'"

	    # Insert all mappings that do not already exist.
	    #
	    ns_db dml $db "insert into site_wide_category_map
(map_id, category_id, on_which_table, on_what_id, mapping_date, mapping_weight, one_line_item_desc, mapping_comment)
select site_wide_cat_map_id_seq.nextval, category_id, '$which_table', '$what_id', sysdate, $mapping_weight, '[DoubleApos $one_line_item_desc]', '[DoubleApos $mapping_comment]'
from categories
where category_id in ('[join $category_id_list "', '"]')
and not exists (
 select category_id
 from site_wide_category_map
 where on_which_table = '$which_table'
 and on_what_id = '$what_id'
 and categories.category_id = site_wide_category_map.category_id)"
	}
    } {
	error $errmsg
    }


philg@mit.edu