$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()); $t->is($forum->getNbPosts(), 3, 'Updating a message doesn\'t change the forum\'s post count'); $t->is($forum->getUpdatedAt('U'), $msg3->getCreatedAt('U'), 'Updating a message doesn\'t change the forum\'s last update date'); $t->is($forum->getLatestPost()->getId(), $msg3->getId(), 'Updating a message doesn\'t change the forum\'s last reply'); $t->diag('Updating the topic'); sleep(1); $topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId()); $topic->setTitle('this is another test'); $topic->save();
public function executeDeletePost() { $post = sfSimpleForumPostPeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($post); $topic = $post->getTopic(); if ($topic->countsfSimpleForumPosts() == 1) { // it is the last post of the topic, so delete the whole topic $topic->delete(); $forum = $post->getsfSimpleForumForum(); $this->redirect($this->getModuleName() . '/forum?forum_name=' . $forum->getStrippedName()); } else { // delete only one message and redirect to the topic $post->delete(); $this->redirect($this->getModuleName() . '/topic?id=' . $topic->getId() . '&stripped_title=' . $topic->getStrippedTitle()); } }