public function addsfSimpleForumPost(sfSimpleForumPost $l) { $this->collsfSimpleForumPosts[] = $l; $l->setsfGuardUser($this); }
$forum = sfSimpleForumForumPeer::retrieveByPk($forum->getId()); $t->is($forum->getLatestPost()->getId(), $msg1->getId(), 'Newly added message is seen as the forum\'s latest reply'); $t->is($forum->getNbPosts(), 1, 'Adding a first message increments the forum number of posts'); $t->is($forum->getUpdatedAt('U'), $msg1->getCreatedAt('U'), 'Adding a first message changes the forum\'s latest update date to the message creation date'); sleep(1); $msg2 = new sfSimpleForumPost(); $msg2->setTopicId($topic->getId()); $msg2->setUserId($user2->getId()); $msg2->save(); $topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId()); $t->is($topic->getNbPosts(), 2, 'Adding a second message increments the topic number of posts'); $t->is($topic->getNbReplies(), 1, 'A topic can calculate its number of replies based on its number of posts'); $t->is($topic->getUpdatedAt('U'), $msg2->getCreatedAt('U'), 'Adding a second message changes the latest reply date of the topic to the message creation date'); $t->is($topic->getLatestPost()->getAuthorName(), $user2->getUsername(), 'Adding a second message changes the latest reply author name to the message author name'); sleep(1); $msg3 = new sfSimpleForumPost(); $msg3->setTopicId($topic->getId()); $msg3->setUserId($user3->getId()); $msg3->save(); $topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId()); $t->is($topic->getNbPosts(), 3, 'Adding a third message increments the topic number of replies'); $t->is($topic->getUpdatedAt('U'), $msg3->getCreatedAt('U'), 'Adding a third message changes the latest reply date of the topic to the message creation date'); $t->is($topic->getLatestPost()->getAuthorName(), $user3->getUsername(), 'Adding a third message changes the latest reply author name to the message author name'); $t->diag('Updating a message'); sleep(1); $msg1 = sfSimpleForumPostPeer::retrieveByPk($msg1->getId()); $msg1->setTitle('this is a test'); $msg1->save(); $topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId()); $t->is($topic->getNbPosts(), 3, 'Updating a message doesn\'t change the topic post count'); $t->is($topic->getUpdatedAt('U'), $msg3->getCreatedAt('U'), 'Updating a message doesn\'t change the topic\'s last update date');
public function executeCreateTopic($request) { $this->form = new forumTopic(); if ($request->hasParameter('forum_name')) { $this->forum = Doctrine::getTable('sfSimpleForumForum')->retrieveBySlug($request->getParameter('forum_name')); $this->forward404Unless($this->forum, 'Forum not found !'); $this->form->setDefaults(array('forum_id' => $this->forum->get('id'))); } elseif (!$request->isMethod('post')) { // we don't allow new topic outside forum $this->forward404(); } if ($request->isMethod('post')) { $this->form->bind($request->getParameter('forum_topic')); if ($this->form->isValid()) { $values = $this->form->getValues(); $topic = new sfSimpleForumTopic(); $topic->set('forum_id', $values['forum_id']); $topic->setTitle($values['title']); $topic->setUserId(sfSimpleForumTools::getConnectedUserId($this->getUser())); if ($this->getUser()->hasCredential('moderator')) { $topic->setIsSticked($values['is_sticked'] ? 1 : 0); $topic->setIsLocked($values['is_locked'] ? 1 : 0); } $topic->save(); $post = new sfSimpleForumPost(); $post->setContent($values['content']); $post->setTitle($values['title']); $post->setUserId(sfSimpleForumTools::getConnectedUserId($this->getUser())); $post->setsfSimpleForumTopic($topic); $post->setForumId($topic->get('sfSimpleForumForum')->get('id')); $post->save(); $this->redirectToPost($post); } } }
/** * Selects a collection of sfSimpleForumPost objects pre-filled with related topic and forum objects. * * @return array Array of sfSimpleForumPost objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinTopicAndForum(Criteria $c, $con = null) { foreach (sfMixer::getCallables('BasesfSimpleForumPostPeer:doSelectJoinAllExcept:doSelectJoinAllExcept') as $callable) { call_user_func($callable, 'BasesfSimpleForumPostPeer', $c, $con); } $c = clone $c; if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } sfSimpleForumPostPeer::addSelectColumns($c); $startcol2 = sfSimpleForumPostPeer::NUM_COLUMNS - sfSimpleForumPostPeer::NUM_LAZY_LOAD_COLUMNS + 1; sfSimpleForumTopicPeer::addSelectColumns($c); $startcol3 = $startcol2 + sfSimpleForumTopicPeer::NUM_COLUMNS; sfSimpleForumForumPeer::addSelectColumns($c); $startcol4 = $startcol3 + sfSimpleForumForumPeer::NUM_COLUMNS; $c->addJoin(sfSimpleForumPostPeer::TOPIC_ID, sfSimpleForumTopicPeer::ID); $c->addJoin(sfSimpleForumPostPeer::FORUM_ID, sfSimpleForumForumPeer::ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $post = new sfSimpleForumPost(); $post->hydrate($rs); $topic = new sfSimpleForumTopic(); $topic->hydrate($rs, $startcol2); $newObject = true; foreach ($results as $temp_post) { $existing_topic = $temp_post->getsfSimpleForumTopic(); if ($existing_topic->getPrimaryKey() === $topic->getPrimaryKey()) { $newObject = false; $existing_topic->addsfSimpleForumPost($post); break; } } if ($newObject) { $topic->initsfSimpleForumPosts(); $topic->addsfSimpleForumPost($post); } $forum = new sfSimpleForumForum(); $forum->hydrate($rs, $startcol3); $newObject = true; foreach ($results as $temp_post) { $existing_forum = $temp_post->getsfSimpleForumForum(); if ($existing_forum->getPrimaryKey() === $forum->getPrimaryKey()) { $newObject = false; $existing_forum->addsfSimpleForumPost($post); break; } } if ($newObject) { $forum->initsfSimpleForumPosts(); $forum->addsfSimpleForumPost($post); } $results[] = $post; } return $results; }
protected function redirectToPost(sfSimpleForumPost $post) { $position = $post->getPositionInTopic(); $page = ceil(($position + 1) / sfConfig::get('app_sfSimpleForumPlugin_max_per_page', 10)); $this->redirect($this->getModuleName() . '/topic?id=' . $post->getTopic()->getId() . '&stripped_title=' . $post->getTopic()->getSlug() . '&page=' . $page . '#post' . $post->getId()); }
public function executeAddPost() { $topic = sfSimpleForumTopicPeer::retrieveByPK($this->getRequestParameter('topic_id')); $this->forward404Unless($topic); // We must check if the topic isn't locked $this->forward404If($topic->getIsLocked()); $post = new sfSimpleForumPost(); $post->setContent($this->getRequestParameter('body')); $post->setUserId(sfSimpleForumTools::getConnectedUserId()); $post->setTopicId($topic->getId()); $post->save(); $this->redirectToPost($post); }
public function executeAddPost() { $topic = sfSimpleForumTopicPeer::retrieveByPK($this->getRequestParameter('topic_id')); $this->forward404Unless($topic); // We must check if the topic isn't locked $this->forward404If($topic->getIsLocked(), 'Topic is locked, unable to post'); $post = new sfSimpleForumPost(); $post->setContent($this->getRequestParameter('body')); $post->setUserId(sfSimpleForumTools::getConnectedUserId()); $post->setTopicId($topic->getId()); $post->save(); if ($this->getUser()->isAuthenticated()) { $this->getUser()->getProfile()->addKarma(sfConfig::get('app_karma_post_forum_points')); } $this->redirectToPost($post); }