Forum OpenACS Development: Category Description

Posted by Iuri Sampaio on
Hi there,

Is there an ad_proc to get the category description?

I've found category::get_name (api-doc: )

the main part is:
if { [catch { array set cat_lang [lindex [nsv_get categories $category_id] 1] }] }
, which returns pairs of locales and names. (i.e. {{$locale $name} {...} ... }

Modifying ad_proc category::get_name (it could break legacy code) or creating a new ad_proc (more recommended approach), what would we apply ?

2: Re: Category Description (response to 1)
Posted by Brian Fenton on
Hi Iuri

not that I am aware of. I don't think get_name is much use to you either as that uses the categories nsv, which I doubt holds the description info.

If you have the category_id and the locale, the following should be sufficient to get the description.

set category_description [db_string get_desc "select description from category_translations where category_id = :category_id and locale = :locale" -default ""]

hope that helps

3: Re: Category Description (response to 1)
Posted by Gustaf Neumann on

You are right, there is no API call provided for obtaining the description of a category. The description is language-specific, and is kept in the table category_translations. One should be able to use a proc in the following style.

I'll commit this later. all the best


d_proc -public category::get {
    {-locale ""}
} {
    Get name and description for a category_id in the given or
    connection's locale. If for the combination of category and locale
    no entry in category_translations exists, then empty is returned.

    @option category_id category_id of the category to be queried.
    @option locale locale of the language. [ad_conn locale] used by default.
    @return list of attribute value pairs containing name and description
} {
    if {$locale eq ""} {
        set locale [ad_conn locale]
    if {[db_0or1row category_get {
        select name, description
        from category_translations
        where category_id = :category_id
        and locale = :locale
    }]} {
        set result [list name $name description $description]
    } else {
        set result ""
    return $result
4: Re: Category Description (response to 3)
Posted by Iuri Sampaio on
Thanks Brian, right on!

I figured that out after debugging how category info is inserted into translation.

@Thanks Gustaf,
No rush, that will be my humble contribution to the next release.

Also, I have built a FB authentication, login and registration. But that I'll save for in the future! It still lacks some dots "in the i's" (code optimization and fixes)

I'm pretty sure if we build social media integration packages into OACS, it will attract more people to our community.