template::data::transform::category (public)

 template::data::transform::category element_ref

Defined in packages/categories/tcl/widget-procs.tcl

Transform the value from the form request into the widget internal representation.

Parameters:
element_ref (required)
Author:
Timo Hentschel <timo@timohentschel.de>

Partial Call Graph (max 5 caller/called nodes):
%3 ad_conn ad_conn (public) category_tree::get_mapped_trees category_tree::get_mapped_trees (public) category_tree::get_name category_tree::get_name (public) category_tree::get_tree category_tree::get_tree (public) template::element::set_error template::element::set_error (public) template::data::transform::category template::data::transform::category template::data::transform::category->ad_conn template::data::transform::category->category_tree::get_mapped_trees template::data::transform::category->category_tree::get_name template::data::transform::category->category_tree::get_tree template::data::transform::category->template::element::set_error

Testcases:
No testcase defined.
Source code:
    upvar $element_ref element
    set values [ns_querygetall $element(id)]

    # QUIRK: ns_querygetall returns a single-element list {{}} for no values
    if { [string equal $values {{}}] } {
        set values [list]
    }

    # to mark submission of form for rendering element in case of invalid data
    # (to preselect with last selected values)
    set element(submit) 1

    # Get parameters for the category widget
    set package_id {}
    set tree_id {}
    set subtree_id {}
    set require_category_p f

    if { [info exists element(value)] && $element(value) ne ""
         && [llength $element(value)] == 2
    } {
        # Legacy method for passing parameters
        set package_id [lindex $element(value) 1]
    } else {
        if { [info exists element(category_application_id)] && $element(category_application_id) ne "" } {
            set package_id $element(category_application_id)
        }
        if { [info exists element(category_tree_id)] && $element(category_tree_id) ne "" } {
            set tree_id $element(category_tree_id)
        }
        if { [info exists element(category_subtree_id)] && $element(category_subtree_id) ne "" } {
            set subtree_id $element(category_subtree_id)
        }
        if { [info exists element(category_require_category_p)] && $element(category_require_category_p) ne "" } {
            set require_category_p $element(category_require_category_p)
        }
    }
    if { $package_id eq "" } {
        set package_id [ad_conn package_id]
    }

    if { $tree_id eq "" } {
        set trees [list]
        foreach tree [category_tree::get_mapped_trees $package_id] {
            lassign $tree tree_id tree_name subtree_id assign_single_p require_category_p
            if {$require_category_p == "t" || ![info exists element(optional)]} {
                lappend trees [list $tree_id $subtree_id]
            }
        }
    } else {
        if {$require_category_p == "t"} {
            set trees [list [list $tree_id $subtree_id]]
        } else {
            set trees [list]
        }
    }

    set trees_without_category [list]
    foreach tree $trees {
        lassign $tree tree_id subtree_id
        # get categories of every tree requiring a categorization
        foreach category [category_tree::get_tree -all -subtree_id $subtree_id $tree_id] {
            set tree_categories([lindex $category 0]) 1
        }
        set found_p 0
        # check if at least one selected category is among tree categories
        foreach value $values {
            if {[info exists tree_categories($value)]} {
                set found_p 1
            }
        }
        if {!$found_p} {
            # no categories of this tree selected, so add for error message
            lappend trees_without_category [category_tree::get_name $tree_id]
        }
        array unset tree_categories
    }
    if {[llength $trees_without_category] > 0} {
        # some trees require category, but none selected
        template::element::set_error $element(form_id) $element(id) "Please select a category for [join $trees_without_category ""]."
        return [list]
    }

    return $values
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: