/**
  * get voted user list
  *
  * @param Request $request
  * @param $menuUrl
  * @param $option
  * @param $id
  * @return mixed
  */
 public function votedUserList(Request $request, $menuUrl, $option, $id)
 {
     $startId = $request->get('startId');
     $limit = $request->get('limit', 10);
     $item = $this->handler->getModel($this->config)->find($id);
     $this->handler->setModelConfig($item, $this->config);
     $counter = $this->handler->getVoteCounter();
     $logModel = $counter->newModel();
     $query = $logModel->where('counterName', $counter->getName())->where('targetId', $id)->where('counterOption', $option);
     if ($startId != null) {
         $query->where('id', '<', $startId);
     }
     $logs = $query->orderBy('id', 'desc')->take($limit)->get();
     $list = [];
     foreach ($logs as $log) {
         /** @var User $user */
         $user = $log->user;
         $profilePage = '#';
         if ($user->getId() != '') {
             $profilePage = route('member.profile', ['member' => $user->getId()]);
         }
         $list[] = ['id' => $user->getId(), 'displayName' => $user->getDisplayName(), 'profileImage' => $user->getProfileImage(), 'createdAt' => (string) $log->createdAt, 'profilePage' => $profilePage];
     }
     $nextStartId = 0;
     if (count($logs) == $limit) {
         $nextStartId = $logs->last()->id;
     }
     return XePresenter::makeApi(['item' => $item, 'list' => $list, 'nextStartId' => $nextStartId]);
 }
 /**
  * change instance id
  *
  * @return \Xpressengine\Presenter\RendererInterface
  */
 public function copy()
 {
     $documentIds = Input::get('id');
     $documentIds = is_array($documentIds) ? $documentIds : [$documentIds];
     $instanceId = Input::get('instanceId');
     foreach ($documentIds as $id) {
         XeDB::beginTransaction();
         $this->handler->copy($id, $this->configHandler->get($instanceId), (new Keygen())->generate());
         XeDB::commit();
     }
     return $this->presenter->makeApi([]);
 }
 /**
  * set current page
  *
  * @param Request       $request       request
  * @param Handler       $handler       handler
  * @param ConfigHandler $configHandler config handler
  * @param BoardSlug     $slug          slug model
  * @return void
  */
 protected function setCurrentPage(Request $request, Handler $handler, ConfigHandler $configHandler, BoardSlug $slug)
 {
     $instanceId = $slug->instanceId;
     // 이 slug 가 포함된 페이지 출력
     $config = $configHandler->get($instanceId);
     $query = $handler->getModel($config)->where('instanceId', $instanceId)->visible();
     $orderType = $request->get('orderType', '');
     if ($orderType === '' && $config->get('orderType') != null) {
         $orderType = $config->get('orderType', '');
     }
     if ($orderType == '') {
         $query->where('head', '>=', $slug->board->head);
     } elseif ($orderType == 'assentCount') {
         $query->where('assentCount', '>', $slug->board->assentCount)->orWhere(function ($query) use($slug) {
             $query->where('assentCount', '=', $slug->board->assentCount);
             $query->where('head', '>=', $slug->board->head);
         });
     } elseif ($orderType == 'recentlyCreated') {
         $query->where(Board::CREATED_AT, '>', $slug->board->{Board::CREATED_AT})->orWhere(function ($query) use($slug) {
             $query->where(Board::CREATED_AT, '=', $slug->board->{Board::CREATED_AT});
             $query->where('head', '>=', $slug->board->head);
         });
     } elseif ($orderType == 'recentlyUpdated') {
         $query->where(Board::UPDATED_AT, '>', $slug->board->{Board::UPDATED_AT})->orWhere(function ($query) use($slug) {
             $query->where(Board::UPDATED_AT, '=', $slug->board->{Board::UPDATED_AT});
             $query->where('head', '>=', $slug->board->head);
         });
     }
     Event::fire('xe.plugin.board.archive', [$query, $slug->board]);
     $count = $query->count() ?: 1;
     $page = (int) ($count / $config->get('perPage'));
     if ($count % $config->get('perPage') != 0) {
         ++$page;
     }
     $request->query->set('page', $page);
 }
 /**
  * get voted user list
  *
  * @param $boardId
  * @param $option
  */
 public function votedUsers($boardId, $option)
 {
     $id = Input::get('id');
     $author = Auth::user();
     $item = $this->handler->get($id, $this->boardId);
     $voteHandler = app('xe.board.vote');
     $paginator = $voteHandler->paginate($id, $option, Input::get('perPage'));
     $userIds = [];
     foreach ($paginator as $item) {
         $userIds[] = $item['userId'];
     }
     /** @var \Xpressengine\Member\Repositories\MemberRepositoryInterface $memberRepository */
     $memberRepository = app('Xpressengine\\Member\\Repositories\\MemberRepositoryInterface');
     $users = $memberRepository->findAll($userIds);
     $userList = [];
     foreach ($users as $user) {
         $userList[] = ['id' => $user->id, 'displayName' => $user->displayName, 'profileImage' => $user->getProfileImage()];
     }
     return Presenter::makeApi(['current_page' => $paginator->currentPage(), 'last_page' => $paginator->lastPage(), 'users' => $userList]);
 }
 /**
  * move to copy
  *
  * @return \Illuminate\Http\RedirectResponse|Redirect
  */
 public function copy(Request $request)
 {
     $documentIds = $request->get('id');
     $documentIds = is_array($documentIds) ? $documentIds : [$documentIds];
     $instanceId = $request->get('instanceId');
     $config = $this->configHandler->get($instanceId);
     if ($config === null) {
         throw new NotFoundConfigHttpException(['instanceId' => $instanceId]);
     }
     $items = Board::find($documentIds);
     foreach ($items as $item) {
         $this->handler->setModelConfig($item, $this->configHandler->get($item->instanceId));
         $user = new Guest();
         if ($item->userId != '') {
             $user = User::find($item->userId);
         }
         $this->handler->copy($item, $user, $config);
     }
     Session::flash('alert', ['type' => 'success', 'message' => xe_trans('xe::processed')]);
     return $this->presenter->makeApi([]);
 }
 /**
  * 게시판 요약 정보 반환
  *
  * @param string  $instanceId instance id
  * @param Handler $handler    board handler
  * @return string
  */
 public function summary($instanceId, Handler $handler)
 {
     $documentCount = $handler->countByBoardId($instanceId);
     $configs = $this->configHandler->getDynamicFields($this->configHandler->get($instanceId));
     $dynamicFieldCount = count($configs);
     return ['documentCount' => $documentCount, 'dynamicFieldCount' => $dynamicFieldCount];
 }