root/trunk/website/forums/cfcs/conference.cfc @ 21

Revision 5, 14.4 kB (checked in by DanWilson, 17 years ago)

Initial Commit Of ModelGlue? Website (upgrade to blogcfc 511)

Line 
1<!---
2        Name         : message.cfc
3        Author       : Raymond Camden
4        Created      : January 25, 2005
5        Last Updated : November 5, 2006
6        History      : Support dbtype, switched to UUID (rkc 1/25/05)
7                                   Fix use of top in mysql (rkc 2/3/05)
8                                   getConferences can now get msgcount, lastpost (rkc 4/4/05)
9                                   New init, use of table prefix (rkc 8/27/05)
10                                   query returns threadid of last post. thanks to shlomy! (rkc 9/15/05)
11                                   limit length of search term (rkc 10/30/05)
12                                   clean up subscriptions (rkc 11/22/05)
13                                   show last user for post, other small fixes (rkc 7/12/06)
14                                   Simple size change (rkc 7/27/06)
15                                   Note to myself on bug to look into (rkc 11/3/06)
16                                   Reverted description to text field (rkc 11/5/06)
17        Purpose          :
18--->
19<cfcomponent displayName="Conference" hint="Handles Conferences, the highest level container for Forums.">
20
21        <cfset variables.dsn = "">
22        <cfset variables.dbtype = "">
23        <cfset variables.tableprefix = "">
24               
25        <cffunction name="init" access="public" returnType="conference" output="false"
26                                hint="Returns an instance of the CFC initialized with the correct DSN.">
27
28                <cfreturn this>
29               
30        </cffunction>
31
32        <cffunction name="addConference" access="remote" returnType="uuid" roles="forumsadmin" output="false"
33                                hint="Adds a conference.">
34                               
35                <cfargument name="conference" type="struct" required="true">
36                <cfset var newconference = "">
37                <cfset var newid = createUUID()>
38               
39                <cfif not validConference(arguments.conference)>
40                        <cfset variables.utils.throw("ConferenceCFC","Invalid data passed to addConference.")>
41                </cfif>
42               
43                <cfquery name="newconference" datasource="#variables.dsn#">
44                        insert into #variables.tableprefix#conferences(id,name,description,active)
45                        values(<cfqueryparam value="#newid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">,
46                                   <cfqueryparam value="#arguments.conference.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">,
47                                   <cfqueryparam value="#arguments.conference.description#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">,
48                                   <cfqueryparam value="#arguments.conference.active#" cfsqltype="CF_SQL_BIT">
49                                   )
50                </cfquery>
51               
52                <cfreturn newid>
53               
54        </cffunction>
55       
56        <cffunction name="deleteConference" access="public" returnType="void" roles="forumsadmin" output="false"
57                                hint="Deletes a conference along with all of it's children.">
58
59                <cfargument name="id" type="uuid" required="true">
60                <cfset var forumKids = "">
61                               
62                <!--- first, delete my children --->
63                <cfset forumKids = variables.forum.getForums(false,arguments.id)>
64                <cfloop query="forumKids">
65                        <cfset variables.forum.deleteForum(forumKids.id)>
66                </cfloop>
67               
68                <cfquery datasource="#variables.dsn#">
69                        delete  from #variables.tableprefix#conferences
70                        where   id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
71                </cfquery>
72
73                <!--- clean up subscriptions --->
74                <cfquery datasource="#variables.dsn#">
75                        delete  from #variables.tableprefix#subscriptions
76                        where   conferenceidfk = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
77                </cfquery>
78               
79        </cffunction>
80
81        <cffunction name="getConference" access="remote" returnType="struct" output="false"
82                                hint="Returns a struct copy of the conferene.">
83                <cfargument name="id" type="uuid" required="true">
84                <cfset var qGetConference = "">
85                               
86                <cfquery name="qGetConference" datasource="#variables.dsn#">
87                        select  id, name, description, active
88                        from    #variables.tableprefix#conferences
89                        where   id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
90                </cfquery>
91
92                <!--- Throw if invalid id passed --->
93                <cfif not qGetConference.recordCount>
94                        <cfset variables.utils.throw("ConferenceCFC","Invalid ID")>
95                </cfif>
96               
97                <!--- Only a ForumsAdmin can get bActiveOnly=false --->
98                <cfif not qGetConference.active and not isUserInRole("forumsadmin")>
99                        <cfset variables.utils.throw("ConferenceCFC","Invalid call to getConferfence")>
100                </cfif>
101               
102                <cfreturn variables.utils.queryToStruct(qGetConference)>
103                       
104        </cffunction>
105               
106        <cffunction name="getConferences" access="remote" returnType="query" output="false"
107                                hint="Returns a list of conferences.">
108
109                <cfargument name="bActiveOnly" type="boolean" required="false" default="true">
110                <cfset var qGetConferences = "">
111               
112                <!--- Only a ForumsAdmin can be bActiveOnly=false --->
113                <cfif not arguments.bActiveOnly and not isUserInRole("forumsadmin")>
114                        <cfset variables.utils.throw("ConferenceCFC","Invalid call to getConferfences")>
115                </cfif>
116               
117                <cfquery name="qGetConferences" datasource="#variables.dsn#">
118                        select #variables.tableprefix#conferences.id,#variables.tableprefix#conferences.name, #variables.tableprefix#conferences.description,
119                        #variables.tableprefix#conferences.active, Count(#variables.tableprefix#messages.id) AS messagecount, max(#variables.tableprefix#messages.posted)
120                        as lastpost,
121                        (
122                        select threadidfk from #variables.tableprefix#messages m where  m.posted = (SELECT max(mm.posted)
123                        as lastpost
124                        from ((#variables.tableprefix#conferences c left JOIN #variables.tableprefix#forums f ON c.id = f.conferenceidfk) left
125                        join #variables.tableprefix#threads t  ON f.id = t.forumidfk) left JOIN #variables.tableprefix#messages mm ON t.id =
126                        mm.threadidfk  where c.id = #variables.tableprefix#conferences.id )
127                        ) as threadidfk,
128(
129select useridfk from #variables.tableprefix#messages m where  m.posted = (SELECT
130max(mm.posted) as lastpost from ((#variables.tableprefix#conferences c left JOIN
131#variables.tableprefix#forums f ON c.id = f.conferenceidfk) left join #variables.tableprefix#threads t  ON
132f.id = t.forumidfk) left JOIN #variables.tableprefix#messages mm ON t.id = mm.threadidfk
133where c.id = #variables.tableprefix#conferences.id )
134) as useridfk
135                        from ((#variables.tableprefix#conferences left JOIN #variables.tableprefix#forums ON #variables.tableprefix#conferences.id =
136                        #variables.tableprefix#forums.conferenceidfk) left JOIN #variables.tableprefix#threads ON #variables.tableprefix#forums.id = #variables.tableprefix#threads.forumidfk)
137                        left JOIN #variables.tableprefix#messages ON #variables.tableprefix#threads.id = #variables.tableprefix#messages.threadidfk
138                        <cfif arguments.bActiveOnly>
139                        where   #variables.tableprefix#conferences.active = 1
140                        </cfif>
141                        GROUP BY #variables.tableprefix#conferences.id,#variables.tableprefix#conferences.name, #variables.tableprefix#conferences.description,
142                        #variables.tableprefix#conferences.active
143                        order by #variables.tableprefix#conferences.name
144                </cfquery>
145               
146                <!---
147                TODO:
148               
149                I discovered a bug that crops up where 2 messages for the same conf have the same date. Need to ping my man Schlomy
150                <cfquery name="qGetConfs" datasource="#variables.dsn#">
151                                select  #variables.tableprefix#conferences.id,#variables.tableprefix#conferences.name, #variables.tableprefix#conferences.description,
152                                #variables.tableprefix#conferences.active, count(#variables.tableprefix#messages.id) AS messagecount, max(#variables.tableprefix#messages.posted) as lastpost
153                        from ((#variables.tableprefix#conferences left JOIN #variables.tableprefix#forums ON #variables.tableprefix#conferences.id =
154                        #variables.tableprefix#forums.conferenceidfk) left JOIN #variables.tableprefix#threads ON #variables.tableprefix#forums.id = #variables.tableprefix#threads.forumidfk)
155                        left JOIN #variables.tableprefix#messages ON #variables.tableprefix#threads.id = #variables.tableprefix#messages.threadidfk
156                        <cfif arguments.bActiveOnly>
157                        where   #variables.tableprefix#conferences.active = 1
158                        </cfif>
159                        GROUP BY #variables.tableprefix#conferences.id,#variables.tableprefix#conferences.name, #variables.tableprefix#conferences.description,
160                        #variables.tableprefix#conferences.active
161
162                        order by #variables.tableprefix#conferences.name
163                </cfquery>
164               
165                <cfset queryAddColumn(qGetConfs, "threadidfk", arrayNew(1))>
166                <cfset queryAddColumn(qGetConfs, "useridfk", arrayNew(1))>
167
168                <cfloop query="qGetConfs">
169               
170                        <cfquery name="test" datasource="#variables.dsn#">
171                        select threadidfk from #variables.tableprefix#messages m where  m.posted =
172                        (
173                                SELECT max(mm.posted)   as lastpost
174                                from ((#variables.tableprefix#conferences c left JOIN #variables.tableprefix#forums f ON c.id = f.conferenceidfk) left
175                                join #variables.tableprefix#threads t  ON f.id = t.forumidfk) left JOIN #variables.tableprefix#messages mm ON t.id =
176                                mm.threadidfk  where c.id = #variables.tableprefix#conferences.id
177                        )
178                       
179                        <cfquery name="getForums" datasource="#variables.dsn#">
180                        select  id
181                        from    #variables.tableprefix#forums
182                        where   conferenceidfk = <cfqueryparam cfsqltype="cf_sql_varchar" value="#id#">
183                        </cfquery>
184                       
185                        <cfif getForums.recordCount>
186
187                                <cfquery name="q" datasource="#variables.dsn#" >
188                                select  max(datecreated) as lastpost
189                                from    #variables.tableprefix#threads
190                                where   forumidfk in (<cfqueryparam cfsqltype="cf_sql_varchar" value="#valueList(getForums.id)#" list="true">)
191                                </cfquery>
192                               
193                                <cfset querySetCell(qGetConfs, "threadidfk", q.lastpost, currentRow)>
194                        </cfif>
195                </cfloop>
196                --->
197               
198                <cfreturn qGetConferences>
199                       
200        </cffunction>
201       
202        <cffunction name="getLatestPosts" access="remote" returnType="query" output="false"
203                                hint="Retrieve the last 20 posts to any threads in forums in this conference.">
204                <cfargument name="conferenceid" type="uuid" required="true">
205                <cfset var qLatestPosts = "">
206               
207                <cfquery name="qLatestPosts" datasource="#variables.dsn#">
208                        select         
209                                <cfif variables.dbtype is not "mysql">
210                                top 20
211                                </cfif>
212                                                #variables.tableprefix#messages.title, #variables.tableprefix#threads.name as thread, #variables.tableprefix#messages.posted, #variables.tableprefix#users.username, #variables.tableprefix#messages.threadidfk as threadid, #variables.tableprefix#messages.body
213                        from            #variables.tableprefix#messages, #variables.tableprefix#threads, #variables.tableprefix#users, #variables.tableprefix#forums
214                        where           #variables.tableprefix#messages.threadidfk = #variables.tableprefix#threads.id
215                        and                     #variables.tableprefix#messages.useridfk = #variables.tableprefix#users.id
216                        and                     #variables.tableprefix#threads.forumidfk = #variables.tableprefix#forums.id
217                        and                     #variables.tableprefix#forums.conferenceidfk = <cfqueryparam value="#arguments.conferenceid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
218                        order by        #variables.tableprefix#messages.posted desc
219                                <cfif variables.dbtype is "mysql">
220                                limit 20
221                                </cfif>
222                </cfquery>
223               
224                <cfreturn qLatestPosts>
225        </cffunction>
226       
227        <cffunction name="saveConference" access="remote" returnType="void" roles="forumsadmin" output="false"
228                                hint="Saves an existing conference.">
229                               
230                <cfargument name="id" type="uuid" required="true">
231                <cfargument name="conference" type="struct" required="true">
232               
233                <cfif not validConference(arguments.conference)>
234                        <cfset variables.utils.throw("ConferfenceCFC","Invalid data passed to saveConference.")>
235                </cfif>
236               
237                <cfquery datasource="#variables.dsn#">
238                        update  #variables.tableprefix#conferences
239                        set             name = <cfqueryparam value="#arguments.conference.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">,
240                                        description = <cfqueryparam value="#arguments.conference.description#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">,
241                                        active = <cfqueryparam value="#arguments.conference.active#" cfsqltype="CF_SQL_BIT">
242                        where   id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
243                </cfquery>
244               
245        </cffunction>
246       
247        <cffunction name="search" access="remote" returnType="query" output="false"
248                                hint="Allows you to search conferences.">
249                <cfargument name="searchterms" type="string" required="true">
250                <cfargument name="searchtype" type="string" required="false" default="phrase" hint="Must be: phrase,any,all">
251               
252                <cfset var results  = "">
253                <cfset var x = "">
254                <cfset var joiner = "">
255                <cfset var aTerms = "">
256
257                <cfset arguments.searchTerms = variables.utils.searchSafe(arguments.searchTerms)>
258
259                               
260                <!--- massage search terms into an array --->           
261                <cfset aTerms = listToArray(arguments.searchTerms," ")>
262               
263               
264                <!--- confirm searchtype is ok --->
265                <cfif not listFindNoCase("phrase,any,all", arguments.searchtype)>
266                        <cfset arguments.searchtype = "phrase">
267                <cfelseif arguments.searchtype is "any">
268                        <cfset joiner = "OR">
269                <cfelseif arguments.searchtype is "all">
270                        <cfset joiner = "AND">
271                </cfif>
272               
273                <cfquery name="results" datasource="#variables.dsn#">
274                        select  id, name, description
275                        from    #variables.tableprefix#conferences
276                        where   active = 1
277                        and (
278                                <cfif arguments.searchtype is not "phrase">
279                                        <cfloop index="x" from=1 to="#arrayLen(aTerms)#">
280                                                (name like <cfqueryparam cfsqltype="CF_SQL_VARCHAR" maxlength="255" value="%#left(aTerms[x],255)#%">
281                                                 or
282                                                 description like '%#aTerms[x]#%')
283                                                 <cfif x is not arrayLen(aTerms)>#joiner#</cfif>
284                                        </cfloop>
285                                <cfelse>
286                                        name like <cfqueryparam cfsqltype="CF_SQL_VARCHAR" maxlength="255" value="%#left(arguments.searchTerms,255)#%">
287                                        or
288                                        description like '%#arguments.searchTerms#%'
289                                </cfif>
290                        )
291                </cfquery>
292               
293                <cfreturn results>
294        </cffunction>
295       
296        <cffunction name="validConference" access="private" returnType="boolean" output="false"
297                                hint="Checks a structure to see if it contains all the proper keys/values for a conference.">
298               
299                <cfargument name="cData" type="struct" required="true">
300                <cfset var rList = "name,description,active">
301                <cfset var x = "">
302               
303                <cfloop index="x" list="#rList#">
304                        <cfif not structKeyExists(cData,x)>
305                                <cfreturn false>
306                        </cfif>
307                </cfloop>
308               
309                <cfreturn true>
310               
311        </cffunction>
312       
313        <cffunction name="setSettings" access="public" output="No" returntype="void">
314                <cfargument name="settings" required="true" hint="Setting">
315                <cfset variables.dsn = arguments.settings.getSettings().dsn>
316                <cfset variables.dbtype = arguments.settings.getSettings().dbtype>
317                <cfset variables.tableprefix = arguments.settings.getSettings().tableprefix>
318        </cffunction>
319       
320        <cffunction name="setUtils" access="public" output="No" returntype="void">
321                <cfargument name="utils" required="true" hint="utils">
322                <cfset variables.utils = arguments.utils />
323        </cffunction>
324
325        <cffunction name="setForum" access="public" output="No" returntype="void">
326                <cfargument name="forum" required="true" hint="forum">
327                <cfset variables.forum = arguments.forum />
328        </cffunction>
329       
330</cfcomponent>
Note: See TracBrowser for help on using the browser.