Please upgrade here. These earlier versions are no longer being updated and have security issues.

Sorting discussions by votes

This discussion is related to the Voting addon.
tmilovantmilovan New
edited November 2010 in Vanilla 2.0 - 2.3
It would be really great if we could sort discussions on "Popular" dicussion list by votes. Or is this already possible somehow?
Tagged:

Comments

  • RaizeRaize vancouver ✭✭
    kind of like digg
  • that'll sound good. having such a sort option would be great.
  • LincLinc Director of Development Detroit Vanilla Staff
    Doesn't clicking on the "Votes" tab before the first comment accomplish this?
  • No, or yes :)) but only for comments. I was thinking about sorting discussions on discussions list.
  • I just realized the "popular" tab in the discussions page does not take into account votes like I thought. Kind of makes voting on discussions a bit futile right? Has anyone implemented a sort on votes tab for discussions not comments?
  • I second @scoobee, shouldn't there be an option to sort discussions by vote and make this the default view?
  • Find:

    DiscussionModel->SQL->OrderBy('d.CountViews', 'desc');
    (for me it was line 458)

    Comment out and insert:
    $DiscussionModel->SQL->OrderBy('COALESCE(d.Score,0)', 'desc');

    Now you will have it sorted by vote.

    charlieprattdominikl
  • Thanks, @realrasengan. That worked like a charm.

  • Followup: is there a way to constrain the date range for this view of popular discussions? I'd like to avoid having a static list of "all-time" popular discussions, and opt instead for a 30-day range.

  • hgtonighthgtonight ∞ · New Moderator

    @charliepratt add a where statement that compares DateUpdated to 30 days ago. Something like:

    $DiscussionModel->SQL->OrderBy('COALESCE(d.Score,0)', 'desc')
      ->Where('DateUpdated >=', 'NOW() - INTERVAL 1 MONTH');
    

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    UnderDog
  • @hgtonight just tried this option and it returns no results.

  • hgtonighthgtonight ∞ · New Moderator

    You probably have to add a d. in front of the field.

        $DiscussionModel->SQL->OrderBy('COALESCE(d.Score,0)', 'desc')
        ->Where('d.DateUpdated >=', 'NOW() - INTERVAL 1 MONTH');
    

    I can't test against Vanilla right now. :(

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    UnderDog
  • peregrineperegrine MVP
    edited May 2013

    try this:

    ->Where('d.DateUpdated >=', Gdn_Format::ToDateTime(strtotime('-30 days')));

    but be forewarned your pager will still show additional pages where discussion topics will be blank because of the where restriction, but it will do the job.

    Todd presented this tip for me months ago for a different table.

    I suspect you could change the pager to reflect the proper count based on number of discussions retrieved, but that I'll leave up to you to research :).

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    UnderDogcharliepratt
  • or this

     $DiscussionModel->SQL->OrderBy('COALESCE(d.Score,0)', 'desc')
           ->Where('d.DateLastComment >=', Gdn_Format::ToDateTime(strtotime('-30 days')))
           ->OrWhere('d.DateUpdated >=', Gdn_Format::ToDateTime(strtotime('-30 days')));
    

    depending on what you want to do based on what.

    for a 30-day range of what?

    30 days since last comment maybe better.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine said:

    try this:

    ->Where('d.DateUpdated >=', Gdn_Format::ToDateTime(strtotime('-30 days')));

    @peregrine - this did what I needed. Thanks to @hgtonight for the alley oop. :)

    hgtonight
  • I am sorry but can you tell me in which file I have to edit? You all seem to know which file you are talking about, but i don´t =D

  • hgtonighthgtonight ∞ · New Moderator

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.