| 1 | <cfcomponent displayName="Page" output="false"> |
|---|
| 2 | |
|---|
| 3 | <cfset variables.dsn = ""> |
|---|
| 4 | <cfset variables.username = ""> |
|---|
| 5 | <cfset variables.password = ""> |
|---|
| 6 | <cfset variables.blog = ""> |
|---|
| 7 | |
|---|
| 8 | <cffunction name="init" returnType="page" output="false" access="public"> |
|---|
| 9 | <cfargument name="dsn" type="string" required="true"> |
|---|
| 10 | <cfargument name="username" type="string" required="true"> |
|---|
| 11 | <cfargument name="password" type="string" requirred="true"> |
|---|
| 12 | <cfargument name="blog" type="string" required="true"> |
|---|
| 13 | |
|---|
| 14 | <cfset variables.dsn = arguments.dsn> |
|---|
| 15 | <cfset variables.username = arguments.username> |
|---|
| 16 | <cfset variables.password = arguments.password> |
|---|
| 17 | <cfset variables.blog = arguments.blog> |
|---|
| 18 | |
|---|
| 19 | <cfreturn this> |
|---|
| 20 | </cffunction> |
|---|
| 21 | |
|---|
| 22 | <cffunction name="deletePage" returnType="void" output="false" access="public"> |
|---|
| 23 | <cfargument name="id" type="uuid" required="true"> |
|---|
| 24 | |
|---|
| 25 | <cfquery datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#"> |
|---|
| 26 | delete from tblblogpages |
|---|
| 27 | where id = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.id#" maxlength="35"> |
|---|
| 28 | and blog = <cfqueryparam cfsqltype="cf_sql_varchar" value="#variables.blog#" maxlength="50"> |
|---|
| 29 | </cfquery> |
|---|
| 30 | </cffunction> |
|---|
| 31 | |
|---|
| 32 | <cffunction name="getPage" returnType="struct" output="false" access="public"> |
|---|
| 33 | <cfargument name="id" type="uuid" required="true"> |
|---|
| 34 | <cfset var q = ""> |
|---|
| 35 | <cfset var s = structNew()> |
|---|
| 36 | |
|---|
| 37 | <cfquery name="q" datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#"> |
|---|
| 38 | select id, blog, title, alias, body |
|---|
| 39 | from tblblogpages |
|---|
| 40 | where id = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.id#" maxlength="35"> |
|---|
| 41 | and blog = <cfqueryparam cfsqltype="cf_sql_varchar" value="#variables.blog#" maxlength="50"> |
|---|
| 42 | </cfquery> |
|---|
| 43 | |
|---|
| 44 | <cfif q.recordCount> |
|---|
| 45 | <cfset s.id = q.id> |
|---|
| 46 | <cfset s.blog = q.blog> |
|---|
| 47 | <cfset s.title = q.title> |
|---|
| 48 | <cfset s.alias = q.alias> |
|---|
| 49 | <cfset s.body = q.body> |
|---|
| 50 | </cfif> |
|---|
| 51 | |
|---|
| 52 | <cfreturn s> |
|---|
| 53 | </cffunction> |
|---|
| 54 | |
|---|
| 55 | <cffunction name="getPageByAlias" returnType="struct" output="false" access="public"> |
|---|
| 56 | <cfargument name="alias" type="string" required="true"> |
|---|
| 57 | <cfset var q = ""> |
|---|
| 58 | <cfset var s = structNew()> |
|---|
| 59 | |
|---|
| 60 | <cfquery name="q" datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#"> |
|---|
| 61 | select id, blog, title, alias, body |
|---|
| 62 | from tblblogpages |
|---|
| 63 | where alias = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.alias#" maxlength="100"> |
|---|
| 64 | and blog = <cfqueryparam cfsqltype="cf_sql_varchar" value="#variables.blog#" maxlength="50"> |
|---|
| 65 | </cfquery> |
|---|
| 66 | |
|---|
| 67 | <cfif q.recordCount> |
|---|
| 68 | <cfset s.id = q.id> |
|---|
| 69 | <cfset s.blog = q.blog> |
|---|
| 70 | <cfset s.title = q.title> |
|---|
| 71 | <cfset s.alias = q.alias> |
|---|
| 72 | <cfset s.body = q.body> |
|---|
| 73 | </cfif> |
|---|
| 74 | |
|---|
| 75 | <cfreturn s> |
|---|
| 76 | </cffunction> |
|---|
| 77 | |
|---|
| 78 | <cffunction name="getPages" returnType="query" output="false" access="public"> |
|---|
| 79 | <cfset var q = ""> |
|---|
| 80 | |
|---|
| 81 | <cfquery name="q" datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#"> |
|---|
| 82 | select id, blog, title, alias, body |
|---|
| 83 | from tblblogpages |
|---|
| 84 | where blog = <cfqueryparam cfsqltype="cf_sql_varchar" value="#variables.blog#" maxlength="50"> |
|---|
| 85 | order by title asc |
|---|
| 86 | </cfquery> |
|---|
| 87 | |
|---|
| 88 | <cfreturn q> |
|---|
| 89 | </cffunction> |
|---|
| 90 | |
|---|
| 91 | <cffunction name="savePage" returnType="void" output="false" access="public"> |
|---|
| 92 | <cfargument name="id" type="string" required="true"> |
|---|
| 93 | <cfargument name="title" type="string" required="true"> |
|---|
| 94 | <cfargument name="alias" type="string" required="true"> |
|---|
| 95 | <cfargument name="body" type="string" required="true"> |
|---|
| 96 | |
|---|
| 97 | <cfif arguments.id is 0> |
|---|
| 98 | <cfset arguments.id = createUUID()> |
|---|
| 99 | |
|---|
| 100 | <cfquery datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#"> |
|---|
| 101 | insert into tblblogpages(id, title, alias, body, blog) |
|---|
| 102 | values( |
|---|
| 103 | <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.id#" maxlength="35">, |
|---|
| 104 | <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.title#" maxlength="255">, |
|---|
| 105 | <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.alias#" maxlength="100">, |
|---|
| 106 | <cfqueryparam cfsqltype="cf_sql_longvarchar" value="#arguments.body#">, |
|---|
| 107 | <cfqueryparam cfsqltype="cf_sql_varchar" value="#variables.blog#" maxlength="35"> |
|---|
| 108 | ) |
|---|
| 109 | </cfquery> |
|---|
| 110 | |
|---|
| 111 | <cfelse> |
|---|
| 112 | |
|---|
| 113 | <cfquery datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#"> |
|---|
| 114 | update tblblogpages |
|---|
| 115 | set |
|---|
| 116 | title = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.title#" maxlength="255">, |
|---|
| 117 | alias = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.alias#" maxlength="100">, |
|---|
| 118 | body = <cfqueryparam cfsqltype="cf_sql_longvarchar" value="#arguments.body#"> |
|---|
| 119 | where id = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.id#" maxlength="35"> |
|---|
| 120 | </cfquery> |
|---|
| 121 | |
|---|
| 122 | </cfif> |
|---|
| 123 | |
|---|
| 124 | </cffunction> |
|---|
| 125 | |
|---|
| 126 | </cfcomponent> |
|---|