src/AppBundle/Controller/GroupThreadController.php line 160

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller;
  3. use AppBundle\Common\ArrayToolkit;
  4. use AppBundle\Common\Exception\FileToolkitException;
  5. use AppBundle\Common\FileToolkit;
  6. use AppBundle\Common\Paginator;
  7. use Biz\Content\FileException;
  8. use Biz\Content\Service\FileService;
  9. use Biz\Favorite\Service\FavoriteService;
  10. use Biz\File\Service\UploadFileService;
  11. use Biz\Group\Service\GroupService;
  12. use Biz\Group\Service\ThreadService;
  13. use Biz\System\Service\SettingService;
  14. use Biz\User\Service\NotificationService;
  15. use Biz\User\Service\UserService;
  16. use Biz\User\UserException;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\Response;
  19. class GroupThreadController extends BaseController
  20. {
  21.     public function addThreadAction(Request $request$id)
  22.     {
  23.         $user $this->getCurrentUser();
  24.         $groupinfo $this->getGroupService()->getGroup($id);
  25.         if (empty($groupinfo) || 'close' == $groupinfo['status']) {
  26.             return $this->createMessageResponse('info''该小组已被关闭');
  27.         }
  28.         if (!$this->getGroupMemberRole($id)) {
  29.             return $this->createMessageResponse('info''只有小组成员可以发言');
  30.         }
  31.         if ('POST' == $request->getMethod()) {
  32.             try {
  33.                 $threadData $request->request->all();
  34.                 if(!$this->checkDragCaptchaToken($request$threadData['_dragCaptchaToken'])){
  35.                     return $this->createMessageResponse('error'$this->trans("exception.form..drag.expire"));
  36.                 }
  37.                 unset($threadData['_dragCaptchaToken']);
  38.                 $info = [
  39.                     'title' => $threadData['thread']['title'],
  40.                     'content' => $threadData['thread']['content'],
  41.                     'groupId' => $id,
  42.                     'userId' => $user['id'],
  43.                 ];
  44.                 $thread $this->getThreadService()->addThread($info);
  45.                 $attachment $request->request->get('attachment');
  46.                 $this->getUploadFileService()->createUseFiles($attachment['fileIds'], $thread['id'], $attachment['targetType'], $attachment['type']);
  47.                 if (isset($threadData['file'])) {
  48.                     $file $threadData['file'];
  49.                     $this->getThreadService()->addAttach($file$thread['id']);
  50.                 }
  51.                 return $this->redirect($this->generateUrl('group_thread_show', [
  52.                     'id' => $id,
  53.                     'threadId' => $thread['id'],
  54.                 ]));
  55.             } catch (\Exception $e) {
  56.                 return $this->createMessageResponse('error'$this->trans($e->getMessage()), '错误提示'1$request->getPathInfo());
  57.             }
  58.         }
  59.         return $this->render('group/add-thread.html.twig',
  60.             [
  61.                 'id' => $id,
  62.                 'groupinfo' => $groupinfo,
  63.                 'is_groupmember' => $this->getGroupMemberRole($id),
  64.             ]);
  65.     }
  66.     public function updateThreadAction(Request $request$id$threadId)
  67.     {
  68.         $user $this->getCurrentUser();
  69.         $groupinfo $this->getGroupService()->getGroup($id);
  70.         if (!$groupinfo) {
  71.             return $this->createMessageResponse('info''该小组已被关闭');
  72.         }
  73.         $thread $this->getThreadService()->getThread($threadId);
  74.         if (!$this->checkManagePermission($id$thread)) {
  75.             return $this->createMessageResponse('info''您没有权限编辑');
  76.         }
  77.         $thread $this->getThreadService()->getThread($threadId);
  78.         $attachs $this->getThreadService()->searchGoods(['threadId' => $thread['id'], 'type' => 'attachment'], ['createdTime' => 'DESC'], 01000);
  79.         if ('POST' == $request->getMethod()) {
  80.             try {
  81.                 $threadData $request->request->all();
  82.                 $fields = [
  83.                     'title' => $threadData['thread']['title'],
  84.                     'content' => $threadData['thread']['content'],
  85.                 ];
  86.                 $thread $this->getThreadService()->updateThread($threadId$fields);
  87.                 $attachment $request->request->get('attachment');
  88.                 $this->getUploadFileService()->createUseFiles($attachment['fileIds'], $thread['id'], $attachment['targetType'], $attachment['type']);
  89.                 if (isset($threadData['file'])) {
  90.                     $file $threadData['file'];
  91.                     $this->getThreadService()->addAttach($file$thread['id']);
  92.                 }
  93.                 if ($user->isAdmin()) {
  94.                     $message = [
  95.                         'id' => $id,
  96.                         'threadId' => $thread['id'],
  97.                         'title' => $thread['title'],
  98.                         'type' => 'modify',
  99.                     ];
  100.                     $this->getNotifiactionService()->notify($thread['userId'], 'group-thread'$message);
  101.                 }
  102.                 return $this->redirect($this->generateUrl('group_thread_show', [
  103.                     'id' => $id,
  104.                     'threadId' => $threadId,
  105.                 ]));
  106.             } catch (\Exception $e) {
  107.                 return $this->createMessageResponse('error'$this->trans($e->getMessage()), '错误提示'1$request->getPathInfo());
  108.             }
  109.         }
  110.         return $this->render('group/add-thread.html.twig', [
  111.             'id' => $id,
  112.             'groupinfo' => $groupinfo,
  113.             'thread' => $thread,
  114.             'attachs' => $attachs,
  115.             'is_groupmember' => $this->getGroupMemberRole($id),
  116.         ]);
  117.     }
  118.     public function checkUserAction(Request $request)
  119.     {
  120.         $nickname $request->query->get('value');
  121.         $result $this->getUserService()->isNicknameAvaliable($nickname);
  122.         if ($result) {
  123.             $response = ['success' => false'message' => 'json_response.user_not_found.message'];
  124.         } else {
  125.             $response = ['success' => true'message' => ''];
  126.         }
  127.         return $this->createJsonResponse($response);
  128.     }
  129.     public function groupThreadIndexAction(Request $request$id$threadId)
  130.     {
  131.         $group $this->getGroupService()->getGroup($id);
  132.         if ('close' == $group['status']) {
  133.             return $this->createMessageResponse('info''该小组已被关闭');
  134.         }
  135.         $user $this->getCurrentUser();
  136.         $threadMain $this->getThreadService()->getThread($threadId);
  137.         if (empty($threadMain)) {
  138.             return $this->createMessageResponse('info''该话题已被管理员删除');
  139.         }
  140.         if ('close' == $threadMain['status']) {
  141.             return $this->createMessageResponse('info''该话题已被关闭');
  142.         }
  143.         if ('close' != $threadMain['status']) {
  144.             $isCollected = !empty($this->getFavoriteService()->getUserFavorite($this->getCurrentUser()->id'thread'$threadMain['id']));
  145.         } else {
  146.             $isCollected false;
  147.         }
  148.         $this->getThreadService()->waveHitNum($threadId);
  149.         if ($request->query->get('post')) {
  150.             $url $this->getPost($request->query->get('post'), $threadId$id);
  151.             return $this->redirect($url);
  152.         }
  153.         $owner $this->getUserService()->getUser($threadMain['userId']);
  154.         $filters $this->getPostSearchFilters($request);
  155.         $condition $this->getPostCondition($filters['type'], $threadMain['userId'], $threadId);
  156.         $condition['excludeAuditStatus'] = 'illegal';
  157.         $sort $this->getPostOrderBy($filters['sort']);
  158.         $postCount $this->getThreadService()->searchPostsCount($condition);
  159.         $paginator = new Paginator(
  160.             $this->get('request'),
  161.             $postCount,
  162.             30
  163.         );
  164.         $post $this->getThreadService()->searchPosts($condition$sort,
  165.             $paginator->getOffsetCount(),
  166.             $paginator->getPerPageCount());
  167.         $postMemberIds ArrayToolkit::column($post'userId');
  168.         $postId ArrayToolkit::column($post'id');
  169.         $postReplyAll = [];
  170.         $postReply = [];
  171.         $postReplyCount = [];
  172.         $postReplyPaginator = [];
  173.         $postFiles = [];
  174.         foreach ($postId as $value) {
  175.             $replyCount $this->getThreadService()->searchPostsCount(['postId' => $value'excludeAuditStatus' => 'illegal']);
  176.             $replyPaginator = new Paginator(
  177.                 $this->get('request'),
  178.                 $replyCount,
  179.                 10
  180.             );
  181.             $reply $this->getThreadService()->searchPosts(['postId' => $value'excludeAuditStatus' => 'illegal'], ['createdTime' => 'ASC'],
  182.                 $replyPaginator->getOffsetCount(),
  183.                 $replyPaginator->getPerPageCount());
  184.             $postReplyCount[$value] = $replyCount;
  185.             $postReply[$value] = $reply;
  186.             $postReplyPaginator[$value] = $replyPaginator;
  187.             if ($reply) {
  188.                 $postReplyAll array_merge($postReplyAllArrayToolkit::column($reply'userId'));
  189.             }
  190.         }
  191.         $postReplyMembers $this->getUserService()->findUsersByIds($postReplyAll);
  192.         $postMember $this->getUserService()->findUsersByIds($postMemberIds);
  193.         $activeMembers $this->getGroupService()->searchMembers(['groupId' => $id],
  194.             ['postNum' => 'DESC'], 020);
  195.         $memberIds ArrayToolkit::column($activeMembers'userId');
  196.         $members $this->getUserService()->findUsersByIds($memberIds);
  197.         $isAdopt $this->getThreadService()->searchPosts(['adopt' => 1'threadId' => $threadId], ['createdTime' => 'DESC'], 01);
  198.         $threadMain $this->hideThings($threadMain);
  199.         $threadMainContent strip_tags($threadMain['content'], '');
  200.         $threadMainContent preg_replace('/ /'''$threadMainContent);
  201.         return $this->render('group/thread.html.twig', [
  202.             'groupinfo' => $group,
  203.             'isCollected' => $isCollected,
  204.             'threadMain' => $threadMain,
  205.             'user' => $user,
  206.             'owner' => $owner,
  207.             'post' => $post,
  208.             'paginator' => $paginator,
  209.             'postMember' => $postMember,
  210.             'filters' => $filters,
  211.             'postCount' => $postCount,
  212.             'postReply' => $postReply,
  213.             'activeMembers' => $activeMembers,
  214.             'postReplyMembers' => $postReplyMembers,
  215.             'members' => $members,
  216.             'postReplyCount' => $postReplyCount,
  217.             'postReplyPaginator' => $postReplyPaginator,
  218.             'isAdopt' => $isAdopt,
  219.             'threadMainContent' => $threadMainContent,
  220.             'is_groupmember' => $this->getGroupMemberRole($id),
  221.         ]);
  222.     }
  223.     public function postReplyAction(Request $request$postId)
  224.     {
  225.         $postReplyAll = [];
  226.         $replyCount $this->getThreadService()->searchPostsCount(['postId' => $postId]);
  227.         $postReplyPaginator = new Paginator(
  228.             $this->get('request'),
  229.             $replyCount,
  230.             10
  231.         );
  232.         $postReply $this->getThreadService()->searchPosts(['postId' => $postId], ['createdTime' => 'ASC'],
  233.             $postReplyPaginator->getOffsetCount(),
  234.             $postReplyPaginator->getPerPageCount());
  235.         if ($postReply) {
  236.             $postReplyAll array_merge($postReplyAllArrayToolkit::column($postReply'userId'));
  237.         }
  238.         $postReplyMembers $this->getUserService()->findUsersByIds($postReplyAll);
  239.         return $this->render('group/thread-reply-list.html.twig', [
  240.             'postMain' => ['id' => $postId],
  241.             'postReply' => $postReply,
  242.             'postReplyMembers' => $postReplyMembers,
  243.             'postReplyCount' => $replyCount,
  244.             'postReplyPaginator' => $postReplyPaginator,
  245.         ]);
  246.     }
  247.     public function postThreadAction(Request $request$groupId$threadId)
  248.     {
  249.         $user $this->getCurrentUser();
  250.         if (!$user->isLogin()) {
  251.             $this->createNewException(UserException::UN_LOGIN());
  252.         }
  253.         if (!$this->getGroupMemberRole($groupId)) {
  254.             $this->getGroupService()->joinGroup($user$groupId);
  255.         }
  256.         $thread $this->getThreadService()->getThread($threadId);
  257.         $postContent $request->request->all();
  258.         if(!$this->checkDragCaptchaToken($request$postContent['_dragCaptchaToken'])){
  259.             return $this->createJsonResponse(['error' => ['code'=> 403'message' => $this->trans("exception.form..drag.expire")]], 403);
  260.         }
  261.         unset($postContent['_dragCaptchaToken']);
  262.         $fromUserId = empty($postContent['fromUserId']) ? $postContent['fromUserId'];
  263.         $content = [
  264.             'content' => $postContent['content'], 'fromUserId' => $fromUserId,
  265.         ];
  266.         if (isset($postContent['postId'])) {
  267.             $post $this->getThreadService()->postThread($content$groupId$user['id'], $threadId$postContent['postId']);
  268.         } else {
  269.             $post $this->getThreadService()->postThread($content$groupId$user['id'], $threadId);
  270.             if (isset($postContent['file'])) {
  271.                 $file $postContent['file'];
  272.                 $this->getThreadService()->addPostAttach($file$thread['id'], $post['id']);
  273.             }
  274.         }
  275.         $attachment $request->request->get('attachment');
  276.         $this->getUploadFileService()->createUseFiles($attachment['fileIds'], $post['id'], $attachment['targetType'], $attachment['type']);
  277.         $message = [
  278.             'id' => $groupId,
  279.             'threadId' => $thread['id'],
  280.             'title' => $thread['title'],
  281.             'userId' => $user['id'],
  282.             'userName' => $user['nickname'],
  283.             'page' => $this->getPostPage($post['id'], $threadId),
  284.             'post' => $post['id'],
  285.             'type' => 'reply',
  286.         ];
  287.         if ($user->id != $thread['userId']) {
  288.             $this->getNotifiactionService()->notify($thread['userId'], 'group-thread'$message);
  289.         }
  290.         if (empty($fromUserId) && !empty($postContent['postId'])) {
  291.             $post $this->getThreadService()->getPost($postContent['postId']);
  292.             if ($post['userId'] != $user->id && $post['userId'] != $thread['userId']) {
  293.                 $this->getNotifiactionService()->notify($post['userId'], 'group-thread'$message);
  294.             }
  295.         }
  296.         if (!empty($fromUserId) && $fromUserId != $user->id && $fromUserId != $thread['userId']) {
  297.             $this->getNotifiactionService()->notify($postContent['fromUserId'], 'group-thread'$message);
  298.         }
  299.         return $this->createJsonResponse(true);
  300.     }
  301.     public function searchResultAction(Request $request$id)
  302.     {
  303.         $keyWord $request->query->get('keyWord') ?: '';
  304.         $group $this->getGroupService()->getGroup($id);
  305.         $threadSetting $this->getSettingService()->get('ugc_thread', []);
  306.         if (empty($threadSetting['enable_thread']) || empty(($threadSetting['enable_group_thread']))) {
  307.             $paginator = new Paginator(
  308.                 $this->get('request'),
  309.                 0,
  310.                 15
  311.             );
  312.             $threads = [];
  313.         } else {
  314.             $paginator = new Paginator(
  315.                 $this->get('request'),
  316.                 $this->getThreadService()->countThreads(['status' => 'open''title' => $keyWord'groupId' => $id]),
  317.                 15
  318.             );
  319.             $threads $this->getThreadService()->searchThreads(
  320.                 ['status' => 'open''title' => $keyWord'groupId' => $id],
  321.                 ['createdTime' => 'DESC'],
  322.                 $paginator->getOffsetCount(),
  323.                 $paginator->getPerPageCount());
  324.         }
  325.         $ownerIds ArrayToolkit::column($threads'userId');
  326.         $userIds ArrayToolkit::column($threads'lastPostMemberId');
  327.         $owner $this->getUserService()->findUsersByIds($ownerIds);
  328.         $lastPostMembers $this->getUserService()->findUsersByIds($userIds);
  329.         return $this->render('group/group-search-result.html.twig', [
  330.             'groupinfo' => $group,
  331.             'keyWord' => $keyWord,
  332.             'threads' => $threads,
  333.             'owner' => $owner,
  334.             'paginator' => $paginator,
  335.             'lastPostMembers' => $lastPostMembers,
  336.             'is_groupmember' => $this->getGroupMemberRole($id),
  337.         ]);
  338.     }
  339.     public function setEliteAction($threadId)
  340.     {
  341.         return $this->postAction($threadId'setElite');
  342.     }
  343.     public function removeEliteAction($threadId)
  344.     {
  345.         return $this->postAction($threadId'removeElite');
  346.     }
  347.     public function setStickAction($threadId)
  348.     {
  349.         return $this->postAction($threadId'setStick');
  350.     }
  351.     public function removeStickAction($threadId)
  352.     {
  353.         return $this->postAction($threadId'removeStick');
  354.     }
  355.     public function closeThreadAction($threadId$memberId)
  356.     {
  357.         $thread $this->getThreadService()->getThread($threadId);
  358.         $groupMemberRole $this->getGroupMemberRole($thread['groupId']);
  359.         if (== $groupMemberRole || $thread['userId'] == $memberId) {
  360.             $this->getThreadService()->closeThread($threadId);
  361.         }
  362.         return new Response($this->generateUrl('group_show', [
  363.             'id' => $thread['groupId'],
  364.         ]));
  365.     }
  366.     public function deletePostAction($postId)
  367.     {
  368.         $post $this->getThreadService()->getPost($postId);
  369.         $thread $this->getThreadService()->getThread($post['threadId']);
  370.         $groupMemberRole $this->getGroupMemberRole($thread['groupId']);
  371.         $user $this->getCurrentUser();
  372.         if ($user['id'] == $post['userId'] || == $groupMemberRole || == $groupMemberRole || true == $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
  373.             $this->getThreadService()->deletePost($postId);
  374.             $thread $this->getThreadService()->getThread($post['threadId']);
  375.             $message = [
  376.                 'id' => $thread['groupId'],
  377.                 'threadId' => $thread['id'],
  378.                 'title' => $thread['title'],
  379.                 'type' => 'delete-post',
  380.             ];
  381.             $this->getNotifiactionService()->notify($thread['userId'], 'group-thread'$message);
  382.         }
  383.         return new Response($this->generateUrl('group_thread_show', [
  384.             'id' => $thread['groupId'], 'threadId' => $post['threadId'],
  385.         ]));
  386.     }
  387.     public function adoptAction($postId)
  388.     {
  389.         $post $this->getThreadService()->getPost($postId);
  390.         $thread $this->getThreadService()->getThread($post['threadId']);
  391.         $groupMemberRole $this->getGroupMemberRole($thread['groupId']);
  392.         $isAdopt $this->getThreadService()->searchPosts(['adopt' => 1'threadId' => $post['threadId']], ['createdTime''desc'], 01);
  393.         if ($isAdopt) {
  394.             goto response;
  395.         }
  396.         if (== $groupMemberRole || == $groupMemberRole || true == $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
  397.             $post $this->getThreadService()->updatePost($post['id'], ['adopt' => 1]);
  398.         }
  399.         response:
  400.         return new Response($this->generateUrl('group_thread_show', [
  401.             'id' => $thread['groupId'], 'threadId' => $post['threadId'],
  402.         ]));
  403.     }
  404.     protected function postAction($threadId$action)
  405.     {
  406.         $thread $this->getThreadService()->getThread($threadId);
  407.         $groupMemberRole $this->getGroupMemberRole($thread['groupId']);
  408.         $message = [
  409.             'title' => $thread['title'],
  410.             'groupId' => $thread['groupId'],
  411.             'threadId' => $thread['id'],
  412.         ];
  413.         if (== $groupMemberRole || == $groupMemberRole || true == $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
  414.             if ('setElite' == $action) {
  415.                 $this->getThreadService()->setElite($threadId);
  416.                 $message['type'] = 'elite';
  417.                 $this->getNotifiactionService()->notify($thread['userId'], 'group-thread'$message);
  418.             }
  419.             if ('removeElite' == $action) {
  420.                 $this->getThreadService()->removeElite($threadId);
  421.                 $message['type'] = 'unelite';
  422.                 $this->getNotifiactionService()->notify($thread['userId'], 'group-thread'$message);
  423.             }
  424.             if ('setStick' == $action) {
  425.                 $this->getThreadService()->setStick($threadId);
  426.                 $message['type'] = 'top';
  427.                 $this->getNotifiactionService()->notify($thread['userId'], 'group-thread'$message);
  428.             }
  429.             if ('removeStick' == $action) {
  430.                 $this->getThreadService()->removeStick($threadId);
  431.                 $message['type'] = 'untop';
  432.                 $this->getNotifiactionService()->notify($thread['userId'], 'group-thread'$message);
  433.             }
  434.         }
  435.         return new Response($this->generateUrl('group_thread_show', [
  436.             'id' => $thread['groupId'],
  437.             'threadId' => $threadId,
  438.         ]));
  439.     }
  440.     protected function getPost($postId$threadId$id)
  441.     {
  442.         $post $this->getThreadService()->getPost($postId);
  443.         if (!= $post['postId']) {
  444.             $postId $post['postId'];
  445.         }
  446.         $page $this->getPostPage($postId$threadId);
  447.         $url $this->generateUrl('group_thread_show', ['id' => $id'threadId' => $threadId]);
  448.         $url $url."?page=$page#post-$postId";
  449.         return $url;
  450.     }
  451.     public function getPostPage($postId$threadId)
  452.     {
  453.         $count $this->getThreadService()->countThreads(['threadId' => $threadId'status' => 'open''id' => $postId'postId' => 0]);
  454.         return floor(($count) / 30) + 1;
  455.     }
  456.     public function hideThings($thread)
  457.     {
  458.         $thread['content'] = str_replace('#''<!--></>'$thread['content']);
  459.         $thread['content'] = str_replace('[hide=reply''#[hide=reply'$thread['content']);
  460.         $thread['content'] = str_replace('[hide=coin''#[hide=coin'$thread['content']);
  461.         $data explode('[/hide]'$thread['content']);
  462.         $user $this->getCurrentUser();
  463.         $role $this->getGroupMemberRole($thread['groupId']);
  464.         $context '';
  465.         $count 0;
  466.         foreach ($data as $value) {
  467.             $value ' '.$value;
  468.             sscanf($value'%[^#]#[hide=coin%[^]]]%[^$$]'$content$coin$hideContent);
  469.             sscanf($value'%[^#]#[hide=reply]%[^$$]'$replyContent$replyHideContent);
  470.             $trade $this->getThreadService()->getTradeByUserIdAndThreadId($user->id$thread['id']);
  471.             if (== $role || == $role || $user['id'] == $thread['userId'] || !empty($trade)) {
  472.                 if ($coin) {
  473.                     if (== $role || == $role || $user['id'] == $thread['userId']) {
  474.                         $context .= $content."<div class=\"hideContent mtl mbl clearfix\"><span class=\"pull-right\" style='font-size:10px;'>".'隐藏区域'.'</span>'.$hideContent.'</div>';
  475.                     } else {
  476.                         $context .= $content.$hideContent;
  477.                     }
  478.                 } else {
  479.                     $context .= $content;
  480.                 }
  481.             } else {
  482.                 if ($coin) {
  483.                     $count 1;
  484.                     if ($user['id']) {
  485.                         $context .= $content."<div class=\"hideContent mtl mbl\"><h4> <a href=\"javascript:\" data-toggle=\"modal\" data-target=\"#modal\" data-urL=\"/thread/{$thread['id']}/hide\">".'点击查看'.'</a>'.'本话题隐藏内容'.'</h4></div>';
  486.                     } else {
  487.                         $context .= $content.'<div class="hideContent mtl mbl"><h4>'.'游客,如果您要查看本话题隐藏内容请先'.'<a href="/login">'.'登录'.'</a>'.'或'.'<a href="/register">'.'注册'.'</a>!</h4></div>';
  488.                     }
  489.                 } else {
  490.                     $context .= $content;
  491.                 }
  492.             }
  493.             if ($replyHideContent) {
  494.                 $context .= $this->replyCanSee($role$thread$content$replyHideContent);
  495.             }
  496.             unset($coin);
  497.             unset($content);
  498.             unset($replyHideContent);
  499.             unset($hideContent);
  500.             unset($replyContent);
  501.         }
  502.         if ($context) {
  503.             $thread['content'] = $context;
  504.         }
  505.         $thread['count'] = $count;
  506.         $thread['content'] = str_replace('<!--></>''#'$thread['content']);
  507.         return $thread;
  508.     }
  509.     protected function replyCanSee($role$thread$content$replyHideContent)
  510.     {
  511.         $context '';
  512.         $user $this->getCurrentUser();
  513.         if ($replyHideContent) {
  514.             if (== $role || == $role || $user['id'] == $thread['userId']) {
  515.                 $context $content."<div class=\"hideContent mtl mbl clearfix\"><span class=\"pull-right\" style='font-size:10px;'>".'回复可见区域'.'</span>'.$replyHideContent.'</div>';
  516.                 return $context;
  517.             }
  518.             if (!$user['id']) {
  519.                 $context .= $content.'<div class="hideContent mtl mbl"><h4>'.'游客,如果您要查看本话题隐藏内容请先'.'<a href="/login">'.'登录'.'</a>或<a href="/register">'.'注册'.'</a>!</h4></div>';
  520.                 return $context;
  521.             }
  522.             $count $this->getThreadService()->countThreads(['userId' => $user['id'], 'threadId' => $thread['id']]);
  523.             if ($count 0) {
  524.                 $context .= $content.$replyHideContent;
  525.             } else {
  526.                 $context .= $content.'<div class="hideContent mtl mbl"><h4> <a href="#post-thread-form">'.'回复'.'</a>'.'本话题可见'.'</h4></div>';
  527.             }
  528.         }
  529.         return $context;
  530.     }
  531.     public function uploadAction(Request $request)
  532.     {
  533.         $group $request->query->get('group');
  534.         $file $this->get('request')->files->get('file');
  535.         if (!is_object($file)) {
  536.             $this->createNewException(FileException::FILE_EMPTY_ERROR());
  537.         }
  538.         if (filesize($file) > 1024 1024 2) {
  539.             $this->createNewException(FileException::FILE_SIZE_LIMIT());
  540.         }
  541.         if (FileToolkit::validateFileExtension($file'png jpg gif doc xls txt rar zip')) {
  542.             $this->createNewException(FileToolkitException::FILE_TYPE_ERROR());
  543.         }
  544.         $record $this->getFileService()->uploadFile($group$file);
  545.         unset($record['uri']);
  546.         $record['name'] = $file->getClientOriginalName();
  547.         return new Response(json_encode($record));
  548.     }
  549.     protected function isFeatureEnabled($feature)
  550.     {
  551.         $features $this->container->hasParameter('enabled_features') ? $this->container->getParameter('enabled_features') : [];
  552.         return in_array($feature$features);
  553.     }
  554.     protected function getPostSearchFilters($request)
  555.     {
  556.         $filters = [];
  557.         $filters['type'] = $request->query->get('type');
  558.         if (!in_array($filters['type'], ['all''onlyOwner'])) {
  559.             $filters['type'] = 'all';
  560.         }
  561.         $filters['sort'] = $request->query->get('sort');
  562.         if (!in_array($filters['sort'], ['asc''desc'])) {
  563.             $filters['sort'] = 'asc';
  564.         }
  565.         return $filters;
  566.     }
  567.     protected function getPostCondition($filters$ownId$threadId)
  568.     {
  569.         if ('all' == $filters) {
  570.             return ['threadId' => $threadId'status' => 'open''postId' => 0];
  571.         }
  572.         if ('onlyOwner' == $filters) {
  573.             return ['threadId' => $threadId'status' => 'open''userId' => $ownId'postId' => 0];
  574.         }
  575.         return false;
  576.     }
  577.     protected function getPostOrderBy($sort)
  578.     {
  579.         if ('asc' == $sort) {
  580.             return ['createdTime' => 'asc'];
  581.         }
  582.         if ('desc' == $sort) {
  583.             return ['createdTime' => 'desc'];
  584.         }
  585.     }
  586.     protected function getGroupMemberRole($groupId)
  587.     {
  588.         $user $this->getCurrentUser();
  589.         if (!$user['id']) {
  590.             return 0;
  591.         }
  592.         if ($this->getGroupService()->isOwner($groupId$user['id'])) {
  593.             return 2;
  594.         }
  595.         if ($this->getGroupService()->isAdmin($groupId$user['id'])) {
  596.             return 3;
  597.         }
  598.         if ($this->getGroupService()->isMember($groupId$user['id'])) {
  599.             return 1;
  600.         }
  601.         return 0;
  602.     }
  603.     protected function checkManagePermission($id$thread)
  604.     {
  605.         $user $this->getCurrentUser();
  606.         if (true == $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
  607.             return true;
  608.         }
  609.         if ($this->getGroupService()->isOwner($id$user['id'])) {
  610.             return true;
  611.         }
  612.         if ($this->getGroupService()->isAdmin($id$user['id'])) {
  613.             return true;
  614.         }
  615.         if ($thread['userId'] == $user['id']) {
  616.             return true;
  617.         }
  618.         return false;
  619.     }
  620.     /**
  621.      * @return UploadFileService
  622.      */
  623.     protected function getUploadFileService()
  624.     {
  625.         return $this->getBiz()->service('File:UploadFileService');
  626.     }
  627.     /**
  628.      * @return SettingService
  629.      */
  630.     protected function getSettingService()
  631.     {
  632.         return $this->getBiz()->service('System:SettingService');
  633.     }
  634.     /**
  635.      * @return NotificationService
  636.      */
  637.     protected function getNotifiactionService()
  638.     {
  639.         return $this->getBiz()->service('User:NotificationService');
  640.     }
  641.     /**
  642.      * @return FileService
  643.      */
  644.     protected function getFileService()
  645.     {
  646.         return $this->getBiz()->service('Content:FileService');
  647.     }
  648.     /**
  649.      * @return ThreadService
  650.      */
  651.     protected function getThreadService()
  652.     {
  653.         return $this->getBiz()->service('Group:ThreadService');
  654.     }
  655.     /**
  656.      * @return UserService
  657.      */
  658.     protected function getUserService()
  659.     {
  660.         return $this->getBiz()->service('User:UserService');
  661.     }
  662.     /**
  663.      * @return GroupService
  664.      */
  665.     protected function getGroupService()
  666.     {
  667.         return $this->getBiz()->service('Group:GroupService');
  668.     }
  669.     /**
  670.      * @return FavoriteService
  671.      */
  672.     protected function getFavoriteService()
  673.     {
  674.         return $this->createService('Favorite:FavoriteService');
  675.     }
  676. }