Index: openacs-4/packages/imsld/tcl/imsld-condition-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-condition-procs.tcl,v diff -u -r1.14 -r1.15 --- openacs-4/packages/imsld/tcl/imsld-condition-procs.tcl 26 Jul 2006 14:37:27 -0000 1.14 +++ openacs-4/packages/imsld/tcl/imsld-condition-procs.tcl 20 Sep 2006 08:26:30 -0000 1.15 @@ -60,26 +60,323 @@ -run_id } { } { -foreach condition_xml [db_list get_other_conditions { - select ici.condition_xml - from imsld_conditionsi ici, - imsld_methodsi imi, - imsld_imsldsi iii, - imsld_runs iri - where ici.item_id not in (select object_id_two - from acs_rels - where (rel_type='imsld_prop_cond_rel' or rel_type='imsld_ilm_cond_rel')) - and ici.method_id=imi.item_id - and imi.imsld_id=iii.item_id - and iri.imsld_id=iii.imsld_id - and iri.run_id=:run_id + foreach condition_xml [db_list get_other_conditions { + select ici.condition_xml + from imsld_conditionsi ici, + imsld_methodsi imi, + imsld_imsldsi iii, + imsld_runs iri + where ici.item_id not in (select object_id_two + from acs_rels + where (rel_type='imsld_prop_cond_rel' or rel_type='imsld_ilm_cond_rel')) + and ici.method_id=imi.item_id + and imi.imsld_id=iii.item_id + and iri.imsld_id=iii.imsld_id + and iri.run_id=:run_id }] { dom parse $condition_xml document $document documentElement condition_node imsld::condition::execute -run_id $run_id -condition $condition_node } } +ad_proc -public imsld::condition::eval_when_condition_true { + -when_condition_true_item_id:required + -run_id:required +} { + Executes the expression of the when-condition-true for all the roles, and if it's for all the individual users + of the role, then the act which references when-condition-true is set to completed. +} { + # 1. get the epression and the role from the when-condition-true table + # 2. get all the users in the role and evaluate the expression for all of them + # 3. if the expression is true for all of the users, mark the act as completed + + # 1. get the expression and role + db_1row get_condition_info { + select iri.role_id, + iwct.expression_xml + from imsld_when_condition_truei iwct, imsld_rolesi iri + where iwct.item_id = :when_condition_true_item_id + and iwct.role_id = iri.item_id + and content_revision__is_live(iri.role_id) = 't' + } + + # 2. evaluate the expression for all the users + set expression_true_p 1 + dom parse $expression_xml document + $document documentElement expression_root + set expression [$expression_root childNodes] + foreach member_id [imsld::roles::get_users_in_role -role_id $role_id -run_id $run_id] { + if { ![imsld::expression::eval -run_id $run_id -expression $expression -user_id $member_id] } { + # expression is false for one user. exit + set expression_true_p 0 + break + } + } + + # 3. if the expression is true for all of the users, mark the rererencer act as completed + db_1row get_context_info { + select ir.imsld_id, + ip.play_id + from imsld_runs ir, + imsld_methodsi im, + imsld_playsi ip, + imsld_imsldsi ii + where ir.run_id = :run_id + and ir.imsld_id = ii.imsld_id + and im.imsld_id = ii.item_id + and ip.method_id = im.item_id + and content_revision__is_live(ip.play_id) = 't' + } + + if { $expression_true_p } { + # get the act_id + db_1row get_act_from_when_cond_true_id { + select ia.act_id + from imsld_actsi ia, + imsld_complete_actsi ica + where ica.when_condition_true_id = :when_condition_true_item_id + and ia.complete_act_id = ica.item_id + } + # mark the act completed for all the users in the run + set users_in_run [db_list get_users_in_run { + select gmm.member_id + from group_member_map gmm, + imsld_run_users_group_ext iruge, + acs_rels ar1 + where iruge.run_id=:run_id + and ar1.object_id_two=iruge.group_id + and ar1.object_id_one=gmm.group_id + group by member_id + }] + foreach user $users_in_run { + if { [imsld::user_participate_p -run_id $run_id -act_id $act_id -user_id $user]} { + imsld::mark_act_finished -act_id $act_id \ + -play_id $play_id \ + -imsld_id $imsld_id \ + -run_id $run_id \ + -user_id $user + } + } + } +} + +ad_proc -public imsld::condition::eval_change_property_value { + -change_property_value_xml:required + -run_id:required +} { + Executes the expression of the change-property-value and sets the result to the associated property. +} { + dom parse $change_property_value_xml document + $document documentElement change_property_value_root + imsld::statement::execute -run_id $run_id -statement [$change_property_value_root childNodes] +} + +ad_proc -public imsld::condition::eval_when_prop_value_is_set { + -complete_act_item_id:required + -run_id:required +} { + Executes the expression of the when-property-value-is-set and compares the result with the referenced property. If the value is the same for both of them (or if there is no expression at all), the referenced activity is marked as completed. +} { + # get the referenced expression in order to evaluate it + db_1row context_info { + select when_prop_val_is_set_xml + from imsld_complete_actsi + where item_id = :complete_act_item_id + and content_revision__is_live(complete_act_id) = 't' + } + set user_id [ad_conn user_id] + dom parse $when_prop_val_is_set_xml document + $document documentElement when_prop_val_is_set_root + set wpv_is_node [$when_prop_val_is_set_root childNodes] +# set wpv_is_node [$statement childNodes] + + set equal_value_p 0 + # get the property value + set property_ref [$wpv_is_node selectNodes {*[local-name()='property-ref']}] + set property_value [imsld::runtime::property::property_value_get -run_id $run_id -user_id $user_id -identifier [$property_ref getAttribute {ref}]] + + # get the value of the referenced exression + set propertyvalueNode [$wpv_is_node selectNodes {*[local-name()='property-value']}] + + if { [llength $propertyvalueNode] } { + set propertyvalueChildNode [$propertyvalueNode childNodes] + set nodeType [$propertyvalueChildNode nodeType] + switch -- $nodeType { + {ELEMENT_NODE} { + switch -- [$propertyvalueChildNode localName] { + {calculate} { + set expression_value [imsld::expression::eval -run_id $run_id -expression [$propertyvalueChildNode childNodes]] + } + {property-ref} { + set expression_value [imsld::runtime::property::property_value_get -run_id $run_id -user_id $user_id -identifier [$propertyvalueChildNode getAttribute {ref}]] + } + } + } + {TEXT_NODE} { + set expression_value [$propertyvalueNode text] + } + } + + if { [string eq $property_value $expression_value] } { + set equal_value_p 1 + } + + } else { + # there is no associated value, the activity is completed + set equal_value_p 1 + } + + if { $equal_value_p } { + # the values are the same, mark the referenced activity as completed + # 1. identify what kind of activiy we must mark as finished. + # it can be a support activity, learning activity, act or play + db_1row get_extra_info { + select imsld_id + from imsld_runs + where run_id = :run_id + } + + if { [db_0or1row learning_activity_p { + select 'learning' as activity_type, + item_id as activity_item_id, + activity_id + from imsld_learning_activitiesi + where complete_act_id = :complete_act_item_id + and content_revision__is_live(activity_id) = 't' + }] } { + # mark the act completed for all the users in the run + set role_part_id_list [imsld::get_role_part_from_activity -activity_type learning -leaf_id $activity_item_id] + + set users_in_run [db_list get_users_in_run { + select gmm.member_id + from group_member_map gmm, + imsld_run_users_group_ext iruge, + acs_rels ar1 + where iruge.run_id=:run_id + and ar1.object_id_two=iruge.group_id + and ar1.object_id_one=gmm.group_id + group by member_id + }] + foreach user $users_in_run { + foreach role_part_id $role_part_id_list { + db_1row context_info { + select acts.act_id, + plays.play_id + from imsld_actsi acts, imsld_playsi plays, imsld_role_parts rp + where rp.role_part_id = :role_part_id + and rp.act_id = acts.item_id + and acts.play_id = plays.item_id + } + imsld::finish_component_element -imsld_id $imsld_id \ + -run_id $run_id \ + -play_id $play_id \ + -act_id $act_id \ + -role_part_id $role_part_id \ + -element_id $activity_id \ + -type learning \ + -code_call + } + } + } + if { [db_0or1row support_activity_p { + select 'support' as activity_type + from imsld_support_activities + where complete_act_id = :complete_act_item_id + and content_revision__is_live(activity_id) = 't' + }] } { + # mark the act completed for all the users in the run + set role_part_id_list [imsld::get_role_part_from_activity -activity_type learning -leaf_id $activity_item_id] + + set users_in_run [db_list get_users_in_run { + select gmm.member_id + from group_member_map gmm, + imsld_run_users_group_ext iruge, + acs_rels ar1 + where iruge.run_id=:run_id + and ar1.object_id_two=iruge.group_id + and ar1.object_id_one=gmm.group_id + group by member_id + }] + foreach user $users_in_run { + foreach role_part_id $role_part_id_list { + db_1row context_info { + select acts.act_id, + plays.play_id + from imsld_actsi acts, imsld_playsi plays, imsld_role_parts rp + where rp.role_part_id = :role_part_id + and rp.act_id = acts.item_id + and acts.play_id = plays.item_id + } + imsld::finish_component_element -imsld_id $imsld_id \ + -run_id $run_id \ + -play_id $play_id \ + -act_id $act_id \ + -role_part_id $role_part_id \ + -element_id $activity_id \ + -type learning \ + -code_call + } + } + } + if { [db_0or1row act_activity_p { + select 'act' as activity_type, + ia.act_id, + ip.play_id + from imsld_acts ia, imsld_playsi ip + where ia.complete_act_id = :complete_act_item_id + and content_revision__is_live(ia.act_id) = 't' + and ia.play_id = ip.item_id + }] } { + # mark the act completed for all the users in the run + set users_in_run [db_list get_users_in_run { + select gmm.member_id + from group_member_map gmm, + imsld_run_users_group_ext iruge, + acs_rels ar1 + where iruge.run_id=:run_id + and ar1.object_id_two=iruge.group_id + and ar1.object_id_one=gmm.group_id + group by member_id + }] + foreach user $users_in_run { + if { [imsld::user_participate_p -run_id $run_id -act_id $act_id -user_id $user] } { + imsld::mark_act_finished -act_id $act_id \ + -play_id $play_id \ + -imsld_id $imsld_id \ + -run_id $run_id \ + -user_id $user + } + } + } + if { [db_0or1row play_p { + select 'play' as activity_type, + play_id + from imsld_plays + where complete_act_id = :complete_act_item_id + and content_revision__is_live(play_id) = 't' + }] } { + # mark the act completed for all the users in the run + set users_in_run [db_list get_users_in_run { + select gmm.member_id + from group_member_map gmm, + imsld_run_users_group_ext iruge, + acs_rels ar1 + where iruge.run_id=:run_id + and ar1.object_id_two=iruge.group_id + and ar1.object_id_one=gmm.group_id + group by member_id + }] + foreach user $users_in_run { + imsld::mark_play_finished -play_id $play_id \ + -imsld_id $imsld_id \ + -run_id $run_id \ + -user_id $user + } + } + } +} + ad_proc -public imsld::expression::eval { -run_id -expression @@ -425,7 +722,6 @@ set propertyValue [$propertyvalueNode text] } } - imsld::runtime::property::property_value_set -run_id $run_id -user_id $user_id -identifier [$propertyref getAttribute {ref}] -value $propertyValue } {notification} {}