Skip to content

Instantly share code, notes, and snippets.

@twelverobots
Last active December 29, 2015 08:29
Show Gist options
  • Save twelverobots/7643742 to your computer and use it in GitHub Desktop.
Save twelverobots/7643742 to your computer and use it in GitHub Desktop.
<cfcomponent>
<cffunction name="getData" access="public" returntype="any" output="false">
<!--- Get the feed --->
<cfset var feed = application.feedManager.readByName("Programs", "DCTC") />
<!--- Set the feed to include enough records that it won't get cut off --->
<cfset feed.setNextN(100) />
<cfset feed.setMaxItems(100) />
<!--- Grab the query from the feed, I also could have done this with the iterator, but it is easier to look at the data this way --->
<cfset var qFeed = feed.getQuery() />
<!--- create the structure for the return object, dataset is the return object. These names are what Mura expects --->
<cfset var dataorder = [] />
<cfset var datarecords = {} />
<cfset var dataset = {} />
<!--- This is how I am adding a value that is NOT included in the feed. Sometimes you may find this necessary, but it is not required --->
<cfset arrayAppend(dataOrder, "Undecided") />
<cfset datarecords["Undecided"]["datarecordid"] = "Undecided" />
<cfset datarecords["Undecided"]["label"] = "Undecided" />
<cfset datarecords["Undecided"]["value"] = "Undecided" />
<cfset datarecords["Undecided"]["isSelected"] = true />
<!--- Loop over the feed and add a new record for each value in it --->
<cfloop query="qFeed">
<!--- Each record needs an idea, since some of the menu titles have spaces and special characters, i am hashing the value to get something that can be used as struct keys --->
<cfset var hash = hash(qFeed.MENUTITLE) />
<!--- Since structs are unordered, we need an array to determine the order in which this will be placed in the field --->
<cfset arrayAppend(dataOrder, hash) />
<!--- Add the record id, the label, the value, and whether or not the record is currently selected --->
<cfset datarecords[hash]["datarecordid"] = hash />
<cfset datarecords[hash]["label"] = qFeed.MENUTITLE />
<cfset datarecords[hash]["value"] = qFeed.MENUTITLE />
<cfset datarecords[hash]["isSelected"] = false />
</cfloop>
<!--- Add the data order and the colleciton of records to the data set --->
<cfset dataset["datarecordorder"] = dataOrder />
<cfset dataset["datarecords"] = datarecords />
<!--- Return the dataset --->
<cfreturn dataset />
</cffunction>
</cfcomponent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment