rwm
11 years agoAdvisor
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 ...
- 11 years ago
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.