ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\MediaObjects\Usage\UsageRetrieval Class Reference
+ Inheritance diagram for ILIAS\MediaObjects\Usage\UsageRetrieval:
+ Collaboration diagram for ILIAS\MediaObjects\Usage\UsageRetrieval:

Public Member Functions

 __construct (protected \ilObjMediaObject $media_object, protected bool $include_hist, protected InternalDomainService $domain)
 
 getData (array $fields, ?Range $range=null, ?Order $order=null, array $filter=[], array $parameters=[])
 
 count (array $filter=[], array $parameters=[])
 
 isFieldNumeric (string $field)
 
 getData (array $fields, ?Range $range=null, ?Order $order=null, array $filter=[], array $parameters=[])
 
 count (array $filter, array $parameters)
 
 isFieldNumeric (string $field)
 

Protected Member Functions

 collectData ()
 
 buildRow (string $id, array $usage)
 
 buildVersions (array $usage)
 
 getFirstWritableRefId (int $object_id)
 

Protected Attributes

array $data = null
 

Detailed Description

Definition at line 29 of file UsageRetrieval.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\MediaObjects\Usage\UsageRetrieval::__construct ( protected \ilObjMediaObject  $media_object,
protected bool  $include_hist,
protected InternalDomainService  $domain 
)

Definition at line 35 of file UsageRetrieval.php.

39 {
40 }

Member Function Documentation

◆ buildRow()

ILIAS\MediaObjects\Usage\UsageRetrieval::buildRow ( string  $id,
array  $usage 
)
protected

Definition at line 133 of file UsageRetrieval.php.

