frardouin
7 years agoGuide
Get kudoed messages by user
Hi everyone,
I'm trying to display all the messages kudoed by a user in his profile page. This is currently not working in my component. I think the problem come maybe from the last query in the listing but I can't figure what's wrong. This is what I have:
<#assign currentUserid = page.context.user???then(page.context.user.id, user.id) /> <#assign kudoedMessages = restadmin("2.0", "/search?q=" + ("SELECT message.id FROM kudos WHERE user.id = '${currentUserid}'")?url).data.items![] /> <#list kudoedMessages as kudoedMessage> <#assign kudoedMessage = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE id='${message.id}'"?url).data.items![] /> <p>${kudoedMessage.id}</p> </#list>
(Last quick question: Is it possible to "var_dump" variable in Freemarker? I have a hard time to get the property I need when in 2nd level query )
As 2nd APi also returning the array so we must put it in list also. Here is the corrected version.
<#assign currentUserid = page.context.user???then(page.context.user.id, user.id) /> <#assign kudoedMessages = restadmin("2.0", "/search?q=" + ("SELECT * FROM kudos WHERE user.id = '${currentUserid}'")?url).data.items![] /> <#list kudoedMessages as kudoedMessage> <#assign messages= rest("2.0","/search?q=" + "SELECT * FROM messages WHERE id='${kudoedMessage.message.id}'"?url).data.items![] /> <#list messages as message> <p>${message.id}</p> <p>${message.subject}</p> <p>${message.post_time?date}</p> <p>${message.author.login}</p> </#list> </#list>