Index: openacs-4/packages/categories/tcl/category-trees-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/categories/tcl/category-trees-procs.tcl,v
diff -u -r1.31 -r1.31.2.1
--- openacs-4/packages/categories/tcl/category-trees-procs.tcl 18 Sep 2018 18:50:25 -0000 1.31
+++ openacs-4/packages/categories/tcl/category-trees-procs.tcl 15 Feb 2019 18:18:00 -0000 1.31.2.1
@@ -28,16 +28,32 @@
ad_proc -public get_categories {
{-tree_id:required}
+ -locale
} {
- returns the main categories of a given tree
+ Return root categories of a given tree
+
+ @param locale sort results by name in specified locale. If a
+ translation in this locale is not available, the one in en_US
+ will be used. When missing, will default to locale of the
+ connection or en_US when we are outside a connection context.
+
+ @return list of category ids
} {
- set locale [ad_conn locale]
- set result [list]
- set categories [db_list get_categories ""]
- foreach category_id $categories {
- lappend result $category_id
+ if {![info exists locale]} {
+ set locale [expr {[ns_conn isconnected] ? [ad_conn locale] : "en_US"}]
}
- return $result
+ return [db_list get_categories {
+ select c.category_id
+ from categories c
+ left join category_translations loct
+ on c.category_id = loct.category_id and loct.locale = :locale,
+ category_translations ent
+ where c.category_id = ent.category_id
+ and c.parent_id is null
+ and c.tree_id = :tree_id
+ and ent.locale = 'en_US'
+ order by coalesce(loct.name, ent.name)
+ }]
}
ad_proc -public map {
Index: openacs-4/packages/categories/tcl/category-trees-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/categories/tcl/Attic/category-trees-procs.xql,v
diff -u -r1.11 -r1.11.2.1
--- openacs-4/packages/categories/tcl/category-trees-procs.xql 7 Aug 2017 23:48:05 -0000 1.11
+++ openacs-4/packages/categories/tcl/category-trees-procs.xql 15 Feb 2019 18:18:00 -0000 1.11.2.1
@@ -11,17 +11,6 @@
-
-
- select c.category_id as category_id from categories c, category_translations ct
- where parent_id is null
- and tree_id = :tree_id
- and c.category_id = ct.category_id
- and locale = :locale
- order by name
-
-
-