/** * 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); }
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = sfPollAnswerPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setPollId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setName($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setVotes($arr[$keys[3]]); } }
public function countsfPollAnswers($criteria = null, $distinct = false, $con = null) { include_once 'plugins/sfPropelPollsPlugin/lib/model/om/BasesfPollAnswerPeer.php'; if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } $criteria->add(sfPollAnswerPeer::POLL_ID, $this->getId()); return sfPollAnswerPeer::doCount($criteria, $distinct, $con); }
/** * Retrieves poll results * * @return array **/ public function getResults() { $c = new Criteria(); $c->add(sfPollAnswerPeer::POLL_ID, $this->getId()); $c->addJoin(sfPollUserAnswerPeer::ANSWER_ID, sfPollAnswerPeer::ID); $c->clearSelectColumns(); $c->addSelectColumn(sfPollAnswerPeer::ID); $c->addSelectColumn(sfPollAnswerPeer::NAME); $c->addAsColumn('count_votes', 'COUNT(' . sfPollUserAnswerPeer::ID . ')'); $c->addAsColumn('total_votes', '(SELECT COUNT(' . sfPollUserAnswerPeer::ID . ') FROM ' . sfPollUserAnswerPeer::TABLE_NAME . ' WHERE ' . sfPollUserAnswerPeer::POLL_ID . '=' . $this->getId() . ')'); $c->addGroupByColumn(sfPollUserAnswerPeer::ANSWER_ID); $rs = sfPollAnswerPeer::doSelectRS($c); $results = array(); while ($rs->next()) { $count = $rs->getString(3); $total = $rs->getString(4); if (!$total) { break; // Avoid division by zero } $id = $rs->getString(1); $percent = $count * 100 / $total; $results[$id] = array('name' => $rs->getString(2), 'count' => $count, 'percent' => $percent); } foreach ($this->getsfPollAnswers() as $answer) { if (!array_key_exists($answer->getId(), $results)) { $results[$answer->getId()] = array('name' => $answer->getName(), 'count' => 0, 'percent' => 0); } } return $results; }
public static function doSelectJoinAllExceptsfPoll(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; sfPollAnswerPeer::addSelectColumns($c); $startcol3 = $startcol2 + sfPollAnswerPeer::NUM_COLUMNS; $c->addJoin(sfPollUserAnswerPeer::ANSWER_ID, sfPollAnswerPeer::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 = sfPollAnswerPeer::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->getsfPollAnswer(); 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(sfPollAnswerPeer::ID, $pks, Criteria::IN); $objs = sfPollAnswerPeer::doSelect($criteria, $con); } return $objs; }
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; }