| 1 | <!--- |
|---|
| 2 | Name : cfcs/questiontype.cfc |
|---|
| 3 | Author : Raymond Camden |
|---|
| 4 | Created : |
|---|
| 5 | Last Updated : March 10, 2006 |
|---|
| 6 | History : support for tableprefix (3/10/06) |
|---|
| 7 | Purpose : |
|---|
| 8 | ---> |
|---|
| 9 | |
|---|
| 10 | <cfcomponent displayName="QuestionType" hint="A Question Type." output="false"> |
|---|
| 11 | |
|---|
| 12 | <cfset variables.utils = createObject("component","utils")> |
|---|
| 13 | |
|---|
| 14 | <cffunction name="init" access="public" returnType="questionType" output="false" |
|---|
| 15 | hint="Returns an instance of the CFC initialized with the correct DSN."> |
|---|
| 16 | <cfargument name="dsn" type="string" required="true" hint="DSN used for all operations in the CFC."> |
|---|
| 17 | <cfargument name="dbtype" type="string" required="true" hint="Database type."> |
|---|
| 18 | <cfargument name="tableprefix" type="string" required="true" hint="Table prefix."> |
|---|
| 19 | |
|---|
| 20 | <cfset variables.dsn = arguments.dsn> |
|---|
| 21 | <cfset variables.dbtype = arguments.dbtype> |
|---|
| 22 | <cfset variables.tableprefix = arguments.tableprefix> |
|---|
| 23 | |
|---|
| 24 | <cfreturn this> |
|---|
| 25 | |
|---|
| 26 | </cffunction> |
|---|
| 27 | |
|---|
| 28 | <cffunction name="addQuestionType" access="public" returnType="uuid" output="false" |
|---|
| 29 | hint="Adds a new questionType to the the db."> |
|---|
| 30 | <cfargument name="name" type="string" required="true"> |
|---|
| 31 | <cfargument name="handlerRoot" type="string" required="true"> |
|---|
| 32 | <cfset var newID = createUUID()> |
|---|
| 33 | |
|---|
| 34 | <cfif not validData(arguments)> |
|---|
| 35 | <cfset variables.utils.throw("QuestionTypeCFC","QuestionType data is not valid.")> |
|---|
| 36 | </cfif> |
|---|
| 37 | |
|---|
| 38 | <cfquery datasource="#variables.dsn#"> |
|---|
| 39 | insert into #variables.tableprefix#questiontypes(id,name,handlerroot) |
|---|
| 40 | values( |
|---|
| 41 | <cfqueryparam value="#newID#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">, |
|---|
| 42 | <cfqueryparam value="#arguments.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">, |
|---|
| 43 | <cfqueryparam value="#arguments.handlerRoot#" cfsqltype="CF_SQL_VARCHAR" maxlength="50"> |
|---|
| 44 | ) |
|---|
| 45 | </cfquery> |
|---|
| 46 | |
|---|
| 47 | <cfreturn newID> |
|---|
| 48 | </cffunction> |
|---|
| 49 | |
|---|
| 50 | <cffunction name="deleteQuestionType" access="public" returnType="void" output="false" |
|---|
| 51 | hint="Deletes a questionType."> |
|---|
| 52 | <cfargument name="id" type="uuid" required="true"> |
|---|
| 53 | |
|---|
| 54 | <cfquery datasource="#variables.dsn#"> |
|---|
| 55 | delete from #variables.tableprefix#questionTypes |
|---|
| 56 | where id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 57 | </cfquery> |
|---|
| 58 | |
|---|
| 59 | </cffunction> |
|---|
| 60 | |
|---|
| 61 | <cffunction name="getQuestionType" access="public" returnType="query" output="false" |
|---|
| 62 | hint="Returns a questionType."> |
|---|
| 63 | <cfargument name="id" type="uuid" required="false"> |
|---|
| 64 | <cfset var qGetQT = ""> |
|---|
| 65 | |
|---|
| 66 | <cfquery name="qGetQT" datasource="#variables.dsn#"> |
|---|
| 67 | select id, name, handlerRoot |
|---|
| 68 | from #variables.tableprefix#questiontypes |
|---|
| 69 | where id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 70 | </cfquery> |
|---|
| 71 | |
|---|
| 72 | <cfif qGetQT.recordCount> |
|---|
| 73 | <cfreturn qGetQT> |
|---|
| 74 | <cfelse> |
|---|
| 75 | <cfset variables.utils.throw("QuestionTypeCFC","Invalid QuestionType requested.")> |
|---|
| 76 | </cfif> |
|---|
| 77 | |
|---|
| 78 | </cffunction> |
|---|
| 79 | |
|---|
| 80 | <cffunction name="getQuestionTypes" access="public" returnType="query" output="false" |
|---|
| 81 | hint="Returns all the questionTypes."> |
|---|
| 82 | <cfset var qGetQuestionTypes = ""> |
|---|
| 83 | |
|---|
| 84 | <cfquery name="qGetQuestionTypes" datasource="#variables.dsn#"> |
|---|
| 85 | select id, name, handlerroot |
|---|
| 86 | from #variables.tableprefix#questiontypes |
|---|
| 87 | order by name asc |
|---|
| 88 | </cfquery> |
|---|
| 89 | |
|---|
| 90 | <cfreturn qGetQuestionTypes> |
|---|
| 91 | |
|---|
| 92 | </cffunction> |
|---|
| 93 | |
|---|
| 94 | <cffunction name="updateQuestionType" access="public" returnType="void" output="false" |
|---|
| 95 | hint="Adds a new questionType to the db."> |
|---|
| 96 | <cfargument name="id" type="uuid" required="true" hint="QuestionType ID."> |
|---|
| 97 | <cfargument name="name" type="string" required="true"> |
|---|
| 98 | <cfargument name="handlerRoot" type="string" required="true"> |
|---|
| 99 | |
|---|
| 100 | <cfif not validData(arguments)> |
|---|
| 101 | <cfset variables.utils.throw("QuestionTypeCFC","QuestionType data is not valid.")> |
|---|
| 102 | </cfif> |
|---|
| 103 | |
|---|
| 104 | <cfquery datasource="#variables.dsn#"> |
|---|
| 105 | update #variables.tableprefix#questiontypes |
|---|
| 106 | set |
|---|
| 107 | name = <cfqueryparam value="#arguments.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">, |
|---|
| 108 | handlerroot = <cfqueryparam value="#arguments.handlerRoot#" cfsqltype="CF_SQL_VARCHAR" maxlength="255"> |
|---|
| 109 | where id = <cfqueryparam value="#arguments.ID#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 110 | </cfquery> |
|---|
| 111 | |
|---|
| 112 | </cffunction> |
|---|
| 113 | |
|---|
| 114 | <cffunction name="validData" access="public" returnType="boolean" output="false" |
|---|
| 115 | hint="Checks to see if the questionType is valid."> |
|---|
| 116 | <cfargument name="data" type="struct" required="true" hint="Data to validate."> |
|---|
| 117 | |
|---|
| 118 | <cfif not structKeyExists(data,"name") or not len(trim(data.name)) or |
|---|
| 119 | not structKeyExists(data,"handlerRoot") or not len(trim(data.handlerRoot))> |
|---|
| 120 | <cfreturn false> |
|---|
| 121 | </cfif> |
|---|
| 122 | |
|---|
| 123 | <cfreturn true> |
|---|
| 124 | |
|---|
| 125 | </cffunction> |
|---|
| 126 | |
|---|
| 127 | </cfcomponent> |
|---|