category::add (public)

 category::add [ -category_id category_id ] -tree_id tree_id \
    -parent_id parent_id -name name [ -locale locale ] \
    [ -description description ] [ -deprecated_p deprecated_p ] \
    [ -user_id user_id ] [ -creation_ip creation_ip ] [ -noflush ]

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

Insert a new category. The same translation will be added in the default language if it's in a different language.

Switches:
-category_id (optional)
-tree_id (required)
-parent_id (required)
-name (required)
-locale (optional)
-description (optional)
-deprecated_p (optional, defaults to "f")
-user_id (optional)
-creation_ip (optional)
-noflush (optional, boolean)
Options:
-category_id
category_id of the category to be inserted.
-locale
locale of the language. [ad_conn locale] used by default.
-name
category name.
-description
description of the category.
-deprecated_p
is category deprecated?
-tree_id
tree_id of the category the category should be added.
-parent_id
id of the parent category. "" if top level category.
-user_id
user that adds the category. [ad_conn user_id] used by default.
-creation_ip
ip-address of the user that adds the category. [ad_conn peeraddr] used by default.
-noflush
defer calling category_tree::flush_cache (which if adding multiple categories to a large tree can be very expensive). note that if you set this flag you must call category_tree::flush_cache once the adds are complete.
Returns:
category_id
Author:
Timo Hentschel <timo@timohentschel.de>

Partial Call Graph (max 5 caller/called nodes):
%3 test_category_crud category_crud (test categories) category::add category::add test_category_crud->category::add test_category_get_procs category_get_procs (test categories) test_category_get_procs->category::add test_category_link category_link (test categories) test_category_link->category::add test_category_synonyms category_synonyms (test categories) test_category_synonyms->category::add test_category_tree_procs category_tree_procs (test categories) test_category_tree_procs->category::add ad_conn ad_conn (public) category::add->ad_conn category_tree::flush_cache category_tree::flush_cache (public) category::add->category_tree::flush_cache db_exec_plsql db_exec_plsql (public) category::add->db_exec_plsql db_transaction db_transaction (public) category::add->db_transaction parameter::get parameter::get (public) category::add->parameter::get category_tree::import category_tree::import (public) category_tree::import->category::add category_tree::xml::add_category category_tree::xml::add_category (private) category_tree::xml::add_category->category::add packages/categories/www/cadmin/category-form.tcl packages/categories/ www/cadmin/category-form.tcl packages/categories/www/cadmin/category-form.tcl->category::add

Testcases:
category_synonyms, category_link, category_crud, category_get_procs, category_tree_procs
Source code:
    if {$user_id eq ""} {
        set user_id [ad_conn user_id]
    }
    if {$creation_ip eq ""} {
        set creation_ip [ad_conn peeraddr]
    }
    if {$locale eq ""} {
        set locale [ad_conn locale]
    }
    db_transaction {
        set category_id [db_exec_plsql insert_category ""]
        set translations [list $locale $name]
        set default_locale [parameter::get -parameter DefaultLocale -default en_US]
        if {$locale != $default_locale} {
            lappend translations $default_locale $name
            db_exec_plsql insert_default_category ""
        }
        if {!$noflush_p} {
            category_tree::flush_cache $tree_id
        }
        # JCD: avoid doing a query and set the translation cache directly
        # flush_translation_cache $category_id
        nsv_set categories $category_id [list $tree_id $translations]
    }
    return $category_id
XQL Not present:
Generic
PostgreSQL XQL file:
<fullquery name="category::add.insert_category">
    <querytext>
		select category__new (
				    :category_id,
				    :tree_id,
				    :locale,
				    :name,
				    :description,
				    :parent_id,
                                    :deprecated_p,
                                    current_timestamp,
				    :user_id,
				    :creation_ip
				    )
      </querytext>
</fullquery>

<fullquery name="category::add.insert_default_category">
    <querytext>
		    select category__new_translation (
					      :category_id,
					      :default_locale,
					      :name,
					      :description,
                                              current_timestamp,
					      :user_id,
					      :creation_ip
					      )
      </querytext>
</fullquery>
packages/categories/tcl/categories-procs-postgresql.xql

Oracle XQL file:
<fullquery name="category::add.insert_category">
    <querytext>
      
		begin
		:1 := category.new (
				    category_id   => :category_id,
				    locale        => :locale,
				    name          => :name,
				    description   => :description,
				    tree_id       => :tree_id,
				    parent_id     => :parent_id,
				    creation_user => :user_id,
				    creation_ip   => :creation_ip
				    );
		end;
	    
      </querytext>
</fullquery>

<fullquery name="category::add.insert_default_category">
    <querytext>
      
		    begin
		    category.new_translation (
					      category_id    => :category_id,
					      locale         => :default_locale,
					      name           => :name,
					      description    => :description,
					      modifying_user => :user_id,
					      modifying_ip   => :creation_ip
					      );
		    end;
		
      </querytext>
</fullquery>
packages/categories/tcl/categories-procs-oracle.xql

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