/** * Process a vote for a douche * @param sfWebRequest $request * @param bool $direction true for is a douche, false for not a douche * @return <type> */ protected function processVote(sfWebRequest $request, $direction) { $this->douche = $this->getRoute()->getObject(); // Check the user's hash and the cookie's hash // Then make sure that the hash is valid for this specific douche // based upon what they were viewing if ($this->getUser()->getAttribute('dvote_hash') != $this->getRequest()->getCookie('dvote') || $this->getUser()->getAttribute('dvote_for') != $this->douche->getId()) { $this->forward404('Yikes, that did not want to go, did it?'); } // Overwrite the dvote hash to prevent them from voting on the same person // over and over $this->getUser()->setAttribute('dvote_hash', null); if ($direction) { $vote_score = 1; } else { $vote_score = -1; } // Create the vote for the douche $vote = new DoucheVote(); $vote->setDouche($this->douche); $vote->setSubmitIp($request->getRemoteAddress()); $vote->setVote($vote_score); $vote->save(); $this->direction = (bool) $direction; $this->name = $this->douche->getTwitterName(); $this->upvotes = $this->douche->getUpVotes(); $this->downvotes = $this->douche->getDownVotes(); $this->setTemplate('vote'); return sfView::SUCCESS; }