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 -------------------------------------------------- 19 # Error codes for the forum object 37 $this->ErrorStatus = self::OK;
38 # locate class in database 42 if ($ForumId !== NULL)
44 $this->
ForumId = intval($ForumId);
45 $DB->Query(
"SELECT * FROM Forums WHERE ForumId = " 49 if ($DB->NumRowsSelected() > 0)
51 # set attributes to values returned by database 52 $this->DBFields = $DB->FetchRow();
56 $this->ErrorStatus = self::NONEXISTENT;
59 elseif (func_num_args()==0)
61 # add record to database with that ID 62 $DB->Query(
"INSERT INTO Forums (ForumId) VALUES (NULL)");
63 $this->
ForumId = $DB->Query(
"SELECT LAST_INSERT_ID() AS ForumId" 64 .
" FROM Forums",
"ForumId");
68 $this->ErrorStatus = self::NONEXISTENT;
78 if ($this->ErrorStatus == self::OK)
80 $this->DB->Query(
"Select * from Topics where ForumId = ".
81 $this->
ForumId.
" ORDER BY DateCreated Desc");
83 # get list of topics for this forum 84 while ($Entry = $this->DB->FetchRow())
86 $Topic =
new Topic($Entry[
"TopicId"]);
89 # delete record from database 90 $this->DB->Query(
"DELETE FROM Forums WHERE ForumId = ".$this->
ForumId);
104 return $this->ForumId; }
114 if (isset($Message)) {
115 return $Message->DatePosted().
" by "; }
127 if (isset($Message)) {
128 return $Message->PosterName(); }
138 if (isset($Message)) {
139 return $Message->PosterEmail(); }
149 return $ModeratorName->Get(
"UserName");
159 return $ModeratorName->Get(
"EMail");
170 $this->DB->Query(
"Select * from Topics where ForumId = ".
171 $this->
ForumId.
" ORDER BY DateCreated Desc");
173 # get list of topics for this forum 174 while ($Entry = $this->DB->FetchRow())
176 $Topics[$Entry[
"TopicId"]] =
new Topic($Entry[
"TopicId"]);
191 SELECT M.* FROM Messages M 193 ON M.ParentId = T.TopicId 195 AND T.ForumId = '".addslashes($this->
ForumId).
"' 196 ORDER BY DatePosted DESC 199 if ($this->DB->NumRowsSelected())
201 $Row = $this->DB->FetchRow();
202 $Message =
new Message($Row[
"MessageId"]);
215 return $this->UpdateValue(
"ForumName", $NewValue);
225 return $this->UpdateValue(
"ForumDescription", $NewValue);
235 return $this->UpdateValue(
"TopicCount", $NewValue);
245 return $this->UpdateValue(
"MessageCount", $NewValue);
256 return $this->UpdateValue(
"ModeratorId", $NewValue);
265 return $this->ErrorStatus;
278 public function AddTopic($Author, $TopicName, $Subject, $Body)
280 $Topic =
new Topic();
282 $Topic->TopicName($TopicName);
283 $Topic->DateCreated(date(
"YmdHis"));
284 $Topic->ForumId($this->
ForumId);
285 $Topic->ViewCount(
"0");
286 $Topic->MessageCount(
"0");
287 $Topic->CreatorId($Author->Id() );
291 $this->
PostMessage($Topic->TopicId(), $Author, $Subject, $Body);
293 return $Topic->TopicId();
305 $Topic =
new Topic($TopicId);
306 if ($Topic->GetErrorStatus() ==
Topic::OK)
308 # If the selected topic and forum exist 310 $Message->ParentId( $TopicId );
312 $Message->DatePosted(date(
"YmdHis"));
313 $Message->PosterId( $Author->Id() );
314 $Message->Subject( $Subject );
315 $Message->Body( $Body );
317 # update counts for topic and forum 320 $Topic->MessageCount($Topic->MessageCount() + 1);
326 return self::NOSUCHTOPIC;
338 $Message =
new Message($MessageId);
342 $TopicId = $Message->ParentId();
343 $Topic =
new Topic($TopicId);
344 if ($Topic->GetErrorStatus() ==
Topic::OK)
346 $ForumId = $Topic->ForumId();
347 $Forum =
new Forum($ForumId);
348 if ($Forum->GetErrorStatus() == self::OK)
350 # update count for topic and forum and delete message 351 $Topic->MessageCount($Topic->MessageCount() - 1 );
352 $Forum->MessageCount($Forum->MessageCount() - 1 );
360 return self::NONEXISTENT;
365 return self::NOSUCHTOPIC;
370 return self::NOSUCHMESSAGE;
374 # ---- PRIVATE INTERFACE ------------------------------------------------- 379 private $ErrorStatus;
386 private function UpdateValue($FieldName, $NewValue)
388 if ($this->ErrorStatus==self::OK)
390 return $this->DB->UpdateValue(
"Forums", $FieldName, $NewValue,
391 "ForumId = '".$this->
ForumId.
"'", $this->DBFields, TRUE);
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.
A converastion forum which includes topics and messages.
SQL database abstraction object with smart query caching.
LastMessageDate()
Get the date of the most recent post to the forum.
GetErrorStatus()
Retrieve error codes associated with the creation of the forum.
ModeratorEmail()
Get the e-mail address of the forum's moderator.
ForumDescription($NewValue=DB_NOVALUE)
Get or modify the forum description.
__construct($ForumId=NULL)
Object Constructor.
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.
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.