Skip to content

Instantly share code, notes, and snippets.

@tdm00
Created April 6, 2012 21:30
Show Gist options
  • Select an option

  • Save tdm00/2323099 to your computer and use it in GitHub Desktop.

Select an option

Save tdm00/2323099 to your computer and use it in GitHub Desktop.
requisitiontests/create
<!--- requisitiontests/create --->
<cffunction name="create">
<!--- Create a Requisitiontest object based on the values passed from the form --->
<cfset requisitiontest = model("Requisitiontest").new(params.requisitiontest)>
<!--- Verify that the requisitiontest creates successfully --->
<cfif requisitiontest.save()>
<!--- Next create a recordset of the questions that go along with that test --->
<cfset questions = model("testquestion").findAll(
where="testid=#requisitiontest.testid#",
include="answerlist(answerlistoptions)",
order="id,answerlistid")>
<!--- Loop record set, insert new row for each question into the worksheet --->
<cfoutput query="questions" group="id">
<cfset requisitiontestworksheet = model("Requisitiontestworksheet").create(
requisitiontestid=#requisitiontest.id#,
question=#text#,
answertype=#answertype#,
ordervalue=#ordervalue#)>
<cfif LCase(Trim(answertype)) EQ "list">
<cfset requisitiontestworksheetlist = model("requisitiontestworksheetlist").create(
requisitiontestworksheetid=requisitiontestworksheet.id,
value=#value#)>
</cfif>
</cfoutput>
<cfset flashInsert(success="The test was added to the requisition.")>
<cfset redirectTo(controller="requisitions", action="show", key=requisitiontest.requisitionid) />
<!--- Otherwise --->
<cfelse>
<cfset flashInsert(error="There was an error adding the test to the requisition.")>
<cfset redirectTo(controller="requisitions", action="show", key=requisitiontest.requisitionid) />
</cfif>
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment