FOSCommentBundle icon indicating copy to clipboard operation
FOSCommentBundle copied to clipboard

1 vote for 1 person ?

Open sam57 opened this issue 13 years ago • 18 comments

Hello,

Is it possible to allow people vote only if they haven't vote?

How can I do?

sam57 avatar Jan 16 '12 15:01 sam57

Someone is currently working on this, and we expect to have rate limiting features for voting soon.

merk avatar Jan 16 '12 21:01 merk

Thanks merk. So Have a deadline?

sam57 avatar Jan 17 '12 14:01 sam57

At this time there is no deadline. I expect to release 0.9.1 soon with some major changes that will make it easier for features like this to be added. Hopefully within a few days.

merk avatar Jan 17 '12 20:01 merk

Cool thanks

sam57 avatar Jan 18 '12 09:01 sam57

So voting system already works? Is there any doc/example where I can see how to implement it?

umpirsky avatar Jun 12 '12 13:06 umpirsky

Your comment should implement VotableCommentInterface which will enable basic voting, but there is no rate control or validation on voting which you will need to implement yourself.

merk avatar Jun 12 '12 13:06 merk

Cool, I'll look into it. Will you accept PR if I manage to implement it? Thanks.

umpirsky avatar Jun 12 '12 13:06 umpirsky

A small documentation would be great on this feature. I didn't know about this.

tristanbes avatar Jun 12 '12 13:06 tristanbes

Yeah, any documentation or additions are welcome. I dont use voting at the moment, so havent had a chance to do anything with it.

merk avatar Jun 12 '12 13:06 merk

Any update on this? Is there a branch where rate limiting implementation is happening so we can track or help?

umpirsky avatar Jul 02 '12 11:07 umpirsky

Noone has contributed this feature yet, we will accept a pull with this if someone wants to do it

merk avatar Jul 02 '12 11:07 merk

I had thought to create a new event VotePersistEvent, like CommentPersist, modify VoteManager in that way to abort persistence. But I guess this is not an option because of the BC

franmomu avatar Aug 23 '12 21:08 franmomu

I want to modify a few sections of FOSCB for a new version that removes a lot of legacy things. I regret tagging 2.0.0, so I'll probably have to go to 3 for these changes.

I dont mind such a PR, except that I'd like the voting API to respond with an error code if the vote is not accepted, instead of just silently failing (or at the very least, an option to configure that).

merk avatar Aug 23 '12 23:08 merk

Does this functionality exist yet? I'm a little confused as this issue is tagged as "Documentation", although by the sound of it the actual feature doesn't seem to have been implemented yet.

RobMasters avatar Oct 22 '12 14:10 RobMasters

Any advances on this?

Could you explain your proposal a bit @franmomu , to see if I can do a temporal implementation for my project?

jmorenoamor avatar Nov 14 '12 09:11 jmorenoamor

I suggested to create a new VotePersistEvent, like CommentPersistEvent, so you could create a listener for VOTE_PRE_PERSIST event to abort persistance.

Then in saveVote method of VoteManager the event will be VotePersistEvent and then check if the persistance should be aborted like CommentManager, I don't know why I said about BC, but it's true what @merk said that this will fail silently and you won't be able to know why the vote was not persisted.

So, I think this validation should be done before the saveVote method, one way to do this (I've just tried) is to create a Custom Validation Constraint as a service with class scope and apply to your Vote Entity/Document, you can inject the VoteManager and SecurityContext to the Validator and then (after some checks) do something like this:

$existingVote = $this->voteManager->findVoteBy(array(
    'user' => $this->securityContext->getToken()->getUser()->getId(),
    'comment' => $vote->getComment()->getId()
));

if ($existingVote) {
    $this->context->addViolation($constraint->message);
}

franmomu avatar Nov 14 '12 23:11 franmomu

If the example is ok, I can write it in full in the documentation.

franmomu avatar Jan 03 '13 01:01 franmomu

Your proposal is good. We'd need to add a VotePersistEvent but I would merge such a pull request.

merk avatar Jan 03 '13 02:01 merk