예제 #1
0
 protected function handle()
 {
     $group_id = $this->id;
     $request = $this->getRequest();
     $session = $this->getSession();
     // 检验参数
     $group = GroupModel::getGroup($group_id);
     if (!$group) {
         if ($request->isXmlHttpRequest()) {
             throw new \Exception('论坛分组不存在');
         } else {
             $session->addFlash('error', '论坛分组不存在');
             return new RedirectResponse($this->generateUrl('admin_forum_group_index', array('forum_id' => $group->forumId)));
         }
     }
     if ($request->getMethod() == 'POST') {
         $posts = $request->request;
         try {
             $name = $posts->get('name');
             if (!$name) {
                 throw new \Exception('分组名称不能为空');
             }
             $description = $posts->get('description');
             $board_per_row = $posts->get('board_per_row');
             if (!$board_per_row) {
                 throw new \Exception('每行显示的版块数不能为空');
             }
             $search = $posts->get('search');
             if ($search) {
                 // 检查重复性
                 $g = GroupModel::search($search, $group->forumId);
                 if ($g && $g->id != $group->id) {
                     throw new \Exception('URL占位符已被使用');
                 }
             } else {
                 $search = null;
             }
             $group->name = $name;
             $group->search = $search;
             $group->description = $description;
             $group->boardPerRow = intval($board_per_row);
             $group->updateTimestamp = time();
             // 保存
             GroupModel::saveGroup($group);
             $session->addFlash('success', '操作成功');
         } catch (\Exception $e) {
             $session->addFlash('error', $e->getMessage());
         }
         return new RedirectResponse($this->generateUrl('admin_forum_group_index', array('forum_id' => $group->forumId)));
     }
     return $this->render('group/edit.html.twig', array('group' => $group));
 }
예제 #2
0
 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));
 }
예제 #3
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));
 }