CWIS Developer Documentation
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 
CreatorId($NewValue=DB_NOVALUE)
Get or set the creator of this topic.
Definition: Topic.php:157
ForumId($NewValue=DB_NOVALUE)
Set or modify the forum with which this topic is associated.
Definition: Topic.php:146
Id()
Get item ID.
Definition: Item.php:81
Abstraction for forum messages and resource comments.
Definition: Message.php:14
UpdateValue($ColumnName, $NewValue=DB_NOVALUE)
Convenience function to supply parameters to Database::UpdateValue().
Definition: Item.php:284
A converastion forum which includes topics and messages.
Definition: Forum.php:14
SQL database abstraction object with smart query caching.
Definition: Database.php:22
CreatorEmail()
Get the e-mail address of the user who created this topic.
Definition: Topic.php:126
$DB
Definition: Item.php:210
CreatorName()
Get the CWIS name of the user who created this topic.
Definition: Topic.php:107
Abstraction for topics within a Forum.
Definition: Topic.php:14
Destroy()
Destroy item.
Definition: Item.php:60
TopicName($NewValue=DB_NOVALUE)
Get or modify the name of this topic.
Definition: Topic.php:178
CWIS-specific user factory class.
static Create()
Create an empty new topic.
Definition: Topic.php:25
DateCreated($NewValue=DB_NOVALUE)
Get or set the creation date of this topic.
Definition: Topic.php:168
Delete()
Remove this topic from the database, deleting the underlying messages.
Definition: Topic.php:43
Common base class for persistent items store in database.
Definition: Item.php:13
const DB_NOVALUE
Definition: Database.php:1738
ViewCount($NewValue=DB_NOVALUE)
Get or set the view count for this topic.
Definition: Topic.php:189
TopicId()
Get the ID of this topic.
Definition: Topic.php:97
GetMessageList()
Get the list of messages in this topic.
Definition: Topic.php:72
MessageCount($NewValue=DB_NOVALUE)
Get or set the message count for this topic.
Definition: Topic.php:200
CWIS-specific user class.
Definition: CWUser.php:13