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
This commit is contained in:
mike.morgan%oregonstate.edu
2006-04-04 12:45:37 +00:00
parent 368789c08c
commit 63bfb1e02f
3 changed files with 35 additions and 11 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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