Пример #1
0
 public function __invoke($forum_id)
 {
     $session = $this->getSession();
     $forum = ForumModel::getForum($forum_id);
     if (!$forum) {
         $session->addFlash('error', '论坛版块不存在');
         return new RedirectResponse($this->generateUrl('forum_homepage'));
     }
     /** @var ForumModel[] $sub_tree */
     $sub_tree = $forum->getSubTree();
     $list = array();
     foreach ($sub_tree as $i => $node) {
         if ($i == 0) {
             continue;
         }
         $list[$node->forumId] = $node;
     }
     ForumBusiness::preOrderTree2RecursiveTree($list, $forum);
     $breadcrumbs = $forum->getNodeSinglePath();
     unset($breadcrumbs[0], $breadcrumbs[1]);
     $breadcrumbs = array_values($breadcrumbs);
     $request = $this->getRequest();
     $page = $request->query->get('page');
     if (!$page) {
         $page = 1;
     }
     $size = 20;
     $threads_pager = ThreadModel::listForumThreads($page, $size, function (QueryBuilder $qb) use($forum_id) {
         $qb->andWhere($qb->expr()->eq('forum_id', ':forum_id'))->setParameter(':forum_id', $forum_id);
     });
     return $this->render('forum/board.html.twig', array('forum' => $forum, 'threads_pager' => $threads_pager, 'breadcrumbs' => $breadcrumbs));
 }
Пример #2
0
 protected function handle()
 {
     /** @var ForumModel $root_node */
     $root_node = ForumModel::getRootNode();
     if (!$root_node) {
         // 没有根分类,需要自动创建
         $node = new ForumModel();
         $node->name = '论坛首页';
         $node->description = '论坛首页';
         $node->forumStatus = 1;
         $node->forumType = 'group';
         $now = time();
         $node->createTimestamp = $now;
         $node->updateTimestamp = $now;
         $node->preOrderTreeLeft = 0;
         $node->preOrderTreeRight = 1;
         $root_node = ForumModel::createForumGroup($node);
     }
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $forums_data = $request->request->get('forums');
         if (!$forums_data) {
             $forums_data = array();
         }
         $db = ForumModel::getDb();
         try {
             $db->transaction();
             foreach ($forums_data as $forum_id => $info) {
                 $sort_number = $info['sort'];
                 $forum_name = $info['name'];
                 $forum = ForumModel::getForum($forum_id);
                 if ($forum) {
                     $forum->name = $forum_name;
                     $forum->displayOrder = $sort_number;
                     ForumModel::saveForum($forum);
                 }
             }
             $db->commit();
         } catch (\Exception $e) {
             $db->rollback();
             throw $e;
         }
     }
     /** @var ForumModel[] $sub_tree */
     $sub_tree = $root_node->getSubTree();
     $list = array();
     foreach ($sub_tree as $i => $node) {
         if ($i == 0) {
             continue;
         }
         $list[$node->forumId] = $node;
     }
     ForumBusiness::preOrderTree2RecursiveTree($list, $root_node);
     return $this->render('forum/group-manage.html.twig', array('root_node' => $root_node));
 }
Пример #3
0
 public function __invoke()
 {
     // 论坛首页
     /** @var ForumModel $root_node */
     $root_node = ForumModel::getRootNode();
     /** @var ForumModel[] $sub_tree */
     $sub_tree = $root_node->getSubTree();
     $list = array();
     foreach ($sub_tree as $i => $node) {
         if ($i == 0) {
             continue;
         }
         $list[$node->forumId] = $node;
     }
     ForumBusiness::preOrderTree2RecursiveTree($list, $root_node);
     return $this->render('forum/homepage.html.twig', array('root_node' => $root_node));
 }