Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

JoomlaTune Support Forum    JComments component    General discussion    Topic: Users sorting comments asc/desc themselves - trouble.
Pages: [1]   Go Down
  Print  
Author Topic: Users sorting comments asc/desc themselves - trouble.  (Read 1161 times)
0 Members and 2 Guests are viewing this topic.
Foliz
Newbie
*

Karma: 0
Offline Offline

Posts: 2


« on: December 31, 2010, 21:19:48 »

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):

Code:
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?
Logged
QMedia
Newbie
*

Karma: 0
Offline Offline

Posts: 13


« Reply #1 on: January 02, 2011, 18:34:15 »

Anyone got some feedback on this topic?

I'm trying to accomplish the same thing.

There has to be some way of letting users choose for themselves if they wish to sort by ASC or DESC date?

I've managed this with checking a variable in the URLfield with JRequest etc before...but this doesn't seem to work here with Jcomments? Any pointer in the right direction here will be greatly appriciated Cheesy
Logged
smart
Administrator
Hero Member
*****

Karma: 160
Offline Offline

Gender: Male
Posts: 2559



WWW
« Reply #2 on: January 07, 2011, 03:45:00 »

This feature is planned to future versions so I won't to make any temporary solution now. It require some modifications in templates, javascripts and component's code...
Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
Pages: [1]   Go Up
  Print  
JoomlaTune Support Forum    JComments component    General discussion    Topic: Users sorting comments asc/desc themselves - trouble.
 
Jump to: