Ejemplo n.º 1
0
 public function __invoke($group_slug = null, $board_slug = null)
 {
     $forum = $this->getForum();
     $group = GroupModel::search($group_slug, $forum->id);
     if (!$group) {
         $group = GroupModel::getGroup($group_slug);
     }
     $board = BoardModel::search($board_slug, $forum->id, $group->id);
     if (!$board) {
         $board = BoardModel::getBoard($board_slug);
     }
     $request = $this->getRequest();
     $t_page = $request->query->get('t_page');
     $t_size = $request->query->get('t_size');
     if (!$t_page) {
         $t_page = 1;
     }
     if (!$t_size) {
         $t_size = 5;
     }
     $threads_pager = ThreadModel::listThreads($t_page, $t_size, function (QueryBuilder $qb) use($board, $group, $forum) {
         $qb->andWhere($qb->expr()->eq('board_id', ':board_id'))->setParameter(':board_id', $board->id);
         $qb->andWhere($qb->expr()->eq('group_id', ':group_id'))->setParameter(':group_id', $group->id);
         $qb->andWhere($qb->expr()->eq('forum_id', ':forum_id'))->setParameter(':forum_id', $forum->id);
         $qb->addOrderBy('create_timestamp', 'desc');
     });
     $threads_pager->setPageParamName('t_page');
     $threads_pager->setBaseUrl($this->generateUrl('forum_board_threads', array('group_slug' => $group->search ? $group->search : $group->id, 'board_slug' => $board->search ? $board->search : $board->id)));
     return $this->render('board/threads.html.twig', array('pager' => $threads_pager, 'group' => $group, 'board' => $board));
 }
Ejemplo n.º 2
0
 protected function handle()
 {
     $board_id = $this->boardId;
     $board = BoardModel::getBoard($board_id);
     $moderators = ModeratorModel::allModerator(function (QueryBuilder $qb) use($board) {
         $qb->andWhere($qb->expr()->eq('board_id', ':board_id'))->setParameter(':board_id', $board->id);
         $qb->andWhere($qb->expr()->eq('forum_id', ':forum_id'))->setParameter(':forum_id', $board->forumId);
     });
     $session = $this->getSession();
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $posts = $request->request;
         $moderator_ids = $posts->get('moderators');
         if (!$moderator_ids) {
             $moderator_ids = array();
         } else {
             $moderator_ids = explode(',', $moderator_ids);
         }
         // 先删除所有的管理员, 再逐个添加
         $db = ForumDatabase::getDb();
         $db->transaction();
         try {
             foreach ($moderators as $k => $moderator) {
                 $moderator_id = $moderator['id'];
                 ModeratorModel::deleteModerator($moderator_id);
             }
             foreach ($moderator_ids as $user_id) {
                 $moderator = new ModeratorModel();
                 $moderator->forumId = $board->forumId;
                 $moderator->boardId = $board->id;
                 $moderator->userId = $user_id;
                 ModeratorModel::createModerator($moderator);
             }
             $db->commit();
             $session->addFlash('success', '操作成功');
         } catch (\Exception $e) {
             $db->rollback();
             $session->addFlash('error', $e->getMessage());
         }
         return new JsonResponse(array());
     }
     $moderator_ids = array();
     foreach ($moderators as $k => $moderator) {
         $moderator_ids[] = $moderator['user_id'];
     }
     $moderator_ids = implode(',', $moderator_ids);
     // 采用GraphQL的形式进行查询
     $user_api_url = $this->getContainer()->getParameter('user_url') . '/api/graphql';
     return $this->render('moderator/index.html.twig', array('moderators' => $moderator_ids, 'board' => $board, 'api' => $user_api_url));
 }
Ejemplo n.º 3
0
 public function __invoke($group_slug = null, $board_slug = null)
 {
     $group_id_or_search = $group_slug;
     $board_id_or_search = $board_slug;
     $forum = $this->getForum();
     // 优先search
     $group = GroupModel::search($group_id_or_search, $forum->id);
     if (!$group) {
         $group = GroupModel::getGroup($group_id_or_search);
     }
     $board = BoardModel::search($board_id_or_search, $forum->id, $group->id);
     if (!$board) {
         $board = BoardModel::getBoard($board_id_or_search);
     }
     // 获得论坛的分组信息
     $groups = GroupModel::allGroup(function (QueryBuilder $qb) use($forum) {
         $qb->andWhere($qb->expr()->eq('forum_id', ':forum_id'))->setParameter(':forum_id', $forum->id);
         $qb->addOrderBy('weight', 'desc');
         $qb->addOrderBy('create_timestamp');
     });
     // 子版块
     $sub_boards = BoardModel::allBoards(function (QueryBuilder $qb) use($board) {
         $qb->andWhere($qb->expr()->eq('parent_id', ':parent_id'))->setParameter(':parent_id', $board->id);
         $qb->addOrderBy('weight', 'desc');
         $qb->addOrderBy('create_timestamp');
     });
     // 导航
     $breadcrumbs = array();
     $breadcrumbs[] = array('url' => $this->generateUrl('forum_group', array('slug' => $group_id_or_search)), 'title' => $group->name);
     if ($board->path) {
         $board_ids = explode(',', $board->path);
         foreach ($board_ids as $board_id) {
             $b = BoardModel::getBoard($board_id);
             $breadcrumbs[] = array('url' => $this->generateUrl('forum_board', array('group_slug' => $group_id_or_search, 'board_slug' => $b->search ? $b->search : $b->id)), 'title' => $b->name);
         }
     }
     // 自己
     $breadcrumbs[] = array('url' => $this->generateUrl('forum_board', array('group_slug' => $group_id_or_search, 'board_slug' => $board->search ? $board->search : $board->id)), 'title' => $board->name);
     return $this->render('board/index.html.twig', array('forum' => $forum, 'groups' => $groups, 'group' => $group, 'board' => $board, 'sub_boards' => $sub_boards, 'breadcrumbs' => $breadcrumbs));
 }
Ejemplo n.º 4
0
 protected function handle()
 {
     $board_id = $this->id;
     $board = BoardModel::getBoard($board_id);
     if (!$board) {
         throw new \Exception('论坛版块不存在');
     }
     $group = GroupModel::getGroup($board->groupId);
     if (!$group) {
         throw new \Exception('论坛分组不存在');
     }
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $session = $this->getSession();
         $posts = $request->request;
         $db = WWWDatabase::getDb();
         $db->transaction();
         try {
             $name = $posts->get('name');
             if (!$name) {
                 throw new \Exception('版块名称不能为空');
             }
             $description = $posts->get('description');
             $search = $posts->get('search');
             if ($search) {
                 // 检查重复性
                 $g = BoardModel::search($search, $group->forumId, $group->id);
                 if ($g && $g->id != $board->id) {
                     throw new \Exception('URL占位符已被使用');
                 }
             } else {
                 $search = null;
             }
             $icon = $posts->get('icon');
             $weight = $posts->get('weight');
             $board_per_row = $posts->get('board_per_row');
             $board_per_row = intval($board_per_row);
             if (!$board_per_row) {
                 $board_per_row = 1;
             }
             // 创建
             $board->name = $name;
             $board->search = $search;
             $board->description = $description;
             $board->icon = $icon;
             $board->weight = intval($weight);
             $board->boardPerRow = $board_per_row;
             $now = time();
             $board->updateTimestamp = $now;
             // 保存
             BoardModel::saveBoard($board);
             $db->commit();
             $session->addFlash('success', '操作成功');
         } catch (\Exception $e) {
             $db->rollback();
             $session->addFlash('error', '操作失败');
         }
         return new JsonResponse(array('status' => 1, 'data' => 'success'));
     }
     return $this->render('board/edit.html.twig', array('board' => $board));
 }
