Stats API Demo
<%
period = request.get("period")
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
if (period==null) {
period = cal.get(Calendar.YEAR) * 100 + (cal.get(Calendar.MONTH)+1)
}
jour = cal.get(Calendar.YEAR) * 10000 + (cal.get(Calendar.MONTH)+1) * 100 + (cal.get(Calendar.DAY_OF_MONTH)+1)
type = request.get("type")
if (type==null)
type = "view"
%>
Total
<%
sql = "select stats.name, stats.pageViews, stats.visits from DocumentStats as stats where stats.action = '${type}' and stats.name not like '%.%' and stats.period=${period} order by stats.pageViews desc"
result = xwiki.search(sql, 20, 0)
for (item in result) {
name = item
0?
nb = item
1?
visits = item
2?
if (name=="") {
println "* Total Pages: ${nb}"
println "* Total Visits: ${visits}"
}
else {
println "* Space ${name}: ${nb}"
}
}
%>
Pages
<%
sql = "select stats.name, stats.pageViews from DocumentStats as stats where stats.action = '${type}' and stats.name like '%.%' and stats.period=${period} order by stats.pageViews desc"
result = xwiki.search(sql, 20, 0)
for (item in result) {
name = item
0?
nb = item
1?
println "*
${name}?: ${nb}"
}
%>
Last user connected
<%
sql = "select stats.name, max(stats.endDate) from VisitStats as stats group by stats.name order by 2 desc";
result = xwiki.search(sql, 100, 0)
for (item in result) {
user = item
0?
userdate = item
1?
try {
userlink = xwiki.getUserName(user)
} catch(Exception e) {
userlink = user
}
println "* ${userlink}: ${userdate}"
}
%>