コード例 #1
0
 /**
  * 移动图度
  */
 public function moveAction()
 {
     $tuduIds = explode(',', $this->_request->getPost('tid'));
     $fromBoardId = $this->_request->getPost('fbid');
     $boardId = $this->_request->getPost('bid');
     $classId = $this->_request->getPost('cid', null);
     // 参数:图度ID必须存在
     if (!count($tuduIds)) {
         return $this->json(false, $this->lang['not_selected_board']);
     }
     $boards = $this->getBoards(false);
     // 来源版块必须存在
     if (!isset($boards[$fromBoardId])) {
         return $this->json(false, $this->lang['from_board_not_exists']);
     }
     $fromBoard = $boards[$fromBoardId];
     $isModerator = array_key_exists($this->_user->userId, $fromBoard['moderators']);
     $isSuperModerator = false;
     if ($fromBoard['parentid']) {
         $fromZone = $boards[$fromBoard['parentid']];
         $isSuperModerator = array_key_exists($this->_user->userId, $fromZone['moderators']);
     }
     // 操作人必须同时为源版块和目标版块的版主
     if (!$isModerator && !$isSuperModerator) {
         return $this->json(false, $this->lang['deny_to_move_tudu']);
     }
     // 来源版块和目标版块不能是同一版块
     if ($boardId == $fromBoardId) {
         return $this->json(false, $this->lang['move_to_current_board']);
     }
     // 目前版块必须存在
     if (!isset($boards[$boardId])) {
         return $this->json(false, $this->lang['target_board_not_exists']);
     }
     $success = 0;
     foreach ($tuduIds as $tuduId) {
         $tudu = $this->manager->getTuduById($tuduId, $this->_user->uniqueId);
         if (null === $tudu || $tudu->boardId != $fromBoardId) {
             continue;
         }
         if ($this->manager->moveTudu($tuduId, $boardId, $classId)) {
             $success++;
         }
     }
     if ($success <= 0) {
         return $this->json(false, $this->lang['tudu_move_failure']);
     }
     return $this->json(true, $this->lang['tudu_move_success']);
 }