Index: openacs-4/packages/lorsm/www/delivery/menu-mk.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/lorsm/www/delivery/menu-mk.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/lorsm/www/delivery/menu-mk.tcl 7 Jun 2006 14:05:44 -0000 1.2
+++ openacs-4/packages/lorsm/www/delivery/menu-mk.tcl 13 Aug 2007 09:20:16 -0000 1.3
@@ -1,4 +1,4 @@
-# packages/lorsm/www/delivery/index.tcl
+# packages/lorsm/www/delivery/menu-mk.tcl
ad_page_contract {
@@ -11,48 +11,76 @@
} {
man_id:integer,notnull
ims_id:integer,notnull,optional
- track_id:integer,notnull
+ menu_off:integer,notnull,optional
+ track_id:integer,notnull,optional
} -properties {
} -validate {
} -errors {
}
+if { ![info exists track_id] } {
+ set track_id 0 }
+if { ![info exists menu_off] } {
+ set menu_off 0 }
+
+set debuglevel [ad_get_client_property lorsm debuglevel]
+set deliverymethod [ad_get_client_property lorsm deliverymethod]
+
+if { [string equal $deliverymethod "delivery-scorm"] } {
+ set rte true
+} else {
+ set rte false
+}
+
+
set items_list [list]
set control_list [list]
+set target "content"
-set org_id [db_string get_org_id { select org_id from ims_cp_organizations where man_id = :man_id} ]
-# We need all the count of all items (just live revisions)
-set items_count [db_string get_items_count { select count(ims_item_id)
- from ims_cp_items where ims_item_id in ( select live_revision
- from cr_items where content_type = 'ims_item_object') and
- org_id = :org_id
-}]
+#set org_id [db_string get_org_id { select org_id from ims_cp_organizations where man_id = :man_id} ]
-# Get the root items
-set count 0
-db_foreach get_root_item { select ims_item_id from ims_cp_items where parent_item = :org_id and org_id = :org_id } {
- lappend items_list [list $ims_item_id 1]
- lappend control_list $ims_item_id
- incr count
-}
-template::multirow create tree_items link label indent last_indent target
-
-while { $count < $items_count } {
- foreach item $items_list {
- set item_id [lindex $item 0]
- set indent [expr [lindex $item 1] + 1]
- db_foreach get_items { select ims_item_id from ims_cp_items where parent_item = :item_id and org_id = :org_id } {
- if { [string equal [lsearch -exact $control_list $ims_item_id] "-1"] } {
- lappend items_list [list $ims_item_id $indent]
- lappend control_list $ims_item_id
- incr count
- }
+#we handle multiple orgs
+foreach org_id [db_list get_org_id { } ] {
+ set count 0
+ lappend items_list [list $org_id 0]
+ foreach item [lorsm::get_items_indent -org_id $org_id] {
+ #we shift everything to the right to get the orgs inserted there
+ set indent [expr [lindex $item 1] +1 ]
+ set item_id [lindex $item 0]
+ set item [list $item_id $indent]
+ lappend items_list $item
}
- }
+ # We need all the count of all items (just live revisions)
+ set items_count [db_string get_items_count { select count(ims_item_id)
+ from ims_cp_items where ims_item_id in ( select live_revision
+ from cr_items where content_type = 'ims_item_object') and
+ org_id = :org_id
+ }]
+ # Get the root items
+ db_foreach get_root_item { select ims_item_id from ims_cp_items where parent_item = :org_id and org_id = :org_id } {
+ #lappend items_list [list $ims_item_id 1]
+ #lappend control_list $ims_item_id
+ incr count
+ }
+ while { $count < $items_count } {
+ foreach item $items_list {
+ set item_id [lindex $item 0]
+ set indent [expr [lindex $item 1] + 1]
+ db_foreach get_items { select ims_item_id from ims_cp_items where parent_item = :item_id and org_id = :org_id } {
+ if { [string equal [lsearch -exact $control_list $ims_item_id] "-1"] } {
+ #this duplicates ITEMS lappend items_list [list $ims_item_id $indent]
+ #lappend control_list $ims_item_id
+ incr count
+ }
+ }
+ }
+ }
}
+template::multirow create tree_items icon link label indent last_indent target
+
set community_id [dotlrn_community::get_community_id]
set counter 1
set user_id [ad_conn user_id]
@@ -97,15 +125,15 @@
# Another item in the same level, just add to the list
lappend TREE_HASH "TREE_HASH\[\"ims_id.$item_id\"\] = $counter;"
lappend levelitems "\['$title', $url\]"
- template::multirow append tree_items $url $title $level
+ template::multirow append tree_items "SAMELEVEL" $url $title $level
incr counter
} elseif { $level < $nextlevel } {
# Next item is a sub-item
set ocounter $counter
incr counter
set submenu "[generate_tree_menu $items $index [expr $rlevel + 1]]"
lappend TREE_HASH "TREE_HASH\[\"ims_id.$item_id\"\] = $ocounter;"
- template::multirow append tree_items $url $title $level
+ template::multirow append tree_items "NEXTLEVEL" $url $title $level
if { [llength $submenu] } {
# There's a submenu
lappend levelitems \
@@ -143,7 +171,7 @@
return [list]
} else {
lappend TREE_HASH "TREE_HASH\[\"ims_id.$item_id\"\] = $counter;"
- template::multirow append tree_items $url $title $level
+ template::multirow append tree_items "LEAF" $url $title $level
incr counter
return [join \
[lappend levelitems \
@@ -187,31 +215,32 @@
order by
org_id
} {
-
+ #trying to visualize organizations
+ lappend js [list 0 $org_id $org_title $man_id "ims/organization" ""]
+
db_foreach sql {
- SELECT
- -- (tree_level(ci.tree_sortkey) - :indent) as indent,
- i.parent_item,
- i.ims_item_id,
- i.item_title as item_title,
- cr.mime_type
- FROM
- acs_objects o, ims_cp_items i, cr_items ci, cr_revisions cr,
- ims_cp_items_map im
- WHERE
- o.object_type = 'ims_item_object'
- AND
- i.org_id = :org_id
- AND
- o.object_id = i.ims_item_id
- AND
- i.ims_item_id = im.ims_item_id
- and im.man_id=:man_id
- and im.org_id=:org_id
- and im.hide_p='f'
- and im.community_id=:community_id
- and ci.item_id=cr.item_id
- and cr.revision_id=i.ims_item_id
+ SELECT
+ -- (tree_level(ci.tree_sortkey) - :indent ) as indent,
+ i.parent_item,
+ i.ims_item_id,
+ i.item_title as item_title,
+ i.prerequisites_s as prerequisites,
+ cr.mime_type
+ FROM
+ acs_objects o, ims_cp_items i, cr_items ci, cr_revisions cr,
+ ims_cp_manifest_class im
+ WHERE
+ o.object_type = 'ims_item_object'
+ AND
+ i.org_id = :org_id
+ AND
+ o.object_id = i.ims_item_id
+ AND
+ im.man_id=:man_id
+ and im.isenabled='t'
+ and im.community_id=:community_id
+ and ci.item_id=cr.item_id
+ and cr.revision_id=i.ims_item_id
AND
EXISTS
@@ -228,7 +257,7 @@
set item_id [lindex $item 0]
set indent [lindex $item 1]
if { [string equal $item_id $ims_item_id] } {
- lappend js [list $indent $ims_item_id $item_title $man_id $mime_type]
+ lappend js [list $indent $ims_item_id $item_title $man_id $mime_type $prerequisites]
}
}
}
@@ -237,11 +266,187 @@
if { [info exists js] } {
set last_indent 1
foreach l $js {
- foreach {indent item_id title man_id mime_type} $l {break}
- template::multirow append tree_items [export_vars -base "record-view" \
- -url {item_id man_id}] "$title $mime_type" $indent $last_indent
+ foreach {indent item_id title man_id mime_type prerequisites} $l {break}
+
+ #analyzing LESSON STATUS for the ITEM
+ #this could as well become a lorsm:scorm:function
+
+ ns_log debug "MENU-MK tree : $indent $item_id $title "
+
+ if { ! [string equal $mime_type "ims/organization"] } {
+
+ if { [ db_0or1row isnotanemptyitem "select res_id
+ from ims_cp_items_to_resources
+ where ims_item_id= $item_id
+ limit 1" ] } {
+ set icon ""
+ } else {
+ #since the item has no elements it's a placeholder, we assume it's a folder.
+ #time will tell if the assumption is correct.
+ set icon ""
+ }
+
+ if { ! [ db_0or1row isanysuspendedsession "select lorsm.track_id as track_id,
+ cmi.lesson_status as lesson_status from
+ lorsm_student_track lorsm, lorsm_cmi_core cmi
+ where
+ lorsm.user_id = $user_id
+ and
+ lorsm.community_id = $community_id
+ and
+ lorsm.course_id = $man_id
+ and
+ lorsm.track_id = cmi.track_id
+ and
+ cmi.man_id = $man_id
+ and
+ cmi.item_id = $item_id
+ order by
+ lorsm.track_id desc
+ limit 1" ] } {
+ #item has no track for the user
+ #the icon should be the same as per "not yet visited"
+ append icon ""
+ } else {
+ switch -regexp $lesson_status {
+ null { append icon "" }
+ incomplete { append icon "" }
+ complete { append icon "" }
+ failed { append icon "" }
+ "not attempted" { append icon "" }
+ passed { append icon "" }
+ default { append icon " $lesson_status ** "}
+ }
+ }
+
+
+ #we analize now prerequisites.
+
+ #regsub -all {&} $prerequisites " " prerequisites
+ regsub -all {[\{\}]} $prerequisites "" prerequisites
+ regsub -all { & } $prerequisites " " prerequisites
+ set prerequisites_list [split $prerequisites]
+
+ foreach prer $prerequisites_list {
+ if { ! [empty_string_p $prer] } {
+ ns_log debug "MENU prerequisites for $item_id are $prer "
+ #in the following query we disregard the organization
+ if { ! [ db_0or1row givemeid "select i.ims_item_id as id_from_ref
+ from
+ ims_cp_items i,
+ ims_cp_manifest_class im,
+ ims_cp_organizations o
+ WHERE
+ i.identifier=:prer
+
+ AND
+ o.org_id = i.org_id
+ AND
+ o.man_id = :man_id
+ AND
+ im.man_id= :man_id
+ AND
+ im.isenabled='t'
+ AND
+ im.community_id=:community_id"
+ ] } {
+ ns_log warning "MENU-MK: prerequisites not found comm: $community_id, man: $man_id, org: $org_id, item: $item_id"
+ continue
+ } else {
+ ns_log debug "THE REQUIRED ITEM IS $id_from_ref ";
+ }
+ }
+ if { ! [empty_string_p $id_from_ref] } {
+ ns_log debug "MENU prerequisites for $item_id are $id_from_ref"
+ if { ! [ db_0or1row isanysuspendedsession "
+ select lorsm.track_id as track_id, cmi.lesson_status as lex_status
+ from lorsm_student_track lorsm, lorsm_cmi_core cmi
+ where
+ lorsm.user_id = $user_id
+ and
+ lorsm.community_id = $community_id
+ and
+ lorsm.course_id = $man_id
+ and
+ lorsm.track_id = cmi.track_id
+ and
+ cmi.man_id = $man_id
+ and
+ cmi.item_id = $id_from_ref
+ order by
+ lorsm.track_id desc
+ " ] } {
+ ns_log debug "NOT FOUND TRACK"
+ append icon ""
+ } else {
+ ns_log debug "ITEM ID $id_from_ref HAS A TRACK WITH $lex_status"
+ switch -regexp $lex_status {
+ null { append icon "" }
+ incomplete { append icon "" }
+ failed { append icon "" }
+ "not attempted" { append icon "" }
+ passed { append icon "" }
+ complete { append icon "" }
+ default { append icon " $lesson_status ** "}
+ }
+ }
+ #if found session for id_from_ref
+ }
+ #if found id_from_ref
+ }
+ #foreach close
+
+ template::multirow append tree_items $icon [export_vars -base "record-view" \
+ -url {item_id man_id}] "$title $mime_type" $indent $last_indent $target
set last_indent $indent
+
+ } else {
+
+ regsub -all {[\{\}]} $title "" title
+
+ set icon ""
+
+ if { ! [ db_0or1row isanysuspendedsession "
+ select lorsm.track_id as track_id, cmi.lesson_status as lesson_status
+ from lorsm_student_track lorsm, lorsm_cmi_core cmi
+ where
+ lorsm.user_id = $user_id
+ and
+ lorsm.community_id = $community_id
+ and
+ lorsm.course_id = $man_id
+ and
+ lorsm.track_id = cmi.track_id
+ and
+ cmi.man_id = $man_id
+ and
+ cmi.item_id = $item_id
+ order by
+ lorsm.track_id desc
+ " ] } {
+ ns_log debug "Menu-mk: no org tracking found"
+
+ append icon ""
+ } else {
+ switch -regexp $lesson_status {
+ null { append icon "" }
+ incomplete { append icon "" }
+ complete { append icon "" }
+ failed { append icon "" }
+ "not attempted" { append icon "" }
+ passed { append icon "" }
+ default { append icon " $lesson_status ** "}
+ }
+ }
+
+ set last_indent $indent
+ template::multirow append tree_items $icon "" $title $indent $last_indent ""
+
+ set last_indent $indent
+
+ }
}
}
# return_url
set return_url [dotlrn_community::get_community_url [dotlrn_community::get_community_id]]
+