$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');
$t->is($topic->getLatestPost()->getId(), $msg3->getId(), 'Updating a message doesn\'t change the topic\'s latest reply');
 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 executeTopic($request)
 {
     $this->setTopicVars($request->getParameter('id'));
     $this->post_pager = $this->topic->getPostsPager($request->getParameter('page', 1), sfConfig::get('app_sfSimpleForumPlugin_max_per_page', 10));
     $this->forward404Unless($this->post_pager, 'Topic not found !');
     if (sfConfig::get('app_sfSimpleForumPlugin_count_views', true)) {
         // lame protection against simple page refreshing
         if ($this->getUser()->getAttribute('sf_simple_forum_latest_viewed_topic') != $this->topic->getId()) {
             $this->topic->incrementViews();
             $this->getUser()->setAttribute('sf_simple_forum_latest_viewed_topic', $this->topic->getId());
         }
         if ($this->getUser()->isAuthenticated()) {
             $this->topic->addViewForUser(sfSimpleForumTools::getConnectedUserId($this->getUser()));
         }
     }
     $this->rankArray = $this->getRankArray();
     if (!$this->topic->getIsLocked() && $this->getUser()->isAuthenticated()) {
         $this->form = new forumPost();
         $this->form->setDefaults(array('topic_id' => $this->topic->get('id')));
         if ($request->isMethod('post')) {
             $this->form->bind($request->getParameter('forum_post'));
             // We must check if the topic isn't locked
             $this->forward404If($this->topic->getIsLocked());
             if ($this->form->isValid()) {
                 $values = $this->form->getValues();
                 $post = new sfSimpleForumPost();
                 $post->setContent($values['content']);
                 $post->setTitle($this->topic->get('title'));
                 $post->setUserId(sfSimpleForumTools::getConnectedUserId($this->getUser()));
                 $post->setTopicId($this->topic->getId());
                 $post->setForumId($this->topic->get('sfSimpleForumForum')->get('id'));
                 $post->save();
                 $this->topic->clearTopicView($this->getUser()->getGuardUser()->getId());
                 $this->redirectToPost($post);
             }
         }
     }
     $response = $this->getResponse();
     $response->addMeta('description', $this->topic->getTitle());
 }
Example #4
0
 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);
 }