Here is the story:

I have "project" node type, and "buyer", "provider" roles

single "project" always have "buyer" and "provider" users (which are attached via userreference)

when "project" is "finished", "buyer" and "provider" are allowed to leave a rating for each other (by creating new node of type "review" where I have fivestar field
This fivestar field is configured to have some "user" as target of voting.
Only single review is allowed per project.

So, basically, user Michael can leave a review for user John several times - if these guys work together in 5 projects, user Michael will leave 5 reviews for user John.

And here is the problem: right now, fivestar field widget allows 1 vote of specific user for specific entity.

So, currently, if Michael leaves review for John in second or third project, his vote overwrites all his previous votes, and in votingapi_vote table, there is only single rate entry for Michael.
That looks good at first sight - when you look at specific review node, all votes for user are in place, since they use field table storage to retrieve vote.
But it breakes all votingapi features, like average, sum, etc, for obvious reasons.

I think, the easiest way to fix this issue is to have another setting (checkbox) in fivestar widget "allow user to vote multiple times" and modify _fivestar_cast_vote to use votingapi_add_votes instead of votingapi_set_votes.
That will mean that developer will have to implement his own protection mechanism to restrict voting in certain moment (in my case, I will check if current user already created review for specific project) - which is fine.

What do you think?

Comments

restyler’s picture

restyler’s picture

Project: Voting API » Fivestar
Version: 7.x-2.x-dev » 7.x-2.0-alpha1

when I started writing the code, I realized that the issue is more complex than that.
The problem here is that when some "review" is deleted, we don't know which entry to delete from votingapi_vote table (since there is no direct connection between specific review votes and entries in votingapi_vote table).
also, when review is updated (e.g. by admin) and the node is saved, we can't "update" votinapi_vote table for the same reason.
the only solution that I see is to modify votingapi_vote table to add "via_entity_id" field to votingapi_vote table so we can maintain direct connection between review object id and its votes.

Another solution for the "Allow users to vote several times for some entity" issue can be saving votes to review object, not to user object. but that means that generating totals (averages) for some user have to be done with some custom code that goes through all reviews, creates entries in votingapi_vote table for user object on the base of votes for reviews related to the user, etc. I don't think that's a super-easy solution, too..

restyler’s picture

Project: Fivestar » Voting API
Version: 7.x-2.0-alpha1 » 7.x-2.x-dev
xibun’s picture

Project: Fivestar » Voting API
Version: 7.x-2.0-alpha1 » 7.x-2.x-dev

+1

Energyblazar’s picture

"I think, the easiest way to fix this issue is to have another setting (checkbox) in fivestar widget "allow user to vote multiple times" and modify _fivestar_cast_vote to use votingapi_add_votes instead of votingapi_set_votes."

I like the idea, but just one question is it not the voting api module that must be altered instead of the fivestar module as it manages the vote and all related stuff, while fivestar is just a medium ?

Energyblazar’s picture

I think i am somewhere close to a solution.

What i did is very simple using Rules Module + Rules Form Module.

Created a new rules

In event selected the following -> Comment node user groups form is submitted

In Actions ->
Cast a vote
Parameter: Entity to vote on: [site:current-group], Voting user: [site:current-user], Voting value: 3, Vote tag: comment vote

Now what happenes in database under the table votingapi_vote the vote is added,

But there are problmes which r the following

Vote id added in the table votingapi_vote, is different from that in the 'field_data_field_members_vote.`

Also in the display in the parent note (which is user profile) the latest vote is only displayed.

The screenshot from my database tables is attached below

Will be researching more and posting things in here....if any one knows how do i enable multiple voting of the same user on same content please let me know....desperately looking for an answer.....Thank u

IWasBornToWin’s picture

This post worked for me....but had to hack code. Any way to get this committed?
http://drupal.org/node/561622#comment-6046666

IWasBornToWin’s picture

The above code works good until, like you explained in #2, you delete a comment or something with a vote.

IWasBornToWin’s picture

Is it fair to assume, if a vote is never updated or deleted that the hacked code will work fine?

istryker’s picture

Title: Allow users to vote several times for some entity » Allow users to vote several times for some entities

I have created a patch for Voting Up/Down module to allow users to vote several times for some entities. It works with any entity as the solution is a field, and an entity can be fielded. I don't know if Voteapi module can implement this on its own.

#1869790: Allow multiple votes
Comment #3

istryker’s picture

Issue summary: View changes

clarification

pifagor’s picture

Status: Active » Closed (outdated)