template::list::prepare_for_rendering (private)

 template::list::prepare_for_rendering -name name

Defined in packages/acs-templating/tcl/list-procs.tcl

Build all the variable references that are required when rendering a list template.

Switches:
-name (required)
The name of the list template we hope to be able to render eventually.

Partial Call Graph (max 5 caller/called nodes):
%3 template::list::render template::list::render (public) template::list::prepare_for_rendering template::list::prepare_for_rendering template::list::render->template::list::prepare_for_rendering template::list::write_csv template::list::write_csv (public) template::list::write_csv->template::list::prepare_for_rendering lc_numeric lc_numeric (public) template::list::prepare_for_rendering->lc_numeric template::adp_level template::adp_level (public) template::list::prepare_for_rendering->template::adp_level template::list::get_reference template::list::get_reference (public) template::list::prepare_for_rendering->template::list::get_reference template::list::multirow_cols template::list::multirow_cols (public) template::list::prepare_for_rendering->template::list::multirow_cols template::multirow template::multirow (public) template::list::prepare_for_rendering->template::multirow

Testcases:
No testcase defined.
Source code:
    set __level [template::adp_level]

    # Provide a reference to the list properties for use by the list template
    # This one is named __list_properties to avoid getting scrambled by below multirow
    get_reference -name $name -local_name __list_properties

    # Sort in webserver layer, if requested to do so
    set __multirow_cols [template::list::multirow_cols -name $__list_properties(name)]
    if { $__multirow_cols ne "" } {
        template::multirow sort {*}$__list_properties(multirow) {*}$__multirow_cols
    }

    # Upvar other variables passed in through the pass_properties property
    foreach var $__list_properties(pass_properties) {
        upvar #$__level $var $var
    }

    #
    # Dynamic columns: display_eval, link_url_eval, aggregate
    #

    # TODO: If we want to be able to sort by display_eval'd element values,
    # we'll have to do those in a separate run from doing the aggregates.

    if { $__list_properties(dynamic_cols_p) || $__list_properties(aggregates_p) } {
        foreach __element_ref $__list_properties(element_refs) {
            # We don't need to prefix it with __ to become __element_properties here
            # because we're not doing the multirow foreach loop yet.
            upvar #$__level $__element_ref element_properties

            # display_eval, link_url_eval
            foreach __eval_property { display link_url } {
                if { [info exists element_properties(${__eval_property}_eval)] && $element_properties(${__eval_property}_eval) ne "" } {

                    # Set the display col to the name of the new, dynamic column
                    set element_properties(${__eval_property}_col) "$element_properties(name)___$__eval_property"

                    # And add that column to the multirow
                    template::multirow extend $__list_properties(multirow) $element_properties(${__eval_property}_col)
                }
            }

            # aggregate
            if { [info exists element_properties(aggregate)] && $element_properties(aggregate) ne "" } {
                # Set the aggregate_col to the name of the new, dynamic column
                set element_properties(aggregate_col) "$element_properties(name)___$element_properties(aggregate)"
                set element_properties(aggregate_group_col) "$element_properties(name)___$element_properties(aggregate)_group"

                # Add that column to the multirow
                template::multirow extend $__list_properties(multirow) $element_properties(aggregate_col)
                template::multirow extend $__list_properties(multirow) $element_properties(aggregate_group_col)

                # Initialize our counters to 0
                set __agg_counter($element_properties(name)) 0
                set __agg_sum($element_properties(name)) 0

                # Just in case, we also initialize our group counters to 0
                set __agg_group_counter($element_properties(name)) 0
                set __agg_group_sum($element_properties(name)) 0
            }
        }
        set __have_groupby [expr { [info exists $__list_properties(groupby)]
                                   && [set $__list_properties(groupby)] ne "" }]


        # This keeps track of the value of the group-by column for sub-totals
        set __last_group_val {}

        template::multirow foreach $__list_properties(multirow) {

            foreach __element_ref $__list_properties(element_refs) {
                # We do need to prefix it with __ to become __element_properties here
                # because we are inside the multirow foreach loop yet.
                # LARS: That means we should probably also __-prefix element_ref, eval_property, and others.
                upvar #$__level $__element_ref __element_properties

                # display_eval, link_url_eval
                foreach __eval_property { display link_url } {
                    if { [info exists __element_properties(${__eval_property}_eval)] && $__element_properties(${__eval_property}_eval) ne "" } {
                        set $__element_properties(${__eval_property}_col) [subst $__element_properties(${__eval_property}_eval)]
                    }
                }

                # aggregate
                if { [info exists __element_properties(aggregate)] && $__element_properties(aggregate) ne "" } {
                    # Update totals
                    incr __agg_counter($__element_properties(name))
                    if {$__element_properties(aggregate) eq "sum" } {
                        set __agg_sum($__element_properties(name))  [expr {$__agg_sum($__element_properties(name)) +
                                   ([set $__element_properties(name)] ne "" ? [set $__element_properties(name)] : 0)} ]
                        if {$__list_properties(aggregation_format) ne ""} {
                            set __agg_sum($__element_properties(name)) [format $__list_properties(aggregation_format) $__agg_sum($__element_properties(name))]
                        }
                    }

                    # Check if the value of the groupby column has changed
                    if { $__have_groupby } {
                        if { $__last_group_val ne [set $__list_properties(groupby)] } {
                            # Initialize our group counters to 0
                            set __agg_group_counter($__element_properties(name)) 0
                            set __agg_group_sum($__element_properties(name)) 0
                        }
                        # Update subtotals
                        incr __agg_group_counter($__element_properties(name))
                        set __agg_group_sum($__element_properties(name))  [expr {$__agg_group_sum($__element_properties(name)) +
                                   ([string is double [set $__element_properties(name)]] ? [set $__element_properties(name)] : 0)}]
                        if {$__list_properties(aggregation_format) ne ""} {
                            set __agg_group_sum($__element_properties(name)) [format $__list_properties(aggregation_format) $__agg_group_sum($__element_properties(name))]
                        }
                    }

                    switch -- $__element_properties(aggregate) {
                        sum {
                            set $__element_properties(aggregate_col) $__agg_sum($__element_properties(name))
                            if { $__have_groupby } {
                                set $__element_properties(aggregate_group_col) $__agg_group_sum($__element_properties(name))
                            }
                        }
                        average {
                            set $__element_properties(aggregate_col)  [expr {$__agg_sum($__element_properties(name)) / $__agg_counter($__element_properties(name))}]
                            if { $__have_groupby } {
                                set $__element_properties(aggregate_group_col)  [expr {$__agg_sum($__element_properties(name)) / $__agg_group_counter($__element_properties(name))}]
                            }
                        }
                        count {
                            set $__element_properties(aggregate_col) [expr {$__agg_counter($__element_properties(name))}]
                            if { $__have_groupby } {
                                set $__element_properties(aggregate_group_col)  [expr {$__agg_group_counter($__element_properties(name))}]
                            }
                        }
                        default {
                            error "Unknown aggregate function '$__element_properties(aggregate)'"
                        }
                    }

                    set $__element_properties(aggregate_group_col) [lc_numeric [set $__element_properties(aggregate_group_col)]]
                    set $__element_properties(aggregate_col) [lc_numeric [set $__element_properties(aggregate_col)]]
                }
            }

            # Remember this value of the groupby column
            if { $__have_groupby } {
                set __last_group_val [set $__list_properties(groupby)]
            }
        }
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: