Created
April 9, 2012 16:27
-
-
Save tdm00/2344554 to your computer and use it in GitHub Desktop.
Refactored Requisitiontests.cfc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!--- 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