<!---
ContactBeanerFilter.cfm
Ben Edwards

This filter makes sure there is always a Contact instance 
_in_the_event_.  It is built form the EventFilter class which
is part of the Mach-ii framework. --Leon Chanlick
--->

<cfcomponent display="ContactBeanerFilter" extends="MachII.framework.EventFilter">
  
  <cffunction name="filterEvent" access="public" returntype="boolean">
    <cfargument name="event" type="MachII.framework.Event" required="true" />
    <cfargument name="eventContext" type="MachII.framework.EventContext" required="true" />
    <cfargument name="paramArgs" type="struct" required="false" default="#StructNew()#" />

    <cfif REQUEST.event.isArgDefined('contact')>
      <!--- Do nothing, it's already there. --->
    <cfelseif IsDefined('REQUEST.contact')>
      <!--- Take it from the REQUEST and put in the event. --->
      <cfset ARGUMENTS.event.setArg('contact', REQUEST.contact) />
    <cfelse>
      <!--- Create it based on parameters in the REQUEST. --->
      <cfset contact = CreateObject('component','ows.38.mii_ContactMgr.model.Contact') />
      
      <cfset contact.setFirstName(ARGUMENTS.event.getArg('firstName','')) />
      <cfset contact.setLastName(ARGUMENTS.event.getArg('lastName','')) />
      <cfset contact.setAddress(ARGUMENTS.event.getArg('Address','')) />
      <cfset contact.setCity(ARGUMENTS.event.getArg('city','')) />
      <cfset contact.setState(ARGUMENTS.event.getArg('state','')) />
      <cfset contact.setZip(ARGUMENTS.event.getArg('zip','')) />
      <cfset contact.setCountry(ARGUMENTS.event.getArg('country','')) />
      <cfset contact.setPhone(ARGUMENTS.event.getArg('phone','')) />
      <cfset contact.setUserLogin(ARGUMENTS.event.getArg('userLogin','')) />
      <cfset contact.setUserPassword(ARGUMENTS.event.getArg('userPassword','')) />
      <cfset contact.setMailingList(ARGUMENTS.event.getArg('mailingList',false)) />
      <cfset ARGUMENTS.event.setArg('contact', contact) />
    </cfif>
    
    <cfreturn true />
  </cffunction>
  
</cfcomponent>