pageList)->limit(ApiUtil::getLimit($limit), $offset); if ($filter?->id) { $pageList->andSpec(Operator::inIntArray($filter->id, 'p.id')); } if ($filter?->code) { $pageList->andSpec(Operator::inStringArray($filter->code, 'p.code')); } if ($filter?->parent !== null) { $pageList->andSpec(Operator::inIntArray($filter->parent, 'p.parent')); } if ($sort) { /** @var SortEnum $value */ foreach (array_filter($sort->getData()) as $field => $value) { $pageList->orderBy("p.{$field}", $value->value); } } return (new PageCollection(ApiUtil::wrapItems( $pageList->getPages($totalCount)->toArray(), Page::class )))->setItemsTotalCount($totalCount)->setOffset($offset)->setLimit($limit); } public function getSystemPages(?int $offset, int $limit, ?Parameters $sort, ?SystemPageFilterInput $filter): SystemPageCollection { $systemPageList = (clone $this->systemPageList) ->limit(ApiUtil::getLimit($limit), $offset); if ($filter?->id) { $systemPageList->andSpec(Operator::inIntArray($filter->id, 'p.id')); } if ($filter?->code) { $systemPageList->andSpec(Operator::inStringArray($filter->code, 'p.code')); } if ($filter?->type !== null) { $systemPageList->andSpec(Operator::inIntArray($filter->type, 'p.type')); } if ($sort) { /** @var SortEnum $value */ foreach (array_filter($sort->getData()) as $field => $value) { $systemPageList->orderBy("p.{$field}", $value->value); } } return (new SystemPageCollection(ApiUtil::wrapItems( $systemPageList->getPages($totalCount)->toArray(), Page::class )))->setItemsTotalCount($totalCount)->setOffset($offset)->setLimit($limit); } public function getFragments(): PageCollection { $pageList = (clone $this->systemPageList); $pageList->andSpec(Operator::equals(['p.type' => FragmentPage::getType()])); return new PageCollection( ApiUtil::wrapItems( $pageList->getPages($totalCount)->toArray(), Page::class ) ); } public function getPage(int $id): ?Page { $pageList = (clone $this->pageList) ->andSpec(Operator::equals(['p.id' => $id])); $pages = $pageList->getPages($totalCount)->toArray(); if (count($pages)) { return new Page(reset($pages)); } return null; } public function getSystemPage(int $id): ?SystemPage { $pageList = (clone $this->systemPageList) ->andSpec(Operator::equals(['p.id' => $id])); $pages = $pageList->getPages($totalCount)->toArray(); if (count($pages)) { return new SystemPage(reset($pages)); } return null; } }