Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <cfcomponent output="false">
- <cffunction name="init" access="public" returntype="StatsInputBean">
- <cfreturn this />
- </cffunction>
- <cffunction name="aggregate" output="false" access="public" returntype="struct" hint="I aggregate the stats keys and values from user input into a collection">
- <cfargument name="UserInput" type="struct" required="true"/>
- <cfset var filteredUserInput = {} />
- <cfset var thisInput = "" />
- <cfloop collection="#arguments.userInput#" item="thisInput">
- <cfif thisInput contains ":">
- <cfset filteredUserInput[ thisInput ] = {
- KPIID=listGetAt( thisInput, 2, ":"),
- KPIValueID=listGetAt( thisInput, 3, ":"),
- KPIValue=userInput[ thisInput ]
- } />
- </cfif>
- </cfloop>
- <cfreturn filteredUserInput />
- </cffunction>
- <cffunction name="findActionables" output="false" access="public" returntype="struct" hint="I find the items we wish to process and ignore fields left blank">
- <cfargument name="StructuredInputCollection" type="struct" required="true"/>
- <cfset var thisCollection = duplicate( arguments.StructuredInputCollection ) />
- <cfset var thisItem = "" />
- <cfloop collection="#thisCollection#" item="thisItem">
- <!--- We want to respect updates and also cases where the user submitted --->
- <cfif len( trim( thisCollection[thisItem]["KPIValue"] ) ) IS 0
- AND
- val( thisCollection[thisItem]["KPIValueID"] ) IS 0>
- <cfset structDelete( thisCollection, thisItem ) />
- </cfif>
- </cfloop>
- <cfreturn thisCollection />
- </cffunction>
- <cffunction name="validate" output="false" access="public" returntype="boolean" hint="I validate the input before we do anything with it">
- <cfargument name="UserMsg" type="any" required="true"/>
- <cfset var inputData = getStatsInputData() />
- <cfset var thisItem = "" />
- <cfset var rtn = true />
- <cfif structCount( inputData ) GT 0 AND NOT isDate( getMeasuredOn() ) IS true>
- <cfset arguments.UserMsg.addError( "You must provide the date of measurement for your stats entry")>
- <cfset rtn = false />
- </cfif>
- <cfloop collection="#inputData#" item="thisItem">
- <cfif len( trim( inputData[thisItem].KPIValue ) ) GT 0 AND NOT isValid('Numeric', inputData[thisItem].KPIValue)>
- <cfset arguments.UserMsg.addError("Only use numeric values for #ListFirst( thisItem, ':')#") />
- <cfset rtn = false />
- </cfif>
- </cfloop>
- <cfreturn rtn />
- </cffunction>
- <cffunction name="getStatsInputData" access="public" output="false" returntype="struct">
- <cfreturn variables.instance.StatsInputData />
- </cffunction>
- <cffunction name="setStatsInputData" access="public" output="false" returntype="void">
- <cfargument name="StatsInputData" type="struct" required="true" />
- <cfset variables.instance.StatsInputData = findActionables( aggregate( arguments.StatsInputData ) ) />
- </cffunction>
- <cffunction name="getMeasuredOn" access="public" output="false" returntype="string">
- <cfreturn variables.instance.MeasuredOn />
- </cffunction>
- <cffunction name="setMeasuredOn" access="public" output="false" returntype="void">
- <cfargument name="MeasuredOn" type="string" required="true" />
- <cfset variables.instance.MeasuredOn = arguments.MeasuredOn />
- </cffunction>
- <cffunction name="getMemberID" access="public" output="false" returntype="string">
- <cfreturn variables.instance.MemberID />
- </cffunction>
- <cffunction name="setMemberID" access="public" output="false" returntype="void">
- <cfargument name="MemberID" type="string" required="true" />
- <cfset variables.instance.MemberID = arguments.MemberID />
- </cffunction>
- </cfcomponent>
Add Comment
Please, Sign In to add comment