*/ class ListItemLookup extends ConfigurableService implements ItemLookup { use OntologyAwareTrait; use PermissionLookupTrait; public const SERVICE_ID = 'taoQtiTest/CreatorItems/list'; /** * Retrieve QTI Items for the given parameters. * * @param core_kernel_classes_Class $itemClass the item class * @param array $propertyFilters the lookup format * @param int $offset for paging * @param int $limit for paging * * @return array the items * @throws common_exception_Error */ public function getItems( core_kernel_classes_Class $itemClass, array $propertyFilters = [], $offset = 0, $limit = 30 ): array { $result = $this->getListResourceLookupService()->getResources( $itemClass, [], $propertyFilters, $offset, $limit ); if (empty($result['nodes'])) { return $result; } $nodeIds = array_map( static function (array $node): string { return $node['uri']; }, $result['nodes'] ); foreach ($result['nodes'] as $i => &$node) { if (!in_array($node['uri'], $nodeIds, true)) { unset($result['nodes'][$i]); $result['total']--; continue; } $node['categories'] = $this->getCategoryService()->getItemCategories($this->getResource($node['uri'])); } unset($node); $result['nodes'] = $this->fillPermissions($result['nodes']); return $result; } /** * Get the ListResourceLookup */ protected function getListResourceLookupService() { return $this->getServiceLocator()->get(ListResourceLookup::SERVICE_ID); } private function getCategoryService(): CategoryService { /** @noinspection PhpIncompatibleReturnTypeInspection */ return $this->getServiceLocator()->get(CategoryService::SERVICE_ID); } }