Exemplo n.º 1
0
 /**
  *
  * @param Model_Tudu_Post $post
  * @throws Model_Tudu_Exception
  */
 public function filter(Model_Tudu_Post &$post)
 {
     // 缺少图度ID
     if (!$post->tuduId) {
         require 'Model/Tudu/Exception.php';
         throw new Model_Tudu_Exception('Tudu not exists', Model_Tudu_Exception::TUDU_NOTEXISTS);
     }
     $this->_user = Tudu_User::getInstance();
     // 没有权限
     if (!$this->_user->isLogined() || !$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_CREATE_POST)) {
         require 'Model/Tudu/Exception.php';
         throw new Model_Tudu_Exception('Denied to do current action', Model_Tudu_Exception::PERMISSION_DENIED);
     }
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     $this->_tudu = $daoTudu->getTuduById($this->_user->uniqueId, $post->tuduId);
     if (null === $this->_tudu || $this->_tudu->orgId != $this->_user->orgId) {
         require 'Model/Tudu/Exception.php';
         throw new Model_Tudu_Exception('Tudu not exists', Model_Tudu_Exception::TUDU_NOTEXISTS);
     }
     if ($this->_tudu->isDone) {
         require 'Model/Tudu/Exception.php';
         throw new Model_Tudu_Exception('Denied to do current action', Model_Tudu_Exception::TUDU_IS_DONE);
     }
     $isReceiver = $this->_user->uniqueId == $this->_tudu->uniqueId && count($this->_tudu->labels);
     $isAccepter = in_array($this->_user->userName, $this->_tudu->accepter, true);
     $isSender = in_array($this->_tudu->sender, array($this->_user->userName, $this->_user->account));
     // 编辑已存在回复
     if ($post->postId) {
         /* @var $daoPost Dao_Td_Tudu_Post */
         $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS);
         $this->_fromPost = $daoPost->getPost(array('tuduid' => $post->tuduId, 'postid' => $post->postId));
         if (null === $this->_fromPost) {
             require 'Model/Tudu/Exception.php';
             throw new Model_Tudu_Exception('Post not exists', Model_Tudu_Exception::POST_NOTEXISTS);
         }
         // 编辑回复权限
         if ($this->_fromPost->uniqueId != $this->_user->uniqueId) {
             $boards = $this->_getBoards();
             $board = $boards[$this->_tudu->boardId];
             if (!array_key_exists($this->_user->userId, $board['moderators'])) {
                 require 'Model/Tudu/Exception.php';
                 throw new Model_Tudu_Exception('Denied to do current action', Model_Tudu_Exception::PERMISSION_DENIED);
             }
         }
     } else {
         /*if (!$isReceiver) {
            require 'Model/Tudu/Exception.php';
           throw new Model_Tudu_Exception('Denied to do current action', Model_Tudu_Exception::PERMISSION_DENIED);
           }*/
     }
 }