category_tree::import (public)

 category_tree::import -name name [ -description description ] \
    -categories categories [ -locale locale ] [ -user_id user_id ] \
    [ -creation_ip creation_ip ] [ -context_id context_id ]

Defined in packages/categories/tcl/category-trees-procs.tcl

Insert a new category tree with categories. Here is an example of how to use this in tcl:

    set tree_id [category_tree::import -name regions -description {regions and states} -categories {
    1 europe
    2 germany
    2 {united kingdom}
    2 france
    1 asia
    2 china
    1 {north america}
    2 {united states}
    }]
    

Switches:
-name (required)
-description (optional)
-categories (required)
-locale (optional)
-user_id (optional)
-creation_ip (optional)
-context_id (optional)
Options:
-name
tree name.
-description
tree description.
-categories
Tcl list of levels and category_names.
-locale
locale of the language. [ad_conn locale] used by default.
-user_id
user that adds the category tree. [ad_conn user_id] used by default.
-creation_ip
ip-address of the user that adds the category tree. [ad_conn peeraddr] used by default.
-context_id
context_id of the category tree. [ad_conn package_id] used by default.
Returns:
tree_id
Authors:
Jeff Davis
Timo Hentschel <timo@timohentschel.de>

Partial Call Graph (max 5 caller/called nodes):
%3 test_category_tree_import category_tree_import (test categories) category_tree::import category_tree::import test_category_tree_import->category_tree::import ad_conn ad_conn (public) category_tree::import->ad_conn category::add category::add (public) category_tree::import->category::add category_tree::add category_tree::add (public) category_tree::import->category_tree::add category_tree::flush_cache category_tree::flush_cache (public) category_tree::import->category_tree::flush_cache db_transaction db_transaction (public) category_tree::import->db_transaction

Testcases:
category_tree_import
Source code:
    if {$locale eq ""} {
        set locale [ad_conn locale]
    }
    if {$user_id eq ""} {
        set user_id [ad_conn user_id]
    }
    if {$creation_ip eq ""} {
        set creation_ip [ad_conn peeraddr]
    }
    if {$context_id eq ""} {
        set creation_ip [ad_conn package_id]
    }

    db_transaction {
        set tree_id [category_tree::add -name $name -description $description -locale $locale -user_id $user_id -creation_ip $creation_ip -context_id $context_id]

        set parent(0) {}
        set parent(1) {}
        set parent(2) {}
        foreach {level category_name} $categories {
            set parent([expr {$level + 1}]) [category::add -noflush -name $category_name -description $category_name -tree_id $tree_id -parent_id $parent($level) -locale $locale -user_id $user_id -creation_ip $creation_ip]
        }

        category_tree::flush_cache $tree_id
    }

    return $tree_id
XQL Not present:
Generic
PostgreSQL XQL file:
packages/categories/tcl/category-trees-procs-postgresql.xql

Oracle XQL file:
packages/categories/tcl/category-trees-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: