CWIS Developer Documentation

- Home
- Main Page
- 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 function Topic($TopicId = NULL )
33 {
34 $this->ErrorStatus = Topic::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 = Topic::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 = Topic::NONEXISTENT;
65 }
66 }
67
71 function Delete()
72 {
73 if ($this->ErrorStatus == Topic::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 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 function TopicId() { return $this->TopicId; }
126
131 function CreatorName()
132 {
133 $CreatorName = new CWUser((int)$this->CreatorId());
134 return $CreatorName->Get("UserName");
135 }
136
141 function CreatorEmail()
142 {
143 $CreatorName = new CWUser((int)$this->CreatorId());
144 return $CreatorName->Get("EMail");
145 }
146
153 function ForumId($NewValue = DB_NOVALUE) { return $this->UpdateValue("ForumId", $NewValue); }
154
161 function CreatorId($NewValue = DB_NOVALUE) { return $this->UpdateValue("CreatorId", $NewValue); }
162
169 function DateCreated($NewValue = DB_NOVALUE) { return $this->UpdateValue("DateCreated", $NewValue); }
170
176 function TopicName($NewValue = DB_NOVALUE) { return $this->UpdateValue("TopicName", $NewValue); }
177
184 function ViewCount($NewValue = DB_NOVALUE) { return $this->UpdateValue("ViewCount", $NewValue); }
185
192 function MessageCount($NewValue = DB_NOVALUE) { return $this->UpdateValue("MessageCount", $NewValue); }
193
198 function GetErrorStatus() { return $this->ErrorStatus; }
199
202 # ---- PRIVATE INTERFACE -------------------------------------------------
203
204 private $TopicId;
205 private $DB;
206 private $DBFields;
207 private $ErrorStatus;
208
214 private function UpdateValue($FieldName, $NewValue)
215 {
216 if ($this->ErrorStatus == Topic::OK)
217 {
218 return $this->DB->UpdateValue("Topics", $FieldName, $NewValue,
219 "TopicId = '".$this->TopicId."'", $this->DBFields, TRUE);
220 }
221 else
222 {
223 return NULL;
224 }
225 }
226
227 }
Topic\GetErrorStatus
GetErrorStatus()
Retrieve the error status of the object.
Definition: Topic.php:198
Topic\CreatorId
CreatorId($NewValue=DB_NOVALUE)
Get or set the creator of this topic.
Definition: Topic.php:161
Topic\ForumId
ForumId($NewValue=DB_NOVALUE)
Set or modify the forum with which this topic is associated.
Definition: Topic.php:153
Topic\Topic
Topic($TopicId=NULL)
Object Constructor.
Definition: Topic.php:32
Message
Abstraction for forum messages and resource comments.
Definition: Message.php:15
Forum
A converastion forum which includes topics and messages.
Definition: Forum.php:14
Database
SQL database abstraction object with smart query caching.
Definition: Axis--Database.php:22
Topic\CreatorEmail
CreatorEmail()
Get the e-mail address of the user who created this topic.
Definition: Topic.php:141
DB_NOVALUE
const DB_NOVALUE
Definition: Axis--Database.php:1091
Topic\CreatorName
CreatorName()
Get the CWIS name of the user who created this topic.
Definition: Topic.php:131
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:176
PHP
PHP
Definition: OAIClient.php:39
Topic\DateCreated
DateCreated($NewValue=DB_NOVALUE)
Get or set the creation date of this topic.
Definition: Topic.php:169
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
Topic\ViewCount
ViewCount($NewValue=DB_NOVALUE)
Get or set the view count for this topic.
Definition: Topic.php:184
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:192
CWUser
CWIS-specific user class.
Definition: CWUser.php:13
Topic\OK
const OK
Definition: Topic.php:19