Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor of the Locations component as a fully scripted CFC, plus
updates to the ReadMe file
- Loading branch information
Showing
3 changed files
with
189 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,96 +1,91 @@ | |||
<!--- =========================================================================== | /** | ||
// CLASS/COMPONENT: | * =========================================================================== | ||
// Locations.cfc | * CLASS/COMPONENT: | ||
// | * Locations.cfc | ||
// DESCRIPTION: | * | ||
// Example component for ajax callback to correct lat/lng location information | * DESCRIPTION: | ||
// after being Geocoded by Google's JS Map API | * Example component for ajax callback to correct lat/lng location information | ||
// | * after being Geocoded by Google's JS Map API | ||
// AUTHOR: | * | ||
// Steve 'Cutter' Blades (SGB), cutterDOTblATcutterscrossingDOTcom | * AUTHOR: | ||
// | * Steve 'Cutter' Blades (SGB), cutterDOTblATcutterscrossingDOTcom | ||
// REVISION HISTORY: | * | ||
// | * REVISION HISTORY: | ||
// ****************************************************************************** | * *************************************************************************** | ||
// User: SGB [Date: 12.03.10] | * C [04.11.2012] | ||
// Initial Creation | * Refactor as a scripted component | ||
// None of this works, because no datasource is set | * *************************************************************************** | ||
// ****************************************************************************** | * SGB [12.03.10] | ||
=========================================================================== ---> | * Initial Creation | ||
* None of this works, because no datasource is set | |||
* =========================================================================== | |||
* | |||
* @name Entries | |||
* @displayName Blog Entries | |||
* @output false | |||
*/ | |||
component { | |||
|
|
||
<cfcomponent displayname="Locations"> | VARIABLES.dsn = ""; | ||
<cfset VARIABLES.DSN = "" /> | |||
|
|
||
<!--- | /** | ||
// FUNCTION: correctLocsLatLng(corrArr:string):struct | * FUNCTION correctLocsLatLng | ||
// | * A function to get paging query of blog entries for layout in jqGrid | ||
// DESCRIPTION: | * A function taking an array of locations to 'fix' with new lat/lng data. | ||
// A function taking an array of locations to 'fix' with new lat/lng data. | * Takes a JSON object, an array of objects, and converts it to native CF | ||
// Takes a JSON object, an array of objects, and converts it to native CF | * datatypes before looping each array item for processing. | ||
// datatypes before looping each array item for processing. | * | ||
// | * @access remote | ||
// ARGUMENTS: | * @returnType struct | ||
// corrArr:string A JSON object (an array of objects [{locId,lat,lng}]) | * @output false | ||
// | */ | ||
// RETURN: | function correctLocsLatLng(required string corrArr) { | ||
// LOCAL.ret {success:boolean,message?:string} | LOCAL.retVal = {'success' = true, 'message' = ''}; | ||
---> | if(IsJSON(ARGUMENTS.corrArr)) { | ||
<cffunction name="correctLocsLatLng" access="remote" returntype="struct"> | LOCAL.set = DeserializeJSON(ARGUMENTS.corrArr); | ||
<cfargument name="corrArr" type="string" required="true" /> | } else { | ||
<cfset var LOCAL = StructNew() /> | LOCAL.retVal = {'success' = false, 'message' = 'The argument passed is not valid JSON.'}; | ||
<cfset LOCAL.ret = StructNew() /> | } | ||
<cfset LOCAL.ret['success'] = true /> | try { | ||
<cfset LOCAL.set = DeserializeJson(ARGUMENTS.corrArr,true) /> | for(LOCAL.i = 1; LOCAL.i <= ArrayLen(LOCAL.set); LOCAL.i++) { | ||
<cftry> | LOCAL.try = setGMapLatLng(argumentCollection:LOCAL.set[LOCAL.i]); | ||
<cfloop array="#LOCAL.set#" index="LOCAL.i"> | if(!LOCAL.try.success) { | ||
<cfset LOCAL.try = setGMapLatLng(argumentCollection:LOCAL.i) /> | throw(type = "custom_map_error", errorcode = "cme_01", detail = SerializeJSON({'location' = LOCAL.set[LOCAL.i]}), message = LOCAL.try.message); | ||
<cfif not LOCAL.try.success> | } | ||
<cfthrow type="Custom_DS" errorcode="LOCAL.i.locId" message="#LOCAL.try.message#" /> | } | ||
</cfif> | } catch(any err) { | ||
</cfloop> | LOCAL.retVal = {'success' = false, 'message' = err.message, 'detail' = DeserializeJSON(err.detail), 'errorcode' = err.errorcode}; | ||
<cfcatch type="any"> | // Add any error logging and admin notifications | ||
<cfset LOCAL.ret['success'] = false /> | } | ||
<cfset LOCAL.ret['message'] = CFCATCH.Message /> | return LOCAL.retVal; | ||
<cfreturn LOCAL.ret /> | } | ||
</cfcatch> | |||
</cftry> | |||
<cfreturn LOCAL.ret /> | |||
</cffunction> | |||
|
|
||
<!--- | /** | ||
// FUNCTION: setGMapLatLng(locId:numeric,lat:numeric,lng:numeric):struct | * FUNCTION setGMapLatLng | ||
// | * Updates the lat/lng info in a record of a specific location | ||
// DESCRIPT: | * | ||
// Updates the lat/lng info in a record of a specific location | * @access private | ||
// | * @returnType struct | ||
// ARGUMENTS: | * @output false | ||
// locId:numeric Location ID | */ | ||
// lat:numeric Location's Latitude | function setGMapLatLng(required numeric locId, required numeric lat, required numeric lng) { | ||
// lng:numeric Location's Longitude | LOCAL.retVal = {'success' = true, 'message' = ''}; | ||
// | // Main data query | ||
// RETURN: | LOCAL.sql = "UPDATE Location | ||
// LOCAL.ret:struct {success:boolean,message?:string} | SET Latitude = :lat, | ||
---> | Longitude = :lng | ||
<cffunction name="setGMapLatLng" access="remote" returntype="struct"> | WHERE ID = :locId"; | ||
<cfargument name="locId" type="numeric" required="true" /> | LOCAL.q = new Query(sql = LOCAL.sql, datasource = VARIABLES.dsn); | ||
<cfargument name="lat" type="numeric" required="true" /> | LOCAL.q.addParam(name = "locId", value = ARGUMENTS.locId, cfsqltype = "cf_sql_integer"); | ||
<cfargument name="lng" type="numeric" required="true" /> | LOCAL.q.addParam(name = "lat", value = ARGUMENTS.lat, cfsqltype = "cf_sql_integer"); | ||
<cfset var LOCAL = StructNew() /> | LOCAL.q.addParam(name = "lng", value = ARGUMENTS.lng, cfsqltype = "cf_sql_integer"); | ||
<cfset LOCAL.ret = StructNew() /> | try { | ||
<cfset LOCAL.ret['success'] = true /> | LOCAL.q.execute(); | ||
<cftry> | } catch(any err) { | ||
<cfquery name="setLatLng" datasource="#VARIABLES.DS2#"> | LOCAL.retVal = {'success' = false, 'message' = 'We were unable to set the LatLng for Location: #ARGUMENTS.locId# at this time.'}; | ||
UPDATE Location | // Add any error logging and admin notifications | ||
SET Latitude = <cfqueryparam cfsqltype="cf_sql_varchar" value="#ARGUMENTS.lat#" />, | } | ||
Longitude = <cfqueryparam cfsqltype="cf_sql_varchar" value="#ARGUMENTS.lng#" /> | return LOCAL.retVal; | ||
WHERE ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#ARGUMENTS.locId#" /> | } | ||
</cfquery> |
|
||
<cfcatch type="any"> | } | ||
<cfset LOCAL.ret['success'] = false /> | |||
<cfset LOCAL.ret['message'] = "We were unable to set the LatLng for Location: #ARGUMENTS.locId# at this time." /> | |||
<!--- put Error Handling call here ---> | |||
</cfcatch> | |||
</cftry> | |||
<cfreturn LOCAL.ret /> | |||
</cffunction> | |||
</cfcomponent> |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,96 @@ | |||
<!--- =========================================================================== | |||
// CLASS/COMPONENT: | |||
// Locations.cfc | |||
// | |||
// DESCRIPTION: | |||
// Example component for ajax callback to correct lat/lng location information | |||
// after being Geocoded by Google's JS Map API | |||
// | |||
// AUTHOR: | |||
// Steve 'Cutter' Blades (SGB), cutterDOTblATcutterscrossingDOTcom | |||
// | |||
// REVISION HISTORY: | |||
// | |||
// ****************************************************************************** | |||
// User: SGB [Date: 12.03.10] | |||
// Initial Creation | |||
// None of this works, because no datasource is set | |||
// ****************************************************************************** | |||
=========================================================================== ---> | |||
|
|||
<cfcomponent displayname="Locations"> | |||
<cfset VARIABLES.DSN = "" /> | |||
|
|||
<!--- | |||
// FUNCTION: correctLocsLatLng(corrArr:string):struct | |||
// | |||
// DESCRIPTION: | |||
// A function taking an array of locations to 'fix' with new lat/lng data. | |||
// Takes a JSON object, an array of objects, and converts it to native CF | |||
// datatypes before looping each array item for processing. | |||
// | |||
// ARGUMENTS: | |||
// corrArr:string A JSON object (an array of objects [{locId,lat,lng}]) | |||
// | |||
// RETURN: | |||
// LOCAL.ret {success:boolean,message?:string} | |||
---> | |||
<cffunction name="correctLocsLatLng" access="remote" returntype="struct"> | |||
<cfargument name="corrArr" type="string" required="true" /> | |||
<cfset var LOCAL = StructNew() /> | |||
<cfset LOCAL.ret = StructNew() /> | |||
<cfset LOCAL.ret['success'] = true /> | |||
<cfset LOCAL.set = DeserializeJson(ARGUMENTS.corrArr,true) /> | |||
<cftry> | |||
<cfloop array="#LOCAL.set#" index="LOCAL.i"> | |||
<cfset LOCAL.try = setGMapLatLng(argumentCollection:LOCAL.i) /> | |||
<cfif not LOCAL.try.success> | |||
<cfthrow type="Custom_DS" errorcode="LOCAL.i.locId" message="#LOCAL.try.message#" /> | |||
</cfif> | |||
</cfloop> | |||
<cfcatch type="any"> | |||
<cfset LOCAL.ret['success'] = false /> | |||
<cfset LOCAL.ret['message'] = CFCATCH.Message /> | |||
<cfreturn LOCAL.ret /> | |||
</cfcatch> | |||
</cftry> | |||
<cfreturn LOCAL.ret /> | |||
</cffunction> | |||
|
|||
<!--- | |||
// FUNCTION: setGMapLatLng(locId:numeric,lat:numeric,lng:numeric):struct | |||
// | |||
// DESCRIPT: | |||
// Updates the lat/lng info in a record of a specific location | |||
// | |||
// ARGUMENTS: | |||
// locId:numeric Location ID | |||
// lat:numeric Location's Latitude | |||
// lng:numeric Location's Longitude | |||
// | |||
// RETURN: | |||
// LOCAL.ret:struct {success:boolean,message?:string} | |||
---> | |||
<cffunction name="setGMapLatLng" access="remote" returntype="struct"> | |||
<cfargument name="locId" type="numeric" required="true" /> | |||
<cfargument name="lat" type="numeric" required="true" /> | |||
<cfargument name="lng" type="numeric" required="true" /> | |||
<cfset var LOCAL = StructNew() /> | |||
<cfset LOCAL.ret = StructNew() /> | |||
<cfset LOCAL.ret['success'] = true /> | |||
<cftry> | |||
<cfquery name="setLatLng" datasource="#VARIABLES.DS2#"> | |||
UPDATE Location | |||
SET Latitude = <cfqueryparam cfsqltype="cf_sql_varchar" value="#ARGUMENTS.lat#" />, | |||
Longitude = <cfqueryparam cfsqltype="cf_sql_varchar" value="#ARGUMENTS.lng#" /> | |||
WHERE ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#ARGUMENTS.locId#" /> | |||
</cfquery> | |||
<cfcatch type="any"> | |||
<cfset LOCAL.ret['success'] = false /> | |||
<cfset LOCAL.ret['message'] = "We were unable to set the LatLng for Location: #ARGUMENTS.locId# at this time." /> | |||
<!--- put Error Handling call here ---> | |||
</cfcatch> | |||
</cftry> | |||
<cfreturn LOCAL.ret /> | |||
</cffunction> | |||
</cfcomponent> |