/** * 계층형 목록으로 반환 * * json 으로 반환되어 사용되어지기 위해 * 정순으로 목록화한 역순으로 반환 * * @param string $instanceId instance identifier * @param string $targetId target identifier * @param array $wheres 검색조건 * @param string|null $offsetHead 이전 목록의 마지막 head * @param string|null $offsetReply 이전 목록의 마지막 reply * @param int|null $take 아이템 갯수 * @return Paginator comment list */ public function loadMore($instanceId, $targetId, array $wheres = [], $offsetHead = null, $offsetReply = null, $take = null) { $config = $this->configs->get($this->getConfigKey($instanceId)); $take = $take ?: $config->get('perPage'); $direction = $config->get('reverse') === true ? 'asc' : 'desc'; $wheres['targetId'] = $targetId; $totalCount = $this->repo->countBaseInstanceId($instanceId, $wheres); if ($offsetHead !== null) { $wheres[] = function ($query) use($offsetHead, $offsetReply, $direction) { $query->where('head', $offsetHead); $ltgt = $direction == 'asc' ? '>' : '<'; if ($offsetReply === null) { $offsetReply = ''; } $query->where('reply', $ltgt, $offsetReply); $query->orWhere('head', '<', $offsetHead); }; } $comments = $this->repo->fetchBaseInstanceId($instanceId, $wheres, $take + 1, ['head' => 'desc', 'reply' => $direction]); $comments = $this->member->associates($comments); $paginator = new Paginator($comments, $take, null, ['totalCount' => $totalCount]); return $paginator; }