コード例 #1
0
 /**
  *
  * @access protected
  * @param  \Map2u\ForumBundle\Entity\Board $board
  * @return array
  */
 protected function getFilterQueryStrings(Board $board)
 {
     $params = array();
     if ($board->getCategory()) {
         $params['category_filter'] = $board->getCategory()->getId();
         if ($board->getCategory()->getForum()) {
             $params['forum_filter'] = $board->getCategory()->getForum()->getId();
         }
     }
     return $params;
 }
コード例 #2
0
ファイル: Authorizer.php プロジェクト: josephzhao/map2uforum
 public function canShowBoard(Board $board, Forum $forum = null)
 {
     if ($board->getCategory()) {
         if (!$this->canShowCategory($board->getCategory(), $forum)) {
             return false;
         }
     }
     if (!$board->isAuthorisedToRead($this->securityContext)) {
         return false;
     }
     return true;
 }
コード例 #3
0
 /**
  *
  * @access public
  * @param  Array                                           $boards
  * @param  \Map2u\ForumBundle\Entity\Board             $boardShift
  * @param  int                                             $direction
  * @return \Map2u\ForumBundle\Manager\ManagerInterface
  */
 public function reorderBoards($boards, Board $boardShift, $direction)
 {
     $boardCount = count($boards) - 1;
     // Find board in collection to shift and use list order as array key for easier editing.
     $sorted = array();
     $shiftIndex = null;
     foreach ($boards as $boardIndex => $board) {
         if ($boards[$boardIndex]->getId() == $boardShift->getId()) {
             $shiftIndex = $boardIndex;
         }
         $sorted[$boardIndex] = $board;
     }
     $incrementKeysAfterIndex = function ($index, $arr) {
         $hydrated = array();
         foreach ($arr as $key => $el) {
             if ($key > $index) {
                 $hydrated[$key + 1] = $el;
             } else {
                 $hydrated[$key] = $el;
             }
         }
         return $hydrated;
     };
     $decrementKeysBeforeIndex = function ($index, $arr) {
         $hydrated = array();
         foreach ($arr as $key => $el) {
             if ($key < $index) {
                 $hydrated[$key - 1] = $el;
             } else {
                 $hydrated[$key] = $el;
             }
         }
         return $hydrated;
     };
     $shifted = array();
     // First Board needs reordering??
     if ($shiftIndex == 0) {
         if ($direction) {
             // Down (move down 1)
             $shifted = $sorted;
             $shifted[$shiftIndex] = $sorted[$shiftIndex + 1];
             $shifted[$shiftIndex + 1] = $sorted[$shiftIndex];
         } else {
             // Up (send to bottom)
             $shifted[$boardCount] = $sorted[0];
             unset($sorted[0]);
             $shifted = array_merge($decrementKeysBeforeIndex($boardCount + 1, $sorted), $shifted);
         }
     } else {
         // Last board needs reordering??
         if ($shiftIndex == $boardCount) {
             if ($direction) {
                 // Down (send to top)
                 $shifted[0] = $sorted[$boardCount];
                 unset($sorted[$boardCount]);
                 $shifted = array_merge($shifted, $incrementKeysAfterIndex(-1, $sorted));
             } else {
                 // Up (move up 1)
                 $shifted = $sorted;
                 $shifted[$shiftIndex] = $sorted[$shiftIndex - 1];
                 $shifted[$shiftIndex - 1] = $sorted[$shiftIndex];
             }
         } else {
             // Swap 2 boards not at beginning or end.
             $shifted = $sorted;
             if ($direction) {
                 // Down (move down 1)
                 $shifted[$shiftIndex] = $sorted[$shiftIndex + 1];
                 $shifted[$shiftIndex + 1] = $sorted[$shiftIndex];
             } else {
                 // Up (move up 1)
                 $shifted[$shiftIndex] = $sorted[$shiftIndex - 1];
                 $shifted[$shiftIndex - 1] = $sorted[$shiftIndex];
             }
         }
     }
     // Set the order from the $index arranged prior and persist.
     foreach ($shifted as $index => $board) {
         $board->setListOrderPriority($index);
         $this->persist($board);
     }
     $this->flush();
     return $this;
 }
コード例 #4
0
 /**
  *
  * @access protected
  * @param \Map2u\ForumBundle\Entity\Board $board
  */
 protected function updateBoardStats(Board $board)
 {
     if ($board) {
         if ($board->getId()) {
             $stats = $this->topicModel->getTopicAndPostCountForBoardById($board->getId());
             // set the board topic / post count
             $board->setCachedTopicCount($stats['topicCount']);
             $board->setCachedPostCount($stats['postCount']);
             $lastTopic = $this->topicModel->findLastTopicForBoardByIdWithLastPost($board->getId());
             // set last_post for board
             if ($lastTopic) {
                 $board->setLastPost($lastTopic->getLastPost() ?: null);
             } else {
                 $board->setLastPost(null);
             }
             $this->boardModel->updateBoard($board);
         }
     }
 }
コード例 #5
0
 /**
  *
  * @access public
  * @param  \Map2u\ForumBundle\Entity\Forum                        $forum
  * @param  \Map2u\ForumBundle\Entity\Board                        $board
  * @return \Map2u\ForumBundle\Component\Crumbs\Factory\CrumbTrail
  */
 public function addUserBoardShow(Forum $forum, Board $board)
 {
     return $this->addUserCategoryShow($forum, $board->getCategory())->add($board->getName(), array('route' => 'ccdn_forum_user_board_show', 'params' => array('forumName' => $forum->getName(), 'boardId' => $board->getId())));
 }
コード例 #6
0
 /**
  *
  * @access protected
  * @param \Map2u\ForumBundle\Entity\Board $board
  */
 protected function onSuccess(Board $board)
 {
     $this->dispatcher->dispatch(ForumEvents::ADMIN_BOARD_DELETE_SUCCESS, new AdminBoardEvent($this->request, $board));
     if (!$this->form->get('confirm_subordinates')->getData()) {
         $topics = new ArrayCollection($board->getTopics()->toArray());
         $this->boardModel->reassignTopicsToBoard($topics, null)->flush();
     }
     $this->boardModel->deleteBoard($board);
     $this->dispatcher->dispatch(ForumEvents::ADMIN_BOARD_DELETE_COMPLETE, new AdminBoardEvent($this->request, $board));
 }