Exemplo n.º 1
0
 /**
  * List of forums with topics and forum forms
  * 
  * @param string $slug
  * 
  * @return Response
  */
 public function indexAction($slug = null)
 {
     $currentForum = $this->getForumManager()->findOneBy(array('slug' => $slug));
     $this->get('breadcrumb_service')->generateBreadcrumb($currentForum);
     //generate breadcrumb
     if ($this->isLoggedAsAdmin()) {
         $forum = new Forum();
         $forumForm = $this->createForm('forum_type', $forum);
         $addResult = $this->addForum($forumForm, $forum, $currentForum ? $currentForum->getSlug() : null);
         //call method to add forum
         if ($addResult instanceof RedirectResponse) {
             //if added correctly or feilure, redirect
             return $addResult;
         }
     }
     $topicForm = false;
     if ($this->isLogged() && $currentForum && $currentForum->getParent()) {
         $topic = new Topic();
         $topic->setForum($currentForum);
         $topicForm = $this->createForm('topic_type', $topic);
         $addResult = $this->addTopic($topicForm, $topic, $currentForum ? $currentForum->getSlug() : null);
         //call method to add topic
         if ($addResult instanceof RedirectResponse) {
             //if added correctly or feilure, redirect
             return $addResult;
         }
     }
     $perPage = 10;
     $pagination = $this->paginator->paginate($this->getForumManager()->findForums($slug ? $slug : null), $this->request->query->getInt('page', 1), $perPage, array('wrap-queries' => true));
     $forumsIds = array();
     foreach ($pagination->getItems() as $paginationForum) {
         $forum = $paginationForum[0];
         $forumsIds[] = $forum->getId();
         foreach ($forum->getChildren() as $child) {
             $forumsIds[] = $child->getId();
         }
     }
     return $this->render('ValantirForumBundle:Forum:index.html.twig', array('forums' => $pagination, 'forumForm' => $this->get('security.authorization_checker')->isGranted('ROLE_FORUM_ADMIN') ? $forumForm->createView() : null, 'topicForm' => $topicForm && $currentForum && $currentForum->getId() ? $topicForm->createView() : null, 'lastPosts' => $this->getPostManager()->getForumsLastPosts($forumsIds), 'forumId' => $currentForum ? $currentForum->getId() : null, 'counts' => $this->getForumManager()->countTopicsAndPosts($slug), 'perPage' => $perPage));
 }
Exemplo n.º 2
0
 /**
  * Adds items to breadcrumb
  * 
  * @param Forum|Topic|Post $object
  * @param string $lastText
  * 
  * @return null - only if object is null
  */
 public function generateBreadcrumb($object, $lastText = null)
 {
     if (!$object) {
         return null;
     }
     switch (true) {
         case $object instanceof Forum:
             $this->generateBreadcrumb($object->getParent());
             $this->addItem('forum_index', $object);
             $this->addLastItem($lastText);
             break;
         case $object instanceof Topic:
             $this->generateBreadcrumb($object->getForum());
             $this->addItem('topic_show', $object);
             $this->addLastItem($lastText);
             break;
         case $object instanceof Post:
             $this->generateBreadcrumb($object->getTopic());
             $this->addLastItem($lastText);
             break;
         default:
             break;
     }
 }
Exemplo n.º 3
0
 /**
  * Adds topic to collection of topics
  * 
  * @param Topic $topic
  * 
  * @return User
  */
 public function addTopic(Topic $topic)
 {
     $topic->setAuthor($this);
     $this->topics->add($topic);
     return $this;
 }