/* The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is comprised of the ADF directory The Initial Developer of the Original Code is PaperThin, Inc. Copyright (c) 2009-2018. All Rights Reserved. By downloading, modifying, distributing, using and/or accessing any files in this directory, you agree to the terms and conditions of the applicable end user license agreement. */ /* *************************************************************** */ /* Author: PaperThin, Inc. Name: ceData_3_0.cfc Summary: Custom Element Data functions for the ADF Library Version 2.1 History: 2015-08-31 - GAC - Created 2016-12-05 - GAC - Converted to a cfscript style component 2017-07-27 - GAC - Added getCEDataByPageID() and getCEDataViewByPageID() functions 2017-11-29 - GAC - Added formatDataForGceArchivePostImport() and outputDataForGceArchivePostImport() functions */ component displayname="ceData_3_0" extends="ceData_2_0" hint="Custom Element Data functions for the ADF Library" { /* PROPERTIES */ property name="version" type="string" default="3_0_3"; property name="type" value="singleton"; property name="data" type="dependency" injectedBean="data_2_0"; property name="wikiTitle" value="CEData_3_0"; variables.SQLViewNameADFVersion = "2.0"; /* *************************************************************** */ /* Author: PaperThin, Inc. Name: $getCEDataByPageID Summary: Returns a CEData Array of Structs (only 1 record) Returns: Array Arguments: Numeric - csPageID Usage: application.ADF.ceData.getCEDataByPageID(ficDataValues) History: 2017-07-27 - GAC - Created */ public array function getCEDataByPageID(required string customElementName,required numeric csPageID) { var retArray = ArrayNew(1); var csFormID = application.ADF.cedata.getFormIDByCEName(CEName=arguments.customElementName); var ceData = application.ADF.ceData.getElementInfoByPageID(pageid=arguments.csPageID,formid=csFormID,separateValueStruct=true); if ( !StructIsEmpty(ceData) AND structKeyExists(ceData,"FormID") AND IsNumeric(ceData.FormID) AND ceData.FormID GT 0 ) retArray[1] = ceData; return retArray; } /* *************************************************************** */ /* Author: PaperThin, Inc. Name: $getCEDataViewByPageID Summary: Returns a CEData View Query Returns: Array Arguments: Numeric - csPageID Usage: application.ADF.ceData.getCEDataByPageID(ficDataValues) History: 2017-07-27 - GAC - Created */ public query function getCEDataViewByPageID(required string customElementName,required numeric csPageID,string overrideViewTableName="",boolean forceRebuild=0) { var viewTableName = ""; var ceViewQry = QueryNew("null"); var queryService = new Query(); // Set the override for the view table name if defined if ( LEN(arguments.overrideViewTableName) ) viewTableName = arguments.overrideViewTableName; else viewTableName = getCEViewName(ceName=arguments.customElementName,type="adfversion",version=getSQLViewNameADFVersion()); // Verify if the view table exists, create if doesn't exists viewTableExists = buildView(ceName=arguments.customElementName, viewName=viewTableName, forceRebuild=arguments.forceRebuild); if ( viewTableExists ) { try { queryService.setDatasource("#request.site.datasource#"); queryService.setAttributes(maxrows=1); queryService.setSql(" SELECT * FROM #viewTableName# WHERE PageID = :PageID "); queryService.addParam( name = "PageID", value = "#arguments.csPageID#", cfsqltype = "cf_sql_integer" ); // Execute the query and store the results. ceViewQry = queryService.execute().getResult(); } catch ( any ex ) { application.ADF.utils.doDump(var=ex,label="getCEDataViewByPageID Query Failed!",expand=0); } } return ceViewQry; } /* *************************************************************** */ /* Author: PaperThin, Inc. Name: $convertFICDataValuesToCEData Summary: Returns a CEData Array of Structs from a FIC_ field data struct Returns: Array Arguments: Struct - ficDataValues Usage: application.ADF.ceData.convertFICDataValuesToCEData(ficDataValues) History: 2016-10-19 - GAC - Created */ public array function convertFICDataValuesToCEData(struct ficDataValues=StructNew()) { var retArray = ArrayNew(1); var ceData = StructNew(); var key = ""; var fldName = ""; var fldValue = ""; var ficFieldNameKey = ""; var ficFieldValueKey = ""; ceData.values = StructNew(); ceData.formid = 0; ceData.pageID = 0; // Set the Element ID from the formID or the controlTypeID if ( StructKeyExists(arguments.ficDataValues, 'controlTypeID') ) ceData.formid = arguments.ficDataValues.controlTypeID; else if ( StructKeyExists(arguments.ficDataValues, 'FormID') ) ceData.formid = arguments.ficDataValues.FormID; // Set the Data Page ID from the dataPageID or the PageID if( StructKeyExists(arguments.ficDataValues, 'dataPageID') ) ceData.pageID = arguments.ficDataValues.dataPageID; else if( StructKeyExists(arguments.ficDataValues, 'savePageID') ) ceData.pageID = arguments.ficDataValues.savePageID; else if( StructKeyExists(arguments.ficDataValues, 'pageID') ) ceData.pageID = arguments.ficDataValues.pageID; for ( key IN arguments.ficDataValues) { if ( FindNoCase('FIC_', key, 1) AND !FindNoCase('_FIELDNAME', key, 1) ) { ficFieldNameKey = key & '_FIELDNAME'; ficFieldValueKey = key; fldName = ""; fldValue = ""; if ( StructKeyExists(arguments.ficDataValues,ficFieldNameKey) ) fldName = arguments.ficDataValues[ficFieldNameKey]; if ( StructKeyExists(arguments.ficDataValues,ficFieldNameKey) ) fldValue = arguments.ficDataValues[ficFieldValueKey]; if ( LEN(TRIM(fldName)) AND !StructKeyExists(ceData.values,fldName) ) ceData.values[fldName] = fldValue; } } retArray[1] = ceData; return retArray; } /* *************************************************************** */ /* Author: PaperThin, Inc. Name: $queryToCEDataArrayOfStructures Summary: Converts a query to an array of structures nested in the values node like a ceData array of structures Based on data.queryToArrayOfStructures() Returns: Array Arguments: Query - queryData - "The query that will be converted into an array of structures" Boolean - keysToLowercase - "Use to convert struct key to lowercase" History: 2016-11-16 - GAC - Created */ public array function queryToCEDataArrayOfStructures(required query queryData, boolean keysToLowercase=false) { var theArray = arraynew(1); var cols = ListtoArray(arguments.queryData.columnlist); var row = 1; var thisRow = StructNew(); var col = 1; for ( row = 1; row LTE arguments.queryData.recordcount; row = row + 1 ){ thisRow.formid = 0; thisRow.pageid = 0; thisRow.values = structnew(); for(col = 1; col LTE arraylen(cols); col = col + 1) { if ( cols[col] EQ "formid" AND StructKeyExists(arguments.queryData,"formid") ) thisRow.formid = arguments.queryData.formid[row]; if ( cols[col] EQ "pageid" AND StructKeyExists(arguments.queryData,"pageid") ) thisRow.pageid = arguments.queryData.pageid[row]; if ( arguments.keysToLowercase ) thisRow.values[lcase(cols[col])] = arguments.queryData[cols[col]][row]; else thisRow.values[cols[col]] = arguments.queryData[cols[col]][row]; } arrayAppend(theArray,duplicate(thisRow)); } return theArray; } /* *************************************************************** */ /* Author: PaperThin, Inc. Name: formatDataForGceArchivePostImport Summary: Returns a string of formatted CFML script code with the Fields and Data from a given custom element Returns: String Arguments: String - ceName - "the Global Custom Element Name that contains the data to export" Boolean - alwaysAddFlag - "Set to 'true' to add this data when importing even if element exists and has data" History: 2017-11-29 - GAC - Created */ public string function formatDataForGceArchivePostImport(required string ceName,boolean alwaysAddFlag=false){ var retStr = ""; var items = application.ADF.ceData.getCEdata(arguments.ceName); var item = StructNew(); var TAB = CHR(9); var LF = CHR(10); var i = 1; var key = ""; savecontent variable="retStr" { WriteOutput('<cfscript>');WriteOutput('#LF#'); WriteOutput('#TAB#');WriteOutput(encodeForHTML("dataCFC = createObject('component', 'commonspot.components.form.gce-data'); //NOTE: do not call init"));WriteOutput('#LF#');WriteOutput('#LF#'); WriteOutput('#TAB#');WriteOutput("gceName = '#arguments.ceName#';");WriteOutput('#LF#'); WriteOutput('#TAB#');WriteOutput("alwaysAdd = #arguments.alwaysAddFlag#; // 'false' will NOT populate if any data found in Data_fieldvalue table");WriteOutput('#LF#'); WriteOutput('#TAB#');WriteOutput("data = ArrayNew(1);");WriteOutput('#LF#');WriteOutput('#LF#'); for ( i=1; i lte ArrayLen(items); i=i+1 ) { item = items[i].values; WriteOutput('#TAB#');WriteOutput("info = {};");WriteOutput('#LF#'); for ( key IN item ) { WriteOutput('#TAB#');WriteOutput("info['#lcase(key)#'] = '#item[key]#';");WriteOutput('#LF#'); } WriteOutput('#TAB#');WriteOutput("ArrayAppend(data, info);");WriteOutput('#LF#');WriteOutput('#LF#'); } WriteOutput('#TAB#');WriteOutput(encodeForHTML("dataCFC.populateRawData(gceName, data, alwaysAdd);"));WriteOutput('#LF#'); WriteOutput('</cfscript>'); } return retStr; } /* *************************************************************** */ /* Author: PaperThin, Inc. Name: outputDataForGceArchivePostImport Summary: Renders to the page formatted CFML script code with the Fields and Data from a given custom element Returns: Void Arguments: String - ceName - "the Global Custom Element Name that contains the data to export" Boolean - alwaysAddFlag - "Set to 'true' to add this data when importing even if element exists and has data" History: 2017-11-29 - GAC - Created */ public void function outputDataForGceArchivePostImport(required string ceName,boolean alwaysAddFlag=false){ WriteOutput(formatDataForGceArchivePostImport(arguments.ceName,arguments.alwaysAddFlag)); } }