resources.tcl

Displays statistics based on xowiki_last_visited

Location:
/packages/xotcl-request-monitor/www/resources.tcl
Author:
Gustaf Neumann

Related Files

[ hide source ] | [ make this the default ]

File Contents

ad_page_contract {
    Displays statistics based on xowiki_last_visited

    @param package_id Package id of the xowiki instance of the course to be displayed
    @param page_id Optional item_id of an xowiki page for filtering

    @author Gustaf Neumann
} -query {
    {package_id:naturalnum 75595941}
    {page_id:naturalnum ""}
    {user_id:naturalnum ""}
} -properties {
    title:onevalue
    context:onevalue
}

set title "Read Resources"
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
}

set dimensional {
    {
        package_id "Course:" 75595941 {
            {75595941     "BIS1 ws 2015"}
            {75611112     "Distributed Development"}
        }
    }
}
set dimensional_html [ad_dimensional $dimensional]

set filter_html ""
::xo::Package initialize -package_id $package_id
set package_url [$package_id package_url]

set filter_clause "user_id > -1"
if {$user_id ne ""} {
    append filter_clause " and user_id = :user_id"
    acs_user::get -user_id $user_id -array user_info
    set user_label "$user_info(first_names) $user_info(last_name)"
    set no_filter_url [export_vars -base resources [list package_id page_id]]
    append filter_html [subst {
        <li>Resources read by $user_info(first_names) $user_info(last_name)
        (stop <a href="[ns_quotehtml $no_filter_url]">filtering</a>)</li>
    }]
}
if {$page_id ne ""} {
    append filter_clause " and page_id = :page_id"
    ::xo::db::CrClass get_instance_from_db -item_id $page_id
    set page_label [$page_id pretty_link]

    set no_filter_url [export_vars -base resources [list package_id user_id]]
    append filter_html [subst {
        <li>Users Reading Resource $page_label
        (stop <a href="[ns_quotehtml $no_filter_url]">filtering</a>)</li>
    }]
}

if {1} {
    ##################################################################
    #
    # View Statistics
    #
    ##################################################################
    
    TableWidget create t1 \
        -columns {
            AnchorField user -label User
            AnchorField page -label "Page"
            AnchorField show -label "Show"
            Field last_access -label "Last Access"
            Field count -label "Count" -html {align right}
        }

    set items [::xo::db::Object instantiate_objects -sql [subst {
        select user_id, page_id, count, time
        from xowiki_last_visited
        where package_id = :package_id
        and   $filter_clause
        order by time desc
    }] -initialize false]

    foreach t [$items children] {
        set user_id [$t set user_id]
        set page_id [$t set page_id]
        
        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 resources [list user_id package_id]]
        set page_link [export_vars -base resources [list page_id package_id]]

        regexp {^([^.]+)[.]} [$t set time] _ time
        set nice_time [::xowiki::utility pretty_age -timestamp [clock scan $time]]
        
        set key path($page_id)
        if {![info exists $key]} {
            ::xo::db::CrClass get_instance_from_db -item_id $page_id
            set pretty_link [$page_id pretty_link]
            set $key $pretty_link
        } else {
            set pretty_link [set $key]
        }
        regsub "^$package_url" $pretty_link "" short_link
        
        t1 add \
            -user         $user_label \
            -page         $short_link \
            -page.href    $page_link \
            -show         show \
            -show.href    $pretty_link \
            -count        [$t set count] \
            -last_access  $nice_time

        if {$user_link ne ""} {
            [::template::t1 last_child] set user.href $user_link
        }
    }
}    

set t1 [t1 asHTML]


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