metadata = $metadata; $this->entityManager = $entityManager; $this->user = $user; $this->listLoadProcessor = $listLoadProcessor; } public function getList(array $params): object { $repository = $this->entityManager->getRDBRepository('ActionHistoryRecord'); $scopes = $this->metadata->get('scopes'); $targetTypeList = array_filter( array_keys($scopes), function ($item) use ($scopes) { return !empty($scopes[$item]['object']) || !empty($scopes[$item]['lastViewed']); } ); $offset = $params['offset']; $maxSize = $params['maxSize']; $collection = $repository ->where([ 'userId' => $this->user->getId(), 'action' => 'read', 'targetType' => $targetTypeList, ]) ->order('MAX:createdAt', 'DESC') ->select([ 'targetId', 'targetType', 'MAX:number', ['MAX:createdAt', 'createdAt'], ]) ->group(['targetId', 'targetType']) ->limit($offset, $params['maxSize'] + 1) ->find(); foreach ($collection as $entity) { $this->listLoadProcessor->process($entity); $entity->set('id', Util::generateId()); } if ($maxSize && is_countable($collection) && count($collection) > $maxSize) { $total = -1; unset($collection[count($collection) - 1]); } else { $total = -2; } return (object) [ 'total' => $total, 'collection' => $collection, ]; } }