Index: openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl,v diff -u -r1.38.2.3 -r1.38.2.4 --- openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl 13 Aug 2019 17:02:33 -0000 1.38.2.3 +++ openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl 27 Aug 2019 09:37:04 -0000 1.38.2.4 @@ -383,6 +383,36 @@ ] content_item get_id] } +ad_proc -public content::item::get_descendants { + -parent_id:required + {-depth ""} +} { + Returns the ids of every content item that is descendant of + supplied parent_id. + + @param parent_id + @param depth how deep we should go in the hierarchy. 1 means + direct children. Returns every descendant when not + specified. + + @return list of cr_items.item_id +} { + return [db_list get_descendants { + with recursive descendants (item_id) as ( + select item_id, 1 as depth + from cr_items + where parent_id = :parent_id + + union all + + select i.item_id, d.depth + 1 + from cr_items i, descendants d + where i.parent_id = d.item_id + and (:depth is null or d.depth < :depth) + ) select * from descendants + }] +} + ad_proc -public content::item::get_best_revision { -item_id:required } {