learning-activity-summary.tcl

Displays Learing Activity Summary Statistics based on workflow instances in the hidden global instance of the tlf-lrn package.

Location:
/packages/xotcl-request-monitor/www/learning-activity-summary.tcl
Author:
Gustaf Neumann

Related Files

[ hide source ] | [ make this the default ]

File Contents

ad_page_contract {

    Displays Learing Activity Summary Statistics based on workflow instances
    in the hidden global instance of the tlf-lrn package.

    @param package_id Package id of the xowiki instance of the course to be displayed
    @param page_id Optional id of a activity form for filtering
    
    @author Gustaf Neumann 

} -query {
    {package_id:naturalnum 75595941}
    {page_id:naturalnum    ""}
    {user_id:naturalnum    ""}
    {kind:naturalnum       0}
    {interval:naturalnum   7}
    {limit:naturalnum     10}
} -properties {
    title:onevalue
    context:onevalue
}

set title "Learning Activities Summary"
set context [list $title]

set swa [acs_user::site_wide_admin_p]
if {!$swa} {
    ad_return_forbidden "Permission Denied" \
        "<blockquote><p>You don't have permissions to view this page</blockquote>"
    ad_script_abort
}
array set course_labels {
    75595941     "BIS1 WS/2015"
    75611112     "Distributed Development"
}
# Course_label might provide a link
set course_label [ns_quotehtml $course_labels($package_id)]

set dimensional [subst {
    {
        package_id "Course:" 75595941 {
            {75595941     "$course_labels(75595941)"}
            {75611112     "$course_labels(75611112)"}
        }
    } {
        kind "Kind:" 0 {
            {0     "Students"}
            {1     "Activities"}
        }
    } {
        interval "Interval:" 7 {
            {1     "Last Day"}
            {7     "Last Week"}
            {0     "All"}
        }
    } {
        limit "Limit:" 10 {
            {10    "10"}
            {100  "100"}
            {300  "300"}
            {500  "500"}
            {1000  "1000"}
        }
    }
}]
set dimensional_html [ad_dimensional $dimensional]

set filter_html ""
set filter_clause true

if {$interval ne "0"} {
    append filter_clause " and ic.last_modified > now() - interval '$interval days'"
}

set categories ""
set counts ""

switch $kind {
    0 {
        ##################################################################
        #
        # Students
        #
        ##################################################################
    
        set sql {
            With RECURSIVE items AS (
                                     select ic.*,o.last_modified
                                     from xowiki_form_instance_item_index ic, cr_items cp, acs_objects o
                                     where cp.name = :package_id and ic.parent_id = cp.item_id
                                     and o.object_id = ic.item_id
                                     UNION ALL
                                     select ic.*, o.last_modified
                                     from xowiki_form_instance_item_index ic, acs_objects o, items
                                     where items.item_id = ic.parent_id
                                     and o.object_id = ic.item_id
                                     )
            select
               count(ic.hkey->'form_id'),
               ic.hkey->'creator_id' as creator_id
            from items ic
            where $filter_clause
            group by creator_id
            order by count desc
            limit $limit
        }
    
        set items [::xo::db::Object instantiate_objects -sql [subst $sql] -initialize false]
        foreach t [$items children] {
            set user_id [$t set creator_id]
            set count [$t set count]
            
            acs_user::get -user_id $user_id -array user_info
            set user_label "$user_info(first_names) $user_info(last_name)"
            set user_link [export_vars -base learning-activity [list user_id package_id]]

            lappend categories '$user_label'
            lappend counts [subst {{y: $count, url: "$user_link"}}]
        }
        set count_label "Activities"
        set chart_title "Students working on Learning Activities"
    }
    1 {
        ##################################################################
        #
        # Activities
        #
        ##################################################################
    
        set sql {
            With RECURSIVE items AS (
                                     select ic.*,o.last_modified
                                     from xowiki_form_instance_item_index ic, cr_items cp, acs_objects o
                                     where cp.name = :package_id and ic.parent_id = cp.item_id
                                     and o.object_id = ic.item_id
                                     UNION ALL
                                     select ic.*, o.last_modified
                                     from xowiki_form_instance_item_index ic, acs_objects o, items
                                     where items.item_id = ic.parent_id
                                     and o.object_id = ic.item_id
                                     )
            select
               ic.hkey->'form_id' as activity_id,
               count(ic.hkey->'creator_id')
            from items ic
            where $filter_clause
            group by activity_id
            having count(ic.hkey->'creator_id') > 0
            order by count desc
            limit $limit
        }

        set items [::xo::db::Object instantiate_objects -sql [subst $sql] -initialize false]
        foreach t [$items children] {
            set activity_id [$t set activity_id]
            set count [$t set count]

            ::xo::db::CrClass get_instance_from_db -item_id $activity_id
            set activity_label [$activity_id title]
            set activity_link [export_vars -base learning-activity \
                                   [list [list page_id $activity_id] package_id]]
            lappend categories '$activity_label'
            lappend counts [subst {{y: $count, url: "$activity_link"}}]
        }
        set count_label "Students"
        set chart_title "Learning Activities used by Students"
    }    
}    

set nr_entries [llength [$items children]]
if {$nr_entries < 20} {
    set chart_height [expr {100 + $nr_entries * 30}]
} else {
    set chart_height [expr {100 + $nr_entries * 16}]
}
set counts_js     [join $counts ,]
set categories_js [join $categories ,]


# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: