Index: openacs-4/packages/xowiki/tcl/xowiki-portlet-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/Attic/xowiki-portlet-procs.tcl,v diff -u -r1.28 -r1.29 --- openacs-4/packages/xowiki/tcl/xowiki-portlet-procs.tcl 17 Mar 2007 23:13:21 -0000 1.28 +++ openacs-4/packages/xowiki/tcl/xowiki-portlet-procs.tcl 21 Mar 2007 10:51:40 -0000 1.29 @@ -1154,3 +1154,214 @@ return $output } } + +namespace eval ::xowiki::portlet { + + Class create graph \ + -superclass ::xowiki::Portlet \ + -parameter {{__decoration plain}} + + graph instproc graphHTML {-edges -nodes -max_edges -cutoff -base {-attrib node_id}} { + + ::xowiki::Page requireJS "/resources/ajaxhelper/prototype/prototype.js" + ::xowiki::Page requireJS "/resources/xowiki/collab-graph.js" + ::xowiki::Page requireJS "/resources/ajaxhelper/yui/yahoo/yahoo.js" + ::xowiki::Page requireJS "/resources/ajaxhelper/yui/event/event.js" + + set nodesHTML "" + array set n $nodes + + foreach {node label} $nodes { + set link "$label" + append nodesHTML "
Collaboration Graph for [::xo::get_user_name $user_id] " + if {[array size i] < 1} { + append result "
No collaborations found
" + } else { + append result "(max. [set max_edges] edges)\n" + + foreach x [array names i] { + foreach {u1 c1} $i($x) { + foreach {u2 c2} $i($x) { + if {$u1 < $u2} { + set var collab($u1,$u2) + if {![info exists $var]} {set $var 0} + incr $var $c1 + incr $var $c2 + } + } + } + } + + set max 50 + foreach x [array names collab] { + if {$collab($x) > $max} {set max $collab($x)} + } + + set edges [list] + foreach x [array names collab] { + lappend edges [list $x $collab($x) [expr {$collab($x)*5.0/$max}]] + } + + append result [my graphHTML \ + -nodes [array get user] -edges $edges \ + -max_edges $max_edges -cutoff $cutoff \ + -base collab -attrib user_id] + } + + return $result + } + + + Class create activity-graph \ + -superclass ::xowiki::portlet::graph \ + -parameter {} + + activity-graph instproc render {} { + my initialize -parameter { + {-max_edges 70} + {-cutoff 0.1} + {-max_activities:integer 100} + } + my get_parameters + + set folder_id [$package_id folder_id] + + # there must be a better way to handle temporaray tables safely.... + catch {db_dml drop_temp_table {drop table XOWIKI_TEMP_TABLE }} + + db_dml get_n_most_revent_contributions { + create temporary table XOWIKI_TEMP_TABLE as + select i.item_id, revision_id, creation_user + from cr_revisions cr, cr_items i, acs_objects o + where cr.item_id = i.item_id and i.parent_id = :folder_id + and o.object_id = revision_id + order by revision_id desc limit :max_activities + } + + set total 0 + db_foreach get_activities { + select count(revision_id),item_id, creation_user + from XOWIKI_TEMP_TABLE + where creation_user is not null + group by item_id, creation_user + } { + lappend i($item_id) $creation_user $count + incr total $count + set user($creation_user) [::xo::get_user_name $creation_user] + } + + db_dml drop_temp_table {drop table XOWIKI_TEMP_TABLE } + + if {[array size i] == 0} { + append result "No activities found
" + } elseif {[array size user] == 1} { + set user_id [lindex [array names user] 0] + append result "Last $total activities were done by user " \ + "[::xo::get_user_name $user_id]." + } else { + append result "
Collaborations in last $total activities by [array size user] Users
" + + foreach x [array names i] { + foreach {u1 c1} $i($x) { + foreach {u2 c2} $i($x) { + if {$u1 < $u2} { + set var collab($u1,$u2) + if {![info exists $var]} {set $var 0} + incr $var $c1 + incr $var $c2 + } + } + } + } + + set max 0 + foreach x [array names collab] { + if {$collab($x) > $max} {set max $collab($x)} + } + + set edges [list] + foreach x [array names collab] { + lappend edges [list $x $collab($x) [expr {$collab($x)*5.0/$max}]] + } + + append result [my graphHTML \ + -nodes [array get user] -edges $edges \ + -max_edges $max_edges -cutoff $cutoff \ + -base collab -attrib user_id] + } + + return $result + } + + + +}