I'm using the thumbs up widget to act as a counter. Authenticated users can "thumbs up" any node once per day until a node reaches a certain threshold.

Unfortunately, by default, the rate module only allows one "thumbs up" per node per user... ever. Per the votingapi documentation, if the second parameter ($criteria) to votingapi_set_votes() is left off, it assumes you want to delete all previous votes for this node+user before counting the current vote.

I modified rate_save_vote() in rate.module to pass an empty array() as the second parameter which allows any user to "thumbs up" as many times as they want.

I believe this should be user configurable, maybe in the widget configuration? If you can provide direction, I'm glad to provide a patch.

Thanks

CommentFileSizeAuthor
#4 allow_multiple_votes-1224150-1.patch719 bytesrocketeerbkw
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mauritsl’s picture

The widget configuration is stored in a $widget object. You may add the configuration option to the form in rate_widget_form() (in rate.admin.inc). The call to votingapi_set_votes() is made in rate_save_vote() (rate.module). The $widget object is available in that function.

rocketeerbkw’s picture

I noticed there is no 6.x-1.x branch in git, should I work on master, 6.x-2.x or a 7.x branch and do a backport?

mauritsl’s picture

The master branch is used for 6.x-1.x, so please use that version.

Most new features still go in 6.x and get ported to 7.x later. Ignore the 2.x branch for now, it's not coming soon, but will contain a rewrite of the admin interface.

rocketeerbkw’s picture

Here's a patch that allows the $criteria variable to modified in hook_rate_vote_alter functions. By default, the functionality is the same as it is right now, authenticated users can only vote once.

This will at least allow me to not hack this module on my production site. I'll work on the UI for this in the widget settings next.

mauritsl’s picture

I've committed this to GIT. Thanks!

For reference; the following code can now be used to allow endless voting (on all widgets):

function MODULE_rate_vote_alter(&$votes, &$context) {
  $context['criteria'] = FALSE;
}

Looking forward to the admin section.

emergencyofstate’s picture

Desperately need this functionality however I am using the 7.x-1.2 version.

I don't suppose this has made it to 7? If not, could anybody help me with a patch that would work in 7?

mauritsl’s picture

This hook can be implemented in both D6 and D7.

emergencyofstate’s picture

Ah beautiful! So, all I need to do is employ a custom module that utilizes the hook listed above and all widget's can have endless voting?
-edit-
I've created/enabled a module with the hook and don't see any change in behavior. I'm currently using the thumbs up widget as a counter as well. I want to make sure I know how to make multiple votes per node, per user work.

emergencyofstate’s picture

So after a few days of scratching my head, I decided to look in rate.module and the patch listed above in #4, Absolutely did not make it into the 7 release.

I added (as per the patch in #4):

$criteria = NULL; //added

and

  $context = array(
    'redirect' => &$redirect,
    'save' => &$save,
   'criteria' => &$criteria, //added
    'widget' => $widget,
  );

and now it works.

mauritsl’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Fixed

You're right. I've now put it in GIT for 7.x-1.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rawkode’s picture

Patch still doesn't appear to have been commited properly. The following changes still need applied:

- votingapi_set_votes($votes);
+ votingapi_set_votes($votes, $criteria);

rawkode’s picture

Status: Closed (fixed) » Needs work

Forgot to change the status

mauritsl’s picture

Status: Needs work » Fixed

It has been committed finally:
http://drupalcode.org/project/rate.git/commit/3274946

Thanks again for the investigation!

bdone’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Energyblazar’s picture

Status: Closed (fixed) » Active

Is the patch ready yet ?

Energyblazar’s picture

To enable multiple votes by authenticated users i just edited the votingapi.module (/sites/all/modules/votingapi/votingapi.module)

From Line 132 to Line 153 added " // " infront of all codes which disables clearing out old votes if they exist and therefore members can cast multiple votes

this is how it looks after i add " // "

// Handle clearing out old votes if they exist.
  //if (!isset($criteria)) {
    // If the calling function didn't explicitly set criteria for vote deletion,
    // build up the delete queries here.
    //foreach ($votes as $vote) {
      //$tmp = votingapi_current_user_identifier();
      //$tmp += $vote;
      //if (isset($tmp['value'])) {
        //unset($tmp['value']);
      //}
      //votingapi_delete_votes(votingapi_select_votes($tmp));
    //}
  //}
  //elseif (is_array($criteria)) {
    // The calling function passed in an explicit set of delete filters.
    //if (!empty($criteria['entity_id'])) {
      //$criteria = array($criteria);
    //}
    //foreach ($criteria as $c) {
      //votingapi_delete_votes(votingapi_select_votes($c));
    //}
  //}

Note : This worked with fivestar module not tested and tried on other modules using voting api

lihygaasd’s picture

Works perfect in rate module for drupal 7 , Thanks !! Energyblazar

kojow7’s picture

In regards to #18, it does work, but the problem is that someone could just sit there hitting the vote button thousands of times. Is there a way I can do the following:

1) Allow Multiple votes on the same node, but ...
2) Only allow one vote (across the entire site) per 24 hour period.

edison_doulos’s picture

Issue summary: View changes

Comment #18 works for me too on Drupal 7 and Rate module. Thanks @Energyblazar

  • mauritsl committed b7b4d93 on 8.x-1.x
    Issue #1224150 by rocketeerbkw, emergencyofstate: Add criteria to...
  • mauritsl committed 3274946 on 8.x-1.x
    Issue #1224150 by rocketeerbkw, rawkode: Fix bug in criteria alter...