/** * 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); }
/** * Displays poll form * * @throws sfException */ public function executePoll_form() { if (!isset($this->poll_id)) { throw new sfException('poll_id is missing'); } $poll = sfPollPeer::retrieveByPK($this->poll_id); if (!$poll) { throw new sfException('Unable to retrieve poll object'); } $this->poll = $poll; }
/** * Displays a poll answer creation form through an ajax call * **/ public function executeAddAnswer() { $answer_text = $this->getRequestParameter('answer_text'); $answer_text = $answer_text === 'null' ? NULL : $answer_text; $poll_id = $this->getRequestParameter('poll_id'); $poll = sfPollPeer::retrieveByPK($poll_id); $answer_exists = sfPollAnswerPeer::exists($poll_id, $answer_text); $this->count_user_answers = $poll->getCountUserAnswers(); if ($poll && trim($answer_text) != '' && !$answer_exists) { $this->answer = $poll->addAnswer($answer_text); } }
public function getsfPoll($con = null) { if ($this->asfPoll === null && $this->poll_id !== null) { include_once 'plugins/sfPropelPollsPlugin/lib/model/om/BasesfPollPeer.php'; $this->asfPoll = sfPollPeer::retrieveByPK($this->poll_id, $con); } return $this->asfPoll; }
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = sfPollPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setTitle($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setDescription($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setIsPublished($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setCreatedAt($arr[$keys[4]]); } }
public static function doSelectJoinAllExceptsfPollAnswer(Criteria $c, $con = null) { foreach (sfMixer::getCallables('BasesfPollUserAnswerPeer:doSelectJoinAllExcept:doSelectJoinAllExcept') as $callable) { call_user_func($callable, 'BasesfPollUserAnswerPeer', $c, $con); } $c = clone $c; if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } sfPollUserAnswerPeer::addSelectColumns($c); $startcol2 = sfPollUserAnswerPeer::NUM_COLUMNS - sfPollUserAnswerPeer::NUM_LAZY_LOAD_COLUMNS + 1; sfPollPeer::addSelectColumns($c); $startcol3 = $startcol2 + sfPollPeer::NUM_COLUMNS; $c->addJoin(sfPollUserAnswerPeer::POLL_ID, sfPollPeer::ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = sfPollUserAnswerPeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); $omClass = sfPollPeer::getOMClass(); $cls = Propel::import($omClass); $obj2 = new $cls(); $obj2->hydrate($rs, $startcol2); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj2 = $temp_obj1->getsfPoll(); if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addsfPollUserAnswer($obj1); break; } } if ($newObject) { $obj2->initsfPollUserAnswers(); $obj2->addsfPollUserAnswer($obj1); } $results[] = $obj1; } return $results; }
public static function retrieveByPKs($pks, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(); $criteria->add(sfPollPeer::ID, $pks, Criteria::IN); $objs = sfPollPeer::doSelect($criteria, $con); } return $objs; }