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); } } }
// cleanup database sfSimpleForumCategoryPeer::doDeleteAll(); sfSimpleForumForumPeer::doDeleteAll(); sfSimpleForumPostPeer::doDeleteAll(); // Now we can start to test $t = new lime_test(34, new lime_output_color()); // Initialization $cat = new sfSimpleForumCategory(); $cat->save(); $forum = new sfSimpleForumForum(); $forum->setCategoryId($cat->getId()); $forum->save(); $topic = new sfSimpleForumTopic(); $topic->setTitle('This is a test'); $topic->setsfSimpleForumForum($forum); $topic->save(); $user0 = new sfGuardUser(); $user0->setUsername('me'); $user0->setPassword('me'); $user0->save(); $user1 = new sfGuardUser(); $user1->setUsername('foo'); $user1->setPassword('foo'); $user1->save(); $user2 = new sfGuardUser(); $user2->setUsername('bar'); $user2->setPassword('bar'); $user2->save(); $user3 = new sfGuardUser(); $user3->setUsername('baz'); $user3->setPassword('baz');
public function executeAddTopic() { $forum = sfSimpleForumForumPeer::retrieveByStrippedName($this->getRequestParameter('forum_name')); $this->forward404Unless($forum); $topic = new sfSimpleForumTopic(); $topic->setsfSimpleForumForum($forum); $topic->setTitle($this->getRequestParameter('title')); $topic->setUserId(sfSimpleForumTools::getConnectedUserId()); if ($this->getUser()->hasCredential('moderator')) { $topic->setIsSticked($this->getRequestParameter('is_sticked', 0)); $topic->setIsLocked($this->getRequestParameter('is_locked', 0)); } $topic->save(); $post = new sfSimpleForumPost(); $post->setContent($this->getRequestParameter('body')); $post->setUserId(sfSimpleForumTools::getConnectedUserId()); $post->setsfSimpleForumTopic($topic); $post->save(); $this->redirectToPost($post); }