$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'); $t->is($topic->getLatestPost()->getId(), $msg3->getId(), 'Updating a message doesn\'t change the topic\'s latest reply'); $forum = sfSimpleForumForumPeer::retrieveByPk($forum->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 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); } } }
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); }