Index: openacs-4/packages/assessment/lib/session-items.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/lib/session-items.tcl,v diff -u -N -r1.23 -r1.24 --- openacs-4/packages/assessment/lib/session-items.tcl 7 Aug 2017 23:48:03 -0000 1.23 +++ openacs-4/packages/assessment/lib/session-items.tcl 22 May 2018 22:27:29 -0000 1.24 @@ -1,39 +1,56 @@ -if {![info exists edit_p] || $edit_p eq ""} { - set edit_p 0 -} +ad_include_contract { + Display session items -if {![info exists feedback_only_p] || $feedback_only_p eq ""} { - set feedback_only_p 0 + @param assessment_id + @param assessment_data + @param edit_p + @param feedback_only_p + @param item_id_list + @param next_url + @param return_p + @param session_id + @param section_id + @param show_item_name_p + @param show_feedback + @param subject_id + @param survey_p +} { + assessment_data:array,notnull + {assessment_id:integer $assessment_data(assessment_id)} + {edit_p:boolean,notnull 0} + {feedback_only_p:boolean,notnull 0} + {item_id_list ""} + {next_url:localurl ""} + return_p:optional,notnull + session_id:integer,notnull + section_id:integer,notnull + show_item_name_p:boolean,notnull + show_feedback:notnull + subject_id:integer,notnull + survey_p:boolean,notnull } -if {![info exists assessment_id]} { - set assessment_id $assessment_data(assessment_id) -} set admin_p [permission::permission_p \ - -party_id [ad_conn user_id] \ - -privilege admin \ - -object_id $assessment_id] + -party_id [ad_conn user_id] \ + -privilege admin \ + -object_id $assessment_id] # if we can tell this is the last section, next button should go to feedback for the entire assessment. - set section_list [as::assessment::sections \ -assessment_id $assessment_id \ -session_id $session_id \ -sort_order_type $assessment_data(section_navigation) \ -random_p $assessment_data(random_p)] -if {(![info exists next_url] || $next_url eq "") - && [lsearch $section_list $section_id] eq [llength $section_list]-1 -} { +if {$next_url eq "" && [lsearch $section_list $section_id] eq [llength $section_list]-1} { set next_url [export_vars -base session {session_id next_url}] } -set items_clause "" -if {[info exists item_id_list]} { - if {[llength $item_id_list]} { - set items_clause "and i.as_item_id in ([join $item_id_list ,])" - } +if {$item_id_list ne ""} { + set items_clause "and i.as_item_id in ([join $item_id_list ,])" +} else { + set items_clause "" } ad_form -name session_results_$section_id -mode display -form { @@ -52,143 +69,143 @@ set default_value [as::item_data::get -subject_id $subject_id -as_item_id $as_item_id -session_id $session_id] array set item [as::item::item_data -as_item_id $as_item_id] - + set presentation_type [as::item_form::add_item_to_form -name session_results_$section_id -section_id $section_id -item_id $as_item_id -session_id $session_id -default_value $default_value -show_feedback $show_feedback -random_p $assessment_data(random_p)] if {$presentation_type eq "fitb"} { regsub -all -line -nocase -- {$feedback_wrong" - set has_feedback_p 1 - } else { - set feedback "" - } - } - } else { - set correct_p 1 - if {$show_feedback ne "incorrect"} { - if { $feedback_right ne "" } { - set feedback "$feedback_right" - set has_feedback_p 1 - } else { - set feedback "" - } - } - } - } else { - set correct_p 1 - if {$presentation_type eq "rb" || $presentation_type eq "cb"} { - set user_answers [db_list get_user_choice_answers {}] + array set values $default_value + set result_points $values(points) + set item_data_id $values(item_data_id) + array unset values + set answered_p t + #ns_log notice "points = $points result_points= $result_points" + if { $points != 0 } { + if {$result_points < $points} { + set correct_p 0 + if {$show_feedback ne "correct"} { + if { $feedback_wrong ne "" } { + set feedback "$feedback_wrong" + set has_feedback_p 1 + } else { + set feedback "" + } + } + } else { + set correct_p 1 + if {$show_feedback ne "incorrect"} { + if { $feedback_right ne "" } { + set feedback "$feedback_right" + set has_feedback_p 1 + } else { + set feedback "" + } + } + } + } else { + set correct_p 1 + if {$presentation_type eq "rb" || $presentation_type eq "cb"} { + set user_answers [db_list get_user_choice_answers {}] - set correct_answers [db_list get_correct_choice_answers {}] + set correct_answers [db_list get_correct_choice_answers {}] - if { $presentation_type eq "rb" } { - set user_answers [lindex $user_answers 0] + if { $presentation_type eq "rb" } { + set user_answers [lindex $user_answers 0] - if { [lsearch $correct_answers $user_answers] == -1 } { - set correct_p 0 - if {$show_feedback ne "correct"} { - if { $feedback_wrong ne "" } { - set feedback "$feedback_wrong" - set has_feedback_p 1 - } else { - set feedback "" - } - } - } else { - if {$show_feedback ne "incorrect"} { - if { $feedback_right ne "" } { - set feedback "$feedback_right" - set has_feedback_p 1 - } else { - set feedback "" - } - } - } - } else { - # Checkbox, all answers must be correct if no - # points are set - - if { [llength $user_answers] != [llength $correct_answers] } { - set correct_p 0 - } else { - set correct_p 1 - foreach one_answer $user_answers { - if { [lsearch $correct_answers $one_answer] == -1 } { - set correct_p 0 - break - } - } - } + if { [lsearch $correct_answers $user_answers] == -1 } { + set correct_p 0 + if {$show_feedback ne "correct"} { + if { $feedback_wrong ne "" } { + set feedback "$feedback_wrong" + set has_feedback_p 1 + } else { + set feedback "" + } + } + } else { + if {$show_feedback ne "incorrect"} { + if { $feedback_right ne "" } { + set feedback "$feedback_right" + set has_feedback_p 1 + } else { + set feedback "" + } + } + } + } else { + # Checkbox, all answers must be correct if no + # points are set - if { !$correct_p } { - if {$show_feedback ne "correct"} { - if { $feedback_wrong ne "" } { - set feedback "$feedback_wrong" - set has_feedback_p 1 - } else { - set feedback "" - } - } - } else { - if {$show_feedback ne "incorrect"} { - if { $feedback_right ne "" } { - set feedback "$feedback_right" - set has_feedback_p 1 - } else { - set feedback "" - } - } - } - } - } - } - if {[string is double -strict]} { - set result_points [format "%3.2f" $result_points] - } - # result points here + if { [llength $user_answers] != [llength $correct_answers] } { + set correct_p 0 + } else { + set correct_p 1 + foreach one_answer $user_answers { + if { [lsearch $correct_answers $one_answer] == -1 } { + set correct_p 0 + break + } + } + } + + if { !$correct_p } { + if {$show_feedback ne "correct"} { + if { $feedback_wrong ne "" } { + set feedback "$feedback_wrong" + set has_feedback_p 1 + } else { + set feedback "" + } + } + } else { + if {$show_feedback ne "incorrect"} { + if { $feedback_right ne "" } { + set feedback "$feedback_right" + set has_feedback_p 1 + } else { + set feedback "" + } + } + } + } + } + } + if {[string is double -strict]} { + set result_points [format "%3.2f" $result_points] + } + # result points here } else { - set result_points "" - set feedback "" - set answered_p f + set result_points "" + set feedback "" + set answered_p f } # set content [as::assessment::display_content -content_id $item(content_rev_id) -filename $item(content_filename) -content_type $item(content_type)] set content $question_text if { $has_feedback_p == 1 } { - incr feedback_count + incr feedback_count } } @@ -202,20 +219,19 @@ upvar 0 items:$i this set this(num) $counter if {$i < ${items:rowcount}} { - upvar 0 items:$j next - set this(next_as_item_id) $next(as_item_id) - set this(next_pr_type) $next(presentation_type) - if {$this(as_item_id) != $next(as_item_id)} { - incr counter - } + upvar 0 items:$j next + set this(next_as_item_id) $next(as_item_id) + set this(next_pr_type) $next(presentation_type) + if {$this(as_item_id) != $next(as_item_id)} { + incr counter + } } else { - set this(next_as_item_id) "" - set this(next_pr_type) "" + set this(next_as_item_id) "" + set this(next_pr_type) "" } } set showpoints [parameter::get -parameter "ShowPoints" -default 1 ] - # Local variables: # mode: tcl # tcl-indent-level: 4