コード例 #1
0
 /**
  *
  * @access public
  * @param  Array                                           $boards
  * @param  \CCDNForum\ForumBundle\Entity\Board             $boardShift
  * @param  int                                             $direction
  * @return \CCDNForum\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;
 }
コード例 #2
0
 /**
  *
  * @access public
  * @param  \CCDNForum\ForumBundle\Entity\Forum                        $forum
  * @param  \CCDNForum\ForumBundle\Entity\Board                        $board
  * @return \CCDNForum\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())));
 }
コード例 #3
0
 /**
  *
  * @access protected
  * @param \CCDNForum\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);
         }
     }
 }