Top Kudoed for a role
I want to create a listing very similar to the Top Kudoed Authors list, except only for users with a specific role, and only with a kudo count from the past 30 days.
I know I can get the list of users with the role from /restapi/vc/roles/name/ROLE/users, and I can get a user kudo count with /restapi/vc/users/login/LOGIN/kudos/received/count, as well as their avatar and other settings for the display.
Not sure how to limit the kudo count to 30 days, but hoping there is a filter I can use?
Since there are multiple REST calls involved, my problem is collecting the data and then sorting it by most kudoed user first, as it seems that Freemarker in Lithium does not allow you to add key/value pairs of variables to a hash. Referencing SimpleHash gives an error.
Does anyone have an idea to do this? Is there an easier approach that I am missing?
(Or Lithium, could I have the source to the Top Kudoed Authors component so maybe I could just tweak that?)
Thanks.
Hi rwm ,
this is not a full answer to your question, but for
"it seems that Freemarker in Lithium does not allow you to add key/value pairs of variables to a hash.".....
you can creat a hash like
<#assign retHash = {} />
and add values to your hash like
<#assign retHash = retHash + { maxKey:maxValue} />
there is no direct sorting method in freemarker as I am aware. so I had implemented a selection sort (?) function which just scan the hash and find the biggest pair and put into another hash. here is the code if you are interested :)
<#function sortHashByValue inHash> <#assign retHash = {} /> <#list inHash?keys as outterKey> <#assign maxKey = "" /> <#assign maxValue = 0 /> <#list inHash?keys as curKey> <#assign currentValue = inHash[curKey]?number /> <#if !(retHash[curKey]?? ) > <#if (maxKey == "") || ( currentValue > maxValue ) > <#assign maxKey = curKey /> <#assign maxValue = currentValue /> </#if> </#if> </#list> <#if (maxKey != "") > <#assign retHash = retHash + { maxKey:maxValue} /> </#if> </#list> <#return retHash> </#function>
it sorts the hash based on the value.