Copy link to clipboard
Copied
quote:
<!--- establish default values --->
<cfparam name="output" default="">
<cfparam name="catNameOutput" default="">
<cfparam name="indent" default="">
<cffunction name="GenerateCategories" access="public" returntype="string">
<!--- this holds the outermost parent value being passed to the function --->
<cfargument name="GenCatParent" type="uuid" required="yes" default=0 >
<!--- this holds the nested level we are on --->
<cfargument name="level" type="numeric" required="yes" default=0 >
<!--- this holds the output_type we need for display purposes --->
<cfargument name="output_type" type="numeric" required="yes" default=0 >
<!--- grab the children of the received category --->
<cfquery name="rsCategoryChildren" datasource="webdsn">
SELECT * FROM dbo.BlogCategories
WHERE catParent = '#GenCatParent#'
ORDER BY catName ASC
</cfquery>
<cfloop query="rsCategoryChildren">
<!--- keep track of the indentation needed depending on which level we are at --->
<cfloop from="0" to="#arguments.level#" index="i">
<cfset indent = indent & " ">
</cfloop>
<!--- if the nest is being used in the dropdown on the category manage page, we need to use option tags --->
<cfif arguments.output_type EQ 1>
<cfset catNameOutput = "<option value='" & catPK & "'>" & indent & Trim(catName) & "</option>">
</cfif>
<!--- if the nest is being used in the table on the category manage page, we need to use table row tags --->
<cfif arguments.output_type EQ 2>
<cfset catNameOutput = "<tr> <td>edit</td> <td>delete</td> <td>" & indent & Trim(catName) & "</td> </tr>">
</cfif>
<cfset output = output & catNameOutput>
<!--- reset the indentation --->
<cfset indent = "">
<!--- check for children of this child --->
<cfquery name="checkForKids" datasource="webdsn">
SELECT * FROM dbo.BlogCategories
WHERE catParent = '#rsCategoryChildren.catPK#'
ORDER BY catName ASC
</cfquery>
<!--- if there are any, call this function recursively --->
<cfif checkForKids.recordcount GT 0>
<cfset GenerateCategories(genCatParent=catPK, level = level +1, output_type = arguments.output_type)>
</cfif>
</cfloop>
<cfreturn output>
</cffunction>
<cfquery name="rsCategoryParents" datasource="webdsn">
SELECT * FROM dbo.BlogCategories
WHERE catParent IS NULL
ORDER BY catName ASC
</cfquery>
quote:
<table width="100%" class="managementtable">
<tr bgcolor="#F6F6F6">
<td> </td>
<td> </td>
<td>Category Name</td>
</tr>
<cfloop query="rsCategoryParents">
<cfoutput><tr> <td>edit</td> <td>delete</td> <td>#Trim(catName)#</td> </tr></cfoutput>
<cfset recursivecats = GenerateCategories(genCatParent=catPK,level=0,output_type=2)>
<cfoutput>#recursivecats#</cfoutput>
</cfloop>
</table>
<!---------------------------------------------------------------------------->
<select name="select">
<option>None</option>
<cfoutput query="rsCategoryParents">
<option value="#catPK#">#Trim(catName)#</option>
<cfset recursivecats = GenerateCategories(genCatParent=catPK,level=0,output_type=1)>
#recursivecats#
</cfoutput>
</select>
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied