From 63bfb1e02fb82665b9d8bce77d44a2b87d6da587 Mon Sep 17 00:00:00 2001 From: "mike.morgan%oregonstate.edu" Date: Tue, 4 Apr 2006 12:45:37 +0000 Subject: [PATCH] Fixed LIMIT clause in getComments() and fixed default call to getComments() in addon constructor. git-svn-id: svn://10.0.0.236/trunk@193499 18797224-902f-48f8-a5cc-f745e15eee43 --- .../addons/public/htdocs/comments.php | 2 +- .../addons/shared/lib/addon.class.php | 40 ++++++++++++++----- .../webtools/addons/shared/lib/amo.class.php | 4 ++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/mozilla/webtools/addons/public/htdocs/comments.php b/mozilla/webtools/addons/public/htdocs/comments.php index 2d937f91030..c72f108a554 100644 --- a/mozilla/webtools/addons/public/htdocs/comments.php +++ b/mozilla/webtools/addons/public/htdocs/comments.php @@ -30,7 +30,7 @@ startProcessing('comments.tpl',$clean['id'],$compileId); require_once('includes.php'); $addon = new AddOn($sql['id']); -$addon->getComments($page['left'],$page['right'],$orderby); +$addon->getComments($page['left'],10,$orderby); // Get our result count. $db->query("SELECT FOUND_ROWS()", SQL_INIT); diff --git a/mozilla/webtools/addons/shared/lib/addon.class.php b/mozilla/webtools/addons/shared/lib/addon.class.php index ddb68a648e7..f38dbc736b2 100644 --- a/mozilla/webtools/addons/shared/lib/addon.class.php +++ b/mozilla/webtools/addons/shared/lib/addon.class.php @@ -84,7 +84,7 @@ class AddOn extends AMO_Object { */ function getAddOn() { $this->getAddonCats(); - $this->getComments('3'); + $this->getComments(0,3); $this->getCurrentVersion(); $this->getMainPreview(); $this->getUserInfo(); @@ -244,18 +244,39 @@ class AddOn extends AMO_Object { /** * Get comments attached to this Addon. * - * @param int $limit number of rows to limit by. + * @param int $offset starting point of result set. + * @param int $numrows number of rows to show. * @todo add left/right limit clauses i.e. LIMIT 10,20 to work with pagination */ - function getComments($limit=null) { + function getComments($offset=0, $numrows=10, $orderBy=null) { - // Set the LIMIT if it is not null. - $_limitSql = !empty($limit) ? " LIMIT {$limit} " : null; + // Set order by. + switch ($orderBy) { + case 'ratinghigh': + $_orderBySql = " ORDER BY CommentVote desc "; + break; + case 'ratinglow': + $_orderBySql = " ORDER BY CommentVote asc "; + break; + case 'dateoldest': + $_orderBySql = " ORDER BY CommentDate asc "; + break; + case 'datenewest': + $_orderBySql = " ORDER BY CommentDate desc "; + break; + case 'leasthelpful': + $_orderBySql = " ORDER BY helpful_no desc, helpful_yes asc "; + break; + case 'mosthelpful': + default: + $_orderBySql = " ORDER BY helpful_yes desc "; + break; + } // Gather 10 latest comments. $this->db->query(" - SELECT - CommentID, + SELECT SQL_CALC_FOUND_ROWS + CommentID, CommentName, CommentTitle, CommentNote, @@ -269,9 +290,8 @@ class AddOn extends AMO_Object { WHERE ID = '{$this->ID}' AND CommentVote IS NOT NULL - ORDER BY - CommentDate DESC - {$_limitSql} + {$_orderBySql} + LIMIT {$offset}, {$numrows} ", SQL_ALL, SQL_ASSOC); $this->setVar('Comments',$this->db->record); diff --git a/mozilla/webtools/addons/shared/lib/amo.class.php b/mozilla/webtools/addons/shared/lib/amo.class.php index ec5a78d8770..182c234f919 100644 --- a/mozilla/webtools/addons/shared/lib/amo.class.php +++ b/mozilla/webtools/addons/shared/lib/amo.class.php @@ -170,6 +170,8 @@ class AMO_Object v.approved = 'yes' AND a.appname = '{$app}' AND m.type = '{$type}' + GROUP BY + m.id ORDER BY v.dateupdated DESC , downloadcount DESC, rating DESC LIMIT @@ -259,6 +261,8 @@ class AMO_Object v.approved = 'yes' AND a.appname = '{$app}' AND m.type = '{$type}' + GROUP BY + m.id ORDER BY m.downloadcount DESC, m.rating DESC, v.dateupdated DESC LIMIT