Forum OpenACS Q&A: Re: General Comments on adp pages

Collapse
Posted by Joel Aufrecht on
Here's what I stole from some other package - I offer it up as a straw man for the "right way" to do comments for things that aren't static pages.

You can track comments for any ACS Object. Let's assume that your package is notes, and you've created it as per the tutorial so that each note is also an acs object. (That is, each entry in the notes table has a corresponding entry in acs_objects, and this is enforced with a foreign key and implemented by having a notes__new stored procedure which calls acs_object__new.) Now you have an adp/tcl pair that presents a note.

First, you need to generate a url for adding comments.

set comment_add_url "[general_comments_package_url]comment-add?[export_vars {
 { object_id $note_id } 
 { object_name $title } 
 { return_url "[ad_conn url]?[ad_conn query]"} 
}]"

This calls a global, public tcl function that the general_comments package registered, to get its url. You then embed in that url the id of the note and its title, and set the return_url to the current url so that the user can return after adding a comment.

Now, you need to create html that shows any existing comments. You do this by calling another general_comments function:


set comments_html [general_comments_get_comments -print_content_p 1 $note_id]

First, you pass in a parameter that that says to actually show the contents of the comments, instead of just the fact that there are comments. Then you pass the note id, which is also the acs_object id.

Now that you've set up these two variables, you need to put them in your adp page:


bla blah blah
<a href="@comment_add_url@">Add a comment</a>
<p>@comments_html@

If you want to learn more about these functions, you can go to /api-doc on your instance and look them up or browse to them, if you have general-comments installed.

Collapse
Posted by Pavel Boghita on
Thanks Joel, this is a brilliant piece of information - exactly what I was looking for