Created
July 27, 2010 20:27
-
-
Save mhayes/492806 to your computer and use it in GitHub Desktop.
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
component name="col" { | |
function init( | |
required string name, | |
required string displayName, | |
required string dataType="string", | |
required boolean canSort=false, | |
required boolean canDisplay=false | |
) { | |
variables.tbl = ""; | |
variables.name = arguments.name; | |
variables.displayName = arguments.displayName; | |
variables.dataType = arguments.dataType; | |
variables.canSort = arguments.canSort; | |
variables.canDisplay = arguments.canDisplay; | |
variables.pos.display = 9999; | |
variables.pos.sort = 9999; | |
} | |
function setTbl(required tbl) { | |
variables.tbl = arguments.tbl; | |
} | |
function getName() { | |
return variables.name; | |
} | |
function getTbl() { | |
return variables.tbl; | |
} | |
function getDataType() { | |
return variables.dataType; | |
} | |
function getCanSort() { | |
return variables.canSort; | |
} | |
function getCanDisplay() { | |
return variables.canDisplay; | |
} | |
function getPos(required string type) { | |
return variables.pos["#lcase(arguments.type)#"]; | |
} | |
function setPos(required string type, required numeric val) { | |
variables.pos["#lcase(arguments.type)#"] = arguments.val; | |
} | |
function getFieldName() { | |
return "TBL_#getTbl().getName()#[#getName()#]"; | |
} | |
function toString() { | |
return variables.displayName; | |
} | |
} |
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
component name="colCollection" { | |
function init() { | |
variables.cols = ArrayNew(1); | |
return this; | |
} | |
function addCol(col) { | |
ArrayAppend(variables.cols, col); | |
} | |
function getCols() { | |
return variables.cols; | |
} | |
} |
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
<cfcomponent name="formStruct"> | |
<cffunction name="init"> | |
<cfargument name="fieldNames" required="yes" /> | |
<cfset variables.fieldNames = arguments.fieldNames /> | |
<cfreturn this /> | |
</cffunction> | |
<cffunction name="process"> | |
<cfset var fields = ArrayNew(1) /> | |
<cfloop list="#variables.fieldNames#" index="f"> | |
<!--- | |
CHECK FIELD FORMAT: | |
TBL_<TBL_NAME>[<COL_NAME>] | |
---> | |
<cfset var field = Trim(f) /> | |
<cfif REFind("^TBL_([^\[]+)\[[^]]+\]$", field) NEQ 0> | |
<cfset var fieldOnly = ReplaceNoCase(field, "TBL_", "") /> | |
<cfset var colStart = Find("[", fieldOnly) /> | |
<cfset var ret = StructNew() /> | |
<cfset ret.tbl = Left(fieldOnly, colStart - 1) /> | |
<cfset ret.col = Right(Replace(fieldOnly, "]",""), Len(fieldOnly) - colStart - 1) /> | |
<cfset ArrayAppend(fields, ret) /> | |
</cfif> | |
</cfloop> | |
<cfreturn fields /> | |
</cffunction> | |
</cfcomponent> |
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
component name="tbl" { | |
function init(required string name) { | |
variables.name = arguments.name; | |
variables.cols = ArrayNew(1); | |
} | |
function getName() { | |
return variables.name; | |
} | |
// @pre: col must not already exist in cols collection | |
// @post: col will be added to cols collections | |
function addCol(col) { | |
try { | |
getCol(col.getName()); | |
} catch(ColumnNotFound e) { | |
col.setTbl(this); | |
ArrayAppend(variables.cols, col); | |
return true; | |
} | |
throw(type="ColumnExists", message="Attempted to add duplicate column to #variables.name# table"); | |
} | |
function getCol(required string name) { | |
for(var i=1; i<=ArrayLen(variables.cols); i++) { | |
var currentCol = variables.cols[i]; | |
if(CompareNoCase(currentCol.getName(), arguments.name) EQ 0) { | |
return currentCol; | |
} | |
} | |
throw(type="ColumnNotFound", message="The column titled #arguments.name# could NOT be found."); | |
} | |
function getCols() { | |
return variables.cols; | |
} | |
function toString() { | |
return variables.name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment