| 1 | <!--- |
|---|
| 2 | Name : rank.cfc |
|---|
| 3 | Author : Raymond Camden |
|---|
| 4 | Created : August 28, 2005 |
|---|
| 5 | Last Updated : |
|---|
| 6 | History : |
|---|
| 7 | Purpose : |
|---|
| 8 | ---> |
|---|
| 9 | <cfcomponent displayName="Rank" hint="Handles Ranks. It's not stinky."> |
|---|
| 10 | |
|---|
| 11 | <cfset variables.dsn = ""> |
|---|
| 12 | <cfset variables.dbtype = ""> |
|---|
| 13 | <cfset variables.tableprefix = ""> |
|---|
| 14 | |
|---|
| 15 | <cffunction name="init" access="public" returnType="rank" output="false" |
|---|
| 16 | hint="Returns an instance of the CFC initialized with the correct DSN."> |
|---|
| 17 | <cfreturn this> |
|---|
| 18 | |
|---|
| 19 | </cffunction> |
|---|
| 20 | |
|---|
| 21 | <cffunction name="addRank" access="remote" returnType="uuid" roles="forumsadmin" output="false" |
|---|
| 22 | hint="Adds a rank."> |
|---|
| 23 | |
|---|
| 24 | <cfargument name="rank" type="struct" required="true"> |
|---|
| 25 | <cfset var newid = createUUID()> |
|---|
| 26 | |
|---|
| 27 | <cfif not validRank(arguments.rank)> |
|---|
| 28 | <cfset variables.utils.throw("RankCFC","Invalid data passed to addRank.")> |
|---|
| 29 | </cfif> |
|---|
| 30 | |
|---|
| 31 | <cfquery datasource="#variables.dsn#"> |
|---|
| 32 | insert into #variables.tableprefix#ranks(id,name,minposts) |
|---|
| 33 | values(<cfqueryparam value="#newid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">, |
|---|
| 34 | <cfqueryparam value="#arguments.rank.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">, |
|---|
| 35 | <cfqueryparam value="#arguments.rank.minposts#" cfsqltype="CF_SQL_INTEGER">) |
|---|
| 36 | </cfquery> |
|---|
| 37 | |
|---|
| 38 | <cfreturn newid> |
|---|
| 39 | |
|---|
| 40 | </cffunction> |
|---|
| 41 | |
|---|
| 42 | <cffunction name="deleteRank" access="public" returnType="void" roles="forumsadmin" output="false" |
|---|
| 43 | hint="Deletes a rank."> |
|---|
| 44 | |
|---|
| 45 | <cfargument name="id" type="uuid" required="true"> |
|---|
| 46 | |
|---|
| 47 | <cfquery datasource="#variables.dsn#"> |
|---|
| 48 | delete from #variables.tableprefix#ranks |
|---|
| 49 | where id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 50 | </cfquery> |
|---|
| 51 | |
|---|
| 52 | </cffunction> |
|---|
| 53 | |
|---|
| 54 | <cffunction name="getHighestRank" access="public" returnType="string" output="false" |
|---|
| 55 | hint="For a 'minpost' value, returns the highest rank"> |
|---|
| 56 | <cfargument name="minposts" type="numeric" required="true"> |
|---|
| 57 | <cfset var qGetRank = ""> |
|---|
| 58 | |
|---|
| 59 | <cfquery name="qGetRank" datasource="#variables.dsn#"> |
|---|
| 60 | select |
|---|
| 61 | <cfif variables.dbtype is not "mysql"> |
|---|
| 62 | top 1 |
|---|
| 63 | </cfif> |
|---|
| 64 | name |
|---|
| 65 | from #variables.tableprefix#ranks |
|---|
| 66 | where minposts <= <cfqueryparam value="#arguments.minposts#" cfsqltype="cf_sql_numeric"> |
|---|
| 67 | order by minposts desc |
|---|
| 68 | <cfif variables.dbtype is "mysql"> |
|---|
| 69 | limit 1 |
|---|
| 70 | </cfif> |
|---|
| 71 | </cfquery> |
|---|
| 72 | |
|---|
| 73 | <cfreturn qGetRank.name> |
|---|
| 74 | |
|---|
| 75 | </cffunction> |
|---|
| 76 | |
|---|
| 77 | <cffunction name="getRank" access="remote" returnType="struct" output="false" |
|---|
| 78 | hint="Returns a struct copy of the rank."> |
|---|
| 79 | <cfargument name="id" type="uuid" required="true"> |
|---|
| 80 | <cfset var qGetRank = ""> |
|---|
| 81 | |
|---|
| 82 | <cfquery name="qGetRank" datasource="#variables.dsn#"> |
|---|
| 83 | select id, name, minposts |
|---|
| 84 | from #variables.tableprefix#ranks |
|---|
| 85 | where id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 86 | </cfquery> |
|---|
| 87 | |
|---|
| 88 | <!--- Throw if invalid id passed ---> |
|---|
| 89 | <cfif not qGetRank.recordCount> |
|---|
| 90 | <cfset variables.utils.throw("RankCFC","Invalid ID")> |
|---|
| 91 | </cfif> |
|---|
| 92 | |
|---|
| 93 | <cfreturn variables.utils.queryToStruct(qGetRank)> |
|---|
| 94 | |
|---|
| 95 | </cffunction> |
|---|
| 96 | |
|---|
| 97 | <cffunction name="getRanks" access="remote" returnType="query" output="false" |
|---|
| 98 | hint="Returns a list of ranks."> |
|---|
| 99 | <cfset var qGetRanks = ""> |
|---|
| 100 | |
|---|
| 101 | <cfquery name="qGetRanks" datasource="#variables.dsn#"> |
|---|
| 102 | select id, name, minposts |
|---|
| 103 | from #variables.tableprefix#ranks |
|---|
| 104 | </cfquery> |
|---|
| 105 | |
|---|
| 106 | <cfreturn qGetRanks> |
|---|
| 107 | |
|---|
| 108 | </cffunction> |
|---|
| 109 | |
|---|
| 110 | <cffunction name="saveRank" access="remote" returnType="void" roles="forumsadmin" output="false" |
|---|
| 111 | hint="Saves an existing rank."> |
|---|
| 112 | |
|---|
| 113 | <cfargument name="id" type="uuid" required="true"> |
|---|
| 114 | <cfargument name="rank" type="struct" required="true"> |
|---|
| 115 | |
|---|
| 116 | <cfif not validRank(arguments.rank)> |
|---|
| 117 | <cfset variables.utils.throw("RankCFC","Invalid data passed to saveRank.")> |
|---|
| 118 | </cfif> |
|---|
| 119 | |
|---|
| 120 | <cfquery datasource="#variables.dsn#"> |
|---|
| 121 | update #variables.tableprefix#ranks |
|---|
| 122 | set name = <cfqueryparam value="#arguments.rank.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">, |
|---|
| 123 | minposts = <cfqueryparam value="#arguments.rank.minposts#" cfsqltype="CF_SQL_INTEGER"> |
|---|
| 124 | where id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 125 | </cfquery> |
|---|
| 126 | |
|---|
| 127 | </cffunction> |
|---|
| 128 | |
|---|
| 129 | <cffunction name="validRank" access="private" returnType="boolean" output="false" |
|---|
| 130 | hint="Checks a structure to see if it contains all the proper keys/values for a rank."> |
|---|
| 131 | |
|---|
| 132 | <cfargument name="cData" type="struct" required="true"> |
|---|
| 133 | <cfset var rList = "name,minposts"> |
|---|
| 134 | <cfset var x = ""> |
|---|
| 135 | |
|---|
| 136 | <cfloop index="x" list="#rList#"> |
|---|
| 137 | <cfif not structKeyExists(cData,x)> |
|---|
| 138 | <cfreturn false> |
|---|
| 139 | </cfif> |
|---|
| 140 | </cfloop> |
|---|
| 141 | |
|---|
| 142 | <cfreturn true> |
|---|
| 143 | |
|---|
| 144 | </cffunction> |
|---|
| 145 | |
|---|
| 146 | <cffunction name="setSettings" access="public" output="No" returntype="void"> |
|---|
| 147 | <cfargument name="settings" required="true" hint="Setting"> |
|---|
| 148 | <cfset variables.dsn = arguments.settings.getSettings().dsn /> |
|---|
| 149 | <cfset variables.dbtype = arguments.settings.getSettings().dbtype /> |
|---|
| 150 | <cfset variables.tableprefix = arguments.settings.getSettings().tableprefix /> |
|---|
| 151 | </cffunction> |
|---|
| 152 | |
|---|
| 153 | <cffunction name="setUtils" access="public" output="No" returntype="void"> |
|---|
| 154 | <cfargument name="utils" required="true" hint="utils"> |
|---|
| 155 | <cfset variables.utils = arguments.utils /> |
|---|
| 156 | </cffunction> |
|---|
| 157 | </cfcomponent> |
|---|