Skip to content
Browse files

Refactor of the Locations component as a fully scripted CFC, plus

updates to the ReadMe file
  • Loading branch information...
1 parent a235180 commit 147990e4b04b938339ebb03de8cf672554e4b465 @cutterbl committed
Showing with 189 additions and 93 deletions.
  1. +5 −0 README.txt
  2. +88 −93 cfc/Locations.cfc
  3. +96 −0 cfc/Locations.unscripted
View
5 README.txt
@@ -3,6 +3,11 @@ Demo requires ColdFusion 8 or higher. Demo requires that this directoy (CFGMap)
the root directory of the site. If you choose to do otherwise, please update all
pathing accordingly.
+The Locations.cfc comes in two flavors: scripted and unscripted. The default (scripted)
+version is for ColdFusion 9. Currently all calls will ultimately fail, as there is no
+datasource. This component is for example only, of how a developer can use the geocoding
+callback to database the Lat/Lng results for locations.
+
Further information can be found by reading the comments in the code, and through the
blog entries:
View
181 cfc/Locations.cfc
@@ -1,96 +1,91 @@
-<!--- ===========================================================================
-// 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
-// ******************************************************************************
-=========================================================================== --->
+/**
+ * ===========================================================================
+ * 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:
+ * ***************************************************************************
+ * C [04.11.2012]
+ * Refactor as a scripted component
+ * ***************************************************************************
+ * 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">
- <cfset VARIABLES.DSN = "" />
+ 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 correctLocsLatLng
+ * A function to get paging query of blog entries for layout in jqGrid
+ * 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.
+ *
+ * @access remote
+ * @returnType struct
+ * @output false
+ */
+ function correctLocsLatLng(required string corrArr) {
+ LOCAL.retVal = {'success' = true, 'message' = ''};
+ if(IsJSON(ARGUMENTS.corrArr)) {
+ LOCAL.set = DeserializeJSON(ARGUMENTS.corrArr);
+ } else {
+ LOCAL.retVal = {'success' = false, 'message' = 'The argument passed is not valid JSON.'};
+ }
+ try {
+ for(LOCAL.i = 1; LOCAL.i <= ArrayLen(LOCAL.set); LOCAL.i++) {
+ LOCAL.try = setGMapLatLng(argumentCollection:LOCAL.set[LOCAL.i]);
+ if(!LOCAL.try.success) {
+ throw(type = "custom_map_error", errorcode = "cme_01", detail = SerializeJSON({'location' = LOCAL.set[LOCAL.i]}), message = LOCAL.try.message);
+ }
+ }
+ } catch(any err) {
+ LOCAL.retVal = {'success' = false, 'message' = err.message, 'detail' = DeserializeJSON(err.detail), 'errorcode' = err.errorcode};
+ // Add any error logging and admin notifications
+ }
+ return LOCAL.retVal;
+ }
- <!---
- // 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>
+ /**
+ * FUNCTION setGMapLatLng
+ * Updates the lat/lng info in a record of a specific location
+ *
+ * @access private
+ * @returnType struct
+ * @output false
+ */
+ function setGMapLatLng(required numeric locId, required numeric lat, required numeric lng) {
+ LOCAL.retVal = {'success' = true, 'message' = ''};
+ // Main data query
+ LOCAL.sql = "UPDATE Location
+ SET Latitude = :lat,
+ Longitude = :lng
+ WHERE ID = :locId";
+ LOCAL.q = new Query(sql = LOCAL.sql, datasource = VARIABLES.dsn);
+ LOCAL.q.addParam(name = "locId", value = ARGUMENTS.locId, cfsqltype = "cf_sql_integer");
+ LOCAL.q.addParam(name = "lat", value = ARGUMENTS.lat, cfsqltype = "cf_sql_integer");
+ LOCAL.q.addParam(name = "lng", value = ARGUMENTS.lng, cfsqltype = "cf_sql_integer");
+ try {
+ LOCAL.q.execute();
+ } catch(any err) {
+ LOCAL.retVal = {'success' = false, 'message' = 'We were unable to set the LatLng for Location: #ARGUMENTS.locId# at this time.'};
+ // Add any error logging and admin notifications
+ }
+ return LOCAL.retVal;
+ }
+
+}
View
96 cfc/Locations.unscripted
@@ -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>

0 comments on commit 147990e

Please sign in to comment.
Something went wrong with that request. Please try again.