/** * Stores a vote for the current user. * * @param \Frontpage\Model\PollOption $pollOption The option to vote on * @return bool indicating whether the vote was submitted */ public function submitVote($pollOption) { $poll = $pollOption->getPoll(); if (is_null($poll) || is_null($pollOption)) { return false; } if (!$this->canVote($poll)) { throw new \User\Permissions\NotAllowedException($this->getTranslator()->translate('You are not allowed to vote on this poll.')); } $pollVote = new PollVoteModel(); $pollVote->setRespondent($this->getUser()); $pollVote->setPoll($poll); $pollOption->addVote($pollVote); $pollMapper = $this->getPollMapper(); $pollMapper->persist($pollOption); $pollMapper->flush(); }
/** * Adds a new vote for this poll option * * @param \Frontpage\Model\PollVote $pollVote */ public function addVote($pollVote) { $pollVote->setPollOption($this); $this->votes[] = $pollVote; }