protected function handle() { $forum_id = $this->forumId; $forum = ForumModel::getForum($forum_id); $request = $this->getRequest(); $session = $this->getSession(); if (!$forum) { if ($request->isXmlHttpRequest()) { throw new \Exception('论坛不存在'); } else { $session->addFlash('error', '论坛不存在'); return new RedirectResponse($this->generateUrl('admin_forum_index')); } } if ($request->getMethod() == 'POST') { $posts = $request->request; $db = ForumDatabase::getDb(); $db->transaction(); try { $name = $posts->get('name'); if (!$name) { throw new \Exception('分组名称不能为空'); } $description = $posts->get('description'); $search = $posts->get('search'); if ($search) { // 检查重复性 $g = GroupModel::search($search, $forum_id); if ($g) { throw new \Exception('URL占位符已被使用'); } } else { $search = null; } $group = new GroupModel(); $group->name = $name; $group->search = $search; $group->description = $description; $group->forumId = $forum_id; $now = time(); $group->createTimestamp = $now; $group->updateTimestamp = $now; // 更改论坛数据 $forum->groupCount += 1; // 保存 GroupModel::createGroup($group); ForumModel::saveForum($forum); $db->commit(); $session->addFlash('success', '操作成功'); } catch (\Exception $e) { $db->rollback(); $session->addFlash('error', $e->getMessage()); } return new RedirectResponse($this->generateUrl('admin_forum_group_index', array('forum_id' => $forum_id))); } return $this->render('group/add.html.twig', array('forum' => $forum)); }
protected function handle() { $forum_id = $this->id; $forum = ForumModel::getForum($forum_id); if (!$forum) { $session = $this->getSession(); $session->addFlash('error', '论坛不存在'); return new RedirectResponse($this->generateUrl('admin_forum_index')); } $request = $this->getRequest(); if ($request->getMethod() == 'POST') { $posts = $request->request; $session = $this->getSession(); try { // 检查 $name = $posts->get('name'); if (!$name) { throw new \Exception('论坛名称不能为空'); } if (strlen(trim($name)) < 2) { throw new \Exception('论坛名称至少2个字符'); } $description = $posts->get('description'); $search = $posts->get('search'); if ($search) { // 检查重复 $f = ForumModel::search($search); if ($f && $f->id != $forum->id) { throw new \Exception("URL占位符为 {$search} 的论坛已存在"); } } else { $search = null; } $icon = $posts->get('icon'); $logo = $posts->get('logo'); $slogan = $posts->get('slogan'); // 更新 $forum->name = $name; $forum->description = $description; $forum->search = $search; $forum->icon = $icon; $forum->logo = $logo; $forum->slogan = $slogan; $forum->updateTimestamp = time(); // 保存 ForumModel::saveForum($forum); $session->addFlash('success', '操作成功'); } catch (\Exception $e) { $session->addFlash('error', $e->getMessage()); } return new RedirectResponse($this->generateUrl('admin_forum_edit', array('id' => $forum_id))); } return $this->render('forum/edit.html.twig', array('forum' => $forum)); }
/** * @return null|ForumModel * @throws \Exception */ protected function getForum() { $id_or_search = FORUM; // 优先search $forum = ForumModel::search($id_or_search); if (!$forum) { $forum = ForumModel::getForum($id_or_search); } if (!$forum) { throw new \Exception('论坛 ' . FORUM . ' 不存在'); } return $forum; }
protected function handle() { $forum_id = $this->forumId; $forum = ForumModel::getForum($forum_id); if (!$forum) { $session = $this->getSession(); $session->addFlash('error', '论坛不存在'); return new RedirectResponse($this->generateUrl('admin_forum_index')); } // 查询出论坛的所有分组 $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'); }); $request = $this->getRequest(); if ($request->getMethod() == 'POST') { // 对分组进行排序 $session = $this->getSession(); $posts = $request->request; $weights = $posts->get('weight'); $db = WWWDatabase::getDb(); $db->transaction(); try { foreach ($weights as $group_id => $weight) { $group = GroupModel::getGroup($group_id); if ($group) { $group->weight = $weight; // 保存 GroupModel::saveGroup($group); } } $db->commit(); $session->addFlash('success', '操作成功'); } catch (\Exception $e) { $session->addFlash('error', $e->getMessage()); $db->rollback(); } return new RedirectResponse($this->generateUrl('admin_forum_group_index', array('forum_id' => $forum_id))); } return $this->render('group/index.html.twig', array('forum' => $forum, 'groups' => $groups)); }
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)); } }
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)); }