Thanks Peter. Bonus on actually writing it out. Ultimately, I was just trying to understand the PHP a bit better.
-----Original Message----- From: Peter Boughton [mailto:[email protected]] Subject: Re: PHP to CF pseudo code... Not sure it's how I'd write a rating widget, but here's a fairly direct translation. (Untested, so may contain stupid bugs.) <cffunction name="in_range" returntype="Numeric" output="false"> <cfargument name="Val" type="Numeric" /> <cfargument name="From" type="Numeric" default="0" /> <cfargument name="To" type="Numeric" default="100" /> <cfreturn min( Arguments.To , max( Arguments.From , Arguments.Val ) ) /> </cffunction> <cffunction name="get_dbfile" returntype="string" output="false"> <!--- I *think* __FILE__ from original is a global constant... not really sure? I've plonked it into Application ---> <cfreturn rereplace( Application.File , '\.php$' , '.dat' ) /> </cffunction> <cffunction name="get_votes" returntype="Struct" output="false"> <cfset var dbfile = get_dbfile() /> <cfif FileExists(dbfile)> <cfreturn deserializeJson( FileRead(dbfile) )/> <cfelse> <cfreturn { votes : 0 , sum : 0 , avg : 0 } /> </cfif> </cffunction> <cffunction name="save_vote" returntype="Struct" output="false"> <cfargument name="Vote" type="Numeric" /> <cfscript> var db = get_votes() ; db.votes++ ; db.sum += Arguments.Vote ; db.avg = round( 100 * db.sum / db.votes ) / 100 ; FileWrite( get_dbfile() , serializeJson( db ) ) ; </cfscript> <cfreturn db /> </cffunction> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:323968 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

