## app binding * xe.document 로 바인딩 되어 있음 * Document facade 제공 ## 사용법 ### Instance 생성 php $documentHandler = app('xe.document'); $configEntity = $documentHandler->createInstance('newInstanceId'); $instanceManager->add($configEntity); ### 문서 등록 php $id = (new Keygen())->generate(); $inputs = ['id'=>$id', 'instanceId'=>'instance-id', 'title'=>'title', 'content'=>'content' ...]; $doc = new DocumentEntity($inputs); $documentHandler->add($doc); ### 문서 수정 php $doc = $documentHandler->get('document-id', 'instance-id'); $doc->title = 'changed title'; app('xe.document')->update($doc); ### 문서 삭제 php $doc = $documentHandler->get('document-id', 'instance-id'); app('xe.document')->remove($doc); ### 문서 조회 php instance id, document id 로 문서 갖고오기 $doc = $documentHandler->get('document-id', 'instance-id'); document id 로 문서 조회 $doc = $documentHandler->getById('document-id'); ### 문서 수 조회 php 전체 문서 수 조회회 $count = $documentHandler->count(); 인스턴스의 전체 문서 수 조회 $count = $documentHandler->countByInstanceId('instance-id'); ### 문서 목록 조회 php $wheres, $orders 는 Repository\DocumentRepository 참고 $wheres = []; $orders = []; $docs = $documentHandler->gets($wheres, $orders, 20); $paginate = $documentHandler->paginate($wheres, $orders, 20); ## 기타 ### Interception * Comment count 를 위해 DocumentServiceProvider 에서 Interception 등록
Author: XE Team (developers) (developers@xpressengine.com)
Example #1
0
 /**
  * set model's config
  *
  * @param Board        $board  board model
  * @param ConfigEntity $config board config entity
  * @return Board
  */
 public function setModelConfig(Board $board, ConfigEntity $config)
 {
     $instanceId = $config->get('boardId');
     $documentConfig = $this->documentHandler->getConfig($instanceId);
     $board->setConfig($documentConfig, $this->documentHandler->getDivisionTableName($documentConfig));
     return $board;
 }
Example #2
0
 /**
  * createDocumentInstance
  *
  * @param string $pageId    page instance id
  * @param string $pageTitle page title
  *
  * @return void
  */
 protected function createDocumentInstance($pageId, $pageTitle)
 {
     $documentConfig = new ConfigEntity();
     $documentConfig->set('instanceId', $pageId);
     $documentConfig->set('instanceName', $pageTitle);
     $this->document->getInstanceManager()->add($documentConfig);
 }
 /**
  * 게시판 요약 정보 반환
  *
  * @param string  $instanceId instance id
  * @param Handler $handler    board handler
  * @return string
  */
 public function summary($instanceId, Handler $handler)
 {
     $documentCount = $this->document->getModel($instanceId)->where('instanceId', $instanceId)->count();
     $configs = $this->configHandler->getDynamicFields($this->configHandler->get($instanceId));
     $dynamicFieldCount = count($configs);
     return ['documentCount' => $documentCount, 'dynamicFieldCount' => $dynamicFieldCount];
 }
Example #4
0
 /**
  * 반대
  *
  * @param ItemEntity            $item   board item entity
  * @param MemberEntityInterface $author user instance
  * @param string                $option 'assent' or 'dissent'
  * @return void
  */
 public function remove(ItemEntity $item, MemberEntityInterface $author, $option)
 {
     $doc = $item->getDocument();
     $this->counter->init(self::COUNTER_NAME, $option);
     $this->counter->remove($doc->id, $author, $option);
     $count = $this->count($doc->id);
     if ($option == 'assent') {
         $doc->assentCount = $count['assent'];
     } elseif ($option == 'dissent') {
         $doc->dissentCount = $count['dissent'];
     }
     $this->document->rawPut($doc);
 }
 /**
  * 게시판 제거
  *
  * @param string $boardId board id
  * @return void
  */
 public function destroy($boardId)
 {
     $config = $this->configHandler->get($boardId);
     if ($config === null) {
         throw new Exceptions\InvalidConfigException();
     }
     $this->conn->beginTransaction();
     // get document config
     $this->document->destroyInstance($boardId);
     $this->comment->drop($boardId);
     // remove board config
     $this->configHandler->remove($config);
     // 연결된 df 제거
     foreach ($this->configHandler->getDynamicFields($config) as $config) {
         $this->dynamicField->drop($config);
     }
     $this->conn->commit();
 }
Example #6
0
 /**
  * 게시판 이동
  * Document Package 에서 comment 를 지원하지 않아서 사용할 수 있는 인터페이스가 없음
  *
  * @param string         $id             document id
  * @param ConfigEntity   $config         destination board config entity
  * @param CommentHandler $commentHandler comment handler
  */
 public function move($id, ConfigEntity $config, CommentHandler $commentHandler)
 {
     if ($config === null) {
         throw new InvalidConfigException();
     }
     $item = $this->get($id);
     $doc = $item->getDocument();
     $dstInstanceId = $config->get('boardId');
     // 덧글이 있다면 덧글들을 모두 옯긴다.
     // 이거 document 인터페이스 있으멶 좋을까?? 사용 할 일 없어 보이는데.
     $rows = $this->document->getRepository()->getReplies($doc);
     foreach ($rows as $row) {
         $item = $this->get($row['id'], $row['instanceId']);
         $item->instanceId = $dstInstanceId;
         $item->getSlug()->instanceId = $dstInstanceId;
         if ($item->userId == '') {
             $item->userId = '';
         }
         $this->put($item);
         $commentHandler->moveByTarget($dstInstanceId, $item->id);
     }
 }
Example #7
0
 /**
  * update read count
  *
  * @param DocumentEntity $doc document entity
  * @return void
  */
 private function updateCount(DocumentEntity $doc)
 {
     $count = $this->count($doc->id);
     $doc->readCount = $count;
     $this->document->rawPut($doc);
 }
 /**
  * get revision document entity
  *
  * @param string $revisionId revision id
  * @return DocumentEntity
  */
 public function getRevision($revisionId)
 {
     return $this->document->getRevision($revisionId, $this->configHandler->getDynamicFields($this->config->get('boardId')));
 }
 /**
  * test get depth
  *
  * @return void
  */
 public function testGetDepth()
 {
     $conn = $this->conn;
     $repo = $this->repo;
     $configHandler = $this->configHandler;
     $instanceManager = $this->instanceManager;
     $request = $this->request;
     $handler = new DocumentHandler($conn, $repo, $configHandler, $instanceManager, $request);
     $doc = $this->getDocumentEntity();
     $doc->reply = '';
     $replyHelper = m::mock('Xpressengine\\Document\\Repositories\\ReplyHelper');
     $replyHelper->shouldReceive('getReplyCharLen')->andReturn(3);
     $repo->shouldReceive('getReplyHelper')->andReturn($replyHelper);
     $result = $handler->getDepth($doc);
     $this->assertEquals(0, $result);
     $doc->reply = 'aaa';
     $result = $handler->getDepth($doc);
     $this->assertEquals(1, $result);
 }