CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Topic.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: Topic.php
4 #
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/
8 #
9
14 class Topic {
15
16 # ---- PUBLIC INTERFACE --------------------------------------------------
17
18 # Error codes for the TOPIC
19 const OK = 0;
20 const NONEXISTENT = 1;
21
24
32 public function __construct($TopicId = NULL )
33 {
34 $this->ErrorStatus = self::OK;
35 # locate class in database
36 $this->DB = new Database();
37 $DB = $this->DB;
38 # if ID supplied
39 if ($TopicId !== NULL)
40 {
41 $this->TopicId = intval($TopicId);
42 $DB->Query("SELECT * FROM Topics WHERE TopicId = ".$this->TopicId);
43
44 # if row was loaded
45 if ($DB->NumRowsSelected() > 0)
46 {
47 # set attributes to values returned by database
48 $this->DBFields = $DB->FetchRow();
49 }
50 else
51 {
52 $this->ErrorStatus = self::NONEXISTENT;
53 }
54 }
55 elseif (func_num_args()==0)
56 {
57 # add record to database with that ID
58 $DB->Query("INSERT INTO Topics (TopicId) VALUES (NULL)");
59 $this->TopicId = $DB->Query("SELECT LAST_INSERT_ID()"
60 ." AS TopicId FROM Topics", "TopicId");
61 }
62 else
63 {
64 $this->ErrorStatus = self::NONEXISTENT;
65 }
66 }
67
71 public function Delete()
72 {
73 if ($this->ErrorStatus == self::OK)
74 {
75 # decrement the topic count for the parent forum
76 $Forum = new Forum($this->ForumId());
77 $Forum->TopicCount($Forum->TopicCount() - 1);
78
79 $this->DB->Query("Select * from Messages where ParentId = ".
80 $this->TopicId." AND ParentType = 1");
81
82 # delete messages associated with this topic
83 while ($Entry = $this->DB->FetchRow())
84 {
85 $Message = new Message($Entry["MessageId"]);
86 $Message->Delete();
87 }
88 $this->DB->Query("DELETE FROM Topics WHERE TopicId=".$this->TopicId);
89 }
90 }
91
96
101 public function GetMessageList()
102 {
103 $Messages = array();
104
105 # query for messages associated with this topic
106 $this->DB->Query("
107 SELECT * FROM Messages
108 WHERE ParentId = '".addslashes($this->TopicId)."'
109 AND ParentType = '1'
110 ORDER BY DatePosted ASC");
111
112 # create Message objects from the results
113 while (FALSE !== ($Row = $this->DB->FetchRow()))
114 {
115 $Messages[$Row["MessageId"]] = new Message($Row["MessageId"]);
116 }
117
118 return $Messages;
119 }
120
125 public function TopicId()
126 {
127 return $this->TopicId;
128 }
129
134 public function CreatorName()
135 {
136 $CreatorName = new CWUser((int)$this->CreatorId());
137 return $CreatorName->Get("UserName");
138 }
139
144 public function CreatorEmail()
145 {
146 $CreatorName = new CWUser((int)$this->CreatorId());
147 return $CreatorName->Get("EMail");
148 }
149
156 public function ForumId($NewValue = DB_NOVALUE)
157 {
158 return $this->UpdateValue("ForumId", $NewValue);
159 }
160
167 public function CreatorId($NewValue = DB_NOVALUE)
168 {
169 return $this->UpdateValue("CreatorId", $NewValue);
170 }
171
178 public function DateCreated($NewValue = DB_NOVALUE)
179 {
180 return $this->UpdateValue("DateCreated", $NewValue);
181 }
182
188 public function TopicName($NewValue = DB_NOVALUE)
189 {
190 return $this->UpdateValue("TopicName", $NewValue);
191 }
192
199 public function ViewCount($NewValue = DB_NOVALUE)
200 {
201 return $this->UpdateValue("ViewCount", $NewValue);
202 }
203
210 public function MessageCount($NewValue = DB_NOVALUE)
211 {
212 return $this->UpdateValue("MessageCount", $NewValue);
213 }
214
219 public function GetErrorStatus()
220 {
221 return $this->ErrorStatus;
222 }
223
226 # ---- PRIVATE INTERFACE -------------------------------------------------
227
228 private $TopicId;
229 private $DB;
230 private $DBFields;
231 private $ErrorStatus;
232
238 private function UpdateValue($FieldName, $NewValue)
239 {
240 if ($this->ErrorStatus == self::OK)
241 {
242 return $this->DB->UpdateValue("Topics", $FieldName, $NewValue,
243 "TopicId = '".$this->TopicId."'", $this->DBFields, TRUE);
244 }
245 else
246 {
247 return NULL;
248 }
249 }
250
251 }
Topic\GetErrorStatus
GetErrorStatus()
Retrieve the error status of the object.
Definition: Topic.php:219
Topic\CreatorId
CreatorId($NewValue=DB_NOVALUE)
Get or set the creator of this topic.
Definition: Topic.php:167
Topic\ForumId
ForumId($NewValue=DB_NOVALUE)
Set or modify the forum with which this topic is associated.
Definition: Topic.php:156
Message
Abstraction for forum messages and resource comments.
Definition: Message.php:14
Forum
A converastion forum which includes topics and messages.
Definition: Forum.php:14
Database
SQL database abstraction object with smart query caching.
Definition: Database.php:22
Topic\CreatorEmail
CreatorEmail()
Get the e-mail address of the user who created this topic.
Definition: Topic.php:144
Topic\CreatorName
CreatorName()
Get the CWIS name of the user who created this topic.
Definition: Topic.php:134
Topic
Abstraction for topics within a Forum.
Definition: Topic.php:14
Topic\TopicName
TopicName($NewValue=DB_NOVALUE)
Get or modify the name of this topic.
Definition: Topic.php:188
PHP
PHP
Definition: RSSClient--Test.php:12
Topic\DateCreated
DateCreated($NewValue=DB_NOVALUE)
Get or set the creation date of this topic.
Definition: Topic.php:178
Topic\NONEXISTENT
const NONEXISTENT
Definition: Topic.php:20
Topic\Delete
Delete()
Remove this topic from the database, deleting the underlying messages.
Definition: Topic.php:71
DB_NOVALUE
const DB_NOVALUE
Definition: Database.php:1541
Topic\ViewCount
ViewCount($NewValue=DB_NOVALUE)
Get or set the view count for this topic.
Definition: Topic.php:199
Topic\TopicId
TopicId()
Get the ID of this topic.
Definition: Topic.php:125
Topic\GetMessageList
GetMessageList()
Get the list of messages in this topic.
Definition: Topic.php:101
Topic\MessageCount
MessageCount($NewValue=DB_NOVALUE)
Get or set the message count for this topic.
Definition: Topic.php:210
CWUser
CWIS-specific user class.
Definition: CWUser.php:13
Topic\__construct
__construct($TopicId=NULL)
Object Constructor.
Definition: Topic.php:32
Topic\OK
const OK
Definition: Topic.php:19