[xwiki-devs] distict blog authors
Hello XWiki-Dev's I'm trying to figure out how to create a list blog authors but I want the authors to be listed only once so I'm trying to figure out how to create a "where" clause for searchDocument. I thought if I found all of the Documents with XWiki.ArticleClass as a BaseObject and then used distict I could create a list of Blog authors. One problem is that it looks like searchDocuments doesn't allow me to specify distinct. I'm unclear how to refer to doc.author in the query would that be: StringProperty as prop ? First Try #set ($sql = ", BaseObject as obj where doc.fullName = obj.name and obj.className = 'XWiki.ArticleClass'") #set ($start = 0) #set ($nb = 50) #set ($collect = $xwiki.searchDocuments($sql , $nb , $start)) Is there a better way to do this? Glenn Everitt -- View this message in context: http://www.nabble.com/distict-blog-authors-tp17367672p17367672.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
I found this: http://platform.xwiki.org/xwiki/bin/view/DevGuide/velocityHqlExamples#HPrivi... Getting documents where objects' properties equals some value #displayQuery(select doc.fullName from XWikiDocument doc, BaseObject obj, StringProperty prop where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers' and prop.id.id=obj.id and prop.name='first_name' and prop.value='Jean-Vincent' true) What is #displayQuery ? So I guessed and tried this: #set ($sql = "select doc.author from XWikiDocument doc, BaseObject obj, StringProperty prop where doc.author=obj.name and obj.className='XWiki.ArticleClass' and prop.id.id=obj.id and prop.name='author' and prop.value='XWiki.GEVERITT'") <p>$sql</p> #set($results =$xwiki.search($sql, 30, 0)) #set($arrayresults = $results.toArray()) #foreach($res in $results) <p>$res</p> #end but I don't understand how to specify the name of author - Help. -- View this message in context: http://www.nabble.com/distict-blog-authors-tp17367672p17372634.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
On Wed, May 21, 2008 at 10:30 PM, Glenn Everitt <Glenn.Everitt@compuware.com> wrote:
I found this: http://platform.xwiki.org/xwiki/bin/view/DevGuide/velocityHqlExamples#HPrivi...
Getting documents where objects' properties equals some value
#displayQuery(select doc.fullName from XWikiDocument doc, BaseObject obj, StringProperty prop where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers' and prop.id.id=obj.id and prop.name='first_name' and prop.value='Jean-Vincent' true)
What is #displayQuery ? So I guessed and tried this:
Just a simple macro that displays the query and results from a given query (meant to be used when documenting hql queries).
#set ($sql = "select doc.author from XWikiDocument doc, BaseObject obj, StringProperty prop where doc.author=obj.name and obj.className='XWiki.ArticleClass' and prop.id.id=obj.id and prop.name='author' and prop.value='XWiki.GEVERITT'") <p>$sql</p> #set($results =$xwiki.search($sql, 30, 0)) #set($arrayresults = $results.toArray())
#foreach($res in $results) <p>$res</p> #end
but I don't understand how to specify the name of author - Help.
A snippt to achieve this : #foreach($res in $xwiki.search("select distinct doc.creator from XWikiDocument doc, BaseObject obj where doc.fullName=obj.name and obj.className='XWiki.ArticleClass'", 0, 0)) * $res #end -- Jean-Vincent Drean
Thanks this is a giant help. I'm struggling to understand the connection between hibernate objects and XWiki objects. For example when I wanted to restrict the documents to a particular "space" I thought I should code "and doc.space = '$space'" but I needed to code "and doc.web = '$space'" but I kind of guessed this because the hibernate created the XWIKIDOC table with a XWD_WEB column. So, I thought there should be java classes that exposed methods hibernate would call to serialize objects to database but I'm not sure where to look for these. Thanks again for the help here is the script to list the unique set of Blog Authors within a single space. #set ($space = "some_space") #set ($start = 0) #set ($nb = 50) #set ($sql = "select distinct doc.creator from XWikiDocument doc, BaseObject obj where doc.fullName = obj.name and doc.web = '$space' and obj.className = 'XWiki.ArticleClass'") #set ($collect = $xwiki.search($sql , $nb , $start)) #foreach ($item in $collect) #if ($xwiki.hasAccessLevel("view", "${context.database}:${item}")) #set($bentrydoc = $xwiki.getDocument($item)) #set($pos =$bentrydoc.creator.indexOf(".")+1) #set($blogauthor = $bentrydoc.creator) #set($realName = $xwiki.getLocalUserName($blogauthor, false)) * $realName \\ #end #end -- View this message in context: http://www.nabble.com/distict-blog-authors-tp17367672p17405328.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
participants (2)
-
Glenn Everitt -
Jean-Vincent Drean