Experimental paged topiclists. Expect breakage.
[specialops2.git] / lib / class.topiclist_default.php
blob37cef5d22c8dff1473cfb5612faae8f5cf68645b
1 <?php
2 // $Id$
4 $classes['topiclist']['default'] = array('name' => 'SO2', 'ID' => 0);
6 class topiclist_default implements iface_topiclist
8 protected $tpp;
9 protected $page;
10 protected $topicsum;
12 function __construct($boardid, $tpp = 35, $page = 0)
14 global $DB, $user;
15 $this->tpp = $tpp;
16 $this->page = $page;
17 list($this->topicsum) = $DB->query('SELECT COUNT(*) FROM `topics` WHERE `boardid` = @boardid')->fetch_row();
19 $a = 1;
21 $topics = $DB->query(
22 'SELECT `topics`.`topicid`, `topic_title`, `topics`.`userid`, `alias`, `messageid`, `mtime`,
23 (SELECT COUNT(*) FROM `messages` WHERE `messages`.`topicid` = `topics`.`topicid`) AS `posts`
24 FROM `topics`
25 LEFT JOIN `messages` ON `lastpost` = `messageid`
26 LEFT JOIN `users` ON `topics`.`userid` = `users`.`userid`
27 WHERE `boardid` = @boardid
28 AND `topics`.`visibility` IN(\'normal\', \'sticky\')
29 GROUP BY `topicid`
30 ORDER BY `mtime` DESC
31 LIMIT '.($this->page*$this->tpp).', '.$this->tpp);
33 echo
34 '<table id="topiclist"><thead>',"\n",
35 " <tr>\n",
36 ' <th scope="col">Topic Name</th>',"\n",
37 ' <th scope="col">Creator</th>',"\n",
38 ' <th scope="col">Posts</th>',"\n",
39 ' <th scope="col">Last Post</th>',"\n",
40 " </tr>\n",
41 "</thead>\n",
42 "<tbody>\n";
45 while ( $topic = $topics->fetch_assoc() ) {
46 echo
47 '<tr class="content c',(++$a&1),"\">\n",
48 ' <td><a class="topic" href="messagelist?',$topic['topicid'],'">',$topic['topic_title'],"</a></td>\n",
49 ' <td>',$user->namelink($topic['userid']),"</td>\n",
50 ' <td>',$topic['posts'],"</td>\n",
51 ' <td>',$user->fdate($topic['mtime']),"</td>\n",
52 "</tr>\n";
54 echo "</tbody>\n</table>\n";
57 function display()
61 public function pagelist()
63 if ( $this->topicsum < $this->tpp )
64 return null;
66 $tmp = '';
67 for ( $i = 0; $i < $this->topicsum; $i += $this->tpp )
68 if ( $i/$this->tpp == $this->page )
69 $tmp .= '<dd>['.($i/$this->tpp+1)."]</dd>\n";
70 else
71 $tmp .= '<dd><a href="topiclist?board='.$boardid.';page='.($i/$this->tpp).
72 ';length='.$this->tpp.'">'.($i/$this->tpp+1)."</a></dd>\n";
73 return $tmp;