4
* This class serves to represent a forum under some category
6
define('THREADS_PER_PAGE',50);
7
// Forum sorting styles available
8
define('MODIFIED_NEW', 1);
9
define('MODIFIED_OLD',2);
10
define('VIEWS_MOST',3);
11
define('REPLIES_MOST',4);
12
define('CREATE_TIME_NEW',5);
13
define('CREATE_TIME_OLD',6);
14
unset ($forum_sort_styles);
15
$forum_sort_styles[MODIFIED_NEW] = "Most recent reply first";
16
//$forum_sort_styles[MODIFIED_OLD] = "Least recent reply first";
17
$forum_sort_styles[VIEWS_MOST] = "Most views first";
18
$forum_sort_styles[REPLIES_MOST] = "Most posts first";
19
$forum_sort_styles[CREATE_TIME_NEW] = "Most recently created first";
20
//$forum_sort_styles[CREATE_TIME_OLD] = "Least recently created first";
24
// Container for the variables in the forum
26
// Container for the threads in this forum
34
$this->dbhandler = $mainFactory->getDatabaseHandler();
35
$this->dbObj = $this->dbhandler->getForum($id);
36
if (!$this->dbObj) error_page("Forum with id $id created but nothing returned from DB layer");
40
* The following functions simply return the fields for the forum.
43
return $this->dbObj->id;
46
return $this->dbObj->title;
48
function getDescription(){
49
return $this->dbObj->description;
51
function getPostCount(){
52
return $this->dbObj->posts;
54
function getThreadCount(){
55
return $this->dbObj->threads;
57
function getLastTimestamp(){
58
return $this->dbObj->timestamp;
60
function getPostMinTotalCredit(){
61
return $this->dbObj->post_min_total_credit;
63
function getPostMinExpavgCredit(){
64
return $this->dbObj->post_min_expavg_credit;
66
function getPostMinInterval(){
67
return $this->dbObj->post_min_interval;
69
function getRateMinTotalCredit(){
70
return $this->dbObj->rate_min_total_credit;
72
function getRateMinExpavgCredit(){
73
return $this->dbObj->rate_min_expavg_credit;
75
function getCategory(){
76
return new Category($this->dbObj->category);
79
return $this->dbObj->is_dev_blog;
83
* Increase the post count for the forum (default by one)
85
function incPostCount($amount=1){
86
return ($this->dbhandler->updateForum($this, "posts", ($this->getPostCount()+$amount)) &&
87
$this->dbhandler->updateForum($this, "timestamp", time()));
91
* Decrease the post count for the forum (default by one)
93
function decPostCount($amount=1){
94
return $this->dbhandler->updateForum($this, "posts", ($this->getPostCount()-$amount));
98
* Increase the thread count for the forum by one
100
function incThreadCount(){
101
return $this->dbhandler->updateForum($this, "threads", ($this->getThreadCount()+1));
105
* Decrease the thread count for the forum by one
107
function decThreadCount(){
108
return $this->dbhandler->updateForum($this, "threads", ($this->getThreadCount()-1));
112
* Return a list of threads for this forum
114
function getThreads($start, $count, $sort_style=MODIFIED_NEW, $show_hidden=false, $sticky_first=true){
115
if (!$this->threads){
116
$list = $this->dbhandler->getThreads($this, $start, $count, $sort_style, $show_hidden, $sticky_first);
118
foreach ($list as $key => $thread){
119
$this->threads[] = new Thread($thread->id, $thread);
122
$this->threads = array();
125
return $this->threads;
129
* Create a thread in this forum
131
function createThread($title, $content, $user, $signature){
132
return Thread::createNewThread($title, $content, $user, $this, $signature);
138
* This function returns a string containing a paged navigation bar
139
* for the given forum. The default start place is 0.
141
function show_page_nav($forum, $start=0){
142
// How many pages to potentially show before and after this one:
143
$preshow = 5; $postshow = 10;
145
if ($forum->getThreadCount() > THREADS_PER_PAGE) {
146
$total = ceil($forum->getThreadCount() / THREADS_PER_PAGE);
147
$curpage = ceil($start / THREADS_PER_PAGE);
148
// If this is not the first page, display "previous"
150
$navbar = '<a href="forum_forum.php?id='.get_int("id").'&start='.(($curpage-1)*THREADS_PER_PAGE);
151
$sort = get_int("sort",true);
152
if ($sort) $navbar.='&sort='.$sort;
153
$navbar.= '"> <-- Previous</a> ';
156
// Display a list of pages surrounding this one
157
for ($i=$curpage-$preshow;$i<($curpage+$postshow);$i++){
159
if ($i>$total) break;
160
if ($i == $curpage+1){$navbar.="<em>";} // If this is the current page, emphasize it.
161
$navbar.='<a href="forum_forum.php?id='.get_int("id").'&start='.(($i-1)*THREADS_PER_PAGE);
162
$sort = get_int("sort",true);
163
if ($sort) $navbar.='&sort='.$sort;
164
$navbar.='">'.$i.' |</a> ';
165
if ($i == $curpage+1){$navbar.="</em>";}
168
// If there is a next page
169
if ($curpage+1 < $total){
170
$navbar.= '<a href="forum_forum.php?id='.get_int("id").'&start='.(($curpage+1)*THREADS_PER_PAGE);
171
$sort = get_int("sort",true);
172
if ($sort) $navbar.='&sort='.$sort;
173
$navbar.= '"> Next --></a>';