Forum OpenACS Q&A: Response to Breakthrough on bookmarks module

Collapse
Posted by Bob Fuller on

New proc in bookmarks-defs.tcl

The bookmarks-defs.tcl file, to the best of my recollection, just has the following proc added:

proc_doc bm_set_one_in_closed_p {db owner_id bookmark_id closed_p}
    {This procedure insures that the 'in_closed_p' column in the 'bm_list'
     table is consistent with the open/closed of the folder structure
     (by setting all contents of a single folder in_closed_p=t)} {

    set sort_key [database_to_tcl_string $db "
      select case when parent_sort_key is null then local_sort_key
        else parent_sort_key || cast(local_sort_key as varchar(3)) end
          as sort_key
    from bm_list
    where bookmark_id = $bookmark_id and folder_p = 't'
      and closed_p = '$closed_p' and owner_id = $owner_id"]

    if { $sort_key != "" } {

        ns_db dml $db "begin transaction"

        # ### This can't be done in postgresql, so we've rewritten it
        # Set as in_closed_p those bookmarks which have any parent as closed.
    #     ns_db dml $db "update bm_list set in_closed_p = 't'
    #  where bookmark_id in (select bookmark_id from bm_list
    #  where owner_id = $owner_id
    #  connect by prior bookmark_id = parent_id
    #  start with parent_id in (select bookmark_id from bm_list where owner_id = $owner_id and folder_p = 't' and closed_p = 't'))"

        ns_db dml $db "update bm_list set in_closed_p = '$closed_p'
                       where owner_id = $owner_id and parent_sort_key like '$sort_key%'"

        ns_db dml $db "end transaction"
    }
}

It should be noted that my logic for working with the closed_p and in_closed_p fields was as follows:

  • If the action taken is "open_all", then just set both closed_p and in_closed_p to 'f' where owner_id = $user_id
  • If the action taken is "close_all", then just set closed_p = 't' where owner_id = $user_id, and do the same for in_closed_p (parent_id not null)
  • This leaves two final scenarios:
    1. Open one folder
    2. Close one folder

    In both of these remaining scenarios, all you need to do is update closed_p as appropriate, and then update in_closed_p similarly for all the children of the folder in question. That's what the new proc accomplishes.