Index: openacs-4/contrib/packages/bcms/tcl/bcms-folder-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/bcms/tcl/bcms-folder-procs-postgresql.xql,v diff -u -r1.4 -r1.5 --- openacs-4/contrib/packages/bcms/tcl/bcms-folder-procs-postgresql.xql 13 Oct 2003 17:07:26 -0000 1.4 +++ openacs-4/contrib/packages/bcms/tcl/bcms-folder-procs-postgresql.xql 14 Oct 2003 13:58:56 -0000 1.5 @@ -54,4 +54,15 @@ + + + + select content_folder__register_content_type ( + :folder_id, + :content_type, + :subtypes_p + ) + + + Index: openacs-4/contrib/packages/bcms/tcl/bcms-folder-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/bcms/tcl/bcms-folder-procs.tcl,v diff -u -r1.8 -r1.9 --- openacs-4/contrib/packages/bcms/tcl/bcms-folder-procs.tcl 13 Oct 2003 17:07:27 -0000 1.8 +++ openacs-4/contrib/packages/bcms/tcl/bcms-folder-procs.tcl 14 Oct 2003 13:58:56 -0000 1.9 @@ -42,6 +42,8 @@ {-package_id ""} {-context_id ""} {-folder_id ""} + {-subtypes:boolean} + {-content_types ""} } { creates a new folder in cr_folders @@ -50,6 +52,9 @@ the folder @param parent_id the folder_id of which this folder will become a subfolder @param description a description for this folder + + @param content_types If specified, will register the given content types to the folder. + @param subtypes If set, will cause the content type's subtypes to also be registered to this folder @return the folder_id that was created } { @@ -69,12 +74,20 @@ -package_name "content_folder" \ "content_folder"] - # For some reason, this is not included in the PL/SQL call + # Set package_id. For some reason, this is not included in the PL/SQL call if { ![empty_string_p $package_id] } { db_dml update_package_id { update cr_folders set package_id = :package_id where folder_id = :folder_id } } + + # Register folders + if { [llength $content_types] > 0 } { + bcms::folder::register_content_types \ + -folder_id $folder_id \ + -subtypes=$subtypes_p \ + -content_types $content_types + } } ns_log notice "bcms::folder::create_folder created folder $folder_id" return $folder_id @@ -261,3 +274,44 @@ } +ad_proc -public bcms::folder::register_content_types { + {-subtypes:boolean} + {-folder_id:required} + {-content_types:required} +} { + Register one or more content types to a folder. + + @param subtypes Whether or not we should also register the content type's subtypes. +} { + set subtypes_p [db_boolean $subtypes_p] + foreach content_type $content_types { + db_exec_plsql register_type {} + } +} + + +ad_proc -public bcms::folder::get_id_by_package_id { + {-package_id ""} + {-parent_id ""} +} { + Get the ID of the folder with the given package_id, and optionally with the given parent. + + @return folder_id or empty string if no such folder. +} { + if { [empty_string_p $package_id] } { + set package_id [ad_conn package_id] + } + + if { [empty_string_p $parent_id] } { + return [db_string select_folder_id { select folder_id from cr_folders where package_id = :package_id } -default {}] + } else { + return [db_string select_folder_id_with_parent_id { + select f.folder_id + from cr_folders f, + cr_items i + where f.package_id = :package_id + and i.item_id = f.folder_id + and i.parent_id = :parent_id + } -default {}] + } +}