Forum OpenACS Q&A: Re: Best way to cache a multirow?

Collapse
Posted by Tom Jackson on

I wrote a proc that does just that. Jeff suggested that we have some kind of switch on the list_to_multirow that would allow my code to be used when desired.

Here's the code (which was in the util-procs.tcl file):

ad_proc -public template::util::list_to_multiple { __multiple __nameList __rowList { __level 1 } }  {
    
    Converts list values to multiple tag format. Appends rows to 
    existing multiple.
    
    @param __multiple multiple tag name attribute
    @param __nameList list of array element names
    @param __rowList list of array element values
} {
    
    upvar $__level ${__multiple}:rowcount __rowcount
    
    if {[info exists __rowcount]} {
        set __i [expr $__rowcount + 1]
    } else {
        set __i 1
    }
    
    foreach $__nameList $__rowList {
        upvar $__level ${__multiple}:${__i} __localArray 
        set __localArray(rownum) $__i
        foreach __element $__nameList {
            set __localArray($__element) [set $__element]
        }
        incr __i
    }
    
    set __rowcount [expr $__i -1]
}