/** * Deletes a poll answer through an ajax call * **/ public function executeDelAnswer() { $answer_id = $this->getRequestParameter('answer_id'); $answer = sfPollAnswerPeer::retrieveByPK($answer_id); $this->forward404Unless($answer); $answer->delete(); return sfView::NONE; }
/** * Make a user voting for a poll * **/ public function executeVote() { $poll_id = $this->getRequestParameter('poll_id'); $poll = sfPollPeer::retrieveByPK($poll_id); $answer_id = $this->getRequestParameter('answer_id'); $answer = sfPollAnswerPeer::retrieveByPK($answer_id); $this->forward404Unless($poll && $answer); $poll->addUserAnswer(null, $answer->getId(), $_SERVER['REMOTE_ADDR']); $this->setFlash('notice', 'Thanks for your vote'); $this->redirect('@sf_propel_polls_results?id=' . $poll_id); }
/** * Add a sfPollUserAnswer object related to current sfPoll object instance * * @param int $user_id Typically an integer representing a User PK * @param int $answer_id sfPollAnswer PK * @param string $ip_address IP address (optionnal) * @return sfPollUserAnswer * @throws PropelException **/ public function addUserAnswer($user_id, $answer_id, $ip_address = NULL) { if ($this->isNew() or is_null($this->getId())) { throw new PropelException('You cannot add a user answer to an unsaved poll'); } $answer = sfPollAnswerPeer::retrieveByPK($answer_id); if (!$answer) { throw new PropelException('Unable to retrieve answer associated to poll'); } if ($answer->getPollId() !== $this->getId()) { throw new PropelException('The answer provided is not associated with current poll'); } # Checks if user has already voted $user_answer = sfPollUserAnswerPeer::getOrCreate($this->getId(), $user_id, $ip_address); $user_answer->setPollId($this->getId()); $user_answer->setAnswerId($answer_id); $user_answer->setUserId($user_id); $user_answer->setIpAddress($ip_address); $user_answer->save(); return $user_answer; }
public function getsfPollAnswer($con = null) { if ($this->asfPollAnswer === null && $this->answer_id !== null) { include_once 'plugins/sfPropelPollsPlugin/lib/model/om/BasesfPollAnswerPeer.php'; $this->asfPollAnswer = sfPollAnswerPeer::retrieveByPK($this->answer_id, $con); } return $this->asfPollAnswer; }