
<scaffold>
	<label>sort by datetime last update</label>
	<description>Lists the latest Objects according to datetimelastupdated</description>
	<package>/packages/rules</package>
	<filename>rule[TYPENAME]Latest.cfc</filename>
</scaffold>

<!--- 
|| LEGAL ||
$Copyright: $

|| DESCRIPTION || 
$Description: 
Lists the latest Objects according to datetimelastupdated
$

|| DEVELOPER ||
$Developer: DEVELOPER NAME  $

--->

<cfcomponent displayname="Lists latest objects ([TYPENAME])" extends="farcry.core.packages.rules.rules" hint="Creates a List Table for the latest objects from ([TYPENAME]).">

	<cfproperty ftSeq="1" ftFieldset="General" name="intro" type="longchar" hint="Introduction Text." required="false" default="" ftType="RichText" ftLabel="Introduction Text">
	<cfproperty ftSeq="2" ftFieldset="General" name="suffix" type="longchar" hint="Suffix Text." required="false" default="" ftType="RichText" ftLabel="Suffix Text">	
	<cfproperty ftSeq="3" ftFieldset="General" name="numItems" type="numeric" hint="The number of items to display." required="false" default="5" ftType="numeric" ftLabel="Number of Items" ftIncludeDecimal="false">
	<cfproperty ftSeq="4" ftFieldset="General" name="webskin" type="string" hint="Teaser display method to render links." required="false" default="displayTeaser" ftLabel="Display Type" ftType="webSkin" ftTypename="[TYPENAME]" ftPrefix="displayTeaser" />
	<cfproperty ftSeq="5" ftFieldset="General" name="listType" type="string" hint="should the result be a list?" required="false" default="none" ftLabel="List Type" ftType="list" ftList="none:Not in list,unordered:Unordered List,ordered:Ordered List" />
	
	<cfproperty ftSeq="6" ftFieldset="Categorisation" name="Category" type="longchar" hint="Limit by Category" required="false" default="0" ftLabel="Limit by Category" ftType="category"  />
	
	<cfproperty ftSeq="7" ftFieldset="Pagination" name="bPaginate" type="boolean" hint="Should we include pagination?" required="false" default="0" ftLabel="Include Pagination?" ftType="boolean"  />
	<cfproperty ftSeq="8" ftFieldset="Pagination" name="itemsPerPage" type="numeric" hint="how many items per page?" required="false" default="10" ftLabel="Number of items per page?" ftType="numeric" ftIncludeDecimal="false"  />
	<cfproperty ftSeq="9" ftFieldset="Pagination" name="pageLinksShown" type="numeric" hint="How many page links?" required="false" default="5" ftLabel="Number of page links" ftType="numeric" ftIncludeDecimal="false"  />
	

	<cffunction access="public" name="execute" output="true">
		<cfargument name="objectID" required="Yes" type="uuid" default="">
		<cfargument name="dsn" required="false" type="string" default="#application.dsn#">
		
		<cfset var stObj = this.getData(arguments.objectid) />
		<cfset var o = createObject("component",application.types['[TYPENAME]'].typepath)>
		<cfset var qRecordSet = queryNew("objectID") />
		<cfset var lCategoryObjectIDs = "" />
		<cfset var qObjectsMatchingCategories = queryNew("objectID") />
		
		
		<cfif listLen(stObj.Category)>
			<cfset qObjectsMatchingCategories = createObject("component","farcry.core.packages.farcry.category").getData(typename="[TYPENAME]", lCategoryids=stobj.Category) />
			<cfset lCategoryObjectIDs = valueList(qObjectsMatchingCategories.objectid) />
		</cfif>		
		
		<cfset qRecordSet = o.getMultipleByQuery(maxRows=stObj.numItems, OrderBy="title", sortOrder="desc", lObjectIDs="#lCategoryObjectIDs#") />
		
		
		
		
		<!--- IS THERE INTRO TEXT SET? --->
		<cfif len(stObj.intro)>		
			<cfset arrayAppend(request.aInvocations,stObj.intro) />			
		</cfif>
		
		
		<!--- ARE THE OBJECTS SUPPOSED TO BE PLACED IN A LIST --->
		<cfif stObj.listType EQ "unordered">
			<cfset arrayAppend(request.aInvocations,"<ul>") />
		</cfif>
		<cfif stObj.listType EQ "ordered">
			<cfset arrayAppend(request.aInvocations,"<ol>") />
		</cfif>
		
		<cfloop query="qRecordSet">
			<cfset stInvoke = structNew() />
			<cfset stInvoke.objectID = qRecordSet.ObjectID />
			<cfset stInvoke.typename = application.types["[TYPENAME]"].typePath />
			<cfset stInvoke.method = stObj.webskin />
			
			<!--- ARE THE OBJECTS SUPPOSED TO BE PLACED IN A LIST (ordered or unordered) --->
			<cfif stObj.listType EQ "unordered" OR stObj.listType EQ "ordered">
				<cfset stInvoke.preHTML = "<li>" />
				<cfset stInvoke.postHTML = "</li>" />
			</cfif>
			
			<cfset arrayAppend(request.aInvocations,stInvoke) />
		</cfloop>


		<!--- CLOSE THE LIST IF REQUIRED --->
		<cfif stObj.listType EQ "unordered">
			<cfset arrayAppend(request.aInvocations,"</ul>") />
		</cfif>
		<cfif stObj.listType EQ "ordered">
			<cfset arrayAppend(request.aInvocations,"</ol>") />
		</cfif>



		<!--- IS THERE SUFFIX TEXT SET? --->
		<cfif len(stObj.suffix)>		
			<cfset arrayAppend(request.aInvocations,stObj.suffix) />			
		</cfif>
		
		
	</cffunction>

</cfcomponent>
