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-2016 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9
14 class Topic extends Item
15 {
16 # ---- PUBLIC INTERFACE --------------------------------------------------
17
20
25 public static function Create()
26 {
27 $DB = new Database();
28
29 # create a new topic
30 $DB->Query("INSERT INTO Topics (TopicId) VALUES (NULL)");
31
32 # get its topic id
33 $TopicId = $DB->LastInsertId();
34
35 # set parameters
36 $Topic = new Topic($TopicId);
37 return $Topic;
38 }
39
43 public function Delete()
44 {
45 # decrement the topic count for the parent forum
46 $Forum = new Forum($this->ForumId());
47 $Forum->TopicCount($Forum->TopicCount() - 1);
48
49 $this->DB->Query("SELECT * FROM Messages WHERE ParentId = ".
50 $this->Id()." AND ParentType = 1");
51
52 # delete messages associated with this topic
53 while ($Entry = $this->DB->FetchRow())
54 {
55 $Message = new Message($Entry["MessageId"]);
56 $Message->Delete();
57 }
58
59 # delete this topic itself
60 $this->Destroy();
61 }
62
67
72 public function GetMessageList()
73 {
74 $Messages = array();
75
76 # query for messages associated with this topic
77 $this->DB->Query("
78 SELECT * FROM Messages
79 WHERE ParentId = '".addslashes($this->Id())."'
80 AND ParentType = '1'
81 ORDER BY DatePosted ASC");
82
83 # create Message objects from the results
84 while (FALSE !== ($Row = $this->DB->FetchRow()))
85 {
86 $Messages[$Row["MessageId"]] = new Message($Row["MessageId"]);
87 }
88
89 return $Messages;
90 }
91
97 public function TopicId()
98 {
99 return $this->Id();
100 }
101
107 public function CreatorName()
108 {
109 $UserId = (int)$this->CreatorId();
110 if (!(new CWUserFactory())->UserExists($UserId))
111 {
112 return NULL;
113 }
114 else
115 {
116 $CreatorName = new CWUser($UserId);
117 return $CreatorName->Get("UserName");
118 }
119 }
120
126 public function CreatorEmail()
127 {
128 $UserId = (int)$this->CreatorId();
129 if (!(new CWUserFactory())->UserExists($UserId))
130 {
131 return NULL;
132 }
133 else
134 {
135 $CreatorName = new CWUser($UserId);
136 return $CreatorName->Get("EMail");
137 }
138 }
139
146 public function ForumId($NewValue = DB_NOVALUE)
147 {
148 return $this->UpdateValue("ForumId", $NewValue);
149 }
150
157 public function CreatorId($NewValue = DB_NOVALUE)
158 {
159 return $this->UpdateValue("CreatorId", $NewValue);
160 }
161
168 public function DateCreated($NewValue = DB_NOVALUE)
169 {
170 return $this->UpdateValue("DateCreated", $NewValue);
171 }
172
178 public function TopicName($NewValue = DB_NOVALUE)
179 {
180 return $this->UpdateValue("TopicName", $NewValue);
181 }
182
189 public function ViewCount($NewValue = DB_NOVALUE)
190 {
191 return $this->UpdateValue("ViewCount", $NewValue);
192 }
193
200 public function MessageCount($NewValue = DB_NOVALUE)
201 {
202 return $this->UpdateValue("MessageCount", $NewValue);
203 }
204
206 }
207
Topic\CreatorId
CreatorId($NewValue=DB_NOVALUE)
Get or set the creator of this topic.
Definition: Topic.php:157
Topic\ForumId
ForumId($NewValue=DB_NOVALUE)
Set or modify the forum with which this topic is associated.
Definition: Topic.php:146
Item\Id
Id()
Get item ID.
Definition: Item.php:81
Message
Abstraction for forum messages and resource comments.
Definition: Message.php:14
Item\UpdateValue
UpdateValue($ColumnName, $NewValue=DB_NOVALUE)
Convenience function to supply parameters to Database::UpdateValue().
Definition: Item.php:285
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:126
Item\$DB
$DB
Definition: Item.php:210
Topic\CreatorName
CreatorName()
Get the CWIS name of the user who created this topic.
Definition: Topic.php:107
Topic
Abstraction for topics within a Forum.
Definition: Topic.php:14
Item\Destroy
Destroy()
Destroy item.
Definition: Item.php:60
Topic\TopicName
TopicName($NewValue=DB_NOVALUE)
Get or modify the name of this topic.
Definition: Topic.php:178
CWUserFactory
CWIS-specific user factory class.
Definition: CWUserFactory.php:13
Topic\Create
static Create()
Create an empty new topic.
Definition: Topic.php:25
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:168
Topic\Delete
Delete()
Remove this topic from the database, deleting the underlying messages.
Definition: Topic.php:43
Item
Common base class for persistent items store in database.
Definition: Item.php:13
DB_NOVALUE
const DB_NOVALUE
Definition: Database.php:1784
Topic\ViewCount
ViewCount($NewValue=DB_NOVALUE)
Get or set the view count for this topic.
Definition: Topic.php:189
Topic\TopicId
TopicId()
Get the ID of this topic.
Definition: Topic.php:97
Topic\GetMessageList
GetMessageList()
Get the list of messages in this topic.
Definition: Topic.php:72
Topic\MessageCount
MessageCount($NewValue=DB_NOVALUE)
Get or set the message count for this topic.
Definition: Topic.php:200
CWUser
CWIS-specific user class.
Definition: CWUser.php:13