Index: openacs-4/contrib/packages/bcms/tcl/bcms-item-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/bcms/tcl/bcms-item-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/bcms/tcl/bcms-item-procs.tcl 14 May 2003 15:34:59 -0000 1.1 +++ openacs-4/contrib/packages/bcms/tcl/bcms-item-procs.tcl 4 Aug 2003 11:19:46 -0000 1.2 @@ -12,28 +12,43 @@ # for possible contribution ad_proc -public bcms::item::get_content_type { - -item_id:required + {-item_id:required} } { returns the content type of a particular item_id + + @param item_id you wish to know what content type + + @returns the content type of an item } { array set one_item [get_item -item_id $item_id] return $one_item(content_type) } -ad_proc -public bcms::item::create_item { + +ad_proc -private bcms::item::create_item { {-item_name:required} {-parent_id:required} {-content_type "content_revision"} {-storage_type "text"} - {-creation_user_id ""} - {-creation_ip ""} + {-creation_user_id} + {-creation_ip} } { This proc only creates the content item but not the revision. Normally you would like couple this with create_revision or your own custom create_revision. - Returns the item_id that was created + @param item_name the name or url that will be used for the content item + @param parent_id the parent_id which the page will be under, normally this is a folder + @param content_type content type of the item to be created + @param storage_type where to store the item, valid values are: text, file and lob (lob support not yet implemented) + @param creation_user_id user_id creating this item + @param creation_user_ip ip address which this item is created + + @returns the item_id that was created } { + if {![info exists creation_user_id]} { set creation_user_id [ad_conn user_id] } + if {![info exists creation_ip]} { set creation_ip [ad_conn peeraddr] } + set item_id [db_exec_plsql create_item "SQL"] ns_log notice "bcms::item::create_item created new item $item_id" return $item_id @@ -44,13 +59,23 @@ {-target_id:required} {-name:required} {-label:required} - {-creation_user_id ""} - {-creation_ip ""} + {-creation_user_id} + {-creation_ip} } { creates a symlink to the content item target_id - returns the item_id of the new link + @param parent_id the item which will hold the symlink, normally the destination folder + @param target_id link to which item_id, the source + @param name name of the link + @param label label or title of the link + @param creation_user_id user_id creating this item + @param creation_user_ip ip address which this item is created + + @returns the item_id of the new link } { + if {![info exists creation_user_id]} { set creation_user_id [ad_conn user_id] } + if {![info exists creation_ip]} { set creation_ip [ad_conn peeraddr] } + set item_id [db_exec_plsql create_link "SQL"] ns_log notice "bcms::item::create_link created new link $item_id to $target_id" return $item_id @@ -62,6 +87,10 @@ {-parent_id} } { edits the content item's name or folder/parent_id + + @param item_id id of item to edit + @param name if supplied it will edit the name + @param parent_id if supplied it will move the item to the new parent } { if [info exists name] { @@ -75,82 +104,68 @@ ad_proc -public bcms::item::delete_item { - {-item_id:required} + -item_id:required } { nukes out the content item. + This also deletes the all the revision of the content item - returns 0 if successful. + @param item_id of the item to be deleted - This also deletes the all the revision of the content item + @returns 0 if successful. } { - db_transaction { - # use db_foreach because we may have multiple revisions - db_foreach delete_all_revisions "SQL" {} - return [db_exec_plsql delete_item "SQL"] - } - + return [db_exec_plsql delete_item "SQL"] } -# TODO: refactor this code so we the view cr_XXXx instead of cr_items and cr_revisions. -# remove the depth, lets just use the list_tree + ad_proc -public bcms::item::list_items { - {-parent_id:required} - {-revision} - {-content_type} - {-level_diff 1} - {-multirow_name} + -parent_id:required + {-revision latest} + {-content_type content_revision} + {-multirow_name bcms_list_items} {-return_list:boolean false} + {-additional_columns [list]} } { Gets all content item under the parent_id - upvars a bcms_list_items variable to the adp level that - contains rows of content items below the parent_id + @param parent_id id of the which contents you wish to list, normally a folder + @param revision returns items that have live or latest revision under the parent_id + @param content_type + @param multirow_name you can supply your own multirow name + @param return_list if supplied a list of ns_sets otherwise it + returns a multirow uses the multirow_name if given + @param additional_columns to be returned with the results + + @returns rows of content items below the parent_id with the following columns: item_id, name, live_revision, latest_revision, publish_status, - content_type, storage_type, level, parent_level + content_type, storage_type, tree_sortkey, title, description - Since multirow is not easy to pass around procs I have decided just add a return_list switch. - This will return a list of ns_sets. - - -revision will only returns items that have live or latest revision under the parent_id - if this is used additional info are returned such as revision_id, title, description, publish_date - - -level_diff if present will only returns items that is level_diff >= level - parent_level. - That means "-level_diff 1" will only return the current child of the parent_id. - if its not present then we return all childrens - DO NOT USE THIS ANYMORE, use tree_items instead. - - } { + # TODO: make use of db_map... + # initialize the addtionals we will use set addtnl_where_list [list] - set addtnl_select_list [list] + set addtnl_select_list $additional_columns # if additional revision data must be returned, set the additional columns here - # for revisions. we need to make use of db_map - if [info exists revision] { - lappend addtnl_select_list r.revision_id r.title r.description r.publish_date - set addtnl_from ", cr_revisions r" - switch -exact $revision { - latest { lappend addtnl_where_list "i.latest_revision = r.revision_id" } - live { lappend addtnl_where_list "i.live_revision = r.revision_id" } - default { - # abort the proc - ns_log notice "bcms: revision requested not valid" - return - } + # for revisions. + + # lets get the view for the content type + db_1row get_table_name "SQL" + set addtnl_from ", ${table_name}x r" + + switch -exact $revision { + latest { lappend addtnl_where_list "i.latest_revision = r.revision_id" } + live { lappend addtnl_where_list "i.live_revision = r.revision_id" } + default { + # abort the proc + ns_log notice "bcms: revision requested not valid" + error "revision requested not valid" + return } - } else { - set addtnl_from "" } - # TODO: make use of db_map... - # check to see how deep we want to go - if {$level_diff != 0} { - lappend addtnl_where_list ":level_diff >= tree_level(i.tree_sortkey) - tree_level(p.tree_sortkey)" - } - # pick a particular content type if [info exists content_type] { lappend addtnl_where_list "content_type = :content_type" @@ -163,17 +178,19 @@ set addtnl_where "" } if {[llength $addtnl_select_list] > 0} { + set addtnl_select_folder ", null as [join $addtnl_select_list ", null as "]" + set addtnl_select_list [linsert $addtnl_select_list 0 r.title r.description] set addtnl_select ", [join $addtnl_select_list ", "]" } else { set addtnl_select "" + set addtnl_select_folder "" } if {$return_list_p} { # return a list of lists since its not easy to pass multirow from proc to proc return [db_list_of_ns_sets get_items "SQL"] } else { # make a multirow, it is likely that this proc is not being called from another proc - if ![info exists multirow_name] { set multirow_name bcms_list_items } db_multirow $multirow_name get_items "SQL" } @@ -308,10 +325,19 @@ ad_proc -public bcms::item::get_item_by_url { {-root_id:required} {-url:required} - {-resolve_index true} {-revision} + {-resolve_index:boolean false} } { - get the content item details. Returns an array that contains the following + get the content item details based from the url. + + @param root_id starting from which url to resolve the item + @param url the url which we would like to resolve + @param revision if "-revision live" or "-revision lastest" is given then additional + properties are returned + @param resolve_index return the item_id of the index content item on a content_folder + rather than the content_folder's item_id + + @returns an array that contains the following item_id, name, parent_id, live_revision, latest_revision, publish_status, content_type and storage_type @@ -321,14 +347,11 @@ revision_id, title, content, description, publish_date, mime_type - -resolve_index is to return the item_id of the index content item on a content_folder - rather than the content_folder's item_id - if it returns a single element array that means no item exists so using [array size yourarray] > 0 should check if such item does exists - [array size yourarray] > 1 should check if a revision was retrieved. item exists - but revision does not exists + [array size yourarray] > 1 should check if a live revision was retrieved. item exists + but no live revision Be careful in checking [array size yourarray] inside a loop, you must unset the array first. array unset yourarray. @@ -353,7 +376,13 @@ {-item_id:required} {-revision} } { - get the content item details. Returns an array that contains the following + get the content item details. + + @param item_id id of the item you want to get properties + @param revision if "-revision live" or "-revision lastest" is given then additional + properties are returned + + @returns an array that contains the following name, parent_id, live_revision, latest_revision, publish_status, content_type and storage_type @@ -404,6 +433,7 @@ } } +# TODO move this out, this is too specific ad_proc -public bcms::item::list_pages { {-parent_id:required} {-revision latest} @@ -445,6 +475,7 @@ } +# TODO move this out, this is too specific ad_proc -public bcms::item::list_images { {-parent_id:required} {-live_items:boolean false} @@ -465,6 +496,7 @@ } +# TODO move this out, this is too specific ad_proc -public bcms::item::list_files { {-parent_id:required} {-live_items:boolean false} @@ -566,3 +598,31 @@ } +ad_proc -public bcms::item::get_item_path { + {-item_id:required} + {-root_id} + {-prepend_path ''} + {-multirow_name bcms_item_path} + {-return_list:boolean false} +} { + returns a path from the root_id to the item_id. + + @param item_id build the path to this item + @param root_id build the path from this folder, if not supplied it use the current bcms root + @param prepend_path you can add a string to prepend the path column + @param multirow_name you can supply your own multirow name + @param return_list if supplied a list of ns_sets otherwise it + returns a multirow uses the multirow_name if given + @returns the following attributes item_id, path, title +} { + if ![info exists root_id] { + # if the parent_id does not exists then start from the root + set root_id [bcms::folder::get_bcms_root_folder] + } + + if {$return_list_p} { + return [db_list_of_ns_sets get_item_path "SQL"] + } else { + db_multirow $multirow_name get_item_path "SQL" + } +}