news_user_contributions

one of the documented procedures in this installation of the ACS
Usage:
news_user_contributions   db   user_id   purpose
What it does:
Returns list items, one for each news posting
Defined in: /web/philip/tcl/news-defs.tcl

Source code:


    if { $purpose == "site_admin" } {
	set restriction_clause ""
    } else {
	set restriction_clause "\nand n.approval_state = 'approved'"
    }

    set selection [ns_db select $db "
    select n.news_item_id, n.title, n.approval_state, n.release_date, ng.scope, 
           ng.group_id, ug.group_name, ug.short_name,
           decode(ng.scope, 'all_users', 1, 'registered_users', 1, 'public', 1, 'group', 4, 5)
             as scope_ordering
    from news_items n, newsgroups ng, user_groups ug 
    where n.creation_user = $user_id $restriction_clause
    and n.newsgroup_id = ng.newsgroup_id
    and ng.group_id=ug.group_id(+)
    order by scope_ordering, ng.group_id, n.release_date"]

    set db_sub [ns_db gethandle subquery]

    set items ""
    set last_group_id ""
    set item_counter 0
    while { [ns_db getrow $db $selection] } {
	set_variables_after_query

	switch $scope {
	    public {
		if { $item_counter==0 } {
		    append items "<h4>Public News Postings</h4>"		    
		    set root_url "/news"
		    set admin_root_url "/news/admin"
		}
	    }
	    group {
		if { $last_group_id!=$group_id } {
		    append items "<h4>$group_name News Postings</h4>"
		    
		    set sub_selection [ns_db 0or1row $db_sub "
		    select section_key
		    from content_sections
		    where scope='group' and group_id=$group_id
		    and module_key='news'"]
		    
		    if { [empty_string_p $selection] } {
			set root_url "/news"
			set admin_root_url "/news/admin"
		    } else {
			set_variables_after_subquery
			set root_url "[ug_url]/[ad_urlencode $short_name]/[ad_urlencode $section_key]"
			set admin_root_url "[ug_admin_url]/[ad_urlencode $short_name]/[ad_urlencode $section_key]"
		    }
		} 
	    } 
	}

	if { $purpose == "site_admin" } {
	    append items "<li>[util_AnsiDatetoPrettyDate $release_date]: <a href=\"$admin_root_url/item?[export_url_vars news_item_id]\">$title</a>\n"
	    if { ![string match $approval_state "approved"] } {
		append items "&nbsp; <font color=red>not approved</font>"
	    }
	} else {
	    append items "<li>[util_AnsiDatetoPrettyDate $release_date]: <a href=\"$root_url/item?[export_url_vars news_item_id]\">$title</a>\n"
	}
	set last_group_id $group_id
	incr item_counter
    }

    ns_db releasehandle $db_sub

    if [empty_string_p $items] {
	return [list]
    } else {
	return [list 0 "News Postings" "<ul>\n\n$items\n\n</ul>"]
    }



philg@mit.edu