Forum OpenACS Q&A: News items on index page

Collapse
Posted by Ola Hansson on
Hi all!

I'm trying to present the most recent news items much in the same mannor as on the OpenACS index page, but have temporarily run out of luck. The GetNewsItems proc doesn't seem to work and most_recent_news works but only returns a raw Tcl list.

Is there a proc I've overlooked or should I write some code to show the list in the way I want?

PS. I run OpenACS 3.2.4 (original tarball)

Thanks!

Collapse
Posted by Brian Mann on
I got tired of trying an just did a VERY ugly hack...I use an adp page, so I just did:
<%
 
 set db [ns_db gethandle]
 set selection [ns_db select $db "select * from calendar where sysdate() <= end_date order by start_date"] 
 while {[ns_db getrow $db $selection]} {
 
   set title [ns_set get $selection title]
   set calendar_id [ns_set get $selection calendar_id]
   set approved_p [ns_set get $selection approved_p]
   if {$approved_p != "f"} {
      ns_puts "<li><a href="calendar/item.tcl?calendar_id=$calendar_id">$title</a>"
 }}
  ns_puts "</ul>"
%>
I'm sure somebody can tell me how to do it more elegantly, but it seems to work.
Collapse
Posted by Brian Mann on
boy, I'm glad <pre> tags do what they're supposed to...

that line is supposed to be:

ns_puts "<li><a href="calendar/item.tcl?calendar_id=$calendar_id">$title
</a>"

Collapse
Posted by Alex Sokoloff on
Filching the code from news/index.tcl worked well for me. You'll need to edit a little to give a more compact display of the news. Try something like this (you might have to look at the page source to get some of the html, which the pre tag doesn't seem to be smart enough to interpret as code):

#
# /www/news/index.tcl
#
# news main page
#
# Author: jkoontz@arsdigita.com March 8, 2000
#
# index.tcl,v 3.2 2000/03/10 23:45:33 jkoontz Exp

# Note: if page is accessed through /groups pages then group_id and
# group_vars_set are already set up in the environment by the
# ug_serve_section. group_vars_set contains group related variables
# (group_id, group_name, group_short_name, group_admin_email,
# group_public_url, group_admin_url, group_public_root_url,
# group_admin_root_url, group_type_url_p, group_context_bar_list and
# group_navbar_list)

set_the_usual_form_variables 0
# possibly archive_p
# maybe scope, maybe scope related variables (user_id, group_id, on_which_group, on_what_id)

ad_scope_error_check

set db_conns [ns_db gethandle [philg_server_default_pool] 2]
set db [lindex $db_conns 0]
set db_sub [lindex $db_conns 1]
ad_scope_authorize $db $scope all group_member all


if { ![info exists user_id] } {
    set user_id 0
}
if { ![info exists group_id] } {
    set group_id 0
}

# Create a clause for returning the postings for relavent groups
set newsgroup_clause "(newsgroup_id = [join [news_newsgroup_id_list $db $user_id $group_id] " or newsgroup_id = "])"

if { [info exists archive_p] && $archive_p } {
    set query "
    select news_item_id, title, release_date, body, html_p
    from news_items
    where sysdate() > expiration_date
    and $newsgroup_clause
    and approval_state = 'approved'
    order by release_date desc, creation_date desc"
} else {
    set query "
    select news_item_id, title, release_date, body, html_p
    from news_items
    where sysdate() between release_date and expiration_date
    and $newsgroup_clause
    and approval_state = 'approved'
    order by release_date desc, creation_date desc"
}

set selection [ns_db select $db $query]

set counter 0
while { [ns_db getrow $db $selection] } {
    set_variables_after_query
    incr counter
    append page_content "<li>[util_AnsiDatetoPrettyDate $release_date]: "
    append page_content "<a href="/news/item.tcl?[export_url_scope_vars news_item_id]">$title</a>"
}

if { $counter == 0 } {
    append page_content "None."
}

append page_content "
</ul>
"

ns_db releasehandle $db
ns_db releasehandle $db_sub