DiscussionThread.inc
8.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
/**
* $Id$
*
* Represents a document discussion thread.
*
* Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @version $Revision$
* @author Omar Rahbeeni, CS Holdings, South Africa
* @package lib.discussions
*/
class DiscussionThread extends KTEntity{
/**
* The underlying Discussion Comments class
*/
var $iId;
var $iDocumentID;
var $iFirstCommentID;
var $iLastCommentID;
var $iNumberOfViews;
var $iNumberOfReplies;
var $iCreatorID;
/**
* DiscussionThread Constructor
*/
function DiscussionThread($iNewFirstCommentID, $iNewDocumentID, $iNewCreatorID) {
global $default;
// create a new Discussion Thread object.
$this->iDocumentID = $iNewDocumentID;
$this->iCreatorID = $iNewCreatorID;
$this->iId = -1;
$this->iFirstCommentID = $iNewFirstCommentID;
$this->iLastCommentID = -1;
$this->iNumberOfViews = 0;
$this->iNumberOfReplies = 0;
}
/**
* Get the iId for current thread
*/
function getID(){
return $this->iId;
}
/**
* Get document id
*/
function getDocumentID(){
return $this->iDocumentID;
}
/**
* Get the id of the first comment
*/
function getFirstCommentID(){
return $this->iFirstCommentID;
}
/**
* Set the First Comment ID
*/
function setFirstCommentID($NewFirstCommentID){
$this->iFirstCommentID = $NewFirstCommentID;
}
/**
* get the id of the last comment
*/
function getLastCommentID(){
return $this->iLastCommentID;
}
/**
* Set the id of the last comment
*/
function setLastCommentID($iNewLastComment){
$this->iLastCommentID = $iNewLastComment;
}
/**
* Get the total number of time the thread was viewed
*/
function getNumberOfViews(){
return $this->iNumberOfViews;
}
/**
* Set the total number of times the thread was viewed
*/
function setNumberOfViews($iValue) {
$this->iNumberOfViews = $iValue;
}
/**
* Increment the total number of times the thread was viewed
*/
function incrementNumberOfViews() {
$this->iNumberOfViews += 1;
}
/**
* Get the total number of replies(comments) in a thread
*/
function getNumberOfReplies(){
return $this->iNumberOfReplies;
}
/**
* Increment the total number of replies (comments) in a thread
*/
function incrementNumberOfReplies(){
$this->iNumberOfReplies += 1;
}
/**
* Set the total number of number of replies (comments) in a thread
*/
function setNumberOfReplies($iValue){
$this->iNumberOfReplies = $iValue;
}
/**
* Get a All commentID's seperated by a comma ","
*/
function getAllCommentID() {
global $default;
$sql = $default->db;
$aQuery = array("SELECT id FROM $default->discussion_threads_table WHERE document_id = ? ORDER BY id",/*ok*/
$this->iDocumentID);
$result = $sql->query($aQuery);
if ($result) {
$sql->next_record();
$iThreadID = $sql->f("id");
$aQuery = array("SELECT id FROM $default->discussion_comments_table WHERE thread_id = ? ORDER BY date DESC",/*ok*/
$iThreadID);
$result = $sql->query($aQuery);
if ($result) {
while ($sql->next_record()) {
if ($sql->f("id") > 0) {
$sAllCommentID .= $sql->f("id") . ",";
} else {
//ID not valid
}
}
return $sAllCommentID ;
}
return false;
} else {
// No Thread for document
return false;
}
}
/**
* Static function
* Get a list of DiscussionThreads
*
* @param String Where clause (optional)
*
* @return Array array of DiscussionThreads objects, false otherwise
*/
function getList($sWhereClause = null) {
return KTEntityUtil::getList(DiscussionThread::_table(), 'DiscussionThread', $sWhereClause);
}
function getThreadIDforDoc($iDocumentID){
global $default;
$sql = $default->db;
$result = $sql->query(array("SELECT id FROM $default->discussion_threads_table WHERE document_id = ?", $iDocumentID));/*ok*/
if ($result) {
if ($sql->next_record()) {
if ($sql->f("id") > 0) {
return $sql->f("id");
} else {
return "false";
}
}
return false;
}
return false;
}
/**
* Static function.
* Given a web_documents primary key it will create a
* DiscussionThread object and populate it with the
* corresponding database values
*
* @return Unit populated Unit object on successful query, false otherwise and set $_SESSION["errorMessage"]
*/
function & get($iNewThreadID) {
global $default;
$sql = $default->db;
$result = $sql->query(array("SELECT * FROM $default->discussion_threads_table WHERE id = ?", $iNewThreadID));/*ok*/
if ($result) {
if ($sql->next_record()) {
$oDiscussionThread = & new DiscussionThread($sql->f("first_comment_id"),
$sql->f("document_id"),
$sql->f("creator_id"));
$oDiscussionThread->iId = $iNewThreadID;
$oDiscussionThread->iLastCommentID = $sql->f("last_comment_id");
$oDiscussionThread->iNumberOfViews = $sql->f("views");
$oDiscussionThread->iNumberOfReplies = $sql->f("replies");
return $oDiscussionThread;
}
return false;
}
return false;
}
function _fieldValues () {
return array(
'document_id' => $this->iDocumentID,
'first_comment_id' => $this->iFirstCommentID,
'last_comment_id' => $this->iLastCommentID,
'views' => $this->iNumberOfViews,
'replies' => $this->iNumberOfReplies,
'creator_id' => $this->iCreatorID,
);
}
function _table () {
global $default;
return $default->discussion_threads_table;
}
/**
* Delete a thread in the table
*/
function delete(){
global $default;
//only delete the object if it exists in the database
if ($this->iId > 0) {
//check to see if group is linked to a unit
$sql = $default->db;
$query = array("SELECT * FROM ". $default->discussion_threads_table ." WHERE id = ?", $this->iId);/*ok*/
$sql->query($query);
$rows = $sql->num_rows($sql);
if ($rows > 1) {
// duplicate Thread exists
$_SESSION["errorMessage"] = "Thread::The Thread id " . $this->iId . " has duplicates!";
return false;
} else {
$sql = $default->db;
$result = $sql->query("DELETE FROM $default->discussion_threads_table WHERE id = $this->iId");
if ($result) {
return true;
}
return false;
}
}
return false;
}
}
?>