public function executeQuestion() { $user = $this->authenticateUser(); if (!$user) { $this->error_code = 1; $this->error_message = 'login failed'; return array('api', 'errorSuccess'); } if (!$this->getRequestParameter('stripped_title')) { $this->error_code = 2; $this->error_message = 'the API returns answers to a specific question. Please provide a stripped_title parameter'; return array('api', 'errorSuccess'); } else { // get the question $question = QuestionPeer::getQuestionFromTitle($this->getRequestParameter('stripped_title')); if ($question->getUserId() != $user->getId()) { $this->error_code = 3; $this->error_message = 'You can only use the API for the questions you asked'; return array('api', 'errorSuccess'); } else { // get the answers $this->answers = $question->getAnswers(); $this->question = $question; } } }
public function executeResetQuestionReports() { $question = QuestionPeer::getQuestionFromTitle($this->getRequestParameter('stripped_title')); $this->forward404Unless($question); $question->deleteReports(); $question->save(); $this->redirect($this->getRequest()->getReferer()); }
public function executeSearch() { if ($this->getRequestParameter('search')) { $this->questions = QuestionPeer::search($this->getRequestParameter('search'), $this->getRequestParameter('search_all', false), ($this->getRequestParameter('page', 1) - 1) * sfConfig::get('app_search_results_max'), sfConfig::get('app_search_results_max')); } else { $this->redirect('@homepage'); } }
public function executeShow() { $this->question = QuestionPeer::retrieveByPk($this->getRequestParameter('id')); $c = new Criteria(); $c->add(SolutionPeer::QUESTION_ID, $this->question->getId()); $c->addDescendingOrderByColumn(SolutionPeer::CREATED_AT); $this->solutions = SolutionPeer::doSelect($c); $this->forward404Unless($this->question); }
public function executeInterested() { $this->question = QuestionPeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($this->question); $user = $this->getUser()->getSubscriber(); $interest = new Interest(); $interest->setQuestion($this->question); $interest->setUser($user); $interest->save(); }
public function executeRemove() { // disable web debug toolbar sfConfig::set('sf_web_debug', false); $this->question = QuestionPeer::getQuestionFromTitle($this->getRequestParameter('stripped_title')); $this->forward404Unless($this->question); // remove tag for this user and question $user = $this->getUser()->getSubscriber(); $tag = $this->getRequestParameter('tag'); $user->removeTag($this->question, $tag); $this->tags = $this->question->getTags(); // clear the question tag list fragment in cache if (sfConfig::get('sf_cache')) { $this->getContext()->getViewCacheManager()->remove('@question?stripped_title=' . $this->question->getStrippedTitle(), 'fragment_question_tags'); } }
public function executeAdd() { if ($this->getRequest()->getMethod() == sfRequest::POST) { if (!$this->getRequestParameter('body')) { return sfView::NONE; } $question = QuestionPeer::retrieveByPk($this->getRequestParameter('question_id')); $this->forward404Unless($question); // user or anonymous coward $user = $this->getUser()->isAuthenticated() ? $this->getUser()->getSubscriber() : UserPeer::getUserFromNickname('anonymous'); // create answer $this->answer = new Answer(); $this->answer->setQuestion($question); $this->answer->setBody($this->getRequestParameter('body')); $this->answer->setUser($user); $this->answer->save(); return sfView::SUCCESS; } $this->forward404(); }
public function executeQuestion() { $question = QuestionPeer::getQuestionFromTitle($this->getRequestParameter('stripped_title')); $this->forward404Unless($question); // answers $c = new Criteria(); $c->add(AnswerPeer::QUESTION_ID, $question->getId()); $c->addDescendingOrderByColumn(AnswerPeer::CREATED_AT); $c->setLimit(sfConfig::get('app_feed_max_questions')); $answers = AnswerPeer::doSelect($c); $feed = sfFeed::newInstance('rss201rev2'); // channel $feed->setTitle($question->getTitle() . ' feed'); $feed->setLink('@question?stripped_title=' . $question->getStrippedTitle()); $feed->setFeedUrl('@feed_question?stripped_title=' . $question->getStrippedTitle()); $feed->setDescription('Latest answers to the question: ' . $question->getTitle()); // items $feed->setItems($answers); $this->feed = $feed; }
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = QuestionPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setUserId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setTitle($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setBody($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setCreatedAt($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setUpdatedAt($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setInterestedUsers($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setStrippedTitle($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setHtmlBody($arr[$keys[8]]); } }
public static function doSelectJoinAllExceptUser(Criteria $c, $con = null) { $c = clone $c; if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } AnswerPeer::addSelectColumns($c); $startcol2 = AnswerPeer::NUM_COLUMNS - AnswerPeer::NUM_LAZY_LOAD_COLUMNS + 1; QuestionPeer::addSelectColumns($c); $startcol3 = $startcol2 + QuestionPeer::NUM_COLUMNS; $c->addJoin(AnswerPeer::QUESTION_ID, QuestionPeer::ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = AnswerPeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); $omClass = QuestionPeer::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->getQuestion(); if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addAnswer($obj1); break; } } if ($newObject) { $obj2->initAnswers(); $obj2->addAnswer($obj1); } $results[] = $obj1; } return $results; }
<?php define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..')); define('SF_APP', 'frontend'); define('SF_ENVIRONMENT', 'dev'); define('SF_DEBUG', true); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; sfContext::getInstance(); $questions = QuestionPeer::doSelect(new Criteria()); foreach ($questions as $question) { $question->updateSearchIndex(); }
public function getQuestion($con = null) { include_once 'lib/model/om/BaseQuestionPeer.php'; if ($this->aQuestion === null && $this->question_id !== null) { $this->aQuestion = QuestionPeer::retrieveByPK($this->question_id, $con); } return $this->aQuestion; }
<?php if ($sf_user->hasCredential(array(0 => 'moderator'))) { ?> <h2><?php echo __('moderation'); ?> </h2> <ul> <li><?php echo link_to(__('reported questions'), 'moderator/reportedQuestions'); ?> (<?php echo QuestionPeer::getReportCount(); ?> )</li> <li><?php echo link_to(__('reported answers'), 'moderator/reportedAnswers'); ?> (<?php echo AnswerPeer::getReportCount(); ?> )</li> <li><?php echo link_to(__('unpopular tags'), 'moderator/unpopularTags'); ?> </li> </ul> <?php }
public function executeQuestion() { $this->question = QuestionPeer::getQuestionFromTitle($this->getRequestParameter('stripped_title')); }
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(QuestionPeer::ID, $pks, Criteria::IN); $objs = QuestionPeer::doSelect($criteria, $con); } return $objs; }
public function countQuestions($criteria = null, $distinct = false, $con = null) { include_once 'lib/model/om/BaseQuestionPeer.php'; if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } $criteria->add(QuestionPeer::USER_ID, $this->getId()); return QuestionPeer::doCount($criteria, $distinct, $con); }
public function executeReportQuestion() { $this->question = QuestionPeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($this->question); $spam = new ReportQuestion(); $spam->setQuestionId($this->question->getId()); $spam->setUserId($this->getUser()->getSubscriberId()); $spam->save(); }
<?php $qid = $sf_request->getParameter('qid'); $c = new Criteria(); $c->add(QuestionPeer::ID, $qid); $data = QuestionPeer::doSelect($c); if ($data[0]) { echo $data[0]->getQuestion(); echo input_hidden_tag('question_id', $qid); echo input_hidden_tag('qid', $qid); }