PageRenderTime 145ms CodeModel.GetById 60ms app.highlight 4ms RepoModel.GetById 76ms app.codeStats 1ms

/SampleApplication/ColdBox3/model/form/FormService.cfc

http://github.com/bobsilverberg/ValidateThisColdBoxPlugin
ColdFusion CFScript | 72 lines | 55 code | 14 blank | 3 comment | 1 complexity | e0a94533049fcbee59da3d7d4d07ca46 MD5 | raw file
 1<cfcomponent extends="model.abstract.AbstractService" singleton="true" hint="I am a facade for the form package. Note the singleton attribute which is used by ColdBox">
 2
 3	<!---
 4	-------------------------------------------------------------------------
 5	dependancy injection
 6	-------------------------------------------------------------------------
 7	--->
 8	<cfproperty name="MailService" type="coldbox:plugin:MailService" scope="instance">
 9
10	<!---
11	------------------------------------------------------------
12	constructor
13	------------------------------------------------------------
14	--->
15
16	<cfset instance = {}>
17
18	<cffunction name="init" returntype="FormService" output="false">
19		<cfscript>
20		super.init();
21		return this;
22		</cfscript>
23	</cffunction>
24
25	<!---
26	---------------------------------------------------------------------------
27	public
28	---------------------------------------------------------------------------
29	--->
30
31	<cffunction name="getEnquiryRequiredFields" returntype="struct" output="false" hint="returns a struct of required properties">
32		<cfscript>
33		/// path from model root
34		return getRequiredFields( 'form.Enquiry' );
35		</cfscript>
36	</cffunction>
37	
38	<cffunction name="newEnquiry" returntype="Enquiry" output="false" hint="returns an new Enquiry">
39		<cfscript>
40		return new model.form.Enquiry();
41		</cfscript>
42	</cffunction>
43	
44	<cffunction name="sendEnquiry" returntype="ValidateThis.util.Result" output="false" hint="returns an new Enquiry">
45		<cfargument name="params" type="struct" required="true" hint="I am typically the form collection">
46		<cfscript>
47		var ValidatorResult = "";
48		var Enquiry = newEnquiry();
49		var Email = instance.MailService.newMail();
50		
51		// populate model from request collection
52		instance.BeanFactory.populateModel( Enquiry );
53		
54		ValidatorResult = instance.ValidateThis.validate( theObject=Enquiry, objectType="form.Enquiry" );
55
56		if ( ValidatorResult.getIsSuccess() )
57		{
58			email.setTo( "john.whish@crisp-ebusiness.com" );
59			email.setFrom( "john.whish@crisp-ebusiness.com" );
60			email.setSubject( "Enquiry send with the new ColdBox MailService" );
61			email.setType( "html" );
62			email.setBody( "<em>Hello!</em>" );
63			
64			// send it
65			instance.MailService.send( email );
66		}
67		
68		return ValidatorResult;
69		</cfscript>
70	</cffunction>
71	
72</cfcomponent>