Skip to content

Instantly share code, notes, and snippets.

@davidpanzarella
Last active August 29, 2015 14:05
Show Gist options
  • Save davidpanzarella/f002efe0208cdbf16a10 to your computer and use it in GitHub Desktop.
Save davidpanzarella/f002efe0208cdbf16a10 to your computer and use it in GitHub Desktop.
Remove any empty grouping tags from the Current Params
<!--- start: scrub empty param relationships --->
<cffunction name="scrubEmptyParamRelationships" output="false" returntype="query">
<cfargument name="query" required="true">
<cfset local.openList = "" />
<cfset local.closeList = "" />
<cfset local.removeList = "" />
<cfloop query="arguments.query">
<cfif relationship eq "andOpenGrouping">
<cfset local.openList = listAppend(local.openList,param) />
<cfelseif relationship eq "closeGrouping">
<cfset local.closeList = listAppend(local.closeList,param) />
</cfif>
</cfloop>
<cfloop list="#local.openList#" index="openIndex">
<cfloop list="#local.closeList#" index="closeIndex">
<cfif (closeIndex - openIndex) eq 1 >
<cfset local.removeList = listAppend(local.removeList,openIndex) />
<cfset local.removeList = listAppend(local.removeList,closeIndex) />
</cfif>
</cfloop>
</cfloop>
<cfset local.removeList = listSort(local.removeList,"numeric","desc") />
<cfloop list="#local.removeList#" index="removeIndex">
<cfset arguments.query.deleteRow(removeIndex) />
</cfloop>
<cfreturn arguments.query>
</cffunction>
<!--- end: scrub empty param relationships --->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment