We recently added a few api enhancements for programatically working with content in Mura. With the new content iterators and new improved bean methods we were able to make managing content and users simpler.
We recently added a few api enhancements for programatically working with content in Mura. With the new content iterators and new improved bean methods we were able to make managing content and users simpler. Here are some examples:
<!--- Read out an existing node from the default site.---> <cfset content=application.contentManager.getActiveContentByFilename('blog','default')> <!--- Pull out a content iterator of the nodes child content.---> <cfset it=content.getKidsIterator()> <!--- The number of Items to be listed is determined by the content.getNextN() value. It's default is 10. ---> <cfset it.setPage(1)> <!--- You can also set the start row instead of setting a page number. ---> <cfset it.setStartRow(1)><cfloop from="1" to="#it.pageCount()#" index="p"> <cfset it.setPage(p)><cfoutput><h2>Page #p#</h2></cfoutput> <!--- Iterate throught the child content. The it.hasNext() will return true until the page length as determined by the content.getNextN() has been reached ---> <cfloop condition="it.hasNext()"> <!--- The it.next() method returns a new contentNavBean. It acts as a facade to data into the wrapped query while digging into the full bean when needed. ---> <cfset sub1=it.next()> <cfoutput> #it.currentIndex()#:#sub1.getMenuTitle()#</br> </cfoutput> </cfloop> </cfloop>
You can also get the same iterator from local content indexes:
<!--- Pull a index by it's name with the newfeedManager.readByName() method. This example is pulling alocal index named "documents" from the default site.---><cfset feed=application.feedManager.readByName('documents','default')><cfset it=feed.getIterator()><h2><cfoutput>#feed.getName()#</cfoutput></h2><cfif it.recordCount()><!--- Iterate throught the child content ---><cfloop condition="it.hasNext()"><cfset subContent=it.next()><cfoutput>#it.currentIndex()#: #subContent.getMenutitle()#</br></cfoutput></cfloop></cfif>
You can also wrap any existing query that contains contentID and siteID or contentHistID and siteID and start iterating.
<cfquery name="rsExample">select content,siteID from tcontent where .....</cfquery><cfset it=application.serviceFactory.getBean("contentIterator")><cfset it.setQuery(rsExample)/><!--- Now Iterate and pull attributes that aren't in the query ---><cfloop condition="it.hasNext()"><cfset content=it.next()><cfoutput>#it.currentIndex()#: #content.getMenutitle()# - #content.getCustomVar()#</br></cfoutput>
<cfset it=application.serviceFactory.getBean("contentIterator")><cfset it.BuildQueryFromList("423AC11B-3DB8-49EF-B411A2FB008CAB1E,423AC11B-3DB8-49EF-B411A2FB008CABAS","default")><!--- Now Iterate ---><cfloop condition="it.hasNext()"><cfset content=it.next()><cfoutput>#it.currentIndex()#: #content.getMenutitle()# - #content.getCustomVar()#</br></cfoutput>
Many beans in Mura now have direct methods for saving and deleting content instead of having to always submitting to it's appropriate service manager.
contentBean.save()contentBean.delete()contentBean.deleteVersion()contentBean.deleteVersionHistory()contentBean.getKidsQuery()contentBean.getKidsIterator()contentBean.getRelatedContentQuery()contentBean.getRelatedContentIterator()contentBean.getVersionHistoryQuery()contentBean.getVersionHistoryIterator()contentBean.getCategoriesQuery()
userBean.save()userBean.delete()<!--- Get members[returnType] returns usersthat belong to this use.For example if this user.getType() equas 1then it is a group and it would return it's members--->userBean.getMembersQuery()userBean.getMembersIterator()<!--- getMemberships[returnType] returns groups towhich this user belongs --->userBean.getMembershipsQuery()userBean.getMembershipsIterator()userBean.getAddressesQuery()userBean.getAddressesIterator()addressBean.save()addressBean.delete()
feedBean.save()feedBean.delete()feedBean.getQuery()feedBean.getIterator()