Index: openacs-4/packages/faq-portlet/tcl/faq-portlet-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/faq-portlet/tcl/faq-portlet-procs.tcl,v diff -u -r1.15 -r1.16 --- openacs-4/packages/faq-portlet/tcl/faq-portlet-procs.tcl 3 Dec 2001 02:51:57 -0000 1.15 +++ openacs-4/packages/faq-portlet/tcl/faq-portlet-procs.tcl 10 Dec 2001 22:35:49 -0000 1.16 @@ -43,13 +43,25 @@ @author arjun@openforce.net @creation-date Sept 2001 } { - # Tell portal to add this element to the page - set element_id [portal::add_element $portal_id [my_name]] - - # The default param "package_id" must be configured - set key "package_id" - portal::set_element_param $element_id $key $package_id + # Find out if faq already exists on this portal page + set element_id_list \ + [portal::get_element_ids_by_ds $portal_id [my_name]] + if {[llength $element_id_list] == 0} { + # Tell portal to add this element to the page + set element_id [portal::add_element $portal_id [my_name]] + # There is already a value for the param which must be overwritten + portal::set_element_param $element_id package_id $package_id + set package_id_list [list] + } else { + set element_id [lindex $element_id_list 0] + # There are existing values which should NOT be overwritten + portal::add_element_param_value \ + -element_id $element_id \ + -key package_id \ + -value $package_id + } + return $element_id } @@ -66,51 +78,79 @@ array set config $cf - # things we need in the config: package_id - - set package_id $config(package_id) - set query "select f.faq_id, f.faq_name, entry_id, question + set query "select f.faq_id, + f.faq_name, + entry_id, + question from acs_objects o, faqs f, faq_q_and_as qa where object_id = f.faq_id and context_id = :package_id and qa.faq_id(+) = f.faq_id" - set data "" - set rowcount 0 + # Should be a list already! + set list_of_package_ids $config(package_id) - db_foreach select_faqs $query { - append data "
FAQ | -Question | -
more..." - } + # not in workspace + if { [db_string count_faqs "select count(*) from faq_q_and_as, acs_objects where context_id = :package_id and object_id=faq_id" ] != 0 } { + # we have faqs + append template "