Guest User

Untitled

a guest
Oct 30th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cfcomponent output="false">
  2.  
  3.     <cffunction name="init" access="public" returntype="StatsInputBean">
  4.         <cfreturn this />
  5.     </cffunction>
  6.    
  7.        
  8.     <cffunction name="aggregate" output="false" access="public" returntype="struct" hint="I aggregate the stats keys and values from user input into a collection">
  9.         <cfargument name="UserInput" type="struct" required="true"/>
  10.         <cfset var filteredUserInput = {} />
  11.         <cfset var thisInput = "" />
  12.        
  13.         <cfloop collection="#arguments.userInput#" item="thisInput">
  14.             <cfif thisInput contains ":">
  15.                 <cfset filteredUserInput[ thisInput  ] = {
  16.                             KPIID=listGetAt( thisInput, 2, ":"),
  17.                             KPIValueID=listGetAt( thisInput, 3, ":"),
  18.                             KPIValue=userInput[ thisInput ]
  19.                         } />
  20.             </cfif>
  21.         </cfloop>          
  22.        
  23.         <cfreturn filteredUserInput /> 
  24.     </cffunction>
  25.  
  26.     <cffunction name="findActionables" output="false" access="public" returntype="struct" hint="I find the items we wish to process and ignore fields left blank">
  27.         <cfargument name="StructuredInputCollection" type="struct" required="true"/>       
  28.         <cfset var thisCollection = duplicate( arguments.StructuredInputCollection ) />
  29.         <cfset var thisItem = "" />
  30.         <cfloop collection="#thisCollection#" item="thisItem">
  31.             <!--- We want to respect updates and also cases where the user submitted  --->
  32.             <cfif len( trim( thisCollection[thisItem]["KPIValue"] ) ) IS 0
  33.                         AND
  34.                     val( thisCollection[thisItem]["KPIValueID"] ) IS 0>
  35.                 <cfset structDelete( thisCollection, thisItem ) />
  36.             </cfif>
  37.         </cfloop>
  38.         <cfreturn thisCollection />
  39.     </cffunction>
  40.  
  41.     <cffunction name="validate" output="false" access="public" returntype="boolean" hint="I validate the input before we do anything with it">
  42.         <cfargument name="UserMsg" type="any" required="true"/>
  43.         <cfset var inputData = getStatsInputData() />
  44.         <cfset var thisItem = "" />
  45.         <cfset var rtn = true />
  46.         <cfif structCount( inputData ) GT 0 AND NOT isDate( getMeasuredOn() ) IS true>
  47.             <cfset arguments.UserMsg.addError( "You must provide the date of measurement for your stats entry")>
  48.             <cfset rtn = false />
  49.         </cfif>
  50.         <cfloop collection="#inputData#" item="thisItem">
  51.             <cfif len( trim( inputData[thisItem].KPIValue ) ) GT 0 AND NOT isValid('Numeric', inputData[thisItem].KPIValue)>
  52.                 <cfset arguments.UserMsg.addError("Only use numeric values for #ListFirst( thisItem, ':')#") />
  53.                 <cfset rtn = false />
  54.             </cfif>
  55.         </cfloop>
  56.         <cfreturn rtn />
  57.     </cffunction>
  58.    
  59.     <cffunction name="getStatsInputData" access="public" output="false" returntype="struct">
  60.         <cfreturn variables.instance.StatsInputData />
  61.     </cffunction>
  62.    
  63.     <cffunction name="setStatsInputData" access="public" output="false" returntype="void">
  64.         <cfargument name="StatsInputData" type="struct" required="true" />
  65.         <cfset variables.instance.StatsInputData = findActionables( aggregate( arguments.StatsInputData ) ) />
  66.     </cffunction>
  67.    
  68.     <cffunction name="getMeasuredOn" access="public" output="false" returntype="string">
  69.         <cfreturn variables.instance.MeasuredOn />
  70.     </cffunction>
  71.    
  72.     <cffunction name="setMeasuredOn" access="public" output="false" returntype="void">
  73.         <cfargument name="MeasuredOn" type="string" required="true" />
  74.         <cfset variables.instance.MeasuredOn = arguments.MeasuredOn />
  75.     </cffunction>
  76.  
  77.     <cffunction name="getMemberID" access="public" output="false" returntype="string">
  78.         <cfreturn variables.instance.MemberID />
  79.     </cffunction>
  80.    
  81.     <cffunction name="setMemberID" access="public" output="false" returntype="void">
  82.         <cfargument name="MemberID" type="string" required="true" />
  83.         <cfset variables.instance.MemberID = arguments.MemberID />
  84.     </cffunction>
  85.  
  86. </cfcomponent>
Add Comment
Please, Sign In to add comment