133 : array
134 {
135 $usage_type = (string) ($usage["type"] ?? "");
136 $container_type = "";
137 if (str_contains($usage_type, ":")) {
138 [$container_type, $usage_type] = explode(":", $usage_type, 2);
139 }
140
141 $item = [
142 "type" => "",
143 "title" => "",
144 "sub_txt" => "",
145 "sub_title" => "",
146 "link" => ""
147 ];
148
149 switch ($usage_type) {
150 case "pg":
151 $page = $usage["page"] ?? null;
152 if (!$page instanceof \ilPageObject) {
153 break;
154 }
155 switch ($container_type) {
156 case "lm":
157 if (\ilObject::_lookupType($page->getParentId()) === "lm") {
158 $learning_module = new \ilObjLearningModule($page->getParentId(), false);
159 $item["type"] = $this->domain->lng()->txt("obj_" . $container_type);
160 $item["title"] = $learning_module->getTitle();
161 $item["sub_txt"] = $this->domain->lng()->txt("pg");
162 $item["sub_title"] = \ilLMObject::_lookupTitle($page->getId());
163 $ref_id = $this->getFirstWritableRefId($learning_module->getId());
164 if ($ref_id > 0) {
165 $item["link"] = \ilLink::_getStaticLink(
166 null,
167 "pg",
168 true,
169 $page->getId() . "_" . $ref_id
170 );
171 }
172 }
173 break;
174
175 case "wpg":
176 $item["type"] = $this->domain->lng()->txt("obj_wiki");
177 $item["title"] = \ilObject::_lookupTitle($page->getParentId());
178 $item["sub_txt"] = $this->domain->lng()->txt("pg");
179 $item["sub_title"] = \ilWikiPage::lookupTitle($page->getId());
180 $ref_id = $this->getFirstWritableRefId($page->getParentId());
181 if ($ref_id > 0) {
182 $item["link"] = \ilLink::_getStaticLink($ref_id, "wiki");
183 }
184 break;
185
186 case "term":
187 $term_id = $page->getId();
188 $glossary_id = \ilGlossaryTerm::_lookGlossaryID($term_id);
189 $item["type"] = $this->domain->lng()->txt("obj_glo");
190 $item["title"] = \ilObject::_lookupTitle($glossary_id);
191 $item["sub_txt"] = $this->domain->lng()->txt("cont_term");
192 $item["sub_title"] = \ilGlossaryTerm::_lookGlossaryTerm($term_id);
193 $ref_id = $this->getFirstWritableRefId($page->getParentId());
194 if ($ref_id > 0) {
195 $item["link"] = \ilLink::_getStaticLink($ref_id, "glo");
196 }
197 break;
198
199 case "cont":
200 $object_type = \ilObject::_lookupType($page->getId());
201 $item["type"] = $this->domain->lng()->txt("obj_" . $object_type);
202 $item["title"] = \ilObject::_lookupTitle($page->getId());
203 $ref_id = $this->getFirstWritableRefId($page->getId());
204 if ($ref_id > 0) {
205 $item["link"] = \ilLink::_getStaticLink($ref_id, $object_type);
206 }
207 break;
208
209 case "mep":
210 $item["type"] = $this->domain->lng()->txt("mep_page_type_mep");
211 $item["sub_txt"] = $this->domain->lng()->txt("mep_page_type_mep");
212 $item["sub_title"] = \ilMediaPoolItem::lookupTitle((int) $usage["id"]);
213 foreach (\ilMediaPoolItem::getPoolForItemId((int) $usage["id"]) as $media_pool_id) {
214 $ref_ids = \ilObject::_getAllReferences($media_pool_id);
215 $item["title"] = \ilObject::_lookupTitle($media_pool_id);
216 foreach ($ref_ids as $ref_id) {
217 $item["link"] = \ilLink::_getStaticLink($ref_id, "mep");
218 break;
219 }
220 break;
221 }
222 break;
223
224 default:
226 if ($object_id > 0) {
227 $object_type = \ilObject::_lookupType($object_id);
228 $item["type"] = $this->domain->lng()->txt("obj_" . $object_type);
229 $item["title"] = \ilObject::_lookupTitle($object_id);
230 $ref_id = $this->getFirstWritableRefId($object_id);
231 if ($ref_id > 0) {
232 $item["link"] = \ilLink::_getStaticLink($ref_id, $object_type);
233 }
234 }
235 break;
236 }
237
238 if (($usage["trash"] ?? false) === true) {
239 $item["title"] .= " (" . $this->domain->lng()->txt("trash") . ")";
240 }
241 break;
242
243 case "mep":
244 $item["type"] = $this->domain->lng()->txt("obj_mep");
245 $item["title"] = \ilObject::_lookupTitle((int) $usage["id"]);
246 $ref_id = $this->getFirstWritableRefId((int) $usage["id"]);
247 if ($ref_id > 0) {
248 $item["link"] = \ilLink::_getStaticLink($ref_id, "mep");
249 }
250 break;
251
252 case "map":
253 $item["type"] = $this->domain->lng()->txt("obj_mob");
254 $item["title"] = \ilObject::_lookupTitle((int) $usage["id"]);
255 $item["sub_txt"] = $this->domain->lng()->txt("cont_link_area");
256 break;
257
258 case "news":
259 $object_id = \ilNewsItem::_lookupContextObjId((int) $usage["id"]);
260 $object_type = \ilObject::_lookupType($object_id);
261 $item["type"] = $this->domain->lng()->txt("obj_" . $object_type);
262 $item["title"] = \ilObject::_lookupTitle($object_id);
263 $item["sub_txt"] = $this->domain->lng()->txt("news");
264 $ref_id = $this->getFirstWritableRefId($object_id);
265 if ($ref_id > 0) {
266 $item["link"] = \ilLink::_getStaticLink($ref_id, $object_type);
267 }
268 break;
269 }
270
271 $title = $item["title"];
272 if ($item["sub_txt"] !== "") {
273 $title .= ", " . $item["sub_txt"];
274 if ($item["sub_title"] !== "") {
275 $title .= ": " . $item["sub_title"];
276 }
277 }
278
279 if ($usage_type === "clip") {
280 $title = $this->domain->lng()->txt("cont_users_have_mob_in_clip1") .
281 " " . (int) ($usage["cnt"] ?? 0) . " " .
282 $this->domain->lng()->txt("cont_users_have_mob_in_clip2");
283 }
284
285 return [
286 "id" => $id,
287 "object" => $title,
288 "object_link" => $item["link"],
289 "type" => $item["type"],
290 "versions" => $this->buildVersions($usage)
291 ];
292 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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)
static getPoolForItemId(int $a_id)
static lookupTitle(int $a_id)
static _lookupContextObjId(int $a_news_id)
Context Object ID.
static getParentObjectIdForUsage(array $a_usage, bool $a_include_all_access_obj_ids=false)
Get's the repository object ID of a parent object, if possible see ilWebAccessChecker.
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
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

References $id, $page, $usage, ilObject\_getAllReferences(), ilLink\_getStaticLink(), ilGlossaryTerm\_lookGlossaryID(), ilGlossaryTerm\_lookGlossaryTerm(), ilNewsItem\_lookupContextObjId(), ilLMObject\_lookupTitle(), ilObject\_lookupTitle(), ilObject\_lookupType(), ilObjMediaObject\getParentObjectIdForUsage(), ilMediaPoolItem\getPoolForItemId(), ILIAS\Repository\int(), ilMediaPoolItem\lookupTitle(), and ilWikiPage\lookupTitle().

+ Here is the call graph for this function:

◆ buildVersions()

ILIAS\MediaObjects\Usage\UsageRetrieval::buildVersions ( array  $usage)
protected

Definition at line 294 of file UsageRetrieval.php.