Ejemplo n.º 5
0
    protected function handle()
    {
        $board_id = $this->id;
        $board = BoardModel::getBoard($board_id);
        $group = GroupModel::getGroup($board->groupId);
        $forum = ForumModel::getForum($group->forumId);
        // 子版块
        $sub_boards = BoardModel::allBoards(function (QueryBuilder $qb) use($board) {
            $qb->andWhere($qb->expr()->eq('parent_id', ':parent_id'))->setParameter(':parent_id', $board->id);
            $qb->addOrderBy('weight', 'desc');
            $qb->addOrderBy('create_timestamp');
        });
        $columns = array('ID', '标题', '作者', '回复');
        // 主题
        $request = $this->getRequest();
        if ($request->isXmlHttpRequest()) {
            $posts = $request->request;
            $page_offset = $posts->get('start');
            $page_offset = intval($page_offset);
            $page_size = $posts->get('length');
            $page_size = intval($page_size);
            $is_all = false;
            if ($page_size < 0) {
                $is_all = true;
            }
            $s_echo = $posts->get('draw');
            $s_echo = intval($s_echo);
            $search = $posts->get('search');
            $search_value = $search['value'];
            $records = array();
            $records['data'] = array();
            $records['draw'] = $s_echo;
            $records['recordsTotal'] = 0;
            $records['recordsFiltered'] = 0;
            if ($is_all) {
                $page_size = ThreadModel::getCount(function (QueryBuilder $qb) use($board, $search_value) {
                    $qb->andWhere($qb->expr()->eq('board_id', ':board_id'))->setParameter(':board_id', $board->id);
                    if ($search_value) {
                        $qb->orWhere($qb->expr()->like("`title`", ":title"))->setParameter(":title", "%{$search_value}%");
                    }
                    $qb->addOrderBy('update_timestamp', 'desc');
                    $qb->addOrderBy('create_timestamp', 'desc');
                });
            }
            $page = $page_offset / $page_size + 1;
            $pager = ThreadModel::listThreads($page, $page_size, function (QueryBuilder $qb) use($board, $search_value) {
                $qb->andWhere($qb->expr()->eq('board_id', ':board_id'))->setParameter(':board_id', $board->id);
                if ($search_value) {
                    $qb->orWhere($qb->expr()->like("`title`", ":title"))->setParameter(":title", "%{$search_value}%");
                }
                $qb->addOrderBy('update_timestamp', 'desc');
                $qb->addOrderBy('create_timestamp', 'desc');
            });
            $total = $pager->getCount();
            $records['recordsTotal'] = $total;
            $records['recordsFiltered'] = $total;
            $data = $pager->getData();
            /*$columns = array(
                  'ID', '标题', '作者', '回复',
              );*/
            foreach ($data as $k => $v) {
                $line = array();
                $line[] = '<input type="checkbox" name="id[]" value="' . $v['id'] . '">';
                $line[] = $v['id'];
                $line[] = $v['title'];
                $line[] = $v['author_name'] . '(' . date('Y-m-d H:i:s', $v['create_timestamp']) . ')';
                $line[] = $v['reply_author_name'] . '(' . date('Y-m-d H:i:s', $v['reply_timestamp']) . ')';
                $operation = '<div class="btn-group">
<a href="javascript:void(0);" data-toggle="dropdown" aria-expanded="false">操作 <i class="fa fa-angle-down"></i></a>
<ul class="dropdown-menu pull-right" role="menu">
</ul>
</div>';
                $line[] = $operation;
                $records['data'][] = $line;
            }
            return new JsonResponse($records);
        } else {
            return $this->render('board/index.html.twig', array('forum' => $forum, 'group' => $group, 'board' => $board, 'sub_boards' => $sub_boards, 'columns' => $columns));
        }
    }
