templateList); if ($filter?->id) { $templateList->andSpec(Operator::inIntArray($filter->id, 't.id')); } if ($filter?->categoryId) { $templateList->andSpec(Operator::inIntArray($filter->categoryId, 't.id_category')); } if ($filter?->visible !== null) { $templateList->andSpec(Operator::equals(['figure' => $filter->visible ? 'Y' : 'N'])); } if ($sort) { /** @var SortEnum $value */ foreach (array_filter($sort->getData()) as $field => $value) { $templateList->orderBy("t.{$field}", $value->value); } } $templates = new TemplateCollection( ApiUtil::wrapItems( $templateList->getTemplates($totalCount)->toArray(), Template::class ) ); return $templates ->setLimit($limit) ->setOffset($offset) ->setItemsTotalCount($totalCount); } public function getTemplate(int $id): ?Template { $templates = (clone $this->templateList) ->andSpec(Operator::equals(['t.id' => $id])) ->getTemplates(); if ($templates = $templates->toArray()) { return new Template(reset($templates)); } return null; } }