Index: openacs-4/packages/imsld/www/activity-frame.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/www/activity-frame.tcl,v diff -u -N -r1.16.4.1 -r1.16.4.2 --- openacs-4/packages/imsld/www/activity-frame.tcl 27 Jun 2007 10:21:59 -0000 1.16.4.1 +++ openacs-4/packages/imsld/www/activity-frame.tcl 9 Jul 2007 16:09:51 -0000 1.16.4.2 @@ -52,6 +52,165 @@ ) } +set activity_item_id [content::revision::item_id -revision_id $activity_id] + +set referencer_structure_item_id "" + +if { [string eq $activity_type "learning"] } { + if { [string eq "" [db_string completion_restriction {select complete_act_id from imsld_learning_activities where activity_id = :activity_id}]] } { + # the learning activity has been visited and doesn't have any completion restriction. + # if it is referenced from an activity structure, verify if every referenced activity have been visted + db_0or1row referenced_from_structure_p { + select ar.object_id_one as referencer_structure_item_id + from acs_rels ar + where ar.object_id_two = :activity_item_id + } + } +} elseif { [string eq $activity_type "support"] } { + if { [string eq "" [db_string completion_restriction {select complete_act_id from imsld_support_activities where activity_id = :activity_id}]] } { + # the learning activity has been visited and doesn't have any completion restriction. + # if it is referenced from an activity structure, verify if every referenced activity have been visted + db_0or1row referenced_from_structure_p { + select ar.object_id_one as referencer_structure_item_id + from acs_rels ar + where ar.object_id_two = :activity_item_id + } + } +} + +if { ![string eq "" $referencer_structure_item_id] } { + db_1row get_structure_info { + select structure_id, + number_to_select + from imsld_activity_structuresi + where item_id = :referencer_structure_item_id + and content_revision__is_live(structure_id) = 't' + } + + # if the structure hasn't been finished + if { ![db_0or1row already_finished { + select 1 + from imsld_status_user + where related_id = :structure_id + and user_id = :user_id + and run_id = :run_id + and status = 'finished' + }] } { + set mark_structure_finished_p 1 + foreach referenced_activity [db_list_of_lists struct_referenced_activities { + select ar.object_id_two, + ar.rel_type + from acs_rels ar + where ar.object_id_one = :referencer_structure_item_id + order by ar.object_id_two + }] { + set object_id_two [lindex $referenced_activity 0] + set rel_type [lindex $referenced_activity 1] + switch $rel_type { + imsld_as_la_rel { + # if the activity doesn't have any completrion restriction + # and it hasn't been started, cancel the completion of the structure + set referenced_activity_id [content::item::get_live_revision -item_id $object_id_two] + set la_completion_restriction [db_string la_completion_restriction { + select complete_act_id + from imsld_learning_activities + where activity_id = :referenced_activity_id + }] + if { ([db_0or1row la_already_started_p { + select 1 + from imsld_status_user + where related_id = :referenced_activity_id + and user_id = :user_id + and run_id = :run_id + and status = 'started' + }] && [string eq "" $la_completion_restriction]) \ + || [db_0or1row la_already_finished { + select 1 + from imsld_status_user + where related_id = :referenced_activity_id + and user_id = :user_id + and run_id = :run_id + and status = 'finished' + }] } { + # the activity has been visited + incr total_completed + } else { + set mark_structure_finished_p 0 + break + } + } + imsld_as_sa_rel { + # if the activity doesn't have any completrion restriction + # and it hasn't been started, cancel the completion of the structure + set referenced_activity_id [content::item::get_live_revision -item_id $object_id_two] + if { ([db_0or1row la_already_started_p { + select 1 + from imsld_status_user + where related_id = :referenced_activity_id + and user_id = :user_id + and run_id = :run_id + and status = 'started' + }] && [string eq "" $sa_completion_restriction]) \ + || [db_0or1row la_already_finished { + select 1 + from imsld_status_user + where related_id = :referenced_activity_id + and user_id = :user_id + and run_id = :run_id + and status = 'finished' + }] } { + # the activity has been visited + incr total_completed + } else { + set mark_structure_finished_p 0 + break + } + } imsld_as_as_rel { + # if the referenced activity structure hasn't been finished, don't finish the activity structure + set structure_id [content::item::get_live_revision -item_id $object_id_two] + if { ![db_0or1row sa_already_finished_p { + select 1 + from imsld_status_user + where related_id = :referenced_activity_id + and user_id = :user_id + and run_id = :run_id + and status = 'finished' + }] } { + set mark_structure_finished_p 0 + break + } else { + incr total_completed + } + } + } + } + if { $mark_structure_finished_p || (![string eq $number_to_select ""] && ($total_completed >= $number_to_select)) } { + # mark the structure as finished + + set role_part_id_list [imsld::get_role_part_from_activity -activity_type structure -leaf_id $referencer_structure_item_id] + 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 $structure_id \ + -type structure \ + -user_id $user_id \ + -code_call + } + } + } +} + set supported_roles [db_list supported_roles_list { select iri.role_id from imsld_rolesi iri, acs_rels ar,