Class ::xowiki::includelet::presence

::xowiki::includelet::presence[i] create ... \
           [ -__decoration (default "rightbox") ] \
           [ -parameter_declaration (default " {-interval "10 minutes"} {-max_users:integer 40} {-show_anonymous "summary"} {-page} ") ]

Show users actively in the wiki.
Documented Parameters:
interval
list users when active in the wiki in the specified interval (default: 10 minutes)
max_users
maximum number of users to list
show_anonymous
specify, whether users not logged in should get a result from this includelet. Possible values "nothing", "all", "summary"
page
restrict listing to changes on a certain page.
Defined in packages/xowiki/tcl/includelet-procs.tcl

Class Relations

  • class: ::xowiki::IncludeletClass[i]
  • superclass: ::xowiki::Includelet[i]
::xowiki::IncludeletClass create ::xowiki::includelet::presence \
     -superclass ::xowiki::Includelet

Methods (to be applied on instances)

  • __decoration (setter)

  • parameter_declaration (setter)

  • render (scripted)

    :get_parameters
    
    set summary 0
    if {[::xo::cc user_id] == 0} {
      switch -- $show_anonymous {
        nothing {return ""}
        all     {set summary 0}
        default {set summary 1}
      }
    }
    
    if {[info exists page] && $page eq "this"} {
      set extra_where_clause "and page_id = [${:__including_page} item_id] "
      set what " on page [${:__including_page} title]"
    } else {
      set extra_where_clause ""
      set what " in community [::$package_id instance_name]"
    }
    
    if {!$summary} {
      set select_users "user_id, to_char(max(time),'YYYY-MM-DD HH24:MI:SS') as max_time from xowiki_last_visited "
    }
    
    # allow for caching prepared value.
    set since [::xo::dc interval $interval]
    set since_condition "time > TO_TIMESTAMP(:since,'YYYY-MM-DD HH24:MI:SS')"
    
    set where_clause "package_id=:package_id and $since_condition $extra_where_clause"
    set when "<br>in last [ns_quotehtml $interval]"
    
    set output ""
    
    if {$summary} {
      set count [::xo::dc get_value presence_count_users  "select count(distinct user_id) from xowiki_last_visited WHERE $where_clause"]
    } else {
      set values [::xo::dc list_of_lists get_users  [::xo::dc select  -vars "user_id, to_char(max(time),'YYYY-MM-DD HH24:MI:SS') as max_time"  -from xowiki_last_visited  -where $where_clause  -groupby user_id  -orderby "max_time desc"  -limit $max_users ]]
      set count [llength $values]
      if {$count == $max_users} {
        # we have to check, whether there were more users...
        set count [::xo::dc get_value presence_count_users  "select count(distinct user_id) from xowiki_last_visited WHERE $where_clause"]
      }
      foreach value  $values {
        lassign $value user_id time
        set seen($user_id$time
    
        regexp {^([^.]+)[.]} $time _ time
        set pretty_time [util::age_pretty -timestamp_ansi $time  -sysdate_ansi [lc_clock_to_ansi [clock seconds]]  -mode_3_fmt "%d %b %Y, at %X"]
        set name [::xo::get_user_name $user_id]
    
        append output [subst {<tr><td class='user'>[ns_quotehtml $name]</td>
          <td class='timestamp'>&nbsp;-&nbsp;[ns_quotehtml $pretty_time]</td></tr>
        }]
      }
      if {$output ne ""} {set output "<table>$output</table>\n"}
    }
    set users [expr {$count == 0 ? "No registered users" :
                     $count == 1 ? "1 registered user" :
                     "$count registered users"}]
    return "<div class='title'>[ns_quotehtml $users$what]$when</div>$output"