/** * 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; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param DoucheVote $value A DoucheVote object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(DoucheVote $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }