ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
Retrieval.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\Repository\RetrievalBase;
28
30{
31 use RetrievalBase;
32
33 protected ?array $data = null;
34
35 public function __construct(
36 protected \ilMediaPoolPage $page,
37 protected bool $include_hist,
38 protected InternalDomainService $domain
39 ) {
40 }
41
42 public function getData(
43 array $fields,
44 ?Range $range = null,
45 ?Order $order = null,
46 array $filter = [],
47 array $parameters = []
48 ): \Generator {
49 $data = $this->collectData();
50 $data = $this->applyOrder($data, $order);
51 $data = $this->applyRange($data, $range);
52
53 yield from $data;
54 }
55
56 public function count(
57 array $filter = [],
58 array $parameters = []
59 ): int {
60 return count($this->collectData());
61 }
62
63 public function isFieldNumeric(string $field): bool
64 {
65 return false;
66 }
67
68 protected function collectData(): array
69 {
70 if ($this->data !== null) {
71 return $this->data;
72 }
73
74 $usages = $this->page->getUsages($this->include_hist);
75 $clip_count = 0;
76 $aggregated_usages = [];
77
78 foreach ($usages as $usage) {
79 $usage["trash"] = false;
80 $usage_type = (string) ($usage["type"] ?? "");
81 if (str_contains($usage_type, ":")) {
82 [$container_type, $sub_type] = explode(":", $usage_type, 2);
83
84 if ($sub_type === "pg") {
86 $container_type,
87 (int) $usage["id"]
88 );
89 $usage["page"] = $page;
90 $repo_tree = $this->domain->repositoryTree();
91 $ref_ids = array_filter(
92 \ilObject::_getAllReferences($page->getRepoObjId()),
93 static fn($ref_id): bool => $repo_tree->isInTree($ref_id)
94 );
95 if ($ref_ids === []) {
96 $usage["trash"] = true;
97 }
98 }
99 }
100
101 if ($usage_type === "clip") {
102 $clip_count++;
103 continue;
104 }
105
106 if (!$this->include_hist && $usage["trash"]) {
107 continue;
108 }
109
110 $key = $usage_type . ":" . (string) $usage["id"];
111 if (!isset($aggregated_usages[$key])) {
112 $aggregated_usages[$key] = $usage;
113 }
114 $aggregated_usages[$key]["versions"][] = [
115 "hist_nr" => $usage["hist_nr"] ?? 0,
116 "lang" => $usage["lang"] ?? ""
117 ];
118 }
119
120 if ($clip_count > 0) {
121 $aggregated_usages["clip"] = [
122 "type" => "clip",
123 "cnt" => $clip_count
124 ];
125 }
126
127 $this->data = [];
128 foreach ($aggregated_usages as $id => $usage) {
129 $this->data[] = $this->buildRow((string) $id, $usage);
130 }
131
132 return $this->data;
133 }
134
135 protected function buildRow(string $id, array $usage): array
136 {
137 $usage_type = (string) ($usage["type"] ?? "");
138 $container_type = "";
139 if (str_contains($usage_type, ":")) {
140 [$container_type, $usage_type] = explode(":", $usage_type, 2);
141 }
142
143 $item = [
144 "type" => "",
145 "title" => "",
146 "sub_txt" => "",
147 "sub_title" => "",
148 "link" => ""
149 ];
150
151 switch ($usage_type) {
152 case "pg":
153 $page = $usage["page"] ?? null;
154 if (!$page instanceof \ilPageObject) {
155 break;
156 }
157
158 switch ($container_type) {
159 case "lm":
160 $lm_obj = new \ilObjLearningModule($page->getParentId(), false);
161 $item["type"] = $this->domain->lng()->txt("obj_" . $container_type);
162 $item["title"] = $lm_obj->getTitle();
163 $item["sub_txt"] = $this->domain->lng()->txt("pg");
164 $item["sub_title"] = \ilLMObject::_lookupTitle($page->getId());
165 $ref_id = $this->getFirstWritableRefId($lm_obj->getId());
166 if ($ref_id > 0) {
167 $item["link"] = \ilLink::_getLink(
168 null,
169 "pg",
170 [],
171 $page->getId() . "_" . $ref_id
172 );
173 }
174 break;
175
176 case "wpg":
177 $item["type"] = $this->domain->lng()->txt("obj_wiki");
178 $item["title"] = \ilObject::_lookupTitle($page->getParentId());
179 $item["sub_txt"] = $this->domain->lng()->txt("pg");
180 $item["sub_title"] = \ilWikiPage::lookupTitle($page->getId());
181 $ref_id = $this->getFirstWritableRefId($page->getParentId());
182 if ($ref_id > 0) {
183 $item["link"] = \ilLink::_getStaticLink($ref_id, "wiki");
184 }
185 break;
186
187 case "term":
188 $term_id = $page->getId();
189 $glossary_id = \ilGlossaryTerm::_lookGlossaryID($term_id);
190 $item["type"] = $this->domain->lng()->txt("obj_glo");
191 $item["title"] = \ilObject::_lookupTitle($glossary_id);
192 $item["sub_txt"] = $this->domain->lng()->txt("cont_term");
193 $item["sub_title"] = \ilGlossaryTerm::_lookGlossaryTerm($term_id);
194 $ref_id = $this->getFirstWritableRefId($page->getParentId());
195 if ($ref_id > 0) {
196 $item["link"] = \ilLink::_getStaticLink($ref_id, "glo");
197 }
198 break;
199
200 case "cont":
201 $object_type = \ilObject::_lookupType($page->getId());
202 $item["type"] = $this->domain->lng()->txt("obj_" . $object_type);
203 $item["title"] = \ilObject::_lookupTitle($page->getId());
204 $ref_id = $this->getFirstWritableRefId($page->getId());
205 if ($ref_id > 0) {
206 $item["link"] = \ilLink::_getStaticLink($ref_id, $object_type);
207 }
208 break;
209
210 case "copa":
211 $item["type"] = $this->domain->lng()->txt("obj_" . $container_type);
212 $item["title"] = \ilObject::_lookupTitle($page->getId());
213 $ref_id = $this->getFirstWritableRefId($page->getId());
214 if ($ref_id > 0) {
215 $item["link"] = \ilLink::_getStaticLink($ref_id, $container_type);
216 }
217 break;
218 }
219
220 if (($usage["trash"] ?? false) === true) {
221 $item["title"] .= " (" . $this->domain->lng()->txt("trash") . ")";
222 }
223 break;
224
225 case "mep":
226 $item["type"] = $this->domain->lng()->txt("obj_mep");
227 $item["title"] = \ilObject::_lookupTitle((int) $usage["id"]);
228 $ref_id = $this->getFirstWritableRefId((int) $usage["id"]);
229 if ($ref_id > 0) {
230 $item["link"] = \ilLink::_getStaticLink($ref_id, "mep");
231 }
232 break;
233
234 case "map":
235 $item["type"] = $this->domain->lng()->txt("obj_mob");
236 $item["title"] = \ilObject::_lookupTitle((int) $usage["id"]);
237 $item["sub_txt"] = $this->domain->lng()->txt("cont_link_area");
238 break;
239 }
240
241 $title = $item["title"];
242 if ($item["sub_txt"] !== "") {
243 $title .= ", " . $item["sub_txt"];
244 if ($item["sub_title"] !== "") {
245 $title .= ": " . $item["sub_title"];
246 }
247 }
248
249 if ($usage_type === "clip") {
250 $title = $this->domain->lng()->txt("cont_users_have_mob_in_clip1") .
251 " " . (int) ($usage["cnt"] ?? 0) . " " .
252 $this->domain->lng()->txt("cont_users_have_mob_in_clip2");
253 }
254
255 return [
256 "id" => $id,
257 "object" => $title,
258 "object_link" => $item["link"],
259 "type" => $item["type"],
260 "versions" => $this->buildVersions($usage)
261 ];
262 }
263
264 protected function buildVersions(array $usage): string
265 {
266 if (!is_array($usage["versions"] ?? null) || !isset($usage["page"])) {
267 return " ";
268 }
269
270 $versions = $usage["versions"];
271 $version_text = "";
272 if (count($versions) > 5) {
273 $version_text = "..., ";
274 $versions = array_slice($versions, -5);
275 }
276
277 $separator = "";
278 foreach ($versions as $version) {
279 $history_number = $version["hist_nr"] ?? 0;
280 if ($history_number == 0) {
281 $history_number = $this->domain->lng()->txt("cont_current_version");
282 }
283 $version_text .= $separator . $history_number;
284 if (($version["lang"] ?? "") !== "") {
285 $version_text .= "/" . $version["lang"];
286 }
287 $separator = ", ";
288 }
289
290 return $version_text;
291 }
292
293 protected function getFirstWritableRefId(int $object_id): int
294 {
295 foreach (\ilObject::_getAllReferences($object_id) as $ref_id) {
296 if ($this->domain->access()->checkAccess("write", "", $ref_id)) {
297 return (int) $ref_id;
298 }
299 }
300 return 0;
301 }
302}
$version
Definition: plugin.php:24
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
buildRow(string $id, array $usage)
Definition: Retrieval.php:135
count(array $filter=[], array $parameters=[])
Definition: Retrieval.php:56
__construct(protected \ilMediaPoolPage $page, protected bool $include_hist, protected InternalDomainService $domain)
Definition: Retrieval.php:35
getData(array $fields, ?Range $range=null, ?Order $order=null, array $filter=[], array $parameters=[])
Definition: Retrieval.php:42
static _lookGlossaryTerm(int $term_id)
get glossary term
static _lookGlossaryID(int $term_id)
get glossary id form term id
static _lookupTitle(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
static lookupTitle(int $a_page_id, string $lang="-")
foreach(array_slice($argv, 1) as $argument) $usage
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$data
Definition: storeScorm.php:45