Changeset 427
- Timestamp:
- 2011-04-22 08:23:54 (1 year ago)
- Files:
-
- trunk/classes/misc/Post.php (modified) (1 diff)
- trunk/classes/pages/Category.php (modified) (1 diff)
- trunk/classes/pages/Delete.php (modified) (1 diff)
- trunk/classes/pages/Topic.php (modified) (3 diffs)
- trunk/db/mysql.sql (modified) (1 diff)
- trunk/db/postgresql.sql (modified) (1 diff)
- trunk/db/sqlite.sql (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/classes/misc/Post.php
r413 r427 524 524 } 525 525 // get last page of topic 526 $q = $C->prepare('SELECT COUNT(postid) FROM ' . $SETTINGS['dbtableprefix'] . 'posts WHERE topic=:id'); 527 $q->bindParam(':id', $INPUT['reply'], PDO::PARAM_INT, 12); 528 $q->execute(); 529 $row = $q->fetchColumn(); 530 $q = NULL; 526 $numberofposts = Topic::countPosts($INPUT['reply']); 531 527 // calculate page 532 $page = ceil($ row/ $SETTINGS['postsperpage']);528 $page = ceil($numberofposts / $SETTINGS['postsperpage']); 533 529 // send e-mail notifications (using the language the receipient has set) 534 530 $q = $C->prepare('SELECT member FROM ' . $SETTINGS['dbtableprefix'] . 'subscriptions WHERE topic = :id'); trunk/classes/pages/Category.php
r407 r427 85 85 $q3 = NULL; 86 86 // number of posts 87 $q4 = $C->prepare('SELECT COUNT(postid) AS posts FROM ' . $SETTINGS['dbtableprefix'] . 'posts WHERE topic IN (SELECT topicid FROM ' . $SETTINGS['dbtableprefix'] . 'topics WHERE forum=:forum)');87 $q4 = $C->prepare('SELECT SUM(posts) AS posts FROM ' . $SETTINGS['dbtableprefix'] . 'topics WHERE forum = :forum'); 88 88 $q4->bindParam(':forum', $row2['forumid'], PDO::PARAM_INT, 12); 89 89 $q4->execute(); trunk/classes/pages/Delete.php
r205 r427 85 85 $q->execute(); 86 86 $q = NULL; 87 // recount posts 88 Topic::countPosts($INPUT['id']); 87 89 // success message 88 90 $div = $this->html->body->addChild('div', $LANG['post_deleted']); trunk/classes/pages/Topic.php
r215 r427 72 72 $postbuttons = new Postbuttons(TRUE, $row->forum, TRUE, $row->topicid, $row->closed); 73 73 $this->html->body->addElement($postbuttons->get()); 74 // get number of posts75 $q2 = $C->prepare('SELECT COUNT(postid) AS posts FROM ' . $SETTINGS['dbtableprefix'] . 'posts WHERE topic=:topic');76 $q2->bindParam(':topic', $row->topicid, PDO::PARAM_INT, 12);77 $q2->execute();78 $row2 = $q2->fetchObject();79 $q2 = NULL;80 74 // calculate start for this page 81 75 if (!isset($INPUT['page']) || $INPUT['page'] == '') { … … 84 78 $_start = $SETTINGS['postsperpage'] * ($INPUT['page'] - 1); 85 79 // build page navigation 86 $pages = new Pagination($SETTINGS['postsperpage'], $INPUT['page'], $row 2->posts);80 $pages = new Pagination($SETTINGS['postsperpage'], $INPUT['page'], $row->posts); 87 81 // display page navigation 88 82 if ($_pagination = $pages->display('topic', Array('id'), Array($row->topicid))) { … … 269 263 } /* function getTitle */ 270 264 265 /** 266 * Function: countPosts 267 * Description: write updated number of posts into the database 268 * Input: $id - topic's id 269 * Returns: the number of posts (-1 on error) 270 **/ 271 public static function countPosts($id) { 272 global $C, $SETTINGS; 273 $q = $C->prepare('SELECT COUNT(*) FROM ' . $SETTINGS['dbtableprefix'] . 'posts WHERE topic = :id'); 274 $q->bindParam(':id', $id, PDO::PARAM_INT, 12); 275 if ($q->execute()) { 276 $number = $q->fetchColumn(); 277 $q = NULL; 278 $q = $C->prepare('UPDATE ' . $SETTINGS['dbtableprefix'] . 'topics SET posts = :number WHERE topicid = :id'); 279 $q->bindParam(':number', $number, PDO::PARAM_INT); 280 $q->bindParam(':id', $id, PDO::PARAM_INT); 281 if ($q->execute()) { 282 $q = NULL; 283 return $number; 284 } else { 285 $q = NULL; 286 return -1; 287 } 288 } else { 289 $q = NULL; 290 return -1; 291 } 292 } /* function countPosts */ 293 271 294 } /* class Topic */ 272 295 trunk/db/mysql.sql
r425 r427 59 59 pinned INTEGER NOT NULL DEFAULT 0, 60 60 poll INTEGER NOT NULL DEFAULT 0, 61 topic_views INTEGER NOT NULL DEFAULT 0 61 topic_views INTEGER NOT NULL DEFAULT 0, 62 posts INTEGER NOT NULL DEFAULT 0 62 63 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci; 63 64 trunk/db/postgresql.sql
r425 r427 59 59 pinned INTEGER NOT NULL DEFAULT 0, 60 60 poll INTEGER NOT NULL DEFAULT 0, 61 topic_views INTEGER NOT NULL DEFAULT 0 61 topic_views INTEGER NOT NULL DEFAULT 0, 62 posts INTEGER NOT NULL DEFAULT 0 62 63 ); 63 64 trunk/db/sqlite.sql
r425 r427 59 59 pinned INTEGER NOT NULL DEFAULT 0, 60 60 poll INTEGER NOT NULL DEFAULT 0, 61 topic_views INTEGER NOT NULL DEFAULT 0 61 topic_views INTEGER NOT NULL DEFAULT 0, 62 posts INTEGER NOT NULL DEFAULT 0 62 63 ); 63 64