Ejemplo n.º 6
0
 public function __invoke($board_id)
 {
     // 检查登录
     $session = $this->getSession();
     if (!isset($session['auth'])) {
         $current_url = $this->getCurrentUrl();
         return new RedirectResponse($this->generateUrl('forum_login') . '?redirection=' . $current_url);
     }
     $board = BoardModel::getBoard($board_id);
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $posts = $request->request;
         $db = ForumDatabase::getDb();
         $db->transaction();
         try {
             // 检查
             $title = $posts->get('title');
             if (!$title) {
                 throw new \Exception('请输入帖子标题');
             }
             $content = $posts->get('content');
             // 创建
             $thread = new ThreadModel();
             $thread->title = $title;
             $thread->boardId = $board->id;
             $thread->groupId = $board->groupId;
             $thread->forumId = $board->forumId;
             $thread->authorId = $session['auth']['id'];
             $thread->authorName = $session['profile']['nickname'];
             $thread->replyAuthorId = $session['auth']['id'];
             $thread->replyAuthorName = $session['profile']['nickname'];
             $now = time();
             $thread->replyTimestamp = $now;
             $thread->createTimestamp = $now;
             $thread->updateTimestamp = $now;
             // 保存
             $thread = ThreadModel::createThread($thread);
             // 创建
             $post = new PostModel();
             $post->threadId = $thread->id;
             $post->boardId = $board->id;
             $post->groupId = $board->groupId;
             $post->forumId = $board->forumId;
             $post->authorId = $session['auth']['id'];
             $post->authorName = $session['profile']['nickname'];
             $post->postId = 0;
             $post->content = $content;
             $post->createTimestamp = $now;
             $post->updateTimestamp = $now;
             // 保存
             $post = PostModel::createPost($post);
             $board->threadCount += 1;
             BoardModel::saveBoard($board);
             // 提交事务
             $db->commit();
             $session->addFlash('success', '发布成功');
             return new JsonResponse(array('status' => 1, 'data' => $thread->id));
         } catch (\Exception $e) {
             $db->rollback();
             return new JsonResponse(array('status' => 0, 'data' => $e->getMessage()));
         }
     } else {
         $forum = $this->getForum();
         // 获得论坛的分组信息
         $groups = GroupModel::allGroup(function (QueryBuilder $qb) use($forum) {
             $qb->andWhere($qb->expr()->eq('forum_id', ':forum_id'))->setParameter(':forum_id', $forum->id);
             $qb->addOrderBy('weight', 'desc');
             $qb->addOrderBy('create_timestamp');
         });
         // 优先search
         $group = GroupModel::getGroup($board->groupId);
         // 导航
         $breadcrumbs = array();
         $breadcrumbs[] = array('url' => $this->generateUrl('forum_group', array('slug' => $group->search ? $group->search : $group->id)), 'title' => $group->name);
         if ($board->path) {
             $board_ids = explode(',', $board->path);
             foreach ($board_ids as $board_id) {
                 $b = BoardModel::getBoard($board_id);
                 $breadcrumbs[] = array('url' => $this->generateUrl('forum_board', array('group_slug' => $group->search ? $group->search : $group->id, 'board_slug' => $b->search ? $b->search : $b->id)), 'title' => $b->name);
             }
         }
         // 自己
         $breadcrumbs[] = array('url' => $this->generateUrl('forum_board', array('group_slug' => $group->search ? $group->search : $group->id, 'board_slug' => $board->search ? $board->search : $board->id)), 'title' => $board->name);
         // 发表帖子
         $breadcrumbs[] = array('title' => '发表帖子');
         return $this->render('thread/post.html.twig', array('forum' => $forum, 'groups' => $groups, 'group' => $group, 'board' => $board, 'breadcrumbs' => $breadcrumbs));
     }
 }
Ejemplo n.º 7
0
 protected function handle()
 {
     $group_id = $this->groupId;
     $group = GroupModel::getGroup($group_id);
     if (!$group) {
         throw new \Exception('论坛分组不存在');
     }
     $forum = ForumModel::getForum($group->forumId);
     $board_id = intval($this->boardId);
     $parent_board = null;
     if ($board_id) {
         $parent_board = BoardModel::getBoard($board_id);
         if (!$parent_board) {
             throw new \Exception('父论坛版块不存在');
         }
     }
     $request = $this->getRequest();
     $session = $this->getSession();
     if ($request->getMethod() == 'POST') {
         $posts = $request->request;
         $db = WWWDatabase::getDb();
         $db->transaction();
         try {
             $name = $posts->get('name');
             if (!$name) {
                 throw new \Exception('版块名称不能为空');
             }
             $description = $posts->get('description');
             $search = $posts->get('search');
             if ($search) {
                 // 检查重复性
                 $g = BoardModel::search($search, $group->forumId, $group->id);
                 if ($g) {
                     throw new \Exception('URL占位符已被使用');
                 }
             } else {
                 $search = null;
             }
             $icon = $posts->get('icon');
             // 创建
             $board = new BoardModel();
             $board->name = $name;
             $board->search = $search;
             $board->description = $description;
             $board->icon = $icon;
             $now = time();
             $board->createTimestamp = $now;
             $board->updateTimestamp = $now;
             $board->forumId = $group->forumId;
             $board->groupId = $group->id;
             $board->parentId = $board_id;
             // 路径
             $path = array();
             while ($parent_board != null) {
                 $path[] = $parent_board->id;
                 if ($parent_board->parentId != 0) {
                     $parent_board = BoardModel::getBoard($parent_board->parentId);
                 } else {
                     $parent_board = null;
                 }
             }
             $board->path = implode(',', array_reverse($path));
             // 保存
             BoardModel::createBoard($board);
             $group->boardCount += 1;
             GroupModel::saveGroup($group);
             $forum->boardCount += 1;
             ForumModel::saveForum($forum);
             $db->commit();
             $session->addFlash('success', '操作成功');
         } catch (\Exception $e) {
             $db->rollback();
             $session->addFlash('error', '操作失败');
         }
         if ($board_id) {
             return new RedirectResponse($this->generateUrl('admin_forum_board_index', array('id' => $board_id)));
         } else {
             return new RedirectResponse($this->generateUrl('admin_forum_group_index', array('forum_id' => $group->forumId)));
         }
     }
     return $this->render('board/add.html.twig', array('group_id' => $group_id, 'board_id' => $board_id));
 }
