5 # Part of the Collection Workflow Integration System (CWIS) 6 # Copyright 2002-2013 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu/cwis/ 17 # ---- PUBLIC INTERFACE -------------------------------------------------- 30 public static function Create($Name, $ModeratorId, $Description = NULL)
33 $ModeratorId = intval($ModeratorId);
39 throw new InvalidArgumentException(
"Specified ForumName is empty.");
42 # check if the ID provided is a valid user ID and has privilege 44 if ($Factory->UserExists($ModeratorId))
46 $Moderator =
new CWUser($ModeratorId);
47 if (!$Moderator->HasPriv(PRIV_FORUMADMIN))
49 throw new InvalidArgumentException(
"Specified moderator ID (" 50 .$ModeratorId.
") is not a forum administrator.");
55 throw new InvalidArgumentException(
"Specified moderator ID (" 56 .$ModeratorId.
") is not found.");
59 # set description if there is any 60 if (!is_null($Description))
62 $Query =
"INSERT INTO Forums (ForumName, ModeratorId, ForumDescription)".
63 " VALUES ('".addslashes($Name).
"', '".addslashes($ModeratorId).
"', '" 64 .addslashes($Description).
"')";
68 $Query =
"INSERT INTO Forums (ForumName, ModeratorId) VALUES ('" 69 .addslashes($Name).
"', '".addslashes($ModeratorId).
"')";
76 $ForumId =
$DB->LastInsertId();
78 return (
new Forum($ForumId));
86 $this->DB->Query(
"SELECT * FROM Topics WHERE ForumId = ".
87 $this->
Id().
" ORDER BY DateCreated DESC");
89 # get list of topics for this forum 90 while ($Entry = $this->DB->FetchRow())
92 $Topic =
new Topic($Entry[
"TopicId"]);
95 # delete record from database 123 return GetPrettyTimestamp($Message->DatePosted()).
" by ";
140 return $Message->PosterName();
153 return $Message->PosterEmail();
167 if ($UserFactory->UserExists($UserId))
169 return (
new CWUser($UserId))->Get(
"UserName");
187 if ($UserFactory->UserExists($UserId))
189 return (
new CWUser($UserId))->Get(
"EMail");
205 $this->DB->Query(
"SELECT * FROM Topics WHERE ForumId = '".
206 addslashes($this->
Id()).
"' ORDER BY DateCreated DESC");
208 # get list of topics for this forum 209 while ($Entry = $this->DB->FetchRow())
211 $Topics[$Entry[
"TopicId"]] =
new Topic($Entry[
"TopicId"]);
226 SELECT M.* FROM Messages M 228 ON M.ParentId = T.TopicId 230 AND T.ForumId = '".addslashes($this->
Id()).
"' 231 ORDER BY DatePosted DESC 234 if ($this->DB->NumRowsSelected())
236 $Row = $this->DB->FetchRow();
237 $Message =
new Message($Row[
"MessageId"]);
260 return $this->
UpdateValue(
"ForumDescription", $NewValue);
270 return $this->
UpdateValue(
"TopicCount", $NewValue);
280 return $this->
UpdateValue(
"MessageCount", $NewValue);
291 return $this->
UpdateValue(
"ModeratorId", $NewValue);
304 public function AddTopic($Author, $TopicName, $Subject, $Body)
307 $Topic->TopicName($TopicName);
308 $Topic->DateCreated(date(
"YmdHis"));
309 $Topic->ForumId($this->
Id());
310 $Topic->CreatorId($Author->Id());
314 $this->
PostMessage($Topic->TopicId(), $Author, $Subject, $Body);
316 return $Topic->TopicId();
328 $Topic =
new Topic($TopicId);
330 # create a new message 332 $Message->ParentId($TopicId);
334 $Message->DatePosted(date(
"YmdHis"));
335 $Message->PosterId($Author->Id());
336 $Message->Subject($Subject);
337 $Message->Body($Body);
339 # update counts for topic and forum 342 $Topic->MessageCount($Topic->MessageCount() + 1);
353 $Message =
new Message($MessageId);
355 $TopicId = $Message->ParentId();
356 $Topic =
new Topic($TopicId);
358 $ForumId = $Topic->ForumId();
359 $Forum =
new Forum($ForumId);
361 # update count for topic and forum and delete message 362 $Topic->MessageCount($Topic->MessageCount() - 1 );
363 $Forum->MessageCount($Forum->MessageCount() - 1 );
AddTopic($Author, $TopicName, $Subject, $Body)
Add topic to forum.
Abstraction for forum messages and resource comments.
MessageCount($NewValue=DB_NOVALUE)
Get or set the forum's message count.
UpdateValue($ColumnName, $NewValue=DB_NOVALUE)
Convenience function to supply parameters to Database::UpdateValue().
A converastion forum which includes topics and messages.
static Create()
Create an empty message object.
SQL database abstraction object with smart query caching.
LastMessageDate()
Get the date of the most recent post to the forum.
ModeratorEmail()
Get the e-mail address of the forum's moderator.
ForumDescription($NewValue=DB_NOVALUE)
Get or modify the forum description.
Abstraction for topics within a Forum.
TopicCount($NewValue=DB_NOVALUE)
Get or set the forum's topic count.
LastMessagePosterEmail()
Get the e-mail address of the user with the most recent post.
GetLastMessage()
Get the last message posted in the forum.
CWIS-specific user factory class.
static Create()
Create an empty new topic.
Common base class for persistent items store in database.
static Create($Name, $ModeratorId, $Description=NULL)
Create a forum.
PostMessage($TopicId, $Author, $Subject, $Body)
Post new message to topic.
static DeleteMessage($MessageId)
Delete a message from a forum, updating the message counts for the associated forum and topic...
ForumId()
Get the forum's ID.
ModeratorId($NewValue=DB_NOVALUE)
Get or set the forum's moderator.
Delete()
Remove this forum, deleting all assocated topics and messages.
GetTopicList()
Get the list of the topics in this forum.
ForumName($NewValue=DB_NOVALUE)
Get or modify the forum's name.
ModeratorName()
Get the CWIS username of the forum's moderator.
LastMessagePoster()
Get the CWIS username of the user with the most recent post.
CWIS-specific user class.