Hello.
I would like to make a feature for our users with the commentsystem, allowing them to sort either ascending or descending when the comments came in.
So far I haven't been able to make this work. The variable I add in the url seems to get dismissed before the script is processed, or it never gets picked up inside the function.
Anyone have a clue as to what to do?
I've put this inside the function _getCommentsQuery(&$options):
function _getCommentsQuery(&$options)
{
$reverse = JRequest::getVar('reverse' , '' );
$acl = & JCommentsFactory::getACL();
$db = & JCommentsFactory::getDBO();
$object_id = @$options['object_id'];
$object_group = @$options['object_group'];
$parent = @$options['parent'];
$published = @$options['published'];
$orderBy = @$options['orderBy'];
$limitStart = @$options['limitStart'];
$limit = @$options['limit'];
$where = array();
if ($object_id) {
$where[] = "c.object_id = " . $object_id;
}
if ($object_group != '') {
$where[] = "c.object_group = '".$db->getEscaped($object_group)."'";
}
if ($parent !== null) {
$where[] = "c.parent = " . $parent;
}
if ($published !== null) {
$where[] = "c.published = " . $published;
}
if (JCommentsMultilingual::isEnabled()) {
$where[] = "c.lang = '" . JCommentsMultilingual::getLanguage() . "'";
}
if($reverse == 1) {
$query = "SELECT c.id, c.parent, c.object_id, c.object_group, c.userid, c.name, c.username, c.title, c.comment"
. "\n, c.email, c.homepage, c.date as datetime, c.ip, c.published, c.checked_out, c.checked_out_time"
. "\n, c.isgood, c.ispoor"
. "\n, v.value as voted"
. "\n, case when c.userid = 0 then 'guest' else replace(lower(u.usertype), ' ', '-') end as usertype"
. "\nFROM #__jcomments AS c"
. "\nLEFT JOIN #__jcomments_votes AS v ON c.id = v.commentid " . ($acl->getUserId() ? " AND v.userid = ".$acl->getUserId() : " AND v.userid = 0 AND v.ip = '".$acl->getUserIP()."'")
. "\nLEFT JOIN #__users AS u ON c.userid = u.id"
. (count($where) ? ("\nWHERE " . implode(' AND ', $where)) : "" )
. "\nORDER BY c.date DESC "
. (($limit > 0) ? "\nLIMIT $limitStart, $limit" : "")
;
}
elseif($reverse == 0) {
$query = "SELECT c.id, c.parent, c.object_id, c.object_group, c.userid, c.name, c.username, c.title, c.comment"
. "\n, c.email, c.homepage, c.date as datetime, c.ip, c.published, c.checked_out, c.checked_out_time"
. "\n, c.isgood, c.ispoor"
. "\n, v.value as voted"
. "\n, case when c.userid = 0 then 'guest' else replace(lower(u.usertype), ' ', '-') end as usertype"
. "\nFROM #__jcomments AS c"
. "\nLEFT JOIN #__jcomments_votes AS v ON c.id = v.commentid " . ($acl->getUserId() ? " AND v.userid = ".$acl->getUserId() : " AND v.userid = 0 AND v.ip = '".$acl->getUserIP()."'")
. "\nLEFT JOIN #__users AS u ON c.userid = u.id"
. (count($where) ? ("\nWHERE " . implode(' AND ', $where)) : "" )
. "\nORDER BY c.date ASC "
. (($limit > 0) ? "\nLIMIT $limitStart, $limit" : "")
;
}
else {
$query = "SELECT c.id, c.parent, c.object_id, c.object_group, c.userid, c.name, c.username, c.title, c.comment"
. "\n, c.email, c.homepage, c.date as datetime, c.ip, c.published, c.checked_out, c.checked_out_time"
. "\n, c.isgood, c.ispoor"
. "\n, v.value as voted"
. "\n, case when c.userid = 0 then 'guest' else replace(lower(u.usertype), ' ', '-') end as usertype"
. "\nFROM #__jcomments AS c"
. "\nLEFT JOIN #__jcomments_votes AS v ON c.id = v.commentid " . ($acl->getUserId() ? " AND v.userid = ".$acl->getUserId() : " AND v.userid = 0 AND v.ip = '".$acl->getUserIP()."'")
. "\nLEFT JOIN #__users AS u ON c.userid = u.id"
. (count($where) ? ("\nWHERE " . implode(' AND ', $where)) : "" )
. "\nORDER BY " . $orderBy
. (($limit > 0) ? "\nLIMIT $limitStart, $limit" : "")
;
}
return $query;
}
Anyone have a clue as to what I can do?