Ejemplo n.º 8
0
 public function __invoke($group_slug = null, $board_slug = null, $thread_id = null)
 {
     $forum = $this->getForum();
     // 优先search
     $group = GroupModel::search($group_slug, $forum->id);
     if (!$group) {
         $group = GroupModel::getGroup($group_slug);
     }
     $board = BoardModel::search($board_slug, $forum->id, $group->id);
     if (!$board) {
         $board = BoardModel::getBoard($board_slug);
     }
     // 获得论坛的分组信息
     $groups = GroupModel::allGroup(function (QueryBuilder $qb) use($forum) {
         $qb->andWhere($qb->expr()->eq('forum_id', ':forum_id'))->setParameter(':forum_id', $forum->id);
         $qb->addOrderBy('weight', 'desc');
         $qb->addOrderBy('create_timestamp');
     });
     // 导航
     $breadcrumbs = array();
     $breadcrumbs[] = array('url' => $this->generateUrl('forum_group', array('slug' => $group->search ? $group->search : $group->id)), 'title' => $group->name);
     if ($board->path) {
         $board_ids = explode(',', $board->path);
         foreach ($board_ids as $board_id) {
             $b = BoardModel::getBoard($board_id);
             $breadcrumbs[] = array('url' => $this->generateUrl('forum_board', array('group_slug' => $group->search ? $group->search : $group->id, 'board_slug' => $b->search ? $b->search : $b->id)), 'title' => $b->name);
         }
     }
     // 自己
     $breadcrumbs[] = array('url' => $this->generateUrl('forum_board', array('group_slug' => $group->search ? $group->search : $group->id, 'board_slug' => $board->search ? $board->search : $board->id)), 'title' => $board->name);
     // 帖子
     $thread = ThreadModel::getThread($thread_id);
     // 增加浏览次数
     $thread->viewCount += 1;
     // 保存
     $thread = ThreadModel::saveThread($thread);
     $breadcrumbs[] = array('title' => $thread->title);
     $request = $this->getRequest();
     // 回复
     $p_page = $request->query->get('p_page');
     $p_size = $request->query->get('p_size');
     if (!$p_page) {
         $p_page = 1;
     }
     if (!$p_size) {
         $p_size = 7;
     }
     $post_pager = PostModel::listPosts($p_page, $p_size, function (QueryBuilder $qb) use($forum, $group, $board, $thread) {
         $qb->andWhere($qb->expr()->eq('forum_id', ':forum_id'))->setParameter(':forum_id', $forum->id);
         $qb->andWhere($qb->expr()->eq('group_id', ':group_id'))->setParameter(':group_id', $group->id);
         $qb->andWhere($qb->expr()->eq('board_id', ':board_id'))->setParameter(':board_id', $board->id);
         $qb->andWhere($qb->expr()->eq('thread_id', ':thread_id'))->setParameter(':thread_id', $thread->id);
         $qb->addOrderBy('create_timestamp');
     });
     $posts_data = $post_pager->getData();
     foreach ($posts_data as $k => $post) {
         // 获得用户的数据
         $user_id = $post['author_id'];
         $user = $this->getUserInfo($user_id);
         $post['author'] = $user;
         $posts_data[$k] = $post;
     }
     $post_pager->setData($posts_data);
     $post_pager->setPageParamName('p_page');
     return $this->render('thread/index.html.twig', array('forum' => $forum, 'groups' => $groups, 'group' => $group, 'board' => $board, 'breadcrumbs' => $breadcrumbs, 'thread' => $thread, 'post_pager' => $post_pager));
 }