@Wolfgang Fahl 希望我们可以修改 Lithium REST API =)!
不幸的是,情况并非如此,所以我们必须处理我们得到的东西,这可能会做这样的事情:
<#-- this variable we need to store unique author ids -->
<#assign authorids = [] />
<#-- I'd use API v2 here, think for such stuff it's more powerful than v1 -->
<#assign query = 'SELECT author FROM messages WHERE conversation.style = "blog" AND board.id = "audiofiles"'?url />
<#assign response = rest("2.0", "/search?q=" + query) />
<#-- the response object will contain a list of blog post authors,
we loop trough them to get uniqe ids of every user that has written
a blog post, we need them later -->
<#list response.data.items as author>
<#-- make sure each author just gets added once -->
<#if !authorids?seq_contains(author.id)>
<#assign authorids = authorids + [author.id] />
</#if>
</#list>
<#-- now we loop trough the unique author ids and ask for the amount of
blog posts they have written -->
<ul>
<#list authorids as id>
<#assign query = 'SELECT count(*) FROM messages WHERE author.id = id AND board.id = "audiofiles"'?url />
<#assign response = rest("2.0", "/search?q=" + query) />
<li>User with ID ${id} has written ${response.data.count} blog posts</li>
</#list>
</ul>
代码未经测试,所以不能 100% 确定它是否有效,但我希望我选择的方法在上面的代码中变得清晰......