Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter
Support for Vanilla Forums Cloud product

In this Discussion

Follow Us


Sorting discussions by votes

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

Comments

  • kind of like digg
  • that'll sound good. having such a sort option would be great.
  • LincolnLincoln Community Instigator Vanilla Staff
    Doesn't clicking on the "Votes" tab before the first comment accomplish this?

    Sr Developer at Vanilla Forums [GitHub, Twitter]

  • 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.

    charliepratt
  • 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 Community Wiki! We are always looking for new content.

    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 Community Wiki! We are always looking for new content.

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

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

    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.

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

  • @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
Sign In or Register to comment.