irach15
8 years agoMaven
Accepted solutions via REST API V2 sorted by acceptance time
I'm trying to get the last 6-8 accepted solutions from a specific category via REST API V2 and sort them by acceptance time. Custom component aka build-in 'Accepted Solutions', showing post title, ...
- 8 years ago
irach15 -
You can achieve this without making any other call. You can sort the array using freemarker sort_by object, however, the array should be in a required format.
http://freemarker.apache.org/docs/ref_builtins_sequence.html#ref_builtin_sort_by
<#assign solutions = restadmin("2.0","/search?q=" + "SELECT solution_data, is_solution, post_time FROM messages WHERE is_solution = true AND category.id = '${catID}' ORDER BY post_time DESC LIMIT 6"?url) />
<#assign sortedMessagesList = [] />
<#list solutions.data.items as solution >
<#assign sortedMessagesList = sortedMessagesList + [{'solution_time': solution.solution_data.time , 'message':solution}] />
</#list>
ASCENDING
<#list sortedMessagesList?sort_by("solution_time") as solution >
<#assign solution_id = solution.message.solution_data.message_id />
<#assign solution_time = solution.message.solution_data.time />
<div class="item-content">
${solution_id} - ${solution_time}
</div>
</#list>
DESENCDING
<#list sortedMessagesList?sort_by("solution_time")?reverse as solution >
<#assign solution_id = solution.message.solution_data.message_id />
<#assign solution_time = solution.message.solution_data.time />
<div class="item-content">
${solution_id} - ${solution_time}
</div>
</#list>