CMS  Version 3.9
forum_manager.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
39 
41 {
42  function ForumManager()
43  {
44 
45  }
46 
47  static $userProfileHandler = null;
48 
49  static function initializeUserProfileHandler()
50  {
52  {
54  ComponentManager::fireEvent("RegisterForumUserProfileHandler");
55  }
56  }
57 
59  {
61  }
62 
63  static function formatUserProfile($u)
64  {
66  return call_user_func_array(ForumManager::$userProfileHandler, array($u));
67  }
68 
70  {
71  return $user->getFullName();
72  }
73 
74  static function displayForum($identifier, &$continue)
75  {
76  global $page_role;
77 
78  try
79  {
81  $page = ComponentPage::findByIdentifier("forum_details", "WHERE enabled=1");
82  $_GET["forum_id"] = $forum->forum_id;
83 
84  $pageView = new ComponentPageView($page, "{$page->template}.tpl");
85 
86  $page_role = $page->role;
87 
88  if (!checkRole($page->role))
89  {
91  redirect("/login");
92  }
93 
94  echo $pageView->drawView();
95 
96  $continue = false;
97  }
98  catch(DataNotFoundException $e)
99  {
100 
101  }
102 
103  return $identifier;
104  }
105 
106  static function enumerateFora($items)
107  {
108  $pages = Query::create(Forum, "WHERE identifier IS NOT NULL AND identifier != '' ORDER BY title")->execute();
109 
110  $items["Discussion Forums"] = $pages;
111  return $items;
112  }
113 
114  static function setDefaults()
115  {
116  Settings::setDefaultValue("forum", "forum_list_items_per_page", 0, Number, "Number of items per page on the forum list (0 for no pagination)");
117  Settings::setDefaultValue("forum", "forum_topics_per_page", 0, Number, "Number of topics per page on the forum list (0 for no pagination)");
118  }
119 
120 
128  static function deleteUser($user)
129  {
130  $pk = $user->getPrimaryKey();
131  $user_id = $user->$pk;
132 
133  trace("Component forum is deleting objects dependent on user_id {$user_id}", 3);
134 
135  $tx = new DataTransaction();
136 
137  try
138  {
139  $forums = Query::create(Forum, "WHERE owner_id=:owner_id")
140  ->bind(":owner_id", $user_id)
141  ->execute();
142 
143  if(count($forums))
144  {
145  foreach($forums as $forum)
146  {
147  $forum->joinTransaction($tx);
149  }
150  }
151 
152  $messages = Query::create(ForumMessage, "WHERE author_id=:author_id")
153  ->bind(":author_id", $user_id)
154  ->execute();
155 
156  if(count($messages))
157  {
158  foreach($messages as $message)
159  {
160  $message->joinTransaction($tx);
162  }
163  }
164 
165  $tx->commit();
166  }
167  catch(Exception $e)
168  {
169  $tx->rollback();
170  throw $e;
171  }
172 
173  return $user;
174  }
175 
183  static function deleteForum($forum)
184  {
185  $forum_id = $forum->forum_id;
186 
187  $tx = new DataTransaction();
188 
189  try
190  {
191  $forum->joinTransaction($tx);
192 
193  $topic = new ForumTopic();
194  $topic->joinTransaction($tx);
195  $topic->delete("WHERE forum_id={$forum_id}");
196 
197  $messages = $forum->Messages();
198 
199  if(count($messages))
200  {
201  foreach($messages as $message)
202  {
203  $message->joinTransaction($tx);
205  }
206  }
207 
208  $xref = new ForumSiteXref();
209  $xref->joinTransaction($tx);
210  $xref->delete("WHERE forum_id={$forum_id}");
211 
212  $forum->delete();
213 
214  $tx->commit();
215  }
216  catch(Exception $e)
217  {
218  $tx->rollback();
219  throw $e;
220  }
221  }
222 
223  static function deleteForumMessage($message)
224  {
225  $tx = new DataTransaction();
226 
227  try
228  {
229  $message->joinTransaction($tx);
230 
231  $attachments = $message->Attachments();
232  if(count($attachments))
233  {
234  $xref = new ForumMessageAttachmentXref();
235  $xref->joinTransaction($tx);
236 
237  foreach($attachments as $attachment)
238  {
239  $attachment->joinTransaction($tx);
240  $attachment->delete();
241  $xref->delete("WHERE attachment_id={$attachment->attachment_id}");
242  }
243  }
244  $message->delete();
245 
246  $tx->commit();
247  }
248  catch(Exception $e)
249  {
250  $tx->rollback();
251  throw $e;
252  }
253  }
254 
255  static function upgradeComponent($version)
256  {
257  $mgr = new ForumUpgradeManager();
258  $mgr->upgrade($version);
259  }
260 
262  {
263  $classes[] = Forum;
264  return $classes;
265  }
266 }?>
$user_id
$handler
Definition: event_form.inc:62
$forum_id
Definition: forum_form.inc:39
$page
Definition: help.inc:39
if(! $attachment_id) $attachment
Definition: delete.inc:42
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
static findByIdentifier($identifier, $constraint="")
ComponentPageView generates the page content for a component page, substituting page fields,...
Definition: forum.inc:42
static findByIdentifier($identifier)
Definition: forum.inc:131
static upgradeComponent($version)
static deleteForum($forum)
When deleting a forum, we must delete topics, messages, attachments and site xrefs.
static registerUserProfileHandler($handler)
static deleteForumMessage($message)
static formatUserProfile($u)
static defaultUserProfileHandler($user)
static initializeUserProfileHandler()
static $userProfileHandler
static registerTaxonomyClasses($classes)
static deleteUser($user)
Respond to fired event DeleteUser.
static displayForum($identifier, &$continue)
static setDefaults()
static enumerateFora($items)
static storeRedirectPage()
Store the page from which a user has been redirected when prompted to login or create an account.
Definition: login.inc:493
static setDefaultValue($component, $name, $value, $field_type="String", $annotation="", $category="", $options="", $weight=0)
Sets the default value of the given component setting.
Definition: settings.inc:174
global $user
$messages
$message
Definition: mail_to.inc:49
$pages
Definition: export.inc:38
$identifier
Definition: rss.inc:37
$topic
Definition: topic_form.inc:42