Back

Get Categories from Widget Selection- with And/Or selector

Description

This "buildCatQuery" will pull the categories from an array (typically passed by a widget).  Part of the widget also includes a field for And|Or to join the categories together.

Example: the widget configuration consists of a Audience and News Type categories.  Audience categories would be items such as Employee, Alumni, Students, College of X, etc.  NewsType would be items such as Announcement, Press Release, University News, Internal News, etc.  The Selectors are either AND or OR.

Use case:  one might need news items that are for the Employee OR Student Audience, AND Internal News.  This type of information might be used on digital signage or portal.

Code

##Setting Audience List
#buildCatQuery($audience $audienceSelectType)
#set($audienceList = $catlist)

##Setting News Type List
#buildCatQuery($newsType $newsSelectType)
#set($newsTypeList =a $catlist)

#Joining category queries
#set($jointList = "$audienceList $newsTypeList")

#Building full query
#set($query = "+structureName:NewsItem +(conhost:d8ee33f7-4846-4fcf-94a1-979a710e8a4b conhost:SYSTEM_HOST) $jointList")

##Running query and displaying content
#foreach($con in $dotcontent.pull($query,$displayCount,"NewsItem.publishDate"))
   <div class="newsItemWrapper" style="display:table;">
   #if($displayPublishDate == "1,")
      <div class="newsItemDate" style="display:table-cell;">$!date.format('MM/dd/yyyy', $con.publishDate)</div>
      <div class="newsItemHypen" style="display:table-cell;width:1em;">&nbsp;-&nbsp;</div>
   #end
   <div class="newsItemTitle" style="display:table-cell;"><a href="details.dot?newsid=$con.identifier">$con.headline</a></div>
   </div>
   <div style="clear:both;"></div>
#end


##Macro to build category section of a lucene query 
#macro(buildCatQuery $categoryVarible $selector)
   #set($catlist="")
   #set($loopCounter=0)
   #foreach($inode in $categoryVarible)
      #if($loopCounter == 0)
         #if($selector=="or")
            #set($catlist = "+(")
            #set($catlist = "$catlist"+"categories:$categories.getCategoryByInode($inode).getCategoryVelocityVarName()")
         #else
            ##Assumes AND
            #set($catlist = "+categories:$categories.getCategoryByInode($inode).getCategoryVelocityVarName()")
         #end
      #else
         #if($selector=="or")
            #set($catlist = "$catlist categories:$categories.getCategoryByInode($inode).getCategoryVelocityVarName()")
         #else
            ##Assumes AND
            #set($catlist = "$catlist +categories:$categories.getCategoryByInode($inode).getCategoryVelocityVarName()")
         #end    
      #end
      #set($loopCounter=$loopCounter+1)
   #end
   
   #if($selector=="or")
   #if($loopCounter>0)
      #set($catlist = "$catlist)")
   #end
   #end
   
   ##Returning $catlist
#end