ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Searcher.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ILIAS\MetaData\Search\Filters\FactoryInterface as SearchFilterFactory;
26use ILIAS\MetaData\Search\Clauses\FactoryInterface as SearchClauseFactory;
28use ILIAS\MetaData\Copyright\Identifiers\HandlerInterface as CopyrightIdentifierHandler;
32
34{
35 protected SearchFilterFactory $search_filter_factory;
36 protected SearchClauseFactory $search_clause_factory;
37 protected PathFactory $path_factory;
38 protected CopyrightIdentifierHandler $copyright_identifier_handler;
39
43 protected array $types = [];
44 protected bool $restricted_to_repo_objects = false;
45
46 public function __construct(
47 SearchFilterFactory $search_filter_factory,
48 SearchClauseFactory $search_clause_factory,
49 PathFactory $path_factory,
50 CopyrightIdentifierHandler $copyright_identifier_handler,
51 ) {
52 $this->search_filter_factory = $search_filter_factory;
53 $this->search_clause_factory = $search_clause_factory;
54 $this->path_factory = $path_factory;
55 $this->copyright_identifier_handler = $copyright_identifier_handler;
56 }
57
61 public function search(
62 LOMRepository $lom_repository,
63 int $first_entry_id,
64 int ...$further_entry_ids
65 ): \Generator {
66 $path_to_copyright = $this->path_factory->custom()
67 ->withNextStep('rights')
68 ->withNextStep('description')
69 ->withNextStep('string')
70 ->get();
71
72 $copyright_search_clauses = [];
73 foreach ([$first_entry_id, ...$further_entry_ids] as $entry_id) {
74 $copyright_search_clauses[] = $this->search_clause_factory->getBasicClause(
75 $path_to_copyright,
76 Mode::EQUALS,
77 $this->copyright_identifier_handler->buildIdentifierFromEntryID($entry_id)
78 );
79 }
80 $full_search_clause = $this->search_clause_factory->getJoinedClauses(
82 ...$copyright_search_clauses
83 );
84
85 $filters = [];
86 foreach ($this->types as $type) {
87 $filters[] = $this->search_filter_factory->get(
89 $this->restricted_to_repo_objects ? Placeholder::OBJ_ID : Placeholder::ANY,
90 $type
91 );
92 }
93 if (empty($filters) && $this->restricted_to_repo_objects) {
94 $filters[] = $this->search_filter_factory->get(
96 Placeholder::OBJ_ID,
98 );
99 }
100
101 yield from $lom_repository->searchMD($full_search_clause, null, null, ...$filters);
102 }
103
104 public function withRestrictionToRepositoryObjects(bool $restricted): SearcherInterface
105 {
106 $clone = clone $this;
107 $clone->restricted_to_repo_objects = $restricted;
108 return $clone;
109 }
110
111 public function withAdditionalTypeFilter(string $type): SearcherInterface
112 {
113 $clone = clone $this;
114 $clone->types[] = $type;
115 return $clone;
116 }
117}
CopyrightIdentifierHandler $copyright_identifier_handler
Definition: Searcher.php:38
__construct(SearchFilterFactory $search_filter_factory, SearchClauseFactory $search_clause_factory, PathFactory $path_factory, CopyrightIdentifierHandler $copyright_identifier_handler,)
Definition: Searcher.php:46
search(LOMRepository $lom_repository, int $first_entry_id, int ... $further_entry_ids)
Definition: Searcher.php:61
SearchClauseFactory $search_clause_factory
Definition: Searcher.php:36
withRestrictionToRepositoryObjects(bool $restricted)
Definition: Searcher.php:104
SearchFilterFactory $search_filter_factory
Definition: Searcher.php:35
get(string $class_name)