Index: openacs-4/packages/curriculum/tcl/misc-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/curriculum/tcl/misc-procs.tcl,v diff -u -N -r1.8 -r1.9 --- openacs-4/packages/curriculum/tcl/misc-procs.tcl 28 Jun 2003 09:30:03 -0000 1.8 +++ openacs-4/packages/curriculum/tcl/misc-procs.tcl 4 Jul 2003 11:22:16 -0000 1.9 @@ -12,6 +12,7 @@ namespace eval curriculum {} +# FIXME. Remove this if it proves unnecessary ... ad_proc -public curriculum::package_keys { } { Builds a list that will be used as an argument to "site_node_closest_ancestor_package". @@ -67,7 +68,7 @@ # "ad_conn subsite_id" does not work when called from within a filter # (which we do for the curriculum bar), so we use the following instead. - return [site_node_closest_ancestor_package [package_keys]] + return [site_node_closest_ancestor_package { acs-subsite dotlrn }] } package_id - package_url - @@ -623,30 +624,38 @@ {new_element ""} } { If not args are supplied, returns the initial value for the CurriculumProgress_**** cookie. - If an old value and new element are supplied, returns an appropriate new cookie value. + If old_value and new_element are supplied, returns an appropriate new cookie value. } { if { [empty_string_p $old_value] && [empty_string_p $new_element] } { return "start" - } elseif { [string equal "start" $old_value] } { - if { [llength [enabled_elements_memoized -package_id $package_id]] == 1} { - return "finished" - } else { - return [list $new_element] - } - } elseif { [string equal "reset_one_curriculum" $old_value] } { + } + + if { [string equal "start" $old_value] } { +# if { [llength [enabled_elements_memoized -package_id $package_id]] == 1} { +# # Just one element in curriculum. Should be rare! +# return "finished" +# } + + return [list $new_element] + } + + if { [string equal "reset_one_curriculum" $old_value] } { set curriculum_id $new_element return [reset_one_curriculum $curriculum_id] - } elseif { [string equal "finished" $old_value] } { - # If you're finished, adding a new element doesn't change that! - return "finished" - } else { - set tentative_result [lappend old_value $new_element] - if { [llength [enabled_elements_memoized -package_id $package_id]] == [llength $tentative_result] } { - return "finished" - } else { - return $tentative_result - } } + +# if { [string equal "finished" $old_value] } { +# # If you're finished, adding a new element doesn't change that! +# return "finished" +# } + + set tentative_result [lappend old_value $new_element] + +# if { [llength [enabled_elements_memoized -package_id $package_id]] == [llength $tentative_result] } { +# return "finished" +# } + + return $tentative_result } @@ -705,45 +714,52 @@ } { set cookie [ad_get_cookie [get_cookie_name]] set package_id [conn package_id] - if { ![empty_string_p $cookie] } { - # We have a cookie. -# if { [string equal "finished" $cookie] } { -# # User has completed curriculum, nothing more to do. -# return -# } - # See what the user is looking at right now and compare - # to curriculums to consider adding to cookie. - set list_of_lists [curriculum::enabled_elements_memoized -package_id $package_id] - set current_url [ad_conn url] - - foreach list $list_of_lists { - array set info $list - # Is the user visiting this curriculum element url? - if { [string equal $current_url $info(url)] } { - # See if this element isn't already in user's cookie. - set element_id $info(element_id) - if { [lsearch -exact $cookie $element_id] == -1 } { - set cookie [curriculum_progress_cookie_value -package_id $package_id $cookie $element_id] - ad_set_cookie -replace t [get_cookie_name] $cookie - # If the user is logged in, we'll also want to record - # the additional element in the database. - if { [set user_id [ad_conn user_id]] } { - # Insert, but only if there isn't a row already there. - set curriculum_id $info(curriculum_id) - db_dml map_insert {*SQL*} - } - } - } - } - } else { + if { [empty_string_p $cookie] } { # No cookie. if { [parameter::get -package_id $package_id \ -parameter AutomaticBarActivationP -default 1] } { ad_set_cookie -replace t \ [get_cookie_name] [curriculum_progress_cookie_value -package_id $package_id] } + return } + + # We have a cookie. +# if { [string equal "finished" $cookie] } { +# # User has completed curriculum, nothing more to do. +# return +# } + + # See what the user is looking at right now and compare + # to curriculums to consider adding to cookie. + set list_of_lists [curriculum::enabled_elements_memoized -package_id $package_id] + set current_url [ad_conn url] + + foreach list $list_of_lists { + array set info $list + + # Is the user visiting this curriculum element url? + if { [string equal $current_url $info(url)] } { + + # See if this element isn't already in user's cookie. + set element_id $info(element_id) + + if { [lsearch -exact $cookie $element_id] == -1 } { + set cookie [curriculum_progress_cookie_value -package_id $package_id $cookie $element_id] + ad_set_cookie -replace t [get_cookie_name] $cookie + + # If the user is logged in, we'll also want to record + # the additional element in the database. + + if { [set user_id [ad_conn user_id]] } { + # Insert, but only if there isn't a row already there. + set curriculum_id $info(curriculum_id) + db_dml map_insert {*SQL*} + } + } + } + } }