Browse files

Initial commit.

  • Loading branch information...
0 parents commit 40d37480bed36f26e200e72fd32f9a908c5979a6 @rarneson committed Sep 21, 2011
Showing with 96 additions and 0 deletions.
  1. +15 −0 app/controllers/ExporterController.cfc
  2. +46 −0 app/util/ExcelUtil.cfc
  3. +35 −0 app/util/ExporterUtil.cfc
15 app/controllers/ExporterController.cfc
@@ -0,0 +1,15 @@
+/**
+ * @extends coldmvc.Controller
+ * @accessors true
+ */
+component {
+
+ property ExporterUtil;
+
+ public function purge() {
+
+ exporterUtil.purge();
+
+ }
+
+}
46 app/util/ExcelUtil.cfc
@@ -0,0 +1,46 @@
+<cfcomponent accessors="true" singleton="true">
+
+ <cfproperty name="exporterUtil" />
+
+ <cffunction name="download" access="public" returntype="void" output="false" actionHelper="toExcel">
+ <cfargument name="records" type="query" required="true" />
+ <cfargument name="name" type="string" required="false" default="Export" />
+
+ <!--- set our folder path for the export destination --->
+ <cfset local.folder = exporterUtil.getPath() />
+
+ <!--- create local.folder if it doesn't exist --->
+ <cfif not directoryExists(local.folder)>
+ <cfset directoryCreate(local.folder)>
+ </cfif>
+
+ <!--- create date/timestamp variables to be used for naming our file --->
+ <cfset local.datestamp = dateFormat(now(), "mmddyy") />
+ <cfset local.timestamp = timeFormat(now(), "HHmmss") />
+
+ <!--- generate our file name using the name provided + the date/time stamp --->
+ <cfset local.filename = arguments.name & "_" & local.datestamp & "_" & local.timestamp & ".xls" />
+
+ <!--- publish our query object to excel --->
+ <cfspreadsheet
+ action="write"
+ filename="#local.folder##local.filename#"
+ overwrite="true"
+ query="arguments.records" />
+
+ <!--- serve up our file to the user to allow them to open or save --->
+ <cfif fileExists(local.folder & local.filename)>
+
+ <cfset local.fileInfo = GetFileInfo(local.folder & local.filename) />
+ <cfset local.mimeType = getPageContext().getServletContext().getMimeType(local.folder & local.filename) />
+
+ <cfheader name="Content-Disposition" value="attachment; filename=#local.filename#" />
+ <cfheader name="Expires" value="#Now()#" />
+ <cfheader name="Content-Length" value="#local.fileInfo.size#" />
+
+ <cfcontent type="#local.mimeType#" file="#local.folder##local.filename#" deletefile="No" />
+ </cfif>
+
+ </cffunction>
+
+</cfcomponent>
35 app/util/ExporterUtil.cfc
@@ -0,0 +1,35 @@
+<cfcomponent output="false" singleton="true">
+
+ <cffunction name="purge" access="public" returntype="void" output="false" events="applicationStart">
+
+ <cfset local.folder = getPath() />
+
+ <cfif directoryExists(local.folder)>
+
+ <cfset directoryDelete(local.folder,true) />
+
+ </cfif>
+
+ </cffunction>
+
+ <cffunction name="schedule" access="public" returntype="void" output="false" events="applicationStart">
+
+ <cfschedule
+ action="update"
+ task="Purge NCFPD Research Database Exports"
+ startDate="#now()#"
+ startTime="#now()#"
+ interval="daily"
+ operation="HTTPRequest"
+ url='#$.link.to({controller="exporter",action="purge"})#' />
+
+ </cffunction>
+
+ <cffunction name="getPath" access="public" returntype="string" output="false">
+
+ <!--- set our folder path for the export destination --->
+ <cfreturn expandPath("/plugins/exporter/temp/") />
+
+ </cffunction>
+
+</cfcomponent>

0 comments on commit 40d3748

Please sign in to comment.