294 : string
295 {
296 if (!is_array($usage["versions"] ?? null) || !isset($usage["page"])) {
297 return " ";
298 }
299
300 $versions = $usage["versions"];
301 $version_text = "";
302 if (count($versions) > 5) {
303 $version_text = "..., ";
304 $versions = array_slice($versions, -5);
305 }
306
307 $separator = "";
308 foreach ($versions as $version) {
309 $history_number = $version["hist_nr"] ?? 0;
310 if ($history_number == 0) {
311 $history_number = $this->domain->lng()->txt("cont_current_version");
312 }
313 $version_text .= $separator . $history_number;
314 if (($version["lang"] ?? "") !== "") {
315 $version_text .= "/" . $version["lang"];
316 }
317 $separator = ", ";
318 }
319
320 return $version_text;
321 }
$version
Definition: plugin.php:24
count(array $filter=[], array $parameters=[])

References $usage, and $version.

◆ collectData()

ILIAS\MediaObjects\Usage\UsageRetrieval::collectData ( )
protected

Definition at line 70 of file UsageRetrieval.php.

70 : array
71 {
72 if ($this->data !== null) {
73 return $this->data;
74 }
75
76 $usages = $this->media_object->getUsages($this->include_hist);
77 $clip_count = 0;
78 $aggregated_usages = [];
79
80 foreach ($usages as $usage) {
81 $usage["trash"] = false;
82 if (str_contains((string) ($usage["type"] ?? ""), ":")) {
83 [$container_type, $usage_type] = explode(":", (string) $usage["type"], 2);
84
85 if ($usage_type === "pg") {
86 $page = \ilPageObjectFactory::getInstance($container_type, (int) $usage["id"]);
87 $usage["page"] = $page;
88 $repo_tree = $this->domain->repositoryTree();
89 $ref_ids = array_filter(
90 \ilObject::_getAllReferences($page->getRepoObjId()),
91 static fn($ref_id): bool => $repo_tree->isInTree($ref_id)
92 );
93 if ($ref_ids === []) {
94 $usage["trash"] = true;
95 }
96 }
97 }
98
99 if (($usage["type"] ?? "") === "clip") {
100 $clip_count++;
101 continue;
102 }
103
104 if (!$this->include_hist && ($usage["trash"] ?? false)) {
105 continue;
106 }
107
108 $key = (string) $usage["type"] . ":" . (string) $usage["id"];
109 if (!isset($aggregated_usages[$key])) {
110 $aggregated_usages[$key] = $usage;
111 }
112 $aggregated_usages[$key]["versions"][] = [
113 "hist_nr" => $usage["hist_nr"] ?? 0,
114 "lang" => $usage["lang"] ?? ""
115 ];
116 }
117
118 if ($clip_count > 0) {
119 $aggregated_usages["clip"] = [
120 "type" => "clip",
121 "cnt" => $clip_count
122 ];
123 }
124
125 $this->data = [];
126 foreach ($aggregated_usages as $id => $usage) {
127 $this->data[] = $this->buildRow((string) $id, $usage);
128 }
129
130 return $this->data;
131 }
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")

References $data, $id, $page, $usage, ilObject\_getAllReferences(), and ilPageObjectFactory\getInstance().

+ Here is the call graph for this function:

◆ count()

ILIAS\MediaObjects\Usage\UsageRetrieval::count ( array  $filter = [],
array  $parameters = [] 
)

Implements ILIAS\Repository\RetrievalInterface.

Definition at line 58 of file UsageRetrieval.php.

61 : int {
62 return count($this->collectData());
63 }

◆ getData()

ILIAS\MediaObjects\Usage\UsageRetrieval::getData ( array  $fields,
?Range  $range = null,
?Order  $order = null,
array  $filter = [],
array  $parameters = [] 
)

Implements ILIAS\Repository\RetrievalInterface.

Definition at line 42 of file UsageRetrieval.php.

48 : \Generator {
49 $data = $this->collectData();
50 $data = $this->applyOrder($data, $order);
51 $data = $this->applyRange($data, $range);
52
53 foreach ($data as $row) {
54 yield $row;
55 }
56 }

◆ getFirstWritableRefId()

ILIAS\MediaObjects\Usage\UsageRetrieval::getFirstWritableRefId ( int  $object_id)
protected

Definition at line 323 of file UsageRetrieval.php.

323 : int
324 {
325 foreach (\ilObject::_getAllReferences($object_id) as $ref_id) {
326 if ($this->domain->access()->checkAccess("write", "", $ref_id)) {
327 return (int) $ref_id;
328 }
329 }
330 return 0;
331 }

References ilObject\_getAllReferences().

+ Here is the call graph for this function:

◆ isFieldNumeric()

ILIAS\MediaObjects\Usage\UsageRetrieval::isFieldNumeric ( string  $field)

Implements ILIAS\Repository\RetrievalInterface.

Definition at line 65 of file UsageRetrieval.php.

65 : bool
66 {
67 return false;
68 }

Field Documentation

◆ $data

array ILIAS\MediaObjects\Usage\UsageRetrieval::$data = null
protected

Definition at line 33 of file UsageRetrieval.php.


The documentation for this class was generated from the following file: