public function executeShow() { $id = $this->getRequestParameter('id'); $this->forward404Unless($id); // for backward compability will be corrected. $this->cod = SnippetPeer::retrieveByPK(1); if (myUtils::is_int_val($id) && $id > 0 && $id < 31) { $this->code = SnippetPeer::retrieveByPK($id); } else { $this->code = sfPropelFriendlyUrl::retrieveByFriendlyUrl('Snippet', $id); } $this->forward404Unless($this->code); if ($this->code->getDraft() && (!$this->getUser()->isAuthenticated() || !myUtils::isUserRecord('SnippetPeer', $this->code->getId(), $this->getUser()->getId()))) { $this->forward404(); } }
public static function getMostDiscussedCodes($max = 10) { $codes = array(); $con = Propel::getConnection(); $sql = 'SELECT %s AS code_id FROM %s LEFT JOIN %s ON %s = %s WHERE %s = false GROUP BY %s ORDER BY COUNT(*) DESC, %s DESC'; $sql = sprintf($sql, SnippetPeer::ID, SnippetPeer::TABLE_NAME, CommentPeer::TABLE_NAME, SnippetPeer::ID, CommentPeer::SNIPPET_ID, SnippetPeer::DRAFT, SnippetPeer::ID, CommentPeer::ID); $stmt = $con->prepareStatement($sql); $stmt->setLimit($max); $rs = $stmt->executeQuery(); while ($rs->next()) { $codes[] = SnippetPeer::retrieveByPK($rs->getInt('code_id')); } return $codes; }