This is an example of an execute function for a custom rule that is used for a custom type. This sorts the itesm by category. Now, here’s what’s really cool…
<cfset staffCategories = "#application.factory.oTree.getDescendants(application.factory.oCategory.getCategoryIDByName('Staff'))#">
This line gets all sub categories under Staff. This is used for the sorting. If the user wants to control the order of the categories in the sort, he/she need only move the sub category up or down in the list through the Keyword Manager tool in the webtop.
Here’s the full code:
<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 i = 1>
<cfset var stObj = this.getData(arguments.objectid)>
<cfset var qGetStaff = ''>
<cfparam name="request.mode.lValidStatus" default="approved">
<cfset staffCategories = "#application.factory.oTree.getDescendants(application.factory.oCategory.getCategoryIDByName('Staff'))#">
<cfset staffCategoriesList = ValueList(staffCategories.objectid)>
<!--- doesn't need to match all categories --->
<cfquery datasource="#arguments.dsn#" name="qGetStaff">
SELECT type.*, cat.categoryID, img.imagefile, img.thumbnail, img.alt
FROM refObjects refObj
JOIN refCategories refCat ON refObj.objectID = refCat.objectID
JOIN dmStaff type ON refObj.objectID = type.objectID
JOIN dmImage img ON img.objectID = type.teaserImage
JOIN categories cat ON cat.categoryID = refCat.categoryID
WHERE refObj.typename = 'dmStaff'
AND type.status IN ('#ListChangeDelims(request.mode.lValidStatus,"','",",")#')
</cfquery>
<cfoutput>
<h1>#stObj.intro#</h1>
<!--- get staff members by category --->
<cfloop from="1" to="#ListLen(staffCategoriesList)#" step="1" index="i">
<cfquery name="QoQ" dbtype="query">
SELECT *
FROM qGetStaff
WHERE categoryID = '#ListGetAt(staffCAtegoriesList, i)#'
ORDER BY displayOrder
</cfquery>
<!--- get category name --->
<cfset categoryName = application.factory.oCategory.getCategoryNameById(ListGetAt(staffCategoriesList, i))>
<!--- display link to anchor --->
<a name="#categoryName#"></a>
<h1>#categoryName#</h1>
<cfloop from="1" to="#QoQ.recordcount#" step="1" index="j">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><img src="/images/#QoQ.imageFile[j]#" alt="#QoQ.alt[j]#"></td>
<td valign="top" style="padding-left:20px;">
<span style="font-size:120%;font-weight:bold;">#QoQ.name[j]#</span><br>
Title: <i>#QoQ.title[j]#</i><br>
Email: <a href="mailto:#QoQ.email[j]#">#QoQ.email[j]#</a><br>
Extension: #QoQ.extension[j]#<br><br>
<a href="#application.url.conjurer#?objectid=#QoQ.objectid[j]#">View Bio</a>
</td>
</tr>
</table>
<p style="border-bottom:1px dashed gray;width:100%;margin-top:0px;"> </p>
</cfloop>
</cfloop>
</cfoutput>
</cffunction>

Related Articles
No user responded in this post
Leave A